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 Craig Andrews <candrews@integralblue.com>
25 * @author Evan Prodromou <evan@status.net>
26 * @author Zach Copley <zach@status.net>
27 * @copyright 2009-2010 StatusNet, Inc.
28 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
29 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
30 * @link http://status.net/
33 if (!defined('STATUSNET')) {
38 * Returns the 20 most recent favorite notices for the authenticating user or user
39 * specified by the ID parameter in the requested format.
43 * @author Craig Andrews <candrews@integralblue.com>
44 * @author Evan Prodromou <evan@status.net>
45 * @author Zach Copley <zach@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://status.net/
49 class ApiTimelineFavoritesAction extends ApiBareAuthAction
54 * Take arguments for running
56 * @param array $args $_REQUEST args
58 * @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 // TRANS: Client error displayed when requesting most recent favourite notices by a user for a non-existing user.
68 $this->clientError(_('No such user.'), 404, $this->format);
72 $this->notices = $this->getNotices();
80 * Just show the notices
82 * @param array $args $_REQUEST data (unused)
86 function handle($args)
88 parent::handle($args);
89 $this->showTimeline();
93 * Show the timeline of notices
97 function showTimeline()
99 $profile = $this->user->getProfile();
101 $sitename = common_config('site', 'name');
103 // TRANS: Title for timeline of most recent favourite notices by a user.
104 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
105 _('%1$s / Favorites from %2$s'),
107 $this->user->nickname
110 $taguribase = TagURI::base();
111 $id = "tag:$taguribase:Favorites:" . $this->user->id;
114 // TRANS: Subtitle for timeline of most recent favourite notices by a user.
115 // TRANS: %1$s is the StatusNet sitename, %2$s is a user's full name,
116 // TRANS: %3$s is a user nickname.
117 _('%1$s updates favorited by %2$s / %3$s.'),
119 $profile->getBestName(),
120 $this->user->nickname
123 $logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
124 $link = common_local_url('showfavorites',
125 array('nickname' => $this->user->nickname));
126 $self = $this->getSelfUri();
128 switch($this->format) {
130 $this->showXmlTimeline($this->notices);
133 $this->showRssTimeline(
144 header('Content-Type: application/atom+xml; charset=utf-8');
146 $atom = new AtomNoticeFeed($this->auth_user);
149 $atom->setTitle($title);
150 $atom->setSubtitle($subtitle);
151 $atom->setLogo($logo);
152 $atom->setUpdated('now');
154 $atom->addLink($link);
155 $atom->setSelfLink($self);
157 $atom->addEntryFromNotices($this->notices);
159 $this->raw($atom->getString());
162 $this->showJsonTimeline($this->notices);
165 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
166 $doc = new ActivityStreamJSONDocument($this->auth_user);
167 $doc->setTitle($title);
168 $doc->addLink($link,'alternate', 'text/html');
169 $doc->addItemsFromNotices($this->notices);
170 $this->raw($doc->asString());
173 // TRANS: Client error displayed when coming across a non-supported API method.
174 $this->clientError(_('API method not found.'), $code = 404);
182 * @return array notices
184 function getNotices()
188 common_debug("since id = " . $this->since_id . " max id = " . $this->max_id);
190 if (!empty($this->auth_user) && $this->auth_user->id == $this->user->id) {
191 $notice = $this->user->favoriteNotices(
193 ($this->page-1) * $this->count,
199 $notice = $this->user->favoriteNotices(
201 ($this->page-1) * $this->count,
208 while ($notice->fetch()) {
209 $notices[] = clone($notice);
216 * Is this action read only?
218 * @param array $args other arguments
220 * @return boolean true
222 function isReadOnly($args)
228 * When was this feed last modified?
230 * @return string datestamp of the latest notice in the stream
232 function lastModified()
234 if (!empty($this->notices) && (count($this->notices) > 0)) {
235 return strtotime($this->notices[0]->created);
242 * An entity tag for this stream
244 * Returns an Etag based on the action name, language, user ID, and
245 * timestamps of the first and last notice in the timeline
247 * @return string etag
251 if (!empty($this->notices) && (count($this->notices) > 0)) {
253 $last = count($this->notices) - 1;
255 return '"' . implode(
257 array($this->arg('action'),
258 common_user_cache_hash($this->auth_user),
261 strtotime($this->notices[0]->created),
262 strtotime($this->notices[$last]->created))