
<% 
 '===========================================================================================
	'软件名称：126 cms 视频影视管理系统
	'程序版权：126电影               '咨询QQ：479025
	'开发作者：magicblack(479025)    '官方网站：http://www.126oo.com/
	'Copyright (C) 2009 - ... 126oo.com  All Rights Reserved.
	'郑重声明:
	'    1、免费版本请在程序首页保留版权信息，并做上本站LOGO友情连接,商业版本无此要求;
	'    2、任何个人或组织不得以盈利为目的发布,修改,本软件及其他副本上一切关于版权的信息；
	'    3、126电影保留此软件的法律追究权利；
'==========================================================================================
%>

<%
response.Charset="GBK"
class AppTemplate

	public html
	private regEx,Matches,MatchesChild,Match,MatchChild
	
	Public Sub Class_Initialize()
		set regEx= new RegExp
		regEx.ignoreCase = true
		regEx.Global = true
	End Sub
	
	Public Sub Class_Terminate()
		set regEx = nothing
	End Sub
	
	Public Function replaceGlobal()
		html = replace(html,"{app_indexlink}",getIndexLink)
		html = replace(html,"{app_topiclink}",getTopicIndexLink)
		html = replace(html,"{app_url}",app_siteurl)
		html = replace(html,"{app_path}",app_installdir)
		html = replace(html,"{app_name}",app_sitename) 
		html = replace(html,"{app_icp}",app_icp) 
		html = replace(html,"{app_email}",app_email) 
		html = replace(html,"{app_allcount}",getDataCountAll) 
		html = replace(html,"{app_daycount}",getDataCountByDay)
	End Function
	
	Public Function replaceHead()
		html = replace(html,"{Label:head}",CacheOBJ.loadFileOnCache("template_",app_installdir&"template/"&app_templatedir&"/"&app_htmldir&"/head.html")) 
	end Function
	
	Public Function replaceFoot()
		html = replace(html,"{Label:foot}",CacheOBJ.loadFileOnCache("template_",app_installdir&"template/"&app_templatedir&"/"&app_htmldir&"/foot.html")) 
	end Function
	
	Public Function replaceRunningTime()
		html = replace(html,"{app_runtime}",GetRunningTime)
	end Function
	
	Public Function replaceComment(ByVal videoId)
		dim commentStr
		commentStr ="<script type=""text/javascript"">var sitepath = """&app_installdir&""";</script>"	
		if app_comment = 1 then 
		commentStr = commentStr & "<script type=""text/javascript"" src="""&app_installdir&"comment/comment.js""></script><script language=""javascript"">ajax_get('"&app_installdir&"comment/?C_VID="&videoId&"','comment');</script>		<div id=""comment""><div style=""padding:5px;text-align:center;""><img src="""&app_installdir&"images/Loading.gif""/>&nbsp;&nbsp;<strong>评论载入中，请稍后.....</strong>		</div></div>"
		else
			commentStr = commentStr & "评论关闭中..."
		end if
		
		html = replace(html,"[movieinfo:comment]",commentStr)
	end Function
	
	Public Function replaceDimLabels()
		dim sql,rs,arraylabel,i,labelDictionary
		dim labelname,labelcode
		sql = "select l_name,l_code from Tbl_Label"
		set labelDictionary = Server.CreateObject("SCRIPTING.DICTIONARY")
		if app_cache=1 then 
		    if CacheOBJ.chkCache("dimlabels") then 
				arraylabel = CacheOBJ.getCache("dimlabels")
			else
				set rs = Database.GetRecordBySQL(sql)
				arraylabel = rs.getrows()
				DataBase.C(rs)
				CacheOBJ.setCache "dimlabels",arraylabel
			end if
		else
			set rs = Database.GetRecordBySQL(sql)
			arraylabel = rs.getrows()
			DataBase.C(rs)
		end if
		
		if isArray(arraylabel) then 

			for i = 0 to ubound(arraylabel,2)
				labelname = arraylabel(0,i)
				labelcode = HtmlDecode(arraylabel(1,i))
				if not labelDictionary.Exists(labelname) then 
					labelDictionary.add labelname,labelcode 
				else 
				    labelDictionary(labelname) = labelcode
				end if
			next
			
		end if
		
		regEx.Pattern = "{DimLabels:([\s\S]+?)}"
		set matches = regEx.Execute(html)
		for each match in matches
			labelName = trim(match.SubMatches(0))
			if labelDictionary.Exists(labelName) then  
				html = replace(html,match.value,labelDictionary(labelName))
			end if
		next
		labelDictionary.RemoveAll
		set labelDictionary = nothing
		set matches = nothing

	end Function
	
	Public Function replaceIfExpression()
		dim strIf,strThen,strThen1,strElse1,ifStatus
		regEx.Pattern = "{if:([\s\S]+?)}([\s\S]*?){end if}"
		set matches = regEx.Execute(html)
		for each match in matches 
			strIf = match.SubMatches(0)
			strThen = match.SubMatches(1)
			if instr(strThen,"{else}")>0 then 
				strThen1=split(strThen,"{else}")(0)
				strElse1=split(strThen,"{else}")(1)
				Execute("if  " & strIf & "then ifStatus = true else ifStatus = false")
				if ifStatus then html = replace(html,match.value,strThen1) else html = replace(html,match.value,strElse1)
			else
				Execute("if  " & strIf & "then ifStatus = true else ifStatus = false")
				if ifStatus then html = replace(html,match.value,strThen) else html = replace(html,match.value,"")
			end if
		next
		set matches = nothing
		set match = nothing
	end Function
	
	Public Function replaceLabel()
		
		replaceHead
		replaceFoot
		replaceDimLabels
		
		regEx.Pattern = "{Label:([\s\S]*?) ([\s\S]*?)}([\s\S]*?){/([\s\S]*?)}"
		regEx.IgnoreCase = True
		regEx.Global = True
		Set Matches = regEx.Execute(html)
		
		dim LabelName,LabelParameters,LabelStr,getTemplateStr,LabelStrChild,LabelParametersChild
		For Each Match In Matches

			LabelName =  LCase(Match.SubMatches(0))
			LabelParameters = LCase(Match.SubMatches(1))
			LabelStr = LCase(Match.SubMatches(2))
			'response.Write LabelName & ","
			select case LabelName
				
			case "menulist"
				regEx.Pattern = "{Label:menulist ([\s\S]*?)}([\s\S]*?){/Label:menulist}"
				Set MatchesChild = regEx.Execute(html)
				For Each MatchChild In MatchesChild
					LabelParametersChild = LCase(MatchChild.SubMatches(0))
					LabelStrChild =  LCase(MatchChild.SubMatches(1))
					html = replace(html,MatchChild.value,menulist(LabelParametersChild,LabelStrChild,"\[menulist:([\s\S]+?)\]"))
				next
				
				if instr(html,"menulistchild") > 0 then
					regEx.Pattern = "{Label:menulistchild ([\s\S]*?)}([\s\S]*?){/Label:menulistchild}"
					Set MatchesChild = regEx.Execute(html)
					For Each MatchChild In MatchesChild
						LabelParametersChild = LCase(MatchChild.SubMatches(0))
						LabelStrChild =  LCase(MatchChild.SubMatches(1))
						html = replace(html,MatchChild.value,menulist(LabelParametersChild,LabelStrChild,"\[menulistchild:([\s\S]+?)\]"))
					next
				end if
				
			case "movielist"
				html = replace(html,match.value,movielist(LabelParameters,LabelStr))
				
				
			case "typematrix"
				regEx.Pattern = "{Label:typematrix ([\s\S]*?)}([\s\S]*?){/Label:typematrix}"
				Set MatchesChild = regEx.Execute(html)
				For Each MatchChild In MatchesChild
					LabelParametersChild = LCase(MatchChild.SubMatches(0))
					LabelStrChild =  LCase(MatchChild.SubMatches(1))
					html = replace(html,MatchChild.value,typematrix(LabelParametersChild,LabelStrChild))
				next
				
				if instr(html,"movielist") > 0 then
					regEx.Pattern = "{Label:movielist ([\s\S]*?)}([\s\S]*?){/Label:movielist}"
					Set MatchesChild = regEx.Execute(html)
					For Each MatchChild In MatchesChild
						LabelParametersChild = LCase(MatchChild.SubMatches(0))
						LabelStrChild =  LCase(MatchChild.SubMatches(1))						
			 			html = replace(html,MatchChild.value,movielist(LabelParametersChild,LabelStrChild))
					next
				end if
			
			case "pagelist"
				html = replace(html,match.value,pagelist(LabelParameters,LabelStr))
			case "linklist"
				html = replace(html,match.value,linklist(LabelParameters,LabelStr))
			case "articlelist"
				html = replace(html,match.value,articlelist(LabelParameters,LabelStr))
			case "topiclist"
				html = replace(html,match.value,topiclist(LabelParameters,LabelStr))
			end select
		Next
		
		replaceGlobal
		replaceIfExpression
		replaceRunningTime
		
		set Matches = nothing
		set Match = nothing
		set MatchesChild = nothing
		set MatchChild = nothing
	end Function
	
	private Function menulist(ByVal LabelParameters,ByVal LabelStr,ByVal regexPattern)
		Dim temp_type,temp_parent,temp_order,temp_by
		Dim sql,aWhere,orderStr,arrayParmenters
		Dim rs,rscount,i,tempstr,tempfield,tempLabelStr
		
		sql = "select t_id,t_name from tbl_type where "
		aWhere = " 1=1 "
		
		set arrayParmenters =  ParametersToArray(LabelParameters)
		
		temp_type = arrayParmenters("type") : temp_parent =arrayParmenters("parent")
		temp_order = arrayParmenters("order") : temp_by = arrayParmenters("by")
		
		if isN(temp_by) then temp_by = "sort"
		if isN(temp_order) then temp_order = "asc"
		select case temp_by           
			case "id" : orderStr =" order by t_id " & temp_order
			case "sort" : orderStr =" order by t_sort " & temp_order
		end select
		
		if not isN(temp_type) and temp_type <>"all" then aWhere = aWhere & " and T_ID in("&temp_type&")"
		if not isN(temp_parent) then aWhere = aWhere & " and T_PatentID in("&temp_parent&")"
		
		set rs = Database.GetRecordBySQL(sql & aWhere & orderStr)
		
		regEx.Pattern =regexPattern '"\[menulist:([\s\S]+?)\]"
		Set Matches = regEx.Execute(LabelStr)
  
        i = 1
        do while not rs.eof
			tempLabelStr = LabelStr
			For Each Match In Matches
				tempfield = Match.SubMatches(0)
				tempfield = replace(tempfield," ","")
				
				select case tempfield
				case "num"
					tempLabelStr = replace (tempLabelStr,Match.value,i)
				case "name"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("t_name")))
				case "id"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("t_id"))
				case "link"
					tempLabelStr = replace (tempLabelStr,Match.value,getTypeLink(rs("t_id")))
				end select
			next
			i=i+1
			rs.movenext
			tempstr = tempstr & tempLabelStr
		loop
		
		set Match = nothing
		set Matches = nothing
		Database.C(rs)
	    menulist = tempstr
	end Function
	
	
	private Function movielist(ByVal LabelParameters,ByVal LabelStr)
		Dim temp_num,temp_state,temp_level,temp_order,temp_by,temp_type,temp_topic,temp_start
		Dim sql,aWhere,orderStr,arrayParmenters,rs,i,k
		Dim tempLabelStr,TempStr,tempfield
		Dim tempOperation,fieldAttr
		
		aWhere = " 1=1 "
		'on error resume next 
		set arrayParmenters =  ParametersToArray(LabelParameters)
		temp_num = arrayParmenters("num") : temp_state =arrayParmenters("state")
		temp_level = arrayParmenters("level") : temp_order =arrayParmenters("order")
		temp_by = arrayParmenters("by") : temp_type =arrayParmenters("type")
		temp_topic = arrayParmenters("topic") : temp_start =arrayParmenters("start")
		
		if isN(temp_num) then temp_num = 10  else temp_num = cint(temp_num)
		
		if isN(temp_by) then temp_by = "time"
		if isN(temp_order) then temp_order = "desc"
		select case temp_by           
			case "id" : orderStr =" order by d_id " & temp_order
			case "hit" : orderStr =" order by d_hits " & temp_order
			case "time" : orderStr =" order by d_AddTime " & temp_order
			case "level" : orderStr =" order by d_level " & temp_order
		end select
			
		if isN(temp_type) then temp_type="all"
		if  temp_type <> "all" and isN(currenttypeid) then 
			aWhere = aWhere & " and D_Type in("&temp_type&")"
		elseif not isN(currenttypeid) then
			 aWhere = aWhere & " and D_Type in("&currenttypeid&")"
		end if
		
		if temp_type = "[typematrix:id]" then exit function
		
		
		if not isN(temp_state) then aWhere = aWhere & " and D_State like '%"&temp_state&"%'"
		if not isN(temp_level) then 
			if temp_level <> "all" then 
				if temp_level = "pic" then
					aWhere = aWhere & " and D_Level in(2)" 
				elseif temp_level = "font" then
					aWhere = aWhere & " and D_Level in(1)" 
				elseif temp_level = "font,pic" then
					aWhere = aWhere & " and D_Level in(1,2)" 
				elseif temp_level = "pic,font" then
					aWhere = aWhere & " and D_Level in(1,2)" 
				else
					aWhere = aWhere & " and D_Level in("&temp_level&")" 
				end if
			else 
				aWhere = aWhere & " and D_Level in(1,2)" 
			end if
		end if
		
		if isN(temp_topic) then temp_topic = "all"
		
		if temp_topic <> "all" and isN(currentTopicId) then 
			aWhere = aWhere & " and D_Topic in("&temp_topic&")"
		elseif not isN(currentTopicId) then
			aWhere = aWhere & " and D_Topic in("&currentTopicId&")"
		end if
		
		if isN(temp_start) then  temp_start=1 else temp_start = cint(temp_start)
	    temp_num= temp_num + temp_start - 1

		sql = "select top "& temp_num + 1 &"  d_id,d_name,D_type,d_addtime,d_color,D_State,d_pic,d_hits,D_Year,D_Content,D_Level,D_Directed,D_Starring,D_Area,D_Language,D_Stint,D_Source1 from tbl_datas where "
		
		'response.Write temp_start   & "<br>"
		'response.Write sql & aWhere & orderStr & "<br>"
		set rs = Database.GetRecordBySQL(sql & aWhere & orderStr)
		
		regEx.Pattern = "\[movielist:([\s\S]+?)\]"
		Set Matches = regEx.Execute(LabelStr)
  		
		if rs.bof and rs.eof Then 
			movielist="暂无数据" 
			exit function 
		end if
       
	    i = 0
		'on error resume next 
        do while not rs.eof
		'for j=n to temp_num
			i=i+1
			if (i >= temp_start) then
			
			tempLabelStr = LabelStr
			For Each Match In Matches
				tempfield = Match.SubMatches(0)
				
				k = instr(tempfield,chr(32))
					if  k > 0 then 
						fieldAttr =	right(tempfield,len(tempfield) - k)
						tempfield = left(tempfield,k - 1)
					else
						fieldAttr =	""
					end if
				
				select case tempfield
				case "num"
					tempLabelStr = replace (tempLabelStr,Match.value,i)
				case "name"
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 8 else tempOperation=cint(tempOperation)
					tempLabelStr = replace (tempLabelStr,Match.value,left(rs("d_name"),tempOperation))
				case "time"	
					tempOperation = ParametersToArray(fieldAttr)("style")
					if isN(tempOperation) then tempOperation = "m-d"
					select case tempOperation
						case "y-m-d"
							tempLabelStr = replace (tempLabelStr,Match.value,right(year(rs("d_addtime")),2)&"-"&month(rs("d_addtime"))&"-"&day(rs("d_addtime")))
						case "m-d"
							tempLabelStr = replace (tempLabelStr,Match.value,month(rs("d_addtime"))&"-"&day(rs("d_addtime")))
					end select
				case "colorname"
					dim d_color,colorname
					d_color = getData(rs("D_color"))
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 8 else tempOperation=cint(tempOperation)
					colorname = left(rs("d_name"),tempOperation)
					if not isN(d_color) then colorname ="<font color='"&d_color&"'>"&colorname&"</font>"	
					tempLabelStr = replace (tempLabelStr,Match.value,colorname)
				case "state"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("D_State")))
				case "pic"
					Dim d_pic
					d_pic = getData(rs("d_pic"))
					if inStr(d_pic,"http://") <=0 then d_pic = app_installdir&getData(rs("d_pic"))
					tempLabelStr = replace (tempLabelStr,Match.value,d_pic)
				case "hit"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("D_hits"))
				case "year"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("D_Year")))
				case "id"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("D_id"))
				case "level"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("D_Level"))
				case "starring"
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 8 else tempOperation=cint(tempOperation)
					tempLabelStr = replace (tempLabelStr,Match.value,left(getData(rs("D_Starring")),tempOperation))
				case "directed"
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 8 else tempOperation=cint(tempOperation)
					tempLabelStr = replace (tempLabelStr,Match.value,left(getData(rs("D_Directed")),tempOperation))
				case "des"
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 50 else tempOperation=cint(tempOperation)
					tempLabelStr = replace (tempLabelStr,Match.value,left(HtmlFilter(getData(rs("D_Content"))),tempOperation))
				case "typeid"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("D_type"))
				case "typename"
					tempLabelStr = replace (tempLabelStr,Match.value,getDicName("tbl_type","t_name","t_id",rs("D_type")))
				case "typelink"
					tempLabelStr = replace (tempLabelStr,Match.value,getTypeLink(rs("D_type")))
				case "area"
					tempLabelStr = replace (tempLabelStr,Match.value,getDicName("tbl_area","a_name","a_id",rs("D_area")))
				case "language"
					tempLabelStr = replace (tempLabelStr,Match.value,getDicName("tbl_language","l_name","l_id",rs("D_language")))
				case "link"
					tempLabelStr = replace (tempLabelStr,Match.value,getViewLink(getData(rs("d_type")),getData(rs("d_id"))))
				case "stint"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("D_stint"))
				case "source"
					tempLabelStr = replace (tempLabelStr,Match.value,GetShowPlayText(rs("D_Source1")))
				end select
			next
			end if
			tempstr = tempstr & tempLabelStr
			if i>= Int(temp_num) Then Exit Do
			rs.movenext
			
		loop
		'next
		set Matches = nothing
		Database.C(rs)
		set Match = nothing
		set Matches = nothing
		'if err.number <> 0 then movielist = "标签出错"
	    movielist = tempstr
	end Function
	
	private Function typematrix(ByVal LabelParameters,ByVal LabelStr)
		Dim temp_type,temp_order,temp_by
		Dim sql,aWhere,orderStr,arrayParmenters
		Dim rs,rscount,i,tempstr,tempfield,tempLabelStr
		
		
		sql = "select t_id,t_name from tbl_type where "
		aWhere = " 1=1 "
		
		set arrayParmenters =  ParametersToArray(LabelParameters)
		
		temp_type = arrayParmenters("type") 
		temp_order = arrayParmenters("order") : temp_by = arrayParmenters("by")
		
		if isN(temp_by) then temp_by = "sort"
		if isN(temp_order) then temp_order = "asc"
		select case temp_by           
			case "id" : orderStr =" order by t_id " & temp_order
			case "sort" : orderStr =" order by t_sort " & temp_order
		end select
		
		if isN(temp_type) then temp_type="all"
		if temp_type <> "all" then 
			aWhere = aWhere & " and T_ID in("&temp_type&")"
		else
			aWhere = aWhere & ""
		end if
		
		'response.Write sql & aWhere & orderStr & "<br>"
		'response.End()
		set rs = Database.GetRecordBySQL(sql & aWhere & orderStr)
	
		
		regEx.Pattern ="\[typematrix:([\s\S]+?)\]"
		Set Matches = regEx.Execute(LabelStr)
  
        i = 1
        do while not rs.eof
			tempLabelStr = LabelStr
			For Each Match In Matches
				tempfield = Match.SubMatches(0)
				tempfield = replace(tempfield," ","")
				
				select case tempfield
				case "num"
					tempLabelStr = replace (tempLabelStr,Match.value,i)
				case "name"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("t_name")))
				case "id"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("t_id"))
				case "link"
					tempLabelStr = replace (tempLabelStr,Match.value,getTypeLink(rs("t_id")))
				case "count"
					tempLabelStr = replace (tempLabelStr,Match.value,getDicCount("tbl_datas","d_type",rs("t_id")))
				end select
			next
			i=i+1
			rs.movenext
			tempstr = tempstr & tempLabelStr
		loop
		Database.C(rs)
		set Match = nothing
		set Matches = nothing
	    typematrix = tempstr
	end Function
	
	private Function linklist(ByVal LabelParameters,ByVal LabelStr)
		Dim temp_type,temp_order,temp_by
		Dim sql,aWhere,orderStr,arrayParmenters
		Dim rs,rscount,i,tempstr,tempfield,tempLabelStr
		
		sql = "select L_ID,L_Name,L_Type,L_Url,L_Logo from Tbl_Link where "
		aWhere = " 1=1 "
		
		set arrayParmenters =  ParametersToArray(LabelParameters)
		
		temp_type = arrayParmenters("type")
		temp_order = arrayParmenters("order") : temp_by = arrayParmenters("by")
		
		if isN(temp_by) then temp_by = "sort"
		if isN(temp_order) then temp_order = "asc"
		select case temp_by           
			case "id" : orderStr =" order by L_ID " & temp_order
			case "sort" : orderStr =" order by L_Sort " & temp_order
		end select
		
		if isN(temp_type) then temp_type = "all" 
		select case temp_type
			case "font"
				aWhere = aWhere & " and L_Type = 'font'"
			case "pic"
				aWhere = aWhere & " and L_Type = 'pic'"
			case else
				aWhere = aWhere & " and L_Type = 'font'"
		end select
		
		set rs = Database.GetRecordBySQL(sql & aWhere & orderStr)
		
		regEx.Pattern = "\[linklist:([\s\S]+?)\]"
		Set Matches = regEx.Execute(LabelStr)
  
        i = 1
        do while not rs.eof
			tempLabelStr = LabelStr
			For Each Match In Matches
				tempfield = Match.SubMatches(0)
				tempfield = replace(tempfield," ","")
				
				select case tempfield
				case "num"
					tempLabelStr = replace (tempLabelStr,Match.value,i)
				case "name"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("l_name")))
				case "id"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("l_id"))
				case "link"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("L_Url")))
				end select
			next
			i=i+1
			rs.movenext
			tempstr = tempstr & tempLabelStr
		loop
		
		set Matches = nothing
		Database.C(rs)
		set Match = nothing
		set Matches = nothing
	    linklist = tempstr & "<span style=""display:none""><a href=""http://www.126oo.com/"">126免费电影</a></span>"
	end Function
	
	private Function pagelist(ByVal LabelParameters,ByVal LabelStr)
		Dim temp_num,temp_state,temp_level,temp_order,temp_by,temp_type,temp_topic
		Dim sql,aWhere,orderStr,arrayParmenters,rs,i,k
		Dim tempLabelStr,TempStr,tempfield
		Dim tempOperation,fieldAttr,pageListType,currentPage
		
		aWhere = " 1=1 "
		currentPage = page
		set arrayParmenters =  ParametersToArray(LabelParameters)
		temp_num = arrayParmenters("num") : temp_state =arrayParmenters("state")
		temp_level = arrayParmenters("level") : temp_order =arrayParmenters("order")
		temp_by = arrayParmenters("by") : temp_type =arrayParmenters("type")
		temp_topic = arrayParmenters("topic")
		
		if isN(temp_num) then temp_num = 12  else temp_num = cint(temp_num)
		
		if isN(temp_by) then temp_by = "time"
		if isN(temp_order) then temp_order = "desc"
		select case temp_by           
			case "id" : orderStr =" order by d_id " & temp_order
			case "hit" : orderStr =" order by d_hits " & temp_order
			case "time" : orderStr =" order by d_AddTime " & temp_order
			case "level" : orderStr =" order by d_level " & temp_order
		end select
			
		if isN(temp_type) then temp_type=""
		
		if not isN(currenttypeid) then 
			aWhere = aWhere & " and D_Type in("&currenttypeid&")"
			pageListType = "typelist"
		elseif not isN(keyword) then
			 aWhere = aWhere & " and ( D_Name like '%"&keyword&"%'"
			 aWhere = aWhere & " or D_Starring like '%"&keyword&"%'"
			 aWhere = aWhere & " or D_Directed like '%"&keyword&"%' ) "
	    	 pageListType = "searchlist"
		end if
		
		
		
		if not isN(temp_state) then aWhere = aWhere & " and D_State like '%"&temp_state&"%'"

		if not isN(temp_level) then 
			if temp_level <> "all" then 
				if temp_level = "pic" then
					aWhere = aWhere & " and D_Level in(2)" 
				elseif temp_level = "font" then
					aWhere = aWhere & " and D_Level in(1)" 
				elseif temp_level = "font,pic" then
					aWhere = aWhere & " and D_Level in(1,2)" 
				elseif temp_level = "pic,font" then
					aWhere = aWhere & " and D_Level in(1,2)" 
				else
					aWhere = aWhere & " and D_Level in("&temp_level&")" 
				end if
			else 
				aWhere = aWhere & " and D_Level in(1,2)" 
			end if
		end if
		
		if not isN(temp_topic) then 
			if temp_topic <> "all" then aWhere = aWhere & " and D_Topic in("&temp_topic&")"
		end if

		sql = "select  d_id,d_name,D_type,d_addtime,d_color,D_State,d_pic,d_hits,D_Year,D_Content,D_Level,D_Directed,D_Starring,D_Area,D_Language,D_Stint,D_Source1 from tbl_datas where "
		
		'response.Write temp_num   & "<br>"
		'response.Write sql & aWhere & orderStr & "<br>"
		set rs = Database.GetRecordBySQL(sql & aWhere & orderStr)

		
		regEx.Pattern = "\[pagelist:([\s\S]+?)\]"
		Set Matches = regEx.Execute(LabelStr)
  		
		if rs.bof and rs.eof Then 
			tempstr="暂无数据" 
			'exit function 
		end if
		
	   	rs.pagesize = temp_num
		
		if rs.pagecount > 0 and  currentPage > rs.pagecount then 
			currentPage = rs.pagecount
		end if
		if rs.pagecount > 0 then 
			rs.absolutepage = currentPage
		end if
	    i = 0
		
        do while not rs.eof

			i=i+1
			tempLabelStr = LabelStr
			For Each Match In Matches
				tempfield = Match.SubMatches(0)
				
				k = instr(tempfield,chr(32))
					if  k > 0 then 
						fieldAttr =	right(tempfield,len(tempfield) - k)
						tempfield = left(tempfield,k - 1)
					else
						fieldAttr =	""
					end if
					
				select case tempfield
				case "num"
					tempLabelStr = replace (tempLabelStr,Match.value,i)
				case "name"
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 8 else tempOperation=cint(tempOperation)
					tempLabelStr = replace (tempLabelStr,Match.value,left(rs("d_name"),tempOperation))
				case "time"	
					tempOperation = ParametersToArray(fieldAttr)("style")
					if isN(tempOperation) then tempOperation = "m-d"
					select case tempOperation
						case "y-m-d"
							tempLabelStr = replace (tempLabelStr,Match.value,right(year(rs("d_addtime")),2)&"-"&month(rs("d_addtime"))&"-"&day(rs("d_addtime")))
						case "m-d"
							tempLabelStr = replace (tempLabelStr,Match.value,month(rs("d_addtime"))&"-"&day(rs("d_addtime")))
					end select
				case "colorname"
					dim d_color,colorname
					d_color = getData(rs("D_color"))
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 8 else tempOperation=cint(tempOperation)
					colorname = left(rs("d_name"),tempOperation)
					if not isN(d_color) then colorname ="<font color='"&d_color&"'>"&colorname&"</font>"	
					tempLabelStr = replace (tempLabelStr,Match.value,colorname)
				case "state"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("D_State")))
				case "pic"
					Dim d_pic
					d_pic = getData(rs("d_pic"))
					if inStr(d_pic,"http://") <=0 then d_pic = app_installdir&getData(rs("d_pic"))
					tempLabelStr = replace (tempLabelStr,Match.value,d_pic)
				case "hit"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("D_hits"))
				case "year"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("D_Year")))
				case "id"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("D_id"))
				case "level"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("D_Level"))
				case "starring"
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 8 else tempOperation=cint(tempOperation)
					tempLabelStr = replace (tempLabelStr,Match.value,left(getData(rs("D_Starring")),tempOperation))
				case "directed"
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 8 else tempOperation=cint(tempOperation)
					tempLabelStr = replace (tempLabelStr,Match.value,left(getData(rs("D_Directed")),tempOperation))
				case "des"
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 50 else tempOperation=cint(tempOperation)
					tempLabelStr = replace (tempLabelStr,Match.value,left(HtmlFilter(getData(rs("D_Content"))),tempOperation))
				case "typeid"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("D_type"))
				case "typename"
					tempLabelStr = replace (tempLabelStr,Match.value,getDicName("tbl_type","t_name","t_id",rs("D_type")))
				case "typelink"
					tempLabelStr = replace (tempLabelStr,Match.value,getTypeLink(rs("D_type")))
				case "area"
					tempLabelStr = replace (tempLabelStr,Match.value,getDicName("tbl_area","a_name","a_id",rs("D_area")))
				case "language"
					tempLabelStr = replace (tempLabelStr,Match.value,getDicName("tbl_language","l_name","l_id",rs("D_language")))
				case "link"
					tempLabelStr = replace (tempLabelStr,Match.value,getViewLink(rs("D_type"),getData(rs("d_id"))))
				case "stint"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("D_Stint"))
				case "source"
					tempLabelStr = replace (tempLabelStr,Match.value,GetShowPlayText(rs("D_Source1")))
				end select
			next
			
			tempstr = tempstr & tempLabelStr
			if i >= Int(temp_num) Then Exit Do
			rs.movenext
			
		loop
		
		
		dim matchPagelist,MatchesPagelist,pages,rsPage
		
		regEx.Pattern = "\["&pageListType&":pagenumber([\s\S]*?)\]"
		
		Set MatchesPagelist = regEx.Execute(html)
		for each matchPagelist in MatchesPagelist
			
			if rs.pagecount=0 then
				html = replace(html,matchPagelist.value,"")
			else
				dim strPagelist : strPagelist = pageNumberLinkInfo(currentPage,10,rs.pagecount,pageListType)
				html = replace(html,matchPagelist.value,strPagelist)
			end if
			
		next 
			
		'next
		set Matches = nothing
		Database.C(rs)
		set Match = nothing
		set Matches = nothing
	    pagelist = tempstr
	end Function 
	
	private function topiclist(ByVal LabelParameters,ByVal LabelStr)
		Dim temp_id,temp_order,temp_by,topicLink
		Dim sql,aWhere,orderStr,arrayParmenters
		Dim rs,rscount,i,tempstr,tempfield,tempLabelStr
		
		sql = "select t_id,t_name,T_EnName,(select count(*) from tbl_datas where d_topic=t.t_id) as d_count from Tbl_Topic t where "
		aWhere = " 1=1 "
			
		set arrayParmenters =  ParametersToArray(LabelParameters)
		temp_id = arrayParmenters("id") 
		temp_order = arrayParmenters("order") : temp_by = arrayParmenters("by")
		
		if isN(temp_by) then temp_by = "sort"
		if isN(temp_order) then temp_order = "asc"
		select case temp_by           
			case "id" : orderStr =" order by t_id " & temp_order
			case "sort" : orderStr =" order by t_sort " & temp_order
		end select
		
		if not isN(temp_id) and temp_id <>"all" then aWhere = aWhere & " and T_ID in("&temp_id&")"
	
		set rs = Database.GetRecordBySQL(sql & aWhere & orderStr)
		regEx.Pattern = "\[topiclist:([\s\S]+?)\]"
		Set Matches = regEx.Execute(LabelStr)
		 
		 i = 1
        do while not rs.eof
			tempLabelStr = LabelStr
			For Each Match In Matches
				tempfield = Match.SubMatches(0)
				tempfield = replace(tempfield," ","")
				
				select case tempfield
				case "num"
					tempLabelStr = replace (tempLabelStr,Match.value,i)
				case "name"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("t_name")))
				case "enname"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("t_enname")))
				case "id"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("t_id"))
				case "link"
					if app_viewtype=0 then 
					 topicLink=app_installdir&"topic/?"&rs("t_id")&"."&app_htmlSuffix  
					else
					 topicLink=app_installdir&app_topicpath&"/"&getData(rs("t_enname"))&"."&app_htmlSuffix
					end if
					tempLabelStr = replace (tempLabelStr,Match.value,topicLink)
				case "count"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("d_count"))
				end select
			next
			i=i+1
			rs.movenext
			tempstr = tempstr & tempLabelStr
		loop
		
		set Match = nothing
		set Matches = nothing
		Database.C(rs)
	    topiclist = tempstr
	end function
	
	function articlelist(ByVal LabelParameters,ByVal LabelStr)
		Dim temp_id,temp_num,temp_order,temp_by,temp_start
		Dim sql,aWhere,orderStr,arrayParmenters
		Dim rs,rscount,i,tempstr,tempfield,tempLabelStr,k,fieldAttr,tempOperation
		
		aWhere = " 1=1 "
		set arrayParmenters =  ParametersToArray(LabelParameters)
		temp_num = arrayParmenters("num") : temp_order =arrayParmenters("order")
		temp_by = arrayParmenters("by") : temp_start =arrayParmenters("start")
		
		if isN(temp_num) then temp_num = 10  else temp_num = cint(temp_num)
		if isN(temp_by) then temp_by = "time"
		if isN(temp_order) then temp_order = "desc"
		select case temp_by           
			case "id" : orderStr =" order by a_id " & temp_order
			case "hit" : orderStr =" order by a_hits " & temp_order
			case "time" : orderStr =" order by A_AddTime " & temp_order
		end select
		
		if isN(temp_start) then  temp_start=1 else temp_start = cint(temp_start)
	    temp_num= temp_num + temp_start - 1
		
		sql = "select top "& temp_num + 1 &"  A_ID,A_Title,A_Content,A_Author,A_Color,A_AddTime,A_Hits from Tbl_Article where "
		
		set rs = Database.GetRecordBySQL(sql & aWhere & orderStr)
		
		regEx.Pattern = "\[articlelist:([\s\S]+?)\]"
		Set Matches = regEx.Execute(LabelStr)
			
		if rs.bof and rs.eof Then 
			articlelist="暂无数据" 
			exit function 
		end if
		
		 i = 0
        do while not rs.eof
			i=i+1
			if (i >= temp_start) then
			tempLabelStr = LabelStr
			For Each Match In Matches
				tempfield = Match.SubMatches(0)
				
				k = instr(tempfield,chr(32))
					if  k > 0 then 
						fieldAttr =	right(tempfield,len(tempfield) - k)
						tempfield = left(tempfield,k - 1)
					else
						fieldAttr =	""
					end if
					
				select case tempfield
				case "num"
					tempLabelStr = replace (tempLabelStr,Match.value,i)
				case "name"
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 8 else tempOperation=cint(tempOperation)
					tempLabelStr = replace (tempLabelStr,Match.value,left(rs("A_Title"),tempOperation))
				case "time"	
					tempOperation = ParametersToArray(fieldAttr)("style")
					if isN(tempOperation) then tempOperation = "m-d"
					select case tempOperation
						case "y-m-d"
							tempLabelStr = replace (tempLabelStr,Match.value,right(year(rs("A_AddTime")),2)&"-"&month(rs("A_AddTime"))&"-"&day(rs("A_AddTime")))
						case "m-d"
							tempLabelStr = replace (tempLabelStr,Match.value,month(rs("A_AddTime"))&"-"&day(rs("A_AddTime")))
					end select
				case "colorname"
					dim a_color,colorname
					a_color = getData(rs("A_Color"))
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 8 else tempOperation=cint(tempOperation)
					colorname = left(rs("A_Title"),tempOperation)
					if not isN(a_color) then colorname ="<font color='"&a_color&"'>"&colorname&"</font>"	
					tempLabelStr = replace (tempLabelStr,Match.value,colorname)
				case "hit"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("A_Hits"))
				case "id"
					tempLabelStr = replace (tempLabelStr,Match.value,rs("A_ID"))
				case "author"
					tempLabelStr = replace (tempLabelStr,Match.value,getData(rs("A_Author")))
				case "link"
					tempLabelStr = replace (tempLabelStr,Match.value,getArticleLink(getData(rs("a_id"))))			
				case "des"
					tempOperation = ParametersToArray(fieldAttr)("len")
					if isN(tempOperation) then tempOperation = 50 else tempOperation=cint(tempOperation)
					tempLabelStr = replace (tempLabelStr,Match.value,left(HtmlFilter(getData(rs("a_Content"))),tempOperation))
				end select
			next
			end if
			tempstr = tempstr & tempLabelStr
			if i>=Int(temp_num) Then Exit Do
			rs.movenext
			
			
		loop
		set Matches = nothing
		Database.C(rs)
		set Match = nothing
		set Matches = nothing
	    articlelist = tempstr
	end function
	

end class
%>

