Пример #1
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';
     }
 }