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 // count public wall messages
247 $r = q("SELECT COUNT(`id`) as `count` FROM `item`
250 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
251 intval($uinfo[0]['uid'])
253 $countitms = $r[0]['count'];
256 $r = q("SELECT COUNT(`id`) as `count` FROM `item`
257 WHERE `contact-id` = %d
258 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
259 intval($uinfo[0]['id'])
261 $countitms = $r[0]['count'];
265 $r = q("SELECT COUNT(`id`) as `count` FROM `contact`
266 WHERE `uid` = %d AND `rel` IN ( %d, %d )
267 AND `self`=0 AND `blocked`=0",
268 intval($uinfo[0]['uid']),
272 $countfriends = $r[0]['count'];
274 $r = q("SELECT COUNT(`id`) as `count` FROM `contact`
275 WHERE `uid` = %d AND `rel` IN ( %d, %d )
276 AND `self`=0 AND `blocked`=0",
277 intval($uinfo[0]['uid']),
281 $countfollowers = $r[0]['count'];
283 if(! $uinfo[0]['self']) {
289 'uid' => $uinfo[0]['uid'],
290 'id' => $uinfo[0]['cid'],
291 'name' => $uinfo[0]['name'],
292 'screen_name' => $uinfo[0]['nick'],
293 'location' => '', //$uinfo[0]['default-location'],
294 'profile_image_url' => $uinfo[0]['micro'],
295 'url' => $uinfo[0]['url'],
296 'contact_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'],
297 'protected' => false, #
298 'friends_count' => $countfriends,
299 'created_at' => api_date($uinfo[0]['name-date']),
300 'utc_offset' => 0, #XXX: fix me
301 'time_zone' => '', //$uinfo[0]['timezone'],
302 'geo_enabled' => false,
303 'statuses_count' => $countitms, #XXX: fix me
304 'lang' => 'en', #XXX: fix me
306 'followers_count' => $countfollowers, #XXX: fix me
307 'favourites_count' => 0,
308 'contributors_enabled' => false,
309 'follow_request_sent' => false,
310 'profile_background_color' => 'cfe8f6',
311 'profile_text_color' => '000000',
312 'profile_link_color' => 'FF8500',
313 'profile_sidebar_fill_color' =>'AD0066',
314 'profile_sidebar_border_color' => 'AD0066',
315 'profile_background_image_url' => '',
316 'profile_background_tile' => false,
317 'profile_use_background_image' => false,
318 'notifications' => false,
319 'verified' => true, #XXX: fix me
320 'followers' => '', #XXX: fix me
328 function api_item_get_user(&$a, $item) {
329 // The author is our direct contact, in a conversation with us.
330 if(link_compare($item['url'],$item['author-link'])) {
331 return api_get_user($a,$item['cid']);
334 // The author may be a contact of ours, but is replying to somebody else.
335 // Figure out if we know him/her.
336 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
337 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
338 return api_get_user($a,$a->contacts[$normalised]['id']);
340 // We don't know this person directly.
344 'name' => $item['author-name'],
346 'location' => '', //$uinfo[0]['default-location'],
347 'profile_image_url' => $item['author-avatar'],
348 'url' => $item['author-link'],
350 'protected' => false, #
351 'friends_count' => 0,
353 'utc_offset' => 0, #XXX: fix me
354 'time_zone' => '', //$uinfo[0]['timezone'],
355 'geo_enabled' => false,
356 'statuses_count' => 0,
357 'lang' => 'en', #XXX: fix me
359 'followers_count' => 0,
360 'favourites_count' => 0,
361 'contributors_enabled' => false,
362 'follow_request_sent' => false,
363 'profile_background_color' => 'cfe8f6',
364 'profile_text_color' => '000000',
365 'profile_link_color' => 'FF8500',
366 'profile_sidebar_fill_color' =>'AD0066',
367 'profile_sidebar_border_color' => 'AD0066',
368 'profile_background_image_url' => '',
369 'profile_background_tile' => false,
370 'profile_use_background_image' => false,
371 'notifications' => false,
372 'verified' => true, #XXX: fix me
373 'followers' => '', #XXX: fix me
381 * apply xmlify() to all values of array $val, recursively
383 function api_xmlify($val){
384 if (is_bool($val)) return $val?"true":"false";
385 if (is_array($val)) return array_map('api_xmlify', $val);
390 * load api $templatename for $type and replace $data array
392 function api_apply_template($templatename, $type, $data){
400 $data = api_xmlify($data);
401 $tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
402 $ret = replace_macros($tpl, $data);
416 * Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful;
417 * returns a 401 status code and an error message if not.
418 * http://developer.twitter.com/doc/get/account/verify_credentials
420 function api_account_verify_credentials(&$a, $type){
421 if (local_user()===false) return false;
422 $user_info = api_get_user($a);
424 return api_apply_template("user", $type, array('$user' => $user_info));
427 api_register_func('api/account/verify_credentials','api_account_verify_credentials', true);
431 * get data from $_POST or $_GET
433 function requestdata($k){
434 if (isset($_POST[$k])){
437 if (isset($_GET[$k])){
442 // TODO - media uploads
443 function api_statuses_update(&$a, $type) {
444 if (local_user()===false) return false;
445 $user_info = api_get_user($a);
447 // convert $_POST array items to the form we use for web posts.
449 // logger('api_post: ' . print_r($_POST,true));
451 $_POST['body'] = urldecode(requestdata('status'));
453 $parent = requestdata('in_reply_to_status_id');
454 if(ctype_digit($parent))
455 $_POST['parent'] = $parent;
457 $_POST['parent_uri'] = $parent;
459 if(requestdata('lat') && requestdata('long'))
460 $_POST['coord'] = sprintf("%s %s",requestdata('lat'),requestdata('long'));
461 $_POST['profile_uid'] = local_user();
462 if(requestdata('parent'))
463 $_POST['type'] = 'net-comment';
465 $_POST['type'] = 'wall';
467 // set this so that the item_post() function is quiet and doesn't redirect or emit json
469 $_POST['api_source'] = true;
471 // call out normal post function
473 require_once('mod/item.php');
476 // this should output the last post (the one we just posted).
477 return api_status_show($a,$type);
479 api_register_func('api/statuses/update','api_statuses_update', true);
482 function api_status_show(&$a, $type){
483 $user_info = api_get_user($a);
484 // get last public wall message
485 $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
486 FROM `item`, `contact`,
487 (SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i`
488 WHERE `item`.`contact-id` = %d
489 AND `i`.`id` = `item`.`parent`
490 AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
491 AND `type`!='activity'
492 AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
493 ORDER BY `created` DESC
495 intval($user_info['id'])
498 if (count($lastwall)>0){
499 $lastwall = $lastwall[0];
501 $in_reply_to_status_id = '';
502 $in_reply_to_user_id = '';
503 $in_reply_to_screen_name = '';
504 if ($lastwall['parent']!=$lastwall['id']) {
505 $in_reply_to_status_id=$lastwall['parent'];
506 $in_reply_to_user_id = $lastwall['reply_uid'];
507 $in_reply_to_screen_name = $lastwall['reply_author'];
509 $status_info = array(
510 'created_at' => api_date($lastwall['created']),
511 'id' => $lastwall['contact-id'],
512 'text' => strip_tags(bbcode($lastwall['body'])),
513 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
514 'truncated' => false,
515 'in_reply_to_status_id' => $in_reply_to_status_id,
516 'in_reply_to_user_id' => $in_reply_to_user_id,
517 'favorited' => false,
518 'in_reply_to_screen_name' => $in_reply_to_screen_name,
520 'coordinates' => $lastwall['coord'],
521 'place' => $lastwall['location'],
524 $status_info['user'] = $user_info;
526 return api_apply_template("status", $type, array('$status' => $status_info));
535 * Returns extended information of a given user, specified by ID or screen name as per the required id parameter.
536 * The author's most recent status will be returned inline.
537 * http://developer.twitter.com/doc/get/users/show
539 function api_users_show(&$a, $type){
540 $user_info = api_get_user($a);
541 // get last public wall message
542 $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
543 FROM `item`, `contact`,
544 (SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i`
545 WHERE `item`.`contact-id` = %d
546 AND `i`.`id` = `item`.`parent`
547 AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
548 AND `type`!='activity'
549 AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
550 ORDER BY `created` DESC
552 intval($user_info['id'])
555 if (count($lastwall)>0){
556 $lastwall = $lastwall[0];
558 $in_reply_to_status_id = '';
559 $in_reply_to_user_id = '';
560 $in_reply_to_screen_name = '';
561 if ($lastwall['parent']!=$lastwall['id']) {
562 $in_reply_to_status_id=$lastwall['parent'];
563 $in_reply_to_user_id = $lastwall['reply_uid'];
564 $in_reply_to_screen_name = $lastwall['reply_author'];
566 $user_info['status'] = array(
567 'created_at' => api_date($lastwall['created']),
568 'id' => $lastwall['contact-id'],
569 'text' => strip_tags(bbcode($lastwall['body'])),
570 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
571 'truncated' => false,
572 'in_reply_to_status_id' => $in_reply_to_status_id,
573 'in_reply_to_user_id' => $in_reply_to_user_id,
574 'favorited' => false,
575 'in_reply_to_screen_name' => $in_reply_to_screen_name,
577 'coordinates' => $lastwall['coord'],
578 'place' => $lastwall['location'],
582 return api_apply_template("user", $type, array('$user' => $user_info));
585 api_register_func('api/users/show','api_users_show');
589 * http://developer.twitter.com/doc/get/statuses/home_timeline
591 * TODO: Optional parameters
592 * TODO: Add reply info
594 function api_statuses_home_timeline(&$a, $type){
595 if (local_user()===false) return false;
597 $user_info = api_get_user($a);
598 // get last newtork messages
599 // $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
601 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
602 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
603 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
604 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
605 FROM `item`, `contact`
606 WHERE `item`.`uid` = %d
607 AND `item`.`visible` = 1 AND `item`.`deleted` = 0
608 AND `contact`.`id` = `item`.`contact-id`
609 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
611 ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
612 intval($user_info['uid']),
616 $ret = api_format_items($r,$user_info);
619 $data = array('$statuses' => $ret);
623 $data = api_rss_extra($a, $data, $user_info);
626 return api_apply_template("timeline", $type, $data);
628 api_register_func('api/statuses/home_timeline','api_statuses_home_timeline', true);
629 api_register_func('api/statuses/friends_timeline','api_statuses_home_timeline', true);
633 function api_statuses_user_timeline(&$a, $type){
634 if (local_user()===false) return false;
636 $user_info = api_get_user($a);
637 // get last newtork messages
638 // $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
640 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
641 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
642 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
643 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
644 FROM `item`, `contact`
645 WHERE `item`.`uid` = %d
646 AND `item`.`visible` = 1 AND `item`.`deleted` = 0
647 AND `item`.`wall` = 1
648 AND `contact`.`id` = `item`.`contact-id`
649 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
651 ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
652 intval($user_info['uid']),
656 $ret = api_format_items($r,$user_info);
659 $data = array('$statuses' => $ret);
663 $data = api_rss_extra($a, $data, $user_info);
666 return api_apply_template("timeline", $type, $data);
669 api_register_func('api/statuses/user_timeline','api_statuses_user_timeline', true);
672 function api_favorites(&$a, $type){
673 if (local_user()===false) return false;
675 $user_info = api_get_user($a);
676 // get last newtork messages
677 // $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
679 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
680 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
681 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
682 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
683 FROM `item`, `contact`
684 WHERE `item`.`uid` = %d
685 AND `item`.`visible` = 1 AND `item`.`deleted` = 0
686 AND `item`.`starred` = 1
687 AND `contact`.`id` = `item`.`contact-id`
688 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
690 ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
691 intval($user_info['uid']),
695 $ret = api_format_items($r,$user_info);
698 $data = array('$statuses' => $ret);
702 $data = api_rss_extra($a, $data, $user_info);
705 return api_apply_template("timeline", $type, $data);
708 api_register_func('api/favorites','api_favorites', true);
711 function api_format_items($r,$user_info) {
713 //logger('api_format_items: ' . print_r($r,true));
715 //logger('api_format_items: ' . print_r($user_info,true));
720 foreach($r as $item) {
721 $status_user = (($item['cid']==$user_info['id'])?$user_info: api_item_get_user($a,$item));
723 'created_at'=> api_date($item['created']),
724 'published' => datetime_convert('UTC','UTC',$item['created'],ATOM_TIME),
725 'updated' => datetime_convert('UTC','UTC',$item['edited'],ATOM_TIME),
727 'message_id' => $item['uri'],
728 'text' => strip_tags(bbcode($item['body'])),
729 'html' => bbcode($item['body']),
730 'source' => (($item['app']) ? $item['app'] : 'web'),
731 'url' => ($item['plink']!=''?$item['plink']:$item['author-link']),
732 'truncated' => False,
733 'in_reply_to_status_id' => ($item['parent']!=$item['id']?$item['parent']:''),
734 'in_reply_to_user_id' => '',
735 'favorited' => false,
736 'in_reply_to_screen_name' => '',
738 'coordinates' => $item['coord'],
739 'place' => $item['location'],
740 'contributors' => '',
743 'user' => $status_user ,
744 'objecttype' => (($item['object-type']) ? $item['object-type'] : ACTIVITY_OBJ_NOTE),
745 'verb' => (($item['verb']) ? $item['verb'] : ACTIVITY_POST),
746 'self' => $a->get_baseurl()."/api/statuses/show/".$item['id'].".".$type,
747 'edit' => $a->get_baseurl()."/api/statuses/show/".$item['id'].".".$type,
755 function api_account_rate_limit_status(&$a,$type) {
758 'remaining_hits' => (string) 150,
759 'hourly_limit' => (string) 150,
760 'reset_time' => datetime_convert('UTC','UTC','now + 1 hour',ATOM_TIME),
761 'reset_time_in_seconds' => strtotime('now + 1 hour')
764 return api_apply_template('ratelimit', $type, array('$hash' => $hash));
767 api_register_func('api/account/rate_limit_status','api_account_rate_limit_status',true);
770 function api_statusnet_config(&$a,$type) {
771 $name = $a->config['sitename'];
772 $server = $a->get_hostname();
773 $logo = $a->get_baseurl() . '/images/friendika-64.png';
774 $email = $a->config['admin_email'];
775 $closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
776 $private = (($a->config['system']['block_public']) ? 'true' : 'false');
777 $textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000);
778 $ssl = (($a->config['system']['have_ssl']) ? 'true' : 'false');
779 $sslserver = (($ssl === 'true') ? str_replace('http:','https:',$a->get_baseurl()) : '');
782 'site' => array('name' => $name,'server' => $server, 'theme' => 'default', 'path' => '',
783 'logo' => $logo, 'fancy' => 'true', 'language' => 'en', 'email' => $email, 'broughtby' => '',
784 'broughtbyurl' => '', 'timezone' => 'UTC', 'closed' => $closed, 'inviteonly' => 'false',
785 'private' => $private, 'textlimit' => $textlimit, 'sslserver' => $sslserver, 'ssl' => $ssl,
786 'shorturllength' => '30'
790 return api_apply_template('config', $type, array('$config' => $config));
793 api_register_func('api/statusnet/config','api_statusnet_config',false);
796 function api_statusnet_version(&$a,$type) {
800 if($type === 'xml') {
801 header("Content-type: application/xml");
802 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<version>0.9.7</version>' . "\r\n";
805 elseif($type === 'json') {
806 header("Content-type: application/json");
811 api_register_func('api/statusnet/version','api_statusnet_version',false);
814 function api_ff_ids(&$a,$type,$qtype) {
818 if($qtype == 'friends')
819 $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(REL_FAN), intval(REL_BUD));
820 if($qtype == 'followers')
821 $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(REL_VIP), intval(REL_BUD));
824 $r = q("SELECT id FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 $sql_extra",
829 if($type === 'xml') {
830 header("Content-type: application/xml");
831 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<ids>' . "\r\n";
833 echo '<id>' . $rr['id'] . '</id>' . "\r\n";
834 echo '</ids>' . "\r\n";
837 elseif($type === 'json') {
839 header("Content-type: application/json");
840 foreach($r as $rr) $ret[] = $rr['id'];
841 echo json_encode($ret);
847 function api_friends_ids(&$a,$type) {
848 api_ff_ids($a,$type,'friends');
850 function api_followers_ids(&$a,$type) {
851 api_ff_ids($a,$type,'followers');
853 api_register_func('api/friends/ids','api_friends_ids',true);
854 api_register_func('api/followers/ids','api_followers_ids',true);