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/
53 class ApiTimelineListAction extends ApiPrivateAuthAction
57 var $notices = array();
63 * Take arguments for running
65 * @param array $args $_REQUEST args
67 * @return boolean success flag
70 function prepare($args)
72 parent::prepare($args);
74 $this->cursor = (int) $this->arg('cursor', -1);
75 $this->list = $this->getTargetList($this->arg('user'), $this->arg('id'));
83 * Just show the notices
85 * @param array $args $_REQUEST data (unused)
89 function handle($args)
91 parent::handle($args);
93 if (empty($this->list)) {
94 // TRANS: Client error displayed trying to perform an action related to a non-existing list.
95 $this->clientError(_('List not found.'), 404, $this->format);
100 $this->showTimeline();
104 * Show the timeline of notices
108 function showTimeline()
110 // We'll pull common formatting out of this for other formats
111 $atom = new AtomListNoticeFeed($this->list, $this->auth_user);
113 $self = $this->getSelfUri();
115 switch($this->format) {
117 $this->initDocument('xml');
118 $this->elementStart('statuses_list',
119 array('xmlns:statusnet' => 'http://status.net/schema/api/1/'));
120 $this->elementStart('statuses', array('type' => 'array'));
122 foreach ($this->notices as $n) {
123 $twitter_status = $this->twitterStatusArray($n);
124 $this->showTwitterXmlStatus($twitter_status);
127 $this->elementEnd('statuses');
128 $this->element('next_cursor', null, $this->next_cursor);
129 $this->element('previous_cursor', null, $this->prev_cursor);
130 $this->elementEnd('statuses_list');
131 $this->endDocument('xml');
134 $this->showRssTimeline(
137 $this->list->getUri(),
145 header('Content-Type: application/atom+xml; charset=utf-8');
149 $atom->setSelfLink($self);
150 $atom->addEntryFromNotices($this->notices);
151 $this->raw($atom->getString());
152 } catch (Atom10FeedException $e) {
153 // TRANS: Server error displayed whe trying to get a timeline fails.
154 // TRANS: %s is the error message.
155 $this->serverError( sprintf(_('Could not generate feed for list - %s'),$e->getMessage()));
161 $this->initDocument('json');
164 foreach ($this->notices as $n) {
165 $twitter_status = $this->twitterStatusArray($n);
166 array_push($statuses, $twitter_status);
169 $statuses_list = array('statuses' => $statuses,
170 'next_cursor' => $this->next_cusror,
171 'next_cursor_str' => strval($this->next_cusror),
172 'previous_cursor' => $this->prev_cusror,
173 'previous_cursor_str' => strval($this->prev_cusror)
175 $this->showJsonObjects($statuses_list);
177 $this->initDocument('json');
181 // TRANS: Client error displayed when coming across a non-supported API method.
182 _('API method not found.'),
193 * @return array notices
195 function getNotices()
197 $fn = array($this->list, 'getNotices');
198 list($this->notices, $this->next_cursor, $this->prev_cursor) =
199 Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
200 if (!$this->notices) {
201 $this->notices = array();
206 * Is this action read only?
208 * @param array $args other arguments
210 * @return boolean true
212 function isReadOnly($args)
218 * When was this feed last modified?
220 * @return string datestamp of the latest notice in the stream
222 function lastModified()
224 if (!empty($this->notices) && (count($this->notices) > 0)) {
225 return strtotime($this->notices[0]->created);
232 * An entity tag for this stream
234 * Returns an Etag based on the action name, language, list ID and
235 * timestamps of the first and last notice in the timeline
237 * @return string etag
241 if (!empty($this->notices) && (count($this->notices) > 0)) {
243 $last = count($this->notices) - 1;
245 return '"' . implode(
247 array($this->arg('action'),
250 strtotime($this->notices[0]->created),
251 strtotime($this->notices[$last]->created))