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 ApiTimelineBookmarksAction 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();
100 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
102 $sitename = common_config('site', 'name');
104 // TRANS: Title for timeline of most recent favourite notices by a user.
105 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
106 _('%1$s / Bookmarks from %2$s'),
108 $this->user->nickname
111 $taguribase = TagURI::base();
112 $id = "tag:$taguribase:Bookmarks:" . $this->user->id;
115 // TRANS: Subtitle for timeline of most recent favourite notices by a user.
116 // TRANS: %1$s is the StatusNet sitename, %2$s is a user's full name,
117 // TRANS: %3$s is a user nickname.
118 _('%1$s updates bookmarked by %2$s / %3$s.'),
120 $profile->getBestName(),
121 $this->user->nickname
123 $logo = !empty($avatar)
124 ? $avatar->displayUrl()
125 : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
127 $link = common_local_url(
129 array('nickname' => $this->user->nickname)
132 $self = $this->getSelfUri();
134 switch($this->format) {
136 $this->showXmlTimeline($this->notices);
139 $this->showRssTimeline(
150 header('Content-Type: application/atom+xml; charset=utf-8');
152 $atom = new AtomNoticeFeed($this->auth_user);
155 $atom->setTitle($title);
156 $atom->setSubtitle($subtitle);
157 $atom->setLogo($logo);
158 $atom->setUpdated('now');
160 $atom->addLink($link);
161 $atom->setSelfLink($self);
163 $atom->addEntryFromNotices($this->notices);
165 $this->raw($atom->getString());
168 $this->showJsonTimeline($this->notices);
171 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
172 $doc = new ActivityStreamJSONDocument($this->auth_user);
173 $doc->setTitle($title);
174 $doc->addLink($link,'alternate', 'text/html');
175 $doc->addItemsFromNotices($this->notices);
176 $this->raw($doc->asString());
179 // TRANS: Client error displayed when coming across a non-supported API method.
180 $this->clientError(_('API method not found.'), $code = 404);
188 * @return array notices
190 function getNotices()
194 common_debug("since id = " . $this->since_id . " max id = " . $this->max_id);
196 $notice = new BookmarksNoticeStream($this->user->id, true);
197 $notice = $notice->getNotices(
198 ($this->page-1) * $this->count,
204 while ($notice->fetch()) {
205 $notices[] = clone($notice);
212 * Is this action read only?
214 * @param array $args other arguments
216 * @return boolean true
218 function isReadOnly($args)
224 * When was this feed last modified?
226 * @return string datestamp of the latest notice in the stream
228 function lastModified()
230 if (!empty($this->notices) && (count($this->notices) > 0)) {
231 return strtotime($this->notices[0]->created);
238 * An entity tag for this stream
240 * Returns an Etag based on the action name, language, user ID, and
241 * timestamps of the first and last notice in the timeline
243 * @return string etag
247 if (!empty($this->notices) && (count($this->notices) > 0)) {
249 $last = count($this->notices) - 1;
251 return '"' . implode(
253 array($this->arg('action'),
254 common_user_cache_hash($this->auth_user),
257 strtotime($this->notices[0]->created),
258 strtotime($this->notices[$last]->created))