Пример #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 index_onDelete()
 {
     if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
         foreach ($checkedIds as $channelId) {
             if (!($channel = Channel::find($channelId))) {
                 continue;
             }
             $channel->delete();
         }
         Flash::success('Successfully deleted those channels.');
     }
     return $this->listRefresh();
 }
Пример #4
0
 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;
 }
Пример #5
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';
 }
Пример #6
0
 public function reorder_onMove()
 {
     $sourceNode = Channel::find(post('sourceNode'));
     $targetNode = post('targetNode') ? Channel::find(post('targetNode')) : null;
     if ($sourceNode == $targetNode) {
         return;
     }
     switch (post('position')) {
         case 'before':
             $sourceNode->moveBefore($targetNode);
             break;
         case 'after':
             $sourceNode->moveAfter($targetNode);
             break;
         case 'child':
             $sourceNode->makeChildOf($targetNode);
             break;
         default:
             $sourceNode->makeRoot();
             break;
     }
     // $this->vars['records'] = Channel::make()->getEagerRoot();
     // return ['#reorderRecords' => $this->makePartial('reorder_records')];
 }
Пример #7
0
 public function onMove()
 {
     $member = $this->getMember();
     if (!$member->is_moderator) {
         Flash::error('Access denied');
         return;
     }
     $channelId = post('channel');
     $channel = ChannelModel::find($channelId);
     if ($channel) {
         $this->getTopic()->moveToChannel($channel);
         Flash::success(post('flash', 'Post moved successfully!'));
     } else {
         Flash::error('Unable to find a channel to move to.');
     }
 }
Пример #8
0
 public function run()
 {
     $orange = Channel::create(['title' => 'Channel Orange', 'description' => 'A root level forum channel']);
     $autumn = $orange->children()->create(['title' => 'Autumn Leaves', 'description' => 'Disccusion about the season of falling leaves.']);
     $autumn->children()->create(['title' => 'September', 'description' => 'The start of the fall season.']);
     $october = $autumn->children()->create(['title' => 'October', 'description' => 'The middle of the fall season.']);
     $autumn->children()->create(['title' => 'November', 'description' => 'The end of the fall season.']);
     $orange->children()->create(['title' => 'Summer Breeze', 'description' => 'Disccusion about the wind at the ocean.']);
     $green = Channel::create(['title' => 'Channel Green', 'description' => 'A root level forum channel']);
     $green->children()->create(['title' => 'Winter Snow', 'description' => 'Disccusion about the frosty snow flakes.']);
     $green->children()->create(['title' => 'Spring Trees', 'description' => 'Disccusion about the blooming gardens.']);
     // if (!Schema::hasTable('users'))
     //     return;
     // $user = \RainLab\User\Models\User::first();
     // if (!$user) return;
     // $member = Member::getFromUser($user);
     // Topic::createInChannel($october, $member, ['subject' => 'First post!', 'content' => 'Welcome to the forum!']);
     // $topic = Topic::createInChannel($october, $member, ['subject' => 'Lots of posts in here!', 'content' => 'Another post!']);
     // Post::createInTopic($topic, $member, ['content' => 'Test content']);
     // Post::createInTopic($topic, $member, ['content' => 'Plugins are the foundation for adding new features to the CMS by extending it']);
     // Post::createInTopic($topic, $member, ['content' => 'Define components']);
     // Post::createInTopic($topic, $member, ['content' => 'Define user permissions']);
     // Post::createInTopic($topic, $member, ['content' => 'Add back-end pages, menu items, and forms']);
     // Post::createInTopic($topic, $member, ['content' => 'Create database table structures and seed data']);
     // Post::createInTopic($topic, $member, ['content' => 'Alter functionality of the core or other plugins']);
     // Post::createInTopic($topic, $member, ['content' => 'Provide classes, back-end controllers, views, assets, and other files']);
     // Post::createInTopic($topic, $member, ['content' => 'Information about the plugin, its name, and author']);
     // Post::createInTopic($topic, $member, ['content' => 'Registration methods for extending the CMS']);
     // Post::createInTopic($topic, $member, ['content' => 'Injecting variables by participating in the page execution cycle']);
     // Post::createInTopic($topic, $member, ['content' => 'Handling AJAX events triggered by the page']);
     // Post::createInTopic($topic, $member, ['content' => 'Providing basic markup using partials']);
     // Post::createInTopic($topic, $member, ['content' => 'Pages - hold the content for each URL.']);
     // Post::createInTopic($topic, $member, ['content' => 'Partials - contain reusable chunks of HTML markup.']);
     // Post::createInTopic($topic, $member, ['content' => 'Layouts - define the page scaffold.']);
     // Post::createInTopic($topic, $member, ['content' => 'Content files - text or HTML blocks that can be edited separately from the page or layout.']);
     // Post::createInTopic($topic, $member, ['content' => 'Asset files - are resource files like images and stylesheets.']);
     // Post::createInTopic($topic, $member, ['content' => 'url - the page URL (required)']);
     // Post::createInTopic($topic, $member, ['content' => 'layout - the page layout, optional. If specified, should contain the name of the layout file, without extension. For example: "default".']);
     // Post::createInTopic($topic, $member, ['content' => 'description - the page description for the back-end interface']);
     // Post::createInTopic($topic, $member, ['content' => 'description - the partial description, for the back-end UI (optional)']);
     // Post::createInTopic($topic, $member, ['content' => 'description - the layout description, for the back-end UI (optional)']);
     // Post::createInTopic($topic, $member, ['content' => 'name - the layout name, for the back-end UI (optional)']);
     // Post::createInTopic($topic, $member, ['content' => 'htm - for HTML markup']);
     // Post::createInTopic($topic, $member, ['content' => 'txt - for plain text']);
     // Post::createInTopic($topic, $member, ['content' => 'md - for Markdown syntax']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Moar posts!', 'content' => 'Another post content!']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Plugins are the foundation for adding new features to the CMS by extending it', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Define components', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Define user permissions', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Add back-end pages, menu items, and forms', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Create database table structures and seed data', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Alter functionality of the core or other plugins', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Provide classes, back-end controllers, views, assets, and other files', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Information about the plugin, its name, and author', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Registration methods for extending the CMS', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Injecting variables by participating in the page execution cycle', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Handling AJAX events triggered by the page', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Providing basic markup using partials', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Pages - hold the content for each URL.', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Partials - contain reusable chunks of HTML markup.', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Layouts - define the page scaffold.', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Content files - text or HTML blocks that can be edited separately from the page or layout.', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'Asset files - are resource files like images and stylesheets.', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'url - the page URL (required)', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'layout - the page layout, optional. If specified, should contain the name of the layout file, without extension. For example: "default".', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'description - the page description for the back-end interface', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'description - the partial description, for the back-end UI (optional)', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'description - the layout description, for the back-end UI (optional)', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'name - the layout name, for the back-end UI (optional)', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'htm - for HTML markup', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'txt - for plain text', 'content' => 'Another post content']);
     // Topic::createInChannel($autumn, $member, ['subject' => 'md - for Markdown syntax', 'content' => 'Another post content']);
 }