Explorar el Código

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
Alexandre Alapetite hace 3 años
padre
commit
dbdb7869c4

+ 1 - 0
Docker/Dockerfile-Newest

@@ -4,6 +4,7 @@ ENV TZ UTC
 SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
 RUN echo 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories && \
 	apk add --no-cache \
+	tzdata \
 	apache2 php82-apache2 \
 	php82 php82-curl php82-gmp php82-intl php82-mbstring php82-xml php82-zip \
 	php82-ctype php82-dom php82-fileinfo php82-iconv php82-json php82-opcache php82-openssl php82-phar php82-session php82-simplexml php82-xmlreader php82-xmlwriter php82-xml php82-tokenizer php82-zlib \

+ 4 - 1
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) {

+ 4 - 0
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';
+	}
 }

+ 1 - 1
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>

+ 1 - 1
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>

+ 1 - 1
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>