]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apitimelinegroup.php
Merge branch '0.9.x' of git://gitorious.org/statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / actions / apitimelinegroup.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show a group's notices
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  API
23  * @package   StatusNet
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 StatusNet, Inc.
29  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
30  * @link      http://status.net/
31  */
32
33 if (!defined('STATUSNET')) {
34     exit(1);
35 }
36
37 require_once INSTALLDIR . '/lib/api.php';
38
39 /**
40  * Returns the most recent notices (default 20) posted to the group specified by ID
41  *
42  * @category API
43  * @package  StatusNet
44  * @author   Craig Andrews <candrews@integralblue.com>
45  * @author   Evan Prodromou <evan@status.net>
46  * @author   Jeffery To <jeffery.to@gmail.com>
47  * @author   Zach Copley <zach@status.net>
48  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49  * @link     http://status.net/
50  */
51
52 class ApiTimelineGroupAction extends ApiAction
53 {
54
55     var $group   = null;
56     var $notices = null;
57
58     /**
59      * Take arguments for running
60      *
61      * @param array $args $_REQUEST args
62      *
63      * @return boolean success flag
64      *
65      */
66
67     function prepare($args)
68     {
69         parent::prepare($args);
70
71         $this->group   = $this->getTargetGroup($this->arg('id'));
72         $this->notices = $this->getNotices();
73
74         return true;
75     }
76
77     /**
78      * Handle the request
79      *
80      * Just show the notices
81      *
82      * @param array $args $_REQUEST data (unused)
83      *
84      * @return void
85      */
86
87     function handle($args)
88     {
89         parent::handle($args);
90         $this->showTimeline();
91     }
92
93     /**
94      * Show the timeline of notices
95      *
96      * @return void
97      */
98
99     function showTimeline()
100     {
101         $sitename   = common_config('site', 'name');
102         $title      = sprintf(_("%s timeline"), $this->group->nickname);
103         $taguribase = common_config('integration', 'taguri');
104         $id         = "tag:$taguribase:GroupTimeline:" . $this->group->id;
105         $link       = common_local_url(
106             'showgroup',
107             array('nickname' => $this->group->nickname)
108         );
109         $subtitle   = sprintf(
110             _('Updates from %1$s on %2$s!'),
111             $this->group->nickname,
112             $sitename
113         );
114
115         switch($this->format) {
116         case 'xml':
117             $this->showXmlTimeline($this->notices);
118             break;
119         case 'rss':
120             $this->showRssTimeline($this->notices, $title, $link, $subtitle);
121             break;
122         case 'atom':
123             $selfuri = common_root_url() .
124                 'api/statusnet/groups/timeline/' .
125                     $this->group->nickname . '.atom';
126             $this->showAtomTimeline(
127                 $this->notices,
128                 $title,
129                 $id,
130                 $link,
131                 $subtitle,
132                 null,
133                 $selfuri
134             );
135             break;
136         case 'json':
137             $this->showJsonTimeline($this->notices);
138             break;
139         default:
140             $this->clientError(
141                 _('API method not found!'),
142                 404,
143                 $this->format
144             );
145             break;
146         }
147     }
148
149     /**
150      * Get notices
151      *
152      * @return array notices
153      */
154
155     function getNotices()
156     {
157         $notices = array();
158
159         $notice = $this->group->getNotices(
160             ($this->page-1) * $this->count,
161             $this->count,
162             $this->since_id,
163             $this->max_id,
164             $this->since
165         );
166
167         while ($notice->fetch()) {
168             $notices[] = clone($notice);
169         }
170
171         return $notices;
172     }
173
174     /**
175      * Is this action read only?
176      *
177      * @param array $args other arguments
178      *
179      * @return boolean true
180      */
181
182     function isReadOnly($args)
183     {
184         return true;
185     }
186
187     /**
188      * When was this feed last modified?
189      *
190      * @return string datestamp of the latest notice in the stream
191      */
192
193     function lastModified()
194     {
195         if (!empty($this->notices) && (count($this->notices) > 0)) {
196             return strtotime($this->notices[0]->created);
197         }
198
199         return null;
200     }
201
202     /**
203      * An entity tag for this stream
204      *
205      * Returns an Etag based on the action name, language, group ID and
206      * timestamps of the first and last notice in the timeline
207      *
208      * @return string etag
209      */
210
211     function etag()
212     {
213         if (!empty($this->notices) && (count($this->notices) > 0)) {
214
215             $last = count($this->notices) - 1;
216
217             return '"' . implode(
218                 ':',
219                 array($this->arg('action'),
220                       common_language(),
221                       $this->group->id,
222                       strtotime($this->notices[0]->created),
223                       strtotime($this->notices[$last]->created))
224             )
225             . '"';
226         }
227
228         return null;
229     }
230
231 }