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/twitterapi.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 TwitterapiAction
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->format = $this->arg('format');
74 $this->notices = $this->getNotices();
82 * Just show the notices
84 * @param array $args $_REQUEST data (unused)
89 function handle($args)
91 parent::handle($args);
92 $this->showTimeline();
96 * Show the timeline of notices
101 function showTimeline()
103 $sitename = common_config('site', 'name');
104 $title = sprintf(_("%s timeline"), $this->group->nickname);
105 $taguribase = common_config('integration', 'taguri');
106 $id = "tag:$taguribase:GroupTimeline:" . $this->group->id;
107 $link = common_local_url(
109 array('nickname' => $this->group->nickname)
112 _('Updates from %1$s on %2$s!'),
113 $this->group->nickname,
117 switch($this->format) {
119 $this->show_xml_timeline($this->notices);
122 $this->show_rss_timeline($this->notices, $title, $link, $subtitle);
125 $selfuri = common_root_url() .
126 'api/statusnet/groups/timeline/' .
127 $this->group->nickname . '.atom';
128 $this->show_atom_timeline(
139 $this->show_json_timeline($this->notices);
143 _('API method not found!'),
154 * @return array notices
157 function getNotices()
161 $notice = $this->group->getNotices(
162 ($this->page-1) * $this->count,
169 while ($notice->fetch()) {
170 $notices[] = clone($notice);
177 * Is this action read only?
179 * @param array $args other arguments
181 * @return boolean true
184 function isReadOnly($args)
190 * When was this feed last modified?
192 * @return string datestamp of the latest notice in the stream
195 function lastModified()
197 if (!empty($this->notices) && (count($this->notices) > 0)) {
198 return strtotime($this->notices[0]->created);
205 * An entity tag for this stream
207 * Returns an Etag based on the action name, language, group ID and
208 * timestamps of the first and last notice in the timeline
210 * @return string etag
215 if (!empty($this->notices) && (count($this->notices) > 0)) {
217 $last = count($this->notices) - 1;
219 return '"' . implode(
221 array($this->arg('action'),
224 strtotime($this->notices[0]->created),
225 strtotime($this->notices[$last]->created))