changeset 35:985596db0f01

Implement recursive depth album covers.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 02 May 2016 12:20:01 +0300
parents e786771dfaa5
children 4f6eda86b9a2
files mgallery.php mgtool.php
diffstat 2 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mgallery.php	Sat Apr 23 20:14:23 2016 +0300
+++ b/mgallery.php	Mon May 02 12:20:01 2016 +0300
@@ -179,7 +179,25 @@
     }
     else
     {
-      $atmp = ($galUseCoverImages && isset($data["image"])) ? $galImageURL.mgCleanPath(TRUE, $galPath, $filename, $galTNPath, $data["image"]) : $galAlbumIcon;
+      if ($galUseCoverImages && isset($data["image"]))
+      {
+        // Recursively determine the album cover image
+        $ptmp = [$galPath, $filename];
+        $curr = &$data;
+        while (is_array($curr["image"]))
+        {
+          $curr = &$curr["image"];
+          $ptmp[] = $curr["base"];
+        }
+
+        $ptmp[] = $galTNPath;
+        $ptmp[] = $curr["image"];
+        $atmp = $galImageURL.implode("/", mgCleanPathArray(TRUE, 0, count($ptmp), $ptmp));
+      }
+      else
+      // No album cover, use default
+        $atmp = $galAlbumIcon;
+
       echo
       "    <a href=\"".mgGetURL(mgCleanPath(TRUE, $galPath, $filename), FALSE)."\">".
       "<img class=\"albumIcon\" src=\"".$atmp."\" alt=\"".chentities($data["caption"])."\" />\n".
--- a/mgtool.php	Sat Apr 23 20:14:23 2016 +0300
+++ b/mgtool.php	Mon May 02 12:20:01 2016 +0300
@@ -362,6 +362,13 @@
     end($images);
     $parentEntry["image"] = key($images);
   }
+  else
+  foreach ($albums as $aid => &$adata)
+  if (isset($adata["image"]))
+  {
+    $parentEntry["image"] = &$adata;
+    break;
+  }
 
   $str =
     "<?\n".