Example #1
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;
         }
     }
 }
Example #2
0
 /**
  * Returns User.
  * @param integer $status
  * @return User
  */
 public function getUser($status = null)
 {
     if ($this->_user === false) {
         $this->_user = User::findByKeyfield($this->username, $status);
     }
     return $this->_user;
 }
 /**
  * Listing the active users for ajax.
  * @return string|\yii\web\Response
  */
 public function actionFieldlist($q = null)
 {
     if (Yii::$app->request->isAjax) {
         if (!is_null($q) && is_string($q)) {
             $cache = Cache::getInstance()->get('members.fieldlist');
             if ($cache === false || empty($cache[$q])) {
                 if ($cache === false) {
                     $cache = [];
                 }
                 $users = User::find()->where(['and', ['status' => User::STATUS_ACTIVE], ['or', ['like', 'username', $q], ['username' => null]]])->orderBy('username, id');
                 $results = ['results' => []];
                 foreach ($users->each() as $user) {
                     $results['results'][] = ['id' => $user->id, 'text' => $user->getPodiumTag(true)];
                 }
                 if (!empty($results['results'])) {
                     $cache[$q] = Json::encode($results);
                     Cache::getInstance()->set('members.fieldlist', $cache);
                 } else {
                     return Json::encode(['results' => []]);
                 }
             }
             return $cache[$q];
         } else {
             return Json::encode(['results' => []]);
         }
     } else {
         return $this->redirect(['default/index']);
     }
 }
Example #4
0
 /**
  * Return User.
  * @return User
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByKeyfield($this->username);
     }
     return $this->_user;
 }
Example #5
0
 /**
  * Returns ID of user responsible for logged action.
  * @return integer|null
  */
 public static function blame()
 {
     if (Yii::$app instanceof Application && !Yii::$app->user->isGuest) {
         return User::loggedId();
     }
     return null;
 }
 /**
  * Searches for subscription
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = self::find()->where(['user_id' => User::loggedId()]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 10, 'forcePageParam' => false]]);
     $dataProvider->sort->defaultOrder = ['post_seen' => SORT_ASC, 'id' => SORT_DESC];
     $dataProvider->pagination->pageSize = Yii::$app->session->get('per-page', 20);
     return $dataProvider;
 }
Example #7
0
 /**
  * Adds Administrator account.
  * @return string result message.
  */
 protected function _addAdmin()
 {
     try {
         $podium = PodiumModule::getInstance();
         if ($podium->userComponent == PodiumModule::USER_INHERIT) {
             if (!empty($podium->adminId)) {
                 $this->authManager->assign($this->authManager->getRole('podiumAdmin'), $podium->adminId);
                 return $this->outputSuccess(Yii::t('podium/flash', Messages::ADMINISTRATOR_PRIVILEGES_SET, ['id' => $podium->adminId]));
             } else {
                 return $this->outputWarning(Yii::t('podium/flash', Messages::NO_ADMINISTRATOR_PRIVILEGES_SET));
             }
         } else {
             $admin = new User();
             $admin->setScenario('installation');
             $admin->username = self::DEFAULT_USERNAME;
             $admin->email = self::DEFAULT_USER_EMAIL;
             $admin->status = User::STATUS_ACTIVE;
             $admin->role = User::ROLE_ADMIN;
             $admin->generateAuthKey();
             $admin->setPassword(self::DEFAULT_USERNAME);
             if ($admin->save()) {
                 $this->authManager->assign($this->authManager->getRole('podiumAdmin'), $admin->getId());
                 return $this->outputSuccess(Yii::t('podium/flash', Messages::ADMINISTRATOR_ACCOUNT_CREATED) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Login') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Password') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME));
             } else {
                 $this->setError(true);
                 return $this->outputDanger(Yii::t('podium/flash', Messages::ACCOUNT_CREATING_ERROR) . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
             }
         }
     } catch (Exception $e) {
         Yii::error([$e->getName(), $e->getMessage()], __METHOD__);
         $this->setError(true);
         return $this->outputDanger(Yii::t('podium/flash', Messages::ACCOUNT_CREATING_ERROR) . ': ' . Html::tag('pre', $e->getMessage()));
     }
 }
