apiqvittertimelinelist.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
  3. · ·
  4. · ·
  5. · Q V I T T E R ·
  6. · ·
  7. · https://git.gnu.io/h2p/Qvitter ·
  8. · ·
  9. · ·
  10. · <o) ·
  11. · /_//// ·
  12. · (____/ ·
  13. · (o< ·
  14. · o> \\\\_\ ·
  15. · \\) \____) ·
  16. · ·
  17. · ·
  18. · ·
  19. · Qvitter is free software: you can redistribute it and / or modify it ·
  20. · under the terms of the GNU Affero General Public License as published by ·
  21. · the Free Software Foundation, either version three of the License or (at ·
  22. · your option) any later version. ·
  23. · ·
  24. · Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
  25. · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
  26. · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
  27. · more details. ·
  28. · ·
  29. · You should have received a copy of the GNU Affero General Public License ·
  30. · along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
  31. · ·
  32. · Contact h@nnesmannerhe.im if you have any questions. ·
  33. · ·
  34. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  35. if (!defined('STATUSNET')) {
  36. exit(1);
  37. }
  38. /**
  39. * Returns the most recent notices (default 20) in the list
  40. */
  41. class ApiQvitterTimelineListAction extends ApiBareAuthAction
  42. {
  43. var $notices = null;
  44. var $list = null;
  45. /**
  46. * Take arguments for running
  47. *
  48. * @param array $args $_REQUEST args
  49. *
  50. * @return boolean success flag
  51. *
  52. */
  53. protected function prepare(array $args=array())
  54. {
  55. parent::prepare($args);
  56. $this->format = 'json';
  57. $this->list = $this->getTargetList($this->arg('nickname'), $this->arg('id'));
  58. if (!($this->list instanceof Profile_list)) {
  59. // TRANS: Client error displayed when requesting a non existing list
  60. $this->clientError(_('List not found.'), 404);
  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->showJsonTimeline($this->notices);
  76. }
  77. /**
  78. * Get notices
  79. *
  80. * @return array notices
  81. */
  82. function getNotices()
  83. {
  84. $notices = array();
  85. $stream = new PeopletagNoticeStream($this->list);
  86. $notice = $stream->getNotices(($this->page - 1) * $this->count,
  87. $this->count,
  88. $this->since_id,
  89. $this->max_id);
  90. $notices = $notice->fetchAll();
  91. NoticeList::prefill($notices);
  92. return $notices;
  93. }
  94. /**
  95. * Is this action read only?
  96. *
  97. * @param array $args other arguments
  98. *
  99. * @return boolean true
  100. */
  101. function isReadOnly($args)
  102. {
  103. return true;
  104. }
  105. /**
  106. * When was this feed last modified?
  107. *
  108. * @return string datestamp of the latest notice in the stream
  109. */
  110. function lastModified()
  111. {
  112. if (!empty($this->notices) && (count($this->notices) > 0)) {
  113. return strtotime($this->notices[0]->created);
  114. }
  115. return null;
  116. }
  117. /**
  118. * An entity tag for this stream
  119. *
  120. * Returns an Etag based on the action name, language, and
  121. * timestamps of the first and last notice in the timeline
  122. *
  123. * @return string etag
  124. */
  125. function etag()
  126. {
  127. if (!empty($this->notices) && (count($this->notices) > 0)) {
  128. $last = count($this->notices) - 1;
  129. return '"' . implode(
  130. ':',
  131. array($this->arg('action'),
  132. common_user_cache_hash($this->auth_user),
  133. common_language(),
  134. strtotime($this->notices[0]->created),
  135. strtotime($this->notices[$last]->created))
  136. )
  137. . '"';
  138. }
  139. return null;
  140. }
  141. }