3 * StatusNet, the distributed open-source microblogging tool
5 * Show a list's notices
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.
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.
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/>.
24 * @author Craig Andrews <candrews@integralblue.com>
25 * @author Evan Prodromou <evan@status.net>
26 * @author Jeffery To <jeffery.to@gmail.com>
27 * @author Zach Copley <zach@status.net>
28 * @copyright 2009 StatusNet, Inc.
29 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
30 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
31 * @link http://status.net/
34 if (!defined('STATUSNET')) {
38 require_once INSTALLDIR . '/lib/atomlistnoticefeed.php';
41 * Returns the most recent notices (default 20) posted to the list specified by ID
45 * @author Craig Andrews <candrews@integralblue.com>
46 * @author Evan Prodromou <evan@status.net>
47 * @author Jeffery To <jeffery.to@gmail.com>
48 * @author Zach Copley <zach@status.net>
49 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
50 * @link http://status.net/
52 class ApiTimelineListAction extends ApiPrivateAuthAction
56 var $notices = array();
62 * Take arguments for running
64 * @param array $args $_REQUEST args
66 * @return boolean success flag
69 protected function prepare($args)
71 parent::prepare($args);
73 $this->cursor = (int) $this->arg('cursor', -1);
74 $this->list = $this->getTargetList($this->arg('user'), $this->arg('id'));
82 * Just show the notices
86 protected function handle()
90 if (empty($this->list)) {
91 // TRANS: Client error displayed trying to perform an action related to a non-existing list.
92 $this->clientError(_('List not found.'), 404);
96 $this->showTimeline();
100 * Show the timeline of notices
104 function showTimeline()
106 // We'll pull common formatting out of this for other formats
107 $atom = new AtomListNoticeFeed($this->list, $this->auth_user);
109 $self = $this->getSelfUri();
111 switch($this->format) {
113 $this->initDocument('xml');
114 $this->elementStart('statuses_list',
115 array('xmlns:statusnet' => 'http://status.net/schema/api/1/'));
116 $this->elementStart('statuses', array('type' => 'array'));
118 foreach ($this->notices as $n) {
119 $twitter_status = $this->twitterStatusArray($n);
120 $this->showTwitterXmlStatus($twitter_status);
123 $this->elementEnd('statuses');
124 $this->element('next_cursor', null, $this->next_cursor);
125 $this->element('previous_cursor', null, $this->prev_cursor);
126 $this->elementEnd('statuses_list');
127 $this->endDocument('xml');
130 $this->showRssTimeline(
133 $this->list->getUri(),
141 header('Content-Type: application/atom+xml; charset=utf-8');
145 $atom->setSelfLink($self);
146 $atom->addEntryFromNotices($this->notices);
147 $this->raw($atom->getString());
148 } catch (Atom10FeedException $e) {
149 // TRANS: Server error displayed whe trying to get a timeline fails.
150 // TRANS: %s is the error message.
151 $this->serverError(sprintf(_('Could not generate feed for list - %s'), $e->getMessage()));
156 $this->initDocument('json');
159 foreach ($this->notices as $n) {
160 $twitter_status = $this->twitterStatusArray($n);
161 array_push($statuses, $twitter_status);
164 $statuses_list = array('statuses' => $statuses,
165 'next_cursor' => $this->next_cusror,
166 'next_cursor_str' => strval($this->next_cusror),
167 'previous_cursor' => $this->prev_cusror,
168 'previous_cursor_str' => strval($this->prev_cusror)
170 $this->showJsonObjects($statuses_list);
172 $this->initDocument('json');
175 // TRANS: Client error displayed when coming across a non-supported API method.
176 $this->clientError(_('API method not found.'), 404);
183 * @return array notices
185 function getNotices()
187 $fn = array($this->list, 'getNotices');
188 list($this->notices, $this->next_cursor, $this->prev_cursor) =
189 Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
190 if (!$this->notices) {
191 $this->notices = array();
196 * Is this action read only?
198 * @param array $args other arguments
200 * @return boolean true
202 function isReadOnly($args)
208 * When was this feed last modified?
210 * @return string datestamp of the latest notice in the stream
212 function lastModified()
214 if (!empty($this->notices) && (count($this->notices) > 0)) {
215 return strtotime($this->notices[0]->created);
222 * An entity tag for this stream
224 * Returns an Etag based on the action name, language, list ID and
225 * timestamps of the first and last notice in the timeline
227 * @return string etag
231 if (!empty($this->notices) && (count($this->notices) > 0)) {
233 $last = count($this->notices) - 1;
235 return '"' . implode(
237 array($this->arg('action'),
240 strtotime($this->notices[0]->created),
241 strtotime($this->notices[$last]->created))