<%
'//读取模板
function cw_redtemp(folder,files)
  Set fso=Server.CreateObject("Scripting.FileSystemObject") 
  if fso.fileExists(Server.MapPath(folder&files))=true then'判断文是否存在 
    Set fed=fso.OpenTextFile(Server.MapPath(folder&files))
	cw_redtemp=fed.ReadAll
	fed.close     
  set fed=nothing
  else
    response.write(folder&files&"模板不存在")
    response.End()
  end if  
  set fso=nothing
end function

'//解析引用文件标签(代码)
function cw_include(content)
  Set Reg = New RegExp 
  Reg.Pattern="{cw:include\(['""]([\s\S]+?)['""]\)}"
  Reg.IgnoreCase = True
  Reg.Global = True
  Set Matches=Reg.Execute(content)
  IF Matches.Count>0 Then
     For Each Match In Matches
	 content=Replace(content,Match.value,cw_redtemp(cf_root&"skins/"&cf_skin,Match.SubMatches(0)))'替换引入文件标签
     Next
  End IF
  cw_include=content
  set Reg=nothing
  set Matches=nothing
end function

'//过滤空白字符
function cw_space(str) 
str=replace(str,chr(8),"")
str=replace(str,chr(9),"")
str=replace(str,chr(10),"")
str=replace(str,chr(11),"")
str=replace(str,chr(12),"")
str=replace(str,chr(13),"")
str=replace(str,chr(22),"")
cw_space=str
end function

'//生成html(内容，生成目录，生成文件名)
function cw_html(content,folder,filename)
  'content=cw_space(content)'过滤源代码中的空白
  Set fso = Server.CreateObject("Scripting.FileSystemObject")
  if not(fso.FolderExists(Server.MapPath(folder))) then'判断目录是否存在
	 cf=split(folder,"/")'下面是创建多级目录
	 cb=""
	 for k=1 to ubound(cf)-1
	   cy="/"&cf(k)
	   cb=cb&cy
	   if not(fso.FolderExists(Server.MapPath(cb&"/"))) then
	     fso.CreateFolder(Server.MapPath(cb&"/"))
	   end if
	 next
  end if
  Set fout = fso.CreateTextFile(Server.MapPath(folder&filename),true)
  fout.Write content
  fout.close
  set fout=nothing
  set fso=nothing
end function
'//删除文件
function cw_del(path)
  if inStr(path,"http://")>0 then exit function'取消远程文件的删除
  Set fs = Server.CreateObject("Scripting.FileSystemObject")
  if fs.FileExists(Server.MapPath(path)) then'判断文件是否存在
     fs.DeleteFile Server.MapPath(path),True '强制删除只读文件
  else
     exit function
  end if
  set fs=nothing
end function

'//解析全局标签
function cw_system(html)
  cw_system=replace(html,"{cw:webname}",cf_name)
  cw_system=replace(cw_system,"{cw:webhost}",cf_host)
  cw_system=replace(cw_system,"{cw:webroot}",cf_root)
  cw_system=replace(cw_system,"{cw:webskin}",cf_root&"skins/"&cf_skin)'模板目录
  cw_system=replace(cw_system,"{cw:webstats}",cf_stats)'统计
  cw_system=replace(cw_system,"{cw:webversion}",cf_version)'系统版本
  cw_system=replace(cw_system,"{cw:webemail}",cf_email)
  cw_system=replace(cw_system,"{cw:webdate}",now())
  cw_system=cw_label(cw_system)
end function

'//解析自定义标签
function cw_label(html)
  set rs=server.CreateObject("adodb.recordset")
  sql="select label,content from cw_label"
  rs.open sql,conn,1,1
  if not rs.eof then
  do while not rs.eof
    html=replace(html,"{cw_"&rs(0)&"}",rs(1))
  rs.movenext
  loop
  end if
  rs.close
  set rs=nothing
  cw_label=html
end function

'//解析循环
function cw_loop(content)
  Set Reg = New RegExp
  Reg.IgnoreCase = True
  Reg.Global = True
  for ri=1 to 2'循环查找 一维和二维
  if ri=1 then Reg.Pattern="{@cw:loop ([\s\S]+?)}([\s\S]+?){/@cw:loop}" else Reg.Pattern="{cw:loop ([\s\S]+?)}([\s\S]+?){/cw:loop}"
  Set Matches=Reg.Execute(content)
  IF Matches.Count>0 Then
     For Each Match In Matches
      r1=Match.SubMatches(0)
      r2=Match.SubMatches(1) 
	  r1=cw_allclassid(r1)'解析allclassid
      r4=cw_loop_sql(r1,r2,ri)'(sql,循环内容,一维或二维)
      content=Replace(content,Match.value,r4)'for循环内容替换
     Next
  End If
  next 
  Set Reg=nothing
  set Matches=nothing
  cw_loop=content
