3 * StatusNet, the distributed open-source microblogging tool
5 * Show the latest notices for a given tag
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/api.php';
37 * Returns the 20 most recent notices tagged by a given tag
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 ApiTimelineTagAction extends ApiAction
52 * Take arguments for running
54 * @param array $args $_REQUEST args
56 * @return boolean success flag
60 function prepare($args)
62 parent::prepare($args);
64 $this->page = (int)$this->arg('page', 1);
65 $this->count = (int)$this->arg('count', 20);
66 $this->tag = $this->arg('tag');
67 $this->format = $this->arg('format');
69 $this->notices = $this->getNotices();
77 * Just show the notices
79 * @param array $args $_REQUEST data (unused)
84 function handle($args)
86 parent::handle($args);
87 $this->showTimeline();
91 * Show the timeline of notices
96 function showTimeline()
98 $sitename = common_config('site', 'name');
99 $title = sprintf(_("Notices tagged with %s"), $this->tag);
100 $link = common_local_url(
102 array('tag' => $this->tag)
105 _('Updates tagged with %1$s on %2$s!'),
109 $taguribase = common_config('integration', 'taguri');
110 $id = "tag:$taguribase:TagTimeline:".$tag;
112 switch($this->format) {
114 $this->show_xml_timeline($this->notices);
117 $this->show_rss_timeline($this->notices, $title, $link, $subtitle);
120 $selfuri = common_root_url() .
121 'api/statusnet/tags/timeline/' .
122 $this->tag . '.atom';
123 $this->show_atom_timeline(
134 $this->show_json_timeline($this->notices);
137 $this->clientError(_('API method not found!'), $code = 404);
145 * @return array notices
148 function getNotices()
152 $notice = Notice_tag::getStream(
154 ($this->page - 1) * $this->count,
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, 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))