火端搜索v2.1自行二开加入xml伪静态

 火端搜索v2.1自行二开加入xml伪静态,根据词库包生成xml,说干就干

首先在index.php文件中找到:

  

else if(preg_match("/sitemap/(.+?).html/", $rewrite, $match)){
		$_GET['name']=$match[1];
		include('inc/sitemap.php');
	    exit;
	}

  在下面再添加以下代码:

else if(preg_match("/sitemap/(.+?).xml/", $rewrite, $match)){
		$type=='.xml';
		$_GET['name']=$match[1];
		include('inc/sitemapxml.php');
	    exit;
	}

  然后在/inc/下目录新建sitemapxml.php文件,如:

  

<?php
if(isset($_GET['name'])){
	$key = $_GET['name']; 
	$type='.xml';
	$dirname = ROOT_PATH.'/data/sitemap/';
	$file = $dirname.$key.'.txt';
	if(!is_file($file)){
		$file = $dirname.iconv("utf-8","gb2312",urldecode($key)).'.txt';
	}
	if($type=='.xml'){

		header("Content-type: text/xml"); 
		echo '<?xml version="1.0" encoding="utf-8"?>';
        echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
		
		 if(is_file($file)){
			 $worddata = file_get_contents($file);
			 if(strpos($worddata,"
")>-1){
			    $words = explode("
",$worddata);
			 }else{
				  $words = explode("
",$worddata);
			 }
			
			  foreach($words as $k=>$v){
                if(strlen($v)>1){
				   echo '<url><loc>'.huoduansourl($v).'</loc></url>'."
";
				}
			 }
		 }else{
			 echo 'Sitemap相关文件不存在';
		 }
		
		echo '</urlset>';
	}else{
		if(is_file($file)){
			 $worddata = file_get_contents($file);
			 if(strpos($worddata,"
")>-1){
			    $words = explode("
",$worddata);
			 }else{
				  $words = explode("
",$worddata);
			 }
			
			  foreach($words as $k=>$v){
                 if(strlen($v)>1){
				    echo huoduansourl($v)."
";
				 }
			 }
		 }else{
			 echo 'Sitemap相关文件不存在';
		 }
	}
	exit;
}
if(isset($_GET['name'])){
	$name = htmlspecialchars($_GET['name']); 
	if(substr($name,0,1)=='.' ||  substr($name,0,1)=='/'){
		echo 'Name参数不合法';exit;
	}
	$nametitle = $name.'相关词';
}
if(isset($_GET['p'])){
	$p=htmlspecialchars($_GET['p']);
}else{
	$p=1;
}
?>

  这样就完美了,演示地图:http://www.myjiancai.net/so/sitemap/fangzhukou.html 而他的地图版本是:http://www.myjiancai.net/so/sitemap/fangzhukou.xml

千行代码,Bug何处藏。 纵使上线又怎样,朝令改,夕断肠。
原文地址:https://www.cnblogs.com/68xi/p/14983677.html