changeset 130:f825d644cf7a

Implement new config setting "timezone" for specifying the timezone used for date/timestamp interpretation.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 01 Sep 2017 00:44:52 +0300
parents bad658e1e7ed
children a6c173e3a175
files example.cfg mgallery.inc.php mgallery.php mgtool.php
diffstat 4 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/example.cfg	Fri Sep 01 00:44:03 2017 +0300
+++ b/example.cfg	Fri Sep 01 00:44:52 2017 +0300
@@ -2,6 +2,11 @@
 ;;; MGallery example configuration
 ;;;
 
+; Timezone used for timestamp/date calculations.
+; See http://php.net/manual/en/timezones.php
+timezone             = "Europe/Helsinki"
+
+
 ;;; Gallery title, etc.
 title_prefix         = "My Own Gallery"
 title_sep            = " - "
--- a/mgallery.inc.php	Fri Sep 01 00:44:03 2017 +0300
+++ b/mgallery.inc.php	Fri Sep 01 00:44:52 2017 +0300
@@ -54,6 +54,7 @@
 // Configuration settings and their default values
 //
 $mgDefaults = [
+  "timezone"         => [MG_STR, NULL],
 
   "base_path"        => [MG_STR, mgPathName(mgRealPath($_SERVER["SCRIPT_FILENAME"]))],
   "base_url"         => [MG_STR, mgPathName($_SERVER["PHP_SELF"])],
--- a/mgallery.php	Fri Sep 01 00:44:03 2017 +0300
+++ b/mgallery.php	Fri Sep 01 00:44:52 2017 +0300
@@ -502,6 +502,9 @@
 if (is_string($galImage))
   $galImage = basename($galImage);
 
+if (($pageTimeZone = mgGetSetting("timezone")) !== NULL)
+  date_default_timezone_set($pageTimeZone);
+
 
 // Check language setting
 if (($tmp = mgGetRequestItem("lang", FALSE, TRUE)) !== FALSE)
--- a/mgtool.php	Fri Sep 01 00:44:03 2017 +0300
+++ b/mgtool.php	Fri Sep 01 00:44:52 2017 +0300
@@ -668,10 +668,6 @@
 {
   global $galTNPath;
 
-  // Fetch the settings we need
-  if (mgReadSettings() === FALSE)
-    die("MGallery not configured.\n");
-
   // Check validity of some settings
   $galPath = mgGetSetting("base_path");
   $galTNPath = mgCleanPath(TRUE, mgGetSetting("tn_path"));
@@ -783,6 +779,11 @@
 pcntl_signal(SIGQUIT, "mgSigHandler");
 pcntl_signal(SIGINT,  "mgSigHandler");
 
+if (mgReadSettings() === FALSE)
+  die("MGallery is not configured, failed to find a configuration file.\n");
+
+if (($pageTimeZone = mgGetSetting("timezone")) !== NULL)
+  date_default_timezone_set($pageTimeZone);
 
 $cmd = mgCArgLC(1);
 switch ($cmd)
@@ -848,8 +849,6 @@
 
   case "config":
   case "dump":
-    if (mgReadSettings() === FALSE)
-      die("MGallery not configured.\n");
 
     foreach ($mgDefaults as $key => $dval)
     {