From 91112037e95ec09d511e37d978a0ff8db18ab85a Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Sun, 26 Mar 2023 09:31:42 +0200 Subject: [PATCH] Bug d'actualisation du sitemap --- CHANGES.md | 3 +- core/core.php | 264 ++++++++++++++++++---------------- core/module/config/config.php | 2 +- core/module/page/page.php | 28 ++-- 4 files changed, 156 insertions(+), 141 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e61657d2..22b1e42a 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,8 @@ # Changelog ## Version 12.3.04 -- Bug de notification de compte bloqué, la traduction n'est pas effectuée. +- Corrige un défaut d'actualisation de la liste des pages et du site map lorsque la page change d'id. +- Notification de compte bloqué, la traduction n'est pas effectuée. - Amélioration du module, aspect de la liste des articles présenté en tableau et du bouton Lire la suite ## Version 12.3.03 diff --git a/core/core.php b/core/core.php index cb3553a9..e298ee14 100644 --- a/core/core.php +++ b/core/core.php @@ -370,55 +370,10 @@ class common // Construit la liste des pages parents/enfants if ($this->hierarchy['all'] === []) { - $pages = helper::arrayColumn($this->getData(['page']), 'position', 'SORT_ASC'); - // Parents - foreach ($pages as $pageId => $pagePosition) { - if ( - // Page parent - $this->getData(['page', $pageId, 'parentPageId']) === "" - // Ignore les pages dont l'utilisateur n'a pas accès - and ($this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR - or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') - and $this->getUser('group') >= $this->getData(['page', $pageId, 'group']) - ) - ) - ) { - if ($pagePosition !== 0) { - $this->hierarchy['visible'][$pageId] = []; - } - if ($this->getData(['page', $pageId, 'block']) === 'bar') { - $this->hierarchy['bar'][$pageId] = []; - } - $this->hierarchy['all'][$pageId] = []; - } - } - // Enfants - foreach ($pages as $pageId => $pagePosition) { - if ( - // Page parent - $parentId = $this->getData(['page', $pageId, 'parentPageId']) - // Ignore les pages dont l'utilisateur n'a pas accès - and ( - ($this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR - and $this->getData(['page', $parentId, 'group']) === self::GROUP_VISITOR - ) - or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') - and $this->getUser('group') >= $this->getData(['page', $parentId, 'group']) - and $this->getUser('group') >= $this->getData(['page', $pageId, 'group']) - ) - ) - ) { - if ($pagePosition !== 0) { - $this->hierarchy['visible'][$parentId][] = $pageId; - } - if ($this->getData(['page', $pageId, 'block']) === 'bar') { - $this->hierarchy['bar'][$pageId] = []; - } - $this->hierarchy['all'][$parentId][] = $pageId; - } - } + $this->buildHierarchy(); } + // Construit l'url if ($this->url === '') { if ($url = $_SERVER['QUERY_STRING']) { @@ -706,6 +661,7 @@ class common } } + /** * Accède à la liste des pages parents et de leurs enfants * @param int $parentId Id de la page parent @@ -731,6 +687,133 @@ class common } } + /** + * Fonction pour construire le tableau des pages + * Appelée par le core uniquement + */ + + private function buildHierarchy() + { + + $pages = helper::arrayColumn($this->getData(['page']), 'position', 'SORT_ASC'); + // Parents + foreach ($pages as $pageId => $pagePosition) { + if ( + // Page parent + $this->getData(['page', $pageId, 'parentPageId']) === "" + // Ignore les pages dont l'utilisateur n'a pas accès + and ($this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR + or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') + and $this->getUser('group') >= $this->getData(['page', $pageId, 'group']) + ) + ) + ) { + if ($pagePosition !== 0) { + $this->hierarchy['visible'][$pageId] = []; + } + if ($this->getData(['page', $pageId, 'block']) === 'bar') { + $this->hierarchy['bar'][$pageId] = []; + } + $this->hierarchy['all'][$pageId] = []; + } + } + // Enfants + foreach ($pages as $pageId => $pagePosition) { + if ( + // Page parent + $parentId = $this->getData(['page', $pageId, 'parentPageId']) + // Ignore les pages dont l'utilisateur n'a pas accès + and ( + ($this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR + and $this->getData(['page', $parentId, 'group']) === self::GROUP_VISITOR + ) + or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') + and $this->getUser('group') >= $this->getData(['page', $parentId, 'group']) + and $this->getUser('group') >= $this->getData(['page', $pageId, 'group']) + ) + ) + ) { + if ($pagePosition !== 0) { + $this->hierarchy['visible'][$parentId][] = $pageId; + } + if ($this->getData(['page', $pageId, 'block']) === 'bar') { + $this->hierarchy['bar'][$pageId] = []; + } + $this->hierarchy['all'][$parentId][] = $pageId; + } + } + } + + /** + * Génère un fichier json avec la liste des pages + * + */ + private function tinyMcePages() + { + // Sauve la liste des pages pour TinyMCE + $parents = []; + $rewrite = (helper::checkRewrite()) ? '' : '?'; + // Boucle de recherche des pages actives + foreach ($this->getHierarchy(null, false, false) as $parentId => $childIds) { + $children = []; + // Exclure les barres + if ($this->getData(['page', $parentId, 'block']) !== 'bar') { + // Boucler sur les enfants et récupérer le tableau children avec la liste des enfants + foreach ($childIds as $childId) { + $children[] = [ + 'title' => ' » ' . html_entity_decode($this->getData(['page', $childId, 'shortTitle']), ENT_QUOTES), + 'value' => $rewrite . $childId + ]; + } + // Traitement + if (empty($childIds)) { + // Pas d'enfant, uniquement l'entrée du parent + $parents[] = [ + 'title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES), + 'value' => $rewrite . $parentId + ]; + } else { + // Des enfants, on ajoute la page parent en premier + array_unshift($children, [ + 'title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES), + 'value' => $rewrite . $parentId + ]); + // puis on ajoute les enfants au parent + $parents[] = [ + 'title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES), + 'value' => $rewrite . $parentId, + 'menu' => $children + ]; + } + } + } + // Sitemap et Search + $children = []; + $children[] = [ + 'title' => 'Rechercher dans le site', + 'value' => $rewrite . 'search' + ]; + $children[] = [ + 'title' => 'Plan du site', + 'value' => $rewrite . 'sitemap' + ]; + $parents[] = [ + 'title' => 'Pages spéciales', + 'value' => '#', + 'menu' => $children + ]; + + // Enregistrement : 3 tentatives + for ($i = 0; $i < 3; $i++) { + if (file_put_contents('core/vendor/tinymce/link_list.json', json_encode($parents, JSON_UNESCAPED_UNICODE), LOCK_EX) !== false) { + break; + } + // Pause de 10 millisecondes + usleep(10000); + } + } + + /** * Accède à une valeur des variables http (ordre de recherche en l'absence de type : _COOKIE, _POST) * @param string $key Clé de la valeur @@ -836,74 +919,6 @@ class common return ($this->checkCSRF() and $this->input['_POST'] !== []); } - /** - * Génère un fichier json avec la liste des pages - * - */ - public function listPages() - { - // Sauve la liste des pages pour TinyMCE - $parents = []; - $rewrite = (helper::checkRewrite()) ? '' : '?'; - // Boucle de recherche des pages actives - foreach ($this->getHierarchy(null, false, false) as $parentId => $childIds) { - $children = []; - // Exclure les barres - if ($this->getData(['page', $parentId, 'block']) !== 'bar') { - // Boucler sur les enfants et récupérer le tableau children avec la liste des enfants - foreach ($childIds as $childId) { - $children[] = [ - 'title' => ' » ' . html_entity_decode($this->getData(['page', $childId, 'shortTitle']), ENT_QUOTES), - 'value' => $rewrite . $childId - ]; - } - // Traitement - if (empty($childIds)) { - // Pas d'enfant, uniquement l'entrée du parent - $parents[] = [ - 'title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES), - 'value' => $rewrite . $parentId - ]; - } else { - // Des enfants, on ajoute la page parent en premier - array_unshift($children, [ - 'title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES), - 'value' => $rewrite . $parentId - ]); - // puis on ajoute les enfants au parent - $parents[] = [ - 'title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES), - 'value' => $rewrite . $parentId, - 'menu' => $children - ]; - } - } - } - // Sitemap et Search - $children = []; - $children[] = [ - 'title' => 'Rechercher dans le site', - 'value' => $rewrite . 'search' - ]; - $children[] = [ - 'title' => 'Plan du site', - 'value' => $rewrite . 'sitemap' - ]; - $parents[] = [ - 'title' => 'Pages spéciales', - 'value' => '#', - 'menu' => $children - ]; - - // Enregistrement : 3 tentatives - for ($i = 0; $i < 3; $i++) { - if (file_put_contents('core/vendor/tinymce/link_list.json', json_encode($parents, JSON_UNESCAPED_UNICODE), LOCK_EX) !== false) { - break; - } - // Pause de 10 millisecondes - usleep(10000); - } - } /** * Retourne une chemin localisé pour l'enregistrement des données @@ -930,14 +945,20 @@ class common /** * Génère un fichier un fichier sitemap.xml * https://github.com/icamys/php-sitemap-generator - * $command valeurs possible * all : génère un site map complet * Sinon contient id de la page à créer + * @param string Valeurs possibles */ - public function createSitemap($command = "all") + public function updateSitemap() { + // Rafraîchit la liste des pages après une modification de pageId notamment + $this->buildHierarchy(); + + // Actualise la liste des pages pour TinyMCE + $this->tinyMcePages(); + //require_once "core/vendor/sitemap/SitemapGenerator.php"; $timezone = $this->getData(['config', 'timezone']); @@ -1034,6 +1055,8 @@ class common } return (file_exists('sitemap.xml') && file_exists('robots.txt')); + + } /* @@ -1119,7 +1142,7 @@ class common $mail->isSMTP(); $mail->SMTPAutoTLS = false; $mail->SMTPSecure = false; - $mail->SMTPAuth = false; + $mail->SMTPAuth = false; $mail->Host = $this->getdata(['config', 'smtp', 'host']); $mail->Port = (int) $this->getdata(['config', 'smtp', 'port']); if ($this->getData(['config', 'smtp', 'auth'])) { @@ -1258,7 +1281,7 @@ class common new RecursiveCallbackFilterIterator( new RecursiveDirectoryIterator( $folder, - RecursiveDirectoryIterator::SKIP_DOTS + RecursiveDirectoryIterator::SKIP_DOTS ), function ($fileInfo, $key, $iterator) use ($filter) { return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter); @@ -1274,5 +1297,4 @@ class common } $zip->close(); } -} - +} \ No newline at end of file diff --git a/core/module/config/config.php b/core/module/config/config.php index 882b3ba0..98e1949d 100644 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -213,7 +213,7 @@ class config extends common { // Mettre à jour le site map - $successSitemap = $this->createSitemap(); + $successSitemap = $this->updateSitemap(); // Valeurs en sortie $this->addOutput([ diff --git a/core/module/page/page.php b/core/module/page/page.php index 9c747c43..94bd3e01 100644 --- a/core/module/page/page.php +++ b/core/module/page/page.php @@ -168,10 +168,10 @@ class page extends common } //file_put_contents(self::DATA_DIR . self::$i18nContent . '/content/' . $pageId . '.html', '

Contenu de votre nouvelle page.

'); $this->setPage($pageId, '

Contenu de votre nouvelle page.

', self::$i18nContent); - // Met à jour le site map - $this->createSitemap('all'); - // Mise à jour de la liste des pages pour TinyMCE - $this->listPages(); + + // Met à jour le sitemap + $this->updateSitemap(); + // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . $pageId, @@ -295,10 +295,10 @@ class page extends common unlink(self::DATA_DIR . self::$i18nContent . '/content/' . $url[0] . '.html'); } $this->deleteData(['module', $url[0]]); - // Met à jour le site map - $this->createSitemap('all'); - // Mise à jour de la liste des pages pour TinyMCE - $this->listPages(); + + // Met à jour le sitemap + $this->updateSitemap(); + // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl(false), @@ -504,10 +504,8 @@ class page extends common $content = empty($this->getInput('pageEditContent', null)) ? '

' : str_replace('

', '

 

', $this->getInput('pageEditContent', null)); $this->setPage($pageId, $content, self::$i18nContent); - // Met à jour le site map - $this->createSitemap('all'); - // Mise à jour de la liste des pages pour TinyMCE - $this->listPages(); + // Met à jour le sitemap + $this->updateSitemap(); // Redirection vers la configuration if ( @@ -554,12 +552,6 @@ class page extends common } } - // Met à jour le site map - $this->createSitemap('all'); - - // Mise à jour de la liste des pages pour TinyMCE - $this->listPages(); - // Valeurs en sortie $this->addOutput([ 'title' => $this->getData(['page', $this->getUrl(2), 'title']),