changeset 232:e618280253ca

Move mgGetTrans() to mgallery.php as it is used only there. Also change how the second function argument works, instead of being a boolean to filter through chentities() use it as a callable which defaults to NULL for greater flexibility.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 26 Mar 2018 19:37:42 +0300
parents 2731d2d8400e
children e7e9b39f2480
files mgallery.inc.php mgallery.php
diffstat 2 files changed, 24 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mgallery.inc.php	Mon Mar 26 17:06:12 2018 +0300
+++ b/mgallery.inc.php	Mon Mar 26 19:37:42 2018 +0300
@@ -290,19 +290,6 @@
 }
 
 
-function mgGetTrans($val, $useEntities = FALSE)
-{
-  global $pageLang;
-
-  if (is_array($val))
-    $str = array_key_exists($pageLang, $val) ? $val[$pageLang] : reset($val);
-  else
-    $str = $val;
-
-  return $useEntities ? chentities($str) : $str;
-}
-
-
 function mgGetArr($data, $skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL)
 {
   global $pageLang;
--- a/mgallery.php	Mon Mar 26 17:06:12 2018 +0300
+++ b/mgallery.php	Mon Mar 26 19:37:42 2018 +0300
@@ -109,6 +109,22 @@
 }
 
 
+function mgGetTrans($val, $filter = NULL)
+{
+  global $pageLang;
+
+  if (is_array($val))
+    $str = array_key_exists($pageLang, $val) ? $val[$pageLang] : reset($val);
+  else
+    $str = $val;
+
+  if (is_callable($filter))
+    return call_user_func($filter, $str);
+  else
+    return $str;
+}
+
+
 function mgMangleURI($filename)
 {
   global $pageDebug;
@@ -325,11 +341,13 @@
         $atmp = $galAlbumIcon;
 
       echo
-      "    <a href=\"".mgGetURL(mgCleanPath(TRUE, $galPath, $filename), FALSE)."\">".
-      "<img class=\"albumIcon\" src=\"".$atmp."\" alt=\"".
-      dhentities(mgGetTrans($data["caption"], TRUE)).
-      "\" />\n".
-      "    <div class=\"albumTitle\">".mgGetTrans($data["caption"], TRUE)."</div></a>\n";
+        "    <a href=\"".mgGetURL(mgCleanPath(TRUE, $galPath, $filename), FALSE)."\">".
+        "<img class=\"albumIcon\" src=\"".$atmp."\" alt=\"".
+        mgGetTrans($data["caption"], "dhentities").
+        "\" />\n".
+        "    <div class=\"albumTitle\">".
+        mgGetTrans($data["caption"], "chentities").
+        "</div></a>\n";
     }
 
     if ($galUseTables)
@@ -409,7 +427,7 @@
 {
   return
     "<a class=\"".$class."\" href=\"".mgGetURL($pdata["path"], FALSE)."\">".
-    mgGetTrans($pdata["caption"], TRUE).
+    mgGetTrans($pdata["caption"], "chentities").
     "</a>";
 }