facebooklogin.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * An action for logging in with Facebook
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Plugin
  24. * @package StatusNet
  25. * @author Zach Copley <zach@status.net>
  26. * @copyright 2010-2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. exit(1);
  32. }
  33. class FacebookloginAction extends Action
  34. {
  35. function handle($args)
  36. {
  37. parent::handle($args);
  38. if (common_is_real_login()) {
  39. // TRANS: Client error displayed when trying to login while already logged in.
  40. $this->clientError(_m('Already logged in.'));
  41. } else {
  42. $this->showPage();
  43. }
  44. }
  45. function getInstructions()
  46. {
  47. // TRANS: Form instructions.
  48. return _m('Login with your Facebook Account');
  49. }
  50. function showPageNotice()
  51. {
  52. $instr = $this->getInstructions();
  53. $output = common_markup_to_html($instr);
  54. $this->elementStart('div', 'instructions');
  55. $this->raw($output);
  56. $this->elementEnd('div');
  57. }
  58. function title()
  59. {
  60. // TRANS: Page title.
  61. return _m('Login with Facebook');
  62. }
  63. function showContent() {
  64. $this->elementStart('fieldset');
  65. $facebook = Facebookclient::getFacebook();
  66. $params = array(
  67. 'scope' => 'read_stream,publish_stream,offline_access,user_status,user_location,user_website,email',
  68. 'redirect_uri' => common_local_url('facebookfinishlogin')
  69. );
  70. // Degrade to plain link if JavaScript is not available
  71. $this->elementStart(
  72. 'a',
  73. array(
  74. 'href' => $facebook->getLoginUrl($params),
  75. 'id' => 'facebook_button'
  76. )
  77. );
  78. $attrs = array(
  79. 'src' => Plugin::staticPath('FacebookBridge', 'images/login-button.png'),
  80. // TRANS: Alt text for "Login with Facebook" image.
  81. 'alt' => _m('Login with Facebook'),
  82. // TRANS: Title for "Login with Facebook" image.
  83. 'title' => _m('Login with Facebook.')
  84. );
  85. $this->element('img', $attrs);
  86. $this->elementEnd('a');
  87. $this->elementEnd('fieldset');
  88. }
  89. function showLocalNav()
  90. {
  91. $nav = new LoginGroupNav($this);
  92. $nav->show();
  93. }
  94. }