예제 #1
0
 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;
     }
 }
예제 #2
0
 public function init()
 {
     $mode = $this->property('mode');
     $code = $this->property('embedCode');
     if (!$code) {
         throw new Exception('No code specified for the Forum Embed component');
     }
     $channel = ($channelSlug = $this->property('channelSlug')) ? ChannelModel::whereSlug($channelSlug)->first() : null;
     if (!$channel) {
         throw new Exception('No channel specified for Forum Embed component');
     }
     $properties = $this->getProperties();
     /*
      * Proxy as topic
      */
     if ($topic = TopicModel::forEmbed($channel, $code)->first()) {
         $properties['slug'] = $topic->slug;
     }
     $component = $this->addComponent('RainLab\\Forum\\Components\\Topic', $this->alias, $properties);
     /*
      * If a topic does not already exist, generate it when the page ends.
      * This can be disabled by the page setting embedMode to FALSE, for example,
      * if the page returns 404 a topic should not be generated.
      */
     if (!$topic) {
         $this->controller->bindEvent('page.end', function () use($component, $channel, $code) {
             if ($component->embedMode !== false) {
                 $topic = TopicModel::createForEmbed($code, $channel, $this->page->title);
                 $component->setProperty('slug', $topic->slug);
                 $component->onRun();
             }
         });
     }
     /*
      * Set the embedding mode: Single topic
      */
     $component->embedMode = 'single';
 }
예제 #3
0
 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();
 }
예제 #4
0
 public function onCreate()
 {
     try {
         if (!($user = Auth::getUser())) {
             throw new ApplicationException('You should be logged in.');
         }
         $member = $this->getMember();
         $channel = $this->getChannel();
         if (TopicModel::checkThrottle($member)) {
             throw new ApplicationException('Please wait a few minutes before posting another topic.');
         }
         if ($member->is_banned) {
             throw new ApplicationException('You cannot create new topics: Your account is banned.');
         }
         $topic = TopicModel::createInChannel($channel, $member, post());
         $topicUrl = $this->currentPageUrl([$this->paramName('slug') => $topic->slug]);
         Flash::success(post('flash', 'Topic created successfully!'));
         /*
          * Extensbility
          */
         Event::fire('rainlab.forum.topic.create', [$this, $topic, $topicUrl]);
         $this->fireEvent('topic.create', [$topic, $topicUrl]);
         /*
          * Redirect to the intended page after successful update
          */
         $redirectUrl = post('redirect', $topicUrl);
         return Redirect::to($redirectUrl);
     } catch (Exception $ex) {
         Flash::error($ex->getMessage());
     }
 }