comparison mgtool.php @ 330:c1de5571b59c

Improve album cover picture handling, perhaps.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 Feb 2022 19:51:45 +0200
parents 782c1520984e
children 0ea16a3777b8
comparison
equal deleted inserted replaced
329:872be876e0f2 330:c1de5571b59c
647 { 647 {
648 $str = trim(fgets($fp)); 648 $str = trim(fgets($fp));
649 // Ignore comments and empty lines 649 // Ignore comments and empty lines
650 if ($str != "#" && $str != "") 650 if ($str != "#" && $str != "")
651 { 651 {
652 if (preg_match("/^([#%]?)\s*(\S+?)\s+(.+)$/", $str, $m)) 652 if (($hasData = preg_match("/^([#%]?)\s*(\S+?)\s+(.+)$/", $str, $m)))
653 $captions[$m[2]] = ["caption" => $m[3], "hide" => ($m[1] == "#"), "hide_contents" => ($m[1] == "%"), "used" => FALSE]; 653 $captions[$m[2]] = ["caption" => $m[3]];
654 else 654 else
655 if (preg_match("/^([#%]?)\s*(\S+?)$/", $str, $m)) 655 $hasData = preg_match("/^([#%]?)\s*(\S+?)$/", $str, $m);
656 $captions[$m[2]] = ["hide" => ($m[1] == "#"), "hide_contents" => ($m[1] == "%"), "used" => FALSE]; 656 if ($hasData)
657 {
658 $captions[$m[2]] = [
659 "hide" => ($m[1] == "#"),
660 "hide_contents" => ($m[1] == "%"),
661 ];
662 }
657 } 663 }
658 } 664 }
659 665
660 fclose($fp); 666 fclose($fp);
661 return $captions; 667 return $captions;
851 { 857 {
852 // Is the cover image set in the album data? 858 // Is the cover image set in the album data?
853 if (isset($gallery["albumpic"])) 859 if (isset($gallery["albumpic"]))
854 { 860 {
855 if (!isset($images[$gallery["albumpic"]])) 861 if (!isset($images[$gallery["albumpic"]]))
856 mgError("Album cover picture '".$gallery["albumpic"]."' set, but is not found in \n"); 862 return mgError("Album cover picture '".$gallery["albumpic"]."' set, but is not found in directory.\n");
857 else 863 else
858 $parentEntry["image"] = $gallery["albumpic"]; 864 $parentEntry["image"] = $gallery["albumpic"];
859 } 865 }
860 866
861 // Got anything? 867 // Got anything?
866 $parentEntry["image"] = key($images); 872 $parentEntry["image"] = key($images);
867 } 873 }
868 } 874 }
869 else 875 else
870 { 876 {
871 foreach ($albums as $aid => &$adata) 877 // Is the cover image set in the album data?
872 if (isset($adata["image"])) 878 if (isset($gallery["albumpic"]))
873 { 879 {
874 $parentEntry["image"] = &$adata; 880 if (!isset($albums[$gallery["albumpic"]]))
875 break; 881 {
882 return mgError("Album cover picture '".$gallery["albumpic"]."' set, but subalbum not found.\n");
883 }
884
885 $parentEntry["image"] = &$albums[$gallery["albumpic"]];
886 }
887 else
888 {
889 foreach ($albums as $aid => &$adata)
890 if (isset($adata["image"]))
891 {
892 $parentEntry["image"] = &$adata;
893 break;
894 }
876 } 895 }
877 } 896 }
878 } 897 }
879 898
880 if ($galBackend == "sql" && $flagSQL) 899 if ($galBackend == "sql" && $flagSQL)