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->page = (int)$this->arg('page', 1);
66 $this->count = (int)$this->arg('count', 20);
67 $this->max_id = (int)$this->arg('max_id', 0);
68 $this->since_id = (int)$this->arg('since_id', 0);
69 $this->since = $this->arg('since');
71 $this->group = $this->getTargetGroup($this->arg('id'));
73 $this->notices = $this->getNotices();
81 * Just show the notices
83 * @param array $args $_REQUEST data (unused)
88 function handle($args)
90 parent::handle($args);
91 $this->showTimeline();
95 * Show the timeline of notices
100 function showTimeline()
102 $sitename = common_config('site', 'name');
103 $title = sprintf(_("%s timeline"), $this->group->nickname);
104 $taguribase = common_config('integration', 'taguri');
105 $id = "tag:$taguribase:GroupTimeline:" . $this->group->id;
106 $link = common_local_url(
108 array('nickname' => $this->group->nickname)
111 _('Updates from %1$s on %2$s!'),
112 $this->group->nickname,
116 switch($this->format) {
118 $this->show_xml_timeline($this->notices);
121 $this->show_rss_timeline($this->notices, $title, $link, $subtitle);
124 $selfuri = common_root_url() .
125 'api/statusnet/groups/timeline/' .
126 $this->group->nickname . '.atom';
127 $this->show_atom_timeline(
138 $this->show_json_timeline($this->notices);
142 _('API method not found!'),
153 * @return array notices
156 function getNotices()
160 $notice = $this->group->getNotices(
161 ($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
183 function isReadOnly($args)
189 * When was this feed last modified?
191 * @return string datestamp of the latest notice in the stream
194 function lastModified()
196 if (!empty($this->notices) && (count($this->notices) > 0)) {
197 return strtotime($this->notices[0]->created);
204 * An entity tag for this stream
206 * Returns an Etag based on the action name, language, group ID and
207 * timestamps of the first and last notice in the timeline
209 * @return string etag
214 if (!empty($this->notices) && (count($this->notices) > 0)) {
216 $last = count($this->notices) - 1;
218 return '"' . implode(
220 array($this->arg('action'),
223 strtotime($this->notices[0]->created),
224 strtotime($this->notices[$last]->created))