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 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
84 * @param array $args $_REQUEST data (unused)
88 function handle($args)
90 parent::handle($args);
92 if (empty($this->list)) {
93 // TRANS: Client error displayed trying to perform an action related to a non-existing list.
94 $this->clientError(_('List not found.'), 404, $this->format);
99 $this->showTimeline();
103 * Show the timeline of notices
107 function showTimeline()
109 // We'll pull common formatting out of this for other formats
110 $atom = new AtomListNoticeFeed($this->list, $this->auth_user);
112 $self = $this->getSelfUri();
114 switch($this->format) {
116 $this->initDocument('xml');
117 $this->elementStart('statuses_list',
118 array('xmlns:statusnet' => 'http://status.net/schema/api/1/'));
119 $this->elementStart('statuses', array('type' => 'array'));
121 foreach ($this->notices as $n) {
122 $twitter_status = $this->twitterStatusArray($n);
123 $this->showTwitterXmlStatus($twitter_status);
126 $this->elementEnd('statuses');
127 $this->element('next_cursor', null, $this->next_cursor);
128 $this->element('previous_cursor', null, $this->prev_cursor);
129 $this->elementEnd('statuses_list');
130 $this->endDocument('xml');
133 $this->showRssTimeline(
136 $this->list->getUri(),
144 header('Content-Type: application/atom+xml; charset=utf-8');
148 $atom->setSelfLink($self);
149 $atom->addEntryFromNotices($this->notices);
150 $this->raw($atom->getString());
151 } catch (Atom10FeedException $e) {
152 // TRANS: Server error displayed whe trying to get a timeline fails.
153 // TRANS: %s is the error message.
154 $this->serverError( sprintf(_('Could not generate feed for list - %s'),$e->getMessage()));
160 $this->initDocument('json');
163 foreach ($this->notices as $n) {
164 $twitter_status = $this->twitterStatusArray($n);
165 array_push($statuses, $twitter_status);
168 $statuses_list = array('statuses' => $statuses,
169 'next_cursor' => $this->next_cusror,
170 'next_cursor_str' => strval($this->next_cusror),
171 'previous_cursor' => $this->prev_cusror,
172 'previous_cursor_str' => strval($this->prev_cusror)
174 $this->showJsonObjects($statuses_list);
176 $this->initDocument('json');
180 // TRANS: Client error displayed when coming across a non-supported API method.
181 _('API method not found.'),
192 * @return array notices
194 function getNotices()
196 $fn = array($this->list, 'getNotices');
197 list($this->notices, $this->next_cursor, $this->prev_cursor) =
198 Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
199 if (!$this->notices) {
200 $this->notices = array();
205 * Is this action read only?
207 * @param array $args other arguments
209 * @return boolean true
211 function isReadOnly($args)
217 * When was this feed last modified?
219 * @return string datestamp of the latest notice in the stream
221 function lastModified()
223 if (!empty($this->notices) && (count($this->notices) > 0)) {
224 return strtotime($this->notices[0]->created);
231 * An entity tag for this stream
233 * Returns an Etag based on the action name, language, list ID and
234 * timestamps of the first and last notice in the timeline
236 * @return string etag
240 if (!empty($this->notices) && (count($this->notices) > 0)) {
242 $last = count($this->notices) - 1;
244 return '"' . implode(
246 array($this->arg('action'),
249 strtotime($this->notices[0]->created),
250 strtotime($this->notices[$last]->created))