From 3bc7f019c5c20a0bb4d9addee25dcbc1d727ed06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Tue, 25 Feb 2014 19:03:46 -0500 Subject: [PATCH] Add timezone configuration option --- controllers/common.php | 3 +++ controllers/config.php | 2 ++ locales/fr_FR/translations.php | 1 + models/config.php | 12 ++++++++++-- models/schema.php | 5 +++++ templates/config.php | 3 +++ 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/controllers/common.php b/controllers/common.php index f5fd2bc..98f303f 100644 --- a/controllers/common.php +++ b/controllers/common.php @@ -21,6 +21,9 @@ Router\before(function($action) { $language = Model\Config\get('language') ?: 'en_US'; if ($language !== 'en_US') PicoTools\Translator\load($language); + // Set timezone + date_default_timezone_set(Model\Config\get('timezone') ?: 'UTC'); + // HTTP secure headers $frame_src = \PicoFeed\Filter::$iframe_whitelist; $frame_src[] = 'https://login.persona.org'; diff --git a/controllers/config.php b/controllers/config.php index 7599eda..3460d2b 100644 --- a/controllers/config.php +++ b/controllers/config.php @@ -36,6 +36,7 @@ Router\get_action('config', function() { 'values' => Model\Config\get_all(), 'db_size' => filesize(DB_FILENAME), 'languages' => Model\Config\get_languages(), + 'timezones' => Model\Config\get_timezones(), 'autoflush_options' => Model\Config\get_autoflush_options(), 'paging_options' => Model\Config\get_paging_options(), 'theme_options' => Model\Config\get_themes(), @@ -69,6 +70,7 @@ Router\post_action('config', function() { 'values' => Model\Config\get_all(), 'db_size' => filesize(DB_FILENAME), 'languages' => Model\Config\get_languages(), + 'timezones' => Model\Config\get_timezones(), 'autoflush_options' => Model\Config\get_autoflush_options(), 'paging_options' => Model\Config\get_paging_options(), 'theme_options' => Model\Config\get_themes(), diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index 00fb0f1..fcf3fd4 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -206,4 +206,5 @@ return array( '%d weeks ago' => 'Il y a %d semaines', '%d month ago' => 'Il y a %d mois', '%d months ago' => 'Il y a %d mois', + 'Timezone' => 'Fuseau horaire', ); diff --git a/models/config.php b/models/config.php index 4e50e73..e8ede3e 100644 --- a/models/config.php +++ b/models/config.php @@ -16,7 +16,7 @@ use SimpleValidator\Validator; use SimpleValidator\Validators; use PicoDb\Database; -const DB_VERSION = 21; +const DB_VERSION = 22; const HTTP_USERAGENT = 'Miniflux - http://miniflux.net'; const HTTP_FAKE_USERAGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36'; @@ -35,6 +35,13 @@ function write_debug() } } +// Get available timezone +function get_timezones() +{ + $timezones = \timezone_identifiers_list(); + return array_combine(array_values($timezones), $timezones); +} + // Get all supported languages function get_languages() { @@ -172,7 +179,7 @@ function get($name) } else { - if (! isset($_SESSION['config'])) { + if (! isset($_SESSION['config'][$name])) { $_SESSION['config'] = get_all(); } @@ -192,6 +199,7 @@ function get_all() ->columns( 'username', 'language', + 'timezone', 'autoflush', 'nocontent', 'items_per_page', diff --git a/models/schema.php b/models/schema.php index 08a904b..a8a9934 100644 --- a/models/schema.php +++ b/models/schema.php @@ -2,6 +2,11 @@ namespace Schema; +function version_22($pdo) +{ + $pdo->exec("ALTER TABLE config ADD COLUMN timezone TEXT DEFAULT 'UTC'"); +} + function version_21($pdo) { diff --git a/templates/config.php b/templates/config.php index 5b0a9b7..c85b0a2 100644 --- a/templates/config.php +++ b/templates/config.php @@ -13,6 +13,9 @@
+ +
+