Exemplo n.º 1
0
 protected function listComponents()
 {
     $result = [];
     if (!isset($this->model->settings['components'])) {
         return $result;
     }
     $manager = ComponentManager::instance();
     $manager->listComponents();
     foreach ($this->model->settings['components'] as $name => $properties) {
         list($name, $alias) = strpos($name, ' ') ? explode(' ', $name) : [$name, $name];
         try {
             $componentObj = $manager->makeComponent($name, null, $properties);
             $componentObj->alias = $alias;
             $componentObj->pluginIcon = 'icon-puzzle-piece';
             $plugin = $manager->findComponentPlugin($componentObj);
             if ($plugin) {
                 $pluginDetails = $plugin->pluginDetails();
                 if (isset($pluginDetails['icon'])) {
                     $componentObj->pluginIcon = $pluginDetails['icon'];
                 }
             }
         } catch (Exception $ex) {
             $componentObj = new UnknownComponent(null, $properties, $ex->getMessage());
             $componentObj->alias = $alias;
             $componentObj->pluginIcon = 'icon-bug';
         }
         $result[] = $componentObj;
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     parent::register('cms');
     /*
      * Register navigation
      */
     BackendMenu::registerCallback(function ($manager) {
         $manager->registerMenuItems('October.Cms', ['cms' => ['label' => 'cms::lang.cms.menu_label', 'icon' => 'icon-magic', 'url' => Backend::url('cms'), 'permissions' => ['cms.*'], 'order' => 10, 'sideMenu' => ['pages' => ['label' => 'cms::lang.page.menu_label', 'icon' => 'icon-copy', 'url' => 'javascript:;', 'attributes' => ['data-menu-item' => 'pages'], 'permissions' => ['cms.manage_pages'], 'counterLabel' => 'cms::lang.page.unsaved_label'], 'partials' => ['label' => 'cms::lang.partial.menu_label', 'icon' => 'icon-tags', 'url' => 'javascript:;', 'attributes' => ['data-menu-item' => 'partials'], 'permissions' => ['cms.manage_partials'], 'counterLabel' => 'cms::lang.partial.unsaved_label'], 'layouts' => ['label' => 'cms::lang.layout.menu_label', 'icon' => 'icon-th-large', 'url' => 'javascript:;', 'attributes' => ['data-menu-item' => 'layouts'], 'permissions' => ['cms.manage_layouts'], 'counterLabel' => 'cms::lang.layout.unsaved_label'], 'content' => ['label' => 'cms::lang.content.menu_label', 'icon' => 'icon-file-text-o', 'url' => 'javascript:;', 'attributes' => ['data-menu-item' => 'content'], 'permissions' => ['cms.manage_content'], 'counterLabel' => 'cms::lang.content.unsaved_label'], 'assets' => ['label' => 'cms::lang.asset.menu_label', 'icon' => 'icon-picture-o', 'url' => 'javascript:;', 'attributes' => ['data-menu-item' => 'assets'], 'permissions' => ['cms.manage_assets'], 'counterLabel' => 'cms::lang.asset.unsaved_label'], 'components' => ['label' => 'cms::lang.component.menu_label', 'icon' => 'icon-puzzle-piece', 'url' => 'javascript:;', 'attributes' => ['data-menu-item' => 'components'], 'permissions' => ['cms.manage_pages', 'cms.manage_layouts', 'cms.manage_partials']]]]]);
     });
     /*
      * Register permissions
      */
     BackendAuth::registerCallback(function ($manager) {
         $manager->registerPermissions('October.Cms', ['cms.manage_content' => ['label' => 'cms::lang.permissions.manage_content', 'tab' => 'Cms'], 'cms.manage_assets' => ['label' => 'cms::lang.permissions.manage_assets', 'tab' => 'Cms'], 'cms.manage_pages' => ['label' => 'cms::lang.permissions.manage_pages', 'tab' => 'Cms'], 'cms.manage_layouts' => ['label' => 'cms::lang.permissions.manage_layouts', 'tab' => 'Cms'], 'cms.manage_partials' => ['label' => 'cms::lang.permissions.manage_partials', 'tab' => 'Cms'], 'cms.manage_themes' => ['label' => 'cms::lang.permissions.manage_themes', 'tab' => 'Cms']]);
     });
     /*
      * Register widgets
      */
     WidgetManager::instance()->registerFormWidgets(function ($manager) {
         $manager->registerFormWidget('Cms\\FormWidgets\\Components');
     });
     /*
      * Register settings
      */
     SettingsManager::instance()->registerCallback(function ($manager) {
         $manager->registerSettingItems('October.Cms', ['theme' => ['label' => 'cms::lang.theme.settings_menu', 'description' => 'cms::lang.theme.settings_menu_description', 'category' => SettingsManager::CATEGORY_CMS, 'icon' => 'icon-picture-o', 'url' => Backend::URL('cms/themes'), 'order' => 200], 'maintenance_settings' => ['label' => 'cms::lang.maintenance.settings_menu', 'description' => 'cms::lang.maintenance.settings_menu_description', 'category' => SettingsManager::CATEGORY_CMS, 'icon' => 'icon-plug', 'class' => 'Cms\\Models\\MaintenanceSettings', 'order' => 400]]);
     });
     /*
      * Register components
      */
     ComponentManager::instance()->registerComponents(function ($manager) {
         $manager->registerComponent('Cms\\Classes\\ViewBag', 'viewBag');
     });
 }
 public function testDefineProperties()
 {
     include_once base_path() . '/tests/fixtures/plugins/october/tester/components/Archive.php';
     $manager = ComponentManager::instance();
     $object = $manager->makeComponent('testArchive');
     $details = $object->componentDetails();
     $this->assertCount(2, $details);
     $this->assertNotNull($details);
     $this->assertArrayHasKey('name', $details);
     $this->assertArrayHasKey('description', $details);
     $this->assertEquals('Blog Archive Dummy Component', $details['name']);
 }
 public static function makeBaguetteGallery($images, $layout = "", $class = "")
 {
     // Set component properties
     if (empty($class)) {
         $class = self::$defaultClass;
     }
     if (empty($layout)) {
         $layout = self::$defaultLayout;
     }
     $parameters = ['layout' => $layout, 'class' => $class, 'images' => []];
     foreach ($images as $key => $val) {
         $parameters['images'][$key] = new BaguetteImage($val, true);
     }
     // Get twig runtime
     $twig = App::make('twig.environment');
     $partial = null;
     $result = "";
     // Create an instance of the component
     $manager = ComponentManager::instance();
     $component = $manager->makeComponent(self::$componentName, null, $parameters);
     $component->init();
     $component->alias = self::$componentName;
     // Try first to find a partial from the theme
     $overrideName = $component->alias . '/' . $parameters['layout'];
     if (Filesystem::isFile(Theme::getActiveTheme()->getPath() . '/partials/' . $overrideName . '.htm')) {
         $partial = Partial::loadCached(Theme::getActiveTheme(), $overrideName);
     }
     // If not found we use one from the plugin
     if (is_null($partial)) {
         if (Filesystem::isFile(plugins_path() . '/nsrosenqvist/baguettegallery/components/baguettegallery/' . $parameters['layout'] . '.htm')) {
             $partial = ComponentPartial::loadCached($component, $parameters['layout']);
         } else {
             $partial = ComponentPartial::loadCached($component, self::$defaultLayout);
         }
     }
     // Render the component
     if (!is_null($partial) && !empty($images)) {
         $template = $twig->loadTemplate($partial->getFullPath());
         $result = $template->render($parameters);
     }
     return $result;
 }
Exemplo n.º 5
0
 /**
  * Adds a component to the page object
  * @param mixed  $name        Component class name or short name
  * @param string $alias       Alias to give the component
  * @param array  $properties  Component properties
  * @param bool   $addToLayout Add to layout, instead of page
  * @return ComponentBase Component object
  */
 public function addComponent($name, $alias, $properties, $addToLayout = false)
 {
     $manager = ComponentManager::instance();
     if ($addToLayout) {
         if (!($componentObj = $manager->makeComponent($name, $this->layoutObj, $properties))) {
             throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $name]));
         }
         $componentObj->alias = $alias;
         $this->vars[$alias] = $this->layout->components[$alias] = $componentObj;
     } else {
         if (!($componentObj = $manager->makeComponent($name, $this->pageObj, $properties))) {
             throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $name]));
         }
         $componentObj->alias = $alias;
         $this->vars[$alias] = $this->page->components[$alias] = $componentObj;
     }
     $this->setComponentPropertiesFromParams($componentObj);
     $componentObj->init();
     return $componentObj;
 }
