<!--#include file="../../../lib/base.asp"-->
<%
''' SEO云链系统
''' ==================================================================
	eycms.stophack

	
	'接收fget传值
	dim act:act=lcase(eycms.fget("act",0))
	dim data,json,token
	dim my_token,my_exchange
	data=eycms.db.dbload(1,"token,exchange","ey_plug_links_site","sid>0","")
	if ubound(data)>=0 then
		my_token=data(0,0)
		my_exchange=data(1,0)
	end if
	if my_exchange="" then my_exchange=0

	select case act
		case "sitesh"
			set json=toobject(request.form)
			token = json.token
			set json=nothing
			if token=my_token then
				eycms.db.dbupdate "ey_plug_links_site","sid>0",array(array("zt",1,1,0))
				eycms.echo "1" & token
			else 
				eycms.echo "0"
			end if
		case "sendlink":sendlinkdb
		case "shenhelink":shenhelinkdb
		case "sendlinkdel":sendlinkdeldb
		case "sendlinkedit":sendlinkeditdb
	end select

	'保存同步过来的链接
	sub sendlinkdb()
		on error resume Next
		dim sid,tosid,linktxt,linkurl
		set json=toobject(request.form)
		token = json.token
		sid = json.sid
		tosid = json.tosid
		linktxt = json.linktxt
		linkurl = json.linkurl
		set json=nothing
		if token<>my_token then
			getjson 101,"同步失败！秘钥错误！":exit sub
		end if
		if eycms.strlen(sid)=0 then getjson 102,"同步失败！被链站点为空！":exit sub
		if eycms.strlen(tosid)=0 then getjson 102,"同步失败！链出站点为空！":exit sub
		if eycms.strlen(linktxt)=0 then getjson 102,"同步失败！链接关键字为空！":exit sub
		if eycms.strlen(linkurl)=0 then getjson 102,"同步失败！链出网址为空！":exit sub
		dim data,addtime
		addtime=now()
		data=array(array("linklx",0,1,0),array("sid",sid,255,1),array("tosid",tosid,255,1),array("linktxt",linktxt,255,1),array("linkurl",linkurl,255,1),array("syno",1,1,0),array("linkzt",my_exchange,1,0),array("linkTime",addtime,50,1))
		if eycms.db.dbnew("ey_plug_links_linkto",data,"(sid='"&sid&"' and tosid='"&tosid&"') or (tosid='"&sid&"' and sid='"&tosid&"')")=0 then
			eycms.db.dbupdate "ey_plug_links_linkto","(sid='"&sid&"' and tosid='"&tosid&"') or (tosid='"&sid&"' and sid='"&tosid&"')",array(array("syno",1,1,0))
			getjson 2,"同步成功！":exit sub
		end if
		
		if my_exchange=1 then
			dim linkid:linkid=eycms.db.insertid("linkid","ey_plug_links_linkto")
			dim linkclassid
			linkclassid=eycms.db.dbloadone("classid","ey_expand_class","followid=1 and classname='云链'")
			data=array(array("webname",linktxt,52,1),array("weburl",linkurl,255,1),array("weblogo",linkid,255,1),array("islogo",0,1,0),array("classid",linkclassid,0,0),array("islock",1,0,0))
			eycms.db.insert "ey_expand_link",data
		end if

		getjson 1,"同步成功！"
		if err then
			eycms.errlog "函数：sendlinkdb<br>详情："&err.description,0
			eycms.echo "0发生错误："&err.description
			err.clear
		End if
	end sub	

	'审核同步过来的链接
	sub shenhelinkdb()
		on error resume Next
		dim sid,tosid,linktxt,linkurl
		set json=toobject(request.form)
		token = json.token
		sid = json.sid
		tosid = json.tosid
		linktxt = json.linktxt
		linkurl = json.linkurl
		set json=nothing
		if token<>my_token then
			getjson 101,"同步失败！秘钥错误！":exit sub
		end if
		dim data
		dim linkid
		data=eycms.db.dbload(1,"linkid","ey_plug_links_linkto","(sid='"&sid&"' and tosid='"&tosid&"') or (tosid='"&sid&"' and sid='"&tosid&"')","")
		if ubound(data)>=0 then
			linkid=data(0,0)
			dim linkclassid
			linkclassid=eycms.db.dbloadone("classid","ey_expand_class","followid=1 and classname='云链'")
			data=array(array("webname",linktxt,52,1),array("weburl",linkurl,255,1),array("weblogo",linkid,255,1),array("islogo",0,1,0),array("classid",linkclassid,0,0),array("islock",1,0,0))
			eycms.db.insert "ey_expand_link",data

			eycms.db.dbupdate "ey_plug_links_linkto","linkid="&linkid&"",array(array("linkzt",1,1,0))
			getjson 1,"同步成功！"
		else
			getjson 101,"同步失败！"
		end if
	end sub	

	'删除同步过来的链接
	sub sendlinkdeldb()
		on error resume Next
		dim sid,tosid
		set json=toobject(request.form)
		token = json.token
		sid = json.sid
		tosid = json.tosid
		set json=nothing
		if token<>my_token then
			getjson 101,"同步失败！秘钥错误！":exit sub
		end if
		if eycms.strlen(sid)=0 then getjson 102,"同步失败！被链站点为空！":exit sub
		if eycms.strlen(tosid)=0 then getjson 102,"同步失败！链出站点为空！":exit sub

		dim data
		data=eycms.db.dbload(1,"linkid","ey_plug_links_linkto","(sid='"&sid&"' and tosid='"&tosid&"') or (tosid='"&sid&"' and sid='"&tosid&"')","")
		if ubound(data)>=0 then
			eycms.db.dbdel "ey_plug_links_linkto","linkid="&data(0,0)&""
			dim cid:cid=eycms.db.dbloadone("classid","ey_expand_class","followid=1 and classname='云链'")
			if cid>0 then
				eycms.db.dbdel "ey_expand_link","classid="&cid&" and weblogo='"&data(0,0)&"'"
			end if
		end if
		getjson 1,"同步成功！"
		if err then
			eycms.errlog "函数：sendlinkdeldb<br>详情："&err.description,0
			eycms.echo "0发生错误："&err.description
			err.clear
		End if
	end sub	

	'更新同步过来的链接
	sub sendlinkeditdb()
		on error resume Next
		dim sid,tosid,seokey
		set json=toobject(request.form)
		token = json.token
		sid = json.sid
		tosid = json.tosid
		seokey = json.seokey
		set json=nothing
		if token<>my_token then
			getjson 101,"同步失败！秘钥错误！":exit sub
		end if
		if eycms.strlen(sid)=0 then getjson 102,"同步失败！被链站点为空！":exit sub
		if eycms.strlen(tosid)=0 then getjson 102,"同步失败！链出站点为空！":exit sub
		if eycms.strlen(seokey)=0 then getjson 102,"同步失败！关键词为空！":exit sub

		dim data
		data=eycms.db.dbload(1,"linkid","ey_plug_links_linkto","sid='"&sid&"' and tosid='"&tosid&"'","")
		if ubound(data)>=0 then
			eycms.db.dbupdate "ey_plug_links_linkto","linkid="&data(0,0),array(array("linktxt",seokey,255,1))
			dim cid:cid=eycms.db.dbloadone("classid","ey_expand_class","followid=1 and classname='云链'")
			if cid>0 then
				eycms.db.dbupdate "ey_expand_link","classid="&cid&" and weblogo='"&data(0,0)&"'",array(array("webname",seokey,255,1))
			end if
		else
			getjson 101,"同步失败！记录不存在！":exit sub
		end if
		getjson 1,"同步成功！"
		if err then
			eycms.errlog "函数：sendlinkdeldb<br>详情："&err.description,0
			eycms.echo "0发生错误："&err.description
			err.clear
		End if
	end sub	

	sub getjson(byval t0,byval t1)
		eycms.echo "{""state"":"""&t0&""",""msg"":"""&t1&"""}"
	end sub

	eycms.db.dbclose
%>
<script language="jscript" runat="server">
	function toobject(json){eval("var o="+json);return o;}
</script>