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';
38 require_once 'bookmarksnoticestream.php';
41 * Returns the 20 most recent favorite notices for the authenticating user or user
42 * specified by the ID parameter in the requested format.
46 * @author Craig Andrews <candrews@integralblue.com>
47 * @author Evan Prodromou <evan@status.net>
48 * @author Zach Copley <zach@status.net>
49 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
50 * @link http://status.net/
52 class ApiTimelineBookmarksAction extends ApiBareAuthAction
57 * Take arguments for running
59 * @param array $args $_REQUEST args
61 * @return boolean success flag
63 function prepare($args)
65 parent::prepare($args);
67 $this->user = $this->getTargetUser($this->arg('id'));
69 if (empty($this->user)) {
70 // TRANS: Client error displayed when requesting most recent favourite notices by a user for a non-existing user.
71 $this->clientError(_('No such user.'), 404, $this->format);
75 $this->notices = $this->getNotices();
83 * Just show the notices
85 * @param array $args $_REQUEST data (unused)
89 function handle($args)
91 parent::handle($args);
92 $this->showTimeline();
96 * Show the timeline of notices
100 function showTimeline()
102 $profile = $this->user->getProfile();
103 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
105 $sitename = common_config('site', 'name');
107 // TRANS: Title for timeline of most recent favourite notices by a user.
108 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
109 _('%1$s / Bookmarks from %2$s'),
111 $this->user->nickname
114 $taguribase = TagURI::base();
115 $id = "tag:$taguribase:Bookmarks:" . $this->user->id;
118 // TRANS: Subtitle for timeline of most recent favourite notices by a user.
119 // TRANS: %1$s is the StatusNet sitename, %2$s is a user's full name,
120 // TRANS: %3$s is a user nickname.
121 _('%1$s updates bookmarked by %2$s / %3$s.'),
123 $profile->getBestName(),
124 $this->user->nickname
126 $logo = !empty($avatar)
127 ? $avatar->displayUrl()
128 : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
130 $link = common_local_url(
132 array('nickname' => $this->user->nickname)
135 $self = $this->getSelfUri();
137 switch($this->format) {
139 $this->showXmlTimeline($this->notices);
142 $this->showRssTimeline(
153 header('Content-Type: application/atom+xml; charset=utf-8');
155 $atom = new AtomNoticeFeed($this->auth_user);
158 $atom->setTitle($title);
159 $atom->setSubtitle($subtitle);
160 $atom->setLogo($logo);
161 $atom->setUpdated('now');
163 $atom->addLink($link);
164 $atom->setSelfLink($self);
166 $atom->addEntryFromNotices($this->notices);
168 $this->raw($atom->getString());
171 $this->showJsonTimeline($this->notices);
174 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
175 $doc = new ActivityStreamJSONDocument($this->auth_user);
176 $doc->setTitle($title);
177 $doc->addLink($link,'alternate', 'text/html');
178 $doc->addItemsFromNotices($this->notices);
179 $this->raw($doc->asString());
182 // TRANS: Client error displayed when coming across a non-supported API method.
183 $this->clientError(_('API method not found.'), $code = 404);
191 * @return array notices
193 function getNotices()
197 common_debug("since id = " . $this->since_id . " max id = " . $this->max_id);
199 $notice = new BookmarksNoticeStream($this->user->id, true);
200 $notice = $notice->getNotices(
201 ($this->page-1) * $this->count,
207 while ($notice->fetch()) {
208 $notices[] = clone($notice);
215 * Is this action read only?
217 * @param array $args other arguments
219 * @return boolean true
221 function isReadOnly($args)
227 * When was this feed last modified?
229 * @return string datestamp of the latest notice in the stream
231 function lastModified()
233 if (!empty($this->notices) && (count($this->notices) > 0)) {
234 return strtotime($this->notices[0]->created);
241 * An entity tag for this stream
243 * Returns an Etag based on the action name, language, user ID, and
244 * timestamps of the first and last notice in the timeline
246 * @return string etag
250 if (!empty($this->notices) && (count($this->notices) > 0)) {
252 $last = count($this->notices) - 1;
254 return '"' . implode(
256 array($this->arg('action'),
257 common_user_cache_hash($this->auth_user),
260 strtotime($this->notices[0]->created),
261 strtotime($this->notices[$last]->created))