end function

'//loop/page的分类解析
function cw_cfass(con,id,tab,lop)
  On error resume next
  set cf=server.CreateObject("adodb.recordset")
  cfq="select * from "&tab&" where id="&id
  cf.open cfq,conn,1,1
  Call Cw_err("Cw_cfass")
  if not cf.eof then
   son=son&con
   if lop=1 then
   son=replace(son,"{@classname}",cf("title"))   
   son=replace(son,"{@classid}",cf("id"))   
   son=replace(son,"{@classurl}",cf_root&cf("html"))
   else
   son=replace(son,"{classname}",cf("title"))
   son=replace(son,"{classid}",cf("id"))
   son=replace(son,"{classurl}",cf_root&cf("html"))
   end if
  end if
  cf.close
  set cf=nothing
  cw_cfass=son
end function

'//loop/page的用户解析
function cw_user(con,id,lop)
  On error resume next
  set cf=server.CreateObject("adodb.recordset")
  cfq="select * from cw_user where id="&id
  cf.open cfq,conn,1,1
  Call Cw_err("Cw_user")
  if not cf.eof then
   son=con
   gr=cf("grade")   
   if lop=1 then
   son=replace(son,"{@username}",cf("user"))   
   son=replace(son,"{@userid}",cf("id"))
   son=replace(son,"{@userpic}",cf("pic"))
   son=replace(son,"{@userjf}",cf("jf"))
   son=replace(son,"{@userjb}",cf("jb"))
   son=replace(son,"{@usergr}",Cw_grade(gr))
   son=replace(son,"{@logindate}",cf("logindate"))
     if cf("type")=0 then son=replace(son,"{@usertype}","个人")
	 if cf("type")=1 then son=replace(son,"{@usertype}","商家")
	 if cf("type")=2 then son=replace(son,"{@usertype}","中介")
   else
   son=replace(son,"{username}",cf("user"))
   son=replace(son,"{userid}",cf("id"))
   son=replace(son,"{userpic}",cf("pic"))
   son=replace(son,"{userjf}",cf("jf"))
   son=replace(son,"{userjb}",cf("jb"))
   son=replace(son,"{usergr}",Cw_grade(gr))
   son=replace(son,"{logindate}",cf("logindate"))
     if cf("type")=0 then son=replace(son,"{usertype}","个人")
	 if cf("type")=1 then son=replace(son,"{usertype}","商家")
	 if cf("type")=2 then son=replace(son,"{usertype}","中介")
   end if
  end if
  cf.close
  set cf=nothing
  cw_user=son
end function

