apiatomservice.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * An AtomPub service document for a user
  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 API
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2010 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. /**
  33. * Shows an AtomPub service document for a user
  34. *
  35. * @category API
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @copyright 2010 StatusNet, Inc.
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
  40. * @link http://status.net/
  41. */
  42. class ApiAtomServiceAction extends ApiBareAuthAction
  43. {
  44. /**
  45. * Take arguments for running
  46. *
  47. * @param array $args $_REQUEST args
  48. *
  49. * @return boolean success flag
  50. *
  51. */
  52. function prepare($args)
  53. {
  54. parent::prepare($args);
  55. $this->user = $this->getTargetUser($this->arg('id'));
  56. if (empty($this->user)) {
  57. // TRANS: Client error displayed when making an Atom API request for an unknown user.
  58. $this->clientError(_('No such user.'), 404);
  59. }
  60. return true;
  61. }
  62. /**
  63. * Handle the arguments. In our case, show a service document.
  64. *
  65. * @param Array $args unused.
  66. *
  67. * @return void
  68. */
  69. function handle($args)
  70. {
  71. parent::handle($args);
  72. header('Content-Type: application/atomsvc+xml');
  73. $this->startXML();
  74. $this->elementStart('service', array('xmlns' => 'http://www.w3.org/2007/app',
  75. 'xmlns:atom' => 'http://www.w3.org/2005/Atom',
  76. 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/'));
  77. $this->elementStart('workspace');
  78. // TRANS: Title for Atom feed.
  79. $this->element('atom:title', null, _m('ATOM','Main'));
  80. $this->elementStart('collection',
  81. array('href' => common_local_url('ApiTimelineUser',
  82. array('id' => $this->user->id,
  83. 'format' => 'atom'))));
  84. $this->element('atom:title',
  85. null,
  86. // TRANS: Title for Atom feed. %s is a user nickname.
  87. sprintf(_("%s timeline"),
  88. $this->user->nickname));
  89. $this->element('accept', null, 'application/atom+xml;type=entry');
  90. $this->element('activity:verb', null, ActivityVerb::POST);
  91. $this->elementEnd('collection');
  92. $this->elementStart('collection',
  93. array('href' => common_local_url('AtomPubSubscriptionFeed',
  94. array('subscriber' => $this->user->id))));
  95. $this->element('atom:title',
  96. null,
  97. // TRANS: Title for Atom feed with a user's subscriptions. %s is a user nickname.
  98. sprintf(_("%s subscriptions"),
  99. $this->user->nickname));
  100. $this->element('accept', null, 'application/atom+xml;type=entry');
  101. $this->element('activity:verb', null, ActivityVerb::FOLLOW);
  102. $this->elementEnd('collection');
  103. $this->elementStart('collection',
  104. array('href' => common_local_url('AtomPubFavoriteFeed',
  105. array('profile' => $this->user->id))));
  106. $this->element('atom:title',
  107. null,
  108. // TRANS: Title for Atom feed with a user's favorite notices. %s is a user nickname.
  109. sprintf(_("%s favorites"),
  110. $this->user->nickname));
  111. $this->element('accept', null, 'application/atom+xml;type=entry');
  112. $this->element('activity:verb', null, ActivityVerb::FAVORITE);
  113. $this->elementEnd('collection');
  114. $this->elementStart('collection',
  115. array('href' => common_local_url('AtomPubMembershipFeed',
  116. array('profile' => $this->user->id))));
  117. $this->element('atom:title',
  118. null,
  119. // TRANS: Title for Atom feed with a user's memberships. %s is a user nickname.
  120. sprintf(_("%s memberships"),
  121. $this->user->nickname));
  122. $this->element('accept', null, 'application/atom+xml;type=entry');
  123. $this->element('activity:verb', null, ActivityVerb::JOIN);
  124. $this->elementEnd('collection');
  125. $this->elementEnd('workspace');
  126. $this->elementEnd('service');
  127. $this->endXML();
  128. }
  129. }