3 * StatusNet, the distributed open-source microblogging tool
5 * Show a group's notices
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 most recent notices (default 20) posted to the group specified by ID
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 ApiTimelineGroupAction 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 $this->group = $this->getTargetGroup($this->arg('id'));
79 * Just show the notices
81 * @param array $args $_REQUEST data (unused)
86 function handle($args)
88 parent::handle($args);
90 if (empty($this->group)) {
91 $this->clientError(_('Group not found!'), 404, $this->format);
95 $this->notices = $this->getNotices();
96 $this->showTimeline();
100 * Show the timeline of notices
105 function showTimeline()
107 $sitename = common_config('site', 'name');
108 $avatar = $this->group->homepage_logo;
109 $title = sprintf(_("%s timeline"), $this->group->nickname);
110 $taguribase = TagURI::base();
111 $id = "tag:$taguribase:GroupTimeline:" . $this->group->id;
114 _('Updates from %1$s on %2$s!'),
115 $this->group->nickname,
119 $logo = ($avatar) ? $avatar : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
121 switch($this->format) {
123 $this->showXmlTimeline($this->notices);
126 $this->showRssTimeline(
129 $this->group->homeUrl(),
137 header('Content-Type: application/atom+xml; charset=utf-8');
141 // If this was called using an integer ID, i.e.: using the canonical
142 // URL for this group's feed, then pass the Group object into the feed,
143 // so the OStatus plugin, and possibly other plugins, can access it.
144 // Feels sorta hacky. -- Z
147 $id = $this->arg('id');
149 if (strval(intval($id)) === strval($id)) {
150 $atom = new AtomGroupNoticeFeed($this->group);
152 $atom = new AtomGroupNoticeFeed();
156 $atom->setTitle($title);
157 $atom->setSubtitle($subtitle);
158 $atom->setLogo($logo);
159 $atom->setUpdated('now');
161 $atom->addAuthorRaw($this->group->asAtomAuthor());
162 $atom->setActivitySubject($this->group->asActivitySubject());
164 $atom->addLink($this->group->homeUrl());
166 $id = $this->arg('id');
167 $aargs = array('format' => 'atom');
173 $this->getSelfUri('ApiTimelineGroup', $aargs),
174 array('rel' => 'self', 'type' => 'application/atom+xml')
177 $atom->addEntryFromNotices($this->notices);
179 //$this->raw($atom->getString());
180 print $atom->getString(); // temp hack until PuSH feeds are redone cleanly
182 } catch (Atom10FeedException $e) {
184 'Could not generate feed for group - ' . $e->getMessage()
191 $this->showJsonTimeline($this->notices);
195 _('API method not found.'),
206 * @return array notices
209 function getNotices()
213 $notice = $this->group->getNotices(
214 ($this->page-1) * $this->count,
221 while ($notice->fetch()) {
222 $notices[] = clone($notice);
229 * Is this action read only?
231 * @param array $args other arguments
233 * @return boolean true
236 function isReadOnly($args)
242 * When was this feed last modified?
244 * @return string datestamp of the latest notice in the stream
247 function lastModified()
249 if (!empty($this->notices) && (count($this->notices) > 0)) {
250 return strtotime($this->notices[0]->created);
257 * An entity tag for this stream
259 * Returns an Etag based on the action name, language, group ID and
260 * timestamps of the first and last notice in the timeline
262 * @return string etag
267 if (!empty($this->notices) && (count($this->notices) > 0)) {
269 $last = count($this->notices) - 1;
271 return '"' . implode(
273 array($this->arg('action'),
276 strtotime($this->notices[0]->created),
277 strtotime($this->notices[$last]->created))