apitimelineretweetedtome.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Show most recent notices that are repeats in user's inbox
  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 2009 StatusNet, Inc.
  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')) {
  30. exit(1);
  31. }
  32. /**
  33. * Show most recent notices that are repeats in user's inbox
  34. *
  35. * @category API
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. */
  41. class ApiTimelineRetweetedToMeAction extends ApiAuthAction
  42. {
  43. const DEFAULTCOUNT = 20;
  44. const MAXCOUNT = 200;
  45. const MAXNOTICES = 3200;
  46. var $repeats = null;
  47. var $cnt = self::DEFAULTCOUNT;
  48. var $page = 1;
  49. var $since_id = null;
  50. var $max_id = null;
  51. /**
  52. * Take arguments for running
  53. *
  54. * @param array $args $_REQUEST args
  55. *
  56. * @return boolean success flag
  57. */
  58. function prepare($args)
  59. {
  60. parent::prepare($args);
  61. $cnt = $this->int('count', self::DEFAULTCOUNT, self::MAXCOUNT, 1);
  62. $page = $this->int('page', 1, (self::MAXNOTICES/$this->cnt));
  63. $since_id = $this->int('since_id');
  64. $max_id = $this->int('max_id');
  65. return true;
  66. }
  67. /**
  68. * Handle the request
  69. *
  70. * show a timeline of the user's repeated notices
  71. *
  72. * @param array $args $_REQUEST data (unused)
  73. *
  74. * @return void
  75. */
  76. function handle($args)
  77. {
  78. parent::handle($args);
  79. $offset = ($this->page-1) * $this->cnt;
  80. $limit = $this->cnt;
  81. // TRANS: Title for Atom feed "repeated to me". %s is the user nickname.
  82. $title = sprintf(_("Repeated to %s"), $this->auth_user->nickname);
  83. $subtitle = sprintf(
  84. // @todo FIXME: $profile is not defined.
  85. // TRANS: Subtitle for API action that shows most recent notices that are repeats in user's inbox.
  86. // TRANS: %1$s is the sitename, %2$s is a user nickname, %3$s is a user profile name.
  87. _('%1$s notices that were to repeated to %2$s / %3$s.'),
  88. $sitename, $this->user->nickname, $profile->getBestName()
  89. );
  90. $taguribase = TagURI::base();
  91. $id = "tag:$taguribase:RepeatedToMe:" . $this->auth_user->id;
  92. $link = common_local_url(
  93. 'all',
  94. array('nickname' => $this->auth_user->nickname)
  95. );
  96. $strm = $this->auth_user->repeatedToMe($offset, $limit, $this->since_id, $this->max_id);
  97. switch ($this->format) {
  98. case 'xml':
  99. $this->showXmlTimeline($strm);
  100. break;
  101. case 'json':
  102. $this->showJsonTimeline($strm);
  103. break;
  104. case 'atom':
  105. header('Content-Type: application/atom+xml; charset=utf-8');
  106. $atom = new AtomNoticeFeed($this->auth_user);
  107. $atom->setId($id);
  108. $atom->setTitle($title);
  109. $atom->setSubtitle($subtitle);
  110. $atom->setUpdated('now');
  111. $atom->addLink($link);
  112. $id = $this->arg('id');
  113. $atom->setSelfLink($self);
  114. $atom->addEntryFromNotices($strm);
  115. $this->raw($atom->getString());
  116. break;
  117. case 'as':
  118. header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
  119. $doc = new ActivityStreamJSONDocument($this->auth_user);
  120. $doc->setTitle($title);
  121. $doc->addLink($link, 'alternate', 'text/html');
  122. $doc->addItemsFromNotices($strm);
  123. $this->raw($doc->asString());
  124. break;
  125. default:
  126. // TRANS: Client error displayed when coming across a non-supported API method.
  127. $this->clientError(_('API method not found.'), $code = 404);
  128. break;
  129. }
  130. }
  131. /**
  132. * Return true if read only.
  133. *
  134. * MAY override
  135. *
  136. * @param array $args other arguments
  137. *
  138. * @return boolean is read only action?
  139. */
  140. function isReadOnly($args)
  141. {
  142. return true;
  143. }
  144. }