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/
52 class ApiTimelineFavoritesAction extends ApiBareAuthAction
57 * Take arguments for running
59 * @param array $args $_REQUEST args
61 * @return boolean success flag
65 function prepare($args)
67 parent::prepare($args);
69 $this->user = $this->getTargetUser($this->arg('id'));
71 if (empty($this->user)) {
72 $this->clientError(_('No such user.'), 404, $this->format);
76 $this->notices = $this->getNotices();
84 * Just show the notices
86 * @param array $args $_REQUEST data (unused)
91 function handle($args)
93 parent::handle($args);
94 $this->showTimeline();
98 * Show the timeline of notices
103 function showTimeline()
105 $profile = $this->user->getProfile();
106 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
108 $sitename = common_config('site', 'name');
110 _('%1$s / Favorites from %2$s'),
112 $this->user->nickname
115 $taguribase = TagURI::base();
116 $id = "tag:$taguribase:Favorites:" . $this->user->id;
119 _('%1$s updates favorited by %2$s / %2$s.'),
121 $profile->getBestName(),
122 $this->user->nickname
124 $logo = !empty($avatar)
125 ? $avatar->displayUrl()
126 : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
128 $link = common_local_url(
130 array('nickname' => $this->user->nickname)
133 $self = $this->getSelfUri();
135 switch($this->format) {
137 $this->showXmlTimeline($this->notices);
140 $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());
171 $this->showJsonTimeline($this->notices);
174 $this->clientError(_('API method not found.'), $code = 404);
182 * @return array notices
185 function getNotices()
189 common_debug("since id = " . $this->since_id . " max id = " . $this->max_id);
191 if (!empty($this->auth_user) && $this->auth_user->id == $this->user->id) {
192 $notice = $this->user->favoriteNotices(
194 ($this->page-1) * $this->count,
200 $notice = $this->user->favoriteNotices(
202 ($this->page-1) * $this->count,
209 while ($notice->fetch()) {
210 $notices[] = clone($notice);
217 * Is this action read only?
219 * @param array $args other arguments
221 * @return boolean true
224 function isReadOnly($args)
230 * When was this feed last modified?
232 * @return string datestamp of the latest notice in the stream
235 function lastModified()
237 if (!empty($this->notices) && (count($this->notices) > 0)) {
238 return strtotime($this->notices[0]->created);
245 * An entity tag for this stream
247 * Returns an Etag based on the action name, language, user ID, and
248 * timestamps of the first and last notice in the timeline
250 * @return string etag
255 if (!empty($this->notices) && (count($this->notices) > 0)) {
257 $last = count($this->notices) - 1;
259 return '"' . implode(
261 array($this->arg('action'),
264 strtotime($this->notices[0]->created),
265 strtotime($this->notices[$last]->created))