apiqvittertimelineuser.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3. · ·
  4. · Show timelines for both local and remote users ·
  5. · ·
  6. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7. · ·
  8. · ·
  9. · Q V I T T E R ·
  10. · ·
  11. · https://git.gnu.io/h2p/Qvitter ·
  12. · ·
  13. · ·
  14. · <o) ·
  15. · /_//// ·
  16. · (____/ ·
  17. · (o< ·
  18. · o> \\\\_\ ·
  19. · \\) \____) ·
  20. · ·
  21. · ·
  22. · ·
  23. · Qvitter is free software: you can redistribute it and / or modify it ·
  24. · under the terms of the GNU Affero General Public License as published by ·
  25. · the Free Software Foundation, either version three of the License or (at ·
  26. · your option) any later version. ·
  27. · ·
  28. · Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
  29. · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
  30. · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
  31. · more details. ·
  32. · ·
  33. · You should have received a copy of the GNU Affero General Public License ·
  34. · along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
  35. · ·
  36. · Contact h@nnesmannerhe.im if you have any questions. ·
  37. · ·
  38. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  39. if (!defined('GNUSOCIAL')) { exit(1); }
  40. class ApiQvitterTimelineUserAction extends ApiBareAuthAction
  41. {
  42. var $notices = null;
  43. var $next_id = null;
  44. /**
  45. * Take arguments for running
  46. *
  47. * @param array $args $_REQUEST args
  48. *
  49. * @return boolean success flag
  50. */
  51. protected function prepare(array $args=array())
  52. {
  53. parent::prepare($args);
  54. $this->target = $this->getTargetProfile($this->arg('id'));
  55. if (!($this->target instanceof Profile)) {
  56. // TRANS: Client error displayed requesting most recent notices for a non-existing user.
  57. $this->clientError(_('No such user.'), 404);
  58. }
  59. // if (!$this->target->isLocal()) {
  60. // $this->serverError(_('Remote user timelines are not available here yet.'), 501);
  61. // }
  62. $this->notices = $this->getNotices();
  63. return true;
  64. }
  65. /**
  66. * Handle the request
  67. *
  68. * Just show the notices
  69. *
  70. * @return void
  71. */
  72. protected function handle()
  73. {
  74. parent::handle();
  75. $this->showTimeline();
  76. }
  77. /**
  78. * Show the timeline of notices
  79. *
  80. * @return void
  81. */
  82. function showTimeline()
  83. {
  84. $this->showJsonTimeline($this->notices);
  85. }
  86. /**
  87. * Get notices
  88. *
  89. * @return array notices
  90. */
  91. function getNotices()
  92. {
  93. $notices = array();
  94. $notice = $this->target->getNotices(($this->page-1) * $this->count,
  95. $this->count + 1,
  96. $this->since_id,
  97. $this->max_id,
  98. $this->scoped);
  99. while ($notice->fetch()) {
  100. if (count($notices) < $this->count) {
  101. $notices[] = clone($notice);
  102. } else {
  103. $this->next_id = $notice->id;
  104. break;
  105. }
  106. }
  107. return $notices;
  108. }
  109. /**
  110. * We expose AtomPub here, so non-GET/HEAD reqs must be read/write.
  111. *
  112. * @param array $args other arguments
  113. *
  114. * @return boolean true
  115. */
  116. function isReadOnly($args)
  117. {
  118. return true;
  119. }
  120. /**
  121. * When was this feed last modified?
  122. *
  123. * @return string datestamp of the latest notice in the stream
  124. */
  125. function lastModified()
  126. {
  127. if (!empty($this->notices) && (count($this->notices) > 0)) {
  128. return strtotime($this->notices[0]->created);
  129. }
  130. return null;
  131. }
  132. /**
  133. * An entity tag for this stream
  134. *
  135. * Returns an Etag based on the action name, language, user ID, and
  136. * timestamps of the first and last notice in the timeline
  137. *
  138. * @return string etag
  139. */
  140. function etag()
  141. {
  142. if (!empty($this->notices) && (count($this->notices) > 0)) {
  143. $last = count($this->notices) - 1;
  144. return '"' . implode(
  145. ':',
  146. array($this->arg('action'),
  147. common_user_cache_hash($this->scoped),
  148. common_language(),
  149. $this->target->getID(),
  150. strtotime($this->notices[0]->created),
  151. strtotime($this->notices[$last]->created))
  152. )
  153. . '"';
  154. }
  155. return null;
  156. }
  157. }