/** * Reporting the post of given category ID, forum ID, thread ID, own ID and slug. * @param integer $cid * @param integer $fid * @param integer $tid * @param integer $pid * @param string $slug * @return string|\yii\web\Response */ public function actionReport($cid = null, $fid = null, $tid = null, $pid = null, $slug = null) { if (!Yii::$app->user->isGuest) { if (!is_numeric($cid) || $cid < 1 || !is_numeric($fid) || $fid < 1 || !is_numeric($tid) || $tid < 1 || !is_numeric($pid) || $pid < 1 || empty($slug)) { $this->error(Yii::t('podium/flash', 'Sorry! We can not find the post you are looking for.')); return $this->redirect(['default/index']); } $category = Category::findOne((int) $cid); if (!$category) { $this->error(Yii::t('podium/flash', 'Sorry! We can not find the post you are looking for.')); return $this->redirect(['default/index']); } else { $forum = Forum::find()->where(['id' => (int) $fid, 'category_id' => $category->id])->limit(1)->one(); if (!$forum) { $this->error(Yii::t('podium/flash', 'Sorry! We can not find the post you are looking for.')); return $this->redirect(['default/index']); } else { $thread = Thread::find()->where(['id' => (int) $tid, 'category_id' => $category->id, 'forum_id' => $forum->id, 'slug' => $slug])->limit(1)->one(); if (!$thread) { $this->error(Yii::t('podium/flash', 'Sorry! We can not find the post you are looking for.')); return $this->redirect(['default/index']); } else { $post = Post::find()->where(['id' => (int) $pid, 'forum_id' => $forum->id, 'thread_id' => $thread->id])->limit(1)->one(); if (!$post) { $this->error(Yii::t('podium/flash', 'Sorry! We can not find the post you are looking for.')); return $this->redirect(['default/index']); } else { if ($post->author_id == User::loggedId()) { $this->info(Yii::t('podium/flash', 'You can not report your own post. Please contact the administrator or moderators if you have got any concerns regarding your post.')); return $this->redirect(['default/thread', 'cid' => $category->id, 'fid' => $forum->id, 'id' => $thread->id, 'slug' => $thread->slug]); } else { $model = new Message(); $model->setScenario('report'); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { try { $mods = $forum->getMods(); $package = []; foreach ($mods as $mod) { if ($mod != User::loggedId()) { $package[] = ['sender_id' => User::loggedId(), 'receiver_id' => $mod, 'topic' => Yii::t('podium/view', 'Complaint about the post #{id}', ['id' => $post->id]), 'content' => $model->content . '<hr>' . Html::a(Yii::t('podium/view', 'Direct link to this post'), ['default/show', 'id' => $post->id]) . '<hr>' . '<strong>' . Yii::t('podium/view', 'Post contents') . '</strong><br><blockquote>' . $post->content . '</blockquote>', 'sender_status' => Message::STATUS_REMOVED, 'receiver_status' => Message::STATUS_NEW, 'created_at' => time(), 'updated_at' => time()]; } } if (!empty($package)) { Yii::$app->db->createCommand()->batchInsert(Message::tableName(), ['sender_id', 'receiver_id', 'topic', 'content', 'sender_status', 'receiver_status', 'created_at', 'updated_at'], array_values($package))->execute(); Cache::getInstance()->delete('user.newmessages'); Log::info('Post reported', $post->id, __METHOD__); $this->success(Yii::t('podium/flash', 'Thank you for your report. The moderation team will take a look at this post.')); return $this->redirect(['default/thread', 'cid' => $category->id, 'fid' => $forum->id, 'id' => $thread->id, 'slug' => $thread->slug]); } else { $this->warning(Yii::t('podium/flash', 'Apparently there is no one we can send this report to except you and you are already reporting it so...')); } } catch (Exception $e) { Log::error($e->getMessage(), null, __METHOD__); $this->error(Yii::t('podium/flash', 'Sorry! There was an error while notifying the moderation team. Contact administrator about this problem.')); } } } return $this->render('report', ['model' => $model, 'category' => $category, 'forum' => $forum, 'thread' => $thread, 'post' => $post]); } } } } } } else { $this->warning(Yii::t('podium/flash', 'Please sign in to report the post.')); return $this->redirect(['account/login']); } }
/** * Updating the forums order. * @return string|\yii\web\Response */ public function actionSortForum() { if (Yii::$app->request->isAjax) { if (User::can(Rbac::PERM_UPDATE_FORUM)) { $modelId = Yii::$app->request->post('id'); $modelCategory = Yii::$app->request->post('category'); $new = Yii::$app->request->post('new'); if (is_numeric($modelId) && is_numeric($modelCategory) && is_numeric($new) && $modelId > 0 && $modelCategory > 0 && $new >= 0) { $moved = Forum::findOne((int) $modelId); $movedCategory = Category::findOne((int) $modelCategory); if ($moved && $modelCategory && $moved->category_id == $movedCategory->id) { $query = (new Query())->from(Forum::tableName())->where('id != :id AND category_id = :cid')->params([':id' => $moved->id, ':cid' => $movedCategory->id])->orderBy(['sort' => SORT_ASC, 'id' => SORT_ASC])->indexBy('id'); $next = 0; $newSort = -1; try { foreach ($query->each() as $id => $forum) { if ($next == (int) $new) { $newSort = $next; $next++; } Yii::$app->db->createCommand()->update(Forum::tableName(), ['sort' => $next], 'id = :id', [':id' => $id])->execute(); $next++; } if ($newSort == -1) { $newSort = $next; } $moved->sort = $newSort; if (!$moved->save()) { return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', "Sorry! We can not save new forums' order."), ['class' => 'text-danger']); } else { Log::info('Forums orded updated', $moved->id, __METHOD__); return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-ok-circle']) . ' ' . Yii::t('podium/view', "New forums' order has been saved."), ['class' => 'text-success']); } } catch (Exception $e) { Log::error($e->getMessage(), null, __METHOD__); return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', "Sorry! We can not save new forums' order."), ['class' => 'text-danger']); } } else { return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Sorry! We can not find Forum with this ID.'), ['class' => 'text-danger']); } } else { return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Sorry! Sorting parameters are wrong.'), ['class' => 'text-danger']); } } else { return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'You are not allowed to perform this action.'), ['class' => 'text-danger']); } } else { return $this->redirect(['admin/forums']); } }