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 protected function prepare(array $args=array())
62 parent::prepare($args);
64 $this->target = $this->getTargetProfile($this->arg('id'));
66 if (!($this->target instanceof Profile)) {
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);
71 $this->notices = $this->getNotices();
79 * Just show the notices
83 protected function handle()
86 $this->showTimeline();
90 * Show the timeline of notices
94 function showTimeline()
96 $sitename = common_config('site', 'name');
98 // TRANS: Title for timeline of most recent favourite notices by a user.
99 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
100 _('%1$s / Favorites from %2$s'),
102 $this->target->nickname
105 $taguribase = TagURI::base();
106 $id = "tag:$taguribase:Favorites:" . $this->target->id;
109 // TRANS: Subtitle for timeline of most recent favourite notices by a user.
110 // TRANS: %1$s is the StatusNet sitename, %2$s is a user's full name,
111 // TRANS: %3$s is a user nickname.
112 _('%1$s updates favorited by %2$s / %3$s.'),
114 $this->target->getBestName(),
115 $this->target->nickname
118 $logo = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
119 $link = common_local_url('showfavorites',
120 array('nickname' => $this->target->nickname));
121 $self = $this->getSelfUri();
123 switch($this->format) {
125 $this->showXmlTimeline($this->notices);
128 $this->showRssTimeline(
139 header('Content-Type: application/atom+xml; charset=utf-8');
141 $atom = new AtomNoticeFeed($this->auth_user);
144 $atom->setTitle($title);
145 $atom->setSubtitle($subtitle);
146 $atom->setLogo($logo);
147 $atom->setUpdated('now');
149 $atom->addLink($link);
150 $atom->setSelfLink($self);
152 $atom->addEntryFromNotices($this->notices);
154 $this->raw($atom->getString());
157 $this->showJsonTimeline($this->notices);
160 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
161 $doc = new ActivityStreamJSONDocument($this->auth_user);
162 $doc->setTitle($title);
163 $doc->addLink($link,'alternate', 'text/html');
164 $doc->addItemsFromNotices($this->notices);
165 $this->raw($doc->asString());
168 // TRANS: Client error displayed when coming across a non-supported API method.
169 $this->clientError(_('API method not found.'), 404);
176 * @return array notices
178 function getNotices()
182 common_debug("since id = " . $this->since_id . " max id = " . $this->max_id);
184 $notice = Fave::stream($this->target->id,
185 ($this->page-1) * $this->count, // offset
186 $this->count, // limit
187 (!empty($this->auth_user) && $this->auth_user->id == $this->target->id), // own feed?
192 while ($notice->fetch()) {
193 $notices[] = clone($notice);
200 * Is this action read only?
202 * @param array $args other arguments
204 * @return boolean true
206 function isReadOnly(array $args=array())
212 * When was this feed last modified?
214 * @return string datestamp of the latest notice in the stream
216 function lastModified()
218 if (!empty($this->notices) && (count($this->notices) > 0)) {
219 return strtotime($this->notices[0]->created);
226 * An entity tag for this stream
228 * Returns an Etag based on the action name, language, user ID, and
229 * timestamps of the first and last notice in the timeline
231 * @return string etag
235 if (!empty($this->notices) && (count($this->notices) > 0)) {
237 $last = count($this->notices) - 1;
239 return '"' . implode(
241 array($this->arg('action'),
242 common_user_cache_hash($this->auth_user),
245 strtotime($this->notices[0]->created),
246 strtotime($this->notices[$last]->created))