Exemplo n.º 6
0
 public function onExpandMarkupToken()
 {
     if (!($alias = post('tokenName'))) {
         throw new ApplicationException(trans('cms::lang.component.no_records'));
     }
     // Can only expand components at this stage
     if (!($type = post('tokenType')) && $type != 'component') {
         return;
     }
     if (!($names = (array) post('component_names')) || !($aliases = (array) post('component_aliases'))) {
         throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias]));
     }
     if (($index = array_get(array_flip($aliases), $alias, false)) === false) {
         throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias]));
     }
     if (!($componentName = array_get($names, $index))) {
         throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias]));
     }
     $manager = ComponentManager::instance();
     $componentObj = $manager->makeComponent($componentName);
     $partial = ComponentPartial::load($componentObj, 'default');
     $content = $partial->getContent();
     $content = str_replace('__SELF__', $alias, $content);
     return $content;
 }
Exemplo n.º 7
0
 /**
  * Initializes CMS components associated with the page.
  */
 public function initCmsComponents($cmsController)
 {
     $snippetComponents = Snippet::listPageComponents($this->getFileName(), $this->theme, $this->markup . $this->code);
     $componentManager = ComponentManager::instance();
     foreach ($snippetComponents as $componentInfo) {
         // Register components for snippet-based components
         // if they're not defined yet. This is required because
         // not all snippet components are registered as components,
         // but it's safe to register them in render-time.
         if (!$componentManager->hasComponent($componentInfo['class'])) {
             $componentManager->registerComponent($componentInfo['class'], $componentInfo['alias']);
         }
         $cmsController->addComponent($componentInfo['class'], $componentInfo['alias'], $componentInfo['properties']);
     }
 }