'//解析SQL
function cw_loop_sql(sql,con,lop)
 On error resume next
 set rst=server.CreateObject("adodb.recordset") 
 rst.open sql,conn,1,1
 Call Cw_err("Cw_loop_sql:"&sql)
 f1=rst.fields.count-1 '字段的数量
   if not rst.eof then   
     i=1
     j=0	
     do while not rst.eof 	
	  son=son&con
	      '判断是哪个表的好取路径
		  sql5=replace(sql,"from ","from$")
		  sql5=sql5&" "
		  st=cw_cut(sql5,"from$"," ",1)'获取当前的表名		  
		  select case st  '判断是否需要获取分类		  
		    case "cw_news","cw_info","cw_shop","cw_job","cw_hous"
			  son=cw_cfass(son,rst("classid"),st&"_class",lop)'解析分类标签
              if lop=2 then
			    son=replace(son,"{link}",cf_root&cw_class("html",st&"_class",rst("classid"))&rst("id")&".html")	
				if st<>"cw_news" then son=cw_user(son,rst("userid"),lop)
				if st<>"cw_job" then
                if rst("pic")<>"" then
			      son=replace(son,"{pic}",cf_root&rst("pic"))
                else
                   son=replace(son,"{pic}","nopic")
                end if
				end if			
			  else
			    son=replace(son,"{@link}",cf_root&cw_class("html",st&"_class",rst("classid"))&rst("id")&".html")	
				son=replace(son,"{@username}",cw_class("user","cw_user",rst("userid")))		
                 if rst("pic")<>"" then
			      son=replace(son,"{@pic}",cf_root&rst("pic"))				  
                 else
                  son=replace(son,"{@pic}","")
                 end if
			  end if
			case "cw_bbs"
				uid=rst("userid")
				redate=cw_rebbs(rst("id"),"redate")				  
			     if lop=1 then
		          son=replace(son,"{@link}",cf_root&"bbs/show.asp?id="&rst("id"))
				  son=replace(son,"{@classname}",cw_class("title",st&"_class",rst("classid")))
				  son=replace(son,"{@classurl}",cf_root&"bbs/list.asp?id="&rst("classid"))
				  son=replace(son,"{@redate}",redate)
				  son=replace(son,"{@reply}",cw_bbsreply(rst("id")))
				  if uid="" then
				  son=replace(son,"{@rename}","")
				  else
				  son=replace(son,"{@rename}",cw_class("user","cw_user",uid))
				  end if				  
			     else
			      son=replace(son,"{link}",cf_root&"bbs/show.asp?id="&rst("id"))
				  son=replace(son,"{classname}",cw_class("title",st&"_class",rst("classid")))
				  son=replace(son,"{classurl}",cf_root&"bbs/list.asp?id="&rst("classid"))	
				  son=replace(son,"{redate}",redate)
				  son=replace(son,"{reply}",cw_bbsreply(rst("id")))	
				  if uid="" then
				  son=replace(son,"{rename}","")
				  else
				  son=replace(son,"{rename}",cw_class("user","cw_user",uid))
				  end if
		         end if				 
				 son=cw_user(son,rst("userid"),lop)	 
			case "cw_news"
			  if rst("tags")<>"" then
			     tags=replace(rst("tags"),"，",",")
				 tag=split(tags,",")
				 for ta=0 to ubound(tag)
				 tag_f=tag_f&"<a href='"&cf_root&"search/?key="&server.URLEncode(tag(ta))&"'>"&tag(ta)&"</a>&nbsp;&nbsp;"
				 next
			     if lop=1 then
				   son=replace(son,"{@tags}",tag_f)
				 else
				   son=replace(son,"{tags}",tag_f)
				 end if				 
			  else
			     if lop=1 then
				 son=replace(son,"{tags}","")
				 else
			     son=replace(son,"{@tags}","")
				 end if
			  end if		   
			case "cw_comment"'解析评论中的用户名
			    son=cw_user(son,rst("userid"),lop)'解析用户标签
			case "cw_hr"
			  if lop=2 then	
			    son=replace(son,"{link}",cf_root&cf_hr&rst("id")&".html")
			    son=replace(son,"{pic}",cf_root&rst("pic"))
				son=replace(son,"{nianling}",year(now())-year(rst("chusheng")))
			  else
			    son=replace(son,"{@link}",cf_root&cf_hr&rst("id")&".html")
			    son=replace(son,"{@pic}",cf_root&rst("pic"))
				son=replace(son,"{@nianling}",year(now())-year(rst("chusheng")))
			  end if
			case "cw_bianmin"
			  if lop=2 then
			    son=replace(son,"{link}",cf_root&cf_tel&rst("id")&".html")
			  else
			    son=replace(son,"{@link}",cf_root&cf_tel&rst("id")&".html")
			  end if
            case "cw_pages"
			  if lop=2 then	
			    son=replace(son,"{link}",cf_root&rst("root")&rst("html"))
			  else
			    son=replace(son,"{@link}",cf_root&rst("root")&rst("html"))
			  end if
			case "cw_news_class","cw_info_class","cw_job_class","cw_shop_class","cw_hous_class"
			   if lop=1 then
		          son=replace(son,"{@link}",cf_root&rst("html"))
				  son=Replace(son,"{@pic}",cf_root&rst("pic"))
			   else
			      son=replace(son,"{link}",cf_root&rst("html"))	
				  son=Replace(son,"{pic}",cf_root&rst("pic"))	
		       end if
			case "cw_bbs_class"
			   if lop=1 then
		          son=replace(son,"{@link}",cf_root&"bbs/list.asp?id="&rst("id"))
				  son=replace(son,"{@daycount}",cw_bbscount(rst("id"),2))
				  son=replace(son,"{@allcount}",cw_bbscount(rst("id"),1))
				  son=Replace(son,"{@pic}",cf_root&rst("pic"))
			   else
			      son=replace(son,"{link}",cf_root&"bbs/list.asp?id="&rst("id"))
				  son=replace(son,"{daycount}",cw_bbscount(rst("id"),2))
				  son=replace(son,"{allcount}",cw_bbscount(rst("id"),1))
				  son=Replace(son,"{pic}",cf_root&rst("pic"))
		       end if
			case "cw_tags"
			   if lop=1 then
		          son=replace(son,"{@link}",cf_root&"search/?sid=1&key="&server.URLEncode(rst("title")))
			   else
			      son=replace(son,"{link}",cf_root&"search/?sid=1&key="&server.URLEncode(rst("title")))		
		       end if
		    end select	
		   if lop=2 then		   
		   son=replace(son,"{i}",i)
           son=replace(son,"{j}",j)  
		   else
		   son=replace(son,"{@i}",i)
           son=replace(son,"{@j}",j)
		   end if
        for f=0 to f1 '替换当前表中的字段
		if rst(f)<>"" then
          if lop=2 then '判断一维还是二维
             son=replace(son,"{"&rst.fields(f).name&"}",rst(f))  'fields(0).name是字段名称         
          else
             son=replace(son,"{@"&rst.fields(f).name&"}",rst(f))
          end if  
		 else
		    if lop=2 then
		    son=replace(son,"{"&rst.fields(f).name&"}","") 
			else
			son=replace(son,"{@"&rst.fields(f).name&"}","")
			end if
		end if        
        next			 
     i=i+1
     j=j+1	
     rst.movenext
     loop
	  rst.close
     set rst=nothing
     cw_loop_sql=son
   else
     cw_loop_sql=""
   end if
