/**
  * Creates inherited user account.
  */
 public function init()
 {
     parent::init();
     if (!Yii::$app->user->isGuest) {
         if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
             $user = User::findMe();
             if (empty($user)) {
                 $new = new User();
                 $new->setScenario('installation');
                 $new->inherited_id = Yii::$app->user->id;
                 $new->status = User::STATUS_ACTIVE;
                 $new->role = User::ROLE_MEMBER;
                 $new->timezone = User::DEFAULT_TIMEZONE;
                 if ($new->save()) {
                     $this->success(Yii::t('podium/flash', 'Hey! Your new forum account has just been automatically created! Go to {link} to complement it.', ['link' => Html::a(Yii::t('podium/view', 'Profile'))]));
                     Cache::clearAfterActivate();
                     Log::info('Inherited account created', $new->id, __METHOD__);
                 } else {
                     throw new Exception(Yii::t('podium/view', 'There was an error while creating inherited user account. Podium can not run with the current configuration. Please contact administrator about this problem.'));
                 }
             } elseif ($user->status == User::STATUS_BANNED) {
                 return $this->redirect(['default/ban']);
             }
         } else {
             $user = Yii::$app->user->identity;
         }
         if ($user && !empty($user->timezone)) {
             Yii::$app->formatter->timeZone = $user->timezone;
         }
     }
 }
 /**
  * Deleting the message of given ID.
  * @param integer $id
  * @param integer $perm wheter to delete message permanently
  * @return \yii\web\Response
  */
 public function actionDelete($id = null, $perm = 0)
 {
     if (!is_numeric($id) || $id < 1 || !in_array($perm, [0, 1])) {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find the message you are looking for.'));
         return $this->redirect(['messages/inbox']);
     } else {
         $model = Message::find()->where(['and', ['id' => (int) $id], ['or', 'receiver_id' => User::loggedId(), 'sender_id' => User::loggedId()]])->limit(1)->one();
         if ($model) {
             if ($model->remove($perm)) {
                 if ($perm) {
                     $this->success(Yii::t('podium/flash', 'Message has been deleted permanently.'));
                 } else {
                     $this->success(Yii::t('podium/flash', 'Message has been moved to Deleted Messages.'));
                 }
             } else {
                 Log::error('Error while deleting message', $model->id, __METHOD__);
                 $this->error(Yii::t('podium/flash', 'Sorry! We can not delete this message. Contact administrator about this problem.'));
             }
         } else {
             $this->error(Yii::t('podium/flash', 'Sorry! We can not find the message with the given ID.'));
         }
         if ($perm) {
             return $this->redirect(['messages/deleted']);
         } else {
             return $this->redirect(['messages/inbox']);
         }
     }
 }
示例#3
0
 /**
  * Creates inherited user account.
  */
 public function init()
 {
     parent::init();
     if (!Yii::$app->user->isGuest) {
         if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
             $user = User::findMe();
             if (empty($user)) {
                 $new = new User();
                 $new->setScenario('installation');
                 $new->inherited_id = Yii::$app->user->id;
                 $new->status = User::STATUS_ACTIVE;
                 $new->role = User::ROLE_MEMBER;
                 $new->timezone = User::DEFAULT_TIMEZONE;
                 if ($new->save()) {
                     $this->success(Yii::t('podium/flash', Messages::ACCOUNT_INHERITED, ['link' => Html::a(Yii::t('podium/layout', 'Profile'))]));
                     Cache::clearAfterActivate();
                     Log::info('Inherited account created', $new->id, __METHOD__);
                 } else {
                     throw new Exception(Yii::t('podium/view', Messages::ACCOUNT_INHERITED_ERROR));
                 }
             } elseif ($user->status == User::STATUS_BANNED) {
                 return $this->redirect(['default/ban']);
             }
         } else {
             $user = Yii::$app->user->identity;
         }
         if ($user && !empty($user->timezone)) {
             Yii::$app->formatter->timeZone = $user->timezone;
         }
     }
 }
