コード例 #1
0
ファイル: Plugin.php プロジェクト: aaronleslie/aaronunix
 public function boot()
 {
     User::extend(function ($model) {
         $model->hasOne['forum_member'] = ['RainLab\\Forum\\Models\\Member'];
         $model->bindEvent('model.beforeDelete', function () use($model) {
             $model->forum_member && $model->forum_member->delete();
         });
     });
     UsersController::extendFormFields(function ($widget, $model, $context) {
         // Prevent extending of related form instead of the intended User form
         if (!$widget->model instanceof \RainLab\User\Models\User) {
             return;
         }
         if ($context != 'update') {
             return;
         }
         if (!Member::getFromUser($model)) {
             return;
         }
         $widget->addFields(['forum_member[username]' => ['label' => 'rainlab.forum::lang.settings.username', 'tab' => 'Forum', 'comment' => 'rainlab.forum::lang.settings.username_comment'], 'forum_member[is_moderator]' => ['label' => 'rainlab.forum::lang.settings.moderator', 'type' => 'checkbox', 'tab' => 'Forum', 'span' => 'auto', 'comment' => 'rainlab.forum::lang.settings.moderator_comment'], 'forum_member[is_banned]' => ['label' => 'rainlab.forum::lang.settings.banned', 'type' => 'checkbox', 'tab' => 'Forum', 'span' => 'auto', 'comment' => 'rainlab.forum::lang.settings.banned_comment']], 'primary');
     });
     UsersController::extendListColumns(function ($widget, $model) {
         if (!$model instanceof \RainLab\User\Models\User) {
             return;
         }
         $widget->addColumns(['forum_member_username' => ['label' => 'rainlab.forum::lang.settings.forum_username', 'relation' => 'forum_member', 'select' => 'username', 'searchable' => false]]);
     });
 }
コード例 #2
0
ファイル: Member.php プロジェクト: aaronleslie/aaronunix
 /**
  * Can the specified member edit this member
  * @param  self $member
  * @return bool
  */
 public function canEdit($member = null)
 {
     if (!$member) {
         $member = Member::getFromUser();
     }
     if (!$member) {
         return false;
     }
     if ($this->id == $member->id) {
         return true;
     }
     if ($member->is_moderator) {
         return true;
     }
     return false;
 }
コード例 #3
0
ファイル: Topics.php プロジェクト: pandabear41/forum-plugin
 protected function prepareTopicList()
 {
     $currentPage = input('page');
     $searchString = trim(input('search'));
     $topics = TopicModel::with('last_post_member')->listFrontEnd(['page' => $currentPage, 'perPage' => $this->topicsPerPage, 'sort' => 'updated_at', 'search' => $searchString]);
     /*
      * Add a "url" helper attribute for linking to each topic
      */
     $topics->each(function ($topic) {
         $topic->setUrl($this->topicPage, $this->controller);
         if ($topic->last_post_member) {
             $topic->last_post_member->setUrl($this->memberPage, $this->controller);
         }
         if ($topic->start_member) {
             $topic->start_member->setUrl($this->memberPage, $this->controller);
         }
     });
     /*
      * Signed in member
      */
     $this->page['member'] = $this->member = MemberModel::getFromUser();
     if ($this->member) {
         $this->member->setUrl($this->memberPage, $this->controller);
         $topics = TopicWatch::setFlagsOnTopics($topics, $this->member);
     }
     $this->page['topics'] = $this->topics = $topics;
     /*
      * Pagination
      */
     if ($topics) {
         $queryArr = [];
         if ($searchString) {
             $queryArr['search'] = $searchString;
         }
         $queryArr['page'] = '';
         $paginationUrl = Request::url() . '?' . http_build_query($queryArr);
         if ($currentPage > ($lastPage = $topics->lastPage()) && $currentPage > 1) {
             return Redirect::to($paginationUrl . $lastPage);
         }
         $this->page['paginationUrl'] = $paginationUrl;
     }
 }
コード例 #4
0
ファイル: Plugin.php プロジェクト: janusnic/OctoberCMS
 public function boot()
 {
     User::extend(function ($model) {
         $model->hasOne['forum_member'] = ['RainLab\\Forum\\Models\\Member'];
     });
     UsersController::extendFormFields(function ($widget, $model, $context) {
         if ($context != 'update') {
             return;
         }
         if (!Member::getFromUser($model)) {
             return;
         }
         $widget->addFields(['forum_member[username]' => ['label' => 'Username', 'tab' => 'Forum', 'comment' => 'The display to represent this user on the forum.'], 'forum_member[is_moderator]' => ['label' => 'Forum moderator', 'type' => 'checkbox', 'tab' => 'Forum', 'span' => 'auto', 'comment' => 'Place a tick in this box if this user can moderate the entire forum.'], 'forum_member[is_banned]' => ['label' => 'Banned from forum', 'type' => 'checkbox', 'tab' => 'Forum', 'span' => 'auto', 'comment' => 'Place a tick in this box if this user is banned from posting to the forum.']], 'primary');
     });
     UsersController::extendListColumns(function ($widget, $model) {
         if (!$model instanceof \RainLab\User\Models\User) {
             return;
         }
         $widget->addColumns(['forum_member_username' => ['label' => 'Forum Username', 'relation' => 'forum_member', 'select' => '@username', 'searchable' => true]]);
     });
 }
