Пример #1
0
 public function run()
 {
     $model = new Comment();
     //条件
     $criteria = new CDbCriteria();
     $type = trim(Yii::app()->request->getParam('type'));
     $type && $criteria->addColumnCondition(array('type' => $type));
     $status = trim(Yii::app()->request->getParam('status'));
     $status && $criteria->addColumnCondition(array('status' => $status));
     $title = trim(Yii::app()->request->getParam('content'));
     $title && $criteria->addSearchCondition('content', $title);
     $criteria->order = 't.id DESC';
     $count = $model->count($criteria);
     //分页
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $pages->applyLimit($criteria);
     //查询
     $result = $model->findAll($criteria);
     //全部类型
     $model_types = ModelType::model()->findAll();
     Yii::app()->clientScript->registerCssFile($this->controller->_static_public . "/js/kindeditor/code/prettify.css");
     Yii::app()->clientScript->registerScriptFile($this->controller->_static_public . "/js/kindeditor/code/prettify.js", CClientScript::POS_END);
     $this->controller->render('index', array('model' => $model, 'model_types' => $model_types, 'datalist' => $result, 'pagebar' => $pages));
 }
Пример #2
0
 public function run()
 {
     $controller = $this->getController();
     $this->_setting = $controller->_setting;
     $this->_stylePath = $controller->_stylePath;
     $this->_static_public = $controller->_static_public;
     $controller->_seoTitle = Yii::t('common', 'User Center') . ' - ' . Yii::t('common', 'My Comments') . ' - ' . $this->_setting['site_name'];
     //加载css,js
     Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/user.css");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js");
     //我的评论
     $uid = Yii::app()->user->id;
     $comment_mod = new Comment();
     $model_type = new ModelType();
     $uid = Yii::app()->user->id;
     $criteria = new CDbCriteria();
     $criteria->condition = 't.user_id=' . $uid;
     $criteria->order = 't.id DESC';
     //分页
     $count = $comment_mod->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 15;
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $datalist = $comment_mod->findAll($criteria);
     foreach ((array) $datalist as $k => $v) {
         $c_mod_class = $controller->_content_models[$v->type];
         $c_mod_name = strtolower($c_mod_class);
         $content_mod = new $c_mod_class();
         $content = $content_mod->findByPk($v->topic_id);
         $datalist[$k]['title'] = $content->title;
         $datalist[$k]['url'] = $controller->createUrl($c_mod_name . '/view', array('id' => $content->id));
     }
     $controller->render('my_comments', array('datalist' => $datalist));
 }
 /**
  * 评论管理
  *
  */
 public function actionIndex()
 {
     $this->_model_type = ModelType::model()->findAll();
     $model = new Comment();
     $criteria = new CDbCriteria();
     $condition = '1';
     $status = $this->_request->getParam('status');
     $title = $this->_request->getParam('postTitle');
     $content = $this->_request->getParam('content');
     $type = $this->_request->getParam('type') ? $this->_request->getParam('type') : $this->_type_ids['post'];
     $type && ($condition .= " AND type={$type}");
     $status && ($condition .= " AND t.status='{$status}'");
     $table = array_search($type, $this->_type_ids);
     if ($table == 'goods') {
         $title && ($condition .= " AND {$table}.goods_name LIKE '%{$title} %'");
     } else {
         $title && ($condition .= " AND {$table}.title LIKE '%{$title} %'");
     }
     $content && ($condition .= ' AND t.content LIKE \'%' . $content . '%\'');
     $criteria->condition = $condition;
     $criteria->order = 't.id DESC';
     $criteria->with = array($table);
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 13;
     $pageParams = $this->buildCondition($_GET, array('postTitle', 'status', 'content', 'type'));
     $pages->params = is_array($pageParams) ? $pageParams : array();
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $result = $model->findAll($criteria);
     Yii::app()->clientScript->registerCssFile($this->_static_public . "/js/kindeditor/code/prettify.css");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/kindeditor/code/prettify.js", CClientScript::POS_END);
     $this->render('index', array('datalist' => $result, 'pagebar' => $pages, 'table' => $table));
 }
