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';
37 * Returns the most recent notices (default 20) posted by the target user.
38 * This is the equivalent of 'You and friends' page accessed via Web.
42 * @author Zach Copley <zach@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
47 class ApiTimelineFriendsAction extends ApiBareAuthAction
52 * Take arguments for running
54 * @param array $args $_REQUEST args
56 * @return boolean success flag
60 function prepare($args)
62 parent::prepare($args);
64 $this->user = $this->getTargetUser($this->arg('id'));
66 if (empty($this->user)) {
67 $this->clientError(_('No such user!'), 404, $this->format);
71 $this->notices = $this->getNotices();
79 * Just show the notices
81 * @param array $args $_REQUEST data (unused)
86 function handle($args)
88 parent::handle($args);
89 $this->showTimeline();
93 * Show the timeline of notices
98 function showTimeline()
100 $profile = $this->user->getProfile();
101 $sitename = common_config('site', 'name');
102 $title = sprintf(_("%s and friends"), $this->user->nickname);
103 $taguribase = common_config('integration', 'taguri');
104 $id = "tag:$taguribase:FriendsTimeline:" . $this->user->id;
105 $link = common_local_url(
106 'all', array('nickname' => $this->user->nickname)
109 _('Updates from %1$s and friends on %2$s!'),
110 $this->user->nickname, $sitename
113 switch($this->format) {
115 $this->showXmlTimeline($this->notices);
118 $this->showRssTimeline($this->notices, $title, $link, $subtitle);
122 $target_id = $this->arg('id');
124 if (isset($target_id)) {
125 $selfuri = common_root_url() .
126 'api/statuses/friends_timeline/' .
127 $target_id . '.atom';
129 $selfuri = common_root_url() .
130 'api/statuses/friends_timeline.atom';
133 $this->showAtomTimeline(
134 $this->notices, $title, $id, $link,
135 $subtitle, null, $selfuri
139 $this->showJsonTimeline($this->notices);
142 $this->clientError(_('API method not found!'), $code = 404);
150 * @return array notices
153 function getNotices()
157 if (!empty($this->auth_user) && $this->auth_user->id == $this->user->id) {
158 $notice = $this->user->noticeInbox(
159 ($this->page-1) * $this->count,
160 $this->count, $this->since_id,
161 $this->max_id, $this->since
164 $notice = $this->user->noticesWithFriends(
165 ($this->page-1) * $this->count,
166 $this->count, $this->since_id,
167 $this->max_id, $this->since
171 while ($notice->fetch()) {
172 $notices[] = clone($notice);
179 * Is this action read only?
181 * @param array $args other arguments
183 * @return boolean true
186 function isReadOnly($args)
192 * When was this feed last modified?
194 * @return string datestamp of the latest notice in the stream
197 function lastModified()
199 if (!empty($this->notices) && (count($this->notices) > 0)) {
200 return strtotime($this->notices[0]->created);
207 * An entity tag for this stream
209 * Returns an Etag based on the action name, language, user ID, and
210 * timestamps of the first and last notice in the timeline
212 * @return string etag
217 if (!empty($this->notices) && (count($this->notices) > 0)) {
219 $last = count($this->notices) - 1;
221 return '"' . implode(
223 array($this->arg('action'),
226 strtotime($this->notices[0]->created),
227 strtotime($this->notices[$last]->created))