Пример #1
0
 public function run()
 {
     $commentsAsset = CommentsAsset::register($this->getView());
     CommentModule::getInstance()->commentsAssetUrl = $commentsAsset->baseUrl;
     $model = $this->model;
     $model_id = $this->model_id;
     $comment = new Comment(compact('model', 'model_id'));
     $comment->scenario = Yii::$app->user->isGuest ? Comment::SCENARIO_GUEST : Comment::SCENARIO_USER;
     if ((!CommentModule::getInstance()->onlyRegistered || !Yii::$app->user->isGuest) && $comment->load(Yii::$app->getRequest()->post())) {
         if ($comment->validate() && Yii::$app->getRequest()->validateCsrfToken() && Yii::$app->getRequest()->getCsrfToken(true) && $comment->save()) {
             if (Yii::$app->user->isGuest) {
                 CommentsHelper::setCookies(['username' => $comment->username, 'email' => $comment->email]);
             }
             return Yii::$app->getResponse()->redirect(Yii::$app->request->referrer);
         }
     }
     return $this->render('comments', compact('model', 'model_id', 'comment'));
 }
Пример #2
0
 public function run()
 {
     $commentsAsset = CommentsAsset::register($this->getView());
     CommentModule::getInstance()->commentsAssetUrl = $commentsAsset->baseUrl;
     $model = $this->model;
     $model_id = $this->model_id;
     $comment = new Comment(compact('model', 'model_id'));
     $comment->scenario = Yii::$app->user->isGuest ? Comment::SCENARIO_GUEST : Comment::SCENARIO_USER;
     if ((!CommentModule::getInstance()->onlyRegistered || !Yii::$app->user->isGuest) && $comment->load(Yii::$app->getRequest()->post())) {
         if ($comment->validate() && Yii::$app->getRequest()->validateCsrfToken() && Yii::$app->getRequest()->getCsrfToken(true) && $comment->checkSpam() && $comment->save()) {
             if (Yii::$app->user->isGuest) {
                 CommentsHelper::setCookies(['username' => $comment->username, 'email' => $comment->email]);
             }
             Yii::$app->getResponse()->redirect(Yii::$app->request->referrer);
             return;
         }
     }
     $dataProvider = new ActiveDataProvider(['query' => Comment::find(true)->where(['model' => $model, 'model_id' => $model_id, 'parent_id' => NULL, 'status' => Comment::STATUS_PUBLISHED]), 'pagination' => ['pageSize' => CommentsModule::getInstance()->commentsPerPage, 'pageParam' => 'comment-page', 'pageSizeParam' => 'comments-per-page'], 'sort' => ['defaultOrder' => ['created_at' => CommentsModule::getInstance()->orderDirection]]]);
     return $this->render('comments', compact('model', 'model_id', 'comment', 'dataProvider'));
 }
Пример #3
0
<?php

use yeesoft\comments\Comments;
use yeesoft\comments\components\CommentsHelper;
use yeesoft\comments\models\Comment;
use yeesoft\comments\widgets\CommentsForm;
use yeesoft\comments\widgets\CommentsList;
use yii\timeago\TimeAgo;
/* @var $this yii\web\View */
/* @var $model yeesoft\comments\models\Comment */
$commentsPage = Yii::$app->getRequest()->get("comment-page", 1);
$cacheKey = 'comment' . $model . $model_id . $commentsPage . substr(\Yii::$app->language, 0, 2);
//SIMONE forse non indispensabile, ma logico
$cacheProperties = CommentsHelper::getCacheProperties($model, $model_id);
?>
<div class="comments">
    <?php 
if ($this->beginCache($cacheKey . '-count', $cacheProperties)) {
    ?>
        <h5><?php 
    echo Comments::t('comments', 'All Comments');
    ?>
 (<?php 
    echo Comment::activeCount($model, $model_id);
    ?>
)</h5>
        <?php 
    $this->endCache();
    ?>
    <?php 
}
Пример #4
0
<?php 
if ($nested_level < Comments::getInstance()->maxNestedLevel) {
    ?>
    <?php 
    if (!Comments::getInstance()->onlyRegistered || !Yii::$app->user->isGuest) {
        ?>
        <div class="reply-form">
            <?php 
        if ($model->id == ArrayHelper::getValue(Yii::$app->getRequest()->post(), 'Comment.parent_id')) {
            ?>
                <?php 
            echo CommentsForm::widget(['reply_to' => $model->id]);
            ?>
            <?php 
        }
        ?>
        </div>
    <?php 
    }
    ?>

    <?php 
    if ($model->isReplied()) {
        echo CommentsList::widget(ArrayHelper::merge(CommentsHelper::getReplyConfig($model), ["comment" => $comment, "nested_level" => $nested_level + 1]));
    }
}
?>