changeset 347:7da360685721

Implement show_keywords setting.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 06 Sep 2023 13:04:41 +0300
parents 4425fe467c81
children 596196f2b0c5
files mgallery.inc.php mgallery.php
diffstat 2 files changed, 44 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mgallery.inc.php	Sun Aug 27 05:35:23 2023 +0300
+++ b/mgallery.inc.php	Wed Sep 06 13:04:41 2023 +0300
@@ -85,6 +85,7 @@
 
   "cover_images"     => [MG_BOOL, TRUE],
   "album_icon"       => [MG_STR, NULL],
+  "show_keywords"    => [MG_CALLABLE, FALSE, "mgParseShowKeywords"],
 
   "title_prefix"     => [MG_STR, ""],
   "title_sep"        => [MG_STR, " - "],
--- a/mgallery.php	Sun Aug 27 05:35:23 2023 +0300
+++ b/mgallery.php	Wed Sep 06 13:04:41 2023 +0300
@@ -51,6 +51,16 @@
     "fi" => "Takaisin galleriasivulle.",
     "en" => "Back to gallery page.",
   ],
+
+  "image_keywords_prefix" => [
+    "fi" => "Avainsanat: ",
+    "en" => "Keywords: ",
+  ],
+
+  "image_keywords_suffix" => [
+    "fi" => "",
+    "en" => "",
+  ],
 ];
 
 
@@ -286,7 +296,26 @@
 }
 
 
-function mgPrintTable($class, $galPath, &$galEntries, &$galIndex, $start, $limit)
+function mgGetImageKeywords(&$galData, &$data, $fmt1, $fmt2)
+{
+  global $galShowKeywords;
+  $showKeywords = isset($galData["show_keywords"]) ? $galData["show_keywords"] : $galShowKeywords;
+
+  if (is_array($showKeywords) && isset($data["keywords"]) && is_array($data["keywords"]))
+  {
+    if (array_intersect($showKeywords, ["*", "all"]))
+      $tmp = $data["keywords"];
+    else
+      $tmp = array_intersect($showKeywords, $data["keywords"]);
+
+    if (count($tmp) > 0)
+      return $fmt1.implode(", ", array_map("chentities", $tmp)).$fmt2;
+  }
+  return "";
+}
+
+
+function mgPrintTable($class, $galData, $galPath, &$galEntries, &$galIndex, $start, $limit)
 {
   global $galAlbumIcon, $galTNPath, $galTNFormat,
          $galImageURL, $galUseCoverImages;
@@ -314,7 +343,8 @@
         "\"><a href=\"".mgGetURL($galPath, $filename)."\"><img src=\"".
         mgGetImageURL(isset($data["path"]) ? $data["path"] : $galPath, $galTNPath, $filename, $galTNFormat).
         "\" alt=\"".dhentities($filename)."\"></a></div>\n".
-        mgGetArr($data, "caption", "    <div class=\"imageCaption\">%1</div>\n", "", "chentities");
+        mgGetArr($data, "caption", "    <div class=\"imageCaption\">%1</div>\n", "", "chentities").
+        mgGetImageKeywords($galData, $data, "     <div class=\"imageKeywords\">(", ")</div>\n");
 /*
       if ($mode == "")
       {
@@ -490,6 +520,7 @@
 $galImageURL = mgGetSetting("image_url", mgGetSetting("base_url"));
 
 $galUseCoverImages = mgGetSetting("cover_images");
+$galShowKeywords = mgGetSetting("show_keywords");
 
 $galAlbumIcon = mgGetSetting("album_icon");
 $galCleanURLS = mgGetSetting("clean_urls");
@@ -503,6 +534,7 @@
 $galPageIndex = intval(mgGetRequestItem("index", 0, TRUE));
 $galImage = mgGetRequestItem("image", FALSE, TRUE);
 
+
 if (is_string($galImage))
   $galImage = basename($galImage);
 
@@ -617,8 +649,13 @@
       mgGetNaviControlImageBoxJS($galPath, $galImagesIndex, $galEntries, $index, "nextBtm", 1)."\n".
       mgGetNaviControlImageBox($galPath, $galImagesIndex, $galEntries, $index, "next", 1)."\n".
     "</div>\n". // pageImageBox
-    (isset($data["caption"]) ? "<div id=\"pageImageCaption\" class=\"imageCaption\">".mgGetArrStr($data, "caption", "%1")."</div>\n" : "").
-    // infoBox
+    (isset($data["caption"]) ?
+      "<div id=\"pageImageCaption\" class=\"imageCaption\">".mgGetArrStr($data, "caption", "%1").
+        mgGetImageKeywords($galData, $data, " (".mgQM("image_keywords_prefix"), mgQM("image_keywords_suffix").")")."</div>\n" :
+      mgGetImageKeywords($galData, $data, "<div id=\"pageImageCaption\" class=\"imageCaption\">".mgQM("image_keywords_prefix"), mgQM("image_keywords_suffix")."</div>\n")
+      );
+  // infoBox
+  echo
     "<div id=\"infoBox\">\n".
       mgGetArr($data, "datetime", "<span class=\"infoDateTime\">%1</span>\n", "", "mgTimeStr").
       implode(",\n", array_filter($list, function($a) { return $a !== NULL; }))."\n".
@@ -709,8 +746,8 @@
 
   echo mgGetPageInfoHeaderEnd();
 
-  mgPrintTable("albumTable", $galPath, $galEntries, $galAlbumsIndex, 0, FALSE);
-  mgPrintTable("imageTable", $galPath, $galEntries, $galImagesIndex, 0, FALSE);
+  mgPrintTable("albumTable", $galData, $galPath, $galEntries, $galAlbumsIndex, 0, FALSE);
+  mgPrintTable("imageTable", $galData, $galPath, $galEntries, $galImagesIndex, 0, FALSE);
 }
 
 mgPrintPageFooter();