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 = ''; - $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/exportcsv.php b/exportcsv.php index 090cbc9..3207f08 100644 --- a/exportcsv.php +++ b/exportcsv.php @@ -38,6 +38,10 @@ $logService = new LogService(); $pollService = new PollService($logService); $securityService = new SecurityService(); +/* Globals */ +global $smarty; +global $date_format; + /* PAGE */ /* ---- */ @@ -77,7 +81,7 @@ if ($poll->format === 'D') { $titles_line = ','; $moments_line = ','; foreach ($slots as $slot) { - $title = Utils::csvEscape(strftime($date_format['txt_date'], $slot->title)); + $title = Utils::csvEscape(formatDate($date_format['txt_date'], $slot->title)); $moments = explode(',', $slot->moments); $titles_line .= str_repeat($title . ',', count($moments)); diff --git a/tpl/create_date_poll_step_2.tpl b/tpl/create_date_poll_step_2.tpl index b9c0c10..675038c 100644 --- a/tpl/create_date_poll_step_2.tpl +++ b/tpl/create_date_poll_step_2.tpl @@ -39,7 +39,7 @@
{foreach $choices as $i=>$choice} {if $choice->getName()} - {$day_value = $choice->getName()|date_format:$date_format['txt_date']} + {$day_value = $choice->getName()|intl_date_format:$date_format['txt_date']} {else} {$day_value = ''} {/if} diff --git a/tpl/mail/find_polls.tpl b/tpl/mail/find_polls.tpl index 933f4ac..db67cbd 100644 --- a/tpl/mail/find_polls.tpl +++ b/tpl/mail/find_polls.tpl @@ -3,7 +3,7 @@ {foreach $polls as $poll}
  • {$poll->title|html} - ({__('Generic', 'Creation date:')} {$poll->creation_date|date_format:$date_format['txt_full']}) + ({__('Generic', 'Creation date:')} {$poll->creation_date|intl_date_format:$date_format['txt_full']})
  • {/foreach} @@ -14,4 +14,4 @@ {capture name="email_url"}{$smarty.const.ADRESSEMAILADMIN}{/capture} {__f('FindPolls',"If you weren't the source of this action and if you think this is an abuse of the service, please notify the administrator on %s.", $smarty.capture.email_url)} -

    \ No newline at end of file +

    diff --git a/tpl/part/comments_list.tpl b/tpl/part/comments_list.tpl index d714a04..766ff0c 100644 --- a/tpl/part/comments_list.tpl +++ b/tpl/part/comments_list.tpl @@ -7,7 +7,7 @@ {if isset($admin) && !$expired} {/if} - {$comment->date|date_format:$date_format['txt_datetime_short']} + {$comment->date|intl_date_format:$date_format['txt_datetime_short']} {$comment->name|html}  {$comment->comment|escape|nl2br}
    diff --git a/tpl/part/poll_info.tpl b/tpl/part/poll_info.tpl index 0f2d2b2..ee69bc2 100644 --- a/tpl/part/poll_info.tpl +++ b/tpl/part/poll_info.tpl @@ -116,12 +116,12 @@
    -

    {$poll->end_date|date_format:$date_format['txt_date']|html}

    +

    {$poll->end_date|intl_date_format:$date_format['txt_date']|html}