<%
'******************************************************************************
'本页功能：生成静态函数
'******************************************************************************

'*************************************************
'替换模板内容
'*************************************************
Function loadtemplate(FileName)
Dim TempHtml
'''处理用户标签
TempHtml = process_customtags(FileName)
loadtemplate = TempHtml
End Function


Function LoopTemplate(FileName)
Dim LoopHtml
'''处理用户标签
LoopHtml = LoopApp(FileName)
LoopHtml = IfApp(LoopHtml)
LoopTemplate = LoopHtml
End Function



'*************************************************
'替换变量
'*************************************************
Function GetAttribute(ByVal strAttribute, ByVal strTag)
Dim objRegEx, Matches
'建立正则表达式
Set objRegEx = New RegExp
'查找内容 (the attribute name followed by double quotes etc)  
objRegEx.Pattern = lCase(strAttribute) & "=""[0-9a-zA-Z]*"""
'忽略大小写
objRegEx.IgnoreCase = True
'全局查找
objRegEx.Global = True
'执行搜索
Set Matches = objRegEx.Execute(strTag)
'如有匹配的则返回值, 不然返回空值
if Matches.Count > 0 then
GetAttribute = Split(Matches(0).Value,"""")(1)
else
GetAttribute = ""
end if
'消毁对象
set Matches = nothing
set objRegEx = nothing
end function


'*************************************************
'替换变量
'*************************************************
Function Parsetag(ByVal strtag)
Dim arrResult, className, arrAttributes, sTemp, i, objclass
'如果标签是空的则退出函数
If Len(strtag) = 0 Then Exit Function
arrResult = Split(strtag, ":")
className = Split(arrResult(1), " ")(0)
Parsetag = strtag
Dim nClass_ID, strLen, nIsWhat, nShowTime, strStyle, strCLen,strModular
select Case className
Case "Index_Article_List"	
	nClass_ID = GetAttribute("Class_ID", strtag)
	strStyle = Int(GetAttribute("strStyle", strtag))
	nPageSize = GetAttribute("PageSize", strtag)
	strLen = Int(GetAttribute("strLen", strtag))
	nShowTime = Int(GetAttribute("ShowTime", strtag))
	Parsetag = Index_Article_List(nClass_ID,strStyle,nPageSize,strLen,nShowTime)	
Case "Index_Product_List"	
	nClass_ID = GetAttribute("Class_ID", strtag)
	strStyle = Int(GetAttribute("strStyle", strtag))
	nPageSize = GetAttribute("PageSize", strtag)
	strLen = Int(GetAttribute("strLen", strtag))
	nShowTime = Int(GetAttribute("ShowTime", strtag))
	Parsetag = Index_Product_List(nClass_ID,strStyle,nPageSize,strLen,nShowTime)
Case "Index_Case_List"	
	nClass_ID = GetAttribute("Class_ID", strtag)
	strStyle = Int(GetAttribute("strStyle", strtag))
	nPageSize = GetAttribute("PageSize", strtag)
	strLen = Int(GetAttribute("strLen", strtag))
	strCLen = Int(GetAttribute("strCLen", strtag))
	nShowTime = Int(GetAttribute("ShowTime", strtag))
	Parsetag = Index_Case_List(nClass_ID,strStyle,nPageSize,strLen,strCLen,nShowTime)
Case "Index_Page"
	nClass_ID = GetAttribute("Class_ID", strtag)
	strStyle = Int(GetAttribute("strStyle", strtag))
	strLen = Int(GetAttribute("strLen", strtag))
	Parsetag = Index_Page(nClass_ID,strStyle,strLen)
Case "Class_List"	
	nClass_ID = GetAttribute("Class_ID", strtag)
	strStyle = Int(GetAttribute("strStyle", strtag))
	strModular = Int(GetAttribute("strModular", strtag))
	strLen = Int(GetAttribute("strLen", strtag))
	nPageSize = Int(GetAttribute("PageSize", strtag))
	Parsetag = Class_List(nClass_ID,strStyle,strModular,nPageSize,strLen)
End select
End Function

Function Dream_Menu(ModularID)

set rsMenu = Server.CreateObject("ADODB.Recordset") 
sqlMenu="select * from Dream_Modular order by id asc"
rsMenu.open sqlMenu,Conn,1,1 
if ModularID = 0 then
DreamMenuStr = "<li class=""a1""><a href=""index.html"">首页</a></li>"
else
DreamMenuStr = "<li><a href=""index.html"">首页</a></li>" 
end if
do while not rsMenu.eof
if rsMenu("id")=ModularID then
DreamMenuStr = DreamMenuStr&"<li><img src=""images/d_003.jpg""></li><li class=""a1""><a href="""&rsMenu("Dream_HtmlName")&".html"">"&rsMenu("Dream_Names")&"</a></li>"
else
DreamMenuStr = DreamMenuStr&"<li><img src=""images/d_003.jpg""></li><li><a href="""&rsMenu("Dream_HtmlName")&".html"">"&rsMenu("Dream_Names")&"</a></li>"
end if
rsMenu.movenext
loop
rsMenu.close
Set rsMenu = Nothing

Dream_Menu = DreamMenuStr
End Function


'==============================
'【功能】处理自定义标签
'==============================
Function process_customtags(ByVal sContent)
Dim objRegEx, Match, Matches
'建立正则表达式
Set objRegEx = New RegExp
'查找内容
objRegEx.Pattern = "{DreamTag:.*/}"
'忽略大小写
objRegEx.IgnoreCase = True
'全局查找
objRegEx.Global = True
Set Matches = objRegEx.Execute(sContent)
'循环已发现的匹配
For Each Match in Matches
sContent = Replace(sContent, Match.Value, Parsetag(Match.Value))
response.Write Match.Value
response.End()
Next
'消毁对象
Set Matches = Nothing
Set objRegEx = Nothing
'返回值
process_customtags = sContent
End Function




'==============================
'【功能】处理系统标签
'==============================
Function SysLabel(ByVal sContent,ByVal Pattern)
	Dim objRegEx, Match, Matches
	Set objRegEx = New RegExp
	objRegEx.Pattern = "{"&Pattern&":(.+?)}"
	objRegEx.IgnoreCase = True
	objRegEx.Global = True
	Set Matches = objRegEx.Execute(sContent)	
	For Each Match in Matches	
	Loopstrstr=""
	set rshtml=server.CreateObject("adodb.recordset")	
	sqlhtml="select * from Dream_Label where Dream_Title='"&Match.SubMatches(0)&"'"
	rshtml.open sqlhtml,conn,1,3
	if not rshtml.eof then
	Loopstrstr=rshtml("Dream_Content")
	end if
	rshtml.close
	set rshtml=nothing
	sContent = Replace(sContent,Match.Value,Loopstrstr)
	Next		
	Set Matches = Nothing
	Set objRegEx = Nothing
	SysLabel = sContent
End Function

'==============================
'【功能】处理循环标签
'==============================
Function LoopApp(ByVal sContent)
	Dim objRegEx, Match, Matches
	'建立正则表达式
	Set objRegEx = New RegExp
	'查找内容
	objRegEx.Pattern = "<!--(.+?):\{(.+?)\}-->([\s\S]*?)<!--\1-->"
	'忽略大小写
	objRegEx.IgnoreCase = True
	'全局查找
	objRegEx.Global = True
	Set Matches = objRegEx.Execute(sContent)
	'循环已发现的匹配
	For Each Match in Matches
	'sContent = Replace(sContent, Match.Value, Parsetag(Match.Value))
	TagLabs = Match.SubMatches(0)
	Tagsstr = Match.SubMatches(1)
	Loopstr = Match.SubMatches(2)
	Loopstrstr=""
	set rshtml=server.CreateObject("adodb.recordset")
	sqlhtml="select"
	Dream_Row = GetAttr(Tagsstr,"row",True)
	Dream_Style = GetAttr(Tagsstr,"type",True)
	Dream_Key = GetAttr(Tagsstr,"key",True)
	Dream_From = GetAttr(Tagsstr,"from",True)
	Dream_Show = GetAttr(Tagsstr,"Show",True)
	Dream_Elite = GetAttr(Tagsstr,"elite",True)
	Dream_ClassID = GetAttr(Tagsstr,"cid",True)
	Dream_ModularID = GetAttr(Tagsstr,"modular",True)
	Dream_ID = GetAttr(Tagsstr,"id",True)
	Dream_Page = GetAttr(Tagsstr,"page",True)
	Dream_Order = Replace(GetAttr(Tagsstr,"order",True),"|"," ")
	Dream_Nav = GetAttr(Tagsstr,"nav",True)
	Dream_SubNavCss = GetAttr(Tagsstr,"subnavcss",True)
	Dream_SubNavLoop = GetAttr(Tagsstr,"subnavloop",False)
	if GetAttr(Tagsstr,"subnavdiv",True) <> "" then
	strdiv = split(GetAttr(Tagsstr,"subnavdiv",True),"|")	
	Dream_SubNavDiv=strdiv(0)
	Dream_SubNavDivClass=strdiv(1)
	end if
	
	if Dream_Order="" then Dream_Order="id desc"
	if Dream_Style="" then Dream_Style=0
	if Dream_Show="" then Dream_Show=1
	if Dream_Elite="" then Dream_Elite=0
	if Dream_ClassID="" then Dream_ClassID=0
	if Dream_ID="" then Dream_ID=0
	if Dream_ModularID="" then Dream_ModularID=0	
	
	if Dream_Row>0 and Dream_Page="" then sqlhtml = sqlhtml&" top "&Dream_Row&"" '显示条数
	if Dream_From<>"" then sqlhtml = sqlhtml&" * from Dream_"&Dream_From&" where id<>0" '设置查询的表
	if Dream_ClassID<>0 and Dream_Nav<>"yes" then sqlhtml = sqlhtml&" and Dream_ClassID in (select id from Dream_Class where Dream_ClassID in ("&Dream_ClassID&") or id in ("&Dream_ClassID&"))" '查询所属类别
	if Dream_Elite=1 then sqlhtml = sqlhtml&" and Dream_Elite=true"
	if Dream_Key<>"" then sqlhtml = sqlhtml&" and Dream_Title like '%"&Dream_Key&"%'" 
	if Dream_ClassID=0 and Dream_Nav="yes"  then sqlhtml = sqlhtml&" and Dream_ClassID=0" '侧栏分类
	if Dream_ModularID<>0 then sqlhtml = sqlhtml&" and Dream_ModularID in ("&Dream_ModularID&")" '查询所属模块
	if Dream_ID<>0 then sqlhtml = sqlhtml&" and ID in ("&Dream_ID&")" '查询信息ID
	'if Dream_Style<>0 then sqlhtml = sqlhtml&" and Dream_Style in ("&Dream_Style&")" '查询所属文章形式
	if Dream_Show=1 and TagLabs="DreamMenu" then sqlhtml = sqlhtml&" and Dream_Show = true " '查询是否显示
	sqlhtml = sqlhtml&" order by "&Dream_Order '排序	
	
	rshtml.open sqlhtml,conn,1,3
		
	if not rshtml.eof then
	'response.Write TagLabs
	if Dream_Page<>"" then
	rshtml.pagesize=Dream_Row
	rshtml.absolutepage=Dream_Page
	for i=0 to rshtml.pagesize-1
	if rshtml.bof or rshtml.eof then exit for
	Loopstrstr=Loopstrstr&Parser_Tags("\["&TagLabs&":(.+?)\]",Loopstr,rshtml)
	rshtml.movenext()
	next
	else
	do while not rshtml.eof 
	Loopstrstr=Loopstrstr&Parser_Tags("\["&TagLabs&":(.+?)\]",Loopstr,rshtml)
		if TagLabs="DreamNav" then
		set rssubnav=server.CreateObject("adodb.recordset")
		sqlsubnav="select * from Dream_"&Dream_From&" where Dream_Classid="&rshtml("id")
		rssubnav.open sqlsubnav,conn,1,3
		subnav=""
		if not rssubnav.eof then
		subnav=subnav&"<"&Dream_SubNavDiv&" class="&Dream_SubNavDivClass&">"
		do while not rssubnav.eof
		if session("Dream_ClassID")=rssubnav("id") then
		classname=Dream_SubNavCss
		else
		classname=""
		end if
		strDream_SubNavLoop=Dream_SubNavLoop
		strUrl=catalog&rssubnav("Dream_HtmlName")&".html"
		strDream_SubNavLoop=Replace(strDream_SubNavLoop,"{classname}",classname)
		strDream_SubNavLoop=Replace(strDream_SubNavLoop,"{url}",strUrl)
		strDream_SubNavLoop=Replace(strDream_SubNavLoop,"{navname}",rssubnav("Dream_Names"))
		subnav=subnav&strDream_SubNavLoop
		rssubnav.movenext
		loop
		subnav=subnav&"</"&Dream_SubNavDiv&">"
		end if
		rssubnav.close
		set rssubnav=nothing
		Loopstrstr=Replace(Loopstrstr,"{subnav}",subnav)
		end if
	rshtml.movenext
	loop
	end if
	else
	Loopstrstr="暂无数据"
	end if
	rshtml.close
	set rshtml=nothing	

	sContent = Replace(sContent,Match.Value,Loopstrstr)
	Next
	'消毁对象
	Set Matches = Nothing
	Set objRegEx = Nothing
	'返回值
	'response.Write sContent
	LoopApp = sContent
End Function

'==============================
'【功能】处理条件标签
'==============================
	
Function IfApp(ByVal sContent)
	On Error Resume Next
	Dim Matches, Match, objRegEx
	Dim TestIF
	'建立正则表达式
	Set objRegEx = New RegExp
	'查找内容		
	objRegEx.Pattern = "{If:(.+?)}([\s\S]*?){Else}([\s\S]*?){End If}"
	Set Matches = objRegEx.Execute(Content)
	For Each Match In Matches
		Execute ("If " & Match.SubMatches(0) & " Then TestIf = True Else TestIf = False")
		If TestIF Then sContent = Replace(sContent, Match.Value, Match.SubMatches(1)) Else sContent = Replace(sContent, Match.Value, Match.SubMatches(2)) ' 替换
		If Err Then Response.Write "<font color=red>" & Lang_Parser_IF_Error & "[" & Match.SubMatches(0) & "]" & Err.Description & "</font>": Err.Clear: Response.End
	Next
	
	objRegEx.Pattern = "{If:(.+?)}([\s\S]*?){End If}"
	Set Matches = objRegEx.Execute(Content)
	For Each Match In Matches
		Execute ("If " & Match.SubMatches(0) & " Then TestIf = True Else TestIf = False")
		If TestIF Then sContent = Replace(sContent, Match.Value, Match.SubMatches(1)) Else sContent = Replace(sContent, Match.Value, "") ' 替换
		If Err Then Response.Write "<font color=red>" & Lang_Parser_IF_Error & "[" & Match.SubMatches(0) & "]" & Err.Description & "</font>": Err.Clear: Response.End
	Next	
	IfApp=sContent
end function


Public Function GetAttr(ByVal Tagsstr, ByVal AttrName, ByVal ReplaceSpace)
	If Len(Tagsstr) <= 3 Or InStr(LCase(Tagsstr), "$" & LCase(AttrName) & "=") = 0 Then GetAttr = "": Exit Function
	Dim Matches, Match,objRegEx	
	Set objRegEx = New RegExp
	objRegEx.Pattern = "\$" & AttrName & "=(.+?) \$"
	Set Matches = objRegEx.Execute(Tagsstr & " $")		
	For Each Match In Matches
		GetAttr = Match.SubMatches(0)
	Next
	If ReplaceSpace Then
		GetAttr = Replace(GetAttr, " ", "")
		If Len(GetAttr) > 0 And IsNumeric(GetAttr) And InStr(GetAttr, ",") = 0 Then GetAttr = Int(GetAttr)
	End If
End Function


' 字符替换
Public Function Parser_Tags(ByVal Pattern, ByVal Temp, ByVal Dat)
	
	On Error Resume Next
	Dim Matches, Match, objRegEx
	Dim Tagsstr, Tagsval, Tagsvalt
	Dim Tag_Len, Tag_Lenext, Tag_Format, Tag_Replace, Tag_Function,Tag_width,Tag_Height
	Dim Re, Re1, Re2
	Dim i, c, l, t
	Set objRegEx = New RegExp
	objRegEx.Global = True
	objRegEx.Pattern = Pattern
	Set Matches = objRegEx.Execute(Temp)
	
	For Each Match In Matches			
		Tagsstr = Match.SubMatches(0)
		Tag_Len = GetAttr(Tagsstr, "len", True)
     	Tag_Class = GetAttr(Tagsstr, "css", True)
		Tag_MenuClass = GetAttr(Tagsstr, "menucss", True)
		Tag_Format = GetAttr(Tagsstr, "format", False)
		Tag_Replace = GetAttr(Tagsstr, "replace", False)
		Tag_Function = GetAttr(Tagsstr, "function", True)
		Tag_Width=GetAttr(Tagsstr, "width", True)
		Tag_Height=GetAttr(Tagsstr, "height", True)
		Tagsval = Split(Tagsstr, " ")(0)		
		select case LCase(Tagsval)
		case "aurl"			
		Tagsval=ModularUrl(dat("Dream_ModularID"))&dat("id")&".html"
		case "picurl"
		if dat("Dream_DefaultPicUrl")="" then
		Tagsval="/images/no_img.jpg"
		else
		Tagsval="/"&dat("Dream_DefaultPicUrl")
		end if		
		case "contentx"			
		Tagsval=gotTopic(ClearHtml(dat("Dream_Content"),0),Tag_Len)
		case "menuurl"
		if dat("Dream_HtmlName")<>"" then		
		Tagsval="/"&dat("Dream_HtmlName")&"/"
		else
		Tagsval="/"&dat("Dream_HtmlName")
		end if
		case "menuname"			
		Tagsval=dat("Dream_Names") 
		case "curl"	
		if catalog="" then
		catalog=ModularUrl(dat("Dream_ModularID"))
		end if
		Tagsval=catalog&dat("Dream_HtmlName")&".html"
		case "murl"	
		Tagsval="/"&dat("Dream_HtmlName")&"/"
		case "titlex"
		Tagsval=gotTopic(dat("Dream_Title"),Tag_Len)
		case "guestbooktitle"
		Tagsval=dat("Title")
		case "username"
		Tagsval=dat("UserName")
		case "guestbookdate"
		Tagsval=dat("Time")
		case "guestbookcontent"
		Tagsval=dat("Content")
		case "refeedback"
		Tagsval=dat("ReFeedback")&" "
		case "linkname"
		Tagsval=dat("SiteName")
		case "linkurl"
		Tagsval=dat("SiteUrl")
		case "classname"
		Tagsval=dat("Dream_Names")
		case "classid"
		Tagsval=dat("id")
		case "date"
		Tagsval=dat("Dream_UpdateTime")
		case "menucss"		
		Tagsval=""
		if session("Dream_ModularID")="" then
		if dat("Dream_Style") = 8 then Tagsval=" class="&Tag_MenuClass
		else
		if dat("ID")=cint(session("Dream_ModularID")) then Tagsval=" class="&Tag_MenuClass
		end if
		case "css"		
		Tagsval=""
		strBagClassID=BagClassID(session("Dream_ClassID"))
		if dat("id")=cint(session("Dream_ClassID")) or dat("id")=strBagClassID then Tagsval=" class="&Tag_Class 
		end select		
		Tagsval = Replace(Replace(Replace(Replace(Tagsval, "&nbsp;", " "), "&quot;", Chr(34)), "&gt;", ">"), "&lt;", "<")
		Temp = Replace(Temp, Match.Value, Tagsval)
	Next	
	
	Set Matches = Nothing
	Set Reg = Nothing
	Parser_Tags = Temp
End Function
	
Function BagClassID(Cid)
	set rsBigClass=server.CreateObject("adodb.recordset")
	sqlBigClass="select * from Dream_Class where Dream_ClassID<>0 and id="&Cid
	rsBigClass.open sqlBigClass,conn,1,3
	if not rsBigClass.eof then
	BigClassName=rsBigClass("Dream_ClassID")
	else
	BigClassName=""
	end if
	rsBigClass.close
	set rsBigClass=nothing
	BagClassID=BigClassName
End Function


Function ModularID(Cid)
	set rsBigClass=server.CreateObject("adodb.recordset")
	sqlBigClass="select * from Dream_Class where id="&Cid
	rsBigClass.open sqlBigClass,conn,1,3
	if not rsBigClass.eof then
	strModularID=rsBigClass("Dream_ModularID")
	else
	strModularID=""
	end if
	rsBigClass.close
	set rsBigClass=nothing
	ModularID=strModularID
End Function


Function ModularUrl(Cid)
	set rsBigClass=server.CreateObject("adodb.recordset")
	sqlBigClass="select * from Dream_Modular where id="&Cid
	rsBigClass.open sqlBigClass,conn,1,3
	if not rsBigClass.eof then	
	strModularID=rsBigClass("Dream_HtmlName")
	if right(strModularID,1)<>"/" then
	strModularID=strModularID&"/"
	end if
	if left(strModularID,1)<>"/" then
	strModularID="/"&strModularID
	end if	
	else
	strModularID=""
	end if
	rsBigClass.close
	set rsBigClass=nothing
	ModularUrl=strModularID
End Function




'==============================
'判断是否为空
'==============================
Function IsBlank(ByRef TempVar)
IsBlank = False
select Case VarType(TempVar)
'Empty & Null
Case 0, 1
IsBlank = True
'String
Case 8
If Len(TempVar) = 0 Then
IsBlank = True
End If
'Object
Case 9
Dim tmpType
tmpType = TypeName(TempVar)
If (tmpType = "Nothing") or (tmpType = "Empty") Then
IsBlank = True
End If
'Array
Case 8192, 8204, 8209
If UBound(TempVar) = -1 Then
IsBlank = True
End If
End select
End Function

Sub genHtml(content,filename)'将替换后的内容写入HTML文档,content为替换后的字符串,filename为生成的文件名 
Dim fso,f 
Set fso = Server.CreateObject("Scripting.FileSystemObject") 
Set f = fso.CreateTextFile(filename,true)'如果文件名重复将覆盖旧文件 
f.Write content 
f.Close 
Set f = Nothing 
set fso=Nothing 
End Sub


Function Dream_PageHtml(ByVal Pages, ByVal Pagecounts, ByVal Catalog, ByVal Filename, ByVal Dream_Style, ByVal Dream_ClassID, ByVal Dream_ModularID)
Tag_Page=""
if Dream_ClassID=0 then
pageurl=Catalog&Filename&"-"&Dream_Style&"-"&Dream_ModularID&"-"
else
pageurl=Catalog&Filename&"-"&Dream_Style&"-"&Dream_ModularID&"-"&Dream_ClassID&"-"
end if

if Pages >= 2 then
Tag_Page=Tag_Page&"<a href="&pageurl&"1.html><<</a>"
Tag_Page=Tag_Page&"<a href="&pageurl&Pages-1&".html><</a>"
else
Tag_Page=Tag_Page&"<span><<</span>"
Tag_Page=Tag_Page&"<span><</span>"
end if

navnum=5

for i=1 to Pagecounts
if Pages=i then
classname="class=""a"""
else
classname=""
end if

if Pagecounts<=11 then
Tag_Page=Tag_Page&"<a href="&pageurl&i&".html "&classname&">"&i&"</a>"
else
if Pages>navnum and i=1 then
Tag_Page=Tag_Page&"<a href="&pageurl&i&".html "&classname&">"&i&"</a>"
if Pages>navnum+1 then Tag_Page=Tag_Page&" <span>...</span>"
end if

if Pages<=navnum and i<=10 then
Tag_Page=Tag_Page&"<a href="&pageurl&i&".html "&classname&">"&i&"</a>"
end if

if Pages>navnum and Pages-navnum<i and Pages+navnum>i and Pages<>1 and Pagecounts-Pages>navnum and Pagecounts<>1 then
Tag_Page=Tag_Page&"<a href="&pageurl&i&".html "&classname&">"&i&"</a>"
end if

if Pagecounts-Pages<=navnum and Pagecounts-i<10 and Pagecounts<>1 then
Tag_Page=Tag_Page&"<a href="&pageurl&i&".html "&classname&">"&i&"</a>"
end if

if Pagecounts-Pages>navnum and i=Pagecounts and Pagecounts<>1 then
if Pagecounts-Pages>navnum-1 then Tag_Page=Tag_Page&" <span>...</span>"
Tag_Page=Tag_Page&"<a href="&pageurl&i&".html "&classname&">"&i&"</a>"
end if

end if

next

if Pagecounts-Pages >= 1 then
Tag_Page=Tag_Page&"<a href="&pageurl&Pages+1&".html>></a>"
Tag_Page=Tag_Page&"<a href="&pageurl&Pagecounts&".html>>></a>"
else
Tag_Page=Tag_Page&"<span>></span>"
Tag_Page=Tag_Page&"<span>>></span>"
end if

Tag_Page=Tag_Page&"<div>"&Pages&"/"&Pagecounts&"</div>"

Dream_PageHtml=Tag_Page
End Function



Function Dream_PageAsp(Page,Keyword,Dream_ClassID)
Page=cint(Page)
set rs = Server.CreateObject("ADODB.Recordset") 
sql="select * from Dream_Articles where Dream_Title like '%"&Keyword&"%' and  Dream_ClassID in (select id from Dream_Class where Dream_ClassID in ("&Dream_ClassID&") or id in ("&Dream_ClassID&"))"
rs.open sql,Conn,1,1 
rs.pagesize=20
if not rs.eof then
rs.absolutepage=Page
Pagecounts=rs.pagecount
end if
rs.close
Set rs = Nothing

if Pagecounts="" then Pagecounts=1

Tag_Page=""
if Page >= 2 then
Tag_Page=Tag_Page&"<a href=""?page=1&classid="&Dream_ClassID&"&keys="&Keyword&"""><<</a>"
Tag_Page=Tag_Page&"<a href=""?page="&Page-1&"&classid="&Dream_ClassID&"&keys="&Keyword&"""><</a>"
else
Tag_Page=Tag_Page&"<span><<</span>"
Tag_Page=Tag_Page&"<span><</span>"
end if

navnum=5

for i=1 to Pagecounts
if Page=i then
classname="class=""a"""
else
classname=""
end if

if Pagecounts<=11 then
Tag_Page=Tag_Page&"<a href=""?page="&i&"&classid="&Dream_ClassID&"&keys="&Keyword&""" "&classname&">"&i&"</a>"
else
if Page>navnum and i=1 then
Tag_Page=Tag_Page&"<a href=""?page="&i&"&classid="&Dream_ClassID&"&keys="&Keyword&""" "&classname&">"&i&"</a>"
if Page>navnum+1 then Tag_Page=Tag_Page&" <span>...</span>"
end if

if Page<=navnum and i<=10 then
Tag_Page=Tag_Page&"<a href=""?page="&i&"&classid="&Dream_ClassID&"&keys="&Keyword&""" "&classname&">"&i&"</a>"
end if

if Page>navnum and Page-navnum<i and Page+navnum>i and Page<>1 and Pagecounts-Page>navnum and Pagecounts<>1 then
Tag_Page=Tag_Page&"<a href=""?page="&i&"&classid="&Dream_ClassID&"&keys="&Keyword&""" "&classname&">"&i&"</a>"
end if

if Pagecounts-Page<=navnum and Pagecounts-i<10 and Pagecounts<>1 then
Tag_Page=Tag_Page&"<a href=""?page="&i&"&classid="&Dream_ClassID&"&keys="&Keyword&""" "&classname&">"&i&"</a>"
end if

if Pagecounts-Page>navnum and i=Pagecounts and Pagecounts<>1 then
if Pagecounts-Page>navnum-1 then Tag_Page=Tag_Page&" <span>...</span>"
Tag_Page=Tag_Page&"<a href=""?page="&i&"&classid="&Dream_ClassID&"&keys="&Keyword&""" "&classname&">"&i&"</a>"
end if

end if

next

if Pagecounts-Page >= 1 then
Tag_Page=Tag_Page&"<a href=""?page="&Page+1&"&classid="&Dream_ClassID&"&keys="&Keyword&""">></a>"
Tag_Page=Tag_Page&"<a href=""?page="&Pagecounts&"&classid="&Dream_ClassID&"&keys="&Keyword&""">>></a>"
else
Tag_Page=Tag_Page&"<span>></span>"
Tag_Page=Tag_Page&"<span>>></span>"
end if

Tag_Page=Tag_Page&"<div>"&Page&"/"&Pagecounts&"</div>"

Dream_PageAsp=Tag_Page
End Function


function gotTopic(str,strlen)
	if str="" then
		gotTopic=""
		exit function
	end if
	dim l,t,c, i
	l=len(str)
	t=0
	for i=1 to l
		c=Abs(Asc(Mid(str,i,1)))
		if c>255 then
			t=t+2
		else
			t=t+1
		end if
		if t>=strlen then
			gotTopic=left(str,i) & "…"
			exit for
		else
			gotTopic=str
		end if
	next
	gotTopic=gotTopic
end function


Function ClearHtml(Content,style)

if style<>1 then '1表示不过滤<p></p>标签
Content=Zxj_ReplaceHtml("</?p[^>]*>","",Content)
end if
Content=Zxj_ReplaceHtml("&#[^>]*;", "", Content) 
Content=Zxj_ReplaceHtml("</?marquee[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("</?object[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("</?param[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("</?embed[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("</?table[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml(" ","",Content)
Content=Zxj_ReplaceHtml("　","",Content)
Content=Zxj_ReplaceHtml("&nbsp;","",Content)
Content=Zxj_ReplaceHtml("</?tr[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("</?th[^>]*>","",Content) 
Content=Zxj_ReplaceHtml("</?a[^>]*>","",Content) 
Content=Zxj_ReplaceHtml("</?img[^>]*>","",Content) 
Content=Zxj_ReplaceHtml("</?tbody[^>]*>","",Content) 
Content=Zxj_ReplaceHtml("</?li[^>]*>","",Content) 
Content=Zxj_ReplaceHtml("</?span[^>]*>","",Content) 
Content=Zxj_ReplaceHtml("</?div[^>]*>","",Content) 
Content=Zxj_ReplaceHtml("</?th[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("</?td[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("</?script[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("(javascript|jscript|vbscript|vbs):", "", Content) 
Content=Zxj_ReplaceHtml("on(mouse|exit|error|click|key)", "", Content) 
Content=Zxj_ReplaceHtml("<\\?xml[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("<\/?[a-z]+:[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("</?font[^>]*>", "", Content) 
Content=Zxj_ReplaceHtml("</?b[^>]*>","",Content) 
Content=Zxj_ReplaceHtml("</?u[^>]*>","",Content) 
Content=Zxj_ReplaceHtml("</?i[^>]*>","",Content) 
Content=Zxj_ReplaceHtml("</?strong[^>]*>","",Content) 
ClearHtml=Content 
End Function 

Function Zxj_ReplaceHtml(patrn, strng,content) 
IF IsNull(content) Then 
content="" 
End IF 
Set regEx = New RegExp ' 建立正则表达式。 
regEx.Pattern = patrn ' 设置模式。 
regEx.IgnoreCase = true ' 设置忽略字符大小写。 
regEx.Global = True ' 设置全局可用性。 
Zxj_ReplaceHtml=regEx.Replace(content,strng) ' 执行正则匹配 
End Function

%>
