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-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 most recent notices (default 20) posted to the group specified by ID
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/
52 class ApiTimelineGroupAction extends ApiPrivateAuthAction
58 * Take arguments for running
60 * @param array $args $_REQUEST args
62 * @return boolean success flag
65 function prepare($args)
67 parent::prepare($args);
69 $this->group = $this->getTargetGroup($this->arg('id'));
77 * Just show the notices
79 * @param array $args $_REQUEST data (unused)
83 function handle($args)
85 parent::handle($args);
87 if (empty($this->group)) {
88 // TRANS: Client error displayed requesting most recent notices to a group for a non-existing group.
89 $this->clientError(_('Group not found.'), 404, $this->format);
93 $this->notices = $this->getNotices();
94 $this->showTimeline();
98 * Show the timeline of notices
102 function showTimeline()
104 // We'll pull common formatting out of this for other formats
105 $atom = new AtomGroupNoticeFeed($this->group, $this->auth_user);
107 $self = $this->getSelfUri();
109 switch($this->format) {
111 $this->showXmlTimeline($this->notices);
114 $this->showRssTimeline(
117 $this->group->homeUrl(),
125 header('Content-Type: application/atom+xml; charset=utf-8');
128 $atom->addAuthorRaw($this->group->asAtomAuthor());
129 $atom->setActivitySubject($this->group->asActivitySubject());
131 $atom->setSelfLink($self);
132 $atom->addEntryFromNotices($this->notices);
133 $this->raw($atom->getString());
134 } catch (Atom10FeedException $e) {
136 // TRANS: Server error displayed when generating an Atom feed fails.
137 // TRANS: %s is the error.
138 sprintf(_('Could not generate feed for group - %s'),$e->getMessage()),
146 $this->showJsonTimeline($this->notices);
150 // TRANS: Client error displayed when trying to handle an unknown API method.
151 _('API method not found.'),
162 * @return array notices
164 function getNotices()
168 $notice = $this->group->getNotices(
169 ($this->page-1) * $this->count,
175 while ($notice->fetch()) {
176 $notices[] = clone($notice);
183 * Is this action read only?
185 * @param array $args other arguments
187 * @return boolean true
189 function isReadOnly($args)
195 * When was this feed last modified?
197 * @return string datestamp of the latest notice in the stream
199 function lastModified()
201 if (!empty($this->notices) && (count($this->notices) > 0)) {
202 return strtotime($this->notices[0]->created);
209 * An entity tag for this stream
211 * Returns an Etag based on the action name, language, group ID and
212 * timestamps of the first and last notice in the timeline
214 * @return string etag
218 if (!empty($this->notices) && (count($this->notices) > 0)) {
220 $last = count($this->notices) - 1;
222 return '"' . implode(
224 array($this->arg('action'),
225 common_user_cache_hash($this->auth_user),
228 strtotime($this->notices[0]->created),
229 strtotime($this->notices[$last]->created))