public function actionChangePost()
 {
     if (!Yii::$app->user->can('app.forum.moderator.change-post')) {
         throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
     }
     $json = [];
     $id = $_POST['YBoardPost']['id'];
     $model = YBoardPost::findOne($id);
     if ($model == null) {
         $json['success'] = 'no';
         $json['error'] = YBoard::t('yboard', 'Post not found.');
     } else {
         $model->attributes = $_POST['YBoardPost'];
         $model->change_reason = YBoard::t('yboard', 'Post modearated by {user}', ['user' => YBoardMember::findOne(Yii::$app->user->id)->profile->username]);
         if ($model->save()) {
             $json['success'] = 'yes';
         } else {
             $json['success'] = 'no';
             $json['error'] = YBoard::t('yboard', 'Post was not updated.');
         }
     }
     echo json_encode($json);
     Yii::$app->end();
 }
Ejemplo n.º 2
0
 /**
  * handle Ajax call for sending a report on a post
  */
 public function actionSendReport()
 {
     if (!Yii::$app->user->can('app.forum.message.send-report')) {
         throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
     }
     $json = [];
     if (isset($_POST['YBoardMessage'])) {
         $model = new YBoardMessage();
         $model->attributes = $_POST['YBoardMessage'];
         $post = YBoardPost::findOne($model->post_id);
         $model->subject = YBoard::t('yboard', 'Post reported:') . ' ' . $post->subject;
         $model->sendto = 0;
         //reported post No recipient
         $model->sendfrom = Yii::$app->user->id;
         $model->outbox = 0;
         // not put to outbox
         $model->type = 2;
         //notifications
         $model->ip = Yii::$app->request->userIP;
         $user = YBoardMember::findOne(Yii::$app->user->id);
         $content = YBoard::t('yboard', 'Reporter: {user} 
         Reason:{reason} . The link to the post is attached below"', ['reason' => $model->content, 'user' => $user->profile->username]) . '<p>' . Html::a(YBoard::t('yboard', 'click to view post'), ['/' . $this->module->id . '/forum/topic', 'id' => $post->topic_id, '#' => $post->id], ['target' => '_blank']) . '</p> <p>' . Html::a(YBoard::t('yboard', 'click to view reporter [{username}]', ['username' => $user->profile->username]), ['/' . $this->module->id . '/member/view', 'id' => $user->id], ['target' => '_blank']) . '</p>' . '<p>' . YBoard::t('yboard', ' Reporter IP: {ip}]', ['ip' => Yii::$app->request->userIP]) . '</p>';
         $model->content = $content;
         if ($model->save()) {
             $json['success'] = 'yes';
             $json['message'] = YBoard::t('yboard', 'Thank you for your report.');
         } else {
             $json['success'] = 'no';
             $json['message'] = YBoard::t('yboard', 'Could not register your report.') . json_encode($_POST) . " ===== " . json_encode($model->errors);
         }
     }
     echo json_encode($json);
     Yii::$app->end();
 }
Ejemplo n.º 3
0
 public function showUpvote($post_id)
 {
     $url = Yii::$app->urlManager->createAbsoluteUrl($this->module->id . '/forum/upvote');
     $post = YBoardPost::findOne($post_id);
     if ($post === null || $post->user_id == Yii::$app->user->id) {
         return '';
     }
     $upvoted = YBoardUpvoted::find()->where(['member_id' => Yii::$app->user->identity->id])->andWhere(['post_id' => $post_id])->count();
     if ($upvoted > 0) {
         $html = Html::button(YBoard::t('yboard', 'Downvote') . ' <span class="glyphicon glyphicon-chevron-down"></span>', ['class' => 'btn btn-sm btn-default', 'title' => YBoard::t('yboard', 'Remove your appreciation'), 'id' => 'upvote_' . $post_id, 'style' => 'cursor:pointer;', 'onclick' => 'upvotePost(' . $post_id . ',' . $post->user_id . ',"' . $url . '")']);
     } else {
         $html = Html::button(YBoard::t('yboard', 'Upvote') . ' <span class="glyphicon glyphicon-chevron-up"></span>', ['class' => 'btn btn-sm btn-default', 'title' => YBoard::t('yboard', 'Appreciate this post'), 'id' => 'upvote_' . $post_id, 'style' => 'cursor:pointer;', 'onclick' => 'upvotePost(' . $post_id . ',' . $post->user_id . ',"' . $url . '")']);
     }
     return $html;
 }