<?

//================== XMLÎÄ¼þ¸ñÊ½ ==================//
function sitemap($file_name) {
        global $part;
		if(strpos($file_name,'-index-')!=false)
		{
			$part = 0.7;
			$strxml = $file_name;
		}elseif(strpos($file_name,'index-')!=false)
		{
			$part = 0.8;
			$strxml = $file_name;
		}elseif(strpos($file_name,'-index')!=false)
		{
			$part = 0.8;
			$strxml = $file_name;
		}elseif(strpos($file_name,'index')!=false)
		{
			$part = 0.9;
			$strxml = str_replace('index.html','',$file_name);
		}else{
			$part = 0.6;
			$strxml = $file_name;
		}
		$strxml=htmlspecialchars(utf8_encode($strxml));
        $xmlstr.="   <url>\n";
        $xmlstr.="      <loc>".$strxml."</loc>\n";
        $xmlstr.="      <lastmod>".date("Y-m-d")."</lastmod>\n";
        $xmlstr.="       <changefreq>weekly</changefreq>\n";
        $xmlstr.="      <priority>".$part."</priority>\n";
        $xmlstr.="   </url>\n";
        return $xmlstr;
}

//================== »ñÈ¡Ä¿Â¼ÖÐÎÄ¼þÐÅÏ¢ ==================//
function fileinfo($dir_name) {
        global $dir_len,$part,$fp,$url;
        $dir = opendir($dir_name);
        while($file_name = readdir($dir)){
                if (($file_name != ".") && ($file_name != "..")) {
                        if(is_dir($dir_name.'/'.$file_name)){
                                fileinfo($dir_name.'/'.$file_name);
                        }else{
                                $pi=pathinfo($file_name);
                                if($pi["extension"]=="html"){
                                        @fwrite($fp, sitemap($url.substr($dir_name.'/'.$file_name,$dir_len)));
                                }
                        }
                }
        }
}
set_time_limit(0);
$url= 'http://'.$_SERVER['HTTP_HOST'].'/products';
$part=0.6;
$dir_root = $_SERVER['DOCUMENT_ROOT'];
$dir_name = $dir_root.'/products';
$dir_len=strlen($dir_name);
if(file_exists($dir_root."/feeds/sitemap.xml")) unlink($dir_root."/feeds/sitemap.xml");
$fp = fopen($dir_root."/feeds/sitemap.xml", 'w');
@flock($fp, 2);
@fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
@fwrite($fp, "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">\n");
@fwrite($fp, "   <url>\n");
@fwrite($fp, "      <loc>http://".$_SERVER['HTTP_HOST']."</loc>\n");
@fwrite($fp, "      <lastmod>".date("Y-m-d")."</lastmod>\n");
@fwrite($fp, "       <changefreq>weekly</changefreq>\n");
@fwrite($fp, "      <priority>1</priority>\n");
@fwrite($fp, "   </url>\n");
fileinfo($dir_name) ;
fwrite($fp, "</urlset>\n");
@fclose($fp);
echo 'finished! ';
?>