public function beforeAction($action) { if (parent::beforeAction($action)) { //update users online information $this->updateOnlineStatus($action); // register visit by webspider if (isset($_SERVER['HTTP_USER_AGENT'])) { $spider = YBoardSpider::find()->where(['user_agent' => $_SERVER['HTTP_USER_AGENT']])->one(); } else { $spider = null; } if ($spider != null) { $spider->setScenario('visit'); $spider->hits++; $spider->last_visit = null; $spider->save(); } //menu fixed for Views $approvals1 = YBoardPost::find()->unapprovedScope()->count(); $approvals2 = YBoardTopic::find()->andWhere(['approved' => 0])->count(); $reports = YBoardMessage::find()->reportScope()->unreadScope()->count(); $this->params['foroMenu'] = [['label' => Yii::t('app', 'Members'), 'url' => ['member/index']], ['label' => Yii::t('app', 'Pending') . ' (' . ($approvals1 + $approvals2) . ')', 'url' => ['moderator/approve'], 'visible' => Yii::$app->user->can('moderator')], ['label' => Yii::t('app', 'Reported') . ' (' . $reports . ')', 'url' => ['moderator/reported'], 'visible' => Yii::$app->user->can('moderator')]]; return true; } else { return false; } }
<?php /* @var $this ForumController */ /* @var $forum YBoardForum */ /* @var $dataProvider DataProvider */ use app\modules\yboard\YBoard; use app\modules\yboard\models\YBoardPost; use app\modules\yboard\models\YBoardTopic; use app\modules\yboard\models\YBoardMessage; use yii\widgets\ListView; use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\jui\Dialog; use yii\web\JsExpression; $this->params['breadcrumbs'] = [['label' => YBoard::t('yboard', 'Forums'), 'url' => ['forum/index']], $forum->name]; $approvals = YBoardPost::find()->unapprovedScope()->count(); $reports = YBoardMessage::find()->reportScope()->count(); $this->title = $forum->name; ?> <?php if (\Yii::$app->session->hasFlash('moderation')) { ?> <div class="flash-notice"> <?php echo \Yii::$app->session->getFlash('moderation'); ?> </div> <?php } ?>
/** * @return \yii\db\ActiveQuery */ public function getLastPost() { return $this->hasOne(YBoardPost::className(), ['id' => 'last_post_id']); }
?> </div> <div class="col-md-1"><?php echo YBoardTopic::find()->count(); ?> </div> <div class="col-md-9"></div> </div> <div class="row"> <div class="col-md-2"><?php echo YBoard::t('yboard', 'Total posts'); ?> </div> <div class="col-md-1"><?php echo YBoardPost::find()->count(); ?> </div> <div class="col-md-9"></div> </div> <div class="row"> <div class="col-md-2"><?php echo YBoard::t('yboard', 'Total members'); ?> </div> <div class="col-md-1"><?php echo YBoardMember::find()->count(); ?> </div> <div class="col-md-9"></div>
/** * 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(); }
public function beforeDelete() { if (parent::beforeDelete()) { //delete: Messages(to/from), Ban History, UpVotes, LogTopic YBoardMessage::deleteAll(['or', 'sendfrom' => $this->id, 'sendto' => $this->id]); // Post(Polls and Votes) YBoardVote::deleteAll(['user_id' => $this->id]); YBoardUpvoted::deleteAll(['member_id' => $this->id]); YBoardPoll::deleteAll(['user_id' => $this->id]); YBoardPost::deleteAll(['user_id' => $this->id]); //log topic YBoardLogTopic::deleteAll(['member_id' => $this->id]); //ban YBoardBan::deleteAll(['user_id' => $this->id]); return true; } else { return false; } }
/** * @return array relational rules. */ public function getLastPost() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return $this->hasOne(YBoardPost::className(), ['id' => 'last_post_id']); }
private function resetLastForumPost($id) { $model = YBoardForum::findOne($id); $criteria = "forum_id = {$id} and approved = 1"; $post = YBoardPost::find()->where($criteria)->orderBy('id DESC')->one(); if ($post !== null) { $model->last_post_id = $post->id; } else { $model->last_post_id = null; } $model->save(); }
/** * Reset the first post id of a topic when a first post is deleted */ private function resetFirstTopicPost() { $model = YBoardTopic::find()->where(['first_post_id' => $this->id])->one(); if ($model !== null) { $post = YBoardPost::find()->where(['topic_id' => $model->id])->orderBy('id DESC')->one(); if ($post !== null) { $model->user_id = $post->user_id; $model->first_post_id = $post->id; $model->save(); } } }
public function beforeDelete() { if (parent::beforeDelete()) { //delete all upvotes and polls YBoardPost::deleteAll(['topic_id' => $this->id]); YBoardLogTopic::deleteAll(['topic_id' => $this->id]); return true; } else { return false; } }
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; }