changeset 303:6bb434968623

Add new MG_STR_LC setting type, which is string but automatically lowercased.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 03 Apr 2020 16:22:51 +0300
parents f8d812d3194f
children da150fe627b6
files mgallery.inc.php mgtool.php
diffstat 2 files changed, 23 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mgallery.inc.php	Thu Mar 26 11:39:30 2020 +0200
+++ b/mgallery.inc.php	Fri Apr 03 16:22:51 2020 +0300
@@ -27,11 +27,12 @@
 // Constants for different value types
 //
 define("MG_STR"              , 1);
-define("MG_INT"              , 2);
-define("MG_DVA"              , 3);
-define("MG_BOOL"             , 4);
-define("MG_FLAGS"            , 5);
-define("MG_DATE"             , 6);
+define("MG_STR_LC"           , 2);
+define("MG_INT"              , 3);
+define("MG_DVA"              , 4);
+define("MG_BOOL"             , 5);
+define("MG_FLAGS"            , 6);
+define("MG_DATE"             , 7);
 
 
 define("yes"                 , 1);
@@ -89,17 +90,17 @@
   "tn_path"          => [MG_STR, "tn/"],
   "med_path"         => [MG_STR, "med/"],
 
-  "tn_format"        => [MG_STR, "jpeg"],
+  "tn_format"        => [MG_STR_LC, "jpeg"],
   "tn_width"         => [MG_INT, 140],  // In pixels, applies as bounding box for w/h
   "tn_height"        => [MG_INT, 100],
   "tn_quality"       => [MG_INT, 90],   // JPEG/WEBP quality percent
 
-  "med_format"       => [MG_STR, "jpeg"],
+  "med_format"       => [MG_STR_LC, "jpeg"],
   "med_width"        => [MG_INT, 960],
   "med_height"       => [MG_INT, 640],
   "med_quality"      => [MG_INT, 90],
 
-  "backend"          => [MG_STR, "php"],
+  "backend"          => [MG_STR_LC, "php"],
   "sql_db"           => [MG_STR, NULL],
   "sql_username"     => [MG_STR, ""],
   "sql_password"     => [MG_STR, ""],
@@ -179,6 +180,10 @@
 
   switch ($mgDefaults[$key][0])
   {
+    case MG_STR_LC:
+      $val = strtolower($val);
+      break;
+
     case MG_FLAGS:
       if (is_string($val))
       {
@@ -351,6 +356,12 @@
       else
         return "\"".$val."\"";
 
+    case MG_STR_LC:
+      if (is_array($val))
+        return implode(", ", array_map('strtolower', $val));
+      else
+        return "\"".strtolower($val)."\"";
+
     case MG_BOOL:
       return $val ? "yes" : "no";
 
--- a/mgtool.php	Thu Mar 26 11:39:30 2020 +0200
+++ b/mgtool.php	Fri Apr 03 16:22:51 2020 +0300
@@ -142,8 +142,7 @@
     }
 
     $img->setImageDepth(8);
-    $tfmt = strtolower($outFormat);
-    switch ($tfmt)
+    switch ($outFormat)
     {
       case "jpeg":
         $img->setFormat("JPEG");
@@ -156,7 +155,7 @@
         break;
 
        default:
-        return mgError("Unsupported MGallery med/tn format '".$tfmt."'.\n");
+        return mgError("Unsupported MGallery med/tn format '".$outFormat."'.\n");
     }
 
     $img->setImageCompressionQuality($outQuality);
@@ -218,8 +217,7 @@
     }
 
     $img->setImageDepth(8);
-    $tfmt = strtolower($outFormat);
-    switch ($tfmt)
+    switch ($outFormat)
     {
       case "jpeg":
         $img->setFormat("JPEG");
@@ -232,7 +230,7 @@
         break;
 
        default:
-        return mgError("Unsupported MGallery med/tn format '".$tfmt."'.\n");
+        return mgError("Unsupported MGallery med/tn format '".$outFormat."'.\n");
     }
 
     $img->setCompressionQuality($outQuality);