Exemple #1
0
function Comments($items, $pages, $id)
{
    foreach ($items as $key => $value) {
        if ($key >= $pages->offset && $key < $pages->offset + $pages->limit) {
            if ($value->parent_id == 0) {
                if (isset($value->user)) {
                    $username = $value->user->username;
                    $avatar = $value->user->avatar;
                    $url = Url::to(['user/view', 'id' => $value->user_id]);
                } else {
                    $username = $value->author ? $value->author : "游客";
                    $avatar = Yii::$app->homeUrl . "upload/avatar/default.png";
                    $url = "javascript:;";
                }
                echo '<li class="media"> <a class="pull-left" href="' . $url . '"> <img class="media-object img-circle" alt="' . Html::encode($username) . '" src="' . $avatar . '" style="width: 48px; height: 48px;"> </a> <div class="media-body"> <h4 class="media-heading"><a href="' . $url . '">' . Html::encode($username) . '</a> • <span title="' . date("Y-m-d H:i:s", $value->create_time) . '">' . Common::formatTime($value->create_time) . '</span></h4> <p>' . Html::encode($value->content) . '</p><div class="ops"><a href="" class="comment-up" data-id="' . $value->id . '"><i class="glyphicon glyphicon-thumbs-up"></i> (<span>' . $value->up . '</span>)</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="" class="comment-down" data-id="' . $value->id . '"><i class="glyphicon glyphicon-thumbs-down"></i> (<span>' . $value->down . '</span>)</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="" class="comment-reply" data-id="' . $value->id . '" data-postid="' . $id . '" title="回复"><i class="glyphicon glyphicon-share-alt"></i></a></div>';
                renderItems($items, $value, $id);
                echo "</li>";
            }
        }
    }
}
Exemple #2
0
 public function actionCommentAjax($id)
 {
     $model = new Comment();
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->params['commentNeedApproval']) {
             $model->type = 0;
         } else {
             $model->type = 1;
         }
         $model->status = 1;
         $model->post_id = $id;
         if ($model->save()) {
             if (isset($model->user)) {
                 $username = $model->user->username;
                 $avatar = $model->user->avatar;
                 $url = Url::to(['user/view', 'id' => $model->user_id]);
             } else {
                 $username = $model->author ? $model->author : "游客";
                 $avatar = Yii::$app->homeUrl . "upload/avatar/default.png";
                 $url = "javascript:;";
             }
             if ($model->parent_id) {
                 $li = '<li class="media">';
                 $endli = '</li>';
             } else {
                 $li = '';
                 $endli = '';
             }
             echo Json::encode($li . '<div class="media"><a class="pull-left" href="' . $url . '"> <img class="media-object img-circle" alt="' . Html::encode($username) . '" src="' . $avatar . '" style="width: 48px; height: 48px;"> </a> <div class="media-body"> <h4 class="media-heading"><a href="' . $url . '">' . Html::encode($username) . '</a> • <span title="' . date("Y-m-d H:i:s", $model->create_time) . '">' . Common::formatTime($model->create_time) . '</span></h4> <p>' . Html::encode($model->content) . '</p><div class="ops"><a href="" class="comment-up" data-id="' . $model->id . '"><i class="glyphicon glyphicon-thumbs-up"></i> (<span>0</span>)</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="" class="comment-down" data-id="' . $model->id . '"><i class="glyphicon glyphicon-thumbs-down"></i> (<span>0</span>)</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="" class="comment-reply" data-id="' . $model->id . '" data-postid="' . $id . '" title="回复"><i class="glyphicon glyphicon-share-alt"></i></a></div>' . $endli);
         } else {
             echo "0";
         }
     } else {
         echo "0";
     }
     Yii::$app->end();
 }
Exemple #3
0
 public function getMakeTime()
 {
     return Common::formatTime($this->published_at);
 }