Exemplo n.º 1
0
 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]);
 }
Exemplo n.º 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->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'));
 }
Exemplo n.º 3
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'));
 }
Exemplo n.º 4
0
        <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'));
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
}
?>
    <?php 
if (Comments::getInstance()->displayAvatar) {
    ?>
        <div class="avatar">
            <img src="<?php 
    echo Comments::getInstance()->renderUserAvatar(Yii::$app->user->id);
    ?>
"/>
        </div>
    <?php 
}
?>
    <div class="comment-fields<?php 
echo Comments::getInstance()->displayAvatar ? ' display-avatar' : '';
?>
">

        <div class="row">
            <div class="col-lg-12">
                <?php 
echo $form->field($comment, 'content')->textarea(['class' => 'form-control input-sm', 'placeholder' => Comments::t('comments', 'Share your thoughts...')])->label(false);
?>
            </div>
        </div>

        <div class="comment-fields-more">
            <div class="buttons text-right">
                <?php 
echo Html::button(Comments::t('comments', 'Cancel'), ['class' => 'btn btn-default btn-sm reply-cancel']);
Exemplo n.º 7
0
?>
</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>
Exemplo n.º 8
0
 /**
  * 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;
     }
 }
Exemplo n.º 9
-1
    /**
     * 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);
    }