From e971e7a725fa9481aedc2158d4f9f2474f7a9624 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 3 Feb 2016 17:54:47 +0900 Subject: [PATCH] Improve time zone selection --- classes/context/Context.class.php | 4 +-- modules/install/install.controller.php | 23 +++++++++++------ modules/install/install.view.php | 35 ++++++++++++++++++++++++-- modules/install/tpl/other_config.html | 2 +- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index b11f9f593..7e68a6e18 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -289,11 +289,11 @@ class Context $this->lang_type = $this->db_info->lang_type; } - if(!$this->lang_type || !in_array($this->lang_type, $enabled_langs)) + if(!$this->lang_type || !isset($enabled_langs[$this->lang_type])) { $this->lang_type = 'ko'; } - + self::setLangType($this->lang_type); $this->lang = Rhymix\Framework\Lang::getInstance($this->lang_type); diff --git a/modules/install/install.controller.php b/modules/install/install.controller.php index 7ddfa5e92..6cecd1d9c 100644 --- a/modules/install/install.controller.php +++ b/modules/install/install.controller.php @@ -157,15 +157,22 @@ class installController extends install $config['locale']['enabled_lang'] = array($config['locale']['default_lang']); // Set the internal and default time zones. - $user_timezone = intval(get_time_zone_offset($time_zone ?: '+0900') / 3600); - switch ($user_timezone) + if (strpos($time_zone, '/') !== false) { - case 9: - $config['locale']['default_timezone'] = 'Asia/Seoul'; break; - case 0: - $config['locale']['default_timezone'] = 'Etc/UTC'; break; - default: - $config['locale']['default_timezone'] = 'Etc/GMT' . ($user_timezone > 0 ? '-' : '+') . abs($user_timezone); + $config['locale']['default_timezone'] = $time_zone; + } + else + { + $user_timezone = intval(get_time_zone_offset($time_zone ?: '+0900') / 3600); + switch ($user_timezone) + { + case 9: + $config['locale']['default_timezone'] = 'Asia/Seoul'; break; + case 0: + $config['locale']['default_timezone'] = 'Etc/UTC'; break; + default: + $config['locale']['default_timezone'] = 'Etc/GMT' . ($user_timezone > 0 ? '-' : '+') . abs($user_timezone); + } } $config['locale']['internal_timezone'] = intval(date('Z')); diff --git a/modules/install/install.view.php b/modules/install/install.view.php index aff654546..67c1ef2ff 100644 --- a/modules/install/install.view.php +++ b/modules/install/install.view.php @@ -145,11 +145,42 @@ class installView extends install return $this->dispInstallCheckEnv(); } - Context::set('use_rewrite', $_SESSION['use_rewrite']); + // Get list of time zones. + $timezones = DateTimeZone::listIdentifiers(); + natcasesort($timezones); + $timezones = array_combine($timezones, $timezones); + Context::set('timezones', $timezones); + + // Automatically select a time zone for the user. + Context::set('selected_timezone', $this->detectUserTimeZone()); + + // Always use SSL if installing via SSL. Context::set('use_ssl', RX_SSL ? 'always' : 'none'); - Context::set('time_zone', $GLOBALS['time_zone']); $this->setTemplateFile('other_config'); } + + /** + * Detect best time zone for the user. + */ + function detectUserTimeZone() + { + switch (Context::getLangType()) + { + case 'ko': return 'Asia/Seoul'; + case 'en': return 'Europe/London'; + case 'ja': return 'Asia/Tokyo'; + case 'zh-CN': return 'Asia/Shanghai'; + case 'zh-TW': return 'Asia/Taipei'; + case 'de': return 'Europe/Berlin'; + case 'es': return 'Europe/Madrid'; + case 'fr': return 'Europe/Paris'; + case 'mn': return 'Asia/Ulaanbaatar'; + case 'ru': return 'Europe/Moscow'; + case 'tr': return 'Europe/Istanbul'; + case 'vi': return 'Asia/Ho_Chi_Minh'; + default: return 'UTC'; + } + } } /* End of file install.view.php */ /* Location: ./modules/install/install.view.php */ diff --git a/modules/install/tpl/other_config.html b/modules/install/tpl/other_config.html index 012d1e52d..fbe4c6138 100644 --- a/modules/install/tpl/other_config.html +++ b/modules/install/tpl/other_config.html @@ -42,7 +42,7 @@