changeset 330:c1de5571b59c

Improve album cover picture handling, perhaps.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 Feb 2022 19:51:45 +0200
parents 872be876e0f2
children 14d3741061f5
files mgtool.php
diffstat 1 files changed, 28 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mgtool.php	Fri Feb 11 19:50:24 2022 +0200
+++ b/mgtool.php	Fri Feb 11 19:51:45 2022 +0200
@@ -649,11 +649,17 @@
     // Ignore comments and empty lines
     if ($str != "#" && $str != "")
     {
-      if (preg_match("/^([#%]?)\s*(\S+?)\s+(.+)$/", $str, $m))
-        $captions[$m[2]] = ["caption" => $m[3], "hide" => ($m[1] == "#"), "hide_contents" => ($m[1] == "%"), "used" => FALSE];
+      if (($hasData = preg_match("/^([#%]?)\s*(\S+?)\s+(.+)$/", $str, $m)))
+        $captions[$m[2]] = ["caption" => $m[3]];
       else
-      if (preg_match("/^([#%]?)\s*(\S+?)$/", $str, $m))
-        $captions[$m[2]] = ["hide" => ($m[1] == "#"), "hide_contents" => ($m[1] == "%"), "used" => FALSE];
+        $hasData = preg_match("/^([#%]?)\s*(\S+?)$/", $str, $m);
+      if ($hasData)
+      {
+        $captions[$m[2]] = [
+          "hide" => ($m[1] == "#"),
+          "hide_contents" => ($m[1] == "%"),
+        ];
+      }
     }
   }
 
@@ -853,7 +859,7 @@
       if (isset($gallery["albumpic"]))
       {
         if (!isset($images[$gallery["albumpic"]]))
-          mgError("Album cover picture '".$gallery["albumpic"]."' set, but is not found in \n");
+          return mgError("Album cover picture '".$gallery["albumpic"]."' set, but is not found in directory.\n");
         else
           $parentEntry["image"] = $gallery["albumpic"];
       }
@@ -868,11 +874,24 @@
     }
     else
     {
-      foreach ($albums as $aid => &$adata)
-      if (isset($adata["image"]))
+      // Is the cover image set in the album data?
+      if (isset($gallery["albumpic"]))
       {
-        $parentEntry["image"] = &$adata;
-        break;
+        if (!isset($albums[$gallery["albumpic"]]))
+        {
+          return mgError("Album cover picture '".$gallery["albumpic"]."' set, but subalbum not found.\n");
+        }
+
+        $parentEntry["image"] = &$albums[$gallery["albumpic"]];
+      }
+      else
+      {
+        foreach ($albums as $aid => &$adata)
+        if (isset($adata["image"]))
+        {
+          $parentEntry["image"] = &$adata;
+          break;
+        }
       }
     }
   }