Example #8
0
 /**
  * Searches for threads with unread posts.
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search()
 {
     $loggedId = User::loggedId();
     $query = Thread::find()->joinWith('threadView')->where(['or', ['and', ['user_id' => $loggedId], new Expression('`new_last_seen` < `new_post_at`')], ['and', ['user_id' => $loggedId], new Expression('`edited_last_seen` < `edited_post_at`')], ['user_id' => null]]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 10, 'forcePageParam' => false]]);
     $dataProvider->sort->defaultOrder = ['edited_post_at' => SORT_ASC, 'id' => SORT_ASC];
     $dataProvider->pagination->pageSize = Yii::$app->session->get('per-page', 20);
     return $dataProvider;
 }
Example #9
0
 public function validateCurrentPassword($attribute)
 {
     if (!empty($this->user_id)) {
         $user = User::findOne($this->user_id);
         if (!$user->validatePassword($this->current_password)) {
             $this->addError($attribute, Yii::t('podium/view', 'Current password is incorrect.'));
         }
     }
 }
Example #10
0
 /**
  * Searches for subscription
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = self::find()->where(['user_id' => User::loggedId()]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 10, 'forcePageParam' => false]]);
     $dataProvider->sort->defaultOrder = ['post_seen' => SORT_ASC, 'id' => SORT_DESC];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     return $dataProvider;
 }
Example #11
0
 /**
  * Renders the list of users reading current section.
  * @return string
  */
 public function run()
 {
     $url = Yii::$app->request->getUrl();
     $out = '';
     switch ($this->what) {
         case 'forum':
             $out .= Yii::t('podium/view', 'Browsing this forum') . ': ';
             break;
         case 'topic':
             $out .= Yii::t('podium/view', 'Reading this thread') . ': ';
             break;
         case 'unread':
             $out .= Yii::t('podium/view', 'Browsing unread threads') . ': ';
             break;
         case 'members':
             $out .= Yii::t('podium/view', 'Browsing the members') . ': ';
             break;
     }
     $conditions = ['and', [Activity::tableName() . '.anonymous' => 0], ['is not', 'user_id', null], new Expression('`url` LIKE :url'), ['>=', Activity::tableName() . '.updated_at', time() - 5 * 60]];
     $guest = true;
     $anon = false;
     if (!Yii::$app->user->isGuest) {
         $guest = false;
         $me = User::findMe();
         $conditions[] = ['not in', 'user_id', $me->id];
         if ($me->anonymous == 0) {
             $out .= $me->podiumTag . ' ';
         } else {
             $anon = true;
         }
     }
     $users = Activity::find()->joinWith(['user'])->where($conditions)->params([':url' => $url . '%']);
     foreach ($users->each() as $user) {
         $out .= $user->user->podiumTag . ' ';
     }
     $conditions = ['and', ['anonymous' => 1], new Expression('`url` LIKE :url'), ['>=', 'updated_at', time() - 5 * 60]];
     $anonymous = Activity::find()->where($conditions)->params([':url' => $url . '%'])->count('id');
     if ($anon) {
         $anonymous += 1;
     }
     $conditions = ['and', ['user_id' => null], new Expression('`url` LIKE :url'), ['>=', 'updated_at', time() - 5 * 60]];
     $guests = Activity::find()->where($conditions)->params([':url' => $url . '%'])->count('id');
     if ($guest) {
         $guests += 1;
     }
     if ($anonymous) {
         $out .= Html::button(Yii::t('podium/view', '{n, plural, =1{# anonymous user} other{# anonymous users}}', ['n' => $anonymous]), ['class' => 'btn btn-xs btn-default disabled']) . ' ';
     }
     if ($guests) {
         $out .= Html::button(Yii::t('podium/view', '{n, plural, =1{# guest} other{# guests}}', ['n' => $guests]), ['class' => 'btn btn-xs btn-default disabled']);
     }
     return $out;
 }
Example #12
0
 /**
  * @inheritdoc
  */
 public function search($params, $active = false, $mods = false)
 {
     $query = User::find();
     if ($active) {
         $query->andWhere(['!=', 'status', User::STATUS_REGISTERED]);
     }
     if ($mods) {
         $query->andWhere(['role' => [User::ROLE_ADMIN, User::ROLE_MODERATOR]]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->defaultOrder = ['id' => SORT_ASC];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id])->andFilterWhere(['status' => $this->status])->andFilterWhere(['role' => $this->role])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'username', $this->username]);
     return $dataProvider;
 }
