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->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 $this->user = $this->getTargetUser($this->arg('id'));
73 if (empty($this->user)) {
74 $this->clientError(_('No such user!'), 404, $this->arg('format'));
78 $this->notices = $this->getNotices();
86 * Just show the notices
88 * @param array $args $_REQUEST data (unused)
93 function handle($args)
95 parent::handle($args);
96 $this->showTimeline();
100 * Show the timeline of notices
105 function showTimeline()
107 $profile = $this->user->getProfile();
109 $sitename = common_config('site', 'name');
111 _('%1$s / Updates mentioning %2$s'),
112 $sitename, $this->user->nickname
114 $taguribase = common_config('integration', 'taguri');
115 $id = "tag:$taguribase:Mentions:" . $this->user->id;
116 $link = common_local_url(
118 array('nickname' => $this->user->nickname)
121 _('%1$s updates that reply to updates from %2$s / %3$s.'),
122 $sitename, $this->user->nickname, $profile->getBestName()
125 switch($this->arg('format')) {
127 $this->show_xml_timeline($this->notices);
130 $this->show_rss_timeline($this->notices, $title, $link, $subtitle);
133 $selfuri = common_root_url() .
134 ltrim($_SERVER['QUERY_STRING'], 'p=');
135 $this->show_atom_timeline(
136 $this->notices, $title, $id, $link, $subtitle,
141 $this->show_json_timeline($this->notices);
144 $this->clientError(_('API method not found!'), $code = 404);
152 * @return array notices
155 function getNotices()
159 $notice = $this->user->getReplies(
160 ($this->page - 1) * $this->count, $this->count,
161 $this->since_id, $this->max_id, $this->since
164 while ($notice->fetch()) {
165 $notices[] = clone($notice);
172 * Is this action read only?
174 * @param array $args other arguments
176 * @return boolean true
179 function isReadOnly($args)
185 * When was this feed last modified?
187 * @return string datestamp of the latest notice in the stream
190 function lastModified()
192 if (!empty($this->notices) && (count($this->notices) > 0)) {
193 return strtotime($this->notices[0]->created);
200 * An entity tag for this stream
202 * Returns an Etag based on the action name, language, user ID, and
203 * timestamps of the first and last notice in the timeline
205 * @return string etag
210 if (!empty($this->notices) && (count($this->notices) > 0)) {
212 $last = count($this->notices) - 1;
214 return '"' . implode(
216 array($this->arg('action'),
219 strtotime($this->notices[0]->created),
220 strtotime($this->notices[$last]->created))