75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
|
<?php
|
||
|
|
||
|
return [
|
||
|
|
||
|
"post" => function($data, $headers, $db) {
|
||
|
function remoteFileExists($url) {
|
||
|
$curl = curl_init($url);
|
||
|
|
||
|
//don't fetch the actual page, you only want to check the connection is ok
|
||
|
curl_setopt($curl, CURLOPT_NOBODY, true);
|
||
|
|
||
|
//do request
|
||
|
$result = curl_exec($curl);
|
||
|
|
||
|
$ret = false;
|
||
|
|
||
|
//if request did not fail
|
||
|
if ($result !== false) {
|
||
|
//if request was ok, check response code
|
||
|
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||
|
|
||
|
if ($statusCode == 200) {
|
||
|
$ret = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
curl_close($curl);
|
||
|
|
||
|
return $ret;
|
||
|
}
|
||
|
|
||
|
$imagesHostName = 'https://geohry.skolazdola.cz/';
|
||
|
|
||
|
if(!isset($data['gameurl']) || empty($data['gameurl'])) return [
|
||
|
"data" => [
|
||
|
"success" => false,
|
||
|
"message" => "Property 'gameurl' is not set."
|
||
|
]
|
||
|
];
|
||
|
|
||
|
$gameUrl = $data['gameurl'];
|
||
|
|
||
|
$gameDetails = $db->select('games4', '*', [
|
||
|
'url' => $gameUrl
|
||
|
]);
|
||
|
|
||
|
if(!$gameDetails) return [
|
||
|
"data" => [
|
||
|
"success" => false,
|
||
|
"message" => "Invalid 'gameurl'."
|
||
|
]
|
||
|
];
|
||
|
|
||
|
$gameDetails = $gameDetails[0];
|
||
|
|
||
|
$gameDetails["questions"] = $db->select('questions4', '*', [
|
||
|
'url' => $gameUrl
|
||
|
]);
|
||
|
|
||
|
$thumbnailPath = "{$imagesHostName}/games/{$gameUrl}/intro.jpg";
|
||
|
$gameDetails["thumbnail"] = remoteFileExists($thumbnailPath) ? $thumbnailPath : null;
|
||
|
|
||
|
foreach($gameDetails["questions"] as &$question) {
|
||
|
$questionThumbnailPath = "{$imagesHostName}/games/{$gameUrl}/" . $question["uniqid"] . ".jpg";
|
||
|
$question["thumbnail"] = remoteFileExists($questionThumbnailPath) ? $questionThumbnailPath : null;
|
||
|
}
|
||
|
|
||
|
return [
|
||
|
"success" => true,
|
||
|
"data" => $gameDetails
|
||
|
];
|
||
|
}
|
||
|
|
||
|
];
|