<!--#Include File="Include.asp"-->
<!--#Include File="../Class/Cls_Template.asp"--><%
'--------------------------------------
'Power By 580Web @2010-2014 f02
'URL:http://www.580Web.Cn/
'EMail:wsok85@qq.com
'QQ:253819801
'版权所有 未经允许不得去除本版权信息
'--------------------------------------

Call CheckAdminType("0,1",UType)
Call CheckAdminLimit(ULimit,"s_SiteMap",0)

Dim PageSuffix,PageCode
Dim CreateType,CreateHtml
PageSuffix=FullHtmlSuffix

Types=Clng(Request.QueryString("Type"))

Select Case Types
	Case 1
		Call CreatBox() '生成网站地图表单
	Case 2
		Call CreateDo() '生成网站地图
	Case Else
		Call FKFun.ShowErr("未发现功能项！",1)
End Select

'==========================================
'函 数 名：CreatBox()
'作    用：生成网站地图表单
'==========================================
Sub CreatBox()
%>
<div id="title">生成网站地图</div>
<div id="box">
	<table width="95%" id="t1" class="t" border="1" bordercolor="#CCCCCC" align="center" cellpadding="0" cellspacing="0">
		<tr>
			<td width="50%" height="30" align="center"><a href="javascript:void(0);" onClick="$('#htmlBox',parent.document.body).attr('src','SiteMap.asp?Type=2&Create=1');">生成百度地图</a></td>
			<td width="50%" align="center"><a href="javascript:void(0);" onClick="$('#htmlBox',parent.document.body).attr('src','SiteMap.asp?Type=2&Create=2');">生成谷歌地图</a></td>
		</tr>
	</table>
	<br />
	<table width="95%" border="1" bordercolor="#CCCCCC" align="center" cellpadding="0" cellspacing="0">
        <tr>
        	<td height="30" align="center">生成结果</td>
       	</tr>
        <tr>
            <td height="30"><iframe src="" id="htmlBox" width="540" height="200" frameborder="0" scrolling="auto"></iframe></td>
        </tr>
	</table>
</div>
<div id="bottom">
	<input type="button" onClick="dialogClose();" class="button" name="button" id="button" value="关 闭" />
</div>
<%
End Sub

