foto: inline showthumb function to format img elements
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 15 Jan 2021 10:25:14 +0000 (11:25 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 23 Jan 2021 12:56:54 +0000 (13:56 +0100)
Slight code simplification.

foto/index.php

index 49e5483d24d4d23ecaa8b0b3dbc078d8a49cd759..e7f1bab54132b0766eba3ecb8a4e54849676b03c 100644 (file)
@@ -48,26 +48,6 @@ if (isset($Page->raw)) {
        print $Page->raw;  # page intro
 }
 
-if (!function_exists('showthumb')) {
-function showthumb($path)
-{
-       // assume all album entries are symlinks to archive originals
-       $target = preg_replace('{^(\.\./)*}', '', readlink($path));
-       $thumb = 'thumb/262/' . $target;
-
-       @list ($order, $size, $title) = explode(':', pathinfo($path, PATHINFO_FILENAME), 3);
-       $imgtag = 'img src="/'.$thumb.'"';
-       if ($title) {
-               $imgtag .= ' title="'.htmlspecialchars(urldecode($title)).'"';
-       }
-       if ($size) {
-               $imgtag .= ' data-size="'.$size.'"';
-       }
-
-       return sprintf('<a href="/%s"><%s /></a>'."\n", $target, $imgtag);
-}
-}
-
 if ($imgs = glob("$rootdir/*", GLOB_ONLYDIR)) {
        natsort($imgs);
        print '<ul class="gallery cat">'."\n";
@@ -94,14 +74,29 @@ if ($imgs = glob("$rootdir/*", GLOB_ONLYDIR)) {
 
 if ($imgs = glob("$rootdir/*.jpg")) {
        print '<ul class="gallery album">'."\n";
-       foreach ($imgs as $img) {
-               if ($img == "$rootdir/index.jpg") {
+       foreach ($imgs as $path) {
+               if ($path == "$rootdir/index.jpg") {
                        # cover image of current album
-                       $Page->image = "/$img";
+                       $Page->image = "/$path";
                        continue;
                }
-               if (!is_link($img)) continue;
-               print '<li>'.showthumb($img);
+               if (!is_link($path)) continue;
+
+               // assume all album entries are symlinks to archive originals
+               $target = preg_replace('{^(\.\./)*}', '', readlink($path));
+               $thumb = 'thumb/262/' . $target;
+
+               @list ($order, $size, $title) = explode(':', pathinfo($path, PATHINFO_FILENAME), 3);
+               $imgtag = 'img src="/'.$thumb.'"';
+               if ($title) {
+                       $imgtag .= ' title="'.htmlspecialchars(urldecode($title)).'"';
+               }
+               if ($size) {
+                       $imgtag .= ' data-size="'.$size.'"';
+               }
+
+               print '<li>';
+               printf('<a href="/%s"><%s /></a>'."\n", $target, $imgtag);
        }
        print '</ul>'."\n\n";