52 lines
No EOL
1.7 KiB
PHP
52 lines
No EOL
1.7 KiB
PHP
<?php
|
|
// Tile Handler for @2x Detection
|
|
$request_uri = $_SERVER['REQUEST_URI'];
|
|
|
|
// Check if it's a @2x request
|
|
if (preg_match('/^\/hot\/(\d+)\/(\d+)\/(\d+)@2x\.png$/', $request_uri, $matches)) {
|
|
$z = $matches[1];
|
|
$x = $matches[2];
|
|
$y = $matches[3];
|
|
|
|
// Check if retina tile exists
|
|
$retina_file = "/var/cache/renderd/tiles/retina/{$z}/{$x}/{$y}.png";
|
|
|
|
if (file_exists($retina_file)) {
|
|
// Serve the retina tile
|
|
header("Content-Type: image/png");
|
|
header("Cache-Control: public, max-age=86400");
|
|
readfile($retina_file);
|
|
exit;
|
|
} else {
|
|
// Try to request tile rendering via mod_tile
|
|
$render_url = "http://localhost/ret/{$z}/{$x}/{$y}.png";
|
|
|
|
// Use cURL to request tile rendering
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $render_url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
$result = curl_exec($ch);
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
// Check if tile was rendered successfully
|
|
if ($http_code == 200 && file_exists($retina_file)) {
|
|
header("Content-Type: image/png");
|
|
header("Cache-Control: public, max-age=86400");
|
|
readfile($retina_file);
|
|
exit;
|
|
} else {
|
|
// Return 404 if tile still doesn't exist
|
|
http_response_code(404);
|
|
echo "Tile not found (HTTP: {$http_code})";
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
// If not a @2x request, continue with normal processing
|
|
http_response_code(404);
|
|
echo "Invalid request";
|
|
?>
|