34968-vm/hero.php
Flatlogic Bot 5fc6fe4ad4 V13
2025-10-15 15:33:06 +00:00

104 lines
2.5 KiB
PHP

<?php
function get_hero_image() {
// Check if we have a cached image URL
if (isset($_SESSION['hero_image_url'])) {
return $_SESSION['hero_image_url'];
}
// If not, fetch a new one from Pexels
require_once __DIR__ . '/includes/pexels.php';
$query = 'island food';
$orientation = 'landscape';
$url = 'https://api.pexels.com/v1/search?query=' . urlencode($query) . '&orientation=' . urlencode($orientation) . '&per_page=1&page=' . rand(1, 100);
$data = pexels_get($url);
if (!empty($data['photos'])) {
$photo = $data['photos'][0];
$image_url = $photo['src']['large2x'] ?? $photo['src']['large'];
// Cache the URL in the session
$_SESSION['hero_image_url'] = $image_url;
return $image_url;
}
// Fallback image
return 'assets/images/hero.jpg';
}
$hero_image_url = get_hero_image();
?>
<style>
.hero-section {
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url('<?= $hero_image_url ?>');
background-size: cover;
background-position: center;
color: white;
text-align: left;
padding: 100px 50px;
display: flex;
align-items: center;
}
.hero-content {
max-width: 600px;
}
.hero-content h1 {
font-size: 3.5rem;
font-weight: 700;
margin-bottom: 1rem;
text-shadow: 2px 2px 8px rgba(0,0,0,0.6);
}
.hero-content p {
font-size: 1.25rem;
margin-bottom: 2rem;
}
.hero-search-form {
display: flex;
border-radius: 50px;
overflow: hidden;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.hero-search-input {
flex-grow: 1;
border: none;
padding: 1rem 1.5rem;
font-size: 1rem;
}
.hero-search-input:focus {
outline: none;
}
.hero-search-button {
border: none;
background-color: #FF6B6B;
color: white;
padding: 0 2rem;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s;
}
.hero-search-button:hover {
background-color: #ff4f4f;
}
</style>
<section class="hero-section">
<div class="hero-content">
<h1>Everything you crave, delivered.</h1>
<p>Your favorite local restaurants, delivered to your door.</p>
<form action="index.php" method="get" class="hero-search-form">
<input type="text" name="search" class="hero-search-input" placeholder="Find restaurants" value="<?= isset($_GET['search']) ? htmlspecialchars($_GET['search']) : '' ?>">
<button type="submit" class="hero-search-button">Find restaurants</button>
</form>
</div>
</section>