Exemplo n.º 8
0
 /**
  * Register components
  */
 protected function registerComponents()
 {
     ComponentManager::instance()->registerComponents(function ($manager) {
         $manager->registerComponent('Cms\\Classes\\ViewBag', 'viewBag');
     });
 }
Exemplo n.º 9
0
 /**
  * Returns a component by its name.
  * This method is used only in the back-end and for internal system needs when 
  * the standard way to access components is not an option.
  * @param string $componentName Specifies the component name.
  * @return \Cms\Classes\ComponentBase Returns the component instance or null.
  */
 public function getComponent($componentName)
 {
     if (!($componentSection = $this->hasComponent($componentName))) {
         return null;
     }
     return ComponentManager::instance()->makeComponent($componentName, null, $this->settings['components'][$componentSection]);
 }
Exemplo n.º 10
0
 /**
  * Adds a component to the page object
  * @param mixed  $name        Component class name or short name
  * @param string $alias       Alias to give the component
  * @param array  $properties  Component properties
  * @param bool   $addToLayout Add to layout, instead of page
  * @return ComponentBase Component object
  */
 public function addComponent($name, $alias, $properties, $addToLayout = false)
 {
     $manager = ComponentManager::instance();
     if ($addToLayout) {
         if (!($componentObj = $manager->makeComponent($name, $this->layoutObj, $properties))) {
             throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $name]));
         }
         $componentObj->alias = $alias;
         $this->vars[$alias] = $this->layout->components[$alias] = $componentObj;
     } else {
         if (!($componentObj = $manager->makeComponent($name, $this->pageObj, $properties))) {
             throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $name]));
         }
         $componentObj->alias = $alias;
         $this->vars[$alias] = $this->page->components[$alias] = $componentObj;
     }
     $componentObj->init();
     $componentObj->onInit();
     // Deprecated: Remove ithis line if year >= 2015
     return $componentObj;
 }
 /**
  * Checks if the object has a component with the specified name.
  * @param string $componentName Specifies the component name.
  * @return mixed Return false or the full component name used on the page (it could include the alias).
  */
 public function hasComponent($componentName)
 {
     $componentManager = ComponentManager::instance();
     $componentName = $componentManager->resolve($componentName);
     foreach ($this->settings['components'] as $sectionName => $values) {
         $result = $sectionName;
         if ($sectionName == $componentName) {
             return $result;
         }
         $parts = explode(' ', $sectionName);
         if (count($parts) > 1) {
             $sectionName = trim($parts[0]);
             if ($sectionName == $componentName) {
                 return $result;
             }
         }
         $sectionName = $componentManager->resolve($sectionName);
         if ($sectionName == $componentName) {
             return $result;
         }
     }
     return false;
 }
