Location: PHPKode > projects > blog > blog/blog_replies_controller.php
<?php
/**
 *
 * @filesource
 * @copyright		Copyright 2008-2009, Lesorb, Inc.
 * @link			http://www.lesorb.cn Blog Project
 * @package			app
 * @subpackage		app.controllers
 * @version			$Revision: 1.1 $
 * @author			WangLiJun
 * @lastmodified	$2009-4-20$
 */
/**
 * file used to handle the replies of blog models about users
 *
 * @name		blog_replies_controller.php
 *
 * @copyright	lesorb
 */

class BlogRepliesController extends AppController {

	var $name = 'BlogReplies';
	var $components	=	array('RequestHandler', 'Acces', 'Cookie','Captcha');

	function replies($commuser_id = 0,$blog_id = null) {
		$this->layout = 'default_commer';

		if($commuser_id == 0)
			exit('非法的请求!');
		if(empty($blog_id))
			exit('非法的请求!');
		$commuser = $this->getCommusers($commuser_id);

		$this->loadModels('Blog');
		$id = $blog_id;
		$blog = $this->Blog->read(null, $id);

		//$this->BlogReply->recursive = 0;
		$blogReplies = $this->getBlogReplies($blog_id);

		$this->set(compact('blog','blogReplies','commuser'));
	}
//快速回复
	function manage_ajaxReplay(){
		$this->autoRender = false;

		if (!empty($this->data)) {
			$this->BlogReply->create();
							
			$this->data['BlogReply']['ip'] = $this->RequestHandler->getClientIP();
			$this->data['BlogReply']['user_id'] = $this->getUidBySession();

			if($this->data['BlogReply']['user_id'] === 0){

				echo '请您重新登录';

			}elseif(strlen($this->data['BlogReply']['description']) < 15){

				echo '请您至少写15个字符的回复内容';

			}elseif($this->Session->read('captcha') != $this->data['BlogReply']['captcha']){

				echo '验证码错误!';

			}elseif((time()-$this->Session->read('Blog.replaytime')) < 180){
				
				echo '您两次操作太快了!'.(time()-$this->Session->read('Blog.replaytime'));

			}else{
				//if ($this->BlogReply->save($this->data)) {
					$this->Session->write('Blog.replaytime', time());

					//blog 回复数加一
					$this->Blog->plusBlogSomeFields($this->data['BlogReply']['blog_id'],'replay_count');

					//$this->data['BlogReply']['description'] = '';
					//$this->data['BlogReply']['captcha'] = '';					

					echo '<div id=\'replay_success\'>回复成功!</div>';
					
			//	} else {

					//echo '回复失败.请您再试';
				//}
			}	
		}		
	}
	
	function manage_edit($id = null) {

		if (!$id && empty($this->data)) {

			$this->Session->setFlash(__('非法的请求!', true));
			$this->redirect(array('action'=>'replies'));
		}
		if (!empty($this->data)) {

			if(empty($this->data['BlogReply']['user_id'])){
				$this->Session->setFlash(__('请您登录先!', true));

			}else{
				if ($this->BlogReply->save($this->data)) {
					$this->Session->setFlash(__('编辑成功', true));
					
				} else {
					$this->Session->setFlash(__('编辑失败,请您再试.', true));
				}
			}
		}
		if (empty($this->data)) {

			$this->data = $this->BlogReply->read(null, $id);
		}

	}
	
	/*function manage_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for BlogReply', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->BlogReply->del($id)) {
			$this->Session->setFlash(__('BlogReply deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}*/


	function admin_index() {
		$this->BlogReply->recursive = 0;
		$this->set('blogReplies', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('非法的请求!.', true));
			$this->redirect(array('action'=>'replies'));
		}
		$this->set('blogReply', $this->BlogReply->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->BlogReply->create();
			if ($this->BlogReply->save($this->data)) {
				$this->Session->setFlash(__('The BlogReply has been saved', true));
				$this->redirect(array('action'=>'replies'));
			} else {
				$this->Session->setFlash(__('The BlogReply could not be saved. Please, try again.', true));
			}
		}
		$blogs = $this->BlogReply->Blog->find('list');
		$users = $this->BlogReply->User->find('list');
		$this->set(compact('blogs', 'users'));
	}

	function admin_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('非法的请求!', true));
			$this->redirect(array('action'=>'replies'));
		}
		if (!empty($this->data)) {
			if ($this->BlogReply->save($this->data)) {
				$this->Session->setFlash(__('The BlogReply has been saved', true));
				$this->redirect(array('action'=>'replies'));
			} else {
				$this->Session->setFlash(__('The BlogReply could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->BlogReply->read(null, $id);
		}

		$users = $this->BlogReply->User->find('list');
		$this->set(compact('users'));
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('非法的id!', true));
			$this->redirect(array('action'=>'replies'));
		}
		if ($this->BlogReply->del($id)) {
			$this->Session->setFlash(__('BlogReply deleted', true));
			$this->redirect(array('action'=>'replies'));
		}
	}
	private function getCommusers($id){
		$commuser = $this->requestAction('/commusers/getCommuserInfoById/'.$id);
		$commuser = $commuser[0];

		return $commuser;
	}
	private function getUsers($id){
		$this->loadModels('User');
		$user = $this->User->find(array('id'=>$id),array('id','username','face','province','city','descriptions','aliasname','subdistrict'),null,0);

		return $user;
	}
	function getBlogReplies($blog_id){
		//Configure::write('debug', 0);
		//$this->autoRender = false;

		$this->BlogReply->recursive = 0;
		$BlogReplies = $this->paginate('BlogReply',array('blog_id'=>$blog_id));

		return  $BlogReplies;
	}
	function showBlogReplies($blog_id){
		$this->layout = null;

		$this->BlogReply->recursive = 0;
		$this->set('blogReplies',$this->paginate('BlogReply',array('blog_id'=>$blog_id)));
	}
}
?>
Return current item: blog