Пример #4
0
 public function run()
 {
     $controller = $this->getController();
     $controller->_seoTitle = Yii::t('common', 'User Center') . ' - ' . Yii::t('common', 'My Comments') . ' - ' . $controller->_setting['site_name'];
     //我的评论
     $uid = Yii::app()->user->id;
     $comment_mod = new Comment();
     $criteria = new CDbCriteria();
     $criteria->addColumnCondition(array('t.user_id' => $uid));
     $criteria->order = 't.id DESC';
     //分页
     $count = $comment_mod->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 15;
     $pages->applyLimit($criteria);
     $datalist = $comment_mod->findAll($criteria);
     foreach ((array) $datalist as $k => $v) {
         $c_mod_class = $controller->_content_models[$v->type];
         $c_mod_name = strtolower($c_mod_class);
         $content_mod = new $c_mod_class();
         $content = $content_mod->findByPk($v->content_id);
         $datalist[$k]['title'] = $content->title;
         $datalist[$k]['url'] = $controller->createUrl($c_mod_name . '/view', array('id' => $content->id));
     }
     $controller->render('my_comments', array('datalist' => $datalist, 'pages' => $pages));
 }
Пример #5
0
 /**
  * Get a list of comments
  *
  * @param Request $request
  * @param string $params
  * @return void
  */
 protected static function get($request, $params)
 {
     try {
         $comments = Comment::query($request->get('queryParams'), $request->include);
     } catch (OutOfBoundsException $e) {
         $comments = Comment::findAll($request->include);
     }
     static::response($comments, 200);
 }
Пример #6
0
 function moderation($page = 0)
 {
     $this->display('comment/views/moderation', array('comments' => Comment::findAll(), 'page' => $page));
 }
Пример #7
0
 public function run()
 {
     $this->controller->layout = false;
     $view_url = Yii::app()->request->getParam('view_url');
     $content_id = Yii::app()->request->getParam('content_id');
     $topic_type = Yii::app()->request->getParam('topic_type');
     $cur_url = Yii::app()->request->hostinfo . Yii::app()->request->getUrl();
     $post = false;
     //评论类型
     switch ($topic_type) {
         case 'post':
             $post = Post::model()->findByPk($content_id);
             break;
         case 'image':
             $post = Image::model()->findByPk($content_id);
             break;
         case 'soft':
             $post = Soft::model()->findByPk($content_id);
             break;
         case 'video':
             $post = Video::model()->findByPk($content_id);
             break;
     }
     if (!$post) {
         throw new CHttpException(404, Yii::t('admin', 'Loading Error'));
     }
     //评论内容
     $model = new Comment('create');
     $criteria = new CDbCriteria();
     $criteria->with = array('user');
     $criteria->addColumnCondition(array('content_id' => $content_id));
     $criteria->addColumnCondition(array('t.status' => Comment::STATUS_SHOW));
     $criteria->addColumnCondition(array('type' => $this->controller->_type_ids[$topic_type]));
     $criteria->addCondition('u.uid > 0');
     $criteria->order = 't.id DESC';
     $criteria->select = 't.id, user_id, content_id, content, t.create_time ';
     //分页
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $comments = $model->findAll($criteria);
     //回复
     if ($comments) {
         foreach ($comments as $c) {
             $replies[$c->id] = Reply::model()->with('user')->findAll(array('condition' => 'cid = ' . $c->id . ' AND t.status = "' . Reply::STATUS_SHOW . '" AND u.uid > 0', 'order' => 'id'));
         }
     } else {
         $comments = array();
         $replies = array();
     }
     if (Yii::app()->request->isPostRequest) {
         $uid = Yii::app()->user->id;
         if (!$uid) {
             $this->message('script', Yii::t('common', 'You Need Login'));
         }
         $model->attributes = $_POST['Comment'];
         $model->content_id = $content_id;
         $model->type = $this->controller->_type_ids[$topic_type];
         $model->user_id = $uid;
         $model->status = 'N';
         $model->client_ip = Yii::app()->request->userHostAddress;
         $model->create_time = time();
         $ret_url = $_POST['ret_url'];
         if ($model->save()) {
             $this->controller->message('script', Yii::t('common', 'Submit Success, Waiting Pass'), $ret_url);
         }
     }
     $data = array('model' => $model, 'view_url' => $view_url, 'cur_url' => $cur_url, 'comments' => $comments, 'pagebar' => $pages, 'replies' => $replies);
     $this->controller->render('create', $data);
 }
