apitimelineretweetsofme.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Show authenticating user's most recent notices that have been repeated
  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 authenticating user's most recent notices that have been repeated
  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 ApiTimelineRetweetsOfMeAction 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 of list of repeated notices of the logged in user.
  82. // TRANS: %s is the nickname of the logged in user.
  83. $title = sprintf(_("Repeats of %s"), $this->auth_user->nickname);
  84. $sitename = common_config('site', 'name');
  85. $profile = $this->auth_user->getProfile();
  86. $subtitle = sprintf(
  87. // TRANS: Subtitle of API time with retweets of me.
  88. // TRANS: %1$s is the StatusNet sitename, %2$s is the user nickname, %3$s is the user profile name.
  89. _('%1$s notices that %2$s / %3$s has repeated.'),
  90. $sitename, $this->auth_user->nickname, $profile->getBestName()
  91. );
  92. $taguribase = TagURI::base();
  93. $id = "tag:$taguribase:RepeatsOfMe:" . $this->auth_user->id;
  94. $link = common_local_url(
  95. 'all',
  96. array('nickname' => $this->auth_user->nickname)
  97. );
  98. // This is a really bad query for some reason
  99. if (!common_config('performance', 'high')) {
  100. $strm = $this->auth_user->repeatsOfMe($offset, $limit, $this->since_id, $this->max_id);
  101. } else {
  102. $strm = new Notice();
  103. $strm->whereAdd('0 = 1');
  104. $strm->find();
  105. }
  106. switch ($this->format) {
  107. case 'xml':
  108. $this->showXmlTimeline($strm);
  109. break;
  110. case 'json':
  111. $this->showJsonTimeline($strm);
  112. break;
  113. case 'atom':
  114. header('Content-Type: application/atom+xml; charset=utf-8');
  115. $atom = new AtomNoticeFeed($this->auth_user);
  116. $atom->setId($id);
  117. $atom->setTitle($title);
  118. $atom->setSubtitle($subtitle);
  119. $atom->setUpdated('now');
  120. $atom->addLink($link);
  121. $atom->setSelfLink($this->getSelfUri());
  122. $atom->addEntryFromNotices($strm);
  123. $this->raw($atom->getString());
  124. break;
  125. case 'as':
  126. header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
  127. $doc = new ActivityStreamJSONDocument($this->auth_user);
  128. $doc->setTitle($title);
  129. $doc->addLink($link, 'alternate', 'text/html');
  130. $doc->addItemsFromNotices($strm);
  131. $this->raw($doc->asString());
  132. break;
  133. default:
  134. // TRANS: Client error displayed when coming across a non-supported API method.
  135. $this->clientError(_('API method not found.'), 404);
  136. break;
  137. }
  138. }
  139. /**
  140. * Return true if read only.
  141. *
  142. * MAY override
  143. *
  144. * @param array $args other arguments
  145. *
  146. * @return boolean is read only action?
  147. */
  148. function isReadOnly($args)
  149. {
  150. return true;
  151. }
  152. }