示例#4
0
 /**
  * Adds email to queue.
  * @param string $address
  * @param string $subject
  * @param string $content
  * @param integer|null $user_id
  * @return boolean
  */
 public static function queue($address, $subject, $content, $user_id = null)
 {
     try {
         $email = new Email();
         $email->user_id = $user_id;
         $email->email = $address;
         $email->subject = $subject;
         $email->content = $content;
         $email->status = Email::STATUS_PENDING;
         $email->attempt = 0;
         return $email->save();
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }
示例#5
0
 /**
  * Deleting the received message of given ID.
  * @param integer $id
  * @return \yii\web\Response
  */
 public function actionDeleteReceived($id = null)
 {
     if (!is_numeric($id) || $id < 1) {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find the message you are looking for.'));
     } else {
         $model = MessageReceiver::find()->where(['and', ['id' => $id, 'receiver_id' => User::loggedId()], ['!=', 'receiver_status', MessageReceiver::STATUS_DELETED]])->limit(1)->one();
         if (empty($model)) {
             $this->error(Yii::t('podium/flash', 'Sorry! We can not find the message with the given ID.'));
         } else {
             if ($model->remove()) {
                 $this->success(Yii::t('podium/flash', 'Message has been deleted.'));
             } else {
                 Log::error('Error while deleting received message', $model->id, __METHOD__);
                 $this->error(Yii::t('podium/flash', 'Sorry! We can not delete this message. Contact administrator about this problem.'));
             }
         }
     }
     return $this->redirect(['messages/inbox']);
 }
示例#6
0
 /**
  * Sets new categories order.
  * @param integer $order new category sorting order number
  * @return boolean
  * @throws Exception
  * @since 0.2
  */
 public function newOrder($order)
 {
     try {
         $next = 0;
         $newSort = -1;
         $query = (new Query())->from(Category::tableName())->where('id != :id')->params([':id' => $this->id])->orderBy(['sort' => SORT_ASC, 'id' => SORT_ASC])->indexBy('id');
         foreach ($query->each() as $id => $forum) {
             if ($next == $order) {
                 $newSort = $next;
                 $next++;
             }
             Yii::$app->db->createCommand()->update(Category::tableName(), ['sort' => $next], 'id = :id', [':id' => $id])->execute();
             $next++;
         }
         if ($newSort == -1) {
             $newSort = $next;
         }
         $this->sort = $newSort;
         if (!$this->save()) {
             throw new Exception('Categories order saving error');
         }
         Log::info('Categories orded updated', $this->id, __METHOD__);
         return true;
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }
 /**
  * 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 the 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 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']);
     }
 }
 /**
  * Sending the account password reset link.
  * @return string|\yii\web\Response
  */
 public function actionReset()
 {
     if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
         $this->info(Yii::t('podium/flash', 'Please contact the administrator to reset your account password.'));
         return $this->module->goPodium();
     }
     $model = new ReForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->reset()) {
             $email = Content::find()->where(['name' => 'email-pass'])->limit(1)->one();
             if ($email) {
                 $topic = $email->topic;
                 $content = $email->content;
             } else {
                 $topic = Messages::EMAIL_PASS_TITLE;
                 $content = Messages::EMAIL_PASS_BODY;
             }
             $forum = Config::getInstance()->get('name');
             if (!empty($model->email)) {
                 if (Email::queue($model->user->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['account/password', 'token' => $model->user->password_reset_token], true), Url::to(['account/password', 'token' => $model->user->password_reset_token], true)), $content)), !empty($model->user->id) ? $model->user->id : null)) {
                     Log::info('Password reset link queued', $model->user->id, __METHOD__);
                     $this->success(Yii::t('podium/flash', 'The password reset link has been sent to your e-mail address.'));
                 } else {
                     Log::error('Error while queuing password reset link', $model->user->id, __METHOD__);
                     $this->error(Yii::t('podium/flash', 'Sorry! There was some error while sending you the password reset link. Contact administrator about this problem.'));
                 }
             } else {
                 Log::error('Error while queuing password reset link - no email set', $model->user->id, __METHOD__);
                 $this->error(Yii::t('podium/flash', 'Sorry! There is no e-mail address saved with your account. Contact administrator about resetting password.'));
             }
             return $this->module->goPodium();
         } else {
             $this->error(Yii::t('podium/flash', 'Sorry! We can not find the account with that user name or e-mail address.'));
         }
     }
     return $this->render('reset', ['model' => $model]);
 }