Example #13
0
 /**
  * Adds Administrator account.
  * @return string result message.
  */
 protected function _addAdmin()
 {
     try {
         $podium = PodiumModule::getInstance();
         if ($podium->userComponent == PodiumModule::USER_INHERIT) {
             if (!empty($podium->adminId)) {
                 $admin = new User();
                 $admin->setScenario('installation');
                 $admin->inherited_id = $podium->adminId;
                 $admin->username = self::DEFAULT_USERNAME;
                 $admin->status = User::STATUS_ACTIVE;
                 $admin->role = User::ROLE_ADMIN;
                 $admin->timezone = User::DEFAULT_TIMEZONE;
                 if ($admin->save()) {
                     $this->authManager->assign($this->authManager->getRole(Rbac::ROLE_ADMIN), $podium->adminId);
                     return $this->outputSuccess(Yii::t('podium/flash', 'Administrator privileges have been set for the user of ID {id}.', ['id' => $podium->adminId]));
                 } else {
                     $this->setError(true);
                     return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
                 }
             } else {
                 return $this->outputWarning(Yii::t('podium/flash', 'No administrator privileges have been set.'));
             }
         } else {
             $admin = new User();
             $admin->setScenario('installation');
             $admin->username = self::DEFAULT_USERNAME;
             $admin->status = User::STATUS_ACTIVE;
             $admin->role = User::ROLE_ADMIN;
             $admin->timezone = User::DEFAULT_TIMEZONE;
             $admin->generateAuthKey();
             $admin->setPassword(self::DEFAULT_USERNAME);
             if ($admin->save()) {
                 $this->authManager->assign($this->authManager->getRole(Rbac::ROLE_ADMIN), $admin->getId());
                 return $this->outputSuccess(Yii::t('podium/flash', 'Administrator account has been created.') . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Login') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Password') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME));
             } else {
                 $this->setError(true);
                 return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
             }
         }
     } catch (Exception $e) {
         Yii::error([$e->getName(), $e->getMessage()], __METHOD__);
         $this->setError(true);
         return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', $e->getMessage()));
     }
 }
