/** * 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('Sorry! We can not find the post you are looking for.'); return $this->redirect(['default/index']); } $category = Category::findOne(['id' => (int) $cid]); if (!$category) { $this->error('Sorry! We can not find the post you are looking for.'); return $this->redirect(['default/index']); } else { $forum = Forum::findOne(['id' => (int) $fid, 'category_id' => $category->id]); if (!$forum) { $this->error('Sorry! We can not find the post you are looking for.'); return $this->redirect(['default/index']); } else { $thread = Thread::findOne(['id' => (int) $tid, 'category_id' => $category->id, 'forum_id' => $forum->id, 'slug' => $slug]); if (!$thread) { $this->error('Sorry! We can not find the post you are looking for.'); return $this->redirect(['default/index']); } else { $post = Post::findOne(['id' => (int) $pid, 'forum_id' => $forum->id, 'thread_id' => $thread->id]); if (!$post) { $this->error('Sorry! We can not find the post you are looking for.'); return $this->redirect(['default/index']); } else { if ($post->author_id == Yii::$app->user->id) { $this->info('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 != Yii::$app->user->id) { $package[] = ['sender_id' => Yii::$app->user->id, '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 the post'), ['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', !empty($post->id) ? $post->id : '', __METHOD__); $this->success('Thank you for your report. The moderation team will take a look at this post.'); return $this->redirect(['thread', 'cid' => $category->id, 'fid' => $forum->id, 'id' => $thread->id, 'slug' => $thread->slug]); } else { $this->warning('Apparently there is no one we can send this report to except you and you already reporting it so...'); } } catch (Exception $e) { Log::error($e->getMessage(), null, __METHOD__); $this->error('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('Please sign in to report the post.'); return $this->redirect(['account/login']); } }
/** * Ignoring the user of given ID. * @return \yii\web\Response */ public function actionIgnore($id = null) { if (!Yii::$app->user->isGuest) { try { $model = (new PodiumUser())->findOne(['and', ['id' => (int) $id], ['!=', 'status', User::STATUS_REGISTERED]]); if (empty($model)) { $this->error('Sorry! We can not find Member with this ID.'); } elseif ($model->id == Yii::$app->user->id) { $this->error('Sorry! You can not ignore your own account.'); } elseif ($model->id == User::ROLE_ADMIN) { $this->error('Sorry! You can not ignore Administrator.'); } else { if ($model->isIgnoredBy(Yii::$app->user->id)) { Yii::$app->db->createCommand()->delete('{{%podium_user_ignore}}', 'user_id = :uid AND ignored_id = :iid', [':uid' => Yii::$app->user->id, ':iid' => $model->id])->execute(); Log::info('User unignored', !empty($model->id) ? $model->id : '', __METHOD__); $this->success('User has been unignored.'); } else { Yii::$app->db->createCommand()->insert('{{%podium_user_ignore}}', ['user_id' => Yii::$app->user->id, 'ignored_id' => $model->id])->execute(); Log::info('User ignored', !empty($model->id) ? $model->id : '', __METHOD__); $this->success('User has been ignored.'); } } } catch (Exception $e) { $this->error('Sorry! There was some error while performing this action.'); Log::error($e->getMessage(), null, __METHOD__); } } return $this->redirect(['members/index']); }
/** * Updating the forums order. * @return string|\yii\web\Response */ public function actionSortForum() { if (Yii::$app->request->isAjax) { $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', !empty($moved->id) ? $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 $this->redirect(['admin/forums']); } }
/** * Sending the account password reset link. * @return string|\yii\web\Response */ public function actionReset() { $model = new ReForm(); if ($model->load(Yii::$app->request->post())) { if ($model->reset()) { $email = Content::find()->where(['name' => 'email-pass'])->one(); if ($email) { $topic = $email->topic; $content = $email->content; } else { $topic = Content::PASS_TITLE; $content = Content::PASS_BODY; } $forum = Config::getInstance()->get('name'); if (Email::queue($model->getUser()->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['account/password', 'token' => $model->getUser()->password_reset_token], true), Url::to(['account/password', 'token' => $model->getUser()->password_reset_token], true)), $content)), !empty($model->getUser()->id) ? $model->getUser()->id : null)) { Log::info('Password reset link queued', !empty($model->getUser()->id) ? $model->getUser()->id : '', __METHOD__); $this->success('The password reset link has been sent to your e-mail address.'); } else { Log::error('Error while queuing password reset link', !empty($model->getUser()->id) ? $model->getUser()->id : '', __METHOD__); $this->error('Sorry! There was some error while sending you the password reset link. Contact administrator about this problem.'); } return $this->module->goPodium(); } else { $this->error('Sorry! We can not find the account with that user name or e-mail address.'); } } return $this->render('reset', ['model' => $model]); }
/** * Updating the forum details. * @return string|\yii\web\Response */ public function actionForum() { $model = Meta::findOne(['user_id' => Yii::$app->user->id]); if (empty($model)) { $model = new Meta(); } if ($model->load(Yii::$app->request->post())) { $model->user_id = Yii::$app->user->id; $uploadAvatar = false; $path = Yii::getAlias('@webroot/avatars'); $avatar = UploadedFile::getInstance($model, 'image'); if ($avatar) { $folderExists = true; if (!file_exists($path)) { if (!FileHelper::createDirectory($path)) { $folderExists = false; Log::error('Error while creating avatars folder', null, __METHOD__); $this->error('Sorry! There was an error while creating the avatars folder. Contact administrator about this problem.'); } } if ($folderExists) { if (!empty($model->avatar)) { if (!unlink($path . DIRECTORY_SEPARATOR . $model->avatar)) { Log::error('Error while deleting old avatar image', null, __METHOD__); } } $model->avatar = Yii::$app->security->generateRandomString() . '.' . $avatar->getExtension(); $uploadAvatar = true; } } if ($model->save()) { if ($uploadAvatar) { if (!$avatar->saveAs($path . DIRECTORY_SEPARATOR . $model->avatar)) { Log::error('Error while saving avatar image', null, __METHOD__); $this->error('Sorry! There was an error while uploading the avatar image. Contact administrator about this problem.'); } } Log::info('Profile updated', !empty($model->id) ? $model->id : '', __METHOD__); $this->success('Your profile details have been updated.'); return $this->refresh(); } else { $model->current_password = null; } } return $this->render('forum', ['model' => $model, 'user' => User::findOne(Yii::$app->user->id)]); }