示例#9
0
 /**
  * Performs post report sending to moderators.
  * @param Post $post reported post
  * @return boolean
  * @since 0.2
  */
 public function podiumReport($post = null)
 {
     try {
         if (empty($post)) {
             throw new Exception('Reported post missing');
         }
         $package = [];
         $mods = $post->forum->mods;
         foreach ($mods as $mod) {
             if ($mod != User::loggedId()) {
                 $package[] = [User::loggedId(), $mod, Yii::t('podium/view', 'Complaint about the post #{id}', ['id' => $post->id]), $this->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><div class="blockquote">' . $post->content . '</div>', Message::STATUS_REMOVED, Message::STATUS_NEW, time(), time()];
             }
         }
         if (empty($package)) {
             throw new Exception('No one to send report to');
         }
         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__);
         return true;
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }
示例#10
0
 /**
  * Updates tag words.
  * @throws Exception
  */
 protected function _updateWords()
 {
     try {
         $vocabulary = [];
         $allWords = $this->_prepareWords();
         $this->_addNewWords($allWords);
         $query = (new Query())->from(Vocabulary::tableName())->where(['word' => $allWords]);
         foreach ($query->each() as $vocabularyNew) {
             $vocabulary[$vocabularyNew['id']] = [$vocabularyNew['id'], $this->id];
         }
         if (!empty($vocabulary)) {
             Yii::$app->db->createCommand()->batchInsert('{{%podium_vocabulary_junction}}', ['word_id', 'post_id'], array_values($vocabulary))->execute();
         }
         $query = (new Query())->from('{{%podium_vocabulary_junction}}')->where(['post_id' => $this->id]);
         foreach ($query->each() as $junk) {
             if (!array_key_exists($junk['word_id'], $vocabulary)) {
                 Yii::$app->db->createCommand()->delete('{{%podium_vocabulary_junction}}', ['id' => $junk['id']])->execute();
             }
         }
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
         throw $e;
     }
 }
示例#11
0
 /**
  * Prepares notification email.
  * @param integer $thread
  */
 public static function notify($thread)
 {
     if (is_numeric($thread) && $thread > 0) {
         $email = Content::find()->where(['name' => 'email-sub'])->limit(1)->one();
         if ($email) {
             $topic = $email->topic;
             $content = $email->content;
         } else {
             $topic = Messages::EMAIL_SUB_TITLE;
             $content = Messages::EMAIL_SUB_BODY;
         }
         $forum = Config::getInstance()->get('name');
         $subs = static::find()->where(['thread_id' => (int) $thread, 'post_seen' => self::POST_SEEN]);
         foreach ($subs->each() as $sub) {
             $sub->post_seen = self::POST_NEW;
             if ($sub->save()) {
                 if (!empty($sub->user->email)) {
                     if (Email::queue($sub->user->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['default/last', 'id' => $sub->thread_id], true), Url::to(['default/last', 'id' => $sub->thread_id], true)), $content)), $sub->user_id)) {
                         Log::info('Subscription notice link queued', $sub->user_id, __METHOD__);
                     } else {
                         Log::error('Error while queuing subscription notice link', $sub->user_id, __METHOD__);
                     }
                 } else {
                     Log::error('Error while queuing subscription notice link - no email set', $sub->user_id, __METHOD__);
                 }
             }
         }
     }
 }
