Ejemplo n.º 1
1
 /**
  * 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;
         }
     }
 }
Ejemplo n.º 2
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;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Validates current password.
  * @param string $attribute
  */
 public function validateCurrentPassword($attribute)
 {
     if (!empty($this->user_id)) {
         $user = User::findMe();
         if (!$user->validatePassword($this->current_password)) {
             $this->addError($attribute, Yii::t('podium/view', 'Current password is incorrect.'));
         }
     }
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
 /**
  * Adds registered user activity.
  * @param string $ip
  * @param string $url
  * @return boolean
  */
 protected static function _addUser($ip, $url)
 {
     $user = User::findMe();
     if ($user) {
         $activity = self::find()->where(['user_id' => $user->id])->limit(1)->one();
         if (!$activity) {
             $activity = new Activity();
             $activity->user_id = $user->id;
         }
         $activity->username = $user->podiumName;
         $activity->user_role = $user->role;
         $activity->user_slug = $user->podiumSlug;
         $activity->url = $url;
         $activity->ip = $ip;
         $activity->anonymous = $user->anonymous;
         return $activity->save();
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * Showing the profile card.
  * @return string|\yii\web\Response
  */
 public function actionIndex()
 {
     $model = User::findMe();
     if (empty($model)) {
         if ($this->module->userComponent == PodiumModule::USER_OWN) {
             return $this->redirect(['account/login']);
         } else {
             return $this->module->goPodium();
         }
     }
     return $this->render('profile', ['model' => $model]);
 }
Ejemplo n.º 7
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) {
Ejemplo n.º 8
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">
Ejemplo n.º 9
0
$items = [['label' => Yii::t('podium/layout', 'Home'), 'url' => ['default/index']]];
$podiumModule = PodiumModule::getInstance();
if (Yii::$app->user->isGuest) {
    if (Config::getInstance()->get('members_visible')) {
        $items[] = ['label' => Yii::t('podium/layout', 'Members'), 'url' => ['members/index'], 'active' => $this->context->id == 'members'];
    }
    if ($podiumModule->userComponent == PodiumModule::USER_OWN) {
        if (!empty($podiumModule->loginUrl)) {
            $items[] = ['label' => Yii::t('podium/layout', 'Sign in'), 'url' => $podiumModule->loginUrl];
        }
        if (!empty($podiumModule->registerUrl)) {
            $items[] = ['label' => Yii::t('podium/layout', 'Register'), 'url' => $podiumModule->registerUrl];
        }
    }
} else {
    $podiumUser = User::findMe();
    $messageCount = $podiumUser->newMessagesCount;
    $subscriptionCount = $podiumUser->subscriptionsCount;
    if (User::can(Rbac::ROLE_ADMIN)) {
        $items[] = ['label' => Yii::t('podium/layout', 'Administration'), 'url' => ['admin/index'], 'active' => $this->context->id == 'admin'];
    }
    $items[] = ['label' => Yii::t('podium/layout', 'Members'), 'url' => ['members/index'], 'active' => $this->context->id == 'members'];
    $items[] = ['label' => Yii::t('podium/layout', 'Profile') . ($subscriptionCount ? ' ' . Html::tag('span', $subscriptionCount, ['class' => 'badge']) : ''), 'url' => ['profile/index'], 'items' => [['label' => Yii::t('podium/view', 'My Profile'), 'url' => ['profile/index']], ['label' => Yii::t('podium/view', 'Account Details'), 'url' => ['profile/details']], ['label' => Yii::t('podium/view', 'Forum Details'), 'url' => ['profile/forum']], ['label' => Yii::t('podium/view', 'Subscriptions'), 'url' => ['profile/subscriptions']]]];
    $items[] = ['label' => Yii::t('podium/layout', 'Messages') . ($messageCount ? ' ' . Html::tag('span', $messageCount, ['class' => 'badge']) : ''), 'url' => ['messages/inbox'], 'items' => [['label' => Yii::t('podium/view', 'Inbox'), 'url' => ['messages/inbox']], ['label' => Yii::t('podium/view', 'Sent'), 'url' => ['messages/sent']], ['label' => Yii::t('podium/view', 'Deleted'), 'url' => ['messages/deleted']], ['label' => Yii::t('podium/view', 'New Message'), 'url' => ['messages/new']]]];
    if ($podiumModule->userComponent == PodiumModule::USER_OWN) {
        $items[] = ['label' => Yii::t('podium/layout', 'Sign out'), 'url' => ['profile/logout'], 'linkOptions' => ['data-method' => 'post']];
    }
}
NavBar::begin(['brandLabel' => Config::getInstance()->get('name'), 'brandUrl' => ['default/index'], 'options' => ['class' => 'navbar-inverse navbar-default'], 'innerContainerOptions' => ['class' => 'container-fluid']]);
echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'encodeLabels' => false, 'activateParents' => true, 'items' => $items]);
NavBar::end();
Ejemplo n.º 10
0
 /**
  * Replying to the message of given ID.
  * @param integer $id
  * @return string|\yii\web\Response
  */
 public function actionReply($id = null)
 {
     $model = new Message();
     $podiumUser = User::findMe();
     $reply = Message::findOne(['id' => $id, 'receiver_id' => $podiumUser->id]);
     if ($reply) {
         $model->topic = Message::re() . ' ' . $reply->topic;
         if ($model->load(Yii::$app->request->post())) {
             if ($model->validate()) {
                 if (!$podiumUser->isIgnoredBy($model->receiver_id)) {
                     $model->replyto = $reply->id;
                     if ($model->send()) {
                         $this->success(Yii::t('podium/flash', 'Message has been sent.'));
                         return $this->redirect(['messages/inbox']);
                     }
                 } else {
                     $this->error(Yii::t('podium/flash', 'Sorry! This member ignores you so you can not send the message.'));
                 }
             }
         }
         $model->receiver_id = $reply->sender_id;
         return $this->render('reply', ['model' => $model, 'reply' => $reply]);
     } else {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find the message with the given ID.'));
         return $this->redirect(['messages/inbox']);
     }
 }
Ejemplo n.º 11
0
 /**
  * Replying to the message of given ID.
  * @param integer $id
  * @return string|\yii\web\Response
  */
 public function actionReply($id = null)
 {
     $podiumUser = User::findMe();
     if (Message::tooMany($podiumUser->id)) {
         $this->warning(Yii::t('podium/flash', 'You have reached maximum {max_messages, plural, =1{ message} other{ messages}} per {max_minutes, plural, =1{ minute} other{ minutes}} limit. Wait few minutes before sending a new message.', ['max_messages' => Message::SPAM_MESSAGES, 'max_minutes' => Message::SPAM_WAIT]));
         return $this->redirect(['messages/inbox']);
     }
     $reply = Message::find()->where([Message::tableName() . '.id' => $id])->joinWith(['messageReceivers' => function ($q) use($podiumUser) {
         $q->where(['receiver_id' => $podiumUser->id]);
     }])->limit(1)->one();
     if (empty($reply)) {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find the message with the given ID.'));
         return $this->redirect(['messages/inbox']);
     }
     $model = new Message();
     $model->topic = Message::re() . ' ' . $reply->topic;
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if (!$podiumUser->isIgnoredBy($model->receiversId[0])) {
                 $model->replyto = $reply->id;
                 if ($model->send()) {
                     $this->success(Yii::t('podium/flash', 'Message has been sent.'));
                     return $this->redirect(['messages/inbox']);
                 } else {
                     $this->error(Yii::t('podium/flash', 'Sorry! There was some error while sending your message.'));
                 }
             } else {
                 $this->error(Yii::t('podium/flash', 'Sorry! This member ignores you so you can not send the message.'));
             }
         }
     }
     $model->receiversId = [$reply->sender_id];
     return $this->render('reply', ['model' => $model, 'reply' => $reply]);
 }
Ejemplo n.º 12
0
 /**
  * Creates inherited user account.
  * @throws Exception
  */
 public function init()
 {
     parent::init();
     if (!Yii::$app->user->isGuest) {
         if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
             $user = User::findMe();
             if (empty($user)) {
                 if (User::createInheritedAccount()) {
                     $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'))]));
                 } 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.'));
                 }
             }
         } else {
             $user = Yii::$app->user->identity;
         }
         if ($user->status == User::STATUS_BANNED) {
             return $this->redirect(['default/ban']);
         }
         if ($user && !empty($user->timezone)) {
             Yii::$app->formatter->timeZone = $user->timezone;
         }
     }
 }