]> git.mxchange.org Git - friendica.git/blob - include/api.php
b8dbdd2d32a4f63d6c6e122d2dd6ff3e62e6ffc0
[friendica.git] / include / api.php
1 <?php
2         require_once("bbcode.php");
3         require_once("datetime.php");
4         
5         /* 
6          * Twitter-Like API
7          *  
8          */
9
10         $API = Array();
11          
12
13         
14         function api_date($str){
15                 //Wed May 23 06:01:13 +0000 2007
16                 return datetime_convert('UTC', 'UTC', $str, "D M d h:i:s +0000 Y" );
17         }
18          
19         
20         function api_register_func($path, $func, $auth=false){
21                 global $API;
22                 $API[$path] = array('func'=>$func,
23                                                         'auth'=>$auth);
24         }
25         
26         /**
27          * Simple HTTP Login
28          */
29         function api_login(&$a){
30                 // workaround for HTTP-auth in CGI mode
31                 if(x($_SERVER,'REDIRECT_REMOTE_USER')) {
32                         $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ;
33                         if(strlen($userpass)) {
34                                 list($name, $password) = explode(':', $userpass);
35                                 $_SERVER['PHP_AUTH_USER'] = $name;
36                                 $_SERVER['PHP_AUTH_PW'] = $password;
37                         }
38                 }
39
40                 if (!isset($_SERVER['PHP_AUTH_USER'])) {
41                    logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
42                     header('WWW-Authenticate: Basic realm="Friendika"');
43                     header('HTTP/1.0 401 Unauthorized');
44                     die('This api requires login');
45                 }
46                 
47                 $user = $_SERVER['PHP_AUTH_USER'];
48                 $encrypted = hash('whirlpool',trim($_SERVER['PHP_AUTH_PW']));
49                 
50                 
51                         /**
52                          *  next code from mod/auth.php. needs better solution
53                          */
54                         
55                 // process normal login request
56
57                 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) 
58                         AND `password` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1",
59                         dbesc(trim($user)),
60                         dbesc(trim($user)),
61                         dbesc($encrypted)
62                 );
63                 if(count($r)){
64                         $record = $r[0];
65                 } else {
66                    logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
67                     header('WWW-Authenticate: Basic realm="Friendika"');
68                     header('HTTP/1.0 401 Unauthorized');
69                     die('This api requires login');
70                 }
71                 $_SESSION['uid'] = $record['uid'];
72                 $_SESSION['theme'] = $record['theme'];
73                 $_SESSION['authenticated'] = 1;
74                 $_SESSION['page_flags'] = $record['page-flags'];
75                 $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $record['nickname'];
76                 $_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
77
78                 //notice( t("Welcome back ") . $record['username'] . EOL);
79                 $a->user = $record;
80
81                 if(strlen($a->user['timezone'])) {
82                         date_default_timezone_set($a->user['timezone']);
83                         $a->timezone = $a->user['timezone'];
84                 }
85
86                 $r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
87                         intval($_SESSION['uid']));
88                 if(count($r)) {
89                         $a->contact = $r[0];
90                         $a->cid = $r[0]['id'];
91                         $_SESSION['cid'] = $a->cid;
92                 }
93                 q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
94                         dbesc(datetime_convert()),
95                         intval($_SESSION['uid'])
96                 );
97
98                 call_hooks('logged_in', $a->user);
99
100                 header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
101         }
102         
103         /**************************
104          *  MAIN API ENTRY POINT  *
105          **************************/
106         function api_call(&$a){
107                 GLOBAL $API;
108                 foreach ($API as $p=>$info){
109                         if (strpos($a->query_string, $p)===0){
110                                 #unset($_SERVER['PHP_AUTH_USER']);
111                                 if ($info['auth']===true && local_user()===false) {
112                                                 api_login($a);
113                                 }
114                 
115                                 $type="json";           
116                                 if (strpos($a->query_string, ".xml")>0) $type="xml";
117                                 if (strpos($a->query_string, ".json")>0) $type="json";
118                                 if (strpos($a->query_string, ".rss")>0) $type="rss";
119                                 if (strpos($a->query_string, ".atom")>0) $type="atom";                          
120                                 
121                                 $r = call_user_func($info['func'], $a, $type);
122                                 if ($r===false) return;
123
124                                 switch($type){
125                                         case "xml":
126                                                 $r = mb_convert_encoding($r, "UTF-8",mb_detect_encoding($r));
127                                                 header ("Content-Type: text/xml");
128                                                 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
129                                                 break;
130                                         case "json": 
131                                                 header ("Content-Type: application/json");  
132                                                 foreach($r as $rr)
133                                                     return json_encode($rr);
134                                                 break;
135                                         case "rss":
136                                                 header ("Content-Type: application/rss+xml");
137                                                 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
138                                                 break;
139                                         case "atom":
140                                                 header ("Content-Type: application/atom+xml");
141                                                 return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
142                                                 break;
143                                                 
144                                 }
145                                 //echo "<pre>"; var_dump($r); die();
146                         }
147                 }
148                 return false;
149         }
150
151         /**
152          * RSS extra info
153          */
154         function api_rss_extra(&$a, $arr, $user_info){
155                 if (is_null($user_info)) $user_info = api_get_user($a);
156                 $arr['$user'] = $user_info;
157                 $arr['$rss'] = array(
158                         'alternate' => $user_info['url'],
159                         'self' => $a->get_baseurl(). "/". $a->query_string,
160                         'updated' => api_date(null),
161                         'language' => $user_info['language'],
162                         'logo'  => $a->get_baseurl()."/images/friendika-32.png",
163                 );
164                 
165                 return $arr;
166         }
167          
168         /**
169          * Returns user info array.
170          */
171         function api_get_user(&$a, $contact_id = Null){
172                 $user = null;
173                 $extra_query = "";
174
175                 if(!is_null($contact_id)){
176                         $user=$contact_id;
177                         $extra_query = "AND `contact`.`id` = %d ";
178                 }
179                 
180                 if(is_null($user) && x($_GET, 'user_id')) {
181                         $user = intval($_GET['user_id']);       
182                         $extra_query = "AND `contact`.`id` = %d ";
183                 }
184                 if(is_null($user) && x($_GET, 'screen_name')) {
185                         $user = dbesc($_GET['screen_name']);    
186                         $extra_query = "AND `contact`.`nick` = '%s' ";
187                 }
188                 
189                 if (is_null($user)){
190                         list($user, $null) = explode(".",$a->argv[3]);
191                         if(is_numeric($user)){
192                                 $user = intval($user);
193                                 $extra_query = "AND `contact`.`id` = %d ";
194                         } else {
195                                 $user = dbesc($user);
196                                 $extra_query = "AND `contact`.`nick` = '%s' ";
197                         }
198                 }
199                 
200                 if ($user==='') {
201                         if (local_user()===false) {
202                                 api_login($a); return False;
203                         } else {
204                                 $user = $_SESSION['uid'];
205                                 $extra_query = "AND `contact`.`uid` = %d AND `contact`.`self` = 1 ";
206                         }
207                         
208                 }
209                 
210
211                 // user info            
212                 $uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `contact`
213                                 WHERE 1
214                                 $extra_query",
215                                 $user
216                 );
217                 if (count($uinfo)==0) {
218                         return False;
219                 }
220                 
221                 // count public wall messages
222                 $r = q("SELECT COUNT(`id`) as `count` FROM `item`
223                                 WHERE  `uid` = %d
224                                 AND `type`='wall' 
225                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
226                                 intval($uinfo[0]['uid'])
227                 );
228                 $countitms = $r[0]['count'];
229                 
230                 // count friends
231                 $r = q("SELECT COUNT(`id`) as `count` FROM `contact`
232                                 WHERE  `uid` = %d
233                                 AND `self`=0 AND `blocked`=0", 
234                                 intval($uinfo[0]['uid'])
235                 );
236                 $countfriends = $r[0]['count'];
237                                 
238
239                 $ret = Array(
240                         'uid' => $uinfo[0]['uid'],
241                         'id' => $uinfo[0]['cid'],
242                         'name' => $uinfo[0]['name'],
243                         'screen_name' => $uinfo[0]['nick'],
244                         'location' => '', //$uinfo[0]['default-location'],
245                         'profile_image_url' => $uinfo[0]['micro'],
246                         'url' => $uinfo[0]['url'],
247                         'contact_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'],
248                         'protected' => false,   #
249                         'friends_count' => $countfriends,
250                         'created_at' => api_date($uinfo[0]['name-date']),
251                         'utc_offset' => 0, #XXX: fix me
252                         'time_zone' => '', //$uinfo[0]['timezone'],
253                         'geo_enabled' => false,
254                         'statuses_count' => $countitms, #XXX: fix me 
255                         'lang' => 'en', #XXX: fix me
256                         'description' => '',
257                         'followers_count' => $countfriends, #XXX: fix me
258                         'favourites_count' => 0,
259                         'contributors_enabled' => false,
260                         'follow_request_sent' => false,
261                         'profile_background_color' => 'cfe8f6',
262                         'profile_text_color' => '000000',
263                         'profile_link_color' => 'FF8500',
264                         'profile_sidebar_fill_color' =>'AD0066',
265                         'profile_sidebar_border_color' => 'AD0066',
266                         'profile_background_image_url' => '',
267                         'profile_background_tile' => false,
268                         'profile_use_background_image' => false,
269                         'notifications' => false,
270                         'verified' => true, #XXX: fix me
271                         'followers' => '', #XXX: fix me
272                         #'status' => null
273                 );
274         
275                 return $ret;
276                 
277         }
278
279         function api_item_get_user(&$a, $item) {
280                 if(link_compare($item['url'],$item['author-link']))
281                         return api_get_user($a,$item['cid']);
282                 $ret = array(
283                         'uid' => 0,
284                         'id' => 0,
285                         'name' => $item['author-name'],
286                         'screen_name' => '',
287                         'location' => '', //$uinfo[0]['default-location'],
288                         'profile_image_url' => $item['author-avatar'],
289                         'url' => $item['author-link'],
290                         'contact_url' => 0,
291                         'protected' => false,   #
292                         'friends_count' => 0,
293                         'created_at' => '0000-00-00 00:00:00',
294                         'utc_offset' => 0, #XXX: fix me
295                         'time_zone' => '', //$uinfo[0]['timezone'],
296                         'geo_enabled' => false,
297                         'statuses_count' => 0,
298                         'lang' => 'en', #XXX: fix me
299                         'description' => '',
300                         'followers_count' => 0,
301                         'favourites_count' => 0,
302                         'contributors_enabled' => false,
303                         'follow_request_sent' => false,
304                         'profile_background_color' => 'cfe8f6',
305                         'profile_text_color' => '000000',
306                         'profile_link_color' => 'FF8500',
307                         'profile_sidebar_fill_color' =>'AD0066',
308                         'profile_sidebar_border_color' => 'AD0066',
309                         'profile_background_image_url' => '',
310                         'profile_background_tile' => false,
311                         'profile_use_background_image' => false,
312                         'notifications' => false,
313                         'verified' => true, #XXX: fix me
314                         'followers' => '', #XXX: fix me
315                         #'status' => null
316                 );
317
318                 return $ret; 
319         }
320
321         /**
322          * apply xmlify() to all values of array $val, recursively
323          */
324         function api_xmlify($val){
325                 if (is_bool($val)) return $val?"true":"false";
326                 if (is_array($val)) return array_map('api_xmlify', $val);
327                 return xmlify($val);
328         }
329
330         /**
331          *  load api $templatename for $type and replace $data array
332          */
333         function api_apply_template($templatename, $type, $data){
334
335                 switch($type){
336                         case "rss":
337                         case "atom":
338                         case "xml":
339                                 $data = api_xmlify($data);
340                                 $tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
341                                 $ret = replace_macros($tpl, $data);
342                                 break;
343                         case "json":
344                                 $ret = $data;
345                                 break;
346                 }
347                 return $ret;
348         }
349         
350         /**
351          ** TWITTER API
352          */
353         
354         /**
355          * Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; 
356          * returns a 401 status code and an error message if not. 
357          * http://developer.twitter.com/doc/get/account/verify_credentials
358          */
359         function api_account_verify_credentials(&$a, $type){
360                 if (local_user()===false) return false;
361                 $user_info = api_get_user($a);
362                 
363                 return api_apply_template("user", $type, array('$user' => $user_info));
364
365         }
366         api_register_func('api/account/verify_credentials','api_account_verify_credentials', true);
367                 
368
369         /**
370          * get data from $_POST or $_GET
371          */
372         function requestdata($k){
373                 if (isset($_POST[$k])){
374                         return $_POST[$k];
375                 }
376                 if (isset($_GET[$k])){
377                         return $_GET[$k];
378                 }
379                 return null;
380         }
381         // TODO - media uploads
382         function api_statuses_update(&$a, $type) {
383                 if (local_user()===false) return false;
384                 $user_info = api_get_user($a);
385
386                 // convert $_POST array items to the form we use for web posts.
387
388                 $_POST['body'] = urldecode(requestdata('status'));
389                 $_POST['parent'] = requestdata('in_reply_to_status_id');
390                 if(requestdata('lat') && requestdata('long'))
391                         $_POST['coord'] = sprintf("%s %s",requestdata('lat'),requestdata('long'));
392                 $_POST['profile_uid'] = local_user();
393                 if(requestdata('parent'))
394                         $_POST['type'] = 'net-comment';
395                 else
396                         $_POST['type'] = 'wall';
397
398                 // set this so that the item_post() function is quiet and doesn't redirect or emit json
399
400                 $_POST['api_source'] = true;
401
402                 // call out normal post function
403
404                 require_once('mod/item.php');
405                 item_post($a);  
406
407                 // this should output the last post (the one we just posted).
408                 return api_status_show($a,$type);
409         }
410         api_register_func('api/statuses/update','api_statuses_update', true);
411
412
413         function api_status_show(&$a, $type){
414                 $user_info = api_get_user($a);
415                 // get last public wall message
416                 $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
417                                 FROM `item`, `contact`,
418                                         (SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i` 
419                                 WHERE `item`.`contact-id` = %d
420                                         AND `i`.`id` = `item`.`parent`
421                                         AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
422                                         AND `type`!='activity'
423                                         AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
424                                 ORDER BY `created` DESC 
425                                 LIMIT 1",
426                                 intval($user_info['id'])
427                 );
428
429                 if (count($lastwall)>0){
430                         $lastwall = $lastwall[0];
431                         
432                         $in_reply_to_status_id = '';
433                         $in_reply_to_user_id = '';
434                         $in_reply_to_screen_name = '';
435                         if ($lastwall['parent']!=$lastwall['id']) {
436                                 $in_reply_to_status_id=$lastwall['parent'];
437                                 $in_reply_to_user_id = $lastwall['reply_uid'];
438                                 $in_reply_to_screen_name = $lastwall['reply_author'];
439                         }  
440                         $status_info = array(
441                                 'created_at' => api_date($lastwall['created']),
442                                 'id' => $lastwall['contact-id'],
443                                 'text' => strip_tags(bbcode($lastwall['body'])),
444                                 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
445                                 'truncated' => false,
446                                 'in_reply_to_status_id' => $in_reply_to_status_id,
447                                 'in_reply_to_user_id' => $in_reply_to_user_id,
448                                 'favorited' => false,
449                                 'in_reply_to_screen_name' => $in_reply_to_screen_name,
450                                 'geo' => '',
451                                 'coordinates' => $lastwall['coord'],
452                                 'place' => $lastwall['location'],
453                                 'contributors' => ''                                    
454                         );
455                         $status_info['user'] = $user_info;
456                 }
457                 return  api_apply_template("status", $type, array('$status' => $status_info));
458                 
459         }
460
461
462
463
464                 
465         /**
466          * Returns extended information of a given user, specified by ID or screen name as per the required id parameter.
467          * The author's most recent status will be returned inline.
468          * http://developer.twitter.com/doc/get/users/show
469          */
470         function api_users_show(&$a, $type){
471                 $user_info = api_get_user($a);
472                 // get last public wall message
473                 $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
474                                 FROM `item`, `contact`,
475                                         (SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i` 
476                                 WHERE `item`.`contact-id` = %d
477                                         AND `i`.`id` = `item`.`parent`
478                                         AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
479                                         AND `type`!='activity'
480                                         AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
481                                 ORDER BY `created` DESC 
482                                 LIMIT 1",
483                                 intval($user_info['id'])
484                 );
485
486                 if (count($lastwall)>0){
487                         $lastwall = $lastwall[0];
488                         
489                         $in_reply_to_status_id = '';
490                         $in_reply_to_user_id = '';
491                         $in_reply_to_screen_name = '';
492                         if ($lastwall['parent']!=$lastwall['id']) {
493                                 $in_reply_to_status_id=$lastwall['parent'];
494                                 $in_reply_to_user_id = $lastwall['reply_uid'];
495                                 $in_reply_to_screen_name = $lastwall['reply_author'];
496                         }  
497                         $user_info['status'] = array(
498                                 'created_at' => api_date($lastwall['created']),
499                                 'id' => $lastwall['contact-id'],
500                                 'text' => strip_tags(bbcode($lastwall['body'])),
501                                 'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
502                                 'truncated' => false,
503                                 'in_reply_to_status_id' => $in_reply_to_status_id,
504                                 'in_reply_to_user_id' => $in_reply_to_user_id,
505                                 'favorited' => false,
506                                 'in_reply_to_screen_name' => $in_reply_to_screen_name,
507                                 'geo' => '',
508                                 'coordinates' => $lastwall['coord'],
509                                 'place' => $lastwall['location'],
510                                 'contributors' => ''                                    
511                         );
512                 }
513                 return  api_apply_template("user", $type, array('$user' => $user_info));
514                 
515         }
516         api_register_func('api/users/show','api_users_show');
517         
518         /**
519          * 
520          * http://developer.twitter.com/doc/get/statuses/home_timeline
521          * 
522          * TODO: Optional parameters
523          * TODO: Add reply info
524          */
525         function api_statuses_home_timeline(&$a, $type){
526                 if (local_user()===false) return false;
527                 
528                 $user_info = api_get_user($a);
529                 // get last newtork messages
530                 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
531
532                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
533                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
534                         `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
535                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
536                         FROM `item`, `contact`
537                         WHERE `item`.`uid` = %d
538                         AND `item`.`visible` = 1 AND `item`.`deleted` = 0
539                         AND `contact`.`id` = `item`.`contact-id`
540                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
541                         $sql_extra
542                         ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
543                         intval($user_info['uid']),
544                         0,20
545                 );
546                 $ret = Array();
547
548                 foreach($r as $item) {
549                         $status_user = (($item['cid']==$user_info['id'])?$user_info: api_item_get_user($a,$item));
550                         $status = array(
551                                 'created_at'=> api_date($item['created']),
552                                 'published' => datetime_convert('UTC','UTC',$item['created'],ATOM_TIME),
553                                 'updated'   => datetime_convert('UTC','UTC',$item['edited'],ATOM_TIME),
554                                 'id'            => $item['id'],
555                                 'text'          => strip_tags(bbcode($item['body'])),
556                                 'html'          => bbcode($item['body']),
557                                 'source'    => (($item['app']) ? $item['app'] : 'web'),
558                                 'url'           => ($item['plink']!=''?$item['plink']:$item['author-link']),
559                                 'truncated' => False,
560                                 'in_reply_to_status_id' => ($item['parent']!=$item['id']?$item['parent']:''),
561                                 'in_reply_to_user_id' => '',
562                                 'favorited' => false,
563                                 'in_reply_to_screen_name' => '',
564                                 'geo' => '',
565                                 'coordinates' => $item['coord'],
566                                 'place' => $item['location'],
567                                 'contributors' => '',
568                                 'annotations'  => '',
569                                 'entities'  => '',
570                                 'user' =>  $status_user ,
571                                 'objecttype' => $item['object-type'],
572                                 'verb' => $item['verb'],
573                                 'self' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type,
574                                 'edit' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type,                         
575                         );
576                         $ret[]=$status;
577                 };
578                 
579                 $data = array('$statuses' => $ret);
580                 switch($type){
581                         case "atom":
582                         case "rss":
583                                 $data = api_rss_extra($a, $data, $user_info);
584                 }
585                                 
586                 return  api_apply_template("timeline", $type, $data);
587         }
588         api_register_func('api/statuses/home_timeline','api_statuses_home_timeline', true);
589         api_register_func('api/statuses/friends_timeline','api_statuses_home_timeline', true);
590         api_register_func('api/statuses/user_timeline','api_statuses_home_timeline', true);
591         # TODO: user_timeline should be profile view
592         
593
594         function api_account_rate_limit_status(&$a,$type) {
595
596                 $hash = array(
597                           'remaining_hits' => (string) 150,
598                           'hourly_limit' => (string) 150,
599                           'reset_time' => datetime_convert('UTC','UTC','now + 1 hour',ATOM_TIME),
600                           'reset_time_in_seconds' => strtotime('now + 1 hour')
601                 );
602
603                 return api_apply_template('ratelimit', $type, array('$hash' => $hash));
604
605         }
606         api_register_func('api/account/rate_limit_status','api_account_rate_limit_status',true);
607
608
609         function api_statusnet_config(&$a,$type) {
610                 $name = $a->config['sitename'];
611                 $server = $a->get_hostname();
612                 $logo = $a->get_baseurl() . '/images/friendika-64.png';
613                 $email = $a->config['admin_email'];
614                 $closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
615                 $private = (($a->config['system']['block_public']) ? 'true' : 'false');
616                 $textlimit = (($a->config['max_import_size']) ? $a->config['max_import_size'] : '200000');
617                 $ssl = (($a->config['system']['have_ssl']) ? 'true' : 'false');
618                 $sslserver = (($ssl === 'true') ? str_replace('http:','https:',$a->get_baseurl()) : '');
619
620                 $config = array(
621                         'site' => array('name' => $name,'server' => $server, 'theme' => 'default', 'path' => '',
622                                 'logo' => $logo, 'fancy' => 'true', 'language' => 'en', 'email' => $email, 'broughtby' => '',
623                                 'broughtbyurl' => '', 'timezone' => 'UTC', 'closed' => $closed, 'inviteonly' => 'false',
624                                 'private' => $private, 'textlimit' => $textlimit, 'sslserver' => $sslserver, 'ssl' => $ssl,
625                                 'shorturllength' => '30'
626                         ),
627                 );  
628
629                 return api_apply_template('config', $type, array('$config' => $config));
630
631         }
632         api_register_func('api/statusnet/config','api_statusnet_config',false);
633
634
635         function api_statusnet_version(&$a,$type) {
636
637                 // liar
638
639                 if($type === 'xml') {
640                         header("Content-type: application/xml");
641                         echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<version>0.9.7</version>' . "\r\n";
642                         killme();
643                 }
644                 elseif($type === 'json') {
645                         header("Content-type: application/json");
646                         echo '"0.9.7"';
647                         killme();
648                 }
649         }
650         api_register_func('api/statusnet/version','api_statusnet_version',false);