revert sitemapgenerator v5

This commit is contained in:
Fred Tempez 2025-01-06 18:25:14 +01:00
parent b8ec14e005
commit 51c5522f5e

View File

@ -1127,133 +1127,122 @@ class common
* @param string Valeurs possibles * @param string Valeurs possibles
*/ */
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();
$config = new \Icamys\SitemapGenerator\Config(); $sitemap = new \Icamys\SitemapGenerator\SitemapGenerator(helper::baseurl(false), $outputDir);
// will create also compressed (gzipped) sitemap : option buguée
// Your site URL. // $sitemap->enableCompression();
$config->setBaseURL(helper::baseurl(false));
// // OPTIONAL. Setting the current working directory to be output directory // determine how many urls should be put into one file
$config->setSaveDirectory(sys_get_temp_dir()); // according to standard protocol 50000 is maximum value (see http://www.sitemaps.org/protocol.html)
$sitemap->setMaxUrlsPerSitemap(50000);
$sitemap = new \Icamys\SitemapGenerator\SitemapGenerator($config); // sitemap file name
$sitemap->setSitemapFileName('sitemap.xml');
// Create a compressed sitemap
$sitemap->enableCompression();
// Set the sitemap index file name
// will create also compressed (gzipped) sitemap : option buguée $sitemap->setSitemapIndexFileName('sitemap-index.xml');
// $sitemap->enableCompression();
$datetime = new DateTime(date('c'));
// determine how many urls should be put into one file $datetime->format(DateTime::ATOM); // Updated ISO8601
// according to standard protocol 50000 is maximum value (see http://www.sitemaps.org/protocol.html)
$sitemap->setMaxUrlsPerSitemap(50000); foreach ($this->getHierarchy() as $parentPageId => $childrenPageIds) {
// Exclure les barres et les pages non publiques et les pages masquées
// sitemap file name if (
$sitemap->setSitemapFileName('sitemap.xml'); $this->getData(['page', $parentPageId, 'group']) !== 0 ||
$this->getData(['page', $parentPageId, 'block']) === 'bar'
) {
// Set the sitemap index file name continue;
$sitemap->setSitemapIndexFileName('sitemap-index.xml'); }
// Page désactivée, traiter les sous-pages sans prendre en compte la page parente.
$datetime = new DateTime(date('c')); if ($this->getData(['page', $parentPageId, 'disable']) !== true) {
$datetime->format(DateTime::ATOM); // Updated ISO8601 // Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ($parentPageId !== $this->getData(['locale', 'homePageId'])) ? $parentPageId : '';
foreach ($this->getHierarchy() as $parentPageId => $childrenPageIds) { $sitemap->addUrl('/' . $pageId, $datetime);
// Exclure les barres et les pages non publiques et les pages masquées $flag = true;
if ( }
$this->getData(['page', $parentPageId, 'group']) !== 0 || // Articles du blog
$this->getData(['page', $parentPageId, 'block']) === 'bar' if (
) { $this->getData(['page', $parentPageId, 'moduleId']) === 'blog'
continue; && !empty($this->getData(['module', $parentPageId]))
} && $this->getData(['module', $parentPageId, 'posts'])
// Page désactivée, traiter les sous-pages sans prendre en compte la page parente. ) {
if ($this->getData(['page', $parentPageId, 'disable']) !== true) { foreach ($this->getData(['module', $parentPageId, 'posts']) as $articleId => $article) {
// Cas de la page d'accueil ne pas dupliquer l'URL if ($this->getData(['module', $parentPageId, 'posts', $articleId, 'state']) === true) {
$pageId = ($parentPageId !== $this->getData(['locale', 'homePageId'])) ? $parentPageId : ''; $date = $this->getData(['module', $parentPageId, 'posts', $articleId, 'publishedOn']);
$sitemap->addUrl('/' . $pageId, $datetime); $sitemap->addUrl('/' . $parentPageId . '/' . $articleId, DateTime::createFromFormat('U', $date));
$flag = true; }
} }
// Articles du blog }
if ( // Sous-pages
$this->getData(['page', $parentPageId, 'moduleId']) === 'blog' foreach ($childrenPageIds as $childKey) {
&& !empty($this->getData(['module', $parentPageId])) if ($this->getData(['page', $childKey, 'group']) !== 0 || $this->getData(['page', $childKey, 'disable']) === true) {
&& $this->getData(['module', $parentPageId, 'posts']) continue;
) { }
foreach ($this->getData(['module', $parentPageId, 'posts']) as $articleId => $article) { // Cas de la page d'accueil ne pas dupliquer l'URL
if ($this->getData(['module', $parentPageId, 'posts', $articleId, 'state']) === true) { $pageId = ($childKey !== $this->getData(['locale', 'homePageId'])) ? $childKey : '';
$date = $this->getData(['module', $parentPageId, 'posts', $articleId, 'publishedOn']); $sitemap->addUrl('/' . $childKey, $datetime);
$sitemap->addUrl('/' . $parentPageId . '/' . $articleId, DateTime::createFromFormat('U', $date)); $flag = true;
}
} // La sous-page est un blog
} if (
// Sous-pages $this->getData(['page', $childKey, 'moduleId']) === 'blog' &&
foreach ($childrenPageIds as $childKey) { !empty($this->getData(['module', $childKey]))
if ($this->getData(['page', $childKey, 'group']) !== 0 || $this->getData(['page', $childKey, 'disable']) === true) { ) {
continue; foreach ($this->getData(['module', $childKey, 'posts']) as $articleId => $article) {
} if ($this->getData(['module', $childKey, 'posts', $articleId, 'state']) === true) {
// Cas de la page d'accueil ne pas dupliquer l'URL $date = $this->getData(['module', $childKey, 'posts', $articleId, 'publishedOn']);
$pageId = ($childKey !== $this->getData(['locale', 'homePageId'])) ? $childKey : ''; $sitemap->addUrl('/' . $childKey . '/' . $articleId, new DateTime("@{$date}", new DateTimeZone($timezone)));
$sitemap->addUrl('/' . $childKey, $datetime); }
$flag = true; }
}
// La sous-page est un blog }
if ( }
$this->getData(['page', $childKey, 'moduleId']) === 'blog' &&
!empty($this->getData(['module', $childKey])) if ($flag === false) {
) { return false;
foreach ($this->getData(['module', $childKey, 'posts']) as $articleId => $article) { }
if ($this->getData(['module', $childKey, 'posts', $articleId, 'state']) === true) {
$date = $this->getData(['module', $childKey, 'posts', $articleId, 'publishedOn']); // Flush all stored urls from memory to the disk and close all necessary tags.
$sitemap->addUrl('/' . $childKey . '/' . $articleId, new DateTime("@{$date}", new DateTimeZone($timezone))); $sitemap->flush();
}
} // Move flushed files to their final location. Compress if the option is enabled.
} $sitemap->finalize();
}
} // Update robots.txt file in output directory
if ($flag === false) { if ($this->getData(['config', 'seo', 'robots']) === true) {
return false; if (file_exists('robots.txt')) {
} unlink('robots.txt');
}
// Flush all stored urls from memory to the disk and close all necessary tags. $sitemap->updateRobots();
$sitemap->flush(); } else {
$this->secure_file_put_contents('robots.txt', 'User-agent: *' . PHP_EOL . 'Disallow: /');
// Move flushed files to their final location. Compress if the option is enabled. }
$sitemap->finalize();
// Submit your sitemaps to Google, Yahoo, Bing and Ask.com
// Update robots.txt file in output directory if (empty($this->getData(['config', 'proxyType']) . $this->getData(['config', 'proxyUrl']) . ':' . $this->getData(['config', 'proxyPort']))) {
$sitemap->submitSitemap();
if ($this->getData(['config', 'seo', 'robots']) === true) { }
if (file_exists('robots.txt')) {
unlink('robots.txt'); return (file_exists('sitemap.xml') && file_exists('robots.txt'));
}
$sitemap->updateRobots(); }
} else {
$this->secure_file_put_contents('robots.txt', 'User-agent: *' . PHP_EOL . 'Disallow: /');
}
// Submit your sitemaps to Google, Yahoo, Bing and Ask.com
if (empty($this->getData(['config', 'proxyType']) . $this->getData(['config', 'proxyUrl']) . ':' . $this->getData(['config', 'proxyPort']))) {
$sitemap->submitSitemap();
}
return (file_exists('sitemap.xml') && file_exists('robots.txt'));
}
/* /*