3 * StatusNet, the distributed open-source microblogging tool
5 * Show a user's favorite notices
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 20 most recent favorite notices for the authenticating user or user
38 * specified by the ID parameter in the requested format.
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 ApiTimelineFavoritesAction 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();
102 $sitename = common_config('site', 'name');
104 _('%s / Favorites from %s'),
106 $this->user->nickname
109 $taguribase = common_config('integration', 'taguri');
110 $id = "tag:$taguribase:Favorites:" . $this->user->id;
111 $link = common_local_url(
113 array('nickname' => $this->user->nickname)
116 _('%s updates favorited by %s / %s.'),
118 $profile->getBestName(),
119 $this->user->nickname
122 switch($this->format) {
124 $this->show_xml_timeline($this->notices);
127 $this->show_rss_timeline($this->notices, $title, $link, $subtitle);
130 $selfuri = common_root_url() .
131 ltrim($_SERVER['QUERY_STRING'], 'p=');
132 $this->show_atom_timeline(
133 $this->notices, $title, $id, $link, $subtitle,
138 $this->show_json_timeline($this->notices);
141 $this->clientError(_('API method not found!'), $code = 404);
149 * @return array notices
152 function getNotices()
156 if (!empty($this->auth_user) && $this->auth_user->id == $this->user->id) {
157 $notice = $this->user->favoriteNotices(
158 ($this->page-1) * $this->count,
163 $notice = $this->user->favoriteNotices(
164 ($this->page-1) * $this->count,
170 while ($notice->fetch()) {
171 $notices[] = clone($notice);
178 * Is this action read only?
180 * @param array $args other arguments
182 * @return boolean true
185 function isReadOnly($args)
191 * When was this feed last modified?
193 * @return string datestamp of the latest notice in the stream
196 function lastModified()
198 if (!empty($this->notices) && (count($this->notices) > 0)) {
199 return strtotime($this->notices[0]->created);
206 * An entity tag for this stream
208 * Returns an Etag based on the action name, language, user ID, and
209 * timestamps of the first and last notice in the timeline
211 * @return string etag
216 if (!empty($this->notices) && (count($this->notices) > 0)) {
218 $last = count($this->notices) - 1;
220 return '"' . implode(
222 array($this->arg('action'),
225 strtotime($this->notices[0]->created),
226 strtotime($this->notices[$last]->created))