if (session_status() == PHP_SESSION_NONE) { session_start(); } $ax_params = []; if (!function_exists("axInit")) { function axInit($code, $version) { global $ax_params; $ax_params["code"] = $code; $ax_params["version"] = $version; $_SESSION["ax_code"] = $code; $_SESSION["ax_version"] = $version; }} if (!function_exists("isEmailx")) { function isEmailx($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); }} if (!function_exists("callAPI")) { function callAPI($code, $method, $url, $data) { //echo "
".$code." //\\ ".$method." //\\ ".$url." //\\ ".json_encode($data); exit(); $_SESSION["token"] = isset($_SESSION["token"]) ? $_SESSION["token"] : ""; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => $data, CURLOPT_HTTPHEADER => array( "Cache-Control: no-cache", "Content-Type: application/x-www-form-urlencoded", "projectID: ".$code, "token: ".$_SESSION["token"] ) )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) $result = "cURL Error #:" . $err; else $result = $response; //echo $response; $result = json_decode($result, JSON_UNESCAPED_SLASHES); return $result; }} if (!function_exists("callAPIFile")) { function callAPIFile($code, $method, $url, $data, $file_url) { $url = strtolower($url); //echo $url; //exit(); $_SESSION["token"] = isset($_SESSION["token"]) ? $_SESSION["token"] : ""; $eol = "\r\n"; $BOUNDARY = md5(time()); $BODY = ""; foreach ($data as $key => $value) { $BODY.= '--'.$BOUNDARY. $eol; $BODY.= 'Content-Disposition: form-data; name="'.$key.'"' . $eol . $eol; $BODY.= $value . $eol; } $BODY.= '--'.$BOUNDARY. $eol; $BODY.= 'Content-Disposition: form-data; name="file"; filename="'.$file_url.'"'. $eol ; $BODY.= 'Content-Type: application/octet-stream' . $eol; $BODY.= 'Content-Transfer-Encoding: base64' . $eol . $eol; $BODY.= file_get_contents($file_url) . $eol; $BODY.= '--'.$BOUNDARY .'--' . $eol. $eol; $curl = curl_init(); curl_setopt($curl, CURLOPT_POST, true); curl_setopt_array($curl, array( CURLOPT_URL => $url, //"https://api.axelib.io/0.1/file/upload", CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array( "Cache-Control: no-cache", "Content-Type: multipart/form-data; boundary=".$BOUNDARY, "projectID: ".$code, "token: ".$_SESSION["token"] ), CURLOPT_POSTFIELDS => $BODY, )); $response = curl_exec($curl); curl_close($curl); $result = json_decode($response, JSON_UNESCAPED_SLASHES); return $result; }} if (!function_exists("axCall")) { function axCall($method, $entity, $post=[], $id=null) { global $ax_params; $code = isset($ax_params["code"]) ? $ax_params["code"] : $_SESSION["ax_code"]; $version = isset($ax_params["version"]) ? $ax_params["version"] : $_SESSION["ax_version"]; $url = "https://api.axelib.io/".$version."/" . $method . "/"; if ($entity) $url .= $entity . "/"; if ($method == "FILE") return callAPIFile($code, "POST", $url, $post, $id); //$id = file_url else if ($id) $url .= $id; return callAPI($code, "POST", $url, http_build_query($post)); }} if (!function_exists("axGet")) { function axGet($entity, $id) { return axCall("get", $entity, [], $id); }} if (!function_exists("axList")) { function axList($entity, $post=[], $id=null) { return axCall("list", $entity, $post, $id); } } if (!function_exists("axPost")) { function axPost($entity, $post) { return axCall("post", $entity, $post); }} if (!function_exists("axUpdate")) { function axUpdate($entity, $post, $id) { return axCall("update", $entity, $post, $id); }} if (!function_exists("axDelete")) { function axDelete($entity, $id) { return axCall("delete", $entity, null, $id); }} if (!function_exists("axQuery")) { function axQuery($queryName, $post, $version) { return axCall("query", $queryName, $post, $version); }} if (!function_exists("axSQL")) { function axSQL($sql) { return axCall("sql", "query", array("sql"=>$sql)); }} if (!function_exists("axMail")) { function axMail($to, $title, $data=null, $template=null) { $id = null; $post = []; if (isEmailx($to)) $post["email"] = $to; else $id = $to; if (isset($template)) { $post["template"] = $template; $post = array_merge($post, $data); } else { $post["title"] = $title; $post["body"] = $data; } return axCall("mail", "user", $post, $id); //echo axMail("bandzagilles@yahoo.fr", "Hello", "World"); //Simple //echo axMail("bandzagilles@yahoo.fr", "bonjour", array("text"=>"Hello world"), "newsletter"); //With template }} if (!function_exists("axPush")) { function axPush($user_id, $title, $message, $add) { $post = array( "title"=>$title, "message"=>$message ); if (isset($add)) $post["additional_info"] = $add; return axCall("push", "user", $post, $id); }} if (!function_exists("axLogout")) { function axLogout() { unset($_SESSION["token"]); return axCall("logout", "user"); }} if (!function_exists("axRegister")) { function axRegister($login, $password, $obj) { $post = array( "email"=>$login, "password"=>$password, ); foreach ($obj as $key => $value) { //echo "$key => $value\n"; $post[$key] = $value; } return axCall("register", "user", $post); }} if (!function_exists("axCount")) { function axCount($entity) { return axCall("count", $entity); }} if (!function_exists("axLogin")) { function axLogin($login, $password) { $post = array( "email"=>$login, "password"=>$password, ); $result = axCall("login", "user", $post); $_SESSION["token"] = $result["user"]["token"]; $_SESSION["user"] = $result["user"]["user"]; return $result; }} if (!function_exists("axChangePwd")) { function axChangePwd($oldpwd, $newpwd) { $post = array( "password"=>$oldpwd, "new_password"=>$newpwd, ); return axCall("changepwd", "user", $post); }} if (!function_exists("axForgotPwd")) { function axForgotPwd($email) { $post = array( "email"=>$email ); return axCall("forgotpwd", "user", $post); }} if (!function_exists("axLogic")) { function axLogic($logicName, $post, $schema) { return axCall("logic", $logicName, $post, $schema); }} if (!function_exists("axFile")) { function axFile($file_url, $table=null, $field=null, $id=null) { $post = []; if (isset($table)) $post["target_table"] = $table; if (isset($field)) $post["target_field"] = $field; if (isset($id)) $post["target_id"] = $id; //echo $file_url; return axCall("file", "upload", $post, $file_url); }} if (!function_exists("axCharge")) { function axCharge($title, $body, $user_id, $email) { return true; }} //echo axList("transaction"); //echo axCount("transaction"); //echo axGet("transaction", 103); //echo axPost("hello", array("name"=>"tito")); //echo axUpdate("hello", array("name"=>"tita"), 1); //echo axDelete("hello", 2); //echo axSQL("SELECT * FROM `@table.hello`"); //echo axMail("bandzagilles@yahoo.fr", "Hello", "World"); //echo axMail("bandzagilles@yahoo.fr", "bonjour", array("text"=>"Hello world"), "newsletter"); //echo axQuery("query_rate", array("name"=>"xaf"), 0.1); //echo axRegister("bandzagilles@yahoo.fr", "toto1234"); //echo axLogin("helloworld@loulou.com", "toto1234"); //Token in : $_SESSION["token"], user in $_SESSION["user"] //echo axLogin("bandzagilles@yahoo.fr", "toto1234"); //echo axChangePwd("bandzagilles@yahoo.fr", "toto1234", "toto5678"); //echo axForgotPwd("bandzagilles@yahoo.fr"); //echo axChangEmail("bandzagilles@yahoo.fr"); //echo axLogic("tarif", $data); OR axLogic("tarif", $data, true); to get the schema //echo axFile("https://file.txt", "car", "image", 7); //echo axPush(1, "New Message", "Your received a new message in AppName", array("name"=>"tito")); //axLogout(); //echo axMail("bandzagilles@yahoo.fr", "Hello", "World"); //Simple //echo axMail("bandzagilles@yahoo.fr", "bonjour", array("text"=>"Hello world"), "newsletter"); //With template //Read response : $result = json_decode($response, JSON_UNESCAPED_SLASHES);