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();
79 function handle($args) {
80 parent::handle($args);
81 $this->showTimeline();
84 function showTimeline()
86 $profile = $this->user->getProfile();
87 $sitename = common_config('site', 'name');
88 $title = sprintf(_("%s and friends"), $user->nickname);
89 $taguribase = common_config('integration', 'taguri');
90 $id = "tag:$taguribase:FriendsTimeline:" . $user->id;
91 $link = common_local_url('all',
92 array('nickname' => $user->nickname));
93 $subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'),
94 $user->nickname, $sitename);
96 switch($this->arg('format')) {
98 $this->show_xml_timeline($this->notices);
101 $this->show_rss_timeline($this->notices, $title, $link, $subtitle);
105 $target_id = $this->arg('id');
107 if (isset($target_id)) {
108 $selfuri = common_root_url() .
109 'api/statuses/friends_timeline/' .
110 $target_id . '.atom';
112 $selfuri = common_root_url() .
113 'api/statuses/friends_timeline.atom';
115 $this->show_atom_timeline($this->notices, $title, $id, $link,
116 $subtitle, null, $selfuri);
119 $this->show_json_timeline($this->notices);
122 $this->clientError(_('API method not found!'), $code = 404);
127 function getNotices()
131 if (!empty($this->auth_user) && $this->auth_user->id == $this->user->id) {
132 $notice = $this->user->noticeInbox(($this->page-1) * $this->count,
133 $this->count, $this->since_id,
134 $this->max_id, $this->since);
136 $notice = $this->user->noticesWithFriends(($this->page-1) * $this->count,
137 $this->count, $this->since_id,
138 $this->max_id, $this->since);
141 while ($notice->fetch()) {
142 $notices[] = clone($notice);
149 * Is this page read-only?
151 * @return boolean true
154 function isReadOnly($args)
160 * When was this feed last modified?
164 function lastModified()
166 if (empty($this->notices)) {
170 if (count($this->notices) == 0) {
174 return strtotime($this->notices[0]->created);