فهرست منبع

User-defined time zone (#4906)

* User-defined time zone
#fix https://github.com/FreshRSS/FreshRSS/issues/2754

* Update app/i18n/nl/conf.php

Co-authored-by: Frans de Jonge <fransdejonge@gmail.com>

* Timezone when creating a new user

Co-authored-by: Frans de Jonge <fransdejonge@gmail.com>
Alexandre Alapetite 3 سال پیش
والد
کامیت
6261dc9cf4

+ 1 - 0
app/Controllers/configureController.php

@@ -42,6 +42,7 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController {
 	public function displayAction() {
 		if (Minz_Request::isPost()) {
 			FreshRSS_Context::$user_conf->language = Minz_Request::param('language', 'en');
+			FreshRSS_Context::$user_conf->timezone = Minz_Request::param('timezone', '');
 			FreshRSS_Context::$user_conf->theme = Minz_Request::param('theme', FreshRSS_Themes::$defaultTheme);
 			FreshRSS_Context::$user_conf->content_width = Minz_Request::param('content_width', 'thin');
 			FreshRSS_Context::$user_conf->topline_read = Minz_Request::param('topline_read', false);

+ 1 - 0
app/Controllers/userController.php

@@ -344,6 +344,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
 
 			$ok = self::createUser($new_user_name, $email, $passwordPlain, array(
 				'language' => Minz_Request::param('new_user_language', FreshRSS_Context::$user_conf->language),
+				'timezone' => Minz_Request::param('new_user_timezone', ''),
 				'is_admin' => Minz_Request::paramBoolean('new_user_is_admin'),
 				'enabled' => true,
 			));

+ 3 - 0
app/FreshRSS.php

@@ -99,6 +99,9 @@ class FreshRSS extends Minz_FrontController {
 
 		Minz_Session::_param('language', $language);
 		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'));
 	}
 
 	private static function getThemeFileUrl($theme_id, $filename) {

+ 1 - 0
app/Models/UserConfiguration.php

@@ -28,6 +28,7 @@
  * @property-read string $is_admin
  * @property int|null $keep_history_default
  * @property string $language
+ * @property string $timezone
  * @property bool $lazyload
  * @property string $mail_login
  * @property bool $mark_updated_article_unread

+ 1 - 0
app/i18n/cz/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Na výšku',
 			'square' => 'Čtverec',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Zobrazení',
 		'width' => array(
 			'content' => 'Šířka obsahu',

+ 1 - 0
app/i18n/de/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Hochformat',
 			'square' => 'Quadrat',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Anzeige',
 		'width' => array(
 			'content' => 'Inhaltsbreite',

+ 1 - 0
app/i18n/el/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Portrait',	// TODO
 			'square' => 'Square',	// TODO
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Display',	// TODO
 		'width' => array(
 			'content' => 'Content width',	// TODO

+ 1 - 0
app/i18n/en-us/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Portrait',	// IGNORE
 			'square' => 'Square',	// IGNORE
 		),
+		'timezone' => 'Time zone',	// IGNORE
 		'title' => 'Display',	// IGNORE
 		'width' => array(
 			'content' => 'Content width',	// IGNORE

+ 1 - 0
app/i18n/en/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Portrait',
 			'square' => 'Square',
 		),
+		'timezone' => 'Time zone',
 		'title' => 'Display',
 		'width' => array(
 			'content' => 'Content width',

+ 1 - 0
app/i18n/es/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Retrato',
 			'square' => 'Cuadrado',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Visualización',
 		'width' => array(
 			'content' => 'Ancho de contenido',

+ 1 - 0
app/i18n/fr/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Portrait',	// IGNORE
 			'square' => 'Carrée',
 		),
+		'timezone' => 'Fuseau horaire',
 		'title' => 'Affichage',
 		'width' => array(
 			'content' => 'Largeur du contenu',

+ 1 - 0
app/i18n/he/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Portrait',	// TODO
 			'square' => 'Square',	// TODO
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'תצוגה',
 		'width' => array(
 			'content' => 'רוחב התוכן',

+ 1 - 0
app/i18n/id/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Portrait',	// TODO
 			'square' => 'Square',	// TODO
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Display',	// TODO
 		'width' => array(
 			'content' => 'Content width',	// TODO

+ 1 - 0
app/i18n/it/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Ritratto',
 			'square' => 'Squadrata',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Visualizzazione',
 		'width' => array(
 			'content' => 'Larghezza contenuto',

+ 1 - 0
app/i18n/ja/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'ポートレート',
 			'square' => '四角',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'ディスプレイ',
 		'width' => array(
 			'content' => 'コンテンツ幅',

+ 1 - 0
app/i18n/ko/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => '세로 방향',
 			'square' => '정사각형',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => '표시',
 		'width' => array(
 			'content' => '내용 표시 너비',

+ 1 - 0
app/i18n/nl/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Staand',
 			'square' => 'Vierkant',
 		),
+		'timezone' => 'Tijdzone',
 		'title' => 'Opmaak',
 		'width' => array(
 			'content' => 'Inhoud breedte',

+ 1 - 0
app/i18n/oc/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Retrach',
 			'square' => 'Carrat',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Afichatge',
 		'width' => array(
 			'content' => 'Largor del contengut',

+ 1 - 0
app/i18n/pl/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Portret',
 			'square' => 'Kwadrat',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Wyświetlanie',
 		'width' => array(
 			'content' => 'Rozmiar treści',

+ 1 - 0
app/i18n/pt-br/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Modo retrato',
 			'square' => 'Modo quadrado',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Exibição',
 		'width' => array(
 			'content' => 'Largura do conteúdo',

+ 1 - 0
app/i18n/ru/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Вертикальный',
 			'square' => 'Квадратный',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Отображение',
 		'width' => array(
 			'content' => 'Ширина содержимого',

+ 1 - 0
app/i18n/sk/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Nastojato',
 			'square' => 'Štvorec',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Zobraziť',
 		'width' => array(
 			'content' => 'Šírka obsahu',

+ 1 - 0
app/i18n/tr/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => 'Portre',
 			'square' => 'Kare',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => 'Görünüm',
 		'width' => array(
 			'content' => 'İçerik genişliği',

+ 1 - 0
app/i18n/zh-cn/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => '纵向',
 			'square' => '方形',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => '显示',
 		'width' => array(
 			'content' => '内容宽度',

+ 1 - 0
app/i18n/zh-tw/conf.php

@@ -57,6 +57,7 @@ return array(
 			'portrait' => '肖像',
 			'square' => '方塊',
 		),
+		'timezone' => 'Time zone',	// TODO
 		'title' => '顯示',
 		'width' => array(
 			'content' => '內容寬度',

+ 12 - 0
app/views/auth/register.phtml

@@ -15,6 +15,18 @@
 			</select>
 		</div>
 
+		<div class="form-group">
+			<label for="new_user_timezone"><?= _t('conf.display.timezone') ?></label>
+			<select name="new_user_timezone" id="new_user_timezone">
+			<?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 ?>
+			</option>
+			<?php endforeach; ?>
+			</select>
+		</div>
+
 		<div class="form-group">
 			<label for="new_user_name"><?= _t('gen.auth.username') ?></label>
 			<input id="new_user_name" name="new_user_name" type="text" size="16" required="required" autocomplete="off"

+ 19 - 0
app/views/configure/display.phtml

@@ -25,6 +25,25 @@
 			</div>
 		</div>
 
+		<div class="form-group">
+			<label class="group-name" for="language"><?= _t('conf.display.timezone') ?></label>
+			<div class="group-controls">
+				<select name="timezone" id="timezone" data-leave-validation="<?= FreshRSS_Context::$user_conf->timezone ?>">
+				<?php
+					$timezones = array_merge([''], DateTimeZone::listIdentifiers());
+					if (!in_array(FreshRSS_Context::$user_conf->timezone, $timezones, true)) {
+						FreshRSS_Context::$user_conf->timezone = '';
+					}
+				?>
+				<?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 ?>
+				</option>
+				<?php endforeach; ?>
+				</select>
+			</div>
+		</div>
+
 		<div class="form-group">
 			<label class="group-name" for="theme"><?= _t('conf.display.theme') ?></label>
 			<div class="group-controls">

+ 14 - 2
app/views/user/manage.phtml

@@ -15,8 +15,6 @@
 		<input type="hidden" name="originController" value="<?= Minz_Request::controllerName() ?>" />
 		<input type="hidden" name="originAction" value="<?= Minz_Request::actionName() ?>" />
 
-
-
 		<div class="form-group">
 			<label class="group-name" for="new_user_language"><?= _t('admin.user.language') ?></label>
 			<div class="group-controls">
@@ -30,6 +28,20 @@
 			</div>
 		</div>
 
+		<div class="form-group">
+			<label class="group-name" for="new_user_timezone"><?= _t('conf.display.timezone') ?></label>
+			<div class="group-controls">
+				<select name="new_user_timezone" id="new_user_timezone">
+				<?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 ?>
+				</option>
+				<?php endforeach; ?>
+				</select>
+			</div>
+		</div>
+
 		<div class="form-group">
 			<label class="group-name" for="new_user_name"><?= _t('admin.user.username') ?></label>
 			<div class="group-controls">

+ 2 - 0
config-user.default.php

@@ -7,6 +7,8 @@ return array (
 	'enabled' => true,
 	'is_admin' => false,
 	'language' => 'en',
+	// A timezone identifier such as 'Europe/Paris' https://php.net/timezones or blank for server default
+	'timezone' => '',
 	'archiving' => [
 		'keep_period' => 'P3M',
 		'keep_max' => 200,