<!--#include file="Conn.asp"--><%
Checklogin("")

't0 内容，t1将什么，t2,替换成什么，t3替换的次数
function sitelink_replace(byval t0,byval t1,byval t2,byval t3)
	If t0="" Or IsNull(t0) Then Exit Function
	dim t4:t4=t0

	reg.pattern="(\<a[^<>]+\>.+?\<\/a\>)|(\<img[^<>]+\>)|(\<h[1-6]+[\s]*\>.+?\<\/h[1-6]+\>)"
	set matches=reg.execute(t4)
	dim i:i=0
	dim myarray()
	if matches.count>0 then
		for each match in matches
			redim preserve myarray(i)
			myarray(i)=mid(match.value,1,len(match.value))
			t4=replace(t4,match.value,"["&i&"]",1,t3)
			i=i+1
		next
	end if
	if i=0 Then
		t0=replace(t0,t1,t2,1,t3)
		sitelink_replace=t0
		'Set reg=Nothing
		exit function
	end if
	t4=replace(t4,t1,t2,1,t3)
	for i=0 to ubound(myarray)
		t4=replace(t4,"["&i&"]",myarray(i),1,t3)
	next
	sitelink_replace=t4
end function


Act = Request.QueryString("act")



If act="setlink" Then

Set reg=New Regexp
reg.Ignorecase=True
reg.Global=True


	Set Rs=Server.CreateObject("ADODB.RecordSet")

	setlinkname=""
	setlinktemplate=""
	setlinkreplace=""
	Rs.Open "Select sname,stitle,surl,sreplace,starget From setlink Where sstate>0 Order By sord Desc,id Desc",Conn,1,1
	Do While Not Rs.Bof And Not Rs.Eof
		sname=Rs("sname"):stitle=Rs("stitle"):surl=Rs("surl"):sreplace=Rs("sreplace"):starget=Rs("starget")
		setlinkname=setlinkname & sname &"<|>"
		If starget=0 Then
			setlinktemplate = setlinktemplate & "<a href="""&surl&""" title="""&stitle&""">"&sname&"</a>" & "<|>"
		Else
			setlinktemplate = setlinktemplate & "<a href="""&surl&""" title="""&stitle&""" target=""_blank"">"&sname&"</a>" & "<|>"
		End If
		If sreplace<=0 Then
			setlinkreplace=setlinkreplace & "-1<|>"
		Else
			setlinkreplace=setlinkreplace & sreplace &"<|>"
		End If
	Rs.MoveNext
	Loop	
	Rs.Close

	setlinknameArr=split(setlinkname,"<|>")
	setlinktemplateArr=split(setlinktemplate,"<|>")
	setlinkreplaceArr=split(setlinkreplace,"<|>")

	Rs.Open "Select xxjs,xxjssetlink From cp",Conn,1,3
	Do While Not Rs.Bof And Not Rs.Eof
		xxjs=HTMLUnCode(Rs("xxjs"))
		For i=0 To Ubound(setlinknameArr)-1
			xxjs = sitelink_replace(xxjs,setlinknameArr(i),setlinktemplateArr(i),setlinkreplaceArr(i))			
		Next
		Rs("xxjssetlink")=HTMLEnCode(xxjs)
		Rs.Update
	Rs.MoveNext
	Loop
	Rs.Close

Set reg=Nothing
Set Rs=Nothing:Conn.Close:Set Conn=Nothing
Response.Write "<script>alert('添加成功');location.href='?'</script>"
Response.End
End If




If act="setlink1" Then

Set reg=New Regexp
reg.Ignorecase=True
reg.Global=True


	Set Rs=Server.CreateObject("ADODB.RecordSet")

	setlinkname=""
	setlinktemplate=""
	setlinkreplace=""
	Rs.Open "Select sname,stitle,surl,sreplace,starget From setlink Where sstate>0 Order By sord Desc,id Desc",Conn,1,1
	Do While Not Rs.Bof And Not Rs.Eof
		sname=Rs("sname"):stitle=Rs("stitle"):surl=Rs("surl"):sreplace=Rs("sreplace"):starget=Rs("starget")
		setlinkname=setlinkname & sname &"<|>"
		If starget=0 Then
			setlinktemplate = setlinktemplate & "<a href="""&surl&""" title="""&stitle&""">"&sname&"</a>" & "<|>"
		Else
			setlinktemplate = setlinktemplate & "<a href="""&surl&""" title="""&stitle&""" target=""_blank"">"&sname&"</a>" & "<|>"
		End If
		If sreplace<=0 Then
			setlinkreplace=setlinkreplace & "-1<|>"
		Else
			setlinkreplace=setlinkreplace & sreplace &"<|>"
		End If
	Rs.MoveNext
	Loop	
	Rs.Close

	setlinknameArr=split(setlinkname,"<|>")
	setlinktemplateArr=split(setlinktemplate,"<|>")
	setlinkreplaceArr=split(setlinkreplace,"<|>")

	Rs.Open "Select infocontent,infocontentsetlink From info",Conn,1,3
	Do While Not Rs.Bof And Not Rs.Eof
		infocontent=HTMLUnCode(Rs("infocontent"))
		For i=0 To Ubound(setlinknameArr)-1
			infocontent = sitelink_replace(infocontent,setlinknameArr(i),setlinktemplateArr(i),setlinkreplaceArr(i))			
		Next
		Rs("infocontentsetlink")=HTMLEnCode(infocontent)
		Rs.Update
	Rs.MoveNext
	Loop
	Rs.Close

Set reg=Nothing
Set Rs=Nothing:Conn.Close:Set Conn=Nothing
Response.Write "<script>alert('添加成功');location.href='?'</script>"
Response.End
End If

If act="esclink" Then
Conn.ExeCute("Update cp Set xxjssetlink=''")
Conn.Close:Set Conn=Nothing
Response.Write "<script>alert('去除成功');location.href='?'</script>":Response.End
End If

If act="esclink1" Then
Conn.ExeCute("Update info Set infocontentsetlink=''")
Conn.Close:Set Conn=Nothing
Response.Write "<script>alert('去除成功');location.href='?'</script>":Response.End
End If
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理区域</title>
<link rel="stylesheet" href="css/common.css" type="text/css" />
<script language="javascript" src="js/jquery-1.7.2.min.js"></script>
<script>
function setlink(){
	if(!confirm('确定要为所有产品内容添加内链吗？')){return false}
	$("#btn1,#btn2,#btn3,#btn4").attr("disabled","disabled");
	$("#msg").html('正在为所有产品内容添加内链，请稍候。。。');
	location.href='?act=setlink';
}
function esclink(){
	if(!confirm('确定要去除所有产品内容内链吗？')){return false}
	$("#btn1,#btn2,#btn3,#btn4").attr("disabled","disabled");
	$("#msg").html('正在去除所有产品内容内链，请稍候。。。');
	location.href='?act=esclink';
}
function setlink1(){
	if(!confirm('确定要为所有信息内容添加内链吗？')){return false}
	$("#btn1,#btn2,#btn3,#btn4").attr("disabled","disabled");
	$("#msg").html('正在为所有信息内容添加内链，请稍候。。。');
	location.href='?act=setlink1';
}
function esclink1(){
	if(!confirm('确定要去除所有信息内容内链吗？')){return false}
	$("#btn1,#btn2,#btn3,#btn4").attr("disabled","disabled");
	$("#msg").html('正在去除所有信息内容内链，请稍候。。。');
	location.href='?act=esclink1';
}
</script>
</head>
<body>
<div id="man_zone">
<input type="button" value="为所有产品内容添加内链" id="btn1" onClick="setlink()" />
<input type="button" value="去除所有产品内容内链" id="btn2" onClick="esclink()" /><br /><br />
<input type="button" value="为所有信息内容添加内链" id="btn3" onClick="setlink1()" />
<input type="button" value="去除所有信息内容内链" id="btn4" onClick="esclink1()" />
<div id="msg" style="color:red;font-size:18px;font-family:'微软雅黑','黑体';padding:20px"></div>
</body>
</html><%Conn.Close:Set Conn=Nothing%>