Exemplo n.º 12
0
 public function test()
 {
     //        $rb = new RuleBuilder;
     //
     //        $bonus_90 = $rb->create('current_user_submissions', 'submission',
     //        $rb['submission']['score']->greaterThan($rb['score_threshold']),
     //        [
     //            $rb['(bonus)']->assign($rb['(bonus)']->add($rb['points']))
     //        ]);
     //
     //        $rb['(bonus)'] = 0;
     //        $rb['submission']['score'] = 0;
     //        $rb['score_threshold'] = 0;
     //        $rb['point'] = 0;
     //
     //        $rg = new RuleGroup('submissionstest');
     //        $rg->add($bonus_90);
     //        $rg->saveRules();
     $manager = ComponentManager::instance();
     echo json_encode($manager->listComponents());
 }
Exemplo n.º 13
0
 /**
  * Returns the configured view bag component.
  * This method is used only in the back-end and for internal system needs when 
  * the standard way to access components is not an option.
  * @return \Cms\Classes\ViewBag Returns the view bag component instance.
  */
 public function getViewBag()
 {
     if ($this->viewBagCache !== false) {
         return $this->viewBagCache;
     }
     $componentName = 'viewBag';
     if (!isset($this->settings['components'][$componentName])) {
         $viewBag = new ViewBag(null, []);
         $viewBag->name = $componentName;
         return $this->viewBagCache = $viewBag;
     }
     return $this->viewBagCache = ComponentManager::instance()->makeComponent($componentName, null, $this->settings['components'][$componentName]);
 }
