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); } }); }
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); }); }
public function onRender() { $this->file = $this->property('file'); $this->fileMode = File::extension($this->property('file')); /* * Compatability with RainLab.Translate */ if (class_exists('\\RainLab\\Translate\\Classes\\Translator')) { $locale = \RainLab\Translate\Classes\Translator::instance()->getLocale(); $fileName = substr_replace($this->file, '.' . $locale, strrpos($this->file, '.'), 0); if (($content = Content::loadCached($this->page->controller->getTheme(), $fileName)) !== null) { $this->file = $fileName; } } if (!$this->isEditor) { return $this->renderContent($this->file); } $this->content = $this->renderContent($this->file); }
/** * 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; }
/** * 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; } }
/** * 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; }
/** * 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; }