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 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 $this->tag = $this->arg('tag');
71 $this->notices = $this->getNotices();
79 * Just show the notices
81 * @param array $args $_REQUEST data (unused)
86 function handle($args)
88 parent::handle($args);
89 $this->showTimeline();
93 * Show the timeline of notices
98 function showTimeline()
100 $sitename = common_config('site', 'name');
101 $sitelogo = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png');
102 $title = sprintf(_("Notices tagged with %s"), $this->tag);
104 _('Updates tagged with %1$s on %2$s!'),
108 $taguribase = TagURI::base();
109 $id = "tag:$taguribase:TagTimeline:".$tag;
111 switch($this->format) {
113 $this->showXmlTimeline($this->notices);
116 $link = common_local_url(
118 array('tag' => $this->tag)
120 $this->showRssTimeline(
131 header('Content-Type: application/atom+xml; charset=utf-8');
133 $atom = new AtomNoticeFeed();
136 $atom->setTitle($title);
137 $atom->setSubtitle($subtitle);
138 $atom->setLogo($logo);
139 $atom->setUpdated('now');
144 array('tag' => $this->tag)
148 $aargs = array('format' => 'atom');
149 if (!empty($this->tag)) {
150 $aargs['tag'] = $this->tag;
154 $this->getSelfUri('ApiTimelineTag', $aargs),
155 array('rel' => 'self', 'type' => 'application/atom+xml')
158 $atom->addEntryFromNotices($this->notices);
159 $this->raw($atom->getString());
163 $this->showJsonTimeline($this->notices);
166 $this->clientError(_('API method not found.'), $code = 404);
174 * @return array notices
177 function getNotices()
181 $notice = Notice_tag::getStream(
183 ($this->page - 1) * $this->count,
187 while ($notice->fetch()) {
188 $notices[] = clone($notice);
195 * Is this action read only?
197 * @param array $args other arguments
199 * @return boolean true
202 function isReadOnly($args)
208 * When was this feed last modified?
210 * @return string datestamp of the latest notice in the stream
213 function lastModified()
215 if (!empty($this->notices) && (count($this->notices) > 0)) {
216 return strtotime($this->notices[0]->created);
223 * An entity tag for this stream
225 * Returns an Etag based on the action name, language, and
226 * timestamps of the first and last notice in the timeline
228 * @return string etag
233 if (!empty($this->notices) && (count($this->notices) > 0)) {
235 $last = count($this->notices) - 1;
237 return '"' . implode(
239 array($this->arg('action'),
242 strtotime($this->notices[0]->created),
243 strtotime($this->notices[$last]->created))