end function

'//解析loop分类标签(字段,表，分类ID)
function cw_class(zd,table,id)
 On error resume next
 set ta=server.CreateObject("adodb.recordset")
 taq="select "&zd&" from "&table&" where id="&id
 ta.open taq,conn,1,1
 Call Cw_err("Cw_class")
 if not ta.eof then
  cw_class=ta(0)
 else
  cw_class=""
 end if
 ta.close
 set ta=nothing 
end function

'//解析分页(解析内容，分页条数,当前页)
function cw_page(content,pag,pa)
  Set Reg = New RegExp
  Reg.IgnoreCase = True
  Reg.Global = True
  Reg.Pattern="{@cw:page ([\s\S]+?)}([\s\S]+?){/@cw:page}"
  Set Matches=Reg.Execute(content)
  IF Matches.Count>0 Then
     For Each Match In Matches
      f1=Match.SubMatches(0)'SQL语句
      f2=Match.SubMatches(1)'循环内容
      f4=Cw_page_sql(f1,f2,pag,pa)	 
      content=Replace(content,Match.value,f4)'for循环内容替换	  
      content=Replace(content,"{cw:listpage}",cw_listpage(f1,pag,pa))'替换分页标签
     Next
  End If
  cw_page=content
  Set Reg=nothing
  set Matches=nothing
end function
'//Page-sql
Function Cw_page_sql(sql,con,pag,p)
 On error resume next
 set rsf=server.CreateObject("adodb.recordset") 
 rsf.open sql,conn,1,1
 Call Cw_err("Cw_page_sql:"&sql)
if not rsf.eof then
fx=rsf.fields.count-1 '字段的数量
i=1
j=0
l=1
rsf.pagesize=pag
rsf.absolutepage=p '当前第几页
for k=1 to rsf.pagesize
if rsf.eof or rsf.bof then exit for
if rsf.eof then
  Cw_page_sql=""
