<?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)));
}
}
?>