Example #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'));
 }
Example #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'));
 }
Example #3
0
<?php

use yeesoft\comments\assets\CommentsAsset;
use yeesoft\comments\Comments;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $modelyeesoft\comments\models\Comment */
?>

<?php 
$commentsAsset = CommentsAsset::register($this);
Comments::getInstance()->commentsAssetUrl = $commentsAsset->baseUrl;
$formID = 'comment-form' . ($comment->parent_id ? '-' . $comment->parent_id : '');
$replyClass = $comment->parent_id ? 'comment-form-reply' : '';
?>

<div class="comment-form <?php 
echo $replyClass;
?>
 clearfix">

    <?php 
$form = ActiveForm::begin(['action' => NULL, 'validateOnBlur' => FALSE, 'validationUrl' => Url::to(['/' . Comments::getInstance()->commentsModuleID . '/validate/index']), 'id' => $formID, 'class' => 'com-form']);
if ($comment->parent_id) {
    echo $form->field($comment, 'parent_id')->hiddenInput()->label(false);
}
?>
    <?php 
if (Comments::getInstance()->displayAvatar) {