示例#12
0
Pjax::begin();
echo PageSizer::widget();
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'filterSelector' => 'select#per-page', 'tableOptions' => ['class' => 'table table-striped table-hover'], 'rowOptions' => function ($model) {
    switch ($model->level) {
        case 1:
            $class = 'danger';
            break;
        case 2:
            $class = 'warning';
            break;
        default:
            $class = '';
    }
    return ['class' => $class];
}, 'columns' => [['attribute' => 'id', 'label' => Yii::t('podium/view', 'ID') . Helper::sortOrder('id'), 'encodeLabel' => false], ['attribute' => 'level', 'label' => Yii::t('podium/view', 'Level') . Helper::sortOrder('level'), 'encodeLabel' => false, 'filter' => Log::getTypes(), 'format' => 'raw', 'value' => function ($model) {
    $name = ArrayHelper::getValue(Log::getTypes(), $model->level, 'other');
    switch ($model->level) {
        case 1:
            $class = 'danger';
            break;
        case 2:
            $class = 'warning';
            break;
        case 4:
            $class = 'info';
            break;
        default:
            $class = 'default';
    }
    return Html::tag('span', $name, ['class' => 'label label-' . $class]);
}], ['attribute' => 'category', 'label' => Yii::t('podium/view', 'Category') . Helper::sortOrder('category'), 'encodeLabel' => false, 'value' => function ($model) {
示例#13
0
 /**
  * Performs marking all unread threads as seen for user.
  * @return boolean
  * @throws Exception
  * @since 0.2
  */
 public static function podiumMarkAllSeen()
 {
     try {
         $loggedId = User::loggedId();
         if (empty($loggedId)) {
             throw new Exception('User ID missing');
         }
         $batch = [];
         $threadsPrevMarked = Thread::find()->joinWith('threadView')->where(['and', ['user_id' => $loggedId], ['or', new Expression('`new_last_seen` < `new_post_at`'), new Expression('`edited_last_seen` < `edited_post_at`')]]);
         $time = time();
         foreach ($threadsPrevMarked->each() as $thread) {
             $batch[] = $thread->id;
         }
         if (!empty($batch)) {
             Yii::$app->db->createCommand()->update(ThreadView::tableName(), ['new_last_seen' => $time, 'edited_last_seen' => $time], ['thread_id' => $batch, 'user_id' => $loggedId])->execute();
         }
         $batch = [];
         $threadsNew = Thread::find()->joinWith('threadView')->where(['user_id' => null]);
         foreach ($threadsNew->each() as $thread) {
             $batch[] = [$loggedId, $thread->id, $time, $time];
         }
         if (!empty($batch)) {
             Yii::$app->db->createCommand()->batchInsert(ThreadView::tableName(), ['user_id', 'thread_id', 'new_last_seen', 'edited_last_seen'], $batch)->execute();
         }
         return true;
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }
示例#14
0
 /**
  * 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']);
     }
 }
示例#15
0
 /**
  * Prepares notification email.
  * @param integer $thread
  */
 public static function notify($thread)
 {
     if (is_numeric($thread) && $thread > 0) {
         $email = Content::find()->where(['name' => 'email-sub'])->limit(1)->one();
         if ($email) {
             $topic = $email->topic;
             $content = $email->content;
         } else {
             $topic = 'New post in subscribed thread at {forum}';
             $content = '<p>There has been new post added in the thread you are subscribing. Click the following link to read the thread.</p><p>{link}</p><p>See you soon!<br>{forum}</p>';
         }
         $forum = Config::getInstance()->get('name');
         $subs = static::find()->where(['thread_id' => (int) $thread, 'post_seen' => self::POST_SEEN]);
         foreach ($subs->each() as $sub) {
             $sub->post_seen = self::POST_NEW;
             if ($sub->save()) {
                 if (!empty($sub->user->email)) {
                     if (Email::queue($sub->user->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['default/last', 'id' => $sub->thread_id], true), Url::to(['default/last', 'id' => $sub->thread_id], true)), $content)), $sub->user_id)) {
                         Log::info('Subscription notice link queued', $sub->user_id, __METHOD__);
                     } else {
                         Log::error('Error while queuing subscription notice link', $sub->user_id, __METHOD__);
                     }
                 } else {
                     Log::error('Error while queuing subscription notice link - no email set', $sub->user_id, __METHOD__);
                 }
             }
         }
     }
 }
 /**
  * Removes message.
  * @return boolean
  */
 public function remove()
 {
     $clearCache = false;
     if ($this->receiver_status == self::STATUS_NEW) {
         $clearCache = true;
     }
     $deleteParent = null;
     $transaction = static::getDb()->beginTransaction();
     try {
         if ($this->message->sender_status != Message::STATUS_DELETED) {
             $this->receiver_status = self::STATUS_DELETED;
             if ($this->save()) {
                 if ($clearCache) {
                     Cache::getInstance()->deleteElement('user.newmessages', $this->receiver_id);
                 }
                 $transaction->commit();
                 return true;
             } else {
                 throw new Exception('Message status changing error!');
             }
         } else {
             if ($this->message->sender_status == Message::STATUS_DELETED && count($this->message->messageReceivers) == 1) {
                 $deleteParent = $this->message;
             }
             if ($this->delete()) {
                 if ($clearCache) {
                     Cache::getInstance()->deleteElement('user.newmessages', $this->receiver_id);
                 }
                 if ($deleteParent) {
                     if (!$deleteParent->delete()) {
                         throw new Exception('Sender message deleting error!');
                     }
                 }
                 $transaction->commit();
                 return true;
             } else {
                 throw new Exception('Message removing error!');
             }
         }
     } catch (Exception $e) {
         $transaction->rollBack();
         Log::error($e->getMessage(), $this->id, __METHOD__);
     }
     return false;
 }
 /**
  * Sending the account password reset link.
  * @return string|\yii\web\Response
  */
 public function actionReset()
 {
     if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
         $this->info(Yii::t('podium/flash', 'Please contact the administrator to reset your account password.'));
         return $this->module->goPodium();
     }
     $model = new ReForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->reset()) {
             $email = Content::find()->where(['name' => 'email-pass'])->limit(1)->one();
             if ($email) {
                 $topic = $email->topic;
                 $content = $email->content;
             } else {
                 $topic = '{forum} password reset link';
                 $content = '<p>{forum} Password Reset</p><p>You are receiving this e-mail because someone has started the process of changing the account password at {forum}.<br>If this person is you open the following link in your Internet browser and follow the instructions on screen.</p><p>{link}</p><p>If it was not you just ignore this e-mail.</p><p>Thank you!<br>{forum}</p>';
             }
             $forum = Config::getInstance()->get('name');
             if (!empty($model->email)) {
                 if (Email::queue($model->user->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['account/password', 'token' => $model->user->password_reset_token], true), Url::to(['account/password', 'token' => $model->user->password_reset_token], true)), $content)), !empty($model->user->id) ? $model->user->id : null)) {
                     Log::info('Password reset link queued', $model->user->id, __METHOD__);
                     $this->success(Yii::t('podium/flash', 'The password reset link has been sent to your e-mail address.'));
                 } else {
                     Log::error('Error while queuing password reset link', $model->user->id, __METHOD__);
                     $this->error(Yii::t('podium/flash', 'Sorry! There was some error while sending you the password reset link. Contact administrator about this problem.'));
                 }
             } else {
                 Log::error('Error while queuing password reset link - no email set', $model->user->id, __METHOD__);
                 $this->error(Yii::t('podium/flash', 'Sorry! There is no e-mail address saved with your account. Contact administrator about resetting password.'));
             }
             return $this->module->goPodium();
         } else {
             $this->error(Yii::t('podium/flash', 'Sorry! We can not find the account with that user name or e-mail address.'));
         }
     }
     return $this->render('reset', ['model' => $model]);
 }
