diff --git a/adminstuds.php b/adminstuds.php index 7e8718c..1a5eae7 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -43,6 +43,12 @@ $poll = null; $message = null; $editingVoteId = 0; +/* Globals */ +/* ------- */ +global $smarty; +global $connect; +global $config; + /* Services */ /*----------*/ @@ -468,6 +474,5 @@ $smarty->assign('resultPubliclyVisible', true); $smarty->assign('editedVoteUniqueId', ''); $smarty->assign('default_to_marldown_editor', $config['markdown_editor_by_default']); $smarty->assign('selectedNewVotes', $selectedNewVotes); - header("X-Robots-Tag: noindex, nofollow, nosnippet, noarchive"); $smarty->display('studs.tpl'); diff --git a/app/inc/i18n.php b/app/inc/i18n.php index 928ac28..0f7f1fe 100644 --- a/app/inc/i18n.php +++ b/app/inc/i18n.php @@ -34,12 +34,34 @@ $i18n->get('', 'Something, just to load the dictionary'); $locale = str_replace('_', '-', $i18n->getLoadedLang()); /* Date Format */ -$date_format['txt_full'] = __('Date', 'FULL'); //summary in create_date_poll.php and removal date in choix_(date|autre).php -$date_format['txt_short'] = __('Date', 'SHORT'); // radio title -$date_format['txt_day'] = __('Date', 'DAY'); -$date_format['txt_date'] = __('Date', 'DATE'); -$date_format['txt_month_year'] = __('Date', 'MONTH_YEAR'); -$date_format['txt_datetime_short'] = __('Date', 'DATETIME'); +//$date_format['txt_full'] = __('Date', 'FULL'); //summary in create_date_poll.php and removal date in choix_(date|autre).php +//$date_format['txt_short'] = __('Date', 'SHORT'); // radio title +//$date_format['txt_day'] = __('Date', 'DAY'); +//$date_format['txt_date'] = __('Date', 'DATE'); +//$date_format['txt_month_year'] = __('Date', 'MONTH_YEAR'); +//$date_format['txt_datetime_short'] = __('Date', 'DATETIME'); + +$date_format['txt_full'] = 'eeee d MMMM y'; //summary in create_date_poll.php and removal date in choix_(date|autre).php +$date_format['txt_short'] = 'E d MMMM y'; // radio title +$date_format['txt_day'] = 'E d'; +$date_format['txt_date'] = ''; // Defaults to IntlDateFormatter::SHORT +$date_format['txt_month_year'] = 'MMMM y'; +$date_format['txt_datetime_short'] = 'dd-MM-y HH:mm'; + +function formatDate(string $format, $date) { + global $locale; + $formatter = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::NONE); + if ($format !== '') { + $formatter->setPattern($format); + } + if (is_numeric($date)) { + $date = (new DateTime())->setTimestamp($date); + } elseif (gettype($date) === 'string') { + $date = new DateTime($date); + } + return datefmt_format($formatter, $date); +} + if (PHP_OS_FAMILY === 'Windows') { //%e can't be used on Windows platform, use %#d instead foreach ($date_format as $k => $v) { $date_format[$k] = preg_replace('#(?setTemplateDir(ROOT_DIR . '/tpl/'); @@ -119,6 +123,10 @@ function smarty_modifier_locale_2_lang(string $locale): string return $locale; } +function smarty_modifier_intl_date_format($date, string $pattern): string { + return formatDate($pattern, $date); +} + function path_for_datepicker_locale(string $lang): string { return __DIR__ . '/../../js/locales/bootstrap-datepicker.' . $lang . '.js'; diff --git a/composer.json b/composer.json index abe47d1..0d7972e 100644 --- a/composer.json +++ b/composer.json @@ -63,6 +63,7 @@ "php": ">=7.3.0", "ext-pdo": "*", "ext-json": "*", + "ext-intl": "*", "smarty/smarty": "^4.0", "o80/i18n": "dev-develop", "phpmailer/phpmailer": "~6.2", diff --git a/create_classic_poll.php b/create_classic_poll.php index fe30725..62dfb0a 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -141,7 +141,7 @@ if (empty($form->title) || empty($form->admin_name) || ($config['use_smtp'] && e } $summary .= ''; - $end_date_str = utf8_encode(strftime($date_format['txt_date'], $pollService->maxExpiryDate()->getTimestamp())); //textual date + $end_date_str = utf8_encode(formatDate($date_format['txt_date'], $pollService->maxExpiryDate()->getTimestamp())); //textual date $_SESSION['form'] = serialize($form); diff --git a/create_date_poll.php b/create_date_poll.php index 8fc6064..a7d9974 100644 --- a/create_date_poll.php +++ b/create_date_poll.php @@ -160,7 +160,7 @@ switch ($step) { $summary = '
{$poll->end_date|date_format:$date_format['txt_date']|html}
+{$poll->end_date|intl_date_format:$date_format['txt_date']|html}