apitimelineretweetedtome.php 4.9 KB

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