Пример #1
0
 public function getChannel()
 {
     if ($this->channel !== null) {
         return $this->channel;
     }
     if (!($slug = $this->property('slug'))) {
         return null;
     }
     return $this->channel = ChannelModel::whereSlug($slug)->first();
 }
Пример #2
0
 public function init()
 {
     $code = $this->propertyOrParam('idParam');
     if (!$code) {
         throw new Exception('No code specified for the Forum Embed component');
     }
     $parentChannel = ($channelId = $this->property('channelId')) ? ChannelModel::whereSlug($channelId)->first() : null;
     if (!$parentChannel) {
         throw new Exception('No channel specified for Forum Embed component');
     }
     $properties = $this->getProperties();
     /*
      * Proxy as topic
      */
     if (post('channel') || $this->propertyOrParam('topicParam')) {
         $properties['idParam'] = $this->property('topicParam');
         $component = $this->addComponent('RainLab\\Forum\\Components\\Topic', $this->alias, $properties);
     } else {
         if ($channel = ChannelModel::forEmbed($parentChannel, $code)->first()) {
             $properties['idParam'] = $channel->slug;
         }
         $properties['topicPage'] = $this->page->baseFileName;
         $component = $this->addComponent('RainLab\\Forum\\Components\\Channel', $this->alias, $properties);
         $component->embedTopicParam = $this->property('topicParam');
         /*
          * If a channel 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 channel should not be generated.
          */
         if (!$channel) {
             $this->controller->bindEvent('page.end', function () use($component, $parentChannel, $code) {
                 if ($component->embedMode !== false) {
                     $channel = ChannelModel::createForEmbed($code, $parentChannel, $this->page->title);
                     $component->setProperty('idParam', $channel->slug);
                     $component->onRun();
                 }
             });
         }
     }
     /*
      * Set the embedding mode
      */
     if (post('channel')) {
         $component->embedMode = 'post';
     } elseif (post('search')) {
         $component->embedMode = 'search';
     } elseif ($this->propertyOrParam('topicParam')) {
         $component->embedMode = 'topic';
     } else {
         $component->embedMode = 'channel';
     }
 }
Пример #3
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';
 }