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') {
104 common_server_error("API method under construction.", $code=501);
105 } elseif ($apidata['content-type'] == 'json') {
107 header('Content-Type: application/json; charset=utf-8');
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);
122 $this->render_twitter_json_statuses($statuses);
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.
134 URL: http://identi.ca/api/statuses/friends_timeline.format
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
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
148 Formats: xml, json, rss, atom
150 function friends_timeline($args, $apidata) {
151 parent::handle($args);
153 $since = $this->arg('since');
154 $since_id = $this->arg('since_id');
155 $count = $this->arg('count');
156 $page = $this->arg('page');
158 print "Friends Timeline! requested content-type: " . $apidata['content-type'] . "\n";
159 print "since: $since, since_id: $since_id, count: $count, page: $page\n";
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.
170 URL: http://identi.ca/api/statuses/user_timeline.format
172 Formats: xml, json, rss, atom
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
190 function user_timeline($args, $apidata) {
191 parent::handle($args);
193 $id = $this->arg('id');
194 $count = $this->arg('count');
195 $since = $this->arg('since');
196 $since_id = $this->arg('since_id');
198 print "User Timeline! requested content-type: " . $apidata['content-type'] . "\n";
199 print "id: $id since: $since, since_id: $since_id, count: $count\n";
205 Returns a single status, specified by the id parameter below. The status's author will be returned inline.
207 URL: http://identi.ca/api/statuses/show/id.format
213 * id. Required. The numerical ID of the status you're trying to retrieve.
214 Ex: http://identi.ca/api/statuses/show/123.xml
216 function show($args, $apidata) {
217 parent::handle($args);
219 $id = $this->arg('id');
221 print "show requested content-type: " . $apidata['content-type'] . "\n";
229 Updates the authenticating user's status. Requires the status parameter specified below. Request must be a POST.
231 URL: http://identi.ca/api/statuses/update.format
233 Formats: xml, json. Returns the posted status in requested format when successful.
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.
241 function update($args, $apidata) {
242 parent::handle($args);
243 common_server_error("API method under construction.", $code=501);
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
250 Formats: xml, json, rss, atom
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
261 function replies($args, $apidata) {
262 parent::handle($args);
263 common_server_error("API method under construction.", $code=501);
268 Destroys the status specified by the required ID parameter. The authenticating user must be
269 the author of the specified status.
271 URL: http://identi.ca/api/statuses/destroy/id.format
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
282 function destroy($args, $apidata) {
283 parent::handle($args);
284 common_server_error("API method under construction.", $code=501);
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.
293 URL: http://identi.ca/api/statuses/friends.format
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
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
310 function friends($args, $apidata) {
311 parent::handle($args);
312 common_server_error("API method under construction.", $code=501);
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).
319 URL: http://identi.ca/api/statuses/followers.format
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
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
332 function followers($args, $apidata) {
333 parent::handle($args);
334 common_server_error("API method under construction.", $code=501);
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
343 function featured($args, $apidata) {
344 parent::handle($args);
345 common_server_error("API method under construction.", $code=501);