Auto commit: 2025-12-01T15:42:03.999Z
This commit is contained in:
parent
7f63bcb39c
commit
3c2fbf7b0e
28
api/pexels.php
Normal file
28
api/pexels.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
require_once __DIR__.'/../includes/pexels.php';
|
||||||
|
$qs = isset($_GET['queries']) ? explode(',', $_GET['queries']) : ['home','apple','pizza','mountains','cat'];
|
||||||
|
$out = [];
|
||||||
|
foreach ($qs as $q) {
|
||||||
|
$u = 'https://api.pexels.com/v1/search?query=' . urlencode(trim($q)) . '&orientation=square&per_page=1&page=1';
|
||||||
|
$d = pexels_get($u);
|
||||||
|
if ($d && !empty($d['photos'])) {
|
||||||
|
$p = $d['photos'][0];
|
||||||
|
$src = $p['src']['original'] ?? null;
|
||||||
|
$dest = __DIR__.'/../assets/images/pexels/'.$p['id'].'.jpg';
|
||||||
|
if ($src) download_to($src, $dest);
|
||||||
|
$out[] = [
|
||||||
|
'src' => 'assets/images/pexels/'.$p['id'].'.jpg',
|
||||||
|
'photographer' => $p['photographer'] ?? 'Unknown',
|
||||||
|
'photographer_url' => $p['photographer_url'] ?? '',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
// Fallback: Picsum
|
||||||
|
$out[] = [
|
||||||
|
'src' => 'https://picsum.photos/600',
|
||||||
|
'photographer' => 'Random Picsum',
|
||||||
|
'photographer_url' => 'https://picsum.photos/'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode($out);
|
||||||
BIN
assets/images/pexels/102104.jpg
Normal file
BIN
assets/images/pexels/102104.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 361 KiB |
BIN
assets/images/pexels/698275.jpg
Normal file
BIN
assets/images/pexels/698275.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 613 KiB |
BIN
assets/images/pexels/842687.jpg
Normal file
BIN
assets/images/pexels/842687.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
25
includes/pexels.php
Normal file
25
includes/pexels.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
function pexels_key() {
|
||||||
|
$k = getenv('PEXELS_KEY');
|
||||||
|
return $k && strlen($k) > 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18';
|
||||||
|
}
|
||||||
|
function pexels_get($url) {
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_URL => $url,
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ],
|
||||||
|
CURLOPT_TIMEOUT => 15,
|
||||||
|
]);
|
||||||
|
$resp = curl_exec($ch);
|
||||||
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
if ($code >= 200 && $code < 300 && $resp) return json_decode($resp, true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
function download_to($srcUrl, $destPath) {
|
||||||
|
$data = file_get_contents($srcUrl);
|
||||||
|
if ($data === false) return false;
|
||||||
|
if (!is_dir(dirname($destPath))) mkdir(dirname($destPath), 0775, true);
|
||||||
|
return file_put_contents($destPath, $data) !== false;
|
||||||
|
}
|
||||||
28
index.php
28
index.php
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@ -47,17 +48,22 @@
|
|||||||
<!-- Gallery Section -->
|
<!-- Gallery Section -->
|
||||||
<section class="gallery-section bg-light py-5">
|
<section class="gallery-section bg-light py-5">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2 class="text-center mb-4">Gallery</h2>
|
<h2 class="text-center mb-4">Winter Gallery</h2>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4 mb-4">
|
<?php
|
||||||
<img src="https://via.placeholder.com/400" class="img-fluid" alt="Gallery Image">
|
ob_start();
|
||||||
</div>
|
include 'api/pexels.php';
|
||||||
<div class="col-md-4 mb-4">
|
$images_json = ob_get_clean();
|
||||||
<img src="https://via.placeholder.com/400" class="img-fluid" alt="Gallery Image">
|
$images = json_decode($images_json, true);
|
||||||
</div>
|
if ($images) {
|
||||||
<div class="col-md-4 mb-4">
|
foreach ($images as $image) {
|
||||||
<img src="https://via.placeholder.com/400" class="img-fluid" alt="Gallery Image">
|
echo '<div class="col-md-4 mb-4">';
|
||||||
</div>
|
echo '<img src="' . htmlspecialchars($image['src']) . '" class="img-fluid" alt="Winter Image">';
|
||||||
|
echo '<div class="text-center mt-2">Photo by <a href="' . htmlspecialchars($image['photographer_url']) . '" target="_blank">' . htmlspecialchars($image['photographer']) . '</a> on Pexels</div>';
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@ -96,4 +102,4 @@
|
|||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user