Erant-OldApp/api/routes/game/details.php

56 lines
1.3 KiB
PHP
Raw Normal View History

2022-09-02 13:47:58 +00:00
<?php
2022-09-02 14:11:52 +00:00
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;
}
2022-09-02 13:47:58 +00:00
return [
"post" => function($data, $headers, $db) {
2022-09-02 14:11:52 +00:00
$imagesHostName = 'https://geohry.skolazdola.cz/';
$gameUrl = $data['gameurl'];
2022-09-02 13:47:58 +00:00
2022-09-02 14:11:52 +00:00
$gameDetails = $db->select('games4', '*', [
'url' => $gameUrl
2022-09-02 13:47:58 +00:00
])[0];
2022-09-02 14:11:52 +00:00
$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;
2022-09-02 13:47:58 +00:00
}
];