]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/twitapistatuses.php
3a495a1296d8d1e808438b92f7fcb9a41e659f4f
[quix0rs-gnu-social.git] / actions / twitapistatuses.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/twitterapi.php');
23
24 /* XXX: Please don't freak out about all the ugly comments in this file.
25  * They are mostly in here for reference while I work on the
26  * API. I'll fix things up to make them look better later. -- Zach 
27  */
28 class TwitapistatusesAction extends TwitterapiAction {
29         
30         /*
31          *  Returns the 20 most recent statuses from non-protected users who have set a custom
32          *  user icon. Does not require authentication.
33          *      
34          *      URL: http://identi.ca/api/statuses/public_timeline.format
35      *
36          *      Formats: xml, json, rss, atom
37          */
38         function public_timeline($args, $apidata) {
39                 parent::handle($args);
40
41                 $notice = DB_DataObject::factory('notice');
42
43                 # FIXME: bad performance
44                 $notice->whereAdd('EXISTS (SELECT user.id from user where user.id = notice.profile_id)');
45                 $notice->orderBy('created DESC, notice.id DESC');
46                 $notice->limit(20);
47                 $cnt = $notice->find();
48
49                 if ($apidata['content-type'] == 'xml') {
50                         
51                         header('Content-Type: application/xml; charset=utf-8');         
52                         
53                         common_start_xml();
54
55                         // XXX: To really live up to the spec we need to build a list
56                         // of notices by users who have custom avatars -- Zach
57                         if ($cnt > 0) {
58                                 common_element_start('statuses', array('type' => 'array'));
59                                 for ($i = 0; $i < 20; $i++) {
60                                         if ($notice->fetch()) {
61                                                 $twitter_status = $this->twitter_status_array($notice);                                         
62                                                 $this->render_twitter_xml_status($twitter_status);
63                                         } else {
64                                                 // shouldn't happen!
65                                                 break;
66                                         }
67                                 }
68                                 common_element_end('statuses');
69                         }
70                 
71                         common_end_xml();
72                 } elseif ($apidata['content-type'] == 'rss') {
73                         
74                         header("Content-Type: application/rss+xml; charset=utf-8");
75
76                         $this->init_twitter_rss();
77                         
78                         $sitename = common_config('site', 'name');
79                         $siteserver = common_config('site', 'server'); 
80                         
81                         common_element_start('channel');
82                         common_element('title', NULL, "$sitename public timeline");
83                         common_element('link', NULL, "http://$siteserver");
84                         common_element('description', NULL, "$sitename updates from everyone!");
85                         common_element('language', NULL, 'en-us');
86                         common_element('ttl', NULL, '40');
87                         
88                         if ($cnt > 0) {
89                                 for ($i = 0; $i < 20; $i++) {
90                                         if ($notice->fetch()) {
91                                                 $entry = $this->twitter_rss_entry_array($notice);                                               
92                                                 $this->show_twitter_rss_item($entry);
93                                         } else {
94                                                 // shouldn't happen!
95                                                 break;
96                                         }
97                                 }
98                         }
99                         common_element_end('channel');
100                                                 
101                         $this->end_twitter_rss();
102
103                 } elseif ($apidata['content-type'] == 'atom') {
104                         common_server_error("API method under construction.", $code=501);       
105                 } elseif ($apidata['content-type'] == 'json') {
106
107                         header('Content-Type: application/json; charset=utf-8');
108
109                         $statuses = array();
110                         
111                         if ($cnt > 0) {
112                                 for ($i = 0; $i < 20; $i++) {
113                                         if ($notice->fetch()) {
114                                                 $twitter_status = $this->twitter_status_array($notice);
115                                                 array_push($statuses, $twitter_status);                                         
116                                         } else {
117                                                 // shouldn't happen!
118                                                 break;
119                                         }
120                                 }                               
121                         }
122                         $this->render_twitter_json_statuses($statuses);                 
123                 }
124
125                 exit();
126         }       
127         
128
129                 
130         /*
131         Returns the 20 most recent statuses posted by the authenticating user and that user's friends. 
132         This is the equivalent of /home on the Web. 
133         
134         URL: http://identi.ca/api/statuses/friends_timeline.format
135         
136         Parameters:
137
138             * since.  Optional.  Narrows the returned results to just those statuses created after the specified 
139                         HTTP-formatted date.  The same behavior is available by setting an If-Modified-Since header in 
140                         your HTTP request.  
141                         Ex: http://identi.ca/api/statuses/friends_timeline.rss?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
142             * since_id.  Optional.  Returns only statuses with an ID greater than (that is, more recent than) 
143                         the specified ID.  Ex: http://identi.ca/api/statuses/friends_timeline.xml?since_id=12345
144             * count.  Optional.  Specifies the number of statuses to retrieve. May not be greater than 200.
145                         Ex: http://identi.ca/api/statuses/friends_timeline.xml?count=5 
146             * page. Optional. Ex: http://identi.ca/api/statuses/friends_timeline.rss?page=3
147         
148         Formats: xml, json, rss, atom
149         */
150         function friends_timeline($args, $apidata) {
151                 parent::handle($args);
152
153                 $since = $this->arg('since');
154                 $since_id = $this->arg('since_id');
155                 $count = $this->arg('count');
156                 $page = $this->arg('page');
157
158                 print "Friends Timeline! requested content-type: " . $apidata['content-type'] . "\n";
159                 print "since: $since, since_id: $since_id, count: $count, page: $page\n";
160                 
161                 exit();
162                 
163         }
164         
165         /*
166                 Returns the 20 most recent statuses posted from the authenticating user. It's also possible to
167         request another user's timeline via the id parameter below. This is the equivalent of the Web
168         /archive page for your own user, or the profile page for a third party.
169
170                 URL: http://identi.ca/api/statuses/user_timeline.format
171
172                 Formats: xml, json, rss, atom
173
174                 Parameters:
175
176                     * id. Optional. Specifies the ID or screen name of the user for whom to return the
177             friends_timeline. Ex: http://identi.ca/api/statuses/user_timeline/12345.xml or
178             http://identi.ca/api/statuses/user_timeline/bob.json. 
179                         * count. Optional. Specifies the number of
180             statuses to retrieve. May not be greater than 200. Ex:
181             http://identi.ca/api/statuses/user_timeline.xml?count=5 
182                         * since. Optional. Narrows the returned
183             results to just those statuses created after the specified HTTP-formatted date. The same
184             behavior is available by setting an If-Modified-Since header in your HTTP request. Ex:
185             http://identi.ca/api/statuses/user_timeline.rss?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT 
186                         * since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than)
187             the specified ID. Ex: http://identi.ca/api/statuses/user_timeline.xml?since_id=12345 * page.
188             Optional. Ex: http://identi.ca/api/statuses/friends_timeline.rss?page=3
189         */
190         function user_timeline($args, $apidata) {
191                 parent::handle($args);
192                 
193                 $id = $this->arg('id');
194                 $count = $this->arg('count');
195                 $since = $this->arg('since');
196                 $since_id = $this->arg('since_id');
197                 
198                 print "User Timeline! requested content-type: " . $apidata['content-type'] . "\n";
199                 print "id: $id since: $since, since_id: $since_id, count: $count\n";
200                 
201                 exit(); 
202         }
203         
204         /*
205                 Returns a single status, specified by the id parameter below. The status's author will be returned inline.
206                 
207                  URL: http://identi.ca/api/statuses/show/id.format
208                 
209                  Formats: xml, json
210                 
211                  Parameters:
212                 
213                  * id. Required. The numerical ID of the status you're trying to retrieve. 
214                  Ex: http://identi.ca/api/statuses/show/123.xml
215         */
216         function show($args, $apidata) {
217                 parent::handle($args);
218
219                 $id = $this->arg('id');
220                 
221                 print "show requested content-type: " . $apidata['content-type'] . "\n";
222                 print "id: $id\n";
223                 
224                 exit();
225                 
226         }
227         
228         /*
229                 Updates the authenticating user's status.  Requires the status parameter specified below.  Request must be a POST.
230
231                 URL: http://identi.ca/api/statuses/update.format
232
233                 Formats: xml, json.  Returns the posted status in requested format when successful.
234
235                 Parameters:
236
237                     * status. Required. The text of your status update. Be sure to URL encode as necessary. Must not be more than 160
238             characters and should not be more than 140 characters to ensure optimal display.
239
240         */
241         function update($args, $apidata) {
242                 parent::handle($args);
243                 common_server_error("API method under construction.", $code=501);
244         }
245         
246         /*
247                 Returns the 20 most recent @replies (status updates prefixed with @username) for the authenticating user.
248                 URL: http://identi.ca/api/statuses/replies.format
249                 
250                 Formats: xml, json, rss, atom
251
252                 Parameters:
253
254                 * page. Optional. Retrieves the 20 next most recent replies. Ex: http://identi.ca/api/statuses/replies.xml?page=3 
255                 * since. Optional. Narrows the returned results to just those replies created after the specified HTTP-formatted date. The
256         same behavior is available by setting an If-Modified-Since header in your HTTP request. Ex:
257         http://identi.ca/api/statuses/replies.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
258                 * since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than) the specified
259                 ID. Ex: http://identi.ca/api/statuses/replies.xml?since_id=12345
260         */
261         function replies($args, $apidata) {
262                 parent::handle($args);
263                 common_server_error("API method under construction.", $code=501);
264         }
265         
266         
267         /*
268                 Destroys the status specified by the required ID parameter. The authenticating user must be
269         the author of the specified status.
270                 
271                  URL: http://identi.ca/api/statuses/destroy/id.format
272                 
273                  Formats: xml, json
274                 
275                  Parameters:
276                 
277                  * id. Required. The ID of the status to destroy. Ex:
278                 http://identi.ca/api/statuses/destroy/12345.json or
279                 http://identi.ca/api/statuses/destroy/23456.xml
280         
281         */
282         function destroy($args, $apidata) {
283                 parent::handle($args);
284                 common_server_error("API method under construction.", $code=501);
285         }
286         
287         # User Methods
288         
289         /*
290                 Returns up to 100 of the authenticating user's friends who have most recently updated, each with current status inline.
291         It's also possible to request another user's recent friends list via the id parameter below.
292                 
293                  URL: http://identi.ca/api/statuses/friends.format
294                 
295                  Formats: xml, json
296                 
297                  Parameters:
298                 
299                  * id. Optional. The ID or screen name of the user for whom to request a list of friends. Ex:
300                 http://identi.ca/api/statuses/friends/12345.json 
301                         or 
302                         http://identi.ca/api/statuses/friends/bob.xml
303                  * page. Optional. Retrieves the next 100 friends. Ex: http://identi.ca/api/statuses/friends.xml?page=2
304                  * lite. Optional. Prevents the inline inclusion of current status. Must be set to a value of true. Ex:
305                 http://identi.ca/api/statuses/friends.xml?lite=true
306                  * since. Optional. Narrows the returned results to just those friendships created after the specified
307                         HTTP-formatted date. The same behavior is available by setting an If-Modified-Since header in your HTTP
308                         request. Ex: http://identi.ca/api/statuses/friends.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
309         */
310         function friends($args, $apidata) {
311                 parent::handle($args);
312                 common_server_error("API method under construction.", $code=501);
313         }
314         
315         /*
316                 Returns the authenticating user's followers, each with current status inline. They are ordered by the
317                 order in which they joined Twitter (this is going to be changed).
318                 
319                 URL: http://identi.ca/api/statuses/followers.format
320                 Formats: xml, json
321
322                 Parameters: 
323
324                     * id. Optional. The ID or screen name of the user for whom to request a list of followers. Ex:
325                 http://identi.ca/api/statuses/followers/12345.json 
326                                 or 
327                                 http://identi.ca/api/statuses/followers/bob.xml
328                     * page. Optional. Retrieves the next 100 followers. Ex: http://identi.ca/api/statuses/followers.xml?page=2   
329                     * lite. Optional. Prevents the inline inclusion of current status. Must be set to a value of true.
330                                 Ex: http://identi.ca/api/statuses/followers.xml?lite=true
331         */
332         function followers($args, $apidata) {
333                 parent::handle($args);
334                 common_server_error("API method under construction.", $code=501);
335         }
336         
337         /*
338         Returns a list of the users currently featured on the site with their current statuses inline. 
339         URL: http://identi.ca/api/statuses/featured.format 
340
341         Formats: xml, json
342         */
343         function featured($args, $apidata) {
344                 parent::handle($args);
345                 common_server_error("API method under construction.", $code=501);
346         }
347         
348 }
349
350