<!--#include file="../../lib/base.asp"-->
<!--#include file="../../lib/cmd.asp"-->
<!--#include file="../../lib/class/eycms.clsxml.asp"-->
<%
''' SEO云链系统
''' ==================================================================
	eycms.stophack
	'注释：插件是否安装
	is_plug_install "eycms.plug.links_user"
	
	'注释：管理权限检查
	is_plug_login
	
	'注释：定义插件模板路径
	dim theme_admin_root:theme_admin_root="admin_leo"
	dim plug_theme
	plug_theme="module/plug_links_user/downlist.html"
	dim apiUrl_,ajaxUrl
	apiUrl_="http://www.eycms.cn/"
	dim errnum:errnum=0

	'注释：删除附件
	sub deldb()
		dim xml:xml=eycms.enhtml(eycms.fget("xml",0))
		'注释：删除此文件
		eycms.delfile webroot&"plug/links_user/xml/"&site_root&"/"&xml
		eycms.echo "1"
	end Sub

	'注释：导入文件
	sub importdb()
		on error resume Next
		dim cid:cid=eycms.db.dbloadone("classid","ey_expand_class","followid=1 and classname='云链'")
		dim xmlfile:xmlfile=eycms.enhtml(eycms.fget("xml",0))
		dim xml,i,item,fname
		dim x_siteid,x_name,x_cate,x_seokey,x_url,x_exchange,x_iscross,x_lockcate,x_bend,x_limit,x_br,x_baidu,x_needbr,x_needbaidu,x_qq,x_zt,x_addtime
		dim data,m
		m=0
		set xml=server.createobject("microsoft.xmldom")
		xml.async=false

		fname=webroot&"plug/links_user/xml/"&xmlfile
		xml.load(server.mappath(fname))
		set item=xml.getElementsByTagName("item")
		for i=0 to (item.length-1)
			x_siteid=item.item(i).getElementsByTagName("siteid").item(0).text
			x_name=item.item(i).getElementsByTagName("name").item(0).text
			x_cate=item.item(i).getElementsByTagName("cate").item(0).text
			x_seokey=item.item(i).getElementsByTagName("seokey").item(0).text
			x_url=item.item(i).getElementsByTagName("url").item(0).text
			x_exchange=item.item(i).getElementsByTagName("exchange").item(0).text
			x_iscross=item.item(i).getElementsByTagName("iscross").item(0).text
			x_lockcate=item.item(i).getElementsByTagName("lockcate").item(0).text
			x_bend=item.item(i).getElementsByTagName("bend").item(0).text
			x_limit=item.item(i).getElementsByTagName("limit").item(0).text
			x_br=item.item(i).getElementsByTagName("br").item(0).text
			x_baidu=item.item(i).getElementsByTagName("baidu").item(0).text
			x_needbr=item.item(i).getElementsByTagName("need_br").item(0).text
			x_needbaidu=item.item(i).getElementsByTagName("need_baidu").item(0).text
			x_qq=item.item(i).getElementsByTagName("qq").item(0).text
			x_zt=item.item(i).getElementsByTagName("zt").item(0).text
			x_addtime=item.item(i).getElementsByTagName("addtime").item(0).text

			if eycms.db.dbcount("ey_plug_links_server","siteid='"&x_siteid&"'")=0 Then
				if cint(x_zt)<>4 then
					data=array(array("siteid",x_siteid,255,1),array("name",x_name,255,1),array("cate",x_cate,0,0),array("seokey",x_seokey,255,1),array("url",x_url,255,1),array("exchange",x_exchange,1,0),array("iscross",x_iscross,1,0),array("lockcate",x_lockcate,1,0),array("bend",x_bend,0,0),array("limit",x_limit,0,0),array("br",x_br,1,0),array("baidu",x_baidu,10,0),array("need_br",x_needbr,1,0),array("need_baidu",x_needbaidu,10,0),array("qq",x_qq,20,1),array("zt",x_zt,1,0),array("addtime",x_addtime,50,1))
					eycms.db.insert "ey_plug_links_server",data
					m=m+1
				end if
			else
				if cint(x_zt)<>4 then
					data=array(array("name",x_name,255,1),array("cate",x_cate,0,0),array("seokey",x_seokey,255,1),array("url",x_url,255,1),array("exchange",x_exchange,1,0),array("iscross",x_iscross,1,0),array("lockcate",x_lockcate,1,0),array("bend",x_bend,0,0),array("limit",x_limit,0,0),array("br",x_br,1,0),array("baidu",x_baidu,10,0),array("need_br",x_needbr,1,0),array("need_baidu",x_needbaidu,10,0),array("qq",x_qq,20,1),array("zt",x_zt,1,0),array("addtime",x_addtime,50,1))
					eycms.db.dbupdate "ey_plug_links_server","siteid='"&x_siteid&"'",data
				else
					data=eycms.db.dbload(1,"linkid","ey_plug_links_linkto","tosid='"&x_siteid&"'","")
					if ubound(data)>=0 then
						eycms.db.dbdel "ey_plug_links_linkto","linkid="&data(0,0)&""
						if cid>0 then
							eycms.db.dbdel "ey_expand_link","classid="&cid&" and weblogo='"&data(0,0)&"'"
						end if
					end if
					eycms.db.dbdel "ey_plug_links_server","siteid='"&x_siteid&"'"
				end if
			end if

		Next
		eycms.newfile webroot&"plug/links_user/xml/"&site_root&"/","version.txt",now(),"utf-8"
		if m>0 then
			eycms.echo "1成功导入"&m&"条新记录"
		else
			eycms.echo "1记录已更新"
		end if	
		if err then
			eycms.errlog "函数：loadall<br>详情："&err.description,0
			eycms.echo "0发生错误："&err.description
			err.clear
		End if
	end Sub

	function getxmlname(byval t0)
		select case right(t0,7)
		case "_01.xml"
			getxmlname="1~500条"
		case "_02.xml"
			getxmlname="501~1000条"
		case "_03.xml"
			getxmlname="1001~1500条"
		case "_04.xml"
			getxmlname="1501~2000条"
		case "_05.xml"
			getxmlname="2001~2500条"
		case "_06.xml"
			getxmlname="2501~3000条"	
		case "_07.xml"
			getxmlname="3001~3500条"
		case "_08.xml"
			getxmlname="3501~4000条"
		case "_09.xml"
			getxmlname="4001~4500条"
		case "_10.xml"
			getxmlname="4501~5000条"
		case "_11.xml"
			getxmlname="5001~5500条"
		case "_12.xml"
			getxmlname="5501~6000条"
		case "_13.xml"
			getxmlname="6001~6500条"
		case "_14.xml"
			getxmlname="6501~7000条"
		case "_15.xml"
			getxmlname="7001~7500条"
		case "_16.xml"
			getxmlname="7501~8000条"	
		case "_17.xml"
			getxmlname="8001~8500条"
		case "_18.xml"
			getxmlname="8501~9000条"
		case "_19.xml"
			getxmlname="9001~9500条"
		case "_20.xml"
			getxmlname="9501~10000条"
		end select
	end function

	sub dotpldb(byval t0,byval t1)
		on error resume Next
		dim html,i
		for i=1 to 20
			if apiUrl_="http://www.eycms.cn/" then
				html=eycms.gethttp(apiUrl_&"plug/links/xml/tpl_ey_plug_links_customer_"&right("0"&i,2)&".xml","")
			else
				html=eycms.gethttp(apiUrl_&"plug/links_user/xml/tpl_ey_plug_links_customer_"&right("0"&i,2)&".xml","")
			end if
			if html<>"ERR" then
				eycms.newfile webroot&"plug/links_user/xml/","tpl_ey_plug_links_customer_"&right("0"&i,2)&".xml",html,"utf-8"
				setstatus "正在载入第<span>"&i&"</span>个文件",i,10
				response.flush()
			else
				if i=1 then
					ajaxUrl=getApiUrl
					if eycms.strlen(ajaxUrl)>0 then
						dotpldb "ey_plug_links_customer", "*"
					else
						exit for
					end if
				else
					exit for
				end if
			end if
		next
		if err then
			errnum = 1
			seterror "发生错误，错误内容为：<span>"&err.description&"</span>"
			response.flush()
		end if
	end Sub

	function getApiUrl()
		getApiUrl=eycms.gethttp(apiUrl_&"plug/links/send/getapiurl.asp?h="&http_host,"")
		if getApiUrl="ERR" then getApiUrl=""
	end function

	function getversion_my()
		if eycms.isfile(webroot&"plug/links_user/xml/"&site_root&"/version.txt") then
			getversion_my=eycms.loadfile(webroot&"plug/links_user/xml/"&site_root&"/version.txt")
		else
			getversion_my=""
		end if
	end function

	function getversion()
		getversion=eycms.gethttp(apiUrl_&"plug/links/xml/version.txt","")
		if getversion="ERR" then getversion=""
	end function

	function isnewversion()
		isnewversion=false
		dim myvs,remotevs
		myvs=getversion_my
		remotevs=getversion
		if eycms.strlen(myvs)>0 and eycms.strlen(remotevs)>0 then
			if DateDiff("d",myvs,remotevs)>0 then isnewversion=true
		end if
	end function

	dim act:act=lcase(eycms.fget("act",0))
	select case act
		case "del":deldb
		case "import":importdb
		case "do"
			eycms.echo "<script src=""../../lib/js/jquery.js""></script>"&vbcrlf
			eycms.newfolder webroot&"plug/links_user/xml/"
			ajaxUrl=apiUrl_
			dotpldb "ey_plug_links_customer", "*"
			If errnum=0 Then 
				setstatus "导入完毕",1,1
				eycms.echo "<script>parent.importfirst();</script>"
				response.flush()
			End if
		case else:load plug_theme
	end Select
	eycms.db.dbclose

	Function FieldTypeName(num)
		If datatype = true then
			Select Case num
			Case 7,202,203
				FieldTypeName = "text"
			Case else
				FieldTypeName = "int"
			End Select
		Else
			Select Case num
			Case 129,130,135,200,201,202,203
				FieldTypeName = "text"
			Case else
				FieldTypeName = "int"
			End Select
		End if
	End Function
	
	sub setstatus(byval t0,byval t1,byval t2)
		on error resume next
		dim str:str="<script>"&vbcrlf
		str=str&"$(""#create_text"",window.parent.document).html("""&t0&""");"&vbcrlf
		str=str&"$(""#create_staus"",window.parent.document).css(""border"",""1px solid #91B6E5"");"&vbcrlf
		str=str&"$(""#create_percent"",window.parent.document).css(""background"",""#91B6E5"");"&vbcrlf
		str=str&"$(""#create_percent"",window.parent.document).css(""color"",""#fff"");"&vbcrlf
		str=str&"$(""#create_percent"",window.parent.document).css(""width"",parseInt("&t1/t2&"*100)+""%"");"&vbcrlf
		str=str&"$(""#create_percent"",window.parent.document).html(parseInt("&t1/t2&"*100)+""%"");"&vbcrlf
		str=str&"</script>"&vbcrlf
		eycms.echo str
		response.flush()
		err.clear
	end sub
	
	sub seterror(byval t0)
		dim str:str="<script>"&vbcrlf
		str=str&"$(""#create_text"",window.parent.document).html("""");"&vbcrlf
		str=str&"$(""#create_staus"",window.parent.document).css(""border"",""1px solid #f00"");"&vbcrlf
		str=str&"$(""#create_percent"",window.parent.document).css(""background"",""#f00"");"&vbcrlf
		str=str&"$(""#create_percent"",window.parent.document).css(""color"",""#fff"");"&vbcrlf
		str=str&"$(""#create_percent"",window.parent.document).css(""width"",""100%"");"&vbcrlf
		str=str&"$(""#create_percent"",window.parent.document).html(""发生错误："&t0&""");"&vbcrlf
		str=str&"</script>"&vbcrlf
		eycms.echo str
		response.flush()
	end sub
%>
