/** * Do something before main template gets parsed * * This creates the frontend placeholders for the preview and the normal view. * * USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! * CALCULATE YOUR STUFF AS LATE AS POSSIBLE * * @param \Cx\Core\Html\Sigma $template The main template */ public function preFinalize(\Cx\Core\Html\Sigma $template) { if ($this->cx->getMode() != Cx::MODE_FRONTEND) { return; } try { $fileStorage = new OptionSetFileStorage($this->cx->getWebsiteThemesPath()); $themeOptionRepository = new OptionSetRepository($fileStorage); $themeRepository = new ThemeRepository(); $themeID = isset($_GET['preview']) ? $_GET['preview'] : null; // load preview theme or page's custom theme $theme = $themeID ? $themeRepository->findById((int) $themeID) : $themeRepository->findById($this->cx->getPage()->getSkin()); // fallback: load default theme of active language if (!$theme) { $theme = $themeRepository->getDefaultTheme(\Cx\Core\View\Model\Entity\Theme::THEME_TYPE_WEB, FRONTEND_LANG_ID); } // final fallback: try to load any existing default theme (independent of the language) if (!$theme) { $theme = $themeRepository->getDefaultTheme(\Cx\Core\View\Model\Entity\Theme::THEME_TYPE_WEB); } $themeOptions = $themeOptionRepository->get($theme); if (isset($_GET['templateEditor'])) { $themeOptions->applyPreset($themeOptions->getPresetRepository()->getByName($_SESSION['TemplateEditor'][$themeID]['activePreset'])); } $themeOptions->renderTheme($template); } catch (PresetRepositoryException $e) { } catch (\Symfony\Component\Yaml\ParserException $e) { } }
/** * Do something before main template gets parsed * * This creates the frontend placeholders for the preview and the normal view. * * USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! * CALCULATE YOUR STUFF AS LATE AS POSSIBLE * * @param \Cx\Core\Html\Sigma $template The main template */ public function preFinalize(\Cx\Core\Html\Sigma $template) { if ($this->cx->getMode() != Cx::MODE_FRONTEND) { return; } try { $fileStorage = new OptionSetFileStorage($this->cx->getWebsiteThemesPath()); $themeOptionRepository = new OptionSetRepository($fileStorage); $themeRepository = new ThemeRepository(); $themeID = isset($_GET['preview']) ? $_GET['preview'] : null; $theme = $themeID ? $themeRepository->findById((int) $themeID) : $themeRepository->getDefaultTheme(); $themeOptions = $themeOptionRepository->get($theme); if (isset($_GET['templateEditor'])) { $themeOptions->applyPreset($themeOptions->getPresetRepository()->getByName($_SESSION['TemplateEditor'][$themeID]['activePreset'])); } $themeOptions->renderTheme($template); } catch (PresetRepositoryException $e) { } catch (\Symfony\Component\Yaml\ParserException $e) { } }
/** * This renders the backend overview. * * @param \Cx\Core\Html\Sigma $template Template for current CMD * @param array $cmd CMD separated by slashes */ public function parsePage(\Cx\Core\Html\Sigma $template, array $cmd) { \Permission::checkAccess(47, 'static'); $fileStorage = new OptionSetFileStorage($this->cx->getWebsiteThemesPath()); $themeOptionRepository = new OptionSetRepository($fileStorage); $this->themeOptionRepository = $themeOptionRepository; $this->themeRepository = new ThemeRepository(); $themeID = isset($_GET['tid']) ? $_GET['tid'] : 1; $this->theme = $this->themeRepository->findById($themeID); if (!$_SESSION['TemplateEditor']) { $_SESSION['TemplateEditor'] = array(); } if (!$_SESSION['TemplateEditor'][$this->theme->getId()]) { $_SESSION['TemplateEditor'][$this->theme->getId()] = array(); } if (isset($_GET['preset']) && Preset::isValidPresetName($_GET['preset'])) { if ($_SESSION['TemplateEditor'][$this->theme->getId()]['activePreset'] != $_GET['preset']) { // If the preset has changed remove all saved options $_SESSION['TemplateEditor'][$this->theme->getId()] = array(); } $_SESSION['TemplateEditor'][$this->theme->getId()]['activePreset'] = isset($_GET['preset']) ? $_GET['preset'] : 'Default'; } $this->presetRepository = new PresetRepository(new PresetFileStorage($this->cx->getWebsiteThemesPath() . '/' . $this->theme->getFoldername())); try { $this->themeOptions = $this->themeOptionRepository->get($this->theme); // If user opens editor use active preset as active preset. if (!isset($_SESSION['TemplateEditor'][$this->theme->getId()]['activePreset']) || !isset($_GET['preset'])) { $_SESSION['TemplateEditor'][$this->theme->getId()]['activePreset'] = $this->themeOptions->getActivePreset()->getName(); } try { $this->themeOptions->applyPreset($this->presetRepository->getByName($_SESSION['TemplateEditor'][$this->theme->getId()]['activePreset'])); } catch (PresetRepositoryException $e) { // If something fails fallback to the default preset. $_SESSION['TemplateEditor'][$this->theme->getId()]['activePreset'] = 'Default'; $this->themeOptions->applyPreset($this->presetRepository->getByName('Default')); } } catch (\Symfony\Component\Yaml\ParserException $e) { } $this->showOverview($template); }
/** * Remove a preset * * @param array $params List of get and post parameters which were sent to * the json adapter. */ public function removePreset($params) { global $_ARRAYLANG; \Env::get('init')->loadLanguageData('TemplateEditor'); if (!Preset::isValidPresetName($params['post']['preset'])) { return; } $presetName = $params['post']['preset']; /** * Default shouldn't be deletable */ if ($presetName == 'Default') { throw new \LogicException($_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_REMOVE_PRESET_DEFAULT_WARNING']); } $themeID = isset($params['post']['tid']) ? intval($params['post']['tid']) : 1; $themeRepository = new ThemeRepository(); $theme = $themeRepository->findById($themeID); $fileStorage = new OptionSetFileStorage($this->cx->getWebsiteThemesPath()); $themeOptionRepository = new OptionSetRepository($fileStorage); $themeOptions = $themeOptionRepository->get($theme); $preset = $themeOptions->getPresetRepository()->getByName($presetName); if ($themeOptions->getActivePreset()->getName() == $preset->getName()) { $themeOptions->setActivePreset($themeOptions->getPresetRepository()->getByName('Default')); $themeOptionRepository->save($themeOptions); } $themeOptions->getPresetRepository()->remove($preset); }