Revert to version 7f63bcb
This commit is contained in:
parent
3c2fbf7b0e
commit
8debf8b949
@ -1,28 +0,0 @@
|
|||||||
<?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);
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 361 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 613 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB |
@ -1,25 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
26
index.php
26
index.php
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@ -48,22 +47,17 @@
|
|||||||
<!-- 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">Winter Gallery</h2>
|
<h2 class="text-center mb-4">Gallery</h2>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<?php
|
<div class="col-md-4 mb-4">
|
||||||
ob_start();
|
<img src="https://via.placeholder.com/400" class="img-fluid" alt="Gallery Image">
|
||||||
include 'api/pexels.php';
|
</div>
|
||||||
$images_json = ob_get_clean();
|
<div class="col-md-4 mb-4">
|
||||||
$images = json_decode($images_json, true);
|
<img src="https://via.placeholder.com/400" class="img-fluid" alt="Gallery Image">
|
||||||
if ($images) {
|
</div>
|
||||||
foreach ($images as $image) {
|
<div class="col-md-4 mb-4">
|
||||||
echo '<div class="col-md-4 mb-4">';
|
<img src="https://via.placeholder.com/400" class="img-fluid" alt="Gallery Image">
|
||||||
echo '<img src="' . htmlspecialchars($image['src']) . '" class="img-fluid" alt="Winter Image">';
|
</div>
|
||||||
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>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user