Example #14
0
 public function searchDeleted($params)
 {
     $dataProvider = $this->search();
     $dataProvider->query->where(['or', ['and', ['sender_id' => Yii::$app->user->id], ['sender_status' => Message::getDeletedStatuses()]], ['and', ['receiver_id' => Yii::$app->user->id], ['receiver_status' => Message::getDeletedStatuses()]]]);
     if (!($this->load($params) && $this->validate())) {
         $dataProvider->query->joinWith(['receiverUser' => function ($q) {
             $q->from(User::tableName() . ' pdu_receiver');
         }, 'senderUser' => function ($q) {
             $q->from(User::tableName() . ' pdu_sender');
         }]);
         return $dataProvider;
     }
     $dataProvider->query->andFilterWhere(['like', 'topic', $this->topic]);
     $dataProvider->query->joinWith(['receiverUser' => function ($q) {
         $q->from(User::tableName() . ' pdu_receiver')->where(['like', 'pdu_receiver.username', $this->receiverName]);
     }, 'senderUser' => function ($q) {
         $q->from(User::tableName() . ' pdu_sender')->where(['like', 'pdu_sender.username', $this->senderName]);
     }]);
     return $dataProvider;
 }
 /**
  * Searches for sent messages.
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     // not very proud of this query - slow for sure
     // let me know if it can be done better.
     $subquery = (new Query())->select(['m2.replyto'])->from(['m1' => Message::tableName()])->leftJoin(['m2' => Message::tableName()], '`m1`.`replyto` = `m2`.`id`')->where(['is not', 'm2.replyto', null]);
     $query = self::find()->where(['and', ['sender_id' => User::loggedId(), 'sender_status' => Message::getSentStatuses()], ['not in', Message::tableName() . '.id', $subquery]]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['attributes' => ['id', 'topic', 'created_at']]]);
     $dataProvider->sort->defaultOrder = ['id' => SORT_DESC];
     $dataProvider->pagination->pageSize = Yii::$app->session->get('per-page', 20);
     if (!($this->load($params) && $this->validate())) {
         $dataProvider->query->joinWith(['messageReceivers' => function ($q) {
             $q->joinWith(['receiver']);
         }]);
         return $dataProvider;
     }
     $dataProvider->query->andFilterWhere(['like', 'topic', $this->topic]);
     if (preg_match('/^(forum|orum|rum|um|m)?#([0-9]+)$/', strtolower($this->receiverName), $matches)) {
         $dataProvider->query->joinWith(['messageReceivers' => function ($q) use($matches) {
             $q->joinWith(['receiver' => function ($q) use($matches) {
                 $q->andFilterWhere(['username' => ['', null], User::tableName() . '.id' => $matches[2]]);
             }]);
         }]);
     } elseif (preg_match('/^([0-9]+)$/', $this->receiverName, $matches)) {
         $dataProvider->query->joinWith(['messageReceivers' => function ($q) use($matches) {
             $q->joinWith(['receiver' => function ($q) use($matches) {
                 $q->andFilterWhere(['or', ['like', 'username', $this->receiverName], ['username' => ['', null], 'id' => $matches[1]]]);
             }]);
         }]);
     } else {
         $dataProvider->query->joinWith(['messageReceivers' => function ($q) {
             $q->joinWith(['receiver' => function ($q) {
                 $q->andFilterWhere(['like', User::tableName() . '.username', $this->receiverName]);
             }]);
         }]);
     }
     return $dataProvider;
 }
Example #16
0
echo Html::encode($reply->topic);
?>
                        </div>
                        <div class="popover-content">
                            <?php 
echo $reply->content;
?>
                        </div>
                    </div>
                </div>
            </div>

<?php 
$stack = 0;
while ($reply->reply && $stack < 4) {
    $loggedId = User::loggedId();
    if ($reply->reply->receiver_id == $loggedId && $reply->reply->receiver_status == Message::STATUS_REMOVED || $reply->reply->sender_id == $loggedId && $reply->reply->sender_status == Message::STATUS_REMOVED) {
        $reply = $reply->reply;
    } else {
        ?>
            <div class="row">
                <div class="col-sm-2 text-center">
                    <?php 
        echo Avatar::widget(['author' => $reply->reply->senderUser]);
        ?>
                </div>
                <div class="col-sm-10">
                    <div class="popover right podium">
                        <div class="arrow"></div>
                        <div class="popover-title">
                            <small class="pull-right"><span data-toggle="tooltip" data-placement="top" title="<?php 
Example #17
0
Pjax::begin();
echo PageSizer::widget();
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'filterSelector' => 'select#per-page', 'tableOptions' => ['class' => 'table table-striped table-hover'], 'columns' => [['attribute' => 'username', 'label' => Yii::t('podium/view', 'Username') . Helper::sortOrder('username'), 'encodeLabel' => false, 'format' => 'raw', 'value' => function ($model) {
    return Html::a($model->podiumName, ['members/view', 'id' => $model->id, 'slug' => $model->podiumSlug], ['data-pjax' => '0']);
}], ['attribute' => 'role', 'label' => Yii::t('podium/view', 'Role') . Helper::sortOrder('role'), 'encodeLabel' => false, 'format' => 'raw', 'filter' => User::getRoles(), 'value' => function ($model) {
    return Helper::roleLabel($model->role);
}], ['attribute' => 'created_at', 'label' => Yii::t('podium/view', 'Joined') . Helper::sortOrder('created_at'), 'encodeLabel' => false, 'value' => function ($model) {
    return Yii::$app->formatter->asDatetime($model->created_at);
}], ['attribute' => 'threads_count', 'label' => Yii::t('podium/view', 'Threads'), 'encodeLabel' => false, 'value' => function ($model) {
    return $model->threadsCount;
}], ['attribute' => 'posts_count', 'label' => Yii::t('podium/view', 'Posts'), 'encodeLabel' => false, 'value' => function ($model) {
    return $model->postsCount;
}], ['class' => ActionColumn::className(), 'header' => Yii::t('podium/view', 'Actions'), 'contentOptions' => ['class' => 'text-right'], 'headerOptions' => ['class' => 'text-right'], 'template' => '{view}' . (!Yii::$app->user->isGuest ? ' {pm}' : ''), 'buttons' => ['view' => function ($url, $model) {
    return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', ['members/view', 'id' => $model->id, 'slug' => $model->podiumSlug], ['class' => 'btn btn-default btn-xs', 'data-pjax' => '0', 'data-toggle' => 'tooltip', 'data-placement' => 'top', 'title' => Yii::t('podium/view', 'View Member')]);
}, 'pm' => function ($url, $model) {
    if ($model->id !== User::loggedId()) {
        return Html::a('<span class="glyphicon glyphicon-envelope"></span>', ['messages/new', 'user' => $model->id], ['class' => 'btn btn-default btn-xs', 'data-pjax' => '0', 'data-toggle' => 'tooltip', 'data-placement' => 'top', 'title' => Yii::t('podium/view', 'Send Message')]);
    } else {
        return Html::a('<span class="glyphicon glyphicon-envelope"></span>', '#', ['class' => 'btn btn-xs disabled text-muted']);
    }
}]]]]);
Pjax::end();
?>
<div class="panel panel-default">
    <div class="panel-body small">
        <ul class="list-inline pull-right">
            <li><a href="<?php 
echo Url::to(['default/index']);
?>
" data-toggle="tooltip" data-placement="top" title="<?php 
echo Yii::t('podium/view', 'Go to the main page');
Example #18
0
        echo Yii::t('podium/view', 'Thumb down');
        ?>
"><span class="glyphicon glyphicon-thumbs-down"></span></a>
<?php 
    }
    ?>
                    <a href="<?php 
    echo Url::to(['default/report', 'cid' => $model->thread->category_id, 'fid' => $model->forum_id, 'tid' => $model->thread_id, 'pid' => $model->id, 'slug' => $model->thread->slug]);
    ?>
" class="btn btn-warning btn-xs" data-pjax="0" data-toggle="tooltip" data-placement="top" title="<?php 
    echo Yii::t('podium/view', 'Report post');
    ?>
"><span class="glyphicon glyphicon-flag"></span></a>
<?php 
}
if ($model->author_id == $loggedId || User::can(Rbac::PERM_DELETE_POST, ['item' => $model->thread])) {
    ?>
                    <a href="<?php 
    echo Url::to(['default/deletepost', 'cid' => $model->thread->category_id, 'fid' => $model->forum_id, 'tid' => $model->thread_id, 'pid' => $model->id]);
    ?>
" class="btn btn-danger btn-xs" data-pjax="0" data-toggle="tooltip" data-placement="top" title="<?php 
    echo Yii::t('podium/view', 'Delete post');
    ?>
"><span class="glyphicon glyphicon-trash"></span></a>
<?php 
}
?>
                </div>
            </div>
        </div>
    </div>
Example #19
0
        echo Avatar::widget(['author' => User::findMe(), 'showName' => false]);
        ?>
    </div>
    <div class="col-sm-10">
        <div class="popover right podium">
            <div class="arrow"></div>
            <div class="popover-title">
                <small class="pull-right"><?php 
        echo Html::tag('span', Yii::t('podium/view', 'In a while'), ['data-toggle' => 'tooltip', 'data-placement' => 'top', 'title' => Yii::t('podium/view', 'As soon as you click Post Reply')]);
        ?>
</small>
                <strong><?php 
        echo Yii::t('podium/view', 'Post Quick Reply');
        ?>
</strong> <?php 
        echo User::findMe()->podiumTag;
        ?>
            </div>
            <div class="popover-content podium-content">
                <?php 
        $form = ActiveForm::begin(['id' => 'new-quick-post-form', 'action' => ['post', 'cid' => $category->id, 'fid' => $forum->id, 'tid' => $thread->id]]);
        ?>
                    <div class="row">
                        <div class="col-sm-12">
                            <?php 
        echo $form->field($model, 'content')->label(false)->widget(Summernote::className(), ['clientOptions' => ['height' => '100', 'lang' => Yii::$app->language != 'en-US' ? Yii::$app->language : null, 'codemirror' => null, 'toolbar' => Helper::summerNoteToolbars()]]);
        ?>
                        </div>
                    </div>
<?php 
        if (!$thread->subscription) {
Example #20
0
 /**
  * Adding or removing user as a friend.
  * @param integer $id user ID
  * @return \yii\web\Response
  * @since 0.2
  */
 public function actionFriend($id = null)
 {
     if (Yii::$app->user->isGuest) {
         return $this->redirect(['default/index']);
     }
     $model = User::find()->where(['and', ['id' => $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.'));
         return $this->redirect(['members/index']);
     }
     if ($model->id == User::loggedId()) {
         $this->error(Yii::t('podium/flash', 'Sorry! You can not befriend your own account.'));
         return $this->redirect(['members/view', 'id' => $model->id, 'slug' => $model->podiumSlug]);
     }
     if ($model->updateFriend()) {
         if ($model->isBefriendedBy(User::loggedId())) {
             $this->success(Yii::t('podium/flash', 'User is your friend now.'));
         } else {
             $this->success(Yii::t('podium/flash', 'User is not your friend anymore.'));
         }
     } else {
         $this->error(Yii::t('podium/flash', 'Sorry! There was some error while performing this action.'));
     }
     return $this->redirect(['members/view', 'id' => $model->id, 'slug' => $model->podiumSlug]);
 }
Example #21
0
 /**
  * Gets User status label.
  * @param integer|null $status status ID
  * @return string label html
  */
 public static function statusLabel($status = null)
 {
     switch ($status) {
         case User::STATUS_ACTIVE:
             $label = 'info';
             $name = ArrayHelper::getValue(User::getStatuses(), $status);
             break;
         case User::STATUS_BANNED:
             $label = 'warning';
             $name = ArrayHelper::getValue(User::getStatuses(), $status);
             break;
         default:
             $label = 'default';
             $name = ArrayHelper::getValue(User::getStatuses(), User::STATUS_REGISTERED);
     }
     return Html::tag('span', Yii::t('podium/view', $name), ['class' => 'label label-' . $label]);
 }
 /**
  * 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']);
     }
 }
Example #23
0
 * @since 0.1
 */
use bizley\podium\components\Helper;
use bizley\podium\models\User;
use bizley\podium\widgets\Avatar;
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Alert;
use yii\helpers\Html;
use Zelenin\yii\widgets\Summernote\Summernote;
$this->title = Yii::t('podium/view', 'New Reply');
$this->params['breadcrumbs'][] = ['label' => Yii::t('podium/view', 'Main Forum'), 'url' => ['default/index']];
$this->params['breadcrumbs'][] = ['label' => Html::encode($category->name), 'url' => ['default/category', 'id' => $category->id, 'slug' => $category->slug]];
$this->params['breadcrumbs'][] = ['label' => Html::encode($forum->name), 'url' => ['default/forum', 'cid' => $forum->category_id, 'id' => $forum->id, 'slug' => $forum->slug]];
$this->params['breadcrumbs'][] = ['label' => Html::encode($thread->name), 'url' => ['default/thread', 'cid' => $thread->category_id, 'fid' => $thread->forum_id, 'id' => $thread->id, 'slug' => $thread->slug]];
$this->params['breadcrumbs'][] = $this->title;
$author = User::findMe();
if (!empty($preview)) {
    ?>
<div class="row">
    <div class="col-sm-10 col-sm-offset-2">
        <?php 
    echo Alert::widget(['body' => '<strong><small>' . Yii::t('podium/view', 'Post Preview') . '</small></strong>:<hr>' . $preview, 'options' => ['class' => 'alert-info']]);
    ?>
    </div>
</div>
<?php 
}
?>

<div class="row">
    <div class="col-sm-2 text-center">
Example #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;
 }
Example #25
0
 /**
  * Listing the details of user of given ID.
  * @param integer $id
  * @return string|\yii\web\Response
  */
 public function actionView($id = null)
 {
     $model = User::findOne((int) $id);
     if (empty($model)) {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find Member with this ID.'));
         return $this->redirect(['admin/members']);
     }
     return $this->render('view', ['model' => $model]);
 }
Example #26
0
 /**
  * Marks post as seen by current user.
  */
 public function markSeen()
 {
     if (!Yii::$app->user->isGuest) {
         $threadView = ThreadView::findOne(['user_id' => User::loggedId(), 'thread_id' => $this->thread_id]);
         if (!$threadView) {
             $threadView = new ThreadView();
             $threadView->user_id = User::loggedId();
             $threadView->thread_id = $this->thread_id;
             $threadView->new_last_seen = $this->created_at;
             $threadView->edited_last_seen = !empty($this->edited_at) ? $this->edited_at : $this->created_at;
             $threadView->save();
             $this->thread->updateCounters(['views' => 1]);
         } else {
             if ($this->edited) {
                 if ($threadView->edited_last_seen < $this->edited_at) {
                     $threadView->edited_last_seen = $this->edited_at;
                     $threadView->save();
                     $this->thread->updateCounters(['views' => 1]);
                 }
             } else {
                 $save = false;
                 if ($threadView->new_last_seen < $this->created_at) {
                     $threadView->new_last_seen = $this->created_at;
                     $save = true;
                 }
                 if ($threadView->edited_last_seen < max($this->created_at, $this->edited_at)) {
                     $threadView->edited_last_seen = max($this->created_at, $this->edited_at);
                     $save = true;
                 }
                 if ($save) {
                     $threadView->save();
                     $this->thread->updateCounters(['views' => 1]);
                 }
             }
         }
         if ($this->thread->subscription) {
             if ($this->thread->subscription->post_seen == Subscription::POST_NEW) {
                 $this->thread->subscription->post_seen = Subscription::POST_SEEN;
                 $this->thread->subscription->save();
             }
         }
     }
 }
Example #27
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;
 }