else
  '内容替换
    son=son&con
	      '判断是哪个表的好取路径
		  sql5=replace(sql,"from ","from$")
		  sql5=sql5&" "
		  st=cw_cut(sql5,"from$"," ",1)'获取当前的表名
		  select case st  '判断是否需要获取分类
		    case "cw_news","cw_info","cw_shop","cw_job","cw_hous"
			 son=cw_cfass(son,rsf("classid"),st&"_class",1)'解析分类标签			 
			 son=replace(son,"{@link}",cf_root&cw_class("html",st&"_class",rsf("classid"))&rsf("id")&".html")
			 if st<>"cw_news" then son=cw_user(son,rsf("userid"),1)
			 if st<>"cw_job" then
             if rsf("pic")<>"" then
			    son=replace(son,"{@pic}",cf_root&rsf("pic"))
             else
                son=replace(son,"{@pic}"," ")
             end if
			 end if		 
			case "cw_bbs"			   
		          son=replace(son,"{@link}",cf_root&"bbs/show.asp?id="&rsf("id"))
				  son=replace(son,"{@classname}",cw_class("title",st&"_class",rsf("classid")))
				  son=replace(son,"{@classurl}",cf_root&"bbs/list.asp?id="&rsf("classid"))
				  son=cw_user(son,rsf("userid"),1)
				  uid=cw_rebbs(rsf("id"),"userid")
				  redate=cw_rebbs(rsf("id"),"redate")
				  son=replace(son,"{@redate}",redate)
				  son=replace(son,"{@reply}",cw_bbsreply(rsf("id")))
				  if uid="" then
				  son=replace(son,"{@rename}","")
				  else
				  son=replace(son,"{@rename}",cw_class("user","cw_user",uid))				  
				  end if
			case "cw_news"
			 if rsf("tags")<>"" then
			   tags=replace(rsf("tags"),"，",",")
			   tag=split(tags,",")
			   for ta=0 to ubound(tag)
			   tag_c=tag_c&"<a href='"&cf_root&"search/?sid=0&key="&server.URLEncode(tag(ta))&"'>"&tag(ta)&"</a>&nbsp;&nbsp;"
			   next
			   son=replace(son,"{@tags}",tag_c)
			 else
			   son=replace(son,"{@tags}","")
			 end if
			case "cw_hr"
			   son=replace(son,"{@link}",cf_root&cf_hr&rsf("id")&".html")	
			   son=replace(son,"{@nianling}",year(now())-year(rsf("chusheng")))
			case "cw_bianmin"
			   	son=replace(son,"{@link}",cf_root&cf_tel&rsf("id")&".html")	   
			case "cw_comment"
			   son=cw_user(son,rsf("userid"),1)'解析用户标签
			case "cw_tags"
			   son=replace(son,"{@link}",cf_root&"search/?key="&server.URLEncode(rsf("title")))
			case "cw_bbs_reply"
				son=cw_user(son,rsf("userid"),1)
				if p>1 then l=pag*(p-1)+i
				if rsf("ispass")=2 then son=replace(son,"{@recontent}","<font style='background-color:#FFCC00; color:#FF0000'>警告：该用户回复的内容己被管理员屏蔽！</font>")
		    end select		      
		    son=replace(son,"{@i}",i)
            son=replace(son,"{@j}",j)
			son=replace(son,"{@l}",l)			
        for x=0 to fx '替换当前表中的字段
        if rsf(x)<>"" then
           son=replace(son,"{@"&rsf.fields(x).name&"}",rsf(x))'fields(0).name是字段名称  
		else
		   son=replace(son,"{@"&rsf.fields(x).name&"}","") 
        end if
        next	 
     if p=1 then l=l+1
	 i=i+1
     j=j+1
  '内容替换结束
end if
rsf.movenext
next
   Cw_page_sql=son
else
   Cw_page_sql=""
end if
rsf.close
set rsf=nothing
End Function

'//获是分页数量
Function cw_pag(content,pag)
  err.clear
  On error resume next
  Set Reg = New RegExp
  Reg.IgnoreCase = True
  Reg.Global = True
  Reg.Pattern="{@cw:page ([\s\S]+?)}([\s\S]+?){/@cw:page}"
  Set Matches=Reg.Execute(content)  
  IF Matches.Count>0 Then
     For Each Match In Matches
      f1=Match.SubMatches(0)'SQL语句
      set st=Server.CreateObject("adodb.recordset")
      st.open f1,conn,1,1
      st.pagesize=pag
      cw_pag=st.pagecount
      st.close
      set st=nothing
     Next
  End If
  Set Reg=nothing
  set Matches=nothing
  Call Cw_err("Cw_pag")
End Function

'//获得分页导航链接
Function cw_listpage(sql,pag,pa)
 set rl=server.CreateObject("adodb.recordset") 
 rl.open sql,conn,1,1
 if not rl.eof then
  page=pa
  n=rl.RecordCount
  rl.pagesize=pag
  m=cint(rl.pagecount)
  if page="" then 
   page=1
  elseif page<1 then 
    page=1
  end if
  if cint(pa)>m then
        page=m
     end if
  page=cint(page)
  if not rl.eof then 
     rl.absolutepage=page
  end if     
  if m>page+3 then 
     endpage=page+3 
  else 
     endpage=m 
  end if 
  if pa=1 then
     pagetitle=pagetitle&"<a>首页</a>"
  else
     pagetitle=pagetitle&"<a href='./'>首页</a>"
  end if
  if pa>1 then
     if pa=2 then
     pagetitle=pagetitle&"<a href='./'>上一页</a>"
     else
     pagetitle=pagetitle&"<a href='index_"&pa-1&".html'>上一页</a>"
     end if
  else
     pagetitle=pagetitle&"<a>上一页</a>"
  end if
  if page>4 then
     pagetitle=pagetitle&"<a href='index_4.html'>...</a>"
  end if     
  for i=page-3 to endpage
     if not i<1 then 
        if i = page then 
          pagetitle=pagetitle&"<span>"&i&"</span>"     
        else 
          if i=1 then
             pagetitle=pagetitle&"<a href='./'>"&i&"</a>"
          else
             pagetitle=pagetitle&"<a href='index_"&i&".html'>"&i&"</a>"
          end if
        end if 
     end if 
  next 
  if page+3 < m then
     pagetitle=pagetitle&"<a href='index_"&page+3&".html'>...</a>"
  end if 
  if rl.pagecount<pa+1 then
     pagetitle=pagetitle&"<a>下一页</a>"
  else
     pagetitle=pagetitle&"<a href='index_"&pa+1&".html'>下一页</a>"
  end if
  if rl.pagecount=<pa+1 then
     pagetitle=pagetitle&"<a>尾页</a>"
  else
     pagetitle=pagetitle&"<a href='index_"&rl.pagecount&".html'>尾页</a>"
  end if
  pagetitle=pagetitle&"<a>"&page&"/"&rl.pagecount&"页</a>"
 end if 
 cw_listpage=pagetitle
 rl.close
 set rl=nothing
