From 21580cf4fac6c01027e998ee5ed776b7bb263a7e Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Mon, 16 Nov 2020 18:39:32 +0100 Subject: [PATCH] =?UTF-8?q?Protection=20des=20donn=C3=A9es=20de=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/blog/blog.php | 86 ++++++++++++++++++------------ module/blog/view/config/config.php | 85 ++++++++++++++++++----------- 2 files changed, 107 insertions(+), 64 deletions(-) diff --git a/module/blog/blog.php b/module/blog/blog.php index 7ea5da21..1573db45 100644 --- a/module/blog/blog.php +++ b/module/blog/blog.php @@ -230,41 +230,59 @@ class blog extends common { * Configuration */ public function config() { - // Ids des articles par ordre de publication - $articleIds = array_keys(helper::arrayCollumn($this->getData(['module', $this->getUrl(0)]), 'publishedOn', 'SORT_DESC')); - // Pagination - $pagination = helper::pagination($articleIds, $this->getUrl(),$this->getData(['config','itemsperPage'])); - // Liste des pages - self::$pages = $pagination['pages']; - // 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 .' à '. $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'], - 'value' => template::ico('pencil') - ]), - template::button('blogConfigDelete' . $articleIds[$i], [ - 'class' => 'blogConfigDelete buttonRed', - 'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $articleIds[$i] . '/' . $_SESSION['csrf'], - 'value' => template::ico('cancel') - ]) - ]; + // Soumission du formulaire + if($this->isPost()) { + $this->setData(['module', $this->getUrl(0), 'config',[ + 'feeds' => $this->getInput('blogConfigShowFeeds',helper::FILTER_BOOLEAN), + 'feedsLabel' => $this->getInput('blogConfigFeedslabel',helper::FILTER_STRING_SHORT) + ]]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => 'Modifications enregistrées', + 'state' => true + ]); + } else { + // Extraire la clé config mot clé réservé + $articles = $this->getData(['module', $this->getUrl(0)]); + unset($articles['config']); + // Ids des articles par ordre de publication + $articleIds = array_keys(helper::arrayCollumn($articles, 'publishedOn', 'SORT_DESC')); + // Supprimer le bloc config + // Pagination + $pagination = helper::pagination($articleIds, $this->getUrl(),$this->getData(['config','itemsperPage'])); + // Liste des pages + self::$pages = $pagination['pages']; + // 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 .' à '. $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'], + 'value' => template::ico('pencil') + ]), + template::button('blogConfigDelete' . $articleIds[$i], [ + 'class' => 'blogConfigDelete buttonRed', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $articleIds[$i] . '/' . $_SESSION['csrf'], + 'value' => template::ico('cancel') + ]) + ]; + } + // Valeurs en sortie + $this->addOutput([ + 'title' => 'Configuration du module', + 'view' => 'config' + ]); } - // Valeurs en sortie - $this->addOutput([ - 'title' => 'Configuration du module', - 'view' => 'config' - ]); } /** diff --git a/module/blog/view/config/config.php b/module/blog/view/config/config.php index a8d472dd..a044b793 100644 --- a/module/blog/view/config/config.php +++ b/module/blog/view/config/config.php @@ -1,32 +1,57 @@ -
-
- 'buttonGrey', - 'href' => helper::baseUrl() . 'page/edit/' . $this->getUrl(0), - 'ico' => 'left', - 'value' => 'Retour' - ]); ?> + +
+
+ 'buttonGrey', + 'href' => helper::baseUrl() . 'page/edit/' . $this->getUrl(0), + 'ico' => 'left', + 'value' => 'Retour' + ]); ?> +
+
+ helper::baseUrl() . $this->getUrl(0) . '/comment', + 'value' => 'Gérer les commentaires' + ]); ?> +
+
+ helper::baseUrl() . $this->getUrl(0) . '/add', + 'ico' => 'plus', + 'value' => 'Article' + ]); ?> +
+
+ +
-
- helper::baseUrl() . $this->getUrl(0) . '/comment', - 'value' => 'Gérer les commentaires' - ]); ?> +
+
+
+

Paramètres du module

+
+
+ $this->getData(['module', $this->getUrl(0), 'config', 'feeds']), + ]); ?> +
+
+ 'Etiquette', + 'value' => empty($this->getData(['module', $this->getUrl(0), 'config','feedsLabel'])) ? 'Syndication RSS' : $this->getData(['module', $this->getUrl(0), 'config', 'feedsLabel']) + ]); ?> +
+
+
+
-
- helper::baseUrl() . $this->getUrl(0) . '/add', - 'ico' => 'plus', - 'value' => 'Article' - ]); ?> -
-
- - - - - - -
Version n° - -
\ No newline at end of file + + + + + + + +
Version n° + +
\ No newline at end of file