* @copyright Tela-Botanica 1999-2008 * @link http://www.tela-botanica.org/wikini/eflore * @licence GPL v3 & CeCILL v2 * @version $Id: Sitemap.class.php 1873 2009-03-31 10:07:24Z Jean-Pascal MILCENT $ */ // +-------------------------------------------------------------------------------------------------------------------+ /** * Classe crééant un Sitemap */ class Robot extends ScriptCommande { private $lastmod = '2008-04-28'; private $changefreq = 'monthly'; public function executer() { $cmd = $this->getParam('a'); switch ($cmd) { case 'creer' : $this->creerSiteMap(); break; default : trigger_error('Erreur : la commande "'.$cmd.'" n\'existe pas!'."\n", E_USER_ERROR); } } private function creerSiteMap() { // +-----------------------------------------------------------------------------------------------------------+ // Initialisation des paramêtres variables $url_site = 'http://www.tela-botanica.org/'; $url_eflore = $url_site.'eflore/%s/nt/%s/%s'; $projets = array( array('id' => 25, 'code' => 'BDNFF', 'url' => $url_eflore, 'taxon_max' => 50000, 'onglets' => '*'), array('id' => 29, 'code' => 'BDNFM', 'url' => $url_eflore, 'taxon_max' => 50000, 'onglets' => 'synthese,synonymie,vernaculaire,chorologie,biblio,information,illustration,wiki'), array('id' => 38, 'code' => 'BDNBE', 'url' => $url_eflore, 'taxon_max' => 50000, 'onglets' => 'synthese,synonymie,chorologie,biblio,information,illustration,wiki'), array('id' => 45, 'code' => 'BDAFN', 'url' => $url_eflore, 'taxon_max' => 500000, 'onglets' => 'synthese,synonymie,chorologie,biblio,information,illustration,wiki') ); $onglets = array( 'synthese' => '0.9', 'synonymie' => '0.6', 'vernaculaire' => '0.8', 'chorologie' => '0.7', 'biblio' => '0.8', 'information' => '0.2', 'illustration' => '0.9', 'wiki' => '0.3', 'cel' => '0.5'); $xmlstr_sitemap = ''."\n". ''."\n". ''."\n"; $xmlstr_sitemapindex = ''."\n". ''."\n". ''."\n"; // +-----------------------------------------------------------------------------------------------------------+ // Initialisation des variables $UrlSet = null; $SiteMapIndex = null; $cpt_url = 1; $cpt_fichier = 1; $Taxon = new EfloreTaxon(true); // +-----------------------------------------------------------------------------------------------------------+ // Lancement du traitement foreach ($projets as $projet) { // Gestion des onglets affichables pour le projet courrant if ($projet['onglets'] != '*') { $projet['onglets'] = array_flip(explode(',', $projet['onglets'])); } // +-------------------------------------------------------------------------------------------------------+ echo "Création des URLs des taxons pour le projet {$projet['code']} : "; $i = 1; $taxons = $Taxon->consulterTaxon($projet['id']); foreach ($taxons as $taxon) { // Seul les taxons du projet sont indexés, on exclue les taxons virtuels if ($taxon['et']['id']['taxon'] < $projet['taxon_max']) { foreach ($onglets as $onglet => $priorite) { // Vérification que l'onglet est autorisé pour ce projet if ($projet['onglets'] == '*' || isset($projet['onglets'][$onglet])) { // Affichage en console et en cas de test... echo str_repeat(chr(8), ( strlen( $i ) + 1 ))."\t".$i++; // Création du fichier XML si nécessaire if (is_null($UrlSet)) { $UrlSet = new SimpleXMLElement($xmlstr_sitemap); } // Ajout de l'url $Url = $UrlSet->addChild('url'); $Url->addChild('loc', sprintf($projet['url'], $projet['code'], $taxon['et']['id']['taxon'], $onglet)); $Url->addChild('lastmod', $this->lastmod); $Url->addChild('changefreq', $this->changefreq); $Url->addChild('priority', $priorite); // Vérification écriture du fichier ou pas if ($cpt_url == 1) { $estimation = strlen($UrlSet->asXml()); } if (49999 == $cpt_url++ || ($estimation * $cpt_url) > 20000000 || $i == (int)$this->getParam('t')) { $contenu = $UrlSet->asXml(); $cpt_url = 1; $UrlSet = null; // Création du fichier Sitemap compressé $fichier_nom = 'sitemap'.$cpt_fichier++.'.xml'; $compression = false; if (!is_numeric($this->getParam('t'))) { $compression = true; $fichier_nom .= '.gz'; } $fichier = $this->getIni('log_chemin').$fichier_nom; $this->creerFichier($fichier, $contenu, $compression); // Création du XML d'index des Sitemap si nécessaire if (is_null($SiteMapIndex)) { $SiteMapIndex = new SimpleXMLElement($xmlstr_sitemapindex); } // Ajout du fichier Sitemap à l'index $SiteMap = $SiteMapIndex->addChild('sitemap'); $SiteMap->addChild('loc', $url_site.$fichier_nom); $SiteMap->addChild('lastmod', date('c', time())); } if ($i == (int)$this->getParam('t')) {break;} } } } // En cas de test... if ($i == (int)$this->getParam('t')) {break;} } echo "\n"; // Création du fichier d'index des Sitemap if (is_object($SiteMapIndex)) { $index_contenu = $SiteMapIndex->asXml(); $index_fichier_nom = 'sitemap_index.xml'; $index_fichier = $this->getIni('log_chemin').$index_fichier_nom; $this->creerFichier($index_fichier, $index_contenu); } } } } ?>