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')) {
39 * Returns the 20 most recent notices tagged by a given tag
43 * @author Craig Andrews <candrews@integralblue.com>
44 * @author Evan Prodromou <evan@status.net>
45 * @author Jeffery To <jeffery.to@gmail.com>
46 * @author Zach Copley <zach@status.net>
47 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48 * @link http://status.net/
50 class ApiTimelineTagAction extends ApiPrivateAuthAction
54 protected function prepare(array $args=array())
56 parent::prepare($args);
58 $this->tag = $this->arg('tag');
59 $this->notices = $this->getNotices();
67 * Just show the notices
69 * @param array $args $_REQUEST data (unused)
73 protected function handle()
76 $this->showTimeline();
80 * Show the timeline of notices
84 function showTimeline()
86 $sitename = common_config('site', 'name');
87 $sitelogo = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png');
88 // TRANS: Title for timeline with lastest notices with a given tag.
89 // TRANS: %s is the tag.
90 $title = sprintf(_("Notices tagged with %s"), $this->tag);
92 // TRANS: Subtitle for timeline with lastest notices with a given tag.
93 // TRANS: %1$s is the tag, $2$s is the StatusNet sitename.
94 _('Updates tagged with %1$s on %2$s!'),
98 $taguribase = TagURI::base();
99 $id = "tag:$taguribase:TagTimeline:".$this->tag;
101 $link = common_local_url(
103 array('tag' => $this->tag)
106 $self = $this->getSelfUri();
108 switch($this->format) {
110 $this->showXmlTimeline($this->notices);
113 $this->showRssTimeline(
124 header('Content-Type: application/atom+xml; charset=utf-8');
126 $atom = new AtomNoticeFeed($this->auth_user);
129 $atom->setTitle($title);
130 $atom->setSubtitle($subtitle);
131 $atom->setLogo($sitelogo);
132 $atom->setUpdated('now');
134 $atom->addLink($link);
135 $atom->setSelfLink($self);
137 $atom->addEntryFromNotices($this->notices);
138 $this->raw($atom->getString());
142 $this->showJsonTimeline($this->notices);
145 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
146 $doc = new ActivityStreamJSONDocument($this->auth_user);
147 $doc->setTitle($title);
148 $doc->addLink($link, 'alternate', 'text/html');
149 $doc->addItemsFromNotices($this->notices);
150 $this->raw($doc->asString());
153 // TRANS: Client error displayed when coming across a non-supported API method.
154 $this->clientError(_('API method not found.'), $code = 404);
162 * @return array notices
164 function getNotices()
166 $notice = Notice_tag::getStream($this->tag)->getNotices(($this->page - 1) * $this->count,
171 return $notice->fetchAll();
175 * Is this action read only?
177 * @param array $args other arguments
179 * @return boolean true
181 function isReadOnly(array $args=array())
187 * When was this feed last modified?
189 * @return string datestamp of the latest notice in the stream
191 function lastModified()
193 if (!empty($this->notices) && (count($this->notices) > 0)) {
194 return strtotime($this->notices[0]->created);
201 * An entity tag for this stream
203 * Returns an Etag based on the action name, language, and
204 * timestamps of the first and last notice in the timeline
206 * @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'),
217 common_user_cache_hash($this->auth_user),
220 strtotime($this->notices[0]->created),
221 strtotime($this->notices[$last]->created))