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();
108 $sitename = common_config('site', 'name');
110 // TRANS: Title for timeline of most recent mentions of a user.
111 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
112 _('%1$s / Updates mentioning %2$s'),
113 $sitename, $this->user->nickname
115 $taguribase = TagURI::base();
116 $id = "tag:$taguribase:Mentions:" . $this->user->id;
118 $logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
119 $link = common_local_url('replies',
120 array('nickname' => $this->user->nickname));
121 $self = $this->getSelfUri();
124 // TRANS: Subtitle for timeline of most recent mentions of a user.
125 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname,
126 // TRANS: %3$s is a user's full name.
127 _('%1$s updates that reply to updates from %2$s / %3$s.'),
128 $sitename, $this->user->nickname, $profile->getBestName()
131 switch($this->format) {
133 $this->showXmlTimeline($this->notices);
136 $this->showRssTimeline(
147 header('Content-Type: application/atom+xml; charset=utf-8');
149 $atom = new AtomNoticeFeed($this->auth_user);
152 $atom->setTitle($title);
153 $atom->setSubtitle($subtitle);
154 $atom->setLogo($logo);
155 $atom->setUpdated('now');
157 $atom->addLink($link);
158 $atom->setSelfLink($self);
160 $atom->addEntryFromNotices($this->notices);
161 $this->raw($atom->getString());
165 $this->showJsonTimeline($this->notices);
168 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
169 $doc = new ActivityStreamJSONDocument($this->auth_user);
170 $doc->setTitle($title);
171 $doc->addLink($link, 'alternate', 'text/html');
172 $doc->addItemsFromNotices($this->notices);
173 $this->raw($doc->asString());
176 // TRANS: Client error displayed when coming across a non-supported API method.
177 $this->clientError(_('API method not found.'), $code = 404);
185 * @return array notices
187 function getNotices()
191 if (empty($this->auth_user)) {
194 $profile = $this->auth_user->getProfile();
197 $stream = new ReplyNoticeStream($this->user->id, $profile);
199 $notice = $stream->getNotices(($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))