3 * StatusNet, the distributed open-source microblogging tool
5 * Show notices mentioning a user (@nickname)
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 Jeffery To <jeffery.to@gmail.com>
27 * @author mac65 <mac65@mac65.com>
28 * @author Mike Cochrane <mikec@mikenz.geek.nz>
29 * @author Robin Millette <robin@millette.info>
30 * @author Zach Copley <zach@status.net>
31 * @copyright 2009 StatusNet, Inc.
32 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
33 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
34 * @link http://status.net/
37 if (!defined('STATUSNET')) {
42 * Returns the most recent (default 20) mentions (status containing @nickname)
46 * @author Craig Andrews <candrews@integralblue.com>
47 * @author Evan Prodromou <evan@status.net>
48 * @author Jeffery To <jeffery.to@gmail.com>
49 * @author mac65 <mac65@mac65.com>
50 * @author Mike Cochrane <mikec@mikenz.geek.nz>
51 * @author Robin Millette <robin@millette.info>
52 * @author Zach Copley <zach@status.net>
53 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
54 * @link http://status.net/
56 class ApiTimelineMentionsAction extends ApiBareAuthAction
61 * Take arguments for running
63 * @param array $args $_REQUEST args
65 * @return boolean success flag
67 function prepare($args)
69 parent::prepare($args);
71 $this->user = $this->getTargetUser($this->arg('id'));
73 if (empty($this->user)) {
74 // TRANS: Client error displayed when requesting most recent mentions for a non-existing user.
75 $this->clientError(_('No such user.'), 404, $this->format);
79 $this->notices = $this->getNotices();
87 * Just show the notices
89 * @param array $args $_REQUEST data (unused)
93 function handle($args)
95 parent::handle($args);
96 $this->showTimeline();
100 * Show the timeline of notices
104 function showTimeline()
106 $profile = $this->user->getProfile();
107 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
109 $sitename = common_config('site', 'name');
111 // TRANS: Title for timeline of most recent mentions of a user.
112 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
113 _('%1$s / Updates mentioning %2$s'),
114 $sitename, $this->user->nickname
116 $taguribase = TagURI::base();
117 $id = "tag:$taguribase:Mentions:" . $this->user->id;
118 $link = common_local_url(
120 array('nickname' => $this->user->nickname)
123 $self = $this->getSelfUri();
126 // TRANS: Subtitle for timeline of most recent mentions of a user.
127 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname,
128 // TRANS: %3$s is a user's full name.
129 _('%1$s updates that reply to updates from %2$s / %3$s.'),
130 $sitename, $this->user->nickname, $profile->getBestName()
132 $logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
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);
164 $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 if (empty($this->auth_user)) {
197 $profile = $this->auth_user->getProfile();
200 $stream = new ReplyNoticeStream($this->user->id, $profile);
202 $notice = $stream->getNotices(($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))