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/
61 class ApiTimelineUserAction extends ApiBareAuthAction
67 * Take arguments for running
69 * @param array $args $_REQUEST args
71 * @return boolean success flag
75 function prepare($args)
77 parent::prepare($args);
79 $this->user = $this->getTargetUser($this->arg('id'));
81 if (empty($this->user)) {
82 $this->clientError(_('No such user.'), 404, $this->format);
86 $this->notices = $this->getNotices();
94 * Just show the notices
96 * @param array $args $_REQUEST data (unused)
101 function handle($args)
103 parent::handle($args);
104 $this->showTimeline();
108 * Show the timeline of notices
113 function showTimeline()
115 $profile = $this->user->getProfile();
117 // We'll use the shared params from the Atom stub
118 // for other feed types.
119 $atom = new AtomUserNoticeFeed($this->user, $this->auth_user);
121 $link = common_local_url(
123 array('nickname' => $this->user->nickname)
126 $self = $this->getSelfUri();
128 // FriendFeed's SUP protocol
129 // Also added RSS and Atom feeds
131 $suplink = common_local_url('sup', null, null, $this->user->id);
132 header('X-SUP-ID: ' . $suplink);
134 switch($this->format) {
136 $this->showXmlTimeline($this->notices);
139 $this->showRssTimeline(
151 header('Content-Type: application/atom+xml; charset=utf-8');
154 $atom->setSelfLink($self);
155 $atom->addEntryFromNotices($this->notices);
156 $this->raw($atom->getString());
160 $this->showJsonTimeline($this->notices);
163 $this->clientError(_('API method not found.'), $code = 404);
172 * @return array notices
175 function getNotices()
179 $notice = $this->user->getNotices(
180 ($this->page-1) * $this->count, $this->count,
181 $this->since_id, $this->max_id
184 while ($notice->fetch()) {
185 $notices[] = clone($notice);
192 * Is this action read only?
194 * @param array $args other arguments
196 * @return boolean true
199 function isReadOnly($args)
205 * When was this feed last modified?
207 * @return string datestamp of the latest notice in the stream
210 function lastModified()
212 if (!empty($this->notices) && (count($this->notices) > 0)) {
213 return strtotime($this->notices[0]->created);
220 * An entity tag for this stream
222 * Returns an Etag based on the action name, language, user ID, and
223 * timestamps of the first and last notice in the timeline
225 * @return string etag
230 if (!empty($this->notices) && (count($this->notices) > 0)) {
232 $last = count($this->notices) - 1;
234 return '"' . implode(
236 array($this->arg('action'),
239 strtotime($this->notices[0]->created),
240 strtotime($this->notices[$last]->created))