- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
$USER_ID = $_GET['user_id'];
$API_METHOD = $_GET['method'];
$Errors = array('Error#001' => 'Undefined data in request!');
switch($API_METHOD)
{
case 'get_user_name_by_id':
echo EncodeJSON(UserAPI::GetUserNameByID($USER_ID));
break;
case 'get_user_status_by_id':
echo EncodeJSON(UserAPI::GetUserStatusByID($USER_ID));
break;
default:
echo $Errors['Error#001'];
break;
}
class UserAPI //test
{
function GetUserNameByID($ID)
{
$SqlQuery = mysql_query("SELECT displayname FROM engine4_users WHERE user_id='$ID'");
$Response = mysql_fetch_array($SqlQuery);
$Result = array('UserName'=>$Response['displayname']);
return $Result;
}
function GetUserStatusByID($ID)
{
$SqlQuery = mysql_query("SELECT status FROM engine4_users WHERE user_id='$ID'");
$Response = mysql_fetch_array($SqlQuery);
$Result = array('UserStatus'=>$Response['status']);
return $Result;
}
}
function EncodeJSON($arr) {
$parts = array();
$is_list = false;
if (!is_array($arr)) return;
if (count($arr)<1) return '{}';
$keys = array_keys($arr);
$max_length = count($arr);
if(($keys[0] == 0) and ($keys[$max_length] == $max_length)) {
$is_list = true;
for($i=0; $i<count($keys); $i++) {
if($i != $keys[$i]) {
$is_list = false;
break;
}
}
}
foreach($arr as $key=>$value) {
if(is_array($value)) {
if($is_list) $parts[] = array2json($value);
else $parts[] = '"' . $key . '":' . array2json($value);
} else {
$str = '';
if(!$is_list) $str = '"' . $key . '":';
if(is_numeric($value)) $str .= $value;
elseif($value === false) $str .= 'false';
elseif($value === true) $str .= 'true';
else $str .= '"' . addslashes($value) . '"';
$parts[] = $str;
}
}
$json = implode(',',$parts);
if($is_list) return '[' . $json . ']';
return '{' . $json . '}';
}
ReckO 14.04.2012 14:35 # +2
Lure Of Chaos 14.04.2012 16:20 # +2
Lowezar 14.04.2012 19:09 # +1
guest 14.04.2012 20:57 # +5
guest10 25.08.2021 03:20 # 0