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')) {
39 * Returns the most recent notices (default 20) posted to the group specified by ID
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 ApiTimelineGroupAction extends ApiPrivateAuthAction
56 * Take arguments for running
58 * @param array $args $_REQUEST args
60 * @return boolean success flag
63 function prepare($args)
65 parent::prepare($args);
67 $this->group = $this->getTargetGroup($this->arg('id'));
75 * Just show the notices
77 * @param array $args $_REQUEST data (unused)
81 function handle($args)
83 parent::handle($args);
85 if (empty($this->group)) {
86 // TRANS: Client error displayed requesting most recent notices to a group for a non-existing group.
87 $this->clientError(_('Group not found.'), 404, $this->format);
91 $this->notices = $this->getNotices();
92 $this->showTimeline();
96 * Show the timeline of notices
100 function showTimeline()
102 // We'll pull common formatting out of this for other formats
103 $atom = new AtomGroupNoticeFeed($this->group, $this->auth_user);
105 $self = $this->getSelfUri();
107 $link = common_local_url('showgroup',
108 array('nickname' => $this->group->nickname));
110 switch($this->format) {
112 $this->showXmlTimeline($this->notices);
115 $this->showRssTimeline(
118 $this->group->homeUrl(),
126 header('Content-Type: application/atom+xml; charset=utf-8');
127 $atom->addEntryFromNotices($this->notices);
128 $this->raw($atom->getString());
131 $this->showJsonTimeline($this->notices);
134 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
135 $doc = new ActivityStreamJSONDocument($this->auth_user);
136 $doc->setTitle($atom->title);
137 $doc->addLink($link, 'alternate', 'text/html');
138 $doc->addItemsFromNotices($this->notices);
139 $this->raw($doc->asString());
143 // TRANS: Client error displayed when trying to handle an unknown API method.
144 _('API method not found.'),
155 * @return array notices
157 function getNotices()
161 $notice = $this->group->getNotices(
162 ($this->page-1) * $this->count,
168 while ($notice->fetch()) {
169 $notices[] = clone($notice);
176 * Is this action read only?
178 * @param array $args other arguments
180 * @return boolean true
182 function isReadOnly($args)
188 * When was this feed last modified?
190 * @return string datestamp of the latest notice in the stream
192 function lastModified()
194 if (!empty($this->notices) && (count($this->notices) > 0)) {
195 return strtotime($this->notices[0]->created);
202 * An entity tag for this stream
204 * Returns an Etag based on the action name, language, group ID and
205 * timestamps of the first and last notice in the timeline
207 * @return string etag
211 if (!empty($this->notices) && (count($this->notices) > 0)) {
213 $last = count($this->notices) - 1;
215 return '"' . implode(
217 array($this->arg('action'),
218 common_user_cache_hash($this->auth_user),
221 strtotime($this->notices[0]->created),
222 strtotime($this->notices[$last]->created))