Пример #1
0
 /**
  * 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('Sorry! We can not find the message you are looking for.');
         return $this->redirect(['inbox']);
     } else {
         $model = Message::findOne(['and', ['id' => (int) $id], ['or', 'receiver_id' => Yii::$app->user->id, 'sender_id' => Yii::$app->user->id]]);
         if ($model) {
             if ($model->remove($perm)) {
                 if ($perm) {
                     $this->success('Message has been deleted permanently.');
                 } else {
                     $this->success('Message has been moved to Deleted Messages.');
                 }
             } else {
                 Log::error('Error while deleting message', !empty($model->id) ? $model->id : '', __METHOD__);
                 $this->error('Sorry! We can not delete this message. Contact administrator about this problem.');
             }
         } else {
             $this->error('Sorry! We can not find the message with the given ID.');
         }
         if ($perm) {
             return $this->redirect(['deleted']);
         } else {
             return $this->redirect(['inbox']);
         }
     }
 }
Пример #2
0
 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;
 }
Пример #3
0
 /**
  * Adds user activity.
  * @return boolean
  */
 public static function add()
 {
     try {
         $ip = Yii::$app->request->getUserIp();
         $url = Yii::$app->request->getUrl();
         if (empty($ip)) {
             $ip = '0.0.0.0';
         }
         if (Yii::$app->user->isGuest) {
             $result = self::_addGuest($ip, $url);
         } else {
             $result = self::_addUser($ip, $url);
         }
         if ($result) {
             return true;
         } else {
             Log::error('Cannot log user activity', null, __METHOD__);
             return false;
         }
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
 }
Пример #4
0
 /**
  * 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']);
     }
 }
Пример #5
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', Yii::t('podium/view', $name), ['class' => 'label label-' . $class]);
}], ['attribute' => 'category', 'label' => Yii::t('podium/view', 'Category') . Helper::sortOrder('category'), 'encodeLabel' => false, 'value' => function ($model) {
Пример #6
0
 /**
  * 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']);
 }
Пример #7
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('user'), $this->id)) {
                     $transaction->commit();
                     return true;
                 }
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Log::error($e->getMessage(), null, __METHOD__);
         }
     }
     return false;
 }
Пример #8
0
 /**
  * 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]);
 }
Пример #9
0
 /**
  * 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']);
     }
 }
Пример #10
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;
 }
Пример #11
0
 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;
     }
 }
Пример #12
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__);
     }
 }
Пример #13
0
 /**
  * Deleting the subscription of given ID.
  * @param integer $id
  * @return \yii\web\Response
  */
 public function actionDelete($id = null)
 {
     $model = Subscription::findOne(['id' => (int) $id, 'user_id' => Yii::$app->user->id]);
     if (empty($model)) {
         $this->error('Sorry! We can not find Subscription with this ID.');
     } else {
         if ($model->delete()) {
             Cache::getInstance()->deleteElement('user.subscriptions', Yii::$app->user->id);
             $this->success('Thread has been unsubscribed.');
         } else {
             Log::error('Error while deleting subscription', !empty($model->id) ? $model->id : '', __METHOD__);
             $this->error('Sorry! There was some error while deleting the subscription.');
         }
     }
     return $this->redirect(['profile/subscriptions']);
 }