3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/twitterapi.php');
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
28 class TwitapistatusesAction extends TwitterapiAction {
31 * Returns the 20 most recent statuses from non-protected users who have set a custom
32 * user icon. Does not require authentication.
34 * URL: http://identi.ca/api/statuses/public_timeline.format
36 * Formats: xml, json, rss, atom
38 function public_timeline($args, $apidata) {
39 parent::handle($args);
41 $notice = DB_DataObject::factory('notice');
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');
47 $cnt = $notice->find();
49 if ($apidata['content-type'] == 'xml') {
51 header('Content-Type: application/xml; charset=utf-8');
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
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);
68 common_element_end('statuses');
72 } elseif ($apidata['content-type'] == 'rss') {
74 header("Content-Type: application/rss+xml; charset=utf-8");
76 $this->init_twitter_rss();
78 $sitename = common_config('site', 'name');
79 $siteserver = common_config('site', 'server');
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');
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);
99 common_element_end('channel');
101 $this->end_twitter_rss();
103 } elseif ($apidata['content-type'] == 'atom') {
105 header('Content-Type: application/atom+xml; charset=utf-8');
107 $this->init_twitter_atom();
109 $sitename = common_config('site', 'name');
110 $siteserver = common_config('site', 'server');
112 common_element('title', NULL, "$sitename public timeline");
113 common_element('id', NULL, "tag:$siteserver:Statuses");
114 common_element('link', array('href' => "http://$siteserver", 'rel' => 'alternate', 'type' => 'text/html'), NULL);
115 common_element('subtitle', NULL, "$sitename updates from everyone!");
118 for ($i = 0; $i < 20; $i++) {
119 if ($notice->fetch()) {
120 $entry = $this->twitter_rss_entry_array($notice);
121 $this->show_twitter_atom_entry($entry);
129 $this->end_twitter_atom();
131 } elseif ($apidata['content-type'] == 'json') {
133 header('Content-Type: application/json; charset=utf-8');
138 for ($i = 0; $i < 20; $i++) {
139 if ($notice->fetch()) {
140 $twitter_status = $this->twitter_status_array($notice);
141 array_push($statuses, $twitter_status);
148 $this->render_twitter_json_statuses($statuses);
157 Returns the 20 most recent statuses posted by the authenticating user and that user's friends.
158 This is the equivalent of /home on the Web.
160 URL: http://identi.ca/api/statuses/friends_timeline.format
164 * since. Optional. Narrows the returned results to just those statuses created after the specified
165 HTTP-formatted date. The same behavior is available by setting an If-Modified-Since header in
167 Ex: http://identi.ca/api/statuses/friends_timeline.rss?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
168 * since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than)
169 the specified ID. Ex: http://identi.ca/api/statuses/friends_timeline.xml?since_id=12345
170 * count. Optional. Specifies the number of statuses to retrieve. May not be greater than 200.
171 Ex: http://identi.ca/api/statuses/friends_timeline.xml?count=5
172 * page. Optional. Ex: http://identi.ca/api/statuses/friends_timeline.rss?page=3
174 Formats: xml, json, rss, atom
176 function friends_timeline($args, $apidata) {
177 parent::handle($args);
179 $since = $this->arg('since');
180 $since_id = $this->arg('since_id');
181 $count = $this->arg('count');
182 $page = $this->arg('page');
184 print "Friends Timeline! requested content-type: " . $apidata['content-type'] . "\n";
185 print "since: $since, since_id: $since_id, count: $count, page: $page\n";
192 Returns the 20 most recent statuses posted from the authenticating user. It's also possible to
193 request another user's timeline via the id parameter below. This is the equivalent of the Web
194 /archive page for your own user, or the profile page for a third party.
196 URL: http://identi.ca/api/statuses/user_timeline.format
198 Formats: xml, json, rss, atom
202 * id. Optional. Specifies the ID or screen name of the user for whom to return the
203 friends_timeline. Ex: http://identi.ca/api/statuses/user_timeline/12345.xml or
204 http://identi.ca/api/statuses/user_timeline/bob.json.
205 * count. Optional. Specifies the number of
206 statuses to retrieve. May not be greater than 200. Ex:
207 http://identi.ca/api/statuses/user_timeline.xml?count=5
208 * since. Optional. Narrows the returned
209 results to just those statuses created after the specified HTTP-formatted date. The same
210 behavior is available by setting an If-Modified-Since header in your HTTP request. Ex:
211 http://identi.ca/api/statuses/user_timeline.rss?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
212 * since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than)
213 the specified ID. Ex: http://identi.ca/api/statuses/user_timeline.xml?since_id=12345 * page.
214 Optional. Ex: http://identi.ca/api/statuses/friends_timeline.rss?page=3
216 function user_timeline($args, $apidata) {
217 parent::handle($args);
219 $id = $this->arg('id');
220 $count = $this->arg('count');
221 $since = $this->arg('since');
222 $since_id = $this->arg('since_id');
224 print "User Timeline! requested content-type: " . $apidata['content-type'] . "\n";
225 print "id: $id since: $since, since_id: $since_id, count: $count\n";
231 Returns a single status, specified by the id parameter below. The status's author will be returned inline.
233 URL: http://identi.ca/api/statuses/show/id.format
239 * id. Required. The numerical ID of the status you're trying to retrieve.
240 Ex: http://identi.ca/api/statuses/show/123.xml
242 function show($args, $apidata) {
243 parent::handle($args);
245 $id = $this->arg('id');
247 print "show requested content-type: " . $apidata['content-type'] . "\n";
255 Updates the authenticating user's status. Requires the status parameter specified below. Request must be a POST.
257 URL: http://identi.ca/api/statuses/update.format
259 Formats: xml, json. Returns the posted status in requested format when successful.
263 * status. Required. The text of your status update. Be sure to URL encode as necessary. Must not be more than 160
264 characters and should not be more than 140 characters to ensure optimal display.
267 function update($args, $apidata) {
268 parent::handle($args);
269 common_server_error("API method under construction.", $code=501);
273 Returns the 20 most recent @replies (status updates prefixed with @username) for the authenticating user.
274 URL: http://identi.ca/api/statuses/replies.format
276 Formats: xml, json, rss, atom
280 * page. Optional. Retrieves the 20 next most recent replies. Ex: http://identi.ca/api/statuses/replies.xml?page=3
281 * since. Optional. Narrows the returned results to just those replies created after the specified HTTP-formatted date. The
282 same behavior is available by setting an If-Modified-Since header in your HTTP request. Ex:
283 http://identi.ca/api/statuses/replies.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
284 * since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than) the specified
285 ID. Ex: http://identi.ca/api/statuses/replies.xml?since_id=12345
287 function replies($args, $apidata) {
288 parent::handle($args);
289 common_server_error("API method under construction.", $code=501);
294 Destroys the status specified by the required ID parameter. The authenticating user must be
295 the author of the specified status.
297 URL: http://identi.ca/api/statuses/destroy/id.format
303 * id. Required. The ID of the status to destroy. Ex:
304 http://identi.ca/api/statuses/destroy/12345.json or
305 http://identi.ca/api/statuses/destroy/23456.xml
308 function destroy($args, $apidata) {
309 parent::handle($args);
310 common_server_error("API method under construction.", $code=501);
316 Returns up to 100 of the authenticating user's friends who have most recently updated, each with current status inline.
317 It's also possible to request another user's recent friends list via the id parameter below.
319 URL: http://identi.ca/api/statuses/friends.format
325 * id. Optional. The ID or screen name of the user for whom to request a list of friends. Ex:
326 http://identi.ca/api/statuses/friends/12345.json
328 http://identi.ca/api/statuses/friends/bob.xml
329 * page. Optional. Retrieves the next 100 friends. Ex: http://identi.ca/api/statuses/friends.xml?page=2
330 * lite. Optional. Prevents the inline inclusion of current status. Must be set to a value of true. Ex:
331 http://identi.ca/api/statuses/friends.xml?lite=true
332 * since. Optional. Narrows the returned results to just those friendships created after the specified
333 HTTP-formatted date. The same behavior is available by setting an If-Modified-Since header in your HTTP
334 request. Ex: http://identi.ca/api/statuses/friends.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
336 function friends($args, $apidata) {
337 parent::handle($args);
338 common_server_error("API method under construction.", $code=501);
342 Returns the authenticating user's followers, each with current status inline. They are ordered by the
343 order in which they joined Twitter (this is going to be changed).
345 URL: http://identi.ca/api/statuses/followers.format
350 * id. Optional. The ID or screen name of the user for whom to request a list of followers. Ex:
351 http://identi.ca/api/statuses/followers/12345.json
353 http://identi.ca/api/statuses/followers/bob.xml
354 * page. Optional. Retrieves the next 100 followers. Ex: http://identi.ca/api/statuses/followers.xml?page=2
355 * lite. Optional. Prevents the inline inclusion of current status. Must be set to a value of true.
356 Ex: http://identi.ca/api/statuses/followers.xml?lite=true
358 function followers($args, $apidata) {
359 parent::handle($args);
360 common_server_error("API method under construction.", $code=501);
364 Returns a list of the users currently featured on the site with their current statuses inline.
365 URL: http://identi.ca/api/statuses/featured.format
369 function featured($args, $apidata) {
370 parent::handle($args);
371 common_server_error("API method under construction.", $code=501);