Пример #8
0
 function index()
 {
     $this->display('comment/views/index', array('comments' => Comment::findAll()));
 }
Пример #9
0
 /**
  * 提交评论
  *
  * @return [type] [description]
  */
 public function actionCreate()
 {
     $this->layout = false;
     $view_url = $this->_request->getParam('view_url');
     $topic_id = $this->_request->getParam('topic_id');
     $topic_type = $this->_request->getParam('topic_type');
     $cur_url = $this->_request->hostinfo . $this->_request->getUrl();
     $post = false;
     //评论类型
     switch ($topic_type) {
         case 'post':
             $post = Post::model()->findByPk($topic_id);
             break;
         case 'image':
             $post = Image::model()->findByPk($topic_id);
             break;
         case 'soft':
             $post = Soft::model()->findByPk($topic_id);
             break;
         case 'video':
             $post = Video::model()->findByPk($topic_id);
             break;
     }
     if (!$post) {
         throw new CHttpException(404, Yii::t('admin', 'Submit Error'));
         break;
     }
     //评论内容
     $model = new Comment('create');
     $criteria = new CDbCriteria();
     $condition = "topic_id={$topic_id} AND status='Y' AND type={$this->_type_ids[$topic_type]}";
     $criteria->condition = $condition;
     $criteria->order = 'id DESC';
     $criteria->select = "id, user_id, topic_id, content, create_time ";
     //分页
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $comments = $model->findAll($criteria);
     //回复
     if ($comments) {
         foreach ((array) $comments as $c) {
             $replies[$c->id] = Reply::model()->findAll('cid=:cid AND status=:status ORDER BY id', array(':cid' => $c->id, ':status' => 'Y'));
         }
     }
     //加载css,js
     Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/comment.css");
     Yii::app()->clientScript->registerCssFile($this->_static_public . "/js/kindeditor/code/prettify.css");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/kindeditor/code/prettify.js", CClientScript::POS_END);
     if ($this->_request->isPostRequest) {
         $uid = Yii::app()->user->id;
         if (!$uid) {
             $this->message('script', Yii::t('common', 'You Need Login'));
         }
         $model->attributes = $_POST['Comment'];
         $model->topic_id = $topic_id;
         $model->type = $this->_type_ids[$topic_type];
         $model->user_id = $uid;
         $model->status = 'N';
         $model->client_ip = $this->_request->userHostAddress;
         $model->create_time = time();
         $ret_url = $_POST['ret_url'];
         if ($model->save()) {
             $this->message('script', Yii::t('common', 'Submit Success, Waiting Pass'), $ret_url);
             //$this->redirect($ret_url);
         }
     }
     $data = array('model' => $model, 'view_url' => $view_url, 'cur_url' => $cur_url, 'comments' => $comments, 'pagebar' => $pages, 'replies' => $replies);
     $this->render('create', $data);
 }
Пример #10
0
<?php

require_once "../models/db.php";
require_once "../models/Comment.php";
require_once "../models/User.php";
$result = array();
$names = array();
$comments;
$user = new User();
if ($_GET["time"] == "") {
    $comments = Comment::findAll($dbh);
} else {
    $comments = Comment::findNewComments($_GET["time"], $dbh);
}
foreach ($comments as $comment) {
    $user->find($comment->author_id, $dbh);
    array_push($names, $user->name);
}
array_push($result, $comments);
array_push($result, $names);
header("Content-type: text/json");
echo json_encode($result);