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