<!--#include file="../lib/base.asp"-->
<!--#include file="../theme.asp"-->
<%
''' EYCMS 评论
''' ==================================================================
	eycms.stophack
	dim etrans
	set etrans=new eycms_lang
	sub userstaus()
		dim gourl:gourl=eycms.enhtml(eycms.fpost("gourl",0))
		dim str:str=""
		dim avatar:avatar=0
		dim staus
			str=str&"<form class=""form_comment"" method=""post"">"
			str=str&"	<div class=""commentadd"">"
			str=str&"		<div class=""face""><img src="""&webroot&"site/"&site_root&"/upfile/avatar/{avatar}/normal.jpg"" /></div>"
			str=str&"		<div class=""text"">"
			str=str&"			<div class=""div""><textarea name=""t0"" id=""comment_content"" data-rule=""评论内容:required;"" onKeyUp=""strlen_verify(this,'commentlen',255)""></textarea>"
			str=str&"			<span>还可以输入<span id=""commentlen"">255</span>个字符</span>"
			str=str&"			</div>"
			str=str&"			{staus}"
			str=str&"		</div>"
			str=str&"	</div>"
			str=str&"	</form>"
			dim user_islock:user_islock=eycms.db.dbloadone("islock","ey_admin_menu","title='会员'")
			if eycms.is_login then
				dim userdata:userdata=eycms.userinfo
				avatar=userdata(12)
				staus="<div class=""input""><input type=""submit"" value=""发表评论"" name=""send"" class=""send"" />"&userdata(13)&"<input type=""hidden"" name=""t1"" class=""ip"" value="""&userdata(13)&""" maxlength=""20"" readonly=""readonly"" />(<a href="""&webroot&"user/login.asp?act=out&gourl="&gourl&""">匿名发表</a>)</div>"
				str=replace(str,"{avatar}",avatar)
				str=replace(str,"{staus}",staus)
			else
				dim nickname:nickname=eycms.get_cityname("EYCMS")&"网友"
				staus="<div class=""input""><input type=""submit"" value=""发表评论"" class=""send"" />"&nickname&"<input type=""hidden"" name=""t1"" class=""ip"" value="""&nickname&""" maxlength=""20"" />"
				If user_islock=1 Then staus=staus&"(<a href="""&webroot&"user/login.asp?gourl="&gourl&""">登录发表</a>)"
				staus=staus&"</div>"
				str=replace(str,"{avatar}",0)
				str=replace(str,"{staus}",staus)
			end if
		if commentconfig(2) then
			if not(eycms.is_login) then
				str="<a href="""&webroot&"user/login.asp?gourl="&gourl&""">请登录后发表评论</a>"
			end if
		end if
		str=etrans.trans(str,theme_root)
		eycms.echo str 
	end sub
	
	sub adddb()
		if commentconfig(2) then
			if not(eycms.is_login) then
				eycms.ajaxjson etrans.trans("请登录后发表评论",theme_root),0
				exit sub
			end if
		end if
		dim t0,t1,id
		t0=eycms.enhtml(eycms.fpost("t0",0))
		t1=eycms.enhtml(eycms.fpost("t1",0))
		id=eycms.getint(eycms.fget("id",0),0)
		if not(syscomment) then
			eycms.ajaxjson etrans.trans("系统未开启评论",theme_root),0
			exit sub
		end if
		dim f,passnum
		if commentconfig(1) then
			f=1
			passnum=0
		else
			f=2
			passnum=1
		end if
		if not(eycms.checkpost) then
			eycms.ajaxjson etrans.trans("禁止外部提交数据",theme_root),0
			exit sub
		end if
		if id=0 then
			eycms.ajaxjson etrans.trans("参数错误",theme_root),0
			exit sub
		end if
		if eycms.strlen(t0)=0 then
			eycms.ajaxjson etrans.trans("内容不能为空",theme_root),0
			exit sub
		end if
		if eycms.strlen(t0)<5 then
			eycms.ajaxjson etrans.trans("至少输入5个字符",theme_root),0
			exit sub
		end if
		if eycms.strlen(t1)=0 then
			eycms.ajaxjson etrans.trans("昵称不能为空",theme_root),0
			exit sub
		end if
		if eycms.loadcookie("comment_add_"&id)<>"" then
			if int(datediff("s",eycms.loadcookie("comment_add_"&id),now()))<=60 then
				eycms.ajaxjson etrans.trans("请勿重复提交",theme_root),0
				exit sub
			end if
		end if
		dim userid,avatar
		userid=0
		avatar=0
		
		if eycms.is_login then
			dim userdata:userdata=eycms.userinfo
			userid=userdata(0)
			avatar=userdata(12)
			if t1<>userdata(1) then
				t1=userdata(1)
			end if
		end if
		dim data,comments,tname
		data=eycms.db.dbload(1,"comments,iscomment,title","ey_content","id="&id&"","")
		if ubound(data)<0 then
			eycms.ajaxjson etrans.trans("参数错误",theme_root),0
			exit sub
		else
			comments=data(0,0)
			tname=data(2,0)
			if data(1,0)=0 then
				eycms.ajaxjson etrans.trans("本文禁止评论",theme_root),0
				exit sub
			end if
		end if
		data=array(array("contentid",id,0,1),array("username",t1,20,1),array("userid",userid,0,0),array("avatar",avatar,0,0),array("content",t0,255,1),array("createdate",sqltime,0,0),array("islock",passnum,0,0),array("followid",0,0,0),array("postip",eycms.getip,0,1))
		eycms.db.insert "ey_expand_comment",data
		eycms.setcookie "comment_add_"&id,now()
		eycms.setcookie "content_"&id,""
		eycms.db.dbupdate "ey_content","id="&id&"",array(array("comments",comments+1,0,0))
		dim body:body=""
		dim title:title="您有一条新评论(来自网站)"
		body=body&"昵　称："&t1
		body=body&"<br>日　期："&now()
		body=body&"<br>标　题："&tname
		body=body&"<br>内　容："&t0
		eycms.sendmail eycms.getsys("adminemail"),title,body
		if commentconfig(1) then
			eycms.ajaxjson f & etrans.trans("提交成功，审核后显示！",theme_root),1
		else
			eycms.ajaxjson f & etrans.trans("提交成功！",theme_root),1
		end if
	end sub
	
	sub loadtop()
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		if id=0 then
			exit sub
		end if
		if not(syscomment) then
			eycms.echo etrans.trans("系统未开启评论",theme_root)
			exit sub
		end if
		dim data:data=eycms.db.dbload(10,"avatar,username,createdate,content,reply","ey_expand_comment","contentid="&id&" and islock=1","commentid desc")
		if ubound(data)<0 then
			eycms.echo etrans.trans("没有评论",theme_root)
			exit sub
		else
			dim i,str,temp,show
			temp=""
			temp=temp&"<div class=""comment"">"
            temp=temp&"        <div class=""face""><img src="""&webroot&"site/"&site_root&"/upfile/avatar/{avatar}/normal.jpg"" /></div>"
            temp=temp&"        <div class=""text"">"
            temp=temp&"            <div class=""div"">"
            temp=temp&"                <div class=""icon""></div>"
            temp=temp&"                <div class=""base""><span>{createdate}</span>{username}</div>"
            temp=temp&"                <div class=""content"">{content}</div>"
            temp=temp&"                {reply}"
            temp=temp&"            </div>"
            temp=temp&"        </div>"
            temp=temp&"    </div>"
			for i=0 to ubound(data,2)
				show=temp
				show=replace(show,"{avatar}",data(0,i))
				show=replace(show,"{username}",data(1,i))
				show=replace(show,"{createdate}",data(2,i))
				show=replace(show,"{content}",data(3,i))
				if eycms.strlen(data(4,i))>0 then
					show=replace(show,"{reply}","<div class=""reply""><strong>"&etrans.trans("管理员回复：",theme_root)&"</strong>"&data(4,i)&"</div>")
				else
					show=replace(show,"{reply}","")
				end if
				str=str&show
			next
			eycms.echo str
		end if
	end sub
	
	dim act:act=eycms.fget("act",0)
	select case act
		case "islogin":userstaus
		case "add":adddb
		case "load":loadtop
		case else
			if not(syscomment) then
				dim errormsg:errormsg=etrans.trans("系统未开启评论",theme_root)
				eycms.show eycms.getsys("theme_404"),""
				eycms.die
			end if
			dim infoid:infoid=eycms.getint(eycms.fget("id",0),0)
			dim data,comments
			data=eycms.db.dbload(1,"comments,iscomment,title,isurl,url,catedir,intro,classid,point,islock","ey_content left join ey_category on ey_content.classid=ey_category.cateid","id="&infoid&"","")
			if ubound(data)<0 then
				errormsg=etrans.trans("参数错误",theme_root)
				eycms.show eycms.getsys("theme_404"),""
				eycms.die
			else
				if data(9,0)<>1 then
					errormsg=etrans.trans("您查看的内容不存在",theme_root)
					eycms.show eycms.getsys("theme_404"),""
					eycms.die
				end if
				if data(1,0)=0 then
					errormsg=etrans.trans("本文禁止评论",theme_root)
					eycms.show eycms.getsys("theme_404"),""
					eycms.die
				end if
				dim infotitle,infourl,infointro,infopoint,classid
				infotitle=data(2,0)
				infourl=eycms.geturl(infoid,data(7,0),data(3,0),data(4,0))
				infointro=data(6,0)
				classid=data(7,0)
				infopoint=data(8,0)
				data=eycms.getclassdb(classid)
				dim parentid:parentid=data(6)
			end if
			dim sqlwhere:sqlwhere="and contentid="&infoid&""
			eycms.show eycms.getsys("theme_comment"),""
	end select
	set etrans=nothing
	eycms.db.dbclose
%>
