Skip to content

Commit 55f0191

Browse files
benjaminkottandi34
authored andcommitted
bugfix: sort images and check for existing thumbnails
Change-Id: Ie21fde75c51c605600a407e6c08de33c8834576c
1 parent 380c6b5 commit 55f0191

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

resources/template/index.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
'images' => glob($templateConfig['paths']['images'] . '/*.{jpg,JPG}', GLOB_BRACE) ?: [],
1313
'thumbs' => glob($templateConfig['paths']['thumbs'] . '/*.{jpg,JPG}', GLOB_BRACE) ?: [],
1414
];
15+
16+
asort($images['images']);
17+
asort($images['thumbs']);
18+
1519
$firstImage = $images['images'][0] ?? null;
1620
$totalImages = count($images['images']);
1721

@@ -274,29 +278,37 @@ function zipFilesAndDownload($files, $templateConfig)
274278
</header>
275279
<div class="container">
276280
<div class="gallery-list">
277-
<?php foreach ($images['thumbs'] as $key => $filename) { ?>
278-
<?php $fullImage = $urlPrefix . $images['images'][$key]; ?>
281+
<?php foreach ($images['images'] as $key => $filename) { ?>
282+
<?php
283+
$filename = basename($filename);
284+
$image = $urlPrefix . $templateConfig['paths']['images'] . '/' . $filename;
285+
$thumbnail = $image;
286+
$possibleThumbnail = $templateConfig['paths']['thumbs'] . '/' . $filename;
287+
if (file_exists($possibleThumbnail)) {
288+
$thumbnail = $urlPrefix . $possibleThumbnail;
289+
}
290+
?>
279291
<a class="gallery-list-item" id="gallery-list-item-<?= $key ?>" href="#lightbox-uid-<?= $key ?>">
280292
<figure>
281-
<img src="<?= $urlPrefix . $filename ?>" alt="<?= basename($filename) ?>"/>
293+
<img src="<?= $thumbnail ?>" alt="<?= basename($filename) ?>" loading="lazy" />
282294
</figure>
283295
</a>
284296
<div class="lightbox" id="lightbox-uid-<?= $key ?>">
285297
<div class="lightbox-content">
286298
<div class="lightbox-action-bar-outer">
287299
<div class="lightbox-action-bar">
288-
<a href="<?= $fullImage ?>" download="<?= $templateConfig['files']['download_prefix'] ?>_<?= basename($filename) ?>">
300+
<a href="<?= $image ?>" download="<?= $templateConfig['files']['download_prefix'] ?>_<?= basename($image) ?>">
289301
<i class="fa-solid fa-download"></i>
290302
</a>
291-
<a href="whatsapp://send?text=<?= urlencode(sprintf($templateConfig['labels']['share'], $fullImage))?>">
303+
<a href="whatsapp://send?text=<?= urlencode(sprintf($templateConfig['labels']['share'], $image))?>">
292304
<i class="fa-brands fa-whatsapp"></i>
293305
</a>
294306
<a href="#gallery-list-item-<?= $key ?>" title="<?= $templateConfig['labels']['close'] ?>">
295307
<i class="fa-solid fa-xmark"></i>
296308
</a>
297309
</div>
298310
</div>
299-
<img src="<?= $fullImage ?>" loading="lazy" alt="<?= $filename ?>" />
311+
<img src="<?= $image ?>" alt="<?= $image ?>" loading="lazy" />
300312
</div>
301313
</div>
302314
<?php } ?>

0 commit comments

Comments
 (0)