api issues

This commit is contained in:
zotlabs 2016-10-10 23:24:30 -07:00
parent c6eecb06d5
commit c4debca11d

View file

@ -118,7 +118,11 @@ require_once('include/api_auth.php');
break; break;
case "json": case "json":
header ("Content-Type: application/json"); header ("Content-Type: application/json");
$json = json_encode((is_array($r[0])) ? $r[0] : array()); if($r) {
foreach($r as $rv) {
$json = json_encode($rv);
}
}
// Lookup JSONP to understand these lines. They provide cross-domain AJAX ability. // Lookup JSONP to understand these lines. They provide cross-domain AJAX ability.
if ($_GET['callback']) if ($_GET['callback'])
$json = $_GET['callback'] . '(' . $json . ')' ; $json = $_GET['callback'] . '(' . $json . ')' ;
@ -133,7 +137,12 @@ require_once('include/api_auth.php');
return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r; return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
break; break;
case "as": case "as":
return json_encode($r); if($r) {
foreach($r as $rv) {
$json = json_encode($rv);
}
}
return $json;
break; break;
} }
@ -338,7 +347,6 @@ require_once('include/api_auth.php');
$x = api_get_status($uinfo[0]['xchan_hash']); $x = api_get_status($uinfo[0]['xchan_hash']);
if($x) if($x)
$ret['status'] = $x; $ret['status'] = $x;
// logger('api_get_user: ' . print_r($ret,true)); // logger('api_get_user: ' . print_r($ret,true));
return $ret; return $ret;
@ -450,9 +458,11 @@ require_once('include/api_auth.php');
$ret = replace_macros($tpl, $data); $ret = replace_macros($tpl, $data);
break; break;
case "json": case "json":
default:
$ret = $data; $ret = $data;
break; break;
} }
return $ret; return $ret;
} }
@ -465,7 +475,6 @@ require_once('include/api_auth.php');
function api_account_verify_credentials( $type){ function api_account_verify_credentials( $type){
if (api_user()===false) return false; if (api_user()===false) return false;
$user_info = api_get_user($a); $user_info = api_get_user($a);
return api_apply_template("user", $type, array('$user' => $user_info)); return api_apply_template("user", $type, array('$user' => $user_info));
} }