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 Craig Andrews <candrews@integralblue.com>
25 * @author Evan Prodromou <evan@status.net>
26 * @author Jeffery To <jeffery.to@gmail.com>
27 * @author Zach Copley <zach@status.net>
28 * @copyright 2009-2010 StatusNet, Inc.
29 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
30 * @link http://status.net/
33 if (!defined('STATUSNET')) {
37 require_once INSTALLDIR . '/lib/apiprivateauth.php';
40 * Returns the 20 most recent notices tagged by a given tag
44 * @author Craig Andrews <candrews@integralblue.com>
45 * @author Evan Prodromou <evan@status.net>
46 * @author Jeffery To <jeffery.to@gmail.com>
47 * @author Zach Copley <zach@status.net>
48 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49 * @link http://status.net/
52 class ApiTimelineTagAction extends ApiPrivateAuthAction
58 * Take arguments for running
60 * @param array $args $_REQUEST args
62 * @return boolean success flag
66 function prepare($args)
68 parent::prepare($args);
70 common_debug("apitimelinetag prepare()");
72 $this->tag = $this->arg('tag');
73 $this->notices = $this->getNotices();
81 * Just show the notices
83 * @param array $args $_REQUEST data (unused)
88 function handle($args)
90 parent::handle($args);
91 $this->showTimeline();
95 * Show the timeline of notices
100 function showTimeline()
102 $sitename = common_config('site', 'name');
103 $sitelogo = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png');
104 $title = sprintf(_("Notices tagged with %s"), $this->tag);
106 _('Updates tagged with %1$s on %2$s!'),
110 $taguribase = TagURI::base();
111 $id = "tag:$taguribase:TagTimeline:".$tag;
113 $link = common_local_url(
115 array('tag' => $this->tag)
118 $self = $this->getSelfUri();
120 common_debug("self link is: $self");
122 switch($this->format) {
124 $this->showXmlTimeline($this->notices);
127 $this->showRssTimeline(
139 header('Content-Type: application/atom+xml; charset=utf-8');
141 $atom = new AtomNoticeFeed();
144 $atom->setTitle($title);
145 $atom->setSubtitle($subtitle);
146 $atom->setLogo($logo);
147 $atom->setUpdated('now');
149 $atom->addLink($link);
150 $atom->setSelfLink($self);
152 $atom->addEntryFromNotices($this->notices);
153 $this->raw($atom->getString());
157 $this->showJsonTimeline($this->notices);
160 $this->clientError(_('API method not found.'), $code = 404);
168 * @return array notices
171 function getNotices()
175 $notice = Notice_tag::getStream(
177 ($this->page - 1) * $this->count,
181 while ($notice->fetch()) {
182 $notices[] = clone($notice);
189 * Is this action read only?
191 * @param array $args other arguments
193 * @return boolean true
196 function isReadOnly($args)
202 * When was this feed last modified?
204 * @return string datestamp of the latest notice in the stream
207 function lastModified()
209 if (!empty($this->notices) && (count($this->notices) > 0)) {
210 return strtotime($this->notices[0]->created);
217 * An entity tag for this stream
219 * Returns an Etag based on the action name, language, and
220 * timestamps of the first and last notice in the timeline
222 * @return string etag
227 if (!empty($this->notices) && (count($this->notices) > 0)) {
229 $last = count($this->notices) - 1;
231 return '"' . implode(
233 array($this->arg('action'),
236 strtotime($this->notices[0]->created),
237 strtotime($this->notices[$last]->created))