par
magikbibi » 07 juin 2010, 19:54
Aller hop, j'ai remonté mes manches et voici un petit script (à améliorer je le conçois) qui génère un fichier sitemap.xml normalement aux normes (je demande confirmation quand meme sur ce coup) :
Ce script nécessite auparavant "simple_html_dom.php" que l'on peu trouver ici :
http://simplehtmldom.sourceforge.net/
<html>
<head></head>
<body>
<?php
include("topdir.php");
include($topdir."/include/fonctions/simplehtmldom/simple_html_dom.php");
$V_SITE_WEB = "http://www.monsiteWeb.com/";
$V_FREQUENCE = "monthly";
function create_site_map($V_LINK,$TAB_LINK)
{
global $TAB_LINK;
global $V_SITE_WEB;
/* Mettre à 1 la page sur laquelle on se trouve pour ne pas la retraiter plus tard */
if(array_key_exists($V_LINK,$TAB_LINK))
{
$V_TAB_LINK_SPLIT = split("::", $TAB_LINK[$V_LINK]);
if($V_TAB_LINK_SPLIT[1] != 1)
{
$TAB_LINK[$V_LINK] = $V_LINK."::1";
}
}
/* Aller SCANNER LA PAGE en HTML */
$post_data = "id=93117887&l=fr";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $V_SITE_WEB.$V_LINK);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($curl);
curl_close($curl);
//echo $page;
/* RECHERCHE DES BALISES <a> */
$html = new simple_html_dom();
$html->load($page);
foreach($html->find("<a") as $element)
{
if(!mb_eregi("www",$element->href) AND !mb_eregi("http",$element->href) AND !mb_eregi("mailto",$element->href) AND substr($element->href, -4, 1)!=".")
{
// Si les liens sont Interne (ne contiennent ni http:// ni www)
$V_LINK_DOM = $element->href;
$V_LINK_DOM = str_replace("../","",$V_LINK_DOM);
$V_LINK_DOM = str_replace("./","",$V_LINK_DOM);
if(!array_key_exists($V_LINK_DOM,$TAB_LINK))
{
$TAB_LINK[$V_LINK_DOM] = $V_LINK_DOM."::0";
}
}
}
/* Faire tourner le tableau des liens et ne prendre en compte uniquement ceux qui sont à 0*/
foreach($TAB_LINK as $TAB_LINK_bis)
{
$V_TAB_LINK_SPLIT = split("::", $TAB_LINK_bis);
if($V_TAB_LINK_SPLIT[1] == 0)
{
//echo $V_TAB_LINK_SPLIT[0];
create_site_map( $V_TAB_LINK_SPLIT[0],$TAB_LINK);
}
}
}
$TAB_LINK["index.php"] = "index.php::1";
create_site_map("index.php",$TAB_LINK);
//print_r($TAB_LINK);
/* CREATION DU FICHIER XML */
$CONTENU_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.9\"\n
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n\n";
foreach($TAB_LINK as $TAB_LINK_bis)
{
$V_TAB_LINK_SPLIT = split("::", $TAB_LINK_bis);
$CONTENU_XML.="<url>\n";
$CONTENU_XML.="<loc>".$V_SITE_WEB.htmlspecialchars($V_TAB_LINK_SPLIT[0])."</loc>\n";
$CONTENU_XML.="<changefreq>".$V_FREQUENCE."</changefreq>\n";
$CONTENU_XML.="<priority>0.50</priority>\n";
$CONTENU_XML.="</url>\n\n";
}
$CONTENU_XML.= "</urlset>";
$V_Fichier_SITEMAP = $topdir."test/sitemap.xml";
touch($V_Fichier_SITEMAP);
$fp = fopen($V_Fichier_SITEMAP, "w");
if(fwrite($fp, utf8_encode($CONTENU_XML)))
{
echo("ok");
}
else
{
echo("ko");
}
fclose($fp);
?>
<body>
</html>
Aller hop, j'ai remonté mes manches et voici un petit script (à améliorer je le conçois) qui génère un fichier sitemap.xml normalement aux normes (je demande confirmation quand meme sur ce coup) :
Ce script nécessite auparavant "simple_html_dom.php" que l'on peu trouver ici : http://simplehtmldom.sourceforge.net/
[php]
<html>
<head></head>
<body>
<?php
include("topdir.php");
include($topdir."/include/fonctions/simplehtmldom/simple_html_dom.php");
$V_SITE_WEB = "http://www.monsiteWeb.com/";
$V_FREQUENCE = "monthly";
function create_site_map($V_LINK,$TAB_LINK)
{
global $TAB_LINK;
global $V_SITE_WEB;
/* Mettre à 1 la page sur laquelle on se trouve pour ne pas la retraiter plus tard */
if(array_key_exists($V_LINK,$TAB_LINK))
{
$V_TAB_LINK_SPLIT = split("::", $TAB_LINK[$V_LINK]);
if($V_TAB_LINK_SPLIT[1] != 1)
{
$TAB_LINK[$V_LINK] = $V_LINK."::1";
}
}
/* Aller SCANNER LA PAGE en HTML */
$post_data = "id=93117887&l=fr";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $V_SITE_WEB.$V_LINK);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($curl);
curl_close($curl);
//echo $page;
/* RECHERCHE DES BALISES <a> */
$html = new simple_html_dom();
$html->load($page);
foreach($html->find("<a") as $element)
{
if(!mb_eregi("www",$element->href) AND !mb_eregi("http",$element->href) AND !mb_eregi("mailto",$element->href) AND substr($element->href, -4, 1)!=".")
{
// Si les liens sont Interne (ne contiennent ni http:// ni www)
$V_LINK_DOM = $element->href;
$V_LINK_DOM = str_replace("../","",$V_LINK_DOM);
$V_LINK_DOM = str_replace("./","",$V_LINK_DOM);
if(!array_key_exists($V_LINK_DOM,$TAB_LINK))
{
$TAB_LINK[$V_LINK_DOM] = $V_LINK_DOM."::0";
}
}
}
/* Faire tourner le tableau des liens et ne prendre en compte uniquement ceux qui sont à 0*/
foreach($TAB_LINK as $TAB_LINK_bis)
{
$V_TAB_LINK_SPLIT = split("::", $TAB_LINK_bis);
if($V_TAB_LINK_SPLIT[1] == 0)
{
//echo $V_TAB_LINK_SPLIT[0];
create_site_map( $V_TAB_LINK_SPLIT[0],$TAB_LINK);
}
}
}
$TAB_LINK["index.php"] = "index.php::1";
create_site_map("index.php",$TAB_LINK);
//print_r($TAB_LINK);
/* CREATION DU FICHIER XML */
$CONTENU_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.9\"\n
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n\n";
foreach($TAB_LINK as $TAB_LINK_bis)
{
$V_TAB_LINK_SPLIT = split("::", $TAB_LINK_bis);
$CONTENU_XML.="<url>\n";
$CONTENU_XML.="<loc>".$V_SITE_WEB.htmlspecialchars($V_TAB_LINK_SPLIT[0])."</loc>\n";
$CONTENU_XML.="<changefreq>".$V_FREQUENCE."</changefreq>\n";
$CONTENU_XML.="<priority>0.50</priority>\n";
$CONTENU_XML.="</url>\n\n";
}
$CONTENU_XML.= "</urlset>";
$V_Fichier_SITEMAP = $topdir."test/sitemap.xml";
touch($V_Fichier_SITEMAP);
$fp = fopen($V_Fichier_SITEMAP, "w");
if(fwrite($fp, utf8_encode($CONTENU_XML)))
{
echo("ok");
}
else
{
echo("ko");
}
fclose($fp);
?>
<body>
</html>
[/php]