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 ApiTimelineMentionsAction 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->user = $this->getTargetUser($this->arg('id'));
67 if (empty($this->user)) {
68 $this->clientError(_('No such user!'), 404, $this->format);
72 $this->notices = $this->getNotices();
80 * Just show the notices
82 * @param array $args $_REQUEST data (unused)
87 function handle($args)
89 parent::handle($args);
90 $this->showTimeline();
94 * Show the timeline of notices
99 function showTimeline()
101 $profile = $this->user->getProfile();
103 $sitename = common_config('site', 'name');
105 _('%1$s / Updates mentioning %2$s'),
106 $sitename, $this->user->nickname
108 $taguribase = common_config('integration', 'taguri');
109 $id = "tag:$taguribase:Mentions:" . $this->user->id;
110 $link = common_local_url(
112 array('nickname' => $this->user->nickname)
115 _('%1$s updates that reply to updates from %2$s / %3$s.'),
116 $sitename, $this->user->nickname, $profile->getBestName()
119 switch($this->format) {
121 $this->show_xml_timeline($this->notices);
124 $this->show_rss_timeline($this->notices, $title, $link, $subtitle);
127 $selfuri = common_root_url() .
128 ltrim($_SERVER['QUERY_STRING'], 'p=');
129 $this->show_atom_timeline(
130 $this->notices, $title, $id, $link, $subtitle,
135 $this->show_json_timeline($this->notices);
138 $this->clientError(_('API method not found!'), $code = 404);
146 * @return array notices
149 function getNotices()
153 $notice = $this->user->getReplies(
154 ($this->page - 1) * $this->count, $this->count,
155 $this->since_id, $this->max_id, $this->since
158 while ($notice->fetch()) {
159 $notices[] = clone($notice);
166 * Is this action read only?
168 * @param array $args other arguments
170 * @return boolean true
173 function isReadOnly($args)
179 * When was this feed last modified?
181 * @return string datestamp of the latest notice in the stream
184 function lastModified()
186 if (!empty($this->notices) && (count($this->notices) > 0)) {
187 return strtotime($this->notices[0]->created);
194 * An entity tag for this stream
196 * Returns an Etag based on the action name, language, user ID, and
197 * timestamps of the first and last notice in the timeline
199 * @return string etag
204 if (!empty($this->notices) && (count($this->notices) > 0)) {
206 $last = count($this->notices) - 1;
208 return '"' . implode(
210 array($this->arg('action'),
213 strtotime($this->notices[0]->created),
214 strtotime($this->notices[$last]->created))