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 Zach Copley <zach@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR . '/lib/api.php';
37 * Returns the most recent notices (default 20) posted to the group specified by ID
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
46 class ApiTimelineGroupAction extends ApiAction
53 * Take arguments for running
55 * @param array $args $_REQUEST args
57 * @return boolean success flag
61 function prepare($args)
63 parent::prepare($args);
65 $this->group = $this->getTargetGroup($this->arg('id'));
66 $this->notices = $this->getNotices();
74 * Just show the notices
76 * @param array $args $_REQUEST data (unused)
81 function handle($args)
83 parent::handle($args);
84 $this->showTimeline();
88 * Show the timeline of notices
93 function showTimeline()
95 $sitename = common_config('site', 'name');
96 $title = sprintf(_("%s timeline"), $this->group->nickname);
97 $taguribase = common_config('integration', 'taguri');
98 $id = "tag:$taguribase:GroupTimeline:" . $this->group->id;
99 $link = common_local_url(
101 array('nickname' => $this->group->nickname)
104 _('Updates from %1$s on %2$s!'),
105 $this->group->nickname,
109 switch($this->format) {
111 $this->showXmlTimeline($this->notices);
114 $this->showRssTimeline($this->notices, $title, $link, $subtitle);
117 $selfuri = common_root_url() .
118 'api/statusnet/groups/timeline/' .
119 $this->group->nickname . '.atom';
120 $this->showAtomTimeline(
131 $this->showJsonTimeline($this->notices);
135 _('API method not found!'),
146 * @return array notices
149 function getNotices()
153 $notice = $this->group->getNotices(
154 ($this->page-1) * $this->count,
161 while ($notice->fetch()) {
162 $notices[] = clone($notice);
169 * Is this action read only?
171 * @param array $args other arguments
173 * @return boolean true
176 function isReadOnly($args)
182 * When was this feed last modified?
184 * @return string datestamp of the latest notice in the stream
187 function lastModified()
189 if (!empty($this->notices) && (count($this->notices) > 0)) {
190 return strtotime($this->notices[0]->created);
197 * An entity tag for this stream
199 * Returns an Etag based on the action name, language, group ID and
200 * timestamps of the first and last notice in the timeline
202 * @return string etag
207 if (!empty($this->notices) && (count($this->notices) > 0)) {
209 $last = count($this->notices) - 1;
211 return '"' . implode(
213 array($this->arg('action'),
216 strtotime($this->notices[0]->created),
217 strtotime($this->notices[$last]->created))