<?php
	//创建 xml 网站地图
	require_once('_approot.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/admin.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/style2.css" />
<?php	
	$timeflag=time();
	$profilename="../sitemap/sitemap".$timeflag.".xml";
	$profilename1="../sitemap.xml"; //sitemap.xml
	$ls=$_GET['ls'];
	
	if($ls=="clear"){
		$clearsql="delete  from ls_writefiles where enable=1 "; //22-2-24
		$writefile_query=$opendb->query($clearsql);
		echo "<br/>网站地图已清空，请 <a href='temp_index.php?ls=all' target='_blank'>生成整站</a> -> <a href='temp_index.php?ls=products&productsall=ok
' target='_blank'>生成产品页</a> -> <a href='ls_xmlsitmap.php' target='_blank'> 生成 sitemap.xml</a> ";exit;
	}
	$procontent='<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">';
	$procontent1=$procontent;
	$thishost=str_replace("www.","",str_replace("https://","",str_replace("http://","",$_SERVER["HTTP_HOST"]))); 
	$trimsql="delete from ls_writefiles where url not like '%".$thishost."%' and enable=1  ";//22-2-24
	$trimsql_query=$opendb->query($trimsql);
 
	$trimsql="update ls_writefiles set url='prolist.html' where url ='/prolist.html' "; //改错
	$trimsql_query=$opendb->query($trimsql);
	$trimsql="update ls_writefiles set url='welcome.html' where url ='/welcome.html' "; //改错
	$trimsql_query=$opendb->query($trimsql);


	$writefilesql="select * from ls_writefiles where enable=1 ";//22-2-24
	$writefile_query=$opendb->query($writefilesql);
	$allsiteurl=mysqli_num_rows($writefile_query);
	while($writefile_rows=mysqli_fetch_assoc($writefile_query)){
		  $procontent0='
<url>
<loc>'.$writefile_rows["url"].'</loc>
<lastmod>'.substr($writefile_rows["lastmod"],0,10).'T'.substr($writefile_rows["lastmod"],11).'+00:00</lastmod>
<changefreq>'.$writefile_rows["changefreq"].'</changefreq>
<priority>'.$writefile_rows["priority"].'</priority>
</url>
';
		if($writefile_rows['submited']==1) $procontent1.=$procontent0; else { $procontent.=$procontent0;$procontent1.=$procontent0;} //已发布、未发布 写入完整sitemap，否则写入新发布
	}
$procontent.="</urlset>";
$procontent1.="</urlset>";
$handle1   = fopen($profilename1,"w"); //打开完整sitemap
?>

<script language="JavaScript" src="js/ls.js"></script>
<title><?=$china?> - <?=$ls?></title>
<style>
button{ padding:5px 15px;}
input { font-size:14px;
    padding: 5px 15px;
    border-radius: 5px;
    border: #00c0ef 1px solid;
    cursor: pointer;
    background-color: #00c0ef;
    color: #fff;
</style>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
	<tr>
        <td height="18" style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc" style="font-size:16px;">网页生成</font></div>
				</td>
	</tr>
	<tr><td><br/>
<?php 	 
	   
	if (!fwrite ($handle1,$procontent1))
	{  //将信息写入文件
		  if($ls_debug)  echo "".$profilename1."失败！";
	} 
	else
	{
		  echo "<br/>已生成网站地图 <a href='".$profilename1."' target='_blank'>".$profilename1."</a>，共 $allsiteurl 条。 请上线后生成，本地没数据。";
		  echo "<br><br/><a href='".$_SERVER["HTTP_REFERER"]."'>返回</a>";
		fclose ($handle1); //关闭指针
     }

?>	
	</td>
	</tr>
	</table>
</body>
</html>