End Function

'//解析for循环
function cw_for()
  On error resume next
  Set Reg = New RegExp
  Reg.Pattern="{cw:for ([\s\S]+?)}([\s\S]+?)\{/cw:for}"  '{cw:for f=0 to 8}aaaaaa{/cw:for}
  Reg.IgnoreCase = True
  Reg.Global = True
  Set Matches=Reg.Execute(content)
  IF Matches.Count>0 Then
     For Each Match In Matches
      f1=Match.SubMatches(0)'for条件
      f2=Match.SubMatches(1)'循环内容
      f8=split(f1,"to ")
      for i=1 to f8(1)
         f3=f2&f3
      next
	  Call Cw_err("Cw_for")
      content=Replace(content,Match.value,f3)'for循环内容替换
    Next
  End If
  cw_for=content
  Set Reg=nothing
  set Matches=nothing
end function

'//获取分类ID
function cw_classid(f1,f2)
  On error resume next
  Set al=server.CreateObject("adodb.recordset")
  alq="select id from "&f1&" where followid="&f2&" or id="&f2
  al.open alq,conn,1,1
  Call Cw_err("Cw_classid")
  if not al.eof then
  do while not al.eof
  sid=sid&al("id")&","
  al.movenext
  loop     
  sid=left(sid,len(sid)-1)
  else
  sid=""
  end if
  al.close
  set al=nothing
  cw_classid=sid  
end function

'//Allclassid [cw:news_allclassid(1)]
function cw_allclassid(content)
  On error resume next
  Set Reg = New RegExp
  Reg.Pattern="\[cw:([\s\S]+?)_allclassid\(([\s\S]+?)\)]" 
  Reg.IgnoreCase = True
  Reg.Global = True
  Set Matches=Reg.Execute(content)
  IF Matches.Count>0 Then
     For Each Match In Matches
      f1=Match.SubMatches(0)'for条件
      f2=Match.SubMatches(1)'循环内容
  set al=server.CreateObject("adodb.recordset")
  alq="select id from cw_"&f1&"_class where followid in("&f2&") or id="&f2
  al.open alq,conn,1,1
  Call Cw_err("Cw_allclassid")
  if not al.eof then
  do while not al.eof
  sid=sid&al("id")&","
  al.movenext
  loop     
  sid=left(sid,len(sid)-1)
  else
  sid=""
  end if
  al.close
  set al=nothing
      content=Replace(content,Match.value,sid)'for循环内容替换
	  sid=""
    Next
  End If
  cw_allclassid=content  
  Set Reg=nothing
  set Matches=nothing  
end function

