|
|
PHP 代码:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN"><head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <meta name="generator" content="HAPedit 3.1" />
- <style type="text/css">
- body {
- text-align: left;
- background-color: #FFFFFF;
- }
- .center {
- text-align: center;
- }
- .italic {
- font-style: italic;
- }
- </style>
- <title>Google网站地图生成器</title>
- </head>
- <body id="top">
- <h2 class="center">自动生成符合GOOGLE要求的网站地图文件</h2>
- <p class="center">Copyright <a href="http://topflood.free.fr" target ="_blank" title="原作者站">Top flood</a><br />
- 原作者 : <br />
- Kloh : <a href="http://timesplittersgames.free.fr" target="_blank" title ="作者1">TimeSplitters' Games</a>; ImmortalPC :<a href="http: //immortalpc.free.fr" target="_blank" title="作者2">Immortal-PC< /a><br /><br />
- <pre>
- 注:<br />
- 1.请把本程序放入网站根目录执行<br />
- 2.程序执行前请修改如下参数(或常量)以符合你网站要求:<br />
- LIMITLIENPARFICHIER
- LIMITLIENINDEXE
- $ExtensionsAutorises
- $DossiersInterdits
- $FichiersInterdits
- <br />
- 3.程序将把列表写入多个xml文件(如果你网页比较多的话)<br />
- 4.请在根目录下建立文件夹sitemap,并保证可写。sitemap(x).xml文件将写入这个目录<br />
- 5.sitemap生成之后请至<a href="" title="submit sitemap">http: //www.google.com/webmasters/sitemaps/</a> 提交给Google<br />
- </pre>
- </p>
- <h2>URL列表(将写入sitemap)中。。。</h2>
- <?php
- define('LIMITLIENPARFICHIER',1000); //每个文件里最大URL数
- define('LIMITLIENINDEXE',50000); //最大URL数(总数)
- $racine= 'http://'.$_SERVER['HTTP_HOST'];
- $compressionGZ = false;
- $Goption=0;
- $ExtensionsAutorises= array('php','php3','html','htm'); //将被写入SITEMAP的文件类型
- $DossiersInterdits = array('includes','modules','sessions','images','pnadodb','webanalyse','_flood','javascript','language','parameters','smileys','themes','_streifer'); //忽略的文件夹(不被列表,不被写入SITEMAP)
- $FichiersInterdits = array('config.php','config_i.php','streifer_forum.gif.php','xmlrpc.php','referer.php','config-old.php','test.php','admin.php','image.php','header.php','footer.php','error.php','confige.php','banners.php','pntables.php','print.php','mainfile.php','modules.php','backend.php');//忽略的文件(不被写入SITEMAP)
- $myfiles=GetDirContents('.');
- function Dossier_Autoris($DossierCourant){
- global $DossiersInterdits;
- return Est_Autoris($DossierCourant, $DossiersInterdits);
- }
- function Fichier_Autoris($FichierCourant){
- global $FichiersInterdits;
- return Est_Autoris($FichierCourant, $FichiersInterdits);
- }
- function Extension_Autoris($ExtensionCourante){
- global $ExtensionsAutorises;
- return !Est_Autoris($ExtensionCourante,$ExtensionsAutorises);
- }
- function Est_Autoris($DossierCourant,$Interdits){
- global $Goption;
- $drapeau = true;
- while ($drapeau && list(,$Dossier)=each($Interdits) ){
- if ( ComparaisonFichier($DossierCourant,$Dossier,$Goption))$drapeau = false;
- }
- reset($Interdits);
- return $drapeau;
- }
- function ComparaisonFichier($DossierCourant,$Dossier,$option=0){
- switch ($option){
- case 0:
- return ($DossierCourant == $Dossier);
- break;
- case 1:
- $pos = strpos($mystring, $findme);
- if ($pos === false) {
- return false;
- } else {
- return true;
- }
- break;
- case 2:
- return ereg($Dossier,$DossierCourant);
- break;
- }
- }
- function getextension($fichier){
- $bouts = explode('.', $fichier);
- return array_pop($bouts);
- }
- function GetDirContents($dir){
- global $racine;
- $i=0;
- ini_set('max_execution_time',10);
- if (!is_dir($dir)){die ('PROBLEME: '.$dir.'!');}
- if ($root=@opendir($dir)){
- while ($file=readdir($root)){
- if($file=='.' || $file=='..'){continue;}
- if(is_dir($dir.'/'.$file) && Dossier_Autoris($file)){
- if(!IsSet($files)){$files = NULL;}
- $files=array_merge($files,GetDirContents($dir.'/'.$file));
- }else{
- $extension=getextension($file);
- if (Extension_Autoris($extension) && Fichier_Autoris($file)){
- echo '<strong>',$dir,'</strong>/',htmlentities($file),'<br />',"\r\n";
- $files[$i]['lien']=utf8_encode($racine.substr($dir,1).'/'.$file);
- $modi_fich=filemtime($dir.'/'.$file);
- $files[$i]['date']=date('Y-m-d', $modi_fich);
- $i++;
- }
- }
- }
- }
- if(!IsSet($files)){$files = NULL;}
- return $files;
- }
- $nbliens=count($myfiles);
- echo '<span class="italic">'.$nbliens.' 行网址将被写入sitemap文件.</span><br />',"\r\n";
- if ($nbliens>LIMITLIENPARFICHIER){
- // utilisation de la norme pour les sites souhaitant rfrencs plus de 1000 liens
- // un fichier sitemap à gnrer en plus
- $numfichier=1;
- echo '<h2>分步生成文件 sitemapXX.xml...</h2>',"\r\n";
- }else {
- $numfichier='';
- echo '<h2>sitemap.xml文件生成完毕...</h2>',"\r\n";
- }
- if ($compressionGZ)
- {
- $open='gzopen';
- $write='gzwrite';
- $close='gzclose';
- $GZ='.gz';
- } else
- {
- $open='fopen';
- $write='fwrite';
- $close='fclose';
- $GZ='';
- }
- $CurLiens=0;
- while ($CurLiens<$nbliens && $CurLiens<LIMITLIENINDEXE )
- {
- if ($fp = $open('./sitemap/sitemap'.$numfichier.'.xml'.$GZ, 'w')){
- $write($fp,'<?xml version="1.0" encoding="UTF-8"?>'."\r\n");
- $write($fp,'<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'."\r\n");
- $Limite = $CurLiens + LIMITLIENPARFICHIER;
- while ($CurLiens< $Limite && $CurLiens<LIMITLIENINDEXE && list(,$file)=each($myfiles))
- {
- $write($fp,'<url> '."\r\n".' <loc>'.$file['lien'].'</loc> '."\r\n \r\n");
- $write($fp,"\t\t".'<lastmod>'.$file['date'].'</lastmod>'."\n");
- $write($fp,'<changefreq>daily</changefreq>');
- $write($fp,'<priority>0.8</priority></url>');
- $CurLiens ++;
- }
- $write($fp, '</urlset>');
- $close($fp);
- echo '<a href="./sitemap/sitemap'.$numfichier.'.xml'.$GZ.'" target="_blank">生成文件 sitemap'.$numfichier.'.xml'.$GZ.'</a><br />',"\r\n";
- }else{
- echo 'sitemap'.$numfichier.'.xml',"\r\n"
- ,'<br /><br /><textarea rows="30" cols="100">',"\r\n"
- ,'<?xml version="1.0" encoding="UTF-8"?>',"\r\n"
- ,'<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">',"\r\n";
- $Limite = $CurLiens + LIMITLIENPARFICHIER;
- while ($CurLiens< $Limite && $CurLiens<LIMITLIENINDEXE && list(,$file)=each($myfiles))
- {
- echo '<url> '."\r\n".' <loc>'.$file['lien'].'</loc> '."\r\n ";
- echo '<lastmod>'.$file['date'].'</lastmod>'."\r\n";
- echo '<changefreq>monthly</changefreq>'."\r\n";
- echo '<priority>0.5</priority></url>'."\r\n";
- $CurLiens ++;
- }
- echo '</urlset></textarea><br />';
- }
- $numfichier++;
- }
- if ($numfichier!=1)
- {
- echo '<h2>写入 sitemap 主文件...</h2>';
- if ($fp = fopen('./sitemap/sitemap.xml', 'w+')){
- fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?>'."\r\n");
- fwrite($fp, '<sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">'."\r\n");
- $date=date('Y-m-d');
- for($k=1;$k<$numfichier;$k++)
- {
- fwrite($fp, '<sitemap>'."\r\n");
- fwrite($fp,'<loc>'.$racine.'/sitemap/sitemap'.$k.'.xml'.$GZ.'</loc>'."\r\n");
- fwrite($fp, '<lastmod>'.$date.'</lastmod>'."\r\n");
- fwrite($fp,'</sitemap>'."\r\n");
- }
- fwrite($fp, '</sitemapindex>'."\r\n");
- fclose($fp);
- echo '<a href="./sitemap/sitemap.xml" target="_blank">生成文件 sitemap.xml</a><br />',"\r\n";
- } else
- {
- echo '<br /><br /><textarea rows="30" cols="100">',"\r\n"
- ,'<?xml version="1.0" encoding="UTF-8"?>',"\r\n"
- ,'<sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">',"\r\n";
- $date=date("Y-m-d");
- for($k=1;$k<$numfichier;$k++)
- {
- echo '<sitemap>',"\r\n"
- ,'<loc>',$racine,'/sitemap/sitemap',$k,'.xml</loc>',"\r\n"
- ,'<lastmod>',$date,'</lastmod>',"\r\n"
- ,'</sitemap>',"\r\n";
- }
- echo '</sitemapindex>',"\r\n";
- }
- }
- ?>
- <span class="italic">全部生成完毕</span>
- <p class="center"><a href="#top" title="回到页面顶部">TOP</a></p>
- </body>
- </html>
复制代码 |
|