/**
  * 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']);
     }
 }
Exemplo n.º 2
0
 /**
  * Replying to the message of given ID.
  * @param integer $id
  * @return string|\yii\web\Response
  */
 public function actionReply($id = null)
 {
     $model = new Message();
     $podiumUser = User::findMe();
     $reply = Message::findOne(['id' => $id, 'receiver_id' => $podiumUser->id]);
     if ($reply) {
         $model->topic = Message::re() . ' ' . $reply->topic;
         if ($model->load(Yii::$app->request->post())) {
             if ($model->validate()) {
                 if (!$podiumUser->isIgnoredBy($model->receiver_id)) {
                     $model->replyto = $reply->id;
                     if ($model->send()) {
                         $this->success(Yii::t('podium/flash', 'Message has been sent.'));
                         return $this->redirect(['messages/inbox']);
                     }
                 } else {
                     $this->error(Yii::t('podium/flash', 'Sorry! This member ignores you so you can not send the message.'));
                 }
             }
         }
         $model->receiver_id = $reply->sender_id;
         return $this->render('reply', ['model' => $model, 'reply' => $reply]);
     } else {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find the message with the given ID.'));
         return $this->redirect(['messages/inbox']);
     }
 }
Exemplo n.º 3
0
 /**
  * Reporting the post of given category ID, forum ID, thread ID, own ID and slug.
  * @param integer $cid category's ID
  * @param integer $fid forum's ID
  * @param integer $tid thread's ID
  * @param integer $pid post's ID
  * @return string|\yii\web\Response
  */
 public function actionReport($cid = null, $fid = null, $tid = null, $pid = null)
 {
     if (Yii::$app->user->isGuest) {
         $this->warning(Yii::t('podium/flash', 'Please sign in to report the post.'));
         return $this->redirect(['account/login']);
     }
     $post = Post::verify($cid, $fid, $tid, $pid);
     if (empty($post)) {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find the post you are looking for.'));
         return $this->redirect(['default/index']);
     }
     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' => $post->forum->category->id, 'fid' => $post->forum->id, 'id' => $post->thread->id, 'slug' => $post->thread->slug]);
     }
     $model = new Message();
     $model->scenario = 'report';
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->podiumReport($post)) {
             $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' => $post->forum->category->id, 'fid' => $post->forum->id, 'id' => $post->thread->id, 'slug' => $post->thread->slug]);
         } else {
             $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, 'post' => $post]);
 }
Exemplo n.º 4
0
 /**
  * Replying to the message of given ID.
  * @param integer $id
  * @return string|\yii\web\Response
  */
 public function actionReply($id = null)
 {
     $podiumUser = User::findMe();
     if (Message::tooMany($podiumUser->id)) {
         $this->warning(Yii::t('podium/flash', 'You have reached maximum {max_messages, plural, =1{ message} other{ messages}} per {max_minutes, plural, =1{ minute} other{ minutes}} limit. Wait few minutes before sending a new message.', ['max_messages' => Message::SPAM_MESSAGES, 'max_minutes' => Message::SPAM_WAIT]));
         return $this->redirect(['messages/inbox']);
     }
     $reply = Message::find()->where([Message::tableName() . '.id' => $id])->joinWith(['messageReceivers' => function ($q) use($podiumUser) {
         $q->where(['receiver_id' => $podiumUser->id]);
     }])->limit(1)->one();
     if (empty($reply)) {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find the message with the given ID.'));
         return $this->redirect(['messages/inbox']);
     }
     $model = new Message();
     $model->topic = Message::re() . ' ' . $reply->topic;
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if (!$podiumUser->isIgnoredBy($model->receiversId[0])) {
                 $model->replyto = $reply->id;
                 if ($model->send()) {
                     $this->success(Yii::t('podium/flash', 'Message has been sent.'));
                     return $this->redirect(['messages/inbox']);
                 } else {
                     $this->error(Yii::t('podium/flash', 'Sorry! There was some error while sending your message.'));
                 }
             } else {
                 $this->error(Yii::t('podium/flash', 'Sorry! This member ignores you so you can not send the message.'));
             }
         }
     }
     $model->receiversId = [$reply->sender_id];
     return $this->render('reply', ['model' => $model, 'reply' => $reply]);
 }