Example #1
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct();
     BackendMenu::setContext('RainLab.Pages', 'pages', 'pages');
     try {
         if (!($this->theme = Theme::getEditTheme())) {
             throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found'));
         }
         new PageList($this, 'pageList');
         new MenuList($this, 'menuList');
         new SnippetList($this, 'snippetList');
         $theme = $this->theme;
         new TemplateList($this, 'contentList', function () use($theme) {
             return Content::listInTheme($theme, true);
         });
     } catch (Exception $ex) {
         $this->handleError($ex);
     }
     $this->addJs('/modules/backend/assets/js/october.treeview.js', 'core');
     $this->addJs('/plugins/rainlab/pages/assets/js/pages-page.js');
     $this->addJs('/plugins/rainlab/pages/assets/js/pages-snippets.js');
     $this->addCss('/plugins/rainlab/pages/assets/css/pages.css');
     // Preload the code editor class as it could be needed
     // before it loads dynamically.
     $this->addJs('/modules/backend/formwidgets/codeeditor/assets/js/codeeditor.js', 'core');
     $this->bodyClass = 'compact-container side-panel-not-fixed';
     $this->pageTitle = 'rainlab.pages::lang.plugin.name';
     $this->pageTitleTemplate = '%s Pages';
 }
Example #2
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);
     }
 }
Example #3
0
 public function testHtmlContent()
 {
     $theme = Theme::load('test');
     $content = Content::load($theme, 'html-content.htm');
     $this->assertEquals('<a href="#">Stephen Saucier</a> changed his profile picture &mdash; <small>7 hrs ago</small></div>', $content->markup);
     $this->assertEquals('<a href="#">Stephen Saucier</a> changed his profile picture &mdash; <small>7 hrs ago</small></div>', $content->parsedMarkup);
 }
Example #4
0
 public function boot()
 {
     /*
      * Set the page context for translation caching.
      */
     Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
         if (!$page) {
             return;
         }
         $translate = Translator::instance();
         $translate->loadLocaleFromSession();
         Message::setContext($translate->getLocale(), $page->url);
     });
     /*
      * Adds language suffixes to content files.
      */
     Event::listen('cms.page.beforeRenderContent', function ($controller, $fileName) {
         if (!strlen(File::extension($fileName))) {
             $fileName .= '.htm';
         }
         /*
          * Splice the active locale in to the filename
          * - content.htm -> content.en.htm
          */
         $locale = Translator::instance()->getLocale();
         $fileName = substr_replace($fileName, '.' . $locale, strrpos($fileName, '.'), 0);
         if (($content = Content::loadCached($controller->getTheme(), $fileName)) !== null) {
             return $content;
         }
     });
     /*
      * Automatically replace form fields for multi lingual equivalents
      */
     Event::listen('backend.form.extendFieldsBefore', function ($widget) {
         if (!($model = $widget->model)) {
             return;
         }
         if (!method_exists($model, 'isClassExtendedWith')) {
             return;
         }
         if (!$model->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) {
             return;
         }
         if (!is_array($model->translatable)) {
             return;
         }
         if (!empty($widget->config->fields)) {
             $widget->fields = $this->processFormMLFields($widget->fields, $model);
         }
         if (!empty($widget->config->tabs['fields'])) {
             $widget->tabs['fields'] = $this->processFormMLFields($widget->tabs['fields'], $model);
         }
         if (!empty($widget->config->secondaryTabs['fields'])) {
             $widget->secondaryTabs['fields'] = $this->processFormMLFields($widget->secondaryTabs['fields'], $model);
         }
     });
 }
Example #5
0
 public function onSave()
 {
     if (!$this->checkEditor()) {
         return;
     }
     $fileName = post('file');
     $template = Content::load($this->getTheme(), $fileName);
     $template->fill(['markup' => post('content')]);
     $template->save();
 }
Example #6
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct();
     BackendMenu::setContext('Shahin.Pages', 'pages', 'pages');
     try {
         if (!($this->theme = Theme::getEditTheme())) {
             throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found'));
         }
         new MenuList($this, 'menuList');
         $theme = $this->theme;
         new TemplateList($this, 'contentList', function () use($theme) {
             return Content::listInTheme($theme, true);
         });
     } catch (Exception $ex) {
         $this->handleError($ex);
     }
 }
 public function boot()
 {
     /*
      * Set the page context for translation caching.
      */
     Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
         if (!$page) {
             return;
         }
         $translator = Translator::instance();
         Message::setContext($translator->getLocale(), $page->url);
     });
     /*
      * Adds language suffixes to content files.
      */
     Event::listen('cms.page.beforeRenderContent', function ($controller, $fileName) {
         if (!strlen(File::extension($fileName))) {
             $fileName .= '.htm';
         }
         /*
          * Splice the active locale in to the filename
          * - content.htm -> content.en.htm
          */
         $locale = Translator::instance()->getLocale();
         $fileName = substr_replace($fileName, '.' . $locale, strrpos($fileName, '.'), 0);
         if (($content = Content::loadCached($controller->getTheme(), $fileName)) !== null) {
             return $content;
         }
     });
     /*
      * Import messages defined by the theme
      */
     Event::listen('cms.theme.setActiveTheme', function ($code) {
         try {
             (new ThemeScanner())->scanThemeConfigForMessages();
         } catch (Exception $ex) {
         }
     });
     /*
      * Prune localized content files from template list
      */
     Event::listen('pages.content.templateList', function ($widget, $templates) {
         return $this->pruneTranslatedContentTemplates($templates);
     });
 }
