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')) {
37 require_once INSTALLDIR.'/lib/apibareauth.php';
40 * Returns the 20 most recent favorite notices for the authenticating user or user
41 * specified by the ID parameter in the requested format.
45 * @author Craig Andrews <candrews@integralblue.com>
46 * @author Evan Prodromou <evan@status.net>
47 * @author Zach Copley <zach@status.net>
48 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49 * @link http://status.net/
51 class ApiTimelineFavoritesAction extends ApiBareAuthAction
56 * Take arguments for running
58 * @param array $args $_REQUEST args
60 * @return boolean success flag
62 function prepare($args)
64 parent::prepare($args);
66 $this->user = $this->getTargetUser($this->arg('id'));
68 if (empty($this->user)) {
69 // TRANS: Client error displayed when requesting most recent favourite notices by a user for a non-existing user.
70 $this->clientError(_('No such user.'), 404, $this->format);
74 $this->notices = $this->getNotices();
82 * Just show the notices
84 * @param array $args $_REQUEST data (unused)
88 function handle($args)
90 parent::handle($args);
91 $this->showTimeline();
95 * Show the timeline of notices
99 function showTimeline()
101 $profile = $this->user->getProfile();
102 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
104 $sitename = common_config('site', 'name');
106 // TRANS: Title for timeline of most recent favourite notices by a user.
107 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
108 _('%1$s / Favorites from %2$s'),
110 $this->user->nickname
113 $taguribase = TagURI::base();
114 $id = "tag:$taguribase:Favorites:" . $this->user->id;
117 // TRANS: Subtitle for timeline of most recent favourite notices by a user.
118 // TRANS: %1$s is the StatusNet sitename, %2$s is a user's full name,
119 // TRANS: %3$s is a user nickname.
120 _('%1$s updates favorited by %2$s / %3$s.'),
122 $profile->getBestName(),
123 $this->user->nickname
125 $logo = !empty($avatar)
126 ? $avatar->displayUrl()
127 : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
129 $link = common_local_url(
131 array('nickname' => $this->user->nickname)
134 $self = $this->getSelfUri();
136 switch($this->format) {
138 $this->showXmlTimeline($this->notices);
141 $this->showRssTimeline(
152 header('Content-Type: application/atom+xml; charset=utf-8');
154 $atom = new AtomNoticeFeed($this->auth_user);
157 $atom->setTitle($title);
158 $atom->setSubtitle($subtitle);
159 $atom->setLogo($logo);
160 $atom->setUpdated('now');
162 $atom->addLink($link);
163 $atom->setSelfLink($self);
165 $atom->addEntryFromNotices($this->notices);
167 $this->raw($atom->getString());
170 $this->showJsonTimeline($this->notices);
173 // TRANS: Client error displayed when trying to handle an unknown 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))