Example #28
0
 public function getMods()
 {
     $mods = Cache::getInstance()->getElement('forum.moderators', $this->id);
     if ($mods === false) {
         $mods = [];
         $modteam = User::find()->select(['id', 'role'])->where(['status' => User::STATUS_ACTIVE, 'role' => [User::ROLE_ADMIN, User::ROLE_MODERATOR]])->asArray()->all();
         foreach ($modteam as $user) {
             if ($user['role'] == User::ROLE_ADMIN) {
                 $mods[] = $user['id'];
             } else {
                 if ((new Query())->from(Mod::tableName())->where(['forum_id' => $this->id, 'user_id' => $user->id])->exists()) {
                     $mods[] = $user['id'];
                 }
             }
         }
         Cache::getInstance()->setElement('forum.moderators', $this->id, $mods);
     }
     return $mods;
 }
 /**
  * Subscribing the thread of given ID.
  * @param integer $id
  * @return \yii\web\Response
  */
 public function actionAdd($id = null)
 {
     if (Yii::$app->request->isAjax) {
         $data = ['error' => 1, 'msg' => Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Error while adding this subscription!'), ['class' => 'text-danger'])];
         if (!Yii::$app->user->isGuest) {
             if (is_numeric($id) && $id > 0) {
                 $thread = Thread::findOne((int) $id);
                 if ($thread) {
                     $subscription = Subscription::findOne(['thread_id' => $thread->id, 'user_id' => User::loggedId()]);
                     if ($subscription) {
                         $data = ['error' => 1, 'msg' => Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'You are already subscribed to this thread.'), ['class' => 'text-info'])];
                     } else {
                         $sub = new Subscription();
                         $sub->thread_id = $thread->id;
                         $sub->user_id = User::loggedId();
                         $sub->post_seen = Subscription::POST_SEEN;
                         if ($sub->save()) {
                             $data = ['error' => 0, 'msg' => Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-ok-circle']) . ' ' . Yii::t('podium/view', 'You have subscribed to this thread!'), ['class' => 'text-success'])];
                         }
                     }
                 }
             }
         } else {
             $data = ['error' => 1, 'msg' => Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Please sign in to subscribe to this thread'), ['class' => 'text-info'])];
         }
         return Json::encode($data);
     } else {
         return $this->redirect(['default/index']);
     }
 }
Example #30
0
/**
 * Podium Module
 * Yii 2 Forum Module
 * @author Paweł Bizley Brzozowski <*****@*****.**>
 * @since 0.1
 */
use bizley\podium\models\User;
use bizley\podium\rbac\Rbac;
use yii\helpers\Html;
use yii\helpers\Url;
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('podium/view', 'Main Forum'), 'url' => ['default/index']];
$this->params['breadcrumbs'][] = ['label' => Html::encode($category->name), 'url' => ['default/category', 'id' => $category->id, 'slug' => $category->slug]];
$this->params['breadcrumbs'][] = Html::encode($this->title);
if (User::can(Rbac::PERM_CREATE_THREAD)) {
    ?>
<div class="row">
    <div class="col-sm-12 text-right">
        <a href="<?php 
    echo Url::to(['default/new-thread', 'cid' => $category->id, 'fid' => $model->id]);
    ?>
" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> <?php 
    echo Yii::t('podium/view', 'Create new thread');
    ?>
</a>
        <br><br>
    </div>
</div>
<?php 
}