3 * StatusNet, the distributed open-source microblogging tool
5 * Show a user's bookmark activities
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 most recent bookmark activities 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(array $args = array())
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);
71 $this->notices = $this->getNotices();
79 * Just show the notices
81 * @param array $args $_REQUEST data (unused)
88 $this->showTimeline();
92 * Show the timeline of notices
96 function showTimeline()
98 $profile = $this->user->getProfile();
100 $sitename = common_config('site', 'name');
102 // TRANS: Title for timeline of most recent favourite notices by a user.
103 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
104 _('%1$s / Bookmarks from %2$s'),
106 $this->user->nickname
109 $taguribase = TagURI::base();
110 $id = "tag:$taguribase:Bookmarks:" . $this->user->id;
113 // TRANS: Subtitle for timeline of most recent favourite notices by a user.
114 // TRANS: %1$s is the StatusNet sitename, %2$s is a user's full name,
115 // TRANS: %3$s is a user nickname.
116 _('%1$s updates bookmarked by %2$s / %3$s.'),
118 $profile->getBestName(),
119 $this->user->nickname
122 $logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
123 $link = common_local_url('bookmarks',
124 array('nickname' => $this->user->nickname));
125 $self = $this->getSelfUri();
127 switch($this->format) {
129 $this->showXmlTimeline($this->notices);
132 $this->showRssTimeline(
143 header('Content-Type: application/atom+xml; charset=utf-8');
145 $atom = new AtomNoticeFeed($this->auth_user);
148 $atom->setTitle($title);
149 $atom->setSubtitle($subtitle);
150 $atom->setLogo($logo);
151 $atom->setUpdated('now');
153 $atom->addLink($link);
154 $atom->setSelfLink($self);
156 $atom->addEntryFromNotices($this->notices);
158 $this->raw($atom->getString());
161 $this->showJsonTimeline($this->notices);
164 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
165 $doc = new ActivityStreamJSONDocument($this->auth_user);
166 $doc->setTitle($title);
167 $doc->addLink($link,'alternate', 'text/html');
168 $doc->addItemsFromNotices($this->notices);
169 $this->raw($doc->asString());
172 // TRANS: Client error displayed when coming across a non-supported API method.
173 $this->clientError(_('API method not found.'), $code = 404);
180 * @return array notices
182 function getNotices()
186 common_debug("since id = " . $this->since_id . " max id = " . $this->max_id);
188 $notice = new BookmarksNoticeStream($this->user->id, true);
189 $notice = $notice->getNotices(
190 ($this->page-1) * $this->count,
196 while ($notice->fetch()) {
197 $notices[] = clone($notice);
204 * Is this action read only?
206 * @param array $args other arguments
208 * @return boolean true
210 function isReadOnly($args)
216 * When was this feed last modified?
218 * @return string datestamp of the latest notice in the stream
220 function lastModified()
222 if (!empty($this->notices) && (count($this->notices) > 0)) {
223 return strtotime($this->notices[0]->created);
230 * An entity tag for this stream
232 * Returns an Etag based on the action name, language, user ID, and
233 * timestamps of the first and last notice in the timeline
235 * @return string etag
239 if (!empty($this->notices) && (count($this->notices) > 0)) {
241 $last = count($this->notices) - 1;
243 return '"' . implode(
245 array($this->arg('action'),
246 common_user_cache_hash($this->auth_user),
249 strtotime($this->notices[0]->created),
250 strtotime($this->notices[$last]->created))