AccountManagerPlugin.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Plugin to implement the Account Manager specification
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Plugin
  23. * @package StatusNet
  24. * @author Craig Andrews <candrews@integralblue.com>
  25. * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. class AccountManagerPlugin extends Plugin
  33. {
  34. const PLUGIN_VERSION = '2.0.0';
  35. const AM_REL = 'acct-mgmt';
  36. function __construct()
  37. {
  38. parent::__construct();
  39. }
  40. /**
  41. * Hook for RouterInitialized event.
  42. *
  43. * @param URLMapper $m path-to-action mapper
  44. * @return boolean hook return
  45. */
  46. public function onRouterInitialized(URLMapper $m)
  47. {
  48. // Discovery actions
  49. $m->connect('main/amcd.json',
  50. ['action' => 'AccountManagementControlDocument']);
  51. $m->connect('main/amsessionstatus',
  52. ['action' => 'AccountManagementSessionStatus']);
  53. return true;
  54. }
  55. function onStartHostMetaLinks(&$links) {
  56. $links[] = new XML_XRD_Element_Link(AccountManagerPlugin::AM_REL,
  57. common_local_url('AccountManagementControlDocument'));
  58. }
  59. function onStartShowHTML($action)
  60. {
  61. //Account management discovery link
  62. header('Link: <'.common_local_url('AccountManagementControlDocument').'>; rel="'. AccountManagerPlugin::AM_REL.'"; type="application/json"');
  63. //Account management login status
  64. $cur = common_current_user();
  65. if(empty($cur)) {
  66. header('X-Account-Management-Status: none');
  67. } else {
  68. //TODO it seems " should be escaped in the name and id, but the spec doesn't seem to indicate how to do that
  69. header('X-Account-Management-Status: active; name="' . $cur->nickname . '"; id="' . $cur->nickname . '"');
  70. }
  71. }
  72. function onLoginAction($action, &$login) {
  73. switch ($action)
  74. {
  75. case 'AccountManagementControlDocument':
  76. $login = true;
  77. return false;
  78. default:
  79. return true;
  80. }
  81. }
  82. public function onPluginVersion(array &$versions): bool
  83. {
  84. $versions[] = array('name' => 'AccountManager',
  85. 'version' => self::PLUGIN_VERSION,
  86. 'author' => 'Craig Andrews',
  87. 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/AccountManager',
  88. 'rawdescription' =>
  89. // TRANS: Plugin description.
  90. _m('The Account Manager plugin implements the Account Manager specification.'));
  91. return true;
  92. }
  93. }