示例#18
0
 /**
  * Updates role after change.
  * @param integer $id
  * @param integer $role
  */
 public static function updateRole($id, $role)
 {
     $activity = self::find()->where(['user_id' => $id])->limit(1)->one();
     if ($activity) {
         $activity->role = $role;
         if ($activity->save()) {
             Cache::getInstance()->delete('forum.lastactive');
         } else {
             Log::error('Cannot update user activity', $id, __METHOD__);
         }
     } else {
         Log::error('Cannot update user activity', $id, __METHOD__);
     }
 }
 /**
  * Marking all unread posts as seen.
  * @return string|\yii\web\Response
  */
 public function actionMarkSeen()
 {
     if (Yii::$app->user->isGuest) {
         $this->info(Yii::t('podium/flash', 'This action is available for registered users only.'));
         return $this->redirect(['account/login']);
     }
     try {
         $loggedId = User::loggedId();
         $batch = [];
         $threadsPrevMarked = Thread::find()->joinWith('threadView')->where(['and', ['user_id' => User::loggedId()], ['or', new Expression('`new_last_seen` < `new_post_at`'), new Expression('`edited_last_seen` < `edited_post_at`')]]);
         $time = time();
         foreach ($threadsPrevMarked->each() as $thread) {
             $batch[] = $thread->id;
         }
         if (!empty($batch)) {
             Yii::$app->db->createCommand()->update(ThreadView::tableName(), ['new_last_seen' => $time, 'edited_last_seen' => $time], ['thread_id' => $batch, 'user_id' => $loggedId])->execute();
         }
         $batch = [];
         $threadsNew = Thread::find()->joinWith('threadView')->where(['user_id' => null]);
         foreach ($threadsNew->each() as $thread) {
             $batch[] = [$loggedId, $thread->id, $time, $time];
         }
         if (!empty($batch)) {
             Yii::$app->db->createCommand()->batchInsert(ThreadView::tableName(), ['user_id', 'thread_id', 'new_last_seen', 'edited_last_seen'], $batch)->execute();
         }
         $this->success(Yii::t('podium/flash', 'All unread threads have been marked as seen.'));
         return $this->redirect(['default/index']);
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
         $this->error(Yii::t('podium/flash', 'Sorry! There was an error while marking threads as seen. Contact administrator about this problem.'));
         return $this->redirect(['default/unread-posts']);
     }
 }
 /**
  * Ignoring the user of given ID.
  * @param integer $id
  * @return \yii\web\Response
  */
 public function actionIgnore($id = null)
 {
     if (!Yii::$app->user->isGuest) {
         try {
             $model = User::find()->where(['and', ['id' => (int) $id], ['!=', 'status', User::STATUS_REGISTERED]])->limit(1)->one();
             if (empty($model)) {
                 $this->error(Yii::t('podium/flash', 'Sorry! We can not find Member with this ID.'));
             } elseif ($model->id == User::loggedId()) {
                 $this->error(Yii::t('podium/flash', 'Sorry! You can not ignore your own account.'));
             } elseif ($model->id == User::ROLE_ADMIN) {
                 $this->error(Yii::t('podium/flash', 'Sorry! You can not ignore Administrator.'));
             } else {
                 if ($model->isIgnoredBy(User::loggedId())) {
                     Yii::$app->db->createCommand()->delete('{{%podium_user_ignore}}', 'user_id = :uid AND ignored_id = :iid', [':uid' => User::loggedId(), ':iid' => $model->id])->execute();
                     Log::info('User unignored', !empty($model->id) ? $model->id : '', __METHOD__);
                     $this->success(Yii::t('podium/flash', 'User has been unignored.'));
                 } else {
                     Yii::$app->db->createCommand()->insert('{{%podium_user_ignore}}', ['user_id' => User::loggedId(), 'ignored_id' => $model->id])->execute();
                     Log::info('User ignored', !empty($model->id) ? $model->id : '', __METHOD__);
                     $this->success(Yii::t('podium/flash', 'User has been ignored.'));
                 }
             }
         } catch (Exception $e) {
             $this->error(Yii::t('podium/flash', 'Sorry! There was some error while performing this action.'));
             Log::error($e->getMessage(), null, __METHOD__);
         }
     }
     return $this->redirect(['members/index']);
 }
