<!--#include file="../../lib/base.asp"-->
<!--#include file="../../theme.asp"-->
<!--#include file="../../lib/cmd.asp"-->
<!--#include file="common.asp"-->
<%
''' 排名监控插件
''' ==================================================================
	'注释：插件是否安装
	is_plug_install "eycms.plug.seoset"
	
	'注释：管理权限检查
	is_plug_login
	
	'注释：定义插件模板路径
	dim theme_admin_root:theme_admin_root="admin_leo"
	dim plug_theme,plug_theme_add,plug_theme_edit
	dim plug_theme_city,plug_theme_cityadd,plug_theme_cityedit,plug_theme_cityeditTpl
	plug_theme="module/plug_seoset/list.html"
	plug_theme_add="module/plug_seoset/add.html"
	plug_theme_edit="module/plug_seoset/edit.html"
	plug_theme_city="module/plug_seoset/city.html"
	plug_theme_cityadd="module/plug_seoset/cityadd.html"
	plug_theme_cityedit="module/plug_seoset/cityedit.html"
	plug_theme_cityeditTpl="module/plug_seoset/cityeditTpl.html"
	
	'接收fget传值
	dim act:act=lcase(eycms.fget("act",0))
	dim id:id=eycms.getint(eycms.fget("id",0),0)
	dim lx:lx=eycms.getint(eycms.fget("lx",0),1)
	dim data
	dim isindex:isindex="yes"
	dim classid:classid=0
	dim root:root="index"
	dim htmlrule:htmlrule=webroot&root&"/[page]/"
	dim islocal:islocal=0
	if eycms.isfolder(webroot&"theme/"&theme_root&"/model") then islocal=1

	select case act
		case "english":english
		case "add"
			load plug_theme_add
		case "adddb":adddb
		case "edit"
			data=eycms.db.dbload(1,"classid,seoTit,seoWord,seoDesc,zt,lx","ey_plug_seoset","id="&id&"","")
			if isarray(data) then
	            dim arr
	            if instr(data(2,0),",") then
	            	arr=split(data(2,0),",")
	            else
	            	redim arr(10)
	            	arr(0)=data(2,0)
	            end if
	        end if
			load plug_theme_edit
		case "editdb":editdb
		case "del":deldb
		case "cityadd"
			load plug_theme_cityadd
		case "cityadddb":cityadddb
		case "cityedit"
			data=eycms.db.dbload(1,"city,htmlname,parentid,replacetxt,replaceto,zt","ey_plug_seocity","id="&id&"","")
			load plug_theme_cityedit
		case "citycreat":citycreatdb
		case "cityeditdb":cityeditdb
		case "citydel":citydeldb
		case "cityedittpl"
			dim filename:filename=eycms.fget("filename",0)
			if not(eycms.checkstr(filename,"filename")) then
				eycms.echo "filename is wrong act.edit1"
				eycms.die
			end if
			if not(eycms.isfile(webroot&"theme/"&theme_root&"/city/"&filename)) then
				eycms.echo "filename is wrong act.edit2"
				eycms.die
			end if

			dim temp_content:temp_content=eycms.loadfile(webroot&"theme/"&theme_root&"/city/"&filename)
			dim r_mid:r_mid="<%"
			r_mid=r_mid&"if not in_eycms then response.write(""template load fail""):response.end() end if"
			r_mid=r_mid&"%"
			r_mid=r_mid&">"
			temp_content=replace(temp_content,r_mid,"")

			load plug_theme_cityeditTpl
		case "cityedittpldb":cityedittpldb
		case "city":load plug_theme_city
		case else
			load plug_theme
	end select	

	'保存SEO设置
	sub adddb()
		dim t0,t1,t2,t3,t4,t5,i
		t0=eycms.getint(eycms.fpost("t0",0),0)
		t1=eycms.enhtml(eycms.fpost("t1",0))
		t2=eycms.enhtml(eycms.fpost("t2",0))
		t3=eycms.enhtml(eycms.fpost("t3",0))
		t4=eycms.getint(eycms.fpost("t4",0),0)
		t5=eycms.getint(eycms.fpost("t5",0),0)
		if eycms.strlen(t0)=0 then eycms.ajaxjson "所属栏目不能为空",0:exit sub
		dim data,ddata
		data=array(array("classid",t0,0,0),array("seoTit",t1,255,1),array("seoWord",t2,255,1),array("seoDesc",t3,255,1),array("zt",t4,0,0),array("lx",t5,1,0))
		if eycms.db.dbnew("ey_plug_seoset",data,"lx="&t5&"&classid="&t0)=0 then
			eycms.ajaxjson "该栏目优化设置已存在，请换个试试",0:exit sub
		end if
		eycms.ajaxjson "保存成功",1
	end sub	

	'编辑
	sub editdb
		dim t0,t1,t2,t3,t4,t5
		t0=eycms.getint(eycms.fpost("t0",0),0)
		t1=eycms.enhtml(eycms.fpost("t1",0))
		t2=eycms.enhtml(eycms.fpost("t2",0))
		t3=eycms.enhtml(eycms.fpost("t3",0))
		t4=eycms.getint(eycms.fpost("t4",0),0)
		t5=eycms.getint(eycms.fpost("t5",0),0)
		if eycms.strlen(t0)=0 then eycms.ajaxjson "所属栏目不能为空",0:exit sub
		dim data,id,ddata
		id=eycms.getint(eycms.fget("id",0),0)
		data=array(array("classid",t0,0,0),array("seoTit",t1,255,1),array("seoWord",t2,255,1),array("seoDesc",t3,255,1),array("zt",t4,1,0),array("lx",t5,1,0))
		if eycms.db.dbupdate("ey_plug_seoset","id="&id&"",data)=1 then
			eycms.ajaxjson "保存成功",1
		end if
	end sub
	
	'删除自定义字段
	sub deldb()
		dim fid:fid=eycms.getint(eycms.fget("fid",0),0)
		'删除ey_plug_filed中的字段
		eycms.db.dbdel "ey_plug_seoset","id="&fid&""
		'打印处理结果		
		eycms.echo "1&#21024;&#38500;&#25104;&#21151;"
	end sub

	function loadcate(cid)
		dim data,mycate,i,issel
		mycate="<select name=""t0"" id=""t0"" class=""ip"" data-rule=""所属栏目:required;"">" & vbcrlf & _
			   "<option value="""">请指定栏目</option>" & vbcrlf
		data=eycms.db.dbload("","cateid,catename","view_category","followid=0 and modeid>0","ordnum,cateid")
		if isarray(data) then
			for i=0 to ubound(data,2)
				if cid=data(0,i) then issel=" selected" else issel=""
				mycate=mycate&"<option value="""&data(0,i)&""""&issel&">"&data(1,i)&"</option>"& vbcrlf
			next
		end if
		mycate=mycate&"</select>"
		loadcate=mycate
	end function

	sub english()
		dim t0:t0=eycms.enhtml(eycms.fpost("t0",0))
		if eycms.strlen(t0)=0 then eycms.echo "0&#26639;&#30446;&#21517;&#31216;&#19981;&#33021;&#20026;&#31354;":exit sub
		eycms.echo eycms.get_english(t0)
	end sub

	sub cityadddb()
		dim t0,t1,t2,t3,t4,t5,i
		dim replacetxt,replaceto
		t0=eycms.enhtml(eycms.fpost("t0",0))
		t1=eycms.enhtml(eycms.fpost("t1",0))
		t2=eycms.getint(eycms.fpost("t2",0),0)
		t3=eycms.enhtml(eycms.fpost("t3",0))
		t4=eycms.enhtml(eycms.fpost("t4",0))
		t5=eycms.getint(eycms.fpost("t5",0),0)
		if eycms.strlen(t0)=0 then eycms.echo "0地区名称不能为空":exit sub
		if eycms.strlen(t1)=0 then t1=eycms.get_english(t0)
		t1=replace(t1," ","")
		if not(eycms.checkstr(t1,"en")) then eycms.echo "0网页名称错误":exit sub
		if eycms.strlen(t4)>0 then t4=replace(t4,"[地区]",t0)
		replacetxt=replace(t3,vbcrlf,"|")
		replaceto=replace(t4,vbcrlf,"|")
		if ubound(split(replacetxt,"|"))<>ubound(split(replaceto,"|")) then
			eycms.echo "0替换字符不对应":exit sub
		end if
		eycms.newfolder webroot&"theme/"&theme_root&"/city/"
		if islocal=1 then
			if eycms.isfile(webroot&"theme/"&theme_root&"/"&eycms.sysdb("theme_index")) then
				eycms.copyfile webroot&"theme/"&theme_root&"/"&eycms.sysdb("theme_index"), webroot&"theme/"&theme_root&"/city/"&t1&".tpl"
			end if
		else
			dim htmlstr
			htmlstr=getRemoteTheme(eycms.sysdb("theme_index"),site_root)
			dim is_end:is_end="<%"
			is_end=is_end&"if not in_eycms then response.write(""template load fail""):response.end() end if"
			is_end=is_end&"%"
			is_end=is_end&">"
			if instr(htmlstr,is_end)<=0 then
				htmlstr=is_end&htmlstr
			end if
			eycms.newfile webroot&"theme/"&theme_root&"/city/",t1&".tpl",htmlstr,""
			
			htmlstr=getRemoteEncry_new(htmlstr,theme_root,"city")
			if left(htmlstr,3)<>"ERR" and eycms.strlen(htmlstr)>0 then
				eycms.newfolder webroot&"encry/theme/"&theme_root&"/city/"
				eycms.newfile webroot&"encry/theme/"&theme_root&"/city/",t1&".tpl",htmlstr,""
			end if
		end if
		dim data
		data=array(array("city",t0,255,1),array("htmlname",t1,50,1),array("parentid",t2,0,0),array("replacetxt",t3,0,1),array("replaceto",t4,0,1),array("template",t1&".tpl",255,1),array("zt",t5,1,0))
		if eycms.db.dbnew("ey_plug_seocity",data,"city='"&t0&"'")=0 then
			eycms.echo "0该地区设置已存在，请换个试试":exit sub
		end if
		eycms.echo "1保存成功"
	end sub	

	sub cityeditdb()
		dim t0,t1,t2,t3,t4,t5,t1_old,i
		dim replacetxt,replaceto
		t0=eycms.enhtml(eycms.fpost("t0",0))
		t1=eycms.enhtml(eycms.fpost("t1",0))
		t1_old=eycms.enhtml(eycms.fpost("t1_old",0))
		t2=eycms.getint(eycms.fpost("t2",0),0)
		t3=eycms.enhtml(eycms.fpost("t3",0))
		t4=eycms.enhtml(eycms.fpost("t4",0))
		t5=eycms.getint(eycms.fpost("t5",0),0)
		if eycms.strlen(t0)=0 then eycms.echo "0地区名称不能为空":exit sub
		if eycms.strlen(t1)=0 then t1=eycms.get_english(t0)
		t1=replace(t1," ","")
		if not(eycms.checkstr(t1,"en")) then eycms.echo "0网页名称错误":exit sub
		replacetxt=replace(t3,vbcrlf,"|")
		replaceto=replace(t4,vbcrlf,"|")
		if ubound(split(replacetxt,"|"))<>ubound(split(replaceto,"|")) then
			eycms.echo "0替换字符不对应":exit sub
		end if
		dim data,id
		id=eycms.getint(eycms.fget("id",0),0)
		data=array(array("city",t0,255,1),array("htmlname",t1,50,1),array("parentid",t2,0,0),array("replacetxt",t3,0,1),array("replaceto",t4,0,1),array("template",t1&".tpl",255,1),array("zt",t5,1,0))
		if eycms.db.dbupdate("ey_plug_seocity","id="&id&"",data)=1 then
			if t1<>t1_old then 
				eycms.copyfile webroot&"theme/"&theme_root&"/city/"&t1_old&".tpl", webroot&"theme/"&theme_root&"/city/"&t1&".tpl"
				eycms.delfile webroot&"theme/"&theme_root&"/city/"&t1_old&".tpl"
				if islocal=0 then
					eycms.copyfile webroot&"encry/theme/"&theme_root&"/city/"&t1_old&".tpl", webroot&"encry/theme/"&theme_root&"/city/"&t1&".tpl"
					eycms.delfile webroot&"encry/theme/"&theme_root&"/city/"&t1_old&".tpl"
				end if
			end if
			eycms.echo "1保存成功"
		else
			eycms.echo "0保存失败"
		end if
	end sub	

	sub citydeldb()
		dim fid:fid=eycms.getint(eycms.fget("fid",0),0)
		dim htmlname:htmlname=eycms.db.dbloadone("htmlname","ey_plug_seocity","id="&fid)	
		dim tplname:tplname=eycms.db.dbloadone("template","ey_plug_seocity","id="&fid)	
		eycms.delfile webroot&"theme/"&theme_root&"/city/"&tplname
		eycms.db.dbdel "ey_plug_seocity","id="&fid&""
		eycms.echo "1&#21024;&#38500;&#25104;&#21151;"
	end sub

	sub cityedittpldb()
		err.clear
		on error resume next
		dim filename:filename=eycms.fget("filename",0)
		if not(eycms.checkstr(filename,"filename")) then
			eycms.ajaxjson "filename is wrong1",0
			exit sub
		end if
		if not(eycms.isfile(webroot&"theme/"&theme_root&"/city/"&filename)) then
			eycms.ajaxjson "filename is wrong2",0
			exit sub
		end if
		dim t1:t1=eycms.fpost("t1",1)
		'木马检测开始************************************************
		if chkhack(t1) Then
			eycms.ajaxjson "模板内容含有疑似木马的代码" & hackstr,0
			exit sub
		end If
		'木马检测结束************************************************
		dim is_end:is_end="<%"
		is_end=is_end&"if not in_eycms then response.write(""template load fail""):response.end() end if"
		is_end=is_end&"%"
		is_end=is_end&">"
		if instr(t1,is_end)<=0 then
			t1=is_end&t1
		end if
		eycms.newfile webroot&"theme/"&theme_root&"/city/",filename,t1,""
		if islocal=0 then
			dim htmlstr:htmlstr=getRemoteEncry_new(t1,theme_root,"city")
			if left(htmlstr,3)<>"ERR" and eycms.strlen(htmlstr)>0 then
				eycms.newfile webroot&"encry/theme/"&theme_root&"/city/",filename,htmlstr,""
			end if
		end if
		eycms.ajaxjson "保存成功",1

		if err then
			eycms.errlog "文件名：plug/seoset<br>函数：cityedittpldb<br>详情："&err.description,1
			err.clear
		end if
	end sub

	eycms.db.dbclose
%>