<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../admin_loginstate.php";
include "../../include/label.php";

$SelID=SafeRequest("SelID","get");

switch($SelID){
	case '1':
		$CNumber=SafeRequest("CNumber1","post");
		Span_BaiduMap($CNumber);
		break;
	case '2':
		$CNumber=SafeRequest("CNumber2","post");
		Span_GoogleMap($CNumber);
		break;
	case '3':
		$CNumber=SafeRequest("CNumber3","post");
		Span_RssMap($CNumber);
		break;
	}
function XmlURL($ID,$ClassID){
		$xmlurl=S_SiteDomain.LinkUrl("s_video",$ClassID,1,$ID);
		return $xmlurl;
	}	
function Span_BaiduMap($CNumber){
	global $db;
	if(!IsNum($CNumber)){$CNumber=100;}
	if(stristr(strtolower(S_SiteDomain),'http://')){
		$SiteDomain=S_SiteDomain;
		}
	else{
		$SiteDomain="http://".S_SiteDomain;
		}	
	$Content="<?xml version=\"1.0\" encoding=\"GBK\" ?>\r\n
					<document>\r\n
					<webSite>".$SiteDomain."</webSite>\r\n
					<webMaster>".S_SiteName."</webMaster>
					<updatePeri>1800</updatePeri>\r\n";	
	$sql="Select * from s_video order by S_ID desc limit ".$CNumber."";
	$result=$db->query($sql);
	if($result){
		while($row=$db->fetch_array($result)){
			$Content.="<item>\r\n
			<title>".xmlEscape($row['S_Name'])."</title>\r\n";
			$Content.="<link>".XmlURL($row['S_ID'],$row['S_ClassID'])."</link>\r\n";
			$Content.="<text>".xmlEscape(cnsubstr($row['S_Content'],200))."</text>\r\n";
			if(stristr(strtolower($row['S_Pic']),'http://')){
				$Content.="<image>".$row['S_Pic']."</image>\r\n";
				}
			else{
				$Content.= "<image>".$SiteDomain."/".S_Vimgfolder."/".$row['S_Pic']."</image>\r\n";
				}	
			$Content.="<keywords>".xmlEscape($row['S_Name'].",".$row['S_Author'])."</keywords>\r\n
							  <author>".S_SiteName."</author>\r\n
							  <source>".S_SiteName."</source>\r\n
							  <pubDate>".$row['S_AddTime']."</pubDate>\r\n
							  </item>\r\n";
			}
		$Content.="</document>\r\n";
		$Folder="baiduxml.xml";
		$Folder1=$Folder;
		echo "<font style=font-size:12pt;><a href=\"../../".$Folder1."\" target=\"_blank\">".S_SiteDomain.S_SitePath.$Folder1."</a> 生成完毕<br>";
	 	fwrite(fopen("../../".$Folder,"wb"),$Content);
		echo "<br/><a href=\"http://news.baidu.com/newsop.html\" target=\"_blank\">http://news.baidu.com/newsop.html</a>请通过提交</font>";
		
		}
	}
	

function Span_GoogleMap($CNumber){
	global $db;
	if(!IsNum($CNumber)){$CNumber=100;}
	if(stristr(strtolower(S_SiteDomain),'http://')){
		$SiteDomain=S_SiteDomain;
		}
	else{
		$SiteDomain="http://".S_SiteDomain;
		}	


	$Content="<?xml version=\"1.0\" encoding=\"GBK\" ?>\r\n
			   <urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">\r\n
			  	<url>\r\n
				<loc>".$SiteDomain."</loc>\r\n
				</url>\r\n";
	$sql="Select * from s_video order by S_ID desc limit ".$CNumber."";
	$result=$db->query($sql);
	if($result){
		while($row=$db->fetch_array($result)){
			$Content.="<url>\r\n
			<loc>".XmlURL($row['S_ID'],$row['S_ClassID'])." </loc>\r\n";
			$Content.="<lastmod>".date("Y-m-d",strtotime($row['S_AddTime']))."</lastmod>\r\n";
			$Content.="</url>";	
		}
	}

	$Content.="</urlset>\r\n";
	$Folder="googlexml.xml";
	echo "<font style=font-size:12pt;><a href=\"../../".$Folder."\" target=\"_blank\">".S_SiteDomain.S_SitePath.$Folder."</a> 生成完毕<br>";
	 fwrite(fopen("../../".$Folder,"wb"),$Content);
	echo "<br/><a href=\"http://www.google.com/webmasters/tools/\" target=\"_blank\">http://www.google.com/webmasters/tools/</a>请通过提交</font>";

}

function Span_RssMap($CNumber){
	global $db;
	if(!IsNum($CNumber)){$CNumber=100;}
	
	if(stristr(strtolower(S_SiteDomain),'http://')){
		$SiteDomain=S_SiteDomain;
		}
	else{
		$SiteDomain="http://".S_SiteDomain;
		}	
	$Content="<?xml version=\"1.0\" encoding=\"GBK\" ?>\r\n
				<rss version='2.0'\r\n>
				<channel>\r\n
				<title><![CDATA[".S_SiteName."]]></title>\r\n
				<description><![CDATA[".S_SiteName."]]></description>\r\n
				<link>/".$SiteDomain."</link>\r\n
				<language>zh-cn</language>\r\n
				<docs>".S_SiteName."</docs>\r\n
				<generator>Rss Powered By ".$SiteDomain."</generator>\r\n
				<image>\r\n
					<url>".$SiteDomain."/images/logo.gif</url>\r\n
				</image>\r\n";
	$sql="Select * from s_video order by S_ID desc limit ".$CNumber."";
	$result=$db->query($sql);
	if($result){
		while($row=$db->fetch_array($result)){
			$Content.="<item>\r\n
						<title><![CDATA[".xmlEscape($row["S_Name"])."]]></title>\r\n
						<link>".XmlURL($row['S_ID'],$row["S_ClassID"])."</link>\r\n
						<author>".xmlEscape($row["S_Author"])."</author>\r\n
						<pubDate>".$row['S_AddTime']."</pubDate>\r\n
						<description><![CDATA[".xmlEscape(cnsubstr($row['S_Content'],200))."]]></description>\r\n
					   </item>\r\n";
		}
	}
	$Content.="</channel></rss>\r\n";
	$Folder="rssxml.xml";
	 fwrite(fopen("../../".$Folder,"wb"),$Content);
	echo "<font style=font-size:12pt;><a href=\"../../".$Folder."\" target=\"_blank\">".S_SiteDomain.S_SitePath.$Folder."</a> 生成完毕<br>";
	echo "<br/>Rss文档全部生成完毕．．．</font>";
}

function xmlEscape($str){
	$str=ReplaceStr($str,"&","&amp;");
	$str=ReplaceStr($str,"'","&apos;");
	$str=ReplaceStr($str,'"',"&quot;");
	$str=ReplaceStr($str,">","&gt;");
	$str=ReplaceStr($str,"<","&lt;");
	return $str;
	}
?>