first WIP implementation

This commit is contained in:
2018-02-10 18:01:42 +01:00
parent b2cc5a0890
commit c1f5f4d451
7 changed files with 356 additions and 0 deletions

52
functions.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
function abort($msg="Unknown")
{
header("403 Forbidden");
$response = array(
"success" => false,
"message" => $msg
);
echo json_encode($response);
print("\n");
exit();
}
function exec_curl_request($handle)
{
$response = curl_exec($handle);
if ($response === false) {
$errno = curl_errno($handle);
$error = curl_error($handle);
error_log("Curl returned error $errno: $error\n");
curl_close($handle);
return false;
}
$http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
curl_close($handle);
if ($http_code >= 500) {
// do not want to DDOS server if something goes wrong
sleep(10);
return false;
} else if ($http_code != 200) {
$response = json_decode($response, true);
error_log("Request has failed with error {$response['error']}\n");
if ($http_code == 401) {
throw new Exception('Invalid access token provided');
}
return false;
} else {
$response = json_decode($response, true);
if (isset($response["event_id"])) {
$response = true;
} else {
$response = false;
}
}
return $response;
}
?>