<?php
namespace Home\Controller;
use Think\Controller;

class BaseController extends Controller {
	function _initialize(){
		//导航
		$this->nav = M('navigation')->where(array('status'=>1,'pid'=>0))->order('ord desc,id asc')->select();
		//热门阅读
		$this->hotRead = M('content')->order('hit desc')->limit(F('ProductShowNum'))->select();
		//最新发布
		$this->newArticle = M('content')->order('id desc')->limit(F('ProductShowNum'))->select();
		
	}
	
	function _empty(){

		$this->display('Public/error');
	}
	
	function comment(){
		if(!I('content')){
			echo '没有提交内容';
			exit;
		}
		$id = split('-',I('id'));
		if(!$id){
			echo '不能发表评论';
			exit;
		}
		if(!I('name')){
			echo '留下您的大名吧！';
			exit;
		}
		$_POST['type'] = $id['0'];
		$_POST['cid'] = $id['1'];
		$_POST['time'] = time();
		$_POST['ip'] = get_client_ip();
		$db = M('book');
		$re = $db->where(array('id'=>$_POST['cid'],time=>array('GT',time()-10*60)))->find();
		if($re){
			echo '请不要重复发表评论！';
			exit;
		}
		$re = $db->where(array('content'=>I('content'),time=>array('GT',time()-10*60)))->find();
		if($re){
			echo '请不要灌水';
			exit;
		}
		$re = $db->where(array('ip'=>$_POST['ip'],time=>array('GT',time()-3*60)))->find();
		if($re){
			echo '休息一会，您提交评论也太快了吧！';
			exit;
		}
		cookie('author',I('name'));
		cookie('web',I('web'));
		cookie('email',I('email'));
		$db->create();
		$db->add();
		echo 'ok';
	}
}