From f863b69a4daa5dda554660798ef045efa33c092c Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Sun, 1 Nov 2020 13:38:25 +0100 Subject: [PATCH] Localisation avec test de l'encodage --- core/core.php | 4 +++- core/module/config/config.php | 4 +++- core/module/user/user.php | 6 ++++-- index.php | 1 - module/blog/blog.php | 15 ++++++++++----- module/blog/view/article/article.php | 15 ++++++++++++--- module/blog/view/index/index.php | 4 +++- module/news/news.php | 10 +++++++--- module/news/view/index/index.php | 4 +++- 9 files changed, 45 insertions(+), 18 deletions(-) diff --git a/core/core.php b/core/core.php index 63ddfaa8..c34e8c79 100644 --- a/core/core.php +++ b/core/core.php @@ -1717,7 +1717,9 @@ class core extends common { exit(); } // Journalisation - $dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ; + $dataLog = mb_detect_encoding(strftime('%d/%m/%y',time()), 'UTF-8', true) + ? strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' + : utf8_encode(strftime('%d/%m/%y',time())) . ';' . utf8_encode(strftime('%R',time())) . ';' ; $dataLog .= helper::getIp() . ';'; $dataLog .= $this->getUser('id') ? $this->getUser('id') . ';' : 'anonyme' . ';'; $dataLog .= $this->getUrl(); diff --git a/core/module/config/config.php b/core/module/config/config.php index 13e474b5..c0ca5bcb 100644 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -695,7 +695,9 @@ class config extends common { $d = $this->getData(['blacklist']); $data = ''; foreach ($d as $key => $item) { - $data .= strftime('%d/%m/%y',$item['lastFail']) . ';' . strftime('%R',$item['lastFail']) . ';' ; + $data .= mb_detect_encoding(strftime('%d/%m/%y',$item['lastFail']), 'UTF-8', true) + ? strftime('%d/%m/%y',$item['lastFail']) . ';' . utf8_encode(strftime('%R',$item['lastFail'])) . ';' + : utf8_encode(strftime('%d/%m/%y',$item['lastFail'])) . ';' . utf8_encode(strftime('%R',$item['lastFail'])) . ';' ; $data .= $key . ';' . $item['ip'] . ';' . $item['connectFail'] . PHP_EOL; } file_put_contents($fileName,$data,FILE_APPEND); diff --git a/core/module/user/user.php b/core/module/user/user.php index f1c8aeef..9d8ce8e5 100644 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -53,7 +53,7 @@ class user extends common { $userFirstname = $this->getInput('userAddFirstname', helper::FILTER_STRING_SHORT, true); $userLastname = $this->getInput('userAddLastname', helper::FILTER_STRING_SHORT, true); $userMail = $this->getInput('userAddMail', helper::FILTER_MAIL, true); - + // Stockage des données $this->setData([ 'user', @@ -433,7 +433,9 @@ class user extends common { $notification = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.'; } // Journalisation - $dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ; + $dataLog = mb_detect_encoding(strftime('%d/%m/%y',time()), 'UTF-8', true) + ? strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' + : utf8_encode(strftime('%d/%m/%y',time())) . ';' . utf8_encode(strftime('%R',time())) . ';' ; $dataLog .= helper::getIp() . ';'; $dataLog .= $userId . ';' ; $dataLog .= $this->getUrl() .';' ; diff --git a/index.php b/index.php index 0aef1059..30ea149e 100644 --- a/index.php +++ b/index.php @@ -37,7 +37,6 @@ if(version_compare(PHP_VERSION, '5.6.0', '<')) { date_default_timezone_set('Europe/Paris'); setlocale (LC_ALL,'french','fr_Fr','fr_FR.utf8'); - /** * Chargement des classes */ diff --git a/module/blog/blog.php b/module/blog/blog.php index 0b37766d..a13c011c 100644 --- a/module/blog/blog.php +++ b/module/blog/blog.php @@ -127,7 +127,9 @@ class blog extends common { // Met en forme le tableau $comment = $comments[$commentIds[$i]]; self::$comments[] = [ - strftime('%d %B %Y - %H:%M', $comment['createdOn']), + mb_detect_encoding(strftime('%d %B %Y - %H:%M', $comment['createdOn']), 'UTF-8', true) + ? strftime('%d %B %Y - %H:%M', $comment['createdOn']) + : utf8_encode(strftime('%d %B %Y - %H:%M', $comment['createdOn'])), $comment['content'], $comment['userId'] ? $this->getData(['user', $comment['userId'], 'firstname']) . ' ' . $this->getData(['user', $comment['userId'], 'lastname']) : $comment['author'], template::button('blogCommentDelete' . $commentIds[$i], [ @@ -188,12 +190,15 @@ class blog extends common { // Articles en fonction de la pagination for($i = $pagination['first']; $i < $pagination['last']; $i++) { // Met en forme le tableau + $date = mb_detect_encoding(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn'])), 'UTF-8', true) + ? strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn'])) + : utf8_encode(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn']))); + $heure = mb_detect_encoding(strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn'])), 'UTF-8', true) + ? strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn'])) + : utf8_encode(strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn']))); self::$articles[] = [ $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'title']), - // date('d/m/Y H:i', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn'])), - strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn'])) - .' à '. - strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn'])), + $date .' à '. $heure, self::$states[$this->getData(['module', $this->getUrl(0), $articleIds[$i], 'state'])], template::button('blogConfigEdit' . $articleIds[$i], [ 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $articleIds[$i] . '/' . $_SESSION['csrf'], diff --git a/module/blog/view/article/article.php b/module/blog/view/article/article.php index 0e48c040..8b5e5d30 100644 --- a/module/blog/view/article/article.php +++ b/module/blog/view/article/article.php @@ -3,8 +3,14 @@
- getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn'])); ?> - à getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn'])); ?> + getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn'])), 'UTF-8', true) + ? strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn'])) + : utf8_encode(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn']))); + $heure = mb_detect_encoding(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn'])), 'UTF-8', true) + ? strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn'])) + : utf8_encode(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn']))); + echo $date . ' à ' . $heure; + ?>
- le + le diff --git a/module/blog/view/index/index.php b/module/blog/view/index/index.php index 7265af36..271e2dba 100644 --- a/module/blog/view/index/index.php +++ b/module/blog/view/index/index.php @@ -34,7 +34,9 @@
- +

