<% '根據(jù)輸入判斷輸出是名稱還是數(shù)據(jù) Function geturlxml(outfile,mode) geturlxml=False If outfile="" Then Exit Function Dim tab Select Case killint(mode,0,0,2) Case 0:tab="szd_tpl" Case 1:tab="szd_content" End Select Set rs=conn.execute("select ["&tab&"] FROM szd_asp where [szd_link]='"&outfile&"'") If rs.eof And rs.bof Then Exit Function else geturlxml=rs(tab) End If End Function '提取include文件到原始的數(shù)據(jù)項中 Function getincludefile(x) Dim regxml,html html="" Set regxml=new regexp regxml.ignorecase=True regxml.global=True regxml.pattern="(<!--#include)(\s)(file|virtual)(=)(\u0022)([a-zA-Z][A-Za-z0-9_/]{0,30})(.)(asp|inc|dll)(\u0022)(-->)" Dim Matches,Match Set Matches = regxml.Execute(x) For Each Match in Matches html=html&match.value Next getincludefile=html End Function '獲取模板項,先判斷輸出,返回值是 html 形式的模板,參數(shù)是模板的名稱 Function gettpl(url) Dim mudule_file,xml_file,asp_file xml_file=url asp_file=gettpldata(xml_file,0)'由模板名稱獲取模板的內(nèi)容 Dim loadxml,parsexml,nodes,node Set loadxml = Server.CreateObject("MSxml2.DOMDocument") loadxml.async=false parsexml=server.mappath("../"&gettpldata(xml_file,10)&xml_file)'裝載本地的xml文檔,先到數(shù)據(jù)庫取到路徑 loadxml.load parsexml Set nodes = loadxml.selectNodes("http://*") for each node in nodes asp_file=insertaspinhtml(asp_file,gettpldata(node.nodename,1),node.nodename)'加載模塊到模板,輸出html模板 Next gettpl=asp_file End function
'匹配模板中的數(shù)據(jù)項 '把data中的數(shù)據(jù)傳入html文件當(dāng)中去 Function tpltodata(html,data) Dim regxml Set regxml=new regexp regxml.ignorecase=True regxml.global=True regxml.pattern="({%)([a-zA-Z][A-Za-z0-9_]{2,60})(%})(.[^\[]*)({%/)\2(%})"
Dim Matches,Match Set Matches = regxml.Execute(data) For Each Match in Matches html=Replace(html,"{%"®xml.Replace(match.value,"$2")&"%}",regxml.Replace(match.value,"$4")) Next tpltodata=html End Function
'geturlxml 傳入?yún)?shù)模板名稱,返回模板的內(nèi)容,失敗的時候返回 null Function geturlxml(outfile) geturlxml=Null If outfile="" Then Exit Function Set rs=conn.execute("select [szd_tpl] FROM szd_asp where [szd_link]='"&outfile&"'") If rs.eof And rs.bof Then Exit Function else geturlxml=rs("szd_tpl") End If End Function
public Function gettpldata(url,mode) 'Set rs=server.CreateObject("server.adodbrecordset") If Len(url)<1 Then Exit Function Dim szd_keytpl Select Case mode Case 0:Set rs=conn.execute("select [szd_content] from szd_tpl where [szd_link]='"&url&"'") Case 10:Set rs=conn.execute("select [szd_url] from szd_tpl where [szd_link]='"&url&"'") Case 1:Set rs=conn.execute("select [szd_content] from szd_keytpl where [szd_key]='"&url&"'") End Select If Not(rs.eof And rs.bof) Then szd_keytpl=rs(0) Else szd_keytpl="<div>{%nodefined%}</div>" End If gettpldata=szd_keytpl End Function '加載標(biāo)記的模塊到 xml 格式的模板中,輸出html格式的模板,asp:xml格式模板,html:導(dǎo)入的模塊,xmls:當(dāng)前標(biāo)記 Function insertaspinhtml(asp,html,xmls) Dim regxml,temp,temps,tempasp,tempasp_e Set regxml=new regexp regxml.ignorecase=True regxml.global=True regxml.pattern="(\<"&xmls&"\>)(.[^\[]*)(\<\/"&xmls&"\>)" temp=regxml.Replace(asp,"$2") Dim Matches,Match Set Matches = regxml.Execute(asp) For Each Match in Matches html=Replace(html,"(&"&xmls&"&)",regxml.Replace(match.value,"$2")) asp=Replace(asp,Match.Value,html) next temps=Replace(html,"(&"&xmls&"&)",temp) insertaspinhtml=asp End Function
Function update_aspfile(id) Dim update_aspfile_return update_aspfile_return=False id=killint(id,0,0,14) If id=0 Then Exit Function Set rs=conn.execute("select [szd_level],[szd_content],[szd_tpl],[szd_link] from szd_asp where id="&id&"") If rs.eof And rs.bof Then Exit Function Dim tpl_level,tpl_content,tpl_tpl,html_content,asp_file_now tpl_level=rs(0) tpl_content=rs(1) tpl_tpl=rs(2) asp_file_now=rs(3) If Len(tpl_tpl)<4 Or tpl_level=1 Or IsNull(tpl_tpl) Then html_content=tpl_content Else html_content=gettpl(tpl_tpl) If Not isnull(html_content) Then html_content=getincludefile(tpl_content)&tpltodata(html_content,tpl_content) 'response.write("<hr/>"&server.htmlencode(getincludefile(tpl_content))&"<hr/>") Else html_content=tpl_content 'response.write("<hr/>"&server.htmlencode(html_content)&"<hr/>") End If End If If writeto("../",asp_file_now,html_content,2) Then update_aspfile_return=True update_aspfile=update_aspfile_return End Function %>