コード例 #5
0
ファイル: Channels.php プロジェクト: rainlab/forum-plugin
 public function listChannels()
 {
     if ($this->channels !== null) {
         return $this->channels;
     }
     $channels = Channel::with('first_topic')->isVisible()->get();
     /*
      * Add a "url" helper attribute for linking to each channel
      */
     $channels->each(function ($channel) {
         $channel->setUrl($this->channelPage, $this->controller);
         if ($channel->first_topic) {
             $channel->first_topic->setUrl($this->topicPage, $this->controller);
         }
     });
     $this->page['member'] = $this->member = MemberModel::getFromUser();
     if ($this->member) {
         $channels = TopicTracker::instance()->setFlagsOnChannels($channels, $this->member);
     }
     $channels = $channels->toNested();
     return $this->channels = $channels;
 }
コード例 #6
0
ファイル: Channel.php プロジェクト: aaronleslie/aaronunix
 protected function prepareTopicList()
 {
     /*
      * If channel exists, load the topics
      */
     if ($channel = $this->getChannel()) {
         $currentPage = input('page');
         $searchString = trim(input('search'));
         $topics = TopicModel::with('last_post_member')->listFrontEnd(['page' => $currentPage, 'sort' => 'updated_at', 'channels' => $channel->id, 'search' => $searchString]);
         /*
          * Add a "url" helper attribute for linking to each topic
          */
         $topics->each(function ($topic) {
             if ($this->embedMode) {
                 $topic->url = $this->pageUrl($this->topicPage, [$this->embedTopicParam => $topic->slug]);
             } else {
                 $topic->setUrl($this->topicPage, $this->controller);
             }
             if ($topic->last_post_member) {
                 $topic->last_post_member->setUrl($this->memberPage, $this->controller);
             }
         });
         /*
          * Signed in member
          */
         $this->page['member'] = $this->member = MemberModel::getFromUser();
         if ($this->member) {
             $this->member->setUrl($this->memberPage, $this->controller);
             $topics = TopicWatch::setFlagsOnTopics($topics, $this->member);
             ChannelWatch::flagAsWatched($channel, $this->member);
         }
         $this->page['topics'] = $this->topics = $topics;
         /*
          * Pagination
          */
         if ($topics) {
             $queryArr = [];
             if ($searchString) {
                 $queryArr['search'] = $searchString;
             }
             $queryArr['page'] = '';
             $paginationUrl = Request::url() . '?' . http_build_query($queryArr);
             if ($currentPage > ($lastPage = $topics->lastPage()) && $currentPage > 1) {
                 return Redirect::to($paginationUrl . $lastPage);
             }
             $this->page['paginationUrl'] = $paginationUrl;
         }
     }
     $this->page['isGuest'] = !Auth::check();
 }
コード例 #7
0
ファイル: Topic.php プロジェクト: rainlab/forum-plugin
 protected function handleOptOutLinks()
 {
     if (!($topic = $this->getTopic())) {
         return;
     }
     if (!($action = post('action'))) {
         return;
     }
     if (!in_array($action, ['unfollow', 'unsubscribe'])) {
         return;
     }
     /*
      * Attempt to find member using dry authentication
      */
     if (!($member = $this->getMember())) {
         if (!($authCode = post('auth')) || !strpos($authCode, '!')) {
             return;
         }
         list($hash, $userId) = explode('!', $authCode);
         if (!($user = UserModel::find($userId))) {
             return;
         }
         if (!($member = MemberModel::getFromUser($user))) {
             return;
         }
         $expectedCode = TopicFollow::makeAuthCode($action, $topic, $member);
         if ($authCode != $expectedCode) {
             Flash::error('Invalid authentication code, please sign in and try the link again.');
             return;
         }
     }
     /*
      * Unfollow link
      */
     if ($action == 'unfollow') {
         TopicFollow::unfollow($topic, $member);
         Flash::success('You will no longer receive notifications about this topic.');
     }
     /*
      * Unsubscribe link
      */
     if ($action == 'unsubscribe' && $member->user) {
         MailBlocker::addBlock('rainlab.forum::mail.topic_reply', $member->user);
         Flash::success('You will no longer receive notifications about any topics in this forum.');
     }
 }
コード例 #8
0
ファイル: Topic.php プロジェクト: janusnic/OctoberCMS
 public function canPost($member = null)
 {
     if (!$member) {
         $member = Member::getFromUser();
     }
     if (!$member) {
         return false;
     }
     if ($member->is_banned) {
         return false;
     }
     if ($this->is_locked && !$member->is_moderator) {
         return false;
     }
     return true;
 }
コード例 #9
0
ファイル: Member.php プロジェクト: idxos/portfolio
 public function canEdit()
 {
     if ($this->property('viewMode') == 'view') {
         return false;
     }
     if (!($member = $this->getMember())) {
         return false;
     }
     return $member->canEdit(MemberModel::getFromUser());
 }