diff options
| author | 2023-01-19 18:26:04 +0100 | |
|---|---|---|
| committer | 2023-01-19 18:26:04 +0100 | |
| commit | dbdb7869c47ab8c9e3a42384401a7e29599e192f (patch) | |
| tree | 2edb8f6ca9210bc0219d80084f846385da048d3a /app | |
| parent | d105761fec48b388aa96e5089111b5c5ae941df2 (diff) | |
Safer timezone set (#5021)
* Safer timezone set
Add missing tzdata in Docker :newest
Fallback to UTC if no timezone is defined at all
#fix https://github.com/FreshRSS/FreshRSS/pull/4906#issuecomment-1386747169
* Better refactoring
Show fallback timezone everywhere
Diffstat (limited to 'app')
| -rw-r--r-- | app/FreshRSS.php | 5 | ||||
| -rw-r--r-- | app/Models/Context.php | 4 | ||||
| -rw-r--r-- | app/views/auth/register.phtml | 2 | ||||
| -rw-r--r-- | app/views/configure/display.phtml | 2 | ||||
| -rw-r--r-- | app/views/user/manage.phtml | 2 |
5 files changed, 11 insertions, 4 deletions
diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 02460af69..e374fa827 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -101,7 +101,10 @@ class FreshRSS extends Minz_FrontController { Minz_Translate::init($language); $timezone = isset(FreshRSS_Context::$user_conf) ? FreshRSS_Context::$user_conf->timezone : ''; - date_default_timezone_set($timezone != '' ? $timezone : '' . ini_get('date.timezone')); + if ($timezone == '') { + $timezone = FreshRSS_Context::defaultTimeZone(); + } + date_default_timezone_set($timezone); } private static function getThemeFileUrl($theme_id, $filename) { diff --git a/app/Models/Context.php b/app/Models/Context.php index 0176e77fa..734458d7f 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -500,4 +500,8 @@ class FreshRSS_Context { return false; } + public static function defaultTimeZone(): string { + $timezone = ini_get('date.timezone'); + return $timezone != '' ? $timezone : 'UTC'; + } } diff --git a/app/views/auth/register.phtml b/app/views/auth/register.phtml index 66c4a1ccb..999b2406a 100644 --- a/app/views/auth/register.phtml +++ b/app/views/auth/register.phtml @@ -21,7 +21,7 @@ <?php $timezones = array_merge([''], DateTimeZone::listIdentifiers()); ?> <?php foreach ($timezones as $timezone): ?> <option value="<?= $timezone ?>"<?= $timezone === '' ? ' selected="selected"' : '' ?>> - <?= $timezone == '' ? _t('gen.short.by_default') . ' (' . ini_get('date.timezone') . ')' : $timezone ?> + <?= $timezone == '' ? _t('gen.short.by_default') . ' (' . FreshRSS_Context::defaultTimeZone() . ')' : $timezone ?> </option> <?php endforeach; ?> </select> diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index 986d7dd17..44ca242ad 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -37,7 +37,7 @@ ?> <?php foreach ($timezones as $timezone): ?> <option value="<?= $timezone ?>"<?= FreshRSS_Context::$user_conf->timezone === $timezone ? ' selected="selected"' : '' ?>> - <?= $timezone == '' ? _t('gen.short.by_default') . ' (' . ini_get('date.timezone') . ')' : $timezone ?> + <?= $timezone == '' ? _t('gen.short.by_default') . ' (' . FreshRSS_Context::defaultTimeZone() . ')' : $timezone ?> </option> <?php endforeach; ?> </select> diff --git a/app/views/user/manage.phtml b/app/views/user/manage.phtml index 22a1a4d03..b996cdf2b 100644 --- a/app/views/user/manage.phtml +++ b/app/views/user/manage.phtml @@ -35,7 +35,7 @@ <?php $timezones = array_merge([''], DateTimeZone::listIdentifiers()); ?> <?php foreach ($timezones as $timezone): ?> <option value="<?= $timezone ?>"<?= $timezone === '' ? ' selected="selected"' : '' ?>> - <?= $timezone == '' ? _t('gen.short.by_default') . ' (' . ini_get('date.timezone') . ')' : $timezone ?> + <?= $timezone == '' ? _t('gen.short.by_default') . ' (' . FreshRSS_Context::defaultTimeZone() . ')' : $timezone ?> </option> <?php endforeach; ?> </select> |
