56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
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;
|
|
}
|
|
|
|
return [
|
|
|
|
"post" => function($data, $headers, $db) {
|
|
$imagesHostName = 'https://geohry.skolazdola.cz/';
|
|
|
|
$gameUrl = $data['gameurl'];
|
|
|
|
$gameDetails = $db->select('games4', '*', [
|
|
'url' => $gameUrl
|
|
])[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 $gameDetails;
|
|
}
|
|
|
|
];
|