Esempio n. 1
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct();
     BackendMenu::setContext('October.Cms', 'cms', true);
     try {
         if (!($theme = Theme::getEditTheme())) {
             throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found'));
         }
         $this->theme = $theme;
         new TemplateList($this, 'pageList', function () use($theme) {
             return Page::listInTheme($theme, true);
         });
         new TemplateList($this, 'partialList', function () use($theme) {
             return Partial::listInTheme($theme, true);
         });
         new TemplateList($this, 'layoutList', function () use($theme) {
             return Layout::listInTheme($theme, true);
         });
         new TemplateList($this, 'contentList', function () use($theme) {
             return Content::listInTheme($theme, true);
         });
         new ComponentList($this, 'componentList');
         new AssetList($this, 'assetList');
     } catch (Exception $ex) {
         $this->handleError($ex);
     }
 }
Esempio n. 2
0
 protected function playerPartialExists($name)
 {
     if (array_key_exists($name, $this->playerPartialFlags)) {
         return $this->playerPartialFlags[$name];
     }
     $controller = Controller::getController();
     if (!$controller) {
         throw new ApplicationException('Media tags can only be processed for front-end requests.');
     }
     $partial = Partial::loadCached($controller->getTheme(), $name);
     return $this->playerPartialFlags[$name] = !!$partial;
 }
Esempio n. 3
0
 public function partials()
 {
     if (!$this->partials) {
         $theme = Theme::getEditTheme();
         $partials = Prtl::listInTheme($theme, true);
         $options = [];
         foreach ($partials as $partial) {
             $options[$partial->baseFileName] = $partial->baseFileName;
         }
         asort($options);
         $this->partials = $options;
     }
     return $this->partials;
 }
Esempio n. 4
0
 /**
  * Scans the theme templates for message references.
  * @return void
  */
 public function scanForMessages()
 {
     $messages = [];
     foreach (Layout::all() as $layout) {
         $messages = array_merge($messages, $this->parseContent($layout->markup));
     }
     foreach (Page::all() as $page) {
         $messages = array_merge($messages, $this->parseContent($page->markup));
     }
     foreach (Partial::all() as $partial) {
         $messages = array_merge($messages, $this->parseContent($partial->markup));
     }
     Message::importMessages($messages);
 }
 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;
 }
 public function up()
 {
     $themes = Theme::all();
     foreach ($themes as $theme) {
         $partials = Partial::inTheme($theme)->all();
         foreach ($partials as $partial) {
             try {
                 $path = $partial->getFullPath();
                 $contents = File::get($path);
                 if (strpos($contents, 'staticPageSnippetCode') === false) {
                     continue;
                 }
                 $contents = str_replace('staticPageSnippetName', 'snippetName', $contents);
                 $contents = str_replace('staticPageSnippetCode', 'snippetCode', $contents);
                 $contents = str_replace('staticPageSnippetProperties', 'snippetProperties', $contents);
                 File::put($path, $contents);
             } catch (\Exception $ex) {
                 continue;
             }
         }
     }
 }
Esempio n. 7
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct();
     BackendMenu::setContext('October.Cms', 'cms', 'pages');
     try {
         if (!($theme = Theme::getEditTheme())) {
             throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found'));
         }
         $this->theme = $theme;
         new TemplateList($this, 'pageList', function () use($theme) {
             return Page::listInTheme($theme, true);
         });
         new TemplateList($this, 'partialList', function () use($theme) {
             return Partial::listInTheme($theme, true);
         });
         new TemplateList($this, 'layoutList', function () use($theme) {
             return Layout::listInTheme($theme, true);
         });
         new TemplateList($this, 'contentList', function () use($theme) {
             return Content::listInTheme($theme, true);
         });
         new ComponentList($this, 'componentList');
         new AssetList($this, 'assetList');
     } catch (Exception $ex) {
         $this->handleError($ex);
     }
     $this->addJs('/modules/cms/assets/js/october.cmspage.js', 'core');
     $this->addJs('/modules/cms/assets/js/october.dragcomponents.js', 'core');
     $this->addCss('/modules/cms/assets/css/october.components.css', 'core');
     // Preload Ace editor modes explicitly, because they could be changed dynamically
     // depending on a content block type
     $this->addJs('/modules/backend/formwidgets/codeeditor/assets/vendor/ace/ace.js', 'core');
     $aceModes = ['markdown', 'plain_text', 'html', 'less', 'css', 'scss', 'sass', 'javascript'];
     foreach ($aceModes as $mode) {
         $this->addJs('/modules/backend/formwidgets/codeeditor/assets/vendor/ace/mode-' . $mode . '.js', 'core');
     }
     $this->bodyClass = 'compact-container side-panel-not-fixed';
     $this->pageTitle = Lang::get('cms::lang.cms.menu_label');
 }
Esempio n. 8
0
 /**
  * Renders a requested partial.
  * The framework uses this method internally.
  * @param string $partial The view to load.
  * @param array $parameters 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', ['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' => $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' => $name]));
             } else {
                 return false;
             }
         }
     }
     /*
      * Run functions for CMS partials only (Cms\Classes\Partial)
      */
     if ($partial instanceof Partial) {
         $this->partialStack->stackPartial();
         $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;
             $this->partialStack->addComponent($alias, $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 partial
      */
     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) {
         $this->partialStack->unstackPartial();
     }
     $this->vars = $vars;
     return $result;
 }
Esempio n. 9
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)
 {
     /*
      * 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' => $name]));
                 } else {
                     return false;
                 }
             }
         } 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;
             }
         }
     }
     CmsException::mask($partial, 400);
     $this->loader->setObject($partial);
     $template = $this->twig->loadTemplate($partial->getFullPath());
     $result = $template->render(array_merge($this->vars, $parameters));
     CmsException::unmask();
     $this->componentContext = null;
     return $result;
 }
Esempio n. 10
0
 /**
  * Creates a partial using the contents of a specified file.
  * @param  string $name      New Partial name
  * @param  string $filePath  File containing partial contents
  * @param  string $themeCode Theme to create the partial
  * @return void
  */
 protected static function createPartialFromFile($name, $filePath, $themeCode)
 {
     if (!File::exists($filePath)) {
         return;
     }
     $partial = new Partial($themeCode);
     $partial->fill(['fileName' => $name, 'markup' => File::get($filePath)]);
     $partial->save();
 }
Esempio n. 11
0
 /**
  * Returns a list of snippets in the specified theme.
  * @param \Cms\Classes\Theme $theme Specifies a parent theme.
  * @return array Returns an array of Snippet objects.
  */
 protected function listThemeSnippets($theme)
 {
     $result = [];
     $partials = Partial::listInTheme($theme, true);
     foreach ($partials as $partial) {
         $viewBag = $partial->getViewBag();
         if (strlen($viewBag->property('snippetCode'))) {
             $snippet = new Snippet();
             $snippet->initFromPartial($partial);
             $result[] = $snippet;
         }
     }
     return $result;
 }
Esempio n. 12
0
 public static function getPartial(Campaign $campaign)
 {
     return Partial::load(Theme::getActiveTheme(), $campaign->file_name);
 }
Esempio n. 13
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' => $name]));
                 } 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) {
             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->setComponentPropertiesFromParameters($componentObj, $parameters);
             $componentObj->init();
             $componentObj->onInit();
             // Deprecated: Remove ithis line if year >= 2015
         }
         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;
 }