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 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
33 * @link http://status.net/
36 if (!defined('STATUSNET')) {
40 require_once INSTALLDIR . '/lib/apibareauth.php';
43 * Returns the most recent notices (default 20) posted by the authenticating
44 * user. Another user's timeline can be requested via the id parameter. This
45 * is the API equivalent of the user profile web page.
49 * @author Craig Andrews <candrews@integralblue.com>
50 * @author Evan Prodromou <evan@status.net>
51 * @author Jeffery To <jeffery.to@gmail.com>
52 * @author mac65 <mac65@mac65.com>
53 * @author Mike Cochrane <mikec@mikenz.geek.nz>
54 * @author Robin Millette <robin@millette.info>
55 * @author Zach Copley <zach@status.net>
56 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
57 * @link http://status.net/
60 class ApiTimelineUserAction extends ApiBareAuthAction
66 * Take arguments for running
68 * @param array $args $_REQUEST args
70 * @return boolean success flag
74 function prepare($args)
76 parent::prepare($args);
78 $this->user = $this->getTargetUser($this->arg('id'));
80 if (empty($this->user)) {
81 $this->clientError(_('No such user.'), 404, $this->format);
85 $this->notices = $this->getNotices();
93 * Just show the notices
95 * @param array $args $_REQUEST data (unused)
100 function handle($args)
102 parent::handle($args);
103 $this->showTimeline();
107 * Show the timeline of notices
112 function showTimeline()
114 $profile = $this->user->getProfile();
115 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
117 $sitename = common_config('site', 'name');
118 $title = sprintf(_("%s timeline"), $this->user->nickname);
119 $link = common_local_url(
121 array('nickname' => $this->user->nickname)
124 _('Updates from %1$s on %2$s!'),
125 $this->user->nickname, $sitename
127 $logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
129 // FriendFeed's SUP protocol
130 // Also added RSS and Atom feeds
132 $suplink = common_local_url('sup', null, null, $this->user->id);
133 header('X-SUP-ID: ' . $suplink);
135 switch($this->format) {
137 $this->showXmlTimeline($this->notices);
140 $this->showRssTimeline(
141 $this->notices, $title, $link,
142 $subtitle, $suplink, $logo
147 header('Content-Type: application/atom+xml; charset=utf-8');
149 // @todo set all this Atom junk up inside the feed class
151 $atom = new AtomUserNoticeFeed($this->user);
153 $atom->setTitle($title);
154 $atom->setSubtitle($subtitle);
155 $atom->setLogo($logo);
156 $atom->setUpdated('now');
161 array('nickname' => $this->user->nickname)
165 $id = $this->arg('id');
166 $aargs = array('format' => 'atom');
171 $atom->setId($this->getSelfUri('ApiTimelineUser', $aargs));
174 $this->getSelfUri('ApiTimelineUser', $aargs),
175 array('rel' => 'self', 'type' => 'application/atom+xml')
181 'rel' => 'http://api.friendfeed.com/2008/03#sup',
182 'type' => 'application/json'
186 $atom->addEntryFromNotices($this->notices);
188 #$this->raw($atom->getString());
189 print $atom->getString(); // temporary for output buffering
193 $this->showJsonTimeline($this->notices);
196 $this->clientError(_('API method not found.'), $code = 404);
205 * @return array notices
208 function getNotices()
212 $notice = $this->user->getNotices(
213 ($this->page-1) * $this->count, $this->count,
214 $this->since_id, $this->max_id, $this->since
217 while ($notice->fetch()) {
218 $notices[] = clone($notice);
225 * Is this action read only?
227 * @param array $args other arguments
229 * @return boolean true
232 function isReadOnly($args)
238 * When was this feed last modified?
240 * @return string datestamp of the latest notice in the stream
243 function lastModified()
245 if (!empty($this->notices) && (count($this->notices) > 0)) {
246 return strtotime($this->notices[0]->created);
253 * An entity tag for this stream
255 * Returns an Etag based on the action name, language, user ID, and
256 * timestamps of the first and last notice in the timeline
258 * @return string etag
263 if (!empty($this->notices) && (count($this->notices) > 0)) {
265 $last = count($this->notices) - 1;
267 return '"' . implode(
269 array($this->arg('action'),
272 strtotime($this->notices[0]->created),
273 strtotime($this->notices[$last]->created))