3 * StatusNet, the distributed open-source microblogging tool
5 * Show a user's timeline
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 mac65 <mac65@mac65.com>
28 * @author Mike Cochrane <mikec@mikenz.geek.nz>
29 * @author Robin Millette <robin@millette.info>
30 * @author Zach Copley <zach@status.net>
31 * @copyright 2009 StatusNet, Inc.
32 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
33 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
34 * @link http://status.net/
37 if (!defined('STATUSNET')) {
41 require_once INSTALLDIR . '/lib/apibareauth.php';
44 * Returns the most recent notices (default 20) posted by the authenticating
45 * user. Another user's timeline can be requested via the id parameter. This
46 * is the API equivalent of the user profile web page.
50 * @author Craig Andrews <candrews@integralblue.com>
51 * @author Evan Prodromou <evan@status.net>
52 * @author Jeffery To <jeffery.to@gmail.com>
53 * @author mac65 <mac65@mac65.com>
54 * @author Mike Cochrane <mikec@mikenz.geek.nz>
55 * @author Robin Millette <robin@millette.info>
56 * @author Zach Copley <zach@status.net>
57 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
58 * @link http://status.net/
60 class ApiTimelineUserAction extends ApiBareAuthAction
65 * Take arguments for running
67 * @param array $args $_REQUEST args
69 * @return boolean success flag
71 function prepare($args)
73 parent::prepare($args);
75 $this->user = $this->getTargetUser($this->arg('id'));
77 if (empty($this->user)) {
78 // TRANS: Client error displayed requesting most recent notices for a non-existing user.
79 $this->clientError(_('No such user.'), 404, $this->format);
83 $this->notices = $this->getNotices();
91 * Just show the notices
93 * @param array $args $_REQUEST data (unused)
97 function handle($args)
99 parent::handle($args);
100 $this->showTimeline();
104 * Show the timeline of notices
108 function showTimeline()
110 $profile = $this->user->getProfile();
112 // We'll use the shared params from the Atom stub
113 // for other feed types.
114 $atom = new AtomUserNoticeFeed($this->user, $this->auth_user);
116 $link = common_local_url(
118 array('nickname' => $this->user->nickname)
121 $self = $this->getSelfUri();
123 // FriendFeed's SUP protocol
124 // Also added RSS and Atom feeds
126 $suplink = common_local_url('sup', null, null, $this->user->id);
127 header('X-SUP-ID: ' . $suplink);
129 switch($this->format) {
131 $this->showXmlTimeline($this->notices);
134 $this->showRssTimeline(
145 header('Content-Type: application/atom+xml; charset=utf-8');
148 $atom->setSelfLink($self);
149 $atom->addEntryFromNotices($this->notices);
150 $this->raw($atom->getString());
154 $this->showJsonTimeline($this->notices);
157 // TRANS: Client error displayed when trying to handle an unknown API method.
158 $this->clientError(_('API method not found.'), $code = 404);
166 * @return array notices
168 function getNotices()
172 $notice = $this->user->getNotices(
173 ($this->page-1) * $this->count, $this->count,
174 $this->since_id, $this->max_id
177 while ($notice->fetch()) {
178 $notices[] = clone($notice);
185 * Is this action read only?
187 * @param array $args other arguments
189 * @return boolean true
191 function isReadOnly($args)
197 * When was this feed last modified?
199 * @return string datestamp of the latest notice in the stream
201 function lastModified()
203 if (!empty($this->notices) && (count($this->notices) > 0)) {
204 return strtotime($this->notices[0]->created);
211 * An entity tag for this stream
213 * Returns an Etag based on the action name, language, user ID, and
214 * timestamps of the first and last notice in the timeline
216 * @return string etag
220 if (!empty($this->notices) && (count($this->notices) > 0)) {
221 $last = count($this->notices) - 1;
223 return '"' . implode(
225 array($this->arg('action'),
226 common_user_cache_hash($this->auth_user),
229 strtotime($this->notices[0]->created),
230 strtotime($this->notices[$last]->created))