You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
<?php
|
|
$endpoint = $_POST['endpoint'];
|
|
|
|
$header = "";
|
|
|
|
if (isset($_POST['headers'])){
|
|
$wanted_headers = $_POST['headers'];
|
|
foreach ($wanted_headers as $key => $value) {
|
|
$header .= "$key: $value\r\n";
|
|
}
|
|
}
|
|
|
|
$api_key = parse_ini_file("../../../.env")['API_KEY'];
|
|
|
|
$opts = [
|
|
"http" => [
|
|
"method" => "GET",
|
|
"header" => "X-Api-Key: $api_key\r\n$header"
|
|
]
|
|
];
|
|
|
|
$context = stream_context_create($opts);
|
|
|
|
$result = @file_get_contents("https://api.toornament.com/$endpoint", false, $context);
|
|
if (!$result){
|
|
echo false;
|
|
} else {
|
|
$real_size = false;
|
|
foreach ($http_response_header as $item){
|
|
$pattern = "#Content-Range: [a-z]+ [0-9]+\-[0-9]+/([0-9]+)#";
|
|
if (preg_match($pattern, $item, $re) == 1){
|
|
$real_size = $re[1];
|
|
break;
|
|
}
|
|
}
|
|
if (is_numeric($real_size)){
|
|
$array = json_decode($result);
|
|
$object = new stdClass();
|
|
$object->items = $array;
|
|
$object->real_size = $real_size;
|
|
echo json_encode($object);
|
|
} else {
|
|
echo $result;
|
|
}
|
|
}
|
|
|