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/apiprivateauth.php';
39 require_once INSTALLDIR . '/lib/atomlistnoticefeed.php';
42 * Returns the most recent notices (default 20) posted to the list specified by ID
46 * @author Craig Andrews <candrews@integralblue.com>
47 * @author Evan Prodromou <evan@status.net>
48 * @author Jeffery To <jeffery.to@gmail.com>
49 * @author Zach Copley <zach@status.net>
50 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
51 * @link http://status.net/
54 class ApiTimelineListAction extends ApiPrivateAuthAction
58 var $notices = array();
64 * Take arguments for running
66 * @param array $args $_REQUEST args
68 * @return boolean success flag
72 function prepare($args)
74 parent::prepare($args);
76 $this->cursor = (int) $this->arg('cursor', -1);
77 $this->list = $this->getTargetList($this->arg('user'), $this->arg('id'));
85 * Just show the notices
87 * @param array $args $_REQUEST data (unused)
92 function handle($args)
94 parent::handle($args);
96 if (empty($this->list)) {
97 $this->clientError(_('List not found.'), 404, $this->format);
102 $this->showTimeline();
106 * Show the timeline of notices
111 function showTimeline()
113 // We'll pull common formatting out of this for other formats
114 $atom = new AtomListNoticeFeed($this->list, $this->auth_user);
116 $self = $this->getSelfUri();
118 switch($this->format) {
120 $this->initDocument('xml');
121 $this->elementStart('statuses_list',
122 array('xmlns:statusnet' => 'http://status.net/schema/api/1/'));
123 $this->elementStart('statuses', array('type' => 'array'));
125 foreach ($this->notices as $n) {
126 $twitter_status = $this->twitterStatusArray($n);
127 $this->showTwitterXmlStatus($twitter_status);
130 $this->elementEnd('statuses');
131 $this->element('next_cursor', null, $this->next_cursor);
132 $this->element('previous_cursor', null, $this->prev_cursor);
133 $this->elementEnd('statuses_list');
134 $this->endDocument('xml');
137 $this->showRssTimeline(
140 $this->list->getUri(),
149 header('Content-Type: application/atom+xml; charset=utf-8');
153 $atom->setSelfLink($self);
154 $atom->addEntryFromNotices($this->notices);
155 $this->raw($atom->getString());
156 } catch (Atom10FeedException $e) {
158 'Could not generate feed for list - ' . $e->getMessage()
165 $this->initDocument('json');
168 foreach ($this->notices as $n) {
169 $twitter_status = $this->twitterStatusArray($n);
170 array_push($statuses, $twitter_status);
173 $statuses_list = array('statuses' => $statuses,
174 'next_cursor' => $this->next_cusror,
175 'next_cursor_str' => strval($this->next_cusror),
176 'previous_cursor' => $this->prev_cusror,
177 'previous_cursor_str' => strval($this->prev_cusror)
179 $this->showJsonObjects($statuses_list);
181 $this->initDocument('json');
185 _('API method not found.'),
196 * @return array notices
199 function getNotices()
201 $fn = array($this->list, 'getNotices');
202 list($this->notices, $this->next_cursor, $this->prev_cursor) =
203 Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
204 if (!$this->notices) {
205 $this->notices = array();
210 * Is this action read only?
212 * @param array $args other arguments
214 * @return boolean true
217 function isReadOnly($args)
223 * When was this feed last modified?
225 * @return string datestamp of the latest notice in the stream
228 function lastModified()
230 if (!empty($this->notices) && (count($this->notices) > 0)) {
231 return strtotime($this->notices[0]->created);
238 * An entity tag for this stream
240 * Returns an Etag based on the action name, language, list ID and
241 * timestamps of the first and last notice in the timeline
243 * @return string etag
248 if (!empty($this->notices) && (count($this->notices) > 0)) {
250 $last = count($this->notices) - 1;
252 return '"' . implode(
254 array($this->arg('action'),
257 strtotime($this->notices[0]->created),
258 strtotime($this->notices[$last]->created))