'==========================================
'函 数 名：CreateDo()
'作    用：生成网站地图
'==========================================
Sub CreateDo()
	Dim mRs,c_Rs,cURL
	Dim mModelTemplate,PageTemplate,MenuDir,MenuTemplate
	Set FKTemplate=New Cls_Template
	Set mRs=Server.Createobject("Adodb.RecordSet")
    Set c_Rs=Server.Createobject("Adodb.RecordSet")

	Call cTop()
	
	'参数获取
	CreateType=Clng(Trim(Request.QueryString("Create")))
	
	If CreateType=1 Then
		CreateHtml="<?xml version=""1.0"" encoding=""UTF-8""?>"&vbLf
		CreateHtml=CreateHtml&"<urlset>"&vbLf
		CreateHtml=CreateHtml&"<url>"&vbLf
		CreateHtml=CreateHtml&"<loc>"&Fk_Site_Url&"</loc>"&vbLf
		CreateHtml=CreateHtml&"<lastmod>"&Date()&"</lastmod>"&vbLf
		CreateHtml=CreateHtml&"<changefreq>daily</changefreq>"&vbLf
		CreateHtml=CreateHtml&"<priority>1.0</priority>"&vbLf
		CreateHtml=CreateHtml&"</url>"&vbLf	
	ElseIf CreateType=2 Then
		CreateHtml="<?xml version=""1.0"" encoding=""UTF-8""?>"&vbLf
		CreateHtml=CreateHtml&"<urlset xmlns=""http://www.google.com/schemas/sitemap/0.84"">"&vbLf
		CreateHtml=CreateHtml&"<url>"&vbLf
		CreateHtml=CreateHtml&"<loc>"&Fk_Site_Url&"</loc>"&vbLf
		CreateHtml=CreateHtml&"</url>"&vbLf
	End If
	'生成栏目页
    Sqlstr="Select Fk_Module_Id,Fk_Module_Type,Fk_Module_Model,Fk_Module_FixedUrl,Fk_Module_Url,Fk_Module_LinkType,Fk_Module_PageSize,Fk_Module_Menu,Fk_Module_GBookReply,Fk_Module_Template From [Fk_Module] Where Fk_Module_State=1 Order By Fk_Module_Id Asc"
    mRs.Open Sqlstr,Conn,1,1
    If Not mRs.Eof Then
        While Not mRs.Eof
            If (mRs("Fk_Module_LinkType")=1 And mRs("Fk_Module_Type")=4) Or Instr(",0,2,",","&mRs("Fk_Module_Type")&",")>0 Then
                cURL=FKTemplate.GetUrl(FullSiteDir,"",mRs("Fk_Module_Url")&"Index","",PageSuffix,1,mRs("Fk_Module_Id"),mRs("Fk_Module_FixedUrl"))
                '生成
                cURL=Replace(cURL,"Index"&PageSuffix,"")
                cURL=Server.HTMLEncode(Replace(Replace(Fk_Site_Url&CURL,"//","/"),"http:/","http://"))
                CreateHtml=CreateHtml&"<url>"&vbLf
                CreateHtml=CreateHtml&"<loc>"&cURL&"</loc>"&vbLf
                If CreateType=1 Then
                    CreateHtml=CreateHtml&"<lastmod>"&Date()&"</lastmod>"&vbLf
                    CreateHtml=CreateHtml&"<changefreq>daily</changefreq>"&vbLf
                    CreateHtml=CreateHtml&"<priority>0.7</priority>"&vbLf
                End If
                CreateHtml=CreateHtml&"</url>"&vbLf
            ElseIf Instr(",1,3,",","&mRs("Fk_Module_Type")&",")>0 Then
                '读取每页数量
                PageSizes=Fk_Site_PageSize
                If mRs("Fk_Module_PageSize")>0 Then
                    PageSizes=mRs("Fk_Module_PageSize")
                End If
                 
                '读取模型绑定模板
                If mRs("Fk_Module_Type")=1 Then
                    Sqlstr="Select Fk_Model_Template From [Fk_Model] Where Fk_Model_Id="& mRs("Fk_Module_Model")&""
                    c_Rs.Open Sqlstr,Conn,1,1
                    If Not c_Rs.Eof Then
                        mModelTemplate=c_Rs("Fk_Model_Template")
                    Else
                        mModelTemplate=""
                    End If
                    c_Rs.Close
                Else
                    mModelTemplate=""
                End If
 
                If mRs("Fk_Module_Type")=1 Then
                    PageTemplate="viewlist"
                ElseIf mRs("Fk_Module_Type")=3 Then
                    PageTemplate="gbook"
                End If
                 
                If mRs("Fk_Module_Template")<>"" Then
                    PageTemplate=mRs("Fk_Module_Template")
                ElseIf mModelTemplate<>"" Then
                    PageTemplate=mModelTemplate
                End If
                                 
                '菜单信息读取
                Sqlstr="Select Fk_Menu_Dir,Fk_Menu_Template From [Fk_Menu] Where Fk_Menu_Id=" & mRs("Fk_Module_Menu")
                c_Rs.Open Sqlstr,Conn,1,1
                If Not c_Rs.Eof Then
                    MenuDir=c_Rs("Fk_Menu_Dir")
                    MenuTemplate=c_Rs("Fk_Menu_Template")
                Else
                    c_Rs.Close
                    Call FKFun.ShowErr("error:菜单不存在！",0)
                End If
                c_Rs.Close
                 
                '目录模板方案_默认模板组合
                If MenuTemplate<>"" Then
                    If Instr(DisTemplate,","&PageTemplate&",")>0 Then
                        PageTemplate=MenuTemplate&"/"&PageTemplate
                    End If
                End If
                 
                '模板标签解析
                PageCode=FKTemplate.GetTemplate(PageTemplate)
                 
                PageCounts=1
                '读取页数
                If Instr(PageCode,"{$ModulePageCode(")>0 Then
                    '内容模块
                    If mRs("Fk_Module_Type")=1 Then
                        Sqlstr="Select Fk_View_Id From [Fk_View] Where Fk_View_Show=1 And Fk_View_Module="&mRs("Fk_Module_Id")&""
                        c_Rs.Open Sqlstr,Conn,1,1
                        c_Rs.PageSize=PageSizes
                        If c_Rs.PageCount>0 Then
                            PageCounts=c_Rs.PageCount
                        End If
                        c_Rs.Close
                    '留言模块
                    ElseIf mRs("Fk_Module_Type")=3 And mRs("Fk_Module_GBookReply")<>3 Then
                        Sqlstr="Select Fk_GBook_Id From [Fk_GBook] Where Fk_GBook_Module="&mRs("Fk_Module_Id")&""
                        If mRs("Fk_Module_GBookReply")=1 Then
                            Sqlstr=Sqlstr&" And Fk_GBook_ReIp<>''"
                        ElseIf mRs("Fk_Module_GBookReply")=2 Then
                            Sqlstr=Sqlstr&" And (Fk_GBook_ReIp='' Or Fk_GBook_ReIp Is Null)"
                        End If
                        c_Rs.Open Sqlstr,Conn,1,1
                        c_Rs.PageSize=PageSizes
                        If c_Rs.PageCount>0 Then
                            PageCounts=c_Rs.PageCount
                        End If
                        c_Rs.Close
                    Else
                        PageCounts=1
                    End If
                    '循环生成
                    For PageNow=1 To PageCounts
                        '链接地址获取
                        If mRs("Fk_Module_FixedUrl")<>"" Then '绝对链接
                            If Instr(mRs("Fk_Module_FixedUrl"),".")>0 Then '绝对链接带后缀
                                cURL=FKTemplate.GetUrl(FullSiteDir,"","","",PageSuffix,1,mRs("Fk_Module_Id"),mRs("Fk_Module_FixedUrl"))
                            Else '绝对链接不带后缀
                                If PageNow=1 Then
                                    cURL=FKTemplate.GetUrl(FullSiteDir,"","","",PageSuffix,1,mRs("Fk_Module_Id"),mRs("Fk_Module_FixedUrl")&"Index")
                                Else
                                    cURL=FKTemplate.GetUrl(FullSiteDir,"","","",PageSuffix,1,mRs("Fk_Module_Id"),mRs("Fk_Module_FixedUrl")&"Index_"&PageNow)
                                End If
                            End If
                        Else '非绝对链接
                            If PageNow=1 Then
                                cURL=FKTemplate.GetUrl(FullSiteDir,"",mRs("Fk_Module_Url")&"Index","",PageSuffix,1,mRs("Fk_Module_Id"),"")
                            Else
                                cURL=FKTemplate.GetUrl(FullSiteDir,"",mRs("Fk_Module_Url")&"Index_"&PageNow,"",PageSuffix,1,mRs("Fk_Module_Id"),"")
                            End If
                        End If
                        '生成
                        cURL=Replace(cURL,"Index"&PageSuffix,"")
                        cURL=Server.HTMLEncode(Replace(Replace(Fk_Site_Url&CURL,"//","/"),"http:/","http://"))
                        CreateHtml=CreateHtml&"<url>"&vbLf
                        CreateHtml=CreateHtml&"<loc>"&cURL&"</loc>"&vbLf
                        If CreateType=1 Then
                            CreateHtml=CreateHtml&"<lastmod>"&Date()&"</lastmod>"&vbLf
                            CreateHtml=CreateHtml&"<changefreq>daily</changefreq>"&vbLf
                            CreateHtml=CreateHtml&"<priority>0.7</priority>"&vbLf
                        End If
                        CreateHtml=CreateHtml&"</url>"&vbLf
                    Next
                End If
            End If
            mRs.MoveNext
        Wend
    End If
    mRs.Close
	'生成内容页
	Sqlstr="Select Fk_View_Id,Fk_View_FixedUrl,Fk_View_Url,Fk_Module_Url,Fk_View_Time From [Fk_ViewList] Where Fk_View_Show=1 And Fk_Module_State=1 And (Fk_View_Link='' Or Fk_View_Link Is Null) Order By Fk_View_Id Asc"
	Rs.Open Sqlstr,Conn,1,1
	If Not Rs.Eof Then
		While Not Rs.Eof
			'链接地址获取
			cURL=FKTemplate.GetUrl(FullSiteDir,"",Rs("Fk_Module_Url"),Rs("Fk_View_Url"),PageSuffix,2,Rs("Fk_View_Id"),Rs("Fk_View_FixedUrl"))
			'生成
			cURL=Server.HTMLEncode(Replace(Replace(Fk_Site_Url&CURL,"//","/"),"http:/","http://"))
			CreateHtml=CreateHtml&"<url>"&vbLf
			CreateHtml=CreateHtml&"<loc>"&cURL&"</loc>"&vbLf
			If CreateType=1 Then
				CreateHtml=CreateHtml&"<lastmod>"&Year(Rs("Fk_View_Time"))&"-"&Month(Rs("Fk_View_Time"))&"-"&Day(Rs("Fk_View_Time"))&"</lastmod>"&vbLf
				CreateHtml=CreateHtml&"<changefreq>weekly</changefreq>"&vbLf
				CreateHtml=CreateHtml&"<priority>0.6</priority>"&vbLf
			End If
			CreateHtml=CreateHtml&"</url>"&vbLf
			Rs.MoveNext
		Wend
	End If
	Rs.Close
	Sqlstr="Select Fk_Subject_Id,Fk_Subject_Name,Fk_Subject_Dir,Fk_Subject_Template From [Fk_Subject] Order By Fk_Subject_Id Asc"
	Rs.Open Sqlstr,Conn,1,1
	If Not Rs.Eof Then
		While Not Rs.Eof			
			'链接地址获取
			cURL=FKTemplate.GetUrl(FullSiteDir,"","Subject/"&Rs("Fk_Subject_Dir")&"/Index","",PageSuffix,3,Rs("Fk_Subject_Id"),"")
			'生成
			cURL=Replace(cURL,"Index"&PageSuffix,"")
			cURL=Server.HTMLEncode(Replace(Replace(Fk_Site_Url&CURL,"//","/"),"http:/","http://"))
			CreateHtml=CreateHtml&"<url>"&vbLf
			CreateHtml=CreateHtml&"<loc>"&cURL&"</loc>"&vbLf
			If CreateType=1 Then
				CreateHtml=CreateHtml&"<lastmod>"&Date()&"</lastmod>"&vbLf
				CreateHtml=CreateHtml&"<changefreq>daily</changefreq>"&vbLf
				CreateHtml=CreateHtml&"<priority>0.7</priority>"&vbLf
			End If
			CreateHtml=CreateHtml&"</url>"&vbLf
			Rs.MoveNext
		Wend
	End If
	Rs.Close
	CreateHtml=CreateHtml&"</urlset>"&vbLf
	
	If CreateType=1 Then
		Call FKFun.CreateHtml("../baidu.xml",CreateHtml)
		Response.Write("<p><a href=""../baidu.xml"" target=""_blank"">baidu.xml</a></p>")
	ElseIf CreateType=2 Then
		Call FKFun.CreateHtml("../google.xml",CreateHtml)
		Response.Write("<p><a href=""../google.xml"" target=""_blank"">google.xml</a></p>")
	End If
		
	Call cEnd()
End Sub

'==========================================
'函 数 名：cTop()
'作    用：生成页格式规范
'==========================================
Function cTop()
%>
<html>
<title><%=SystemName%> <%=SystemVersion%></title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
* {margin:0;padding:0;}
body,td,th {font-size:12px;}
body {margin:10px;}
a {font-size:12px;color:#000;text-decoration:none;}
a:visited {color:#000;text-decoration:none;}
a:hover {color:#000;text-decoration:none;}
a:active {color:#000;text-decoration:none;}
p {line-height:20px;}
</style>
</head>
<body>
<%
End Function

'==========================================
'函 数 名：cEnd()
'作    用：生成结束
'==========================================
Function cEnd()
%>
<p style='color:red;'>生成操作完成！</p>
</body>
</html>
<%
	Call FKFun.PageEnd()
End Function

Call FKFun.PageEnd()
%>