Example #8
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');
 }
Example #9
0
 /**
  * Renders a requested content file.
  * The framework uses this method internally.
  * @param string $name The content view to load.
  * @param array $parameters Parameter variables to pass to the view.
  * @return string
  */
 public function renderContent($name, $parameters = [])
 {
     /*
      * Extensibility
      */
     if (($event = $this->fireEvent('page.beforeRenderContent', [$name], true)) || ($event = Event::fire('cms.page.beforeRenderContent', [$this, $name], true))) {
         $content = $event;
     } elseif (($content = Content::loadCached($this->theme, $name)) === null) {
         throw new CmsException(Lang::get('cms::lang.content.not_found_name', ['name' => $name]));
     }
     $fileContent = $content->parsedMarkup;
     /*
      * Parse basic template variables
      */
     if (!empty($parameters)) {
         $fileContent = TextParser::parse($fileContent, $parameters);
     }
     /*
      * Extensibility
      */
     if (($event = $this->fireEvent('page.renderContent', [$name, $fileContent], true)) || ($event = Event::fire('cms.page.renderContent', [$this, $name, $fileContent], true))) {
         return $event;
     }
     return $fileContent;
 }
Example #10
0
 /**
  * Deletes the object from the disk.
  * Recursively deletes subpages. Returns a list of file names of deleted pages.
  * @return array
  */
 public function delete()
 {
     $result = [];
     /*
      * Delete subpages
      */
     foreach ($this->getChildren() as $subPage) {
         $result = array_merge($result, $subPage->delete());
     }
     /*
      * Remove from meta
      */
     $pageList = new PageList($this->theme);
     $pageList->removeSubtree($this);
     /*
      * Delete the object
      */
     $result = array_merge($result, [$this->getBaseFileName()]);
     parent::delete();
     return $result;
 }
Example #11
0
 /**
  * Renders a requested content file.
  * The framework uses this method internally.
  */
 public function renderContent($name)
 {
     /*
      * Extensibility
      */
     if ($event = $this->fireEvent('page.beforeRenderContent', [$name], true)) {
         $content = $event;
     } elseif ($event = Event::fire('cms.page.beforeRenderContent', [$this, $name], true)) {
         $content = $event;
     } elseif (($content = Content::loadCached($this->theme, $name)) === null) {
         throw new CmsException(Lang::get('cms::lang.content.not_found', ['name' => $name]));
     }
     $filePath = $content->getFullPath();
     $fileContent = File::get($filePath);
     if (strtolower(File::extension($filePath)) == 'md') {
         $fileContent = Markdown::parse($fileContent);
     }
     /*
      * Extensibility
      */
     if ($event = $this->fireEvent('page.renderContent', [$name, $fileContent], true)) {
         return $event;
     }
     if ($event = Event::fire('cms.page.renderContent', [$this, $name, $fileContent], true)) {
         return $event;
     }
     return $fileContent;
 }
 /**
  * Adds language suffixes to content files.
  * @return string|null
  */
 public function findTranslatedContentFile($controller, $fileName)
 {
     if (!strlen(File::extension($fileName))) {
         $fileName .= '.htm';
     }
     /*
      * Splice the active locale in to the filename
      * - content.htm -> content.en.htm
      */
     $locale = Translator::instance()->getLocale();
     $fileName = substr_replace($fileName, '.' . $locale, strrpos($fileName, '.'), 0);
     if (($content = Content::loadCached($controller->getTheme(), $fileName)) !== null) {
         return $content;
     }
 }
Example #13
0
 /**
  * Renders a requested content file.
  * The framework uses this method internally.
  */
 public function renderContent($name)
 {
     /*
      * Extensibility
      */
     if (($event = $this->fireEvent('page.beforeRenderContent', [$name], true)) || ($event = Event::fire('cms.page.beforeRenderContent', [$this, $name], true))) {
         $content = $event;
     } elseif (($content = Content::loadCached($this->theme, $name)) === null) {
         throw new CmsException(Lang::get('cms::lang.content.not_found_name', ['name' => $name]));
     }
     $fileContent = $content->parsedMarkup;
     /*
      * Extensibility
      */
     if (($event = $this->fireEvent('page.renderContent', [$name, $fileContent], true)) || ($event = Event::fire('cms.page.renderContent', [$this, $name, $fileContent], true))) {
         return $event;
     }
     return $fileContent;
 }
Example #14
0
 /**
  * Renders a requested content file.
  * The framework uses this method internally.
  */
 public function renderContent($name)
 {
     if (($content = Content::loadCached($this->theme, $name)) === null) {
         throw new CmsException(Lang::get('cms::lang.content.not_found', ['name' => $name]));
     }
     $filePath = $content->getFullPath();
     $fileContent = File::get($filePath);
     if (strtolower(File::extension($filePath)) == 'md') {
         $fileContent = Markdown::parse($fileContent);
     }
     return $fileContent;
 }