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 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
30 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
31 * @link http://status.net/
34 if (!defined('STATUSNET')) {
38 require_once INSTALLDIR . '/lib/apiprivateauth.php';
41 * Returns the 20 most recent notices tagged by a given tag
45 * @author Craig Andrews <candrews@integralblue.com>
46 * @author Evan Prodromou <evan@status.net>
47 * @author Jeffery To <jeffery.to@gmail.com>
48 * @author Zach Copley <zach@status.net>
49 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
50 * @link http://status.net/
53 class ApiTimelineTagAction extends ApiPrivateAuthAction
59 * Take arguments for running
61 * @param array $args $_REQUEST args
63 * @return boolean success flag
67 function prepare($args)
69 parent::prepare($args);
71 common_debug("apitimelinetag prepare()");
73 $this->tag = $this->arg('tag');
74 $this->notices = $this->getNotices();
82 * Just show the notices
84 * @param array $args $_REQUEST data (unused)
89 function handle($args)
91 parent::handle($args);
92 $this->showTimeline();
96 * Show the timeline of notices
101 function showTimeline()
103 $sitename = common_config('site', 'name');
104 $sitelogo = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png');
105 $title = sprintf(_("Notices tagged with %s"), $this->tag);
107 _('Updates tagged with %1$s on %2$s!'),
111 $taguribase = TagURI::base();
112 $id = "tag:$taguribase:TagTimeline:".$tag;
114 $link = common_local_url(
116 array('tag' => $this->tag)
119 $self = $this->getSelfUri();
121 common_debug("self link is: $self");
123 switch($this->format) {
125 $this->showXmlTimeline($this->notices);
128 $this->showRssTimeline(
140 header('Content-Type: application/atom+xml; charset=utf-8');
142 $atom = new AtomNoticeFeed($this->auth_user);
145 $atom->setTitle($title);
146 $atom->setSubtitle($subtitle);
147 $atom->setLogo($logo);
148 $atom->setUpdated('now');
150 $atom->addLink($link);
151 $atom->setSelfLink($self);
153 $atom->addEntryFromNotices($this->notices);
154 $this->raw($atom->getString());
158 $this->showJsonTimeline($this->notices);
161 $this->clientError(_('API method not found.'), $code = 404);
169 * @return array notices
172 function getNotices()
176 $notice = Notice_tag::getStream(
178 ($this->page - 1) * $this->count,
182 while ($notice->fetch()) {
183 $notices[] = clone($notice);
190 * Is this action read only?
192 * @param array $args other arguments
194 * @return boolean true
197 function isReadOnly($args)
203 * When was this feed last modified?
205 * @return string datestamp of the latest notice in the stream
208 function lastModified()
210 if (!empty($this->notices) && (count($this->notices) > 0)) {
211 return strtotime($this->notices[0]->created);
218 * An entity tag for this stream
220 * Returns an Etag based on the action name, language, and
221 * timestamps of the first and last notice in the timeline
223 * @return string etag
228 if (!empty($this->notices) && (count($this->notices) > 0)) {
230 $last = count($this->notices) - 1;
232 return '"' . implode(
234 array($this->arg('action'),
237 strtotime($this->notices[0]->created),
238 strtotime($this->notices[$last]->created))