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 protected function prepare(array $args=array())
69 parent::prepare($args);
71 $this->target = $this->getTargetProfile($this->arg('id'));
73 if (!($this->target instanceof Profile)) {
74 // TRANS: Client error displayed when requesting most recent mentions for a non-existing user.
75 $this->clientError(_('No such user.'), 404);
78 $this->notices = $this->getNotices();
86 * Just show the notices
90 protected function handle()
93 $this->showTimeline();
97 * Show the timeline of notices
101 function showTimeline()
103 $sitename = common_config('site', 'name');
105 // TRANS: Title for timeline of most recent mentions of a user.
106 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
107 _('%1$s / Updates mentioning %2$s'),
108 $sitename, $this->target->nickname
110 $taguribase = TagURI::base();
111 $id = "tag:$taguribase:Mentions:" . $this->target->id;
113 $logo = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
114 $link = common_local_url('replies',
115 array('nickname' => $this->target->nickname));
116 $self = $this->getSelfUri();
119 // TRANS: Subtitle for timeline of most recent mentions of a user.
120 // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname,
121 // TRANS: %3$s is a user's full name.
122 _('%1$s updates that reply to updates from %3$s / %2$s.'),
123 $sitename, $this->target->nickname, $this->target->getBestName()
126 switch($this->format) {
128 $this->showXmlTimeline($this->notices);
131 $this->showRssTimeline(
142 header('Content-Type: application/atom+xml; charset=utf-8');
144 $atom = new AtomNoticeFeed($this->auth_user);
147 $atom->setTitle($title);
148 $atom->setSubtitle($subtitle);
149 $atom->setLogo($logo);
150 $atom->setUpdated('now');
152 $atom->addLink($link);
153 $atom->setSelfLink($self);
155 $atom->addEntryFromNotices($this->notices);
156 $this->raw($atom->getString());
160 $this->showJsonTimeline($this->notices);
163 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
164 $doc = new ActivityStreamJSONDocument($this->auth_user);
165 $doc->setTitle($title);
166 $doc->addLink($link, 'alternate', 'text/html');
167 $doc->addItemsFromNotices($this->notices);
168 $this->raw($doc->asString());
171 // TRANS: Client error displayed when coming across a non-supported API method.
172 $this->clientError(_('API method not found.'), $code = 404);
180 * @return array notices
182 function getNotices()
186 $stream = new ReplyNoticeStream($this->target->id, $this->scoped);
188 $notice = $stream->getNotices(($this->page - 1) * $this->count,
193 while ($notice->fetch()) {
194 $notices[] = clone($notice);
201 * Is this action read only?
203 * @param array $args other arguments
205 * @return boolean true
207 function isReadOnly($args)
213 * When was this feed last modified?
215 * @return string datestamp of the latest notice in the stream
217 function lastModified()
219 if (!empty($this->notices) && (count($this->notices) > 0)) {
220 return strtotime($this->notices[0]->created);
227 * An entity tag for this stream
229 * Returns an Etag based on the action name, language, user ID, and
230 * timestamps of the first and last notice in the timeline
232 * @return string etag
236 if (!empty($this->notices) && (count($this->notices) > 0)) {
238 $last = count($this->notices) - 1;
240 return '"' . implode(
242 array($this->arg('action'),
243 common_user_cache_hash($this->auth_user),
246 strtotime($this->notices[0]->created),
247 strtotime($this->notices[$last]->created))