示例#21
0
 /**
  * Updating the module configuration.
  * @return string|\yii\web\Response
  */
 public function actionSettings()
 {
     $model = new ConfigForm();
     $data = Yii::$app->request->post('ConfigForm');
     if ($data) {
         if (User::can(Rbac::PERM_CHANGE_SETTINGS)) {
             if ($model->update($data)) {
                 Log::info('Settings updated', null, __METHOD__);
                 $this->success(Yii::t('podium/flash', 'Settings have been updated.'));
                 return $this->refresh();
             } else {
                 $this->error(Yii::t('podium/flash', "One of the setting's values is too long (255 characters max)."));
             }
         } else {
             $this->error(Yii::t('podium/flash', 'You are not allowed to perform this action.'));
         }
     }
     return $this->render('settings', ['model' => $model]);
 }
示例#22
0
 /**
  * Updates friend status for the user.
  * @return boolean
  * @since 0.2
  */
 public function updateFriend()
 {
     try {
         if ($this->isBefriendedBy(User::loggedId())) {
             Yii::$app->db->createCommand()->delete('{{%podium_user_friend}}', 'user_id = :uid AND friend_id = :iid', [':uid' => User::loggedId(), ':iid' => $this->id])->execute();
             Log::info('User unfriended', $this->id, __METHOD__);
         } else {
             Yii::$app->db->createCommand()->insert('{{%podium_user_friend}}', ['user_id' => User::loggedId(), 'friend_id' => $this->id])->execute();
             Log::info('User befriended', $this->id, __METHOD__);
         }
         Cache::getInstance()->deleteElement('user.friends', $this->id);
         return true;
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }
示例#23
0
 /**
  * Sets configuration value of the given name.
  * Every change automatically updates the cache.
  * @param string $name configuration name
  * @param string $value configuration value
  * @return boolean
  */
 public function set($name, $value)
 {
     try {
         if (is_string($name) && is_string($value)) {
             if ($value == '') {
                 if (array_key_exists($name, $this->_defaults)) {
                     $value = $this->_defaults[$name];
                 }
             }
             if ((new Query())->from('{{%podium_config}}')->where(['name' => $name])->exists()) {
                 Yii::$app->db->createCommand()->update('{{%podium_config}}', ['value' => $value], 'name = :name', [':name' => $name])->execute();
             } else {
                 Yii::$app->db->createCommand()->insert('{{%podium_config}}', ['name' => $name, 'value' => $value])->execute();
             }
             $this->cache->set('config', array_merge($this->_defaults, $this->getFromDb()));
             return true;
         }
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }
示例#24
0
 /**
  * Performs vote processing.
  * @param boolean $up whether this is up or downvote
  * @param integer $count number of user's cached votes
  * @return boolean
  * @since 0.2
  */
 public function podiumThumb($up = true, $count = 0)
 {
     try {
         if ($this->thumb) {
             if ($this->thumb->thumb == 1 && !$up) {
                 $this->thumb->thumb = -1;
                 if ($this->thumb->save()) {
                     $this->updateCounters(['likes' => -1, 'dislikes' => 1]);
                 }
             } elseif ($this->thumb->thumb == -1 && $up) {
                 $this->thumb->thumb = 1;
                 if ($this->thumb->save()) {
                     $this->updateCounters(['likes' => 1, 'dislikes' => -1]);
                 }
             }
         } else {
             $postThumb = new PostThumb();
             $postThumb->post_id = $this->id;
             $postThumb->user_id = User::loggedId();
             $postThumb->thumb = $up ? 1 : -1;
             if ($postThumb->save()) {
                 if ($postThumb->thumb) {
                     $this->updateCounters(['likes' => 1]);
                 } else {
                     $this->updateCounters(['dislikes' => 1]);
                 }
             }
         }
         if ($count == 0) {
             Cache::getInstance()->set('user.votes.' . User::loggedId(), ['count' => 1, 'expire' => time() + 3600]);
         } else {
             Cache::getInstance()->setElement('user.votes.' . User::loggedId(), 'count', $count + 1);
         }
         return true;
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }
示例#25
0
 /**
  * Removes threads' subscriptions of given IDs.
  * @param array $threads threads' IDs
  * @return boolean
  * @since 0.2
  */
 public static function remove($threads = [])
 {
     try {
         if (!empty($threads)) {
             Yii::$app->db->createCommand()->delete(Subscription::tableName(), ['id' => $threads, 'user_id' => User::loggedId()])->execute();
             return true;
         }
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }
示例#26
0
 /**
  * Activates account.
  * @return boolean
  */
 public function activate()
 {
     if ($this->status == self::STATUS_REGISTERED) {
         $this->removeActivationToken();
         $this->status = self::STATUS_ACTIVE;
         $transaction = self::getDb()->beginTransaction();
         try {
             if ($this->save()) {
                 if (Yii::$app->authManager->assign(Yii::$app->authManager->getRole(Rbac::ROLE_USER), $this->id)) {
                     $transaction->commit();
                     return true;
                 }
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Log::error($e->getMessage(), null, __METHOD__);
         }
     }
     return false;
 }
示例#27
0
 /**
  * Tries to send email from queue and updates its status.
  * @param string $email
  * @param string $fromName
  * @param string $fromEmail
  * @param integer $maxAttempts
  * @return boolean
  */
 public function process($email, $fromName, $fromEmail, $maxAttempts)
 {
     try {
         if ($this->send($email, $fromName, $fromEmail)) {
             $this->db->createCommand()->update($this->queueTable, ['status' => Email::STATUS_SENT], ['id' => $email['id']])->execute();
             return true;
         } else {
             $attempt = $email['attempt'] + 1;
             if ($attempt <= $maxAttempts) {
                 $this->db->createCommand()->update($this->queueTable, ['attempt' => $attempt], ['id' => $email['id']])->execute();
             } else {
                 $this->db->createCommand()->update($this->queueTable, ['status' => Email::STATUS_GAVEUP], ['id' => $email['id']])->execute();
             }
             return false;
         }
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
 }
示例#28
0
 /**
  * Deleting the subscription of given ID.
  * @param integer $id
  * @return \yii\web\Response
  */
 public function actionDelete($id = null)
 {
     $model = Subscription::find()->where(['id' => (int) $id, 'user_id' => User::loggedId()])->limit(1)->one();
     if (empty($model)) {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find Subscription with this ID.'));
     } else {
         if ($model->delete()) {
             Cache::getInstance()->deleteElement('user.subscriptions', User::loggedId());
             $this->success(Yii::t('podium/flash', 'Thread has been unsubscribed.'));
         } else {
             Log::error('Error while deleting subscription', $model->id, __METHOD__);
             $this->error(Yii::t('podium/flash', 'Sorry! There was some error while deleting the subscription.'));
         }
     }
     return $this->redirect(['profile/subscriptions']);
 }
示例#29
0
 /**
  * Removes message.
  * @return boolean
  */
 public function remove()
 {
     $clearCache = false;
     if ($this->sender_status == self::STATUS_NEW) {
         $clearCache = true;
     }
     $transaction = static::getDb()->beginTransaction();
     try {
         if (empty($this->messageReceivers)) {
             if ($this->delete()) {
                 if ($clearCache) {
                     Cache::getInstance()->deleteElement('user.newmessages', $this->sender_id);
                 }
                 $transaction->commit();
                 return true;
             } else {
                 throw new Exception('Message removing error!');
             }
         } else {
             $allDeleted = true;
             foreach ($this->messageReceivers as $mr) {
                 if ($mr->receiver_status != MessageReceiver::STATUS_DELETED) {
                     $allDeleted = false;
                     break;
                 }
             }
             if ($allDeleted) {
                 foreach ($this->messageReceivers as $mr) {
                     if (!$mr->delete()) {
                         throw new Exception('Received message removing error!');
                     }
                 }
                 if ($this->delete()) {
                     if ($clearCache) {
                         Cache::getInstance()->deleteElement('user.newmessages', $this->sender_id);
                     }
                     $transaction->commit();
                     return true;
                 } else {
                     throw new Exception('Message removing error!');
                 }
             } else {
                 $this->sender_status = self::STATUS_DELETED;
                 if ($this->save()) {
                     if ($clearCache) {
                         Cache::getInstance()->deleteElement('user.newmessages', $this->sender_id);
                     }
                     $transaction->commit();
                     return true;
                 } else {
                     throw new Exception('Message status changing error!');
                 }
             }
         }
     } catch (Exception $e) {
         $transaction->rollBack();
         Log::error($e->getMessage(), $this->id, __METHOD__);
     }
     return false;
 }