AccountManagerPlugin.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 AM_REL = 'acct-mgmt';
  35. function __construct()
  36. {
  37. parent::__construct();
  38. }
  39. /**
  40. * Hook for RouterInitialized event.
  41. *
  42. * @param URLMapper $m path-to-action mapper
  43. * @return boolean hook return
  44. */
  45. public function onRouterInitialized(URLMapper $m)
  46. {
  47. // Discovery actions
  48. $m->connect('main/amcd.json',
  49. array('action' => 'AccountManagementControlDocument'));
  50. $m->connect('main/amsessionstatus',
  51. array('action' => 'AccountManagementSessionStatus'));
  52. return true;
  53. }
  54. function onStartHostMetaLinks(&$links) {
  55. $links[] = new XML_XRD_Element_Link(AccountManagerPlugin::AM_REL,
  56. common_local_url('AccountManagementControlDocument'));
  57. }
  58. function onStartShowHTML($action)
  59. {
  60. //Account management discovery link
  61. header('Link: <'.common_local_url('AccountManagementControlDocument').'>; rel="'. AccountManagerPlugin::AM_REL.'"; type="application/json"');
  62. //Account management login status
  63. $cur = common_current_user();
  64. if(empty($cur)) {
  65. header('X-Account-Management-Status: none');
  66. } else {
  67. //TODO it seems " should be escaped in the name and id, but the spec doesn't seem to indicate how to do that
  68. header('X-Account-Management-Status: active; name="' . $cur->nickname . '"; id="' . $cur->nickname . '"');
  69. }
  70. }
  71. function onLoginAction($action, &$login) {
  72. switch ($action)
  73. {
  74. case 'AccountManagementControlDocument':
  75. $login = true;
  76. return false;
  77. default:
  78. return true;
  79. }
  80. }
  81. function onPluginVersion(&$versions)
  82. {
  83. $versions[] = array('name' => 'AccountManager',
  84. 'version' => GNUSOCIAL_VERSION,
  85. 'author' => 'Craig Andrews',
  86. 'homepage' => 'http://status.net/wiki/Plugin:AccountManager',
  87. 'rawdescription' =>
  88. // TRANS: Plugin description.
  89. _m('The Account Manager plugin implements the Account Manager specification.'));
  90. return true;
  91. }
  92. }