2 require_once("bbcode.php");
3 require_once("datetime.php");
13 function api_date($str){
14 //Wed May 23 06:01:13 +0000 2007
15 return datetime_convert('UTC', 'UTC', $str, "D M d h:i:s +0000 Y" );
19 function api_register_func($path, $func, $auth=false){
21 $API[$path] = array('func'=>$func,
28 function api_login(&$a){
29 // workaround for HTTP-auth in CGI mode
30 if(x($_SERVER,'REDIRECT_REMOTE_USER')) {
31 $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ;
32 if(strlen($userpass)) {
33 list($name, $password) = explode(':', $userpass);
34 $_SERVER['PHP_AUTH_USER'] = $name;
35 $_SERVER['PHP_AUTH_PW'] = $password;
39 if (!isset($_SERVER['PHP_AUTH_USER'])) {
40 logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
41 header('WWW-Authenticate: Basic realm="Friendika"');
42 header('HTTP/1.0 401 Unauthorized');
43 die('This api requires login');
46 $user = $_SERVER['PHP_AUTH_USER'];
47 $encrypted = hash('whirlpool',trim($_SERVER['PHP_AUTH_PW']));
51 * next code from mod/auth.php. needs better solution
54 // process normal login request
56 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' )
57 AND `password` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1",
65 logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
66 header('WWW-Authenticate: Basic realm="Friendika"');
67 header('HTTP/1.0 401 Unauthorized');
68 die('This api requires login');
70 $_SESSION['uid'] = $record['uid'];
71 $_SESSION['theme'] = $record['theme'];
72 $_SESSION['authenticated'] = 1;
73 $_SESSION['page_flags'] = $record['page-flags'];
74 $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $record['nickname'];
75 $_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
77 //notice( t("Welcome back ") . $record['username'] . EOL);
80 if(strlen($a->user['timezone'])) {
81 date_default_timezone_set($a->user['timezone']);
82 $a->timezone = $a->user['timezone'];
85 $r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
86 intval($_SESSION['uid']));
89 $a->cid = $r[0]['id'];
90 $_SESSION['cid'] = $a->cid;
92 q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
93 dbesc(datetime_convert()),
94 intval($_SESSION['uid'])
97 call_hooks('logged_in', $a->user);
99 header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
102 /**************************
103 * MAIN API ENTRY POINT *
104 **************************/
105 function api_call(&$a){
107 foreach ($API as $p=>$info){
108 if (strpos($a->query_string, $p)===0){
109 #unset($_SERVER['PHP_AUTH_USER']);
110 if ($info['auth']===true && local_user()===false) {
114 load_contact_links(local_user());
116 logger('API call for ' . $a->user['username'] . ': ' . $a->query_string);
117 logger('API parameters: ' . print_r($_REQUEST,true));
119 if (strpos($a->query_string, ".xml")>0) $type="xml";
120 if (strpos($a->query_string, ".json")>0) $type="json";
121 if (strpos($a->query_string, ".rss")>0) $type="rss";
122 if (strpos($a->query_string, ".atom")>0) $type="atom";
124 $r = call_user_func($info['func'], $a, $type);
125 if ($r===false) return;
129 $r = mb_convert_encoding($r, "UTF-8",mb_detect_encoding($r));
130 header ("Content-Type: text/xml");
131 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
134 header ("Content-Type: application/json");
136 return json_encode($rr);
139 header ("Content-Type: application/rss+xml");
140 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
143 header ("Content-Type: application/atom+xml");
144 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
148 //echo "<pre>"; var_dump($r); die();
151 $r = '<status><error>not implemented</error></status>';
154 header ("Content-Type: text/xml");
155 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
158 header ("Content-Type: application/json");
159 return json_encode(array('error' => 'not implemented'));
162 header ("Content-Type: application/rss+xml");
163 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
166 header ("Content-Type: application/atom+xml");
167 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
176 function api_rss_extra(&$a, $arr, $user_info){
177 if (is_null($user_info)) $user_info = api_get_user($a);
178 $arr['$user'] = $user_info;
179 $arr['$rss'] = array(
180 'alternate' => $user_info['url'],
181 'self' => $a->get_baseurl(). "/". $a->query_string,
182 'base' => $a->get_baseurl(),
183 'updated' => api_date(null),
184 'atom_updated' => datetime_convert('UTC','UTC','now',ATOM_TIME),
185 'language' => $user_info['language'],
186 'logo' => $a->get_baseurl()."/images/friendika-32.png",
193 * Returns user info array.
195 function api_get_user(&$a, $contact_id = Null){
199 if(!is_null($contact_id)){
201 $extra_query = "AND `contact`.`id` = %d ";
204 if(is_null($user) && x($_GET, 'user_id')) {
205 $user = intval($_GET['user_id']);
206 $extra_query = "AND `contact`.`id` = %d ";
208 if(is_null($user) && x($_GET, 'screen_name')) {
209 $user = dbesc($_GET['screen_name']);
210 $extra_query = "AND `contact`.`nick` = '%s' ";
213 if (is_null($user) && $a->argc > 3){
214 list($user, $null) = explode(".",$a->argv[3]);
215 if(is_numeric($user)){
216 $user = intval($user);
217 $extra_query = "AND `contact`.`id` = %d ";
219 $user = dbesc($user);
220 $extra_query = "AND `contact`.`nick` = '%s' ";
225 if (local_user()===false) {
226 api_login($a); return False;
228 $user = $_SESSION['uid'];
229 $extra_query = "AND `contact`.`uid` = %d AND `contact`.`self` = 1 ";
234 logger('api_user: ' . $extra_query . ' ' , $user);
236 $uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `contact`
241 if (count($uinfo)==0) {
245 if($uinfo[0]['self']) {
246 $usr = q("select * from user where uid = %d limit 1",
249 $profile = q("select * from profile where uid = %d and `is-default` = 1 limit 1",
253 // count public wall messages
254 $r = q("SELECT COUNT(`id`) as `count` FROM `item`
257 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
258 intval($uinfo[0]['uid'])
260 $countitms = $r[0]['count'];
263 $r = q("SELECT COUNT(`id`) as `count` FROM `item`
264 WHERE `contact-id` = %d
265 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
266 intval($uinfo[0]['id'])
268 $countitms = $r[0]['count'];
272 $r = q("SELECT COUNT(`id`) as `count` FROM `contact`
273 WHERE `uid` = %d AND `rel` IN ( %d, %d )
274 AND `self`=0 AND `blocked`=0",
275 intval($uinfo[0]['uid']),
279 $countfriends = $r[0]['count'];
281 $r = q("SELECT COUNT(`id`) as `count` FROM `contact`
282 WHERE `uid` = %d AND `rel` IN ( %d, %d )
283 AND `self`=0 AND `blocked`=0",
284 intval($uinfo[0]['uid']),
288 $countfollowers = $r[0]['count'];
290 $r = q("SELECT count(`id`) as `count` FROM item where starred = 1 and uid = %d and deleted = 0",
291 intval($uinfo[0]['uid'])
293 $starred = $r[0]['count'];
296 if(! $uinfo[0]['self']) {
303 'uid' => intval($uinfo[0]['uid']),
304 'id' => intval($uinfo[0]['cid']),
305 'name' => $uinfo[0]['name'],
306 'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']),
307 'location' => ($usr) ? $usr[0]['default-location'] : '',
308 'profile_image_url' => $uinfo[0]['micro'],
309 'url' => $uinfo[0]['url'],
310 'contact_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'],
311 'protected' => false,
312 'friends_count' => intval($countfriends),
313 'created_at' => api_date($uinfo[0]['name-date']),
314 'utc_offset' => "+00:00",
315 'time_zone' => 'UTC', //$uinfo[0]['timezone'],
316 'geo_enabled' => false,
317 'statuses_count' => intval($countitms), #XXX: fix me
318 'lang' => 'en', #XXX: fix me
319 'description' => (($profile) ? $profile[0]['pdesc'] : ''),
320 'followers_count' => intval($countfollowers),
321 'favourites_count' => intval($starred),
322 'contributors_enabled' => false,
323 'follow_request_sent' => false,
324 'profile_background_color' => 'cfe8f6',
325 'profile_text_color' => '000000',
326 'profile_link_color' => 'FF8500',
327 'profile_sidebar_fill_color' =>'AD0066',
328 'profile_sidebar_border_color' => 'AD0066',
329 'profile_background_image_url' => '',
330 'profile_background_tile' => false,
331 'profile_use_background_image' => false,
332 'notifications' => false,
333 'following' => '', #XXX: fix me
334 'verified' => true, #XXX: fix me
342 function api_item_get_user(&$a, $item) {
343 // The author is our direct contact, in a conversation with us.
344 if(link_compare($item['url'],$item['author-link'])) {
345 return api_get_user($a,$item['cid']);
348 // The author may be a contact of ours, but is replying to somebody else.
349 // Figure out if we know him/her.
350 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
351 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
352 return api_get_user($a,$a->contacts[$normalised]['id']);
354 // We don't know this person directly.
358 'name' => $item['author-name'],
359 'screen_name' => $item['author_name'],
360 'location' => '', //$uinfo[0]['default-location'],
361 'profile_image_url' => $item['author-avatar'],
362 'url' => $item['author-link'],
364 'protected' => false, #
365 'friends_count' => 0,
367 'utc_offset' => 0, #XXX: fix me
368 'time_zone' => '', //$uinfo[0]['timezone'],
369 'geo_enabled' => false,
370 'statuses_count' => 0,
371 'lang' => 'en', #XXX: fix me
373 'followers_count' => 0,
374 'favourites_count' => 0,
375 'contributors_enabled' => false,
376 'follow_request_sent' => false,
377 'profile_background_color' => 'cfe8f6',
378 'profile_text_color' => '000000',
379 'profile_link_color' => 'FF8500',
380 'profile_sidebar_fill_color' =>'AD0066',
381 'profile_sidebar_border_color' => 'AD0066',
382 'profile_background_image_url' => '',
383 'profile_background_tile' => false,
384 'profile_use_background_image' => false,
385 'notifications' => false,
386 'verified' => true, #XXX: fix me
387 'followers' => '', #XXX: fix me
395 * apply xmlify() to all values of array $val, recursively
397 function api_xmlify($val){
398 if (is_bool($val)) return $val?"true":"false";
399 if (is_array($val)) return array_map('api_xmlify', $val);
400 return xmlify((string) $val);
404 * load api $templatename for $type and replace $data array
406 function api_apply_template($templatename, $type, $data){
414 $data = api_xmlify($data);
415 $tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
416 $ret = replace_macros($tpl, $data);
430 * Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful;
431 * returns a 401 status code and an error message if not.
432 * http://developer.twitter.com/doc/get/account/verify_credentials
434 function api_account_verify_credentials(&$a, $type){
435 if (local_user()===false) return false;
436 $user_info = api_get_user($a);
438 return api_apply_template("user", $type, array('$user' => $user_info));
441 api_register_func('api/account/verify_credentials','api_account_verify_credentials', true);
445 * get data from $_POST or $_GET
447 function requestdata($k){
448 if (isset($_POST[$k])){
451 if (isset($_GET[$k])){
456 // TODO - media uploads
457 function api_statuses_update(&$a, $type) {
458 if (local_user()===false) return false;
459 $user_info = api_get_user($a);
461 // convert $_POST array items to the form we use for web posts.
463 // logger('api_post: ' . print_r($_POST,true));
465 $_POST['body'] = urldecode(requestdata('status'));
467 $parent = requestdata('in_reply_to_status_id');
468 if(ctype_digit($parent))
469 $_POST['parent'] = $parent;
471 $_POST['parent_uri'] = $parent;
473 if(requestdata('lat') && requestdata('long'))
474 $_POST['coord'] = sprintf("%s %s",requestdata('lat'),requestdata('long'));
475 $_POST['profile_uid'] = local_user();
476 if(requestdata('parent'))
477 $_POST['type'] = 'net-comment';
479 $_POST['type'] = 'wall';
481 // set this so that the item_post() function is quiet and doesn't redirect or emit json
483 $_POST['api_source'] = true;
485 // call out normal post function
487 require_once('mod/item.php');
490 // this should output the last post (the one we just posted).
491 return api_status_show($a,$type);
493 api_register_func('api/statuses/update','api_statuses_update', true);
496 function api_status_show(&$a, $type){
497 $user_info = api_get_user($a);
498 // get last public wall message
499 $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
500 FROM `item`, `contact`,
501 (SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i`
502 WHERE `item`.`contact-id` = %d
503 AND `i`.`id` = `item`.`parent`
504 AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
505 AND `type`!='activity'
506 AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
507 ORDER BY `created` DESC
509 intval($user_info['id'])
512 if (count($lastwall)>0){
513 $lastwall = $lastwall[0];
515 $in_reply_to_status_id = '';
516 $in_reply_to_user_id = '';
517 $in_reply_to_screen_name = '';
518 if ($lastwall['parent']!=$lastwall['id']) {
519 $in_reply_to_status_id=$lastwall['parent'];
520 $in_reply_to_user_id = $lastwall['reply_uid'];
521 $in_reply_to_screen_name = $lastwall['reply_author'];
523 $status_info = array(
524 'created_at' => api_date($lastwall['created']),
525 'id' => $lastwall['contact-id'],
526 'text' => strip_tags(bbcode($lastwall['body'])),
527 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
528 'truncated' => false,
529 'in_reply_to_status_id' => $in_reply_to_status_id,
530 'in_reply_to_user_id' => $in_reply_to_user_id,
531 'favorited' => false,
532 'in_reply_to_screen_name' => $in_reply_to_screen_name,
534 'coordinates' => $lastwall['coord'],
535 'place' => $lastwall['location'],
538 $status_info['user'] = $user_info;
540 return api_apply_template("status", $type, array('$status' => $status_info));
549 * Returns extended information of a given user, specified by ID or screen name as per the required id parameter.
550 * The author's most recent status will be returned inline.
551 * http://developer.twitter.com/doc/get/users/show
553 function api_users_show(&$a, $type){
554 $user_info = api_get_user($a);
555 // get last public wall message
556 $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
557 FROM `item`, `contact`,
558 (SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i`
559 WHERE `item`.`contact-id` = %d
560 AND `i`.`id` = `item`.`parent`
561 AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
562 AND `type`!='activity'
563 AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
564 ORDER BY `created` DESC
566 intval($user_info['id'])
569 if (count($lastwall)>0){
570 $lastwall = $lastwall[0];
572 $in_reply_to_status_id = '';
573 $in_reply_to_user_id = '';
574 $in_reply_to_screen_name = '';
575 if ($lastwall['parent']!=$lastwall['id']) {
576 $in_reply_to_status_id=$lastwall['parent'];
577 $in_reply_to_user_id = $lastwall['reply_uid'];
578 $in_reply_to_screen_name = $lastwall['reply_author'];
580 $user_info['status'] = array(
581 'created_at' => api_date($lastwall['created']),
582 'id' => $lastwall['contact-id'],
583 'text' => strip_tags(bbcode($lastwall['body'])),
584 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
585 'truncated' => false,
586 'in_reply_to_status_id' => $in_reply_to_status_id,
587 'in_reply_to_user_id' => $in_reply_to_user_id,
588 'favorited' => false,
589 'in_reply_to_screen_name' => $in_reply_to_screen_name,
591 'coordinates' => $lastwall['coord'],
592 'place' => $lastwall['location'],
596 return api_apply_template("user", $type, array('$user' => $user_info));
599 api_register_func('api/users/show','api_users_show');
603 * http://developer.twitter.com/doc/get/statuses/home_timeline
605 * TODO: Optional parameters
606 * TODO: Add reply info
608 function api_statuses_home_timeline(&$a, $type){
609 if (local_user()===false) return false;
611 $user_info = api_get_user($a);
612 // get last newtork messages
613 // $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
615 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
616 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
617 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
618 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
619 FROM `item`, `contact`
620 WHERE `item`.`uid` = %d
621 AND `item`.`visible` = 1 AND `item`.`deleted` = 0
622 AND `contact`.`id` = `item`.`contact-id`
623 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
625 ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
626 intval($user_info['uid']),
630 $ret = api_format_items($r,$user_info);
633 $data = array('$statuses' => $ret);
637 $data = api_rss_extra($a, $data, $user_info);
640 return api_apply_template("timeline", $type, $data);
642 api_register_func('api/statuses/home_timeline','api_statuses_home_timeline', true);
643 api_register_func('api/statuses/friends_timeline','api_statuses_home_timeline', true);
647 function api_statuses_user_timeline(&$a, $type){
648 if (local_user()===false) return false;
650 $user_info = api_get_user($a);
651 // get last newtork messages
652 // $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
654 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
655 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
656 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
657 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
658 FROM `item`, `contact`
659 WHERE `item`.`uid` = %d
660 AND `item`.`visible` = 1 AND `item`.`deleted` = 0
661 AND `item`.`wall` = 1
662 AND `contact`.`id` = `item`.`contact-id`
663 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
665 ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
666 intval($user_info['uid']),
670 $ret = api_format_items($r,$user_info);
673 $data = array('$statuses' => $ret);
677 $data = api_rss_extra($a, $data, $user_info);
680 return api_apply_template("timeline", $type, $data);
683 api_register_func('api/statuses/user_timeline','api_statuses_user_timeline', true);
686 function api_favorites(&$a, $type){
687 if (local_user()===false) return false;
689 $user_info = api_get_user($a);
690 // get last newtork messages
691 // $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
693 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
694 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
695 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
696 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
697 FROM `item`, `contact`
698 WHERE `item`.`uid` = %d
699 AND `item`.`visible` = 1 AND `item`.`deleted` = 0
700 AND `item`.`starred` = 1
701 AND `contact`.`id` = `item`.`contact-id`
702 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
704 ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
705 intval($user_info['uid']),
709 $ret = api_format_items($r,$user_info);
712 $data = array('$statuses' => $ret);
716 $data = api_rss_extra($a, $data, $user_info);
719 return api_apply_template("timeline", $type, $data);
722 api_register_func('api/favorites','api_favorites', true);
725 function api_format_items($r,$user_info) {
727 //logger('api_format_items: ' . print_r($r,true));
729 //logger('api_format_items: ' . print_r($user_info,true));
734 foreach($r as $item) {
735 $status_user = (($item['cid']==$user_info['id'])?$user_info: api_item_get_user($a,$item));
737 'created_at'=> api_date($item['created']),
738 'published' => datetime_convert('UTC','UTC',$item['created'],ATOM_TIME),
739 'updated' => datetime_convert('UTC','UTC',$item['edited'],ATOM_TIME),
740 'id' => intval($item['id']),
741 'message_id' => $item['uri'],
742 'text' => strip_tags(bbcode($item['body'])),
743 'statusnet_html' => bbcode($item['body']),
744 'source' => (($item['app']) ? $item['app'] : 'web'),
745 'url' => ($item['plink']!=''?$item['plink']:$item['author-link']),
746 'truncated' => False,
747 'in_reply_to_status_id' => ($item['parent']!=$item['id']? intval($item['parent']):''),
748 'in_reply_to_user_id' => '',
749 'favorited' => $item['starred'] ? true : false,
750 'in_reply_to_screen_name' => '',
752 'coordinates' => $item['coord'],
753 'place' => $item['location'],
754 'contributors' => '',
757 'user' => $status_user ,
758 'objecttype' => (($item['object-type']) ? $item['object-type'] : ACTIVITY_OBJ_NOTE),
759 'verb' => (($item['verb']) ? $item['verb'] : ACTIVITY_POST),
760 'self' => $a->get_baseurl()."/api/statuses/show/".$item['id'].".".$type,
761 'edit' => $a->get_baseurl()."/api/statuses/show/".$item['id'].".".$type,
769 function api_account_rate_limit_status(&$a,$type) {
772 'remaining_hits' => (string) 150,
773 'hourly_limit' => (string) 150,
774 'reset_time' => datetime_convert('UTC','UTC','now + 1 hour',ATOM_TIME),
775 'reset_time_in_seconds' => strtotime('now + 1 hour')
778 return api_apply_template('ratelimit', $type, array('$hash' => $hash));
781 api_register_func('api/account/rate_limit_status','api_account_rate_limit_status',true);
784 function api_statusnet_config(&$a,$type) {
785 $name = $a->config['sitename'];
786 $server = $a->get_hostname();
787 $logo = $a->get_baseurl() . '/images/friendika-64.png';
788 $email = $a->config['admin_email'];
789 $closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
790 $private = (($a->config['system']['block_public']) ? 'true' : 'false');
791 $textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000);
792 if($a->config['api_import_size'])
793 $texlimit = string($a->config['api_import_size']);
794 $ssl = (($a->config['system']['have_ssl']) ? 'true' : 'false');
795 $sslserver = (($ssl === 'true') ? str_replace('http:','https:',$a->get_baseurl()) : '');
798 'site' => array('name' => $name,'server' => $server, 'theme' => 'default', 'path' => '',
799 'logo' => $logo, 'fancy' => 'true', 'language' => 'en', 'email' => $email, 'broughtby' => '',
800 'broughtbyurl' => '', 'timezone' => 'UTC', 'closed' => $closed, 'inviteonly' => 'false',
801 'private' => $private, 'textlimit' => $textlimit, 'sslserver' => $sslserver, 'ssl' => $ssl,
802 'shorturllength' => '30'
806 return api_apply_template('config', $type, array('$config' => $config));
809 api_register_func('api/statusnet/config','api_statusnet_config',false);
812 function api_statusnet_version(&$a,$type) {
816 if($type === 'xml') {
817 header("Content-type: application/xml");
818 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<version>0.9.7</version>' . "\r\n";
821 elseif($type === 'json') {
822 header("Content-type: application/json");
827 api_register_func('api/statusnet/version','api_statusnet_version',false);
830 function api_ff_ids(&$a,$type,$qtype) {
834 if($qtype == 'friends')
835 $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(REL_FAN), intval(REL_BUD));
836 if($qtype == 'followers')
837 $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(REL_VIP), intval(REL_BUD));
840 $r = q("SELECT id FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 $sql_extra",
845 if($type === 'xml') {
846 header("Content-type: application/xml");
847 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<ids>' . "\r\n";
849 echo '<id>' . $rr['id'] . '</id>' . "\r\n";
850 echo '</ids>' . "\r\n";
853 elseif($type === 'json') {
855 header("Content-type: application/json");
856 foreach($r as $rr) $ret[] = $rr['id'];
857 echo json_encode($ret);
863 function api_friends_ids(&$a,$type) {
864 api_ff_ids($a,$type,'friends');
866 function api_followers_ids(&$a,$type) {
867 api_ff_ids($a,$type,'followers');
869 api_register_func('api/friends/ids','api_friends_ids',true);
870 api_register_func('api/followers/ids','api_followers_ids',true);