Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- error_reporting(E_ALL^E_DEPRECATED);
- include 'inc/db.php';
- include 'inc/generic.php';
- $methods = array();
- function method_register($method)
- {
- global $methods;
- if(strlen($method) < 1)
- return;
- $methods[] = $method;
- }
- function method_supported($method)
- {
- global $methods;
- foreach($methods as $m)
- {
- if($m == $method)
- return true;
- }
- return false;
- }
- function argument_require($arg)
- {
- if(!isset($_GET[$arg]))
- {
- echo "Argument $arg expected";
- exit;
- }
- return $_GET[$arg];
- }
- /**
- Начало блока реализации API вызовов
- */
- function user_get()
- {
- $response["result"] = "OK";
- $id = intval(argument_require("id"));
- $user = user_fetch($id);
- if($user)
- {
- $response["nick"] = $user["nick"];
- $response["rating"] = $user["rating"];
- $response["regdate"] = $user["regdate"];
- $response["rights"] = $user["rights"];
- $response["visit"] = $user["visit"];
- $response["realname"] = $user["ank_real"];
- $response["gender"] = $user["ank_gender"];
- $response["birthday"] = $user["ank_birhday"];
- $response["city"] = $user["ank_city"];
- $response["interests"] = $user["ank_interesy"];
- $response["hair"] = $user["ank_hair"];
- $response["height"] = $user["ank_rost"];
- $response["weight"] = $user["ank_weight"];
- }
- else
- {
- $response["result"] = "UNF";
- }
- return $response;
- }
- function user_exists()
- {
- $response["result"] = "OK";
- $name = mysql_filt(argument_require("name"));
- if(user_fetch_by_name($name) == null)
- $response["result"] = "UNK";
- return $response;
- }
- function user_mail()
- {
- $response["result"] = "OK";
- $from = intval(argument_require("from"));
- $password = mysql_filt(argument_require("password"));
- $to = intval(argument_require("to"));
- $message = smiles_preprocess(bb_preprocess(mysql_filt(argument_require("message"))));
- $user = user_fetch($from);
- $receiver = user_fetch($to);
- if($from && $to)
- {
- if($user["password"] == $password)
- {
- mail_send($to, $from, $message);
- }
- else
- {
- $response["result"] = "IP";
- }
- }
- else
- {
- $response["result"] = "UNK";
- }
- return $response;
- }
- /**
- Конец блока реализации API вызовов
- */
- method_register("user_get");
- method_register("user_mail");
- method_register("user_exists");
- if(!isset($_GET["method"]) || !method_supported($_GET["method"]))
- {
- echo "Unknown API method specified";
- exit;
- }
- $method = $_GET["method"];
- foreach($methods as $m)
- {
- if($m == $method)
- {
- if(function_exists($m))
- {
- $response = call_user_func($m);
- echo json_encode($response);
- }
- else
- {
- echo "Not implemented yet";
- }
- exit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement