revert sitemapgenerator v5

This commit is contained in:
Fred Tempez 2025-01-06 18:08:00 +01:00
parent 8a07bf69a7
commit 85f6c43d79

View File

@ -1120,124 +1120,123 @@ class common
*/ */
public function updateSitemap() public function updateSitemap()
{ {
// Le drapeau prend true quand au moins une page est trouvée // Le drapeau prend true quand au moins une page est trouvée
$flag = false; $flag = false;
// Rafraîchit la liste des pages après une modification de pageId notamment // Rafraîchit la liste des pages après une modification de pageId notamment
$this->buildHierarchy(); $this->buildHierarchy();
// Actualise la liste des pages pour TinyMCE // Actualise la liste des pages pour TinyMCE
$this->tinyMcePages(); $this->tinyMcePages();
//require_once 'core/vendor/sitemap/SitemapGenerator.php'; //require_once 'core/vendor/sitemap/SitemapGenerator.php';
$timezone = $this->getData(['config', 'timezone']); $timezone = $this->getData(['config', 'timezone']);
$outputDir = getcwd(); $outputDir = getcwd();
$sitemap = new \Icamys\SitemapGenerator\SitemapGenerator(helper::baseurl(false), $outputDir); $sitemap = new \Icamys\SitemapGenerator\SitemapGenerator(helper::baseurl(false), $outputDir);
// will create also compressed (gzipped) sitemap : option buguée // will create also compressed (gzipped) sitemap : option buguée
// $sitemap->enableCompression(); // $sitemap->enableCompression();
// determine how many urls should be put into one file // determine how many urls should be put into one file
// according to standard protocol 50000 is maximum value (see http://www.sitemaps.org/protocol.html) // according to standard protocol 50000 is maximum value (see http://www.sitemaps.org/protocol.html)
$sitemap->setMaxUrlsPerSitemap(50000); $sitemap->setMaxUrlsPerSitemap(50000);
// sitemap file name // sitemap file name
$sitemap->setSitemapFileName('sitemap.xml'); $sitemap->setSitemapFileName('sitemap.xml');
// Set the sitemap index file name // Set the sitemap index file name
$sitemap->setSitemapIndexFileName('sitemap-index.xml'); $sitemap->setSitemapIndexFileName('sitemap-index.xml');
$datetime = new DateTime(date('c')); $datetime = new DateTime(date('c'));
$datetime->format(DateTime::ATOM); // Updated ISO8601 $datetime->format(DateTime::ATOM); // Updated ISO8601
foreach ($this->getHierarchy() as $parentPageId => $childrenPageIds) { foreach ($this->getHierarchy() as $parentPageId => $childrenPageIds) {
// Exclure les barres et les pages non publiques et les pages masquées // Exclure les barres et les pages non publiques et les pages masquées
if ( if (
$this->getData(['page', $parentPageId, 'group']) !== 0 || $this->getData(['page', $parentPageId, 'group']) !== 0 ||
$this->getData(['page', $parentPageId, 'block']) === 'bar' $this->getData(['page', $parentPageId, 'block']) === 'bar'
) { ) {
continue; continue;
} }
// Page désactivée, traiter les sous-pages sans prendre en compte la page parente. // Page désactivée, traiter les sous-pages sans prendre en compte la page parente.
if ($this->getData(['page', $parentPageId, 'disable']) !== true) { if ($this->getData(['page', $parentPageId, 'disable']) !== true) {
// Cas de la page d'accueil ne pas dupliquer l'URL // Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ($parentPageId !== $this->homePageId()) ? $parentPageId : ''; $pageId = ($parentPageId !== $this->homePageId()) ? $parentPageId : '';
$sitemap->addUrl('/' . $pageId, $datetime); $sitemap->addUrl('/' . $pageId, $datetime);
$flag = true; $flag = true;
} }
// Articles du blog // Articles du blog
if ( if (
$this->getData(['page', $parentPageId, 'moduleId']) === 'blog' $this->getData(['page', $parentPageId, 'moduleId']) === 'blog'
&& !empty($this->getData(['module', $parentPageId])) && !empty($this->getData(['module', $parentPageId]))
&& $this->getData(['module', $parentPageId, 'posts']) && $this->getData(['module', $parentPageId, 'posts'])
) { ) {
foreach ($this->getData(['module', $parentPageId, 'posts']) as $articleId => $article) { foreach ($this->getData(['module', $parentPageId, 'posts']) as $articleId => $article) {
if ($this->getData(['module', $parentPageId, 'posts', $articleId, 'state']) === true) { if ($this->getData(['module', $parentPageId, 'posts', $articleId, 'state']) === true) {
$date = $this->getData(['module', $parentPageId, 'posts', $articleId, 'publishedOn']); $date = $this->getData(['module', $parentPageId, 'posts', $articleId, 'publishedOn']);
$sitemap->addUrl('/' . $parentPageId . '/' . $articleId, DateTime::createFromFormat('U', $date)); $sitemap->addUrl('/' . $parentPageId . '/' . $articleId, DateTime::createFromFormat('U', $date));
$flag = true; $flag = true;
} }
} }
} }
// Sous-pages // Sous-pages
foreach ($childrenPageIds as $childKey) { foreach ($childrenPageIds as $childKey) {
if ($this->getData(['page', $childKey, 'group']) !== 0 || $this->getData(['page', $childKey, 'disable']) === true) { if ($this->getData(['page', $childKey, 'group']) !== 0 || $this->getData(['page', $childKey, 'disable']) === true) {
continue; continue;
} }
// Cas de la page d'accueil ne pas dupliquer l'URL // Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ($childKey !== $this->homePageId()) ? $childKey : ''; $pageId = ($childKey !== $this->homePageId()) ? $childKey : '';
$sitemap->addUrl('/' . $childKey, $datetime); $sitemap->addUrl('/' . $childKey, $datetime);
$flag = true; $flag = true;
// La sous-page est un blog // La sous-page est un blog
if ( if (
$this->getData(['page', $childKey, 'moduleId']) === 'blog' && $this->getData(['page', $childKey, 'moduleId']) === 'blog' &&
!empty($this->getData(['module', $childKey])) !empty($this->getData(['module', $childKey]))
) { ) {
foreach ($this->getData(['module', $childKey, 'posts']) as $articleId => $article) { foreach ($this->getData(['module', $childKey, 'posts']) as $articleId => $article) {
if ($this->getData(['module', $childKey, 'posts', $articleId, 'state']) === true) { if ($this->getData(['module', $childKey, 'posts', $articleId, 'state']) === true) {
$date = $this->getData(['module', $childKey, 'posts', $articleId, 'publishedOn']); $date = $this->getData(['module', $childKey, 'posts', $articleId, 'publishedOn']);
$sitemap->addUrl('/' . $childKey . '/' . $articleId, DateTime::createFromFormat('U', $date)); $sitemap->addUrl('/' . $childKey . '/' . $articleId, DateTime::createFromFormat('U', $date));
$flag = true; $flag = true;
} }
} }
} }
} }
} }
if ($flag === false) { if ($flag === false) {
return false; return false;
} }
// Flush all stored urls from memory to the disk and close all necessary tags. // Flush all stored urls from memory to the disk and close all necessary tags.
$sitemap->flush(); $sitemap->flush();
// Move flushed files to their final location. Compress if the option is enabled. // Move flushed files to their final location. Compress if the option is enabled.
$sitemap->finalize(); $sitemap->finalize();
// Update robots.txt file in output directory // Update robots.txt file in output directory
if ($this->getData(['config', 'seo', 'robots']) === true) { if ($this->getData(['config', 'seo', 'robots']) === true) {
if (file_exists('robots.txt')) { if (file_exists('robots.txt')) {
unlink('robots.txt'); unlink('robots.txt');
} }
$sitemap->updateRobots(); $sitemap->updateRobots();
} else { } else {
file_put_contents('robots.txt', 'User-agent: *' . PHP_EOL . 'Disallow: /'); file_put_contents('robots.txt', 'User-agent: *' . PHP_EOL . 'Disallow: /');
} }
// Submit your sitemaps to Google, Yahoo, Bing and Ask.com // Submit your sitemaps to Google, Yahoo, Bing and Ask.com
if (empty($this->getData(['config', 'proxyType']) . $this->getData(['config', 'proxyUrl']) . ':' . $this->getData(['config', 'proxyPort']))) { if (empty($this->getData(['config', 'proxyType']) . $this->getData(['config', 'proxyUrl']) . ':' . $this->getData(['config', 'proxyPort']))) {
$sitemap->submitSitemap(); $sitemap->submitSitemap();
} }
return (file_exists('sitemap.xml') && file_exists('robots.txt')); return (file_exists('sitemap.xml') && file_exists('robots.txt'));
}
}
/* /*