... diff --git a/module/news/news.php b/module/news/news.php index 4499028c..10486ec8 100644 --- a/module/news/news.php +++ b/module/news/news.php @@ -89,11 +89,15 @@ class news extends common { // News en fonction de la pagination for($i = $pagination['first']; $i < $pagination['last']; $i++) { // Met en forme le tableau + $date = mb_detect_encoding(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $newsIds[$i], 'publishedOn'])), 'UTF-8', true) + ? strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $newsIds[$i], 'publishedOn'])) + : utf8_encode(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $newsIds[$i], 'publishedOn']))); + $heure = mb_detect_encoding(strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $newsIds[$i], 'publishedOn'])), 'UTF-8', true) + ? strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $newsIds[$i], 'publishedOn'])) + : utf8_encode(strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $newsIds[$i], 'publishedOn']))); self::$news[] = [ $this->getData(['module', $this->getUrl(0), $newsIds[$i], 'title']), - strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $newsIds[$i], 'publishedOn'])) - .' à '. - strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $newsIds[$i], 'publishedOn'])), + $date .' à '. $heure, self::$states[$this->getData(['module', $this->getUrl(0), $newsIds[$i], 'state'])], template::button('newsConfigEdit' . $newsIds[$i], [ 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $newsIds[$i]. '/' . $_SESSION['csrf'], diff --git a/module/news/view/index/index.php b/module/news/view/index/index.php index 7c34a1da..60bbe60b 100644 --- a/module/news/view/index/index.php +++ b/module/news/view/index/index.php @@ -10,7 +10,9 @@

- + - getData(['user', $news['userId'], 'firstname']) . ' ' . $this->getData(['user', $news['userId'], 'lastname']); ?>