# HG changeset patch # User Matti Hamalainen # Date 1644601905 -7200 # Node ID c1de5571b59cef1d2ae766927e138cc63f2f19e8 # Parent 872be876e0f2e6609d927227b9824ca54e8cda37 Improve album cover picture handling, perhaps. diff -r 872be876e0f2 -r c1de5571b59c mgtool.php --- 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; + } } } }