31 lines
1007 B
PHP
31 lines
1007 B
PHP
<?php
|
|
/**
|
|
* api/place-photo.php
|
|
* Handles image redirection based on photo_reference and API key availability.
|
|
*/
|
|
|
|
$photoReference = $_GET['photo_reference'] ?? null;
|
|
$apiKey = getenv('GOOGLE_MAPS_API_KEY');
|
|
$unsplashUrls = [
|
|
'https://images.unsplash.com/photo-1544833316-64d88e00182a?w=800',
|
|
'https://images.unsplash.com/photo-1570168007204-dfb528c6958f?w=800',
|
|
'https://images.unsplash.com/photo-1524231757912-21f4fe3a7200?w=800'
|
|
];
|
|
|
|
if (empty($photoReference)) {
|
|
// Redirect to random Unsplash Kapadokya photo
|
|
header('Location: ' . $unsplashUrls[array_rand($unsplashUrls)]);
|
|
exit;
|
|
}
|
|
|
|
if (!empty($apiKey)) {
|
|
// Redirect to Google Places Photo
|
|
$url = "https://maps.googleapis.com/maps/api/place/photo?maxwidth=800&photo_reference=" . urlencode($photoReference) . "&key=" . urlencode($apiKey);
|
|
header('Location: ' . $url);
|
|
exit;
|
|
}
|
|
|
|
// Fallback: Redirect to random Unsplash photo if no API key
|
|
header('Location: ' . $unsplashUrls[array_rand($unsplashUrls)]);
|
|
exit;
|