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 Zach Copley <zach@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR.'/lib/apibareauth.php';
37 * Returns the most recent (default 20) mentions (status containing @nickname)
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
46 class ApiMentionsAction extends ApiBareAuthAction
53 * Take arguments for running
55 * @param array $args $_REQUEST args
57 * @return boolean success flag
61 function prepare($args)
63 parent::prepare($args);
65 $this->page = (int)$this->arg('page', 1);
66 $this->count = (int)$this->arg('count', 20);
67 $this->max_id = (int)$this->arg('max_id', 0);
68 $this->since_id = (int)$this->arg('since_id', 0);
69 $this->since = $this->arg('since');
71 if ($this->requiresAuth()) {
72 if ($this->checkBasicAuthUser() == false) {
77 $this->user = $this->getTargetUser($this->arg('id'));
79 if (empty($this->user)) {
80 $this->clientError(_('No such user!'), 404, $this->arg('format'));
84 $this->notices = $this->getNotices();
92 * Just show the notices
94 * @param array $args $_REQUEST data (unused)
99 function handle($args)
101 parent::handle($args);
102 $this->showTimeline();
106 * Show the timeline of notices
111 function showTimeline()
113 $profile = $this->user->getProfile();
115 $sitename = common_config('site', 'name');
117 _('%1$s / Updates mentioning %2$s'),
118 $sitename, $this->user->nickname
120 $taguribase = common_config('integration', 'taguri');
121 $id = "tag:$taguribase:Mentions:" . $this->user->id;
122 $link = common_local_url(
124 array('nickname' => $this->user->nickname)
127 _('%1$s updates that reply to updates from %2$s / %3$s.'),
128 $sitename, $this->user->nickname, $profile->getBestName()
131 switch($this->arg('format')) {
133 $this->show_xml_timeline($this->notices);
136 $this->show_rss_timeline($this->notices, $title, $link, $subtitle);
139 $selfuri = common_root_url() .
140 ltrim($_SERVER['QUERY_STRING'], 'p=');
141 $this->show_atom_timeline(
142 $this->notices, $title, $id, $link, $subtitle,
147 $this->show_json_timeline($this->notices);
150 $this->clientError(_('API method not found!'), $code = 404);
158 * @return array notices
161 function getNotices()
165 $notice = $this->user->getReplies(
166 ($this->page - 1) * $this->count, $this->count,
167 $this->since_id, $this->max_id, $this->since
170 while ($notice->fetch()) {
171 $notices[] = clone($notice);
178 * Is this action read only?
180 * @param array $args other arguments
182 * @return boolean true
185 function isReadOnly($args)
191 * When was this feed last modified?
193 * @return string datestamp of the latest notice in the stream
196 function lastModified()
198 if (!empty($this->notices) && (count($this->notices) > 0)) {
199 return strtotime($this->notices[0]->created);
206 * An entity tag for this stream
208 * Returns an Etag based on the action name, language, user ID, and
209 * timestamps of the first and last notice in the timeline
211 * @return string etag
216 if (!empty($this->notices) && (count($this->notices) > 0)) {
218 $last = count($this->notices) - 1;
222 array($this->arg('action'),
225 strtotime($this->notices[0]->created),
226 strtotime($this->notices[$last]->created))