'//解析参数标签
function cw_function(content)
  On error resume next  
  Set Reg = New RegExp
  Reg.Pattern="\[@([\s\S]+?)#\b([\s\S]+?)]"
  Reg.IgnoreCase = True
  Reg.Global = True
  Set Matches=Reg.Execute(content)
  IF Matches.Count>0 Then
     For Each Match In Matches
      rf1=Match.SubMatches(0)
      rf2=Match.SubMatches(1)

      if instr(rf2,"function=")>0 then'判断是否有function
        rf3=cw_cut(rf2,"function=","/",1)
        select case rf3
          case "nohtml"  '去除html
            rf1=cw_nohtml(rf1)         
        end select
      end if
	  
	  if instr(rf2,"date=")>0 then'时间解析	 
	     rf5=replace(rf2,"function=nohtml","")
	     rf5=replace(rf5,"date=","")		 
		 rf1=cw_date(rf1,rf5)
	  end if
	  
      if instr(rf2,"len=")>0 then '判断是否有len   
	    rf4=replace(rf2,"function=nohtml/","")
		rf4=Cw_cut(rf4,"len=","/",1)
        rf4=replace(rf4,"len=","")
		if len(rf1)>cint(rf4) then	
		   rf1=left(rf1,rf4)&"..."
		else
		   rf1=left(rf1,rf4)
		end if
      end if

	  if instr(rf2,"key=")>0 then
	    rf5=Cw_cut(rf2,"key=","/",1)		
	    rf5=replace(rf5,"key=","")		
		rf1=replace(rf1,rf5,"<font style='color:#cc0000'>"&rf5&"</font>")		 
	  end if
	 Call Cw_err("Cw_function")
      content=Replace(content,Match.value,rf1)'for循环内容替换
     Next
  End If  
  Set Reg=nothing
  Set Matches=nothing
  cw_function=content'系统标签处理
end function

'//解析IF判断标签
Function Cw_if(Str)
  On error resume next
  r1=""
  t5=""
  Set Reg = New RegExp
  Reg.IgnoreCase = True
  Reg.Global = True
  Reg.Pattern="\[if ([\s\S]+?)\]([\s\S]+?)\[end if\]"
  Set Matches=Reg.Execute(Str)
  If Matches.Count>0 Then
     For Each Match In Matches
      t0=Match.SubMatches(0)
	  t1=Match.SubMatches(1)
	  If instr(t1,"[else]")>0 then
	     t2=Split(t1,"[else]") 
		 t3=t2(1)
		 t4=t2(0)
		 Execute("if "&t0&" then r1=t4 else r1=t3 end if")
	  Else
		 Execute("if "&t0&" then r1=t1 else r1=t5 end if")
	  End if	  
      Str=Replace(Str,Match.value,r1)
     Next
  End If
  Set Reg=nothing
  set Matches=nothing
  Cw_if=Str
  Call Cw_err("Cw_if")
End Function

'//去除Html
Function cw_nohtml(str)
  Set re=new RegExp 
  re.IgnoreCase =True 
  re.Global=True 
  re.Pattern="(\<.[^\<]*\>)" 
  str=re.replace(str," ") 
  re.Pattern="(\<\/[^\<]*\>)" 
  str=re.replace(str,"") 
  str=replace(str," ","") 
  str=replace(str,"　　","")
  str=replace(str,chr(32),"")
  str=replace(str,chr(8),"")
  str=replace(str,chr(9),"")
  str=replace(str,chr(10),"")
  str=replace(str,chr(11),"")
  str=replace(str,chr(13),"")
  str=replace(str,"&nbsp;","")
  cw_nohtml=str 
  Set re=Nothing 
End Function

'//时间格式化(时间，格式yy-mm-dd)
function cw_date(t3,t5) 
    if isdate(t3) then 
	t4=Replace(t5,"yyyy",Year(t3))
	t4=Replace(t4,"yy",Right(Year(t3),2))
	t4=Replace(t4,"mm",Right("0"&Month(t3),2))
	t4=Replace(t4,"dd",Right("0"&Day(t3),2))
	t4=Replace(t4,"hh",Right("0"&Hour(t3),2))
	t4=Replace(t4,"ff",Right("0"&Minute(t3),2))
	t4=Replace(t4,"ss",Right("0"&Second(t3),2))
	t4=Replace(t4,"m",Month(t3))
	t4=Replace(t4,"d",Day(t3))
	t4=Replace(t4,"h",Hour(t3))
	t4=Replace(t4,"f",Minute(t3))
	t4=Replace(t4,"s",Second(t3))
    cw_date=t4
	else
	response.Write("请检查日期标签！")
	response.End()
	end if
end function

'sContent ---- 被截取的内容
'sStart ------ 首字符串
'sOver ------- 尾字符串
'iType ------- 类型（1：不包含首尾字符串；2：包含首尾字符串；3：包含首、不包含尾；4：不包含首、包含尾）
Function cw_cut(sContent, sStart, sOver, iType)
	Dim iStart, iOver
	iStart = InStr(sContent,sStart)
	iOver  = InStr(iStart+Len(sStar),sContent,sOver)
	If iStart>0 And iOver>0 Then
		Select Case iType
			Case 1 iStart = iStart+Len(sStart)
			Case 2 iOver  = iOver+Len(sOver)
			Case 4 iStart = iStart+Len(sStart):iOver = iOver+Len(sOver)
		End Select		
		cw_cut = Mid(sContent,iStart,iOver-iStart)
	Else
		cw_cut = "没有找到您想要的内容，可能您设定的首尾字符串不存在！"
	End If
