public function run() { $orderDirection = $this->parent_id ? CommentsModule::getInstance()->nestedOrderDirection : CommentsModule::getInstance()->orderDirection; $pageSize = $this->parent_id ? 0 : CommentsModule::getInstance()->commentsPerPage; $dataProvider = new ActiveDataProvider(['query' => Comment::find()->where(['model' => $this->model, 'model_id' => $this->model_id, 'parent_id' => $this->parent_id, 'status' => Comment::STATUS_PUBLISHED]), 'pagination' => ['pageSize' => $pageSize, 'pageParam' => 'comment-page', 'pageSizeParam' => 'comments-per-page'], 'sort' => ['defaultOrder' => ['id' => $orderDirection]]]); return $this->render('list', ['dataProvider' => $dataProvider, 'comment' => $this->comment, 'nested_level' => $this->nested_level]); }
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')); }
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')); }
<?php use yeesoft\comments\Comments; use yii\helpers\ArrayHelper; use yii\widgets\ListView; use yii\widgets\Pjax; /* @var $this yii\web\View */ /* @var $model yeesoft\comments\models\Comment */ ?> <?php $containerClass = ArrayHelper::getValue($dataProvider->query->where, 'parent_id') ? 'sub-comments' : 'comments'; ?> <?php if ($comment) { Pjax::begin(); echo ListView::widget(['dataProvider' => $dataProvider, 'emptyText' => Comments::t('comments', 'No Comments'), 'itemView' => function ($model, $key, $index, $widget) use($comment, $nested_level) { return $this->render('item', compact('model', 'widget', 'comment', 'nested_level')); }, 'options' => ['class' => $containerClass], 'itemOptions' => ['class' => 'comment'], 'layout' => '{items}<div class="text-center">{pager}</div>', 'pager' => ['class' => yii\widgets\LinkPager::className(), 'options' => ['class' => 'pagination pagination-sm']]]); Pjax::end(); }
<h5><?php echo Comments::t('comments', 'All Comments'); ?> (<?php echo Comment::activeCount($model, $model_id); ?> )</h5> <?php $this->endCache(); ?> <?php } ?> <?php if (!Comments::getInstance()->onlyRegistered || !Yii::$app->user->isGuest) { ?> <div class="comments-main-form"> <?php echo CommentsForm::widget(); ?> </div> <?php } ?> <?php if ($this->beginCache($cacheKey, $cacheProperties)) { ?> <?php echo CommentsList::widget(compact('model', 'model_id', 'comment'));
/** * Check if the comment is spam or not. If true the comment will be marked as spam. * * @return Return true if comment was checked successfully */ public function checkSpam() { if (Comments::getInstance()->enableSpamProtection) { $isSpam = Yii::$app->akismet->isSpam($this->content, $this->username, $this->email, $this->url, null, 'comment'); if ($isSpam) { $this->status = self::STATUS_SPAM; } } return true; }
?> <div class="comments-main-form"> <?php echo CommentsForm::widget(); ?> </div> <?php } ?> <?php if ($this->beginCache($cacheKey, $cacheProperties)) { ?> <?php Pjax::begin(); echo ListView::widget(['dataProvider' => $dataProvider, 'emptyText' => CommentsModule::t('comments', 'No Comments'), 'itemView' => function ($model, $key, $index, $widget) { $nested_level = 1; return $this->render('comment', compact('model', 'widget', 'nested_level')); }, 'options' => ['class' => 'comments'], 'itemOptions' => ['class' => 'comment'], 'layout' => '{items}<div class="text-center">{pager}</div>', 'pager' => ['class' => yii\widgets\LinkPager::className(), 'options' => ['class' => 'pagination pagination-sm']]]); Pjax::end(); $this->endCache(); ?> <?php } else { ?> <?php TimeAgo::widget(); ?> <?php } ?>
<div class="col-lg-6"> <?php echo $form->field($comment, 'username', ['enableAjaxValidation' => true])->textInput(['maxlength' => true, 'class' => 'form-control input-sm', 'placeholder' => Comments::t('comments', 'Your name')])->label(false); ?> </div> <div class="col-lg-6"> <?php echo $form->field($comment, 'email')->textInput(['maxlength' => true, 'email' => true, 'class' => 'form-control input-sm', 'placeholder' => Comments::t('comments', 'Your email')])->label(false); ?> </div> <?php } else { ?> <div class="col-lg-6"> <?php echo ($comment->parent_id ? Comments::t('comments', 'Reply as') : Comments::t('comments', 'Post as')) . ' <b>' . Yii::$app->user->identity->username . '</b>'; ?> </div> <?php } ?> </div> </div> </div> </div> <?php ActiveForm::end(); ?>
?> </div> <div class="panel-body"> <?php if (count($recentComments)) { ?> <div class="clearfix"> <?php foreach ($recentComments as $comment) { ?> <div class="clearfix comment"> <div class="avatar"> <img src="<?php echo Comments::getInstance()->renderUserAvatar($comment->user_id); ?> "/> </div> <div class="comment-content"> <div class="comment-header"> <a class="author"><?php echo Html::encode($comment->getAuthor()); ?> </a> <span class="time dot-left dot-right"> <?php echo "{$comment->createdDate} {$comment->createdTime}"; ?> </span>
} ?> </div> <?php } ?> </div> <?php if ($nested_level < Comments::getInstance()->maxNestedLevel) { ?> <?php if (!Comments::getInstance()->onlyRegistered || !Yii::$app->user->isGuest) { ?> <div class="reply-form<?php echo Comments::getInstance()->displayAvatar ? ' display-avatar' : ''; ?> "> <?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 use yeesoft\comments\Comments; use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model yeesoft\comments\models\Comment */ $this->title = Yii::t('yee', 'Update "{item}"', ['item' => Comments::t('comments', 'Comment')]); $this->params['breadcrumbs'][] = ['label' => Comments::t('comments', 'Comments'), 'url' => ['index']]; $this->params['breadcrumbs'][] = Yii::t('yee', 'Update'); ?> <div class="comment-update"> <h3 class="lte-hide-title"><?php echo Html::encode($this->title); ?> </h3> <?php echo $this->render('_form', compact('model')); ?> </div>
?> </div> <div class="col-sm-6 text-right"> <?php echo GridPageSize::widget(['pjaxId' => 'comment-grid-pjax']); ?> </div> </div> <?php Pjax::begin(['id' => 'comment-grid-pjax']); ?> <?php echo GridView::widget(['id' => 'comment-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'bulkActionOptions' => ['gridId' => 'comment-grid', 'actions' => [Url::to(['bulk-activate']) => Comments::t('comments', 'Approve'), Url::to(['bulk-deactivate']) => Comments::t('comments', 'Unapprove'), Url::to(['bulk-spam']) => Comments::t('comments', 'Mark as Spam'), Url::to(['bulk-trash']) => Comments::t('comments', 'Move to Trash'), Url::to(['bulk-delete']) => Yii::t('yee', 'Delete')]], 'columns' => [['class' => 'yeesoft\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'controller' => '/comment/default', 'attribute' => 'content', 'title' => function (Comment $model) { return Html::a(mb_substr($model->content, 0, 32) . '...', ['/comment/default/update', 'id' => $model->id], ['data-pjax' => 0]); }, 'buttonsTemplate' => '{update} {delete}'], ['label' => Yii::t('yee', 'User'), 'value' => function (Comment $model) { return $model->getAuthor(); }, 'options' => ['style' => 'width:150px']], ['attribute' => 'model', 'value' => function (Comment $model) { return $model->model . ($model->model_id ? ' [' . $model->model_id . ']' : ''); }, 'options' => ['style' => 'width:120px']], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'status', 'optionsArray' => Comment::getStatusOptionsList(), 'options' => ['style' => 'width:60px']], ['class' => 'yeesoft\\grid\\columns\\DateFilterColumn', 'attribute' => 'created_at', 'value' => function (Comment $model) { return '<span style="font-size:85%;" class="label label-' . (time() >= $model->created_at ? 'primary' : 'default') . '">' . $model->createdDate . ' ' . $model->createdTime . '</span>'; }, 'format' => 'raw', 'options' => ['style' => 'width:150px']], ['attribute' => 'user_ip', 'options' => ['style' => 'width:100px']]]]); ?> <?php Pjax::end(); ?> </div> </div>
/** * Get author of comment * * @return string */ public function getAuthor() { if ($this->user_id) { $userModel = Comments::getInstance()->userModel; $user = $userModel::findIdentity($this->user_id); return $user && isset($user) ? $user->username : Comments::getInstance()->deletedUserName; } else { return $this->username; } }
/** * Registers this asset bundle with a view. * @param \yii\web\View $view the view to be registered with * @return static the registered asset bundle instance */ public static function register($view) { $commentsModuleID = Comments::getInstance()->commentsModuleID; $getFormLink = Url::to(["/{$commentsModuleID}/default/get-form"]); $js = <<<JS commentsModuleID = "{$commentsModuleID}"; commentsFormLink = "{$getFormLink}"; JS; $view->registerJs($js, View::POS_HEAD); return parent::register($view); }