3 * StatusNet, the distributed open-source microblogging tool
5 * Show the friends 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 Zach Copley <zach@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR.'/lib/apibareauth.php';
36 class ApiFriendsTimelineAction extends ApiBareAuthAction
43 * Take arguments for running
45 * @param array $args $_REQUEST args
47 * @return boolean success flag
51 function prepare($args)
53 parent::prepare($args);
55 $this->page = (int)$this->arg('page', 1);
56 $this->count = (int)$this->arg('count', 20);
57 $this->max_id = (int)$this->arg('max_id', 0);
58 $this->since_id = (int)$this->arg('since_id', 0);
59 $this->since = $this->arg('since');
61 if ($this->requiresAuth()) {
62 if ($this->checkBasicAuthUser() == false) {
67 $this->user = $this->getTargetUser($this->arg('id'));
69 if (empty($this->user)) {
70 $this->clientError(_('No such user!'), 404, $this->arg('format'));
74 $this->notices = $this->getNotices();
82 * Just show the notices
84 * @param array $args $_REQUEST data (unused)
89 function handle($args) {
90 parent::handle($args);
91 $this->showTimeline();
95 * Show the timeline of notices
100 function showTimeline()
102 $profile = $this->user->getProfile();
103 $sitename = common_config('site', 'name');
104 $title = sprintf(_("%s and friends"), $user->nickname);
105 $taguribase = common_config('integration', 'taguri');
106 $id = "tag:$taguribase:FriendsTimeline:" . $user->id;
107 $link = common_local_url('all',
108 array('nickname' => $user->nickname));
109 $subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'),
110 $user->nickname, $sitename);
112 switch($this->arg('format')) {
114 $this->show_xml_timeline($this->notices);
117 $this->show_rss_timeline($this->notices, $title, $link, $subtitle);
121 $target_id = $this->arg('id');
123 if (isset($target_id)) {
124 $selfuri = common_root_url() .
125 'api/statuses/friends_timeline/' .
126 $target_id . '.atom';
128 $selfuri = common_root_url() .
129 'api/statuses/friends_timeline.atom';
131 $this->show_atom_timeline($this->notices, $title, $id, $link,
132 $subtitle, null, $selfuri);
135 $this->show_json_timeline($this->notices);
138 $this->clientError(_('API method not found!'), $code = 404);
146 * @return array notices
149 function getNotices()
153 if (!empty($this->auth_user) && $this->auth_user->id == $this->user->id) {
154 $notice = $this->user->noticeInbox(($this->page-1) * $this->count,
155 $this->count, $this->since_id,
156 $this->max_id, $this->since);
158 $notice = $this->user->noticesWithFriends(($this->page-1) * $this->count,
159 $this->count, $this->since_id,
160 $this->max_id, $this->since);
163 while ($notice->fetch()) {
164 $notices[] = clone($notice);
171 * Is this page read-only?
173 * @return boolean true
176 function isReadOnly($args)
182 * When was this feed last modified?
186 function lastModified()
188 if (!empty($this->notices) && (count($this->notices) > 0)) {
189 return strtotime($this->notices[0]->created);
196 * An entity tag for this page
198 * Returns an Etag based on the action name, language, user ID, and
199 * timestamps of the first and last notice in the timeline
201 * @return string etag
206 if (!empty($this->notices) && (count($this->notices) > 0)) {
208 $last = count($this->notices) - 1;
211 array($this->arg('action'),
214 strtotime($this->notices[0]->created),
215 strtotime($this->notices[$last]->created))) . '"';