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 protected function prepare(array $args=array())
65 parent::prepare($args);
67 $this->group = $this->getTargetGroup($this->arg('id'));
75 * Just show the notices
79 protected function handle()
83 if (empty($this->group)) {
84 // TRANS: Client error displayed requesting most recent notices to a group for a non-existing group.
85 $this->clientError(_('Group not found.'), 404);
88 $this->notices = $this->getNotices();
89 $this->showTimeline();
93 * Show the timeline of notices
97 function showTimeline()
99 // We'll pull common formatting out of this for other formats
100 $atom = new AtomGroupNoticeFeed($this->group, $this->auth_user);
102 $self = $this->getSelfUri();
104 $link = common_local_url('showgroup',
105 array('nickname' => $this->group->nickname));
107 switch($this->format) {
109 $this->showXmlTimeline($this->notices);
112 $this->showRssTimeline(
115 $this->group->homeUrl(),
123 header('Content-Type: application/atom+xml; charset=utf-8');
124 $atom->addEntryFromNotices($this->notices);
125 $this->raw($atom->getString());
128 $this->showJsonTimeline($this->notices);
131 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
132 $doc = new ActivityStreamJSONDocument($this->auth_user);
133 $doc->setTitle($atom->title);
134 $doc->addLink($link, 'alternate', 'text/html');
135 $doc->addItemsFromNotices($this->notices);
136 $this->raw($doc->asString());
139 // TRANS: Client error displayed when trying to handle an unknown API method.
140 $this->clientError(_('API method not found.'), 404);
147 * @return array notices
149 function getNotices()
153 $notice = $this->group->getNotices(
154 ($this->page-1) * $this->count,
160 while ($notice->fetch()) {
161 $notices[] = clone($notice);
168 * Is this action read only?
170 * @param array $args other arguments
172 * @return boolean true
174 function isReadOnly($args)
180 * When was this feed last modified?
182 * @return string datestamp of the latest notice in the stream
184 function lastModified()
186 if (!empty($this->notices) && (count($this->notices) > 0)) {
187 return strtotime($this->notices[0]->created);
194 * An entity tag for this stream
196 * Returns an Etag based on the action name, language, group ID and
197 * timestamps of the first and last notice in the timeline
199 * @return string etag
203 if (!empty($this->notices) && (count($this->notices) > 0)) {
205 $last = count($this->notices) - 1;
207 return '"' . implode(
209 array($this->arg('action'),
210 common_user_cache_hash($this->auth_user),
213 strtotime($this->notices[0]->created),
214 strtotime($this->notices[$last]->created))