End function

'获取内容中第一个图片
Function Frist_Pic(t0)
	Frist_Pic=""
	Dim Regs,Matches
	Set Regs=New RegExp
	Regs.Ignorecase=True
	Regs.Global=True
	Regs.Pattern="<img[^>]+src=""([^"">]+)""[^>]*>"
	Set Matches=Regs.Execute(t0)
	IF Regs.test(t0) Then
	   Frist_Pic=Matches(0).SubMatches(0)
	End IF
	Set Matches=Nothing
	Set Regs=Nothing
End Function

'//show_user
Function Cw_showuser(str,uid)
  On error resume next 
  Set Rs=Server.CreateObject("Adodb.RecordSet")
  Sql="Select * From Cw_user Where Id="&uid
  Rs.Open Sql,Conn,1,1
  Call Cw_err("Cw_showuser")
  If Not Rs.eof then
  Str=Replace(Str,"{cw:show_userid}",Rs("id"))
  Str=Replace(Str,"{cw:show_user}",Rs("user"))
  Str=Replace(Str,"{cw:show_userpic}",Rs("pic"))
  Str=Replace(Str,"{cw:show_usergrade}",Cw_grade(Rs("grade")))
  Else
  Str=Replace(Str,"{cw:show_userid}""")
  Str=Replace(Str,"{cw:show_user}","")
  Str=Replace(Str,"{cw:show_userpic}","")
  Str=Replace(Str,"{cw:show_usergrade}","")
  End If
  Rs.Close
  Set Rs=Nothing
  Cw_showuser=Str
End Function
'//错误提示
Function Cw_err(Str)
  If Err.Number<>0 then
     Response.Write(Str&"<br>"&Err.Description)
	 Err.Clear
	 Response.End()
  End If
End Function

'//删除目录
function del_folder(t0)
	Set Fso=Server.CreateObject("Scrip"&"ting."&"File"&"System"&"Object")
	Set F=Fso.GetFolder(Server.MapPath(t0))
	IF Not IsNull(t0) Then F.Delete True
	IF Err Then
		IF Err.Number<>70 and Err.Number<>424 Then
			response.Write("Del_Folder："&Err.Description)
		End IF
		Err.Clear
	End IF
	Set Fso=Nothing
end function
'//JMail
'参数：发送邮件SMTP服务器， 发件人邮箱地址， 发件人姓名， 发送邮件服务器登录名， 发送邮件服务器登录密码， 接收人邮件地址， 邮件标题， 邮件内容
Function Cw_jmail(s_smtp, s_fmail, s_fname, s_jmailUser, s_jmailPass, s_tmail, s_subject, s_body)
    On Error Resume Next
    Set jmail = Server.CreateObject("JMAIL.Message")   '建立发送邮件的对象
    If Err.Number <> 0 Then
        Cw_jmail = 1
        Exit Function
    End If
    jmail.silent = True
    jmail.logging = False
    jmail.Charset = "GB2312"
    jmail.ISOEncodeHeaders = False
    jmail.ContentType = "text/html"
    jmail.AddRecipient s_tmail
    jmail.From = s_fmail
    jmail.FromName = s_fname
    jmail.MailServerUserName = s_jmailUser
    jmail.MailServerPassword = s_jmailPass
    jmail.Subject = s_subject
    jmail.Body = s_body
    jmail.Priority = 1
    jmail.Send(s_smtp)
    jmail.Close()    
    If jmail.ErrorCode <> 0 Then
        Cw_jmail = 2
    Else
        Cw_jmail = 0
    End If
End Function

'//生成随机字符串
Function Cw_rnd(rn)
		randomize
		dim n1,n2,n3
		do while len(Cw_rnd)<rn '随机字符位数 
			n1=cstr(chrw((57-48)*rnd+48)) '0~9 
			n2=cstr(chrw((90-65)*rnd+65)) 'a~z 
			n3=cstr(chrw((122-97)*rnd+97)) 'a~z 
			Cw_rnd=Cw_rnd&n1&n2&n3 
		loop
End function

'//组件判断
Function Cw_commons(obj) 
  On Error Resume Next 
  Set IsObj = Server.CreateObject(obj) 
  if Err = 0 then 
     Cw_commons=True
  else 
     Cw_commons=false
  end If 
  Set IsObj = Nothing 
  If Err <> 0 Then Err.Clear 
End Function
%>
