apitimelineretweetsofme.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Show authenticating user's most recent notices that have been repeated
  18. *
  19. * @category API
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @copyright 2009 StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * Show authenticating user's most recent notices that have been repeated
  28. *
  29. * @category API
  30. * @package GNUsocial
  31. * @author Evan Prodromou <evan@status.net>
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. */
  34. class ApiTimelineRetweetsOfMeAction extends ApiAuthAction
  35. {
  36. const DEFAULTCOUNT = 20;
  37. const MAXCOUNT = 200;
  38. const MAXNOTICES = 3200;
  39. public $repeats = null;
  40. public $cnt = self::DEFAULTCOUNT;
  41. public $page = 1;
  42. public $since_id = null;
  43. public $max_id = null;
  44. /**
  45. * Take arguments for running
  46. *
  47. * @param array $args $_REQUEST args
  48. *
  49. * @return bool success flag
  50. */
  51. public function prepare(array $args = [])
  52. {
  53. parent::prepare($args);
  54. $cnt = $this->int('count', self::DEFAULTCOUNT, self::MAXCOUNT, 1);
  55. $page = $this->int('page', 1, (self::MAXNOTICES/$this->cnt));
  56. $since_id = $this->int('since_id');
  57. $max_id = $this->int('max_id');
  58. return true;
  59. }
  60. /**
  61. * Handle the request
  62. *
  63. * show a timeline of the user's repeated notices
  64. *
  65. * @param array $args $_REQUEST data (unused)
  66. *
  67. * @return void
  68. */
  69. public function handle()
  70. {
  71. parent::handle();
  72. $offset = ($this->page-1) * $this->cnt;
  73. $limit = $this->cnt;
  74. // TRANS: Title of list of repeated notices of the logged in user.
  75. // TRANS: %s is the nickname of the logged in user.
  76. $title = sprintf(_("Repeats of %s"), $this->auth_user->nickname);
  77. $sitename = common_config('site', 'name');
  78. $profile = $this->auth_user->getProfile();
  79. $subtitle = sprintf(
  80. // TRANS: Subtitle of API time with retweets of me.
  81. // TRANS: %1$s is the StatusNet sitename, %2$s is the user nickname, %3$s is the user profile name.
  82. _('%1$s notices that %2$s / %3$s has repeated.'),
  83. $sitename,
  84. $this->auth_user->nickname,
  85. $profile->getBestName()
  86. );
  87. $taguribase = TagURI::base();
  88. $id = "tag:$taguribase:RepeatsOfMe:" . $this->auth_user->id;
  89. $link = common_local_url(
  90. 'all',
  91. ['nickname' => $this->auth_user->nickname]
  92. );
  93. $strm = $this->auth_user->repeatsOfMe(
  94. $offset,
  95. $limit,
  96. $this->since_id,
  97. $this->max_id
  98. );
  99. switch ($this->format) {
  100. case 'xml':
  101. $this->showXmlTimeline($strm);
  102. break;
  103. case 'json':
  104. $this->showJsonTimeline($strm);
  105. break;
  106. case 'atom':
  107. header('Content-Type: application/atom+xml; charset=utf-8');
  108. $atom = new AtomNoticeFeed($this->auth_user);
  109. $atom->setId($id);
  110. $atom->setTitle($title);
  111. $atom->setSubtitle($subtitle);
  112. $atom->setUpdated('now');
  113. $atom->addLink($link);
  114. $atom->setSelfLink($this->getSelfUri());
  115. $atom->addEntryFromNotices($strm);
  116. $this->raw($atom->getString());
  117. break;
  118. case 'as':
  119. header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
  120. $doc = new ActivityStreamJSONDocument($this->auth_user);
  121. $doc->setTitle($title);
  122. $doc->addLink($link, 'alternate', 'text/html');
  123. $doc->addItemsFromNotices($strm);
  124. $this->raw($doc->asString());
  125. break;
  126. default:
  127. // TRANS: Client error displayed when coming across a non-supported API method.
  128. $this->clientError(_('API method not found.'), 404);
  129. break;
  130. }
  131. }
  132. /**
  133. * Return true if read only.
  134. *
  135. * MAY override
  136. *
  137. * @param array $args other arguments
  138. *
  139. * @return boolean is read only action?
  140. */
  141. public function isReadOnly($args)
  142. {
  143. return true;
  144. }
  145. }