]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/twitapistatuses.php
d18543e041372717cf7adf84b9ddf96936e973c5
[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                 if ($apidata['content-type'] == 'xml') {
42                         header('Content-Type: application/xml; charset=utf-8');         
43                         $notice = DB_DataObject::factory('notice');
44
45                         # FIXME: bad performance
46                         $notice->whereAdd('EXISTS (SELECT user.id from user where user.id = notice.profile_id)');
47                         $notice->orderBy('created DESC, notice.id DESC');
48                         $notice->limit(20);
49                         $cnt = $notice->find();
50
51                         common_start_xml();
52
53                         // XXX: To really live up to the spec we need to build a list
54                         // of notices by users who have custom avatars
55                         if ($cnt > 0) {
56                                 common_element_start('statuses', array('type' => 'array'));
57                                 for ($i = 0; $i < 20; $i++) {
58                                         if ($notice->fetch()) {
59                                                 $this->render_xml_status($notice);
60                                         } else {
61                                                 // shouldn't happen!
62                                                 break;
63                                         }
64                                 }
65                                 common_element_end('statuses');
66                         }
67                 
68                         common_end_xml();
69                 } elseif ($apidata['content-type'] == 'rss') {
70                         common_server_error("API method under construction.", $code=501);
71                 } elseif ($apidata['content-type'] == 'atom') {
72                         common_server_error("API method under construction.", $code=501);       
73                 } elseif ($apidata['content-type'] == 'json') {
74                         common_server_error("API method under construction.", $code=501);
75                 }
76
77                 exit();
78         }       
79         
80
81                 
82         /*
83         Returns the 20 most recent statuses posted by the authenticating user and that user's friends. 
84         This is the equivalent of /home on the Web. 
85         
86         URL: http://identi.ca/api/statuses/friends_timeline.format
87         
88         Parameters:
89
90             * since.  Optional.  Narrows the returned results to just those statuses created after the specified 
91                         HTTP-formatted date.  The same behavior is available by setting an If-Modified-Since header in 
92                         your HTTP request.  
93                         Ex: http://identi.ca/api/statuses/friends_timeline.rss?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
94             * since_id.  Optional.  Returns only statuses with an ID greater than (that is, more recent than) 
95                         the specified ID.  Ex: http://identi.ca/api/statuses/friends_timeline.xml?since_id=12345
96             * count.  Optional.  Specifies the number of statuses to retrieve. May not be greater than 200.
97                         Ex: http://identi.ca/api/statuses/friends_timeline.xml?count=5 
98             * page. Optional. Ex: http://identi.ca/api/statuses/friends_timeline.rss?page=3
99         
100         Formats: xml, json, rss, atom
101         */
102         function friends_timeline($args, $apidata) {
103                 parent::handle($args);
104
105                 $since = $this->arg('since');
106                 $since_id = $this->arg('since_id');
107                 $count = $this->arg('count');
108                 $page = $this->arg('page');
109
110                 print "Friends Timeline! requested content-type: " . $apidata['content-type'] . "\n";
111                 print "since: $since, since_id: $since_id, count: $count, page: $page\n";
112                 
113                 exit();
114                 
115         }
116         
117         /*
118                 Returns the 20 most recent statuses posted from the authenticating user. It's also possible to
119         request another user's timeline via the id parameter below. This is the equivalent of the Web
120         /archive page for your own user, or the profile page for a third party.
121
122                 URL: http://identi.ca/api/statuses/user_timeline.format
123
124                 Formats: xml, json, rss, atom
125
126                 Parameters:
127
128                     * id. Optional. Specifies the ID or screen name of the user for whom to return the
129             friends_timeline. Ex: http://identi.ca/api/statuses/user_timeline/12345.xml or
130             http://identi.ca/api/statuses/user_timeline/bob.json. 
131                         * count. Optional. Specifies the number of
132             statuses to retrieve. May not be greater than 200. Ex:
133             http://identi.ca/api/statuses/user_timeline.xml?count=5 
134                         * since. Optional. Narrows the returned
135             results to just those statuses created after the specified HTTP-formatted date. The same
136             behavior is available by setting an If-Modified-Since header in your HTTP request. Ex:
137             http://identi.ca/api/statuses/user_timeline.rss?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT 
138                         * since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than)
139             the specified ID. Ex: http://identi.ca/api/statuses/user_timeline.xml?since_id=12345 * page.
140             Optional. Ex: http://identi.ca/api/statuses/friends_timeline.rss?page=3
141         */
142         function user_timeline($args, $apidata) {
143                 parent::handle($args);
144                 
145                 $id = $this->arg('id');
146                 $count = $this->arg('count');
147                 $since = $this->arg('since');
148                 $since_id = $this->arg('since_id');
149                 
150                 print "User Timeline! requested content-type: " . $apidata['content-type'] . "\n";
151                 print "id: $id since: $since, since_id: $since_id, count: $count\n";
152                 
153                 exit(); 
154         }
155         
156         /*
157                 Returns a single status, specified by the id parameter below. The status's author will be returned inline.
158                 
159                  URL: http://identi.ca/api/statuses/show/id.format
160                 
161                  Formats: xml, json
162                 
163                  Parameters:
164                 
165                  * id. Required. The numerical ID of the status you're trying to retrieve. 
166                  Ex: http://identi.ca/api/statuses/show/123.xml
167         */
168         function show($args, $apidata) {
169                 parent::handle($args);
170
171                 $id = $this->arg('id');
172                 
173                 print "show requested content-type: " . $apidata['content-type'] . "\n";
174                 print "id: $id\n";
175                 
176                 exit();
177                 
178         }
179         
180         /*
181                 Updates the authenticating user's status.  Requires the status parameter specified below.  Request must be a POST.
182
183                 URL: http://identi.ca/api/statuses/update.format
184
185                 Formats: xml, json.  Returns the posted status in requested format when successful.
186
187                 Parameters:
188
189                     * status. Required. The text of your status update. Be sure to URL encode as necessary. Must not be more than 160
190             characters and should not be more than 140 characters to ensure optimal display.
191
192         */
193         function update($args, $apidata) {
194                 parent::handle($args);
195                 common_server_error("API method under construction.", $code=501);
196         }
197         
198         /*
199                 Returns the 20 most recent @replies (status updates prefixed with @username) for the authenticating user.
200                 URL: http://identi.ca/api/statuses/replies.format
201                 
202                 Formats: xml, json, rss, atom
203
204                 Parameters:
205
206                 * page. Optional. Retrieves the 20 next most recent replies. Ex: http://identi.ca/api/statuses/replies.xml?page=3 
207                 * since. Optional. Narrows the returned results to just those replies created after the specified HTTP-formatted date. The
208         same behavior is available by setting an If-Modified-Since header in your HTTP request. Ex:
209         http://identi.ca/api/statuses/replies.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
210                 * since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than) the specified
211                 ID. Ex: http://identi.ca/api/statuses/replies.xml?since_id=12345
212         */
213         function replies($args, $apidata) {
214                 parent::handle($args);
215                 common_server_error("API method under construction.", $code=501);
216         }
217         
218         
219         /*
220                 Destroys the status specified by the required ID parameter. The authenticating user must be
221         the author of the specified status.
222                 
223                  URL: http://identi.ca/api/statuses/destroy/id.format
224                 
225                  Formats: xml, json
226                 
227                  Parameters:
228                 
229                  * id. Required. The ID of the status to destroy. Ex:
230                 http://identi.ca/api/statuses/destroy/12345.json or
231                 http://identi.ca/api/statuses/destroy/23456.xml
232         
233         */
234         function destroy($args, $apidata) {
235                 parent::handle($args);
236                 common_server_error("API method under construction.", $code=501);
237         }
238         
239         # User Methods
240         
241         /*
242                 Returns up to 100 of the authenticating user's friends who have most recently updated, each with current status inline.
243         It's also possible to request another user's recent friends list via the id parameter below.
244                 
245                  URL: http://identi.ca/api/statuses/friends.format
246                 
247                  Formats: xml, json
248                 
249                  Parameters:
250                 
251                  * id. Optional. The ID or screen name of the user for whom to request a list of friends. Ex:
252                 http://identi.ca/api/statuses/friends/12345.json 
253                         or 
254                         http://identi.ca/api/statuses/friends/bob.xml
255                  * page. Optional. Retrieves the next 100 friends. Ex: http://identi.ca/api/statuses/friends.xml?page=2
256                  * lite. Optional. Prevents the inline inclusion of current status. Must be set to a value of true. Ex:
257                 http://identi.ca/api/statuses/friends.xml?lite=true
258                  * since. Optional. Narrows the returned results to just those friendships created after the specified
259                         HTTP-formatted date. The same behavior is available by setting an If-Modified-Since header in your HTTP
260                         request. Ex: http://identi.ca/api/statuses/friends.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
261         */
262         function friends($args, $apidata) {
263                 parent::handle($args);
264                 common_server_error("API method under construction.", $code=501);
265         }
266         
267         /*
268                 Returns the authenticating user's followers, each with current status inline. They are ordered by the
269                 order in which they joined Twitter (this is going to be changed).
270                 
271                 URL: http://identi.ca/api/statuses/followers.format
272                 Formats: xml, json
273
274                 Parameters: 
275
276                     * id. Optional. The ID or screen name of the user for whom to request a list of followers. Ex:
277                 http://identi.ca/api/statuses/followers/12345.json 
278                                 or 
279                                 http://identi.ca/api/statuses/followers/bob.xml
280                     * page. Optional. Retrieves the next 100 followers. Ex: http://identi.ca/api/statuses/followers.xml?page=2   
281                     * lite. Optional. Prevents the inline inclusion of current status. Must be set to a value of true.
282                                 Ex: http://identi.ca/api/statuses/followers.xml?lite=true
283         */
284         function followers($args, $apidata) {
285                 parent::handle($args);
286                 common_server_error("API method under construction.", $code=501);
287         }
288         
289         /*
290         Returns a list of the users currently featured on the site with their current statuses inline. 
291         URL: http://identi.ca/api/statuses/featured.format 
292
293         Formats: xml, json
294         */
295         function featured($args, $apidata) {
296                 parent::handle($args);
297                 common_server_error("API method under construction.", $code=501);
298         }
299         
300 }
301
302