Exemplo n.º 14
0
 /**
  * Renders a requested partial.
  * The framework uses this method internally.
  * @param string $partial The view to load.
  * @param array $params Parameter variables to pass to the view.
  * @param bool $throwException Throw an exception if the partial is not found.
  * @return mixed Partial contents or false if not throwing an exception.
  */
 public function renderPartial($name, $parameters = [], $throwException = true)
 {
     $vars = $this->vars;
     /*
      * Alias @ symbol for ::
      */
     if (substr($name, 0, 1) == '@') {
         $name = '::' . substr($name, 1);
     }
     /*
      * Process Component partial
      */
     if (strpos($name, '::') !== false) {
         list($componentAlias, $partialName) = explode('::', $name);
         /*
          * Component alias not supplied
          */
         if (!strlen($componentAlias)) {
             if ($this->componentContext !== null) {
                 $componentObj = $this->componentContext;
             } elseif (($componentObj = $this->findComponentByPartial($partialName)) === null) {
                 if ($throwException) {
                     throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name' => $partialName]));
                 } else {
                     return false;
                 }
             }
             /*
              * Component alias is supplied
              */
         } else {
             if (($componentObj = $this->findComponentByName($componentAlias)) === null) {
                 if ($throwException) {
                     throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $componentAlias]));
                 } else {
                     return false;
                 }
             }
         }
         $partial = null;
         $this->componentContext = $componentObj;
         /*
          * Check if the theme has an override
          */
         if (strpos($partialName, '/') === false) {
             $overrideName = $componentObj->alias . '/' . $partialName;
             $partial = Partial::loadCached($this->theme, $overrideName);
         }
         /*
          * Check the component partial
          */
         if ($partial === null) {
             $partial = ComponentPartial::loadCached($componentObj, $partialName);
         }
         if ($partial === null) {
             if ($throwException) {
                 throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name' => $name]));
             } else {
                 return false;
             }
         }
         /*
          * Set context for self access
          */
         $this->vars['__SELF__'] = $componentObj;
     } else {
         /*
          * Process theme partial
          */
         if (($partial = Partial::loadCached($this->theme, $name)) === null) {
             if ($throwException) {
                 throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name' => $name]));
             } else {
                 return false;
             }
         }
     }
     /*
      * Run functions for CMS partials only (Cms\Classes\Partial)
      */
     if ($partial instanceof Partial) {
         $manager = ComponentManager::instance();
         foreach ($partial->settings['components'] as $component => $properties) {
             // Do not inject the viewBag component to the environment.
             // Not sure if they're needed there by the requirements,
             // but there were problems with array-typed properties used by Static Pages
             // snippets and setComponentPropertiesFromParams(). --ab
             if ($component == 'viewBag') {
                 continue;
             }
             list($name, $alias) = strpos($component, ' ') ? explode(' ', $component) : [$component, $component];
             if (!($componentObj = $manager->makeComponent($name, $this->pageObj, $properties))) {
                 throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $name]));
             }
             $componentObj->alias = $alias;
             $parameters[$alias] = $partial->components[$alias] = $componentObj;
             array_push($this->partialComponentStack, ['name' => $alias, 'obj' => $componentObj]);
             $this->setComponentPropertiesFromParams($componentObj, $parameters);
             $componentObj->init();
         }
         CmsException::mask($this->page, 300);
         $parser = new CodeParser($partial);
         $partialObj = $parser->source($this->page, $this->layout, $this);
         CmsException::unmask();
         CmsException::mask($partial, 300);
         $partialObj->onStart();
         $partial->runComponents();
         $partialObj->onEnd();
         CmsException::unmask();
     }
     /*
      * Render the parital
      */
     CmsException::mask($partial, 400);
     $this->loader->setObject($partial);
     $template = $this->twig->loadTemplate($partial->getFullPath());
     $result = $template->render(array_merge($this->vars, $parameters));
     CmsException::unmask();
     if ($partial instanceof Partial) {
         if ($this->partialComponentStack) {
             array_pop($this->partialComponentStack);
         }
     }
     $this->vars = $vars;
     $this->componentContext = null;
     return $result;
 }
Exemplo n.º 15
0
 /**
  * Parse component sections. 
  * Replace the multiple component sections with a single "components" 
  * element in the $settings property.
  */
 public function parseComponentSettings()
 {
     $manager = ComponentManager::instance();
     $components = [];
     foreach ($this->settings as $setting => $value) {
         if (!is_array($value)) {
             continue;
         }
         $settingParts = explode(' ', $setting);
         $settingName = $settingParts[0];
         if (!$manager->hasComponent($settingName)) {
             continue;
         }
         $components[$setting] = $value;
         unset($this->settings[$setting]);
     }
     $this->settings['components'] = $components;
 }