/**
  * 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) {
     }
 }
Пример #2
0
 /**
  * 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) {
     }
 }
 /**
  * Creates the main overview for this component.
  *
  * @param $template
  *
  * @throws \Cx\Core\Routing\UrlException
  */
 public function showOverview(Sigma $template)
 {
     global $_ARRAYLANG, $_CONFIG;
     \JS::registerJS('core_modules/TemplateEditor/View/Script/spectrum.js');
     \JS::activate('intro.js');
     $template->loadTemplateFile($this->cx->getCodeBaseCoreModulePath() . '/TemplateEditor/View/Template/Backend/Default.html');
     /**
      * @var $themes Theme[]
      */
     $themes = $this->themeRepository->findAll();
     foreach ($themes as $theme) {
         $template->setVariable(array('TEMPLATEEDITOR_LAYOUT_NAME' => $theme->getThemesname(), 'TEMPLATEEDITOR_LAYOUT_ID' => $theme->getId()));
         if ($this->theme->getId() == $theme->getId()) {
             $template->setVariable(array('TEMPLATEEDITOR_LAYOUT_ACTIVE' => 'selected'));
         }
         $template->parse('layouts');
     }
     if ($this->themeOptions) {
         $presets = $this->themeOptions->getPresetRepository()->findAll();
         foreach ($presets as $preset) {
             $template->setVariable(array('TEMPLATEEDITOR_PRESET_NAME' => $this->themeOptions->getActivePreset()->getName() == $preset ? $preset . ' (' . $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_PRESET_ACTIVE'] . ')' : $preset, 'TEMPLATEEDITOR_PRESET_ID' => $preset));
             if ($_SESSION['TemplateEditor'][$this->theme->getId()]['activePreset'] == $preset) {
                 $template->setVariable(array('TEMPLATEEDITOR_PRESET_ACTIVE' => 'selected'));
             }
             $template->parse('presets');
         }
         if ($_SESSION['TemplateEditor'][$this->theme->getId()]['activePreset'] == $this->themeOptions->getActivePreset()->getName()) {
             $template->setVariable(array('TEMPLATEDITOR_PRESET_IS_ALREADY_ACTIVE' => 'disabled'));
             $template->setVariable(array('TXT_CORE_MODULE_TEMPLATEEDITOR_REMOVE_PRESET_TEXT_IS_ACTIVE' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_REMOVE_PRESET_TEXT_IS_ACTIVE']));
             $template->show('presetTextActive');
         }
         if ($_SESSION['TemplateEditor'][$this->theme->getId()]['activePreset'] == 'Default') {
             $template->setVariable(array('TEMPLATEDITOR_PRESET_IS_DEFAULT' => 'disabled'));
         }
         foreach ($presets as $preset) {
             $template->setVariable(array('TEMPLATEEDITOR_PRESET_FOR_PRESETS_NAME' => $preset, 'TEMPLATEEDITOR_PRESET_FOR_PRESETS_ID' => $preset));
             $template->parse('presetsForPresets');
         }
         $this->themeOptions->renderOptions($template);
         if ($this->themeOptions->getOptionCount() != 0) {
             $template->parse('presetBlock');
             $template->setVariable('TXT_CORE_MODULE_TEMPLATEEDITOR_SAVE', $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_SAVE']);
             $template->parse('save_button');
         }
     } else {
         $template->setVariable(array('TEMPLATEOPTION_NO_OPTIONS_TEXT' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_NO_OPTIONS_HELP'], 'TEMPLATEOPTION_NO_OPTIONS_LINKNAME' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_NO_OPTIONS_LINKNAME']));
         $template->parse('no_options');
     }
     $template->setVariable(array('TEMPLATEEDITOR_IFRAME_URL' => Url::fromModuleAndCmd('home', '', null, array('preview' => $this->theme->getId(), 'templateEditor' => 1)), 'TEMPLATEEDITOR_BACKURL' => './index.php?cmd=ViewManager'));
     $template->setGlobalVariable($_ARRAYLANG);
     \ContrexxJavascript::getInstance()->setVariable(array('newPresetTemplate' => '', 'TXT_CORE_MODULE_TEMPLATEEDITOR_SAVE' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_SAVE'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_CANCEL' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_CANCEL'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_SAVE_CONTENT' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_SAVE_CONTENT'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_SAVE_TITLE' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_SAVE_TITLE'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_YES' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_YES'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_NO' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_NO'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_ADD_PRESET' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_ADD_PRESET'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_REMOVE_PRESET_TEXT' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_REMOVE_PRESET_TEXT'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_ACTIVATE_PRESET_TITLE' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_ACTIVATE_PRESET_TITLE'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_ADD_PRESET_TITLE' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_ADD_PRESET_TITLE'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_LAYOUT_OPTION' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_LAYOUT_OPTION'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_PRESET_OPTION' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_PRESET_OPTION'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_PRESET_ACTIVATE' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_PRESET_ACTIVATE'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_PRESET_ADD' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_PRESET_ADD'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_PRESET_RESET' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_PRESET_RESET'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_VIEW_OPTION' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_VIEW_OPTION'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_VIEW_OPTION_LIST' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_VIEW_OPTION_LIST'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_PREVIEW' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_PREVIEW'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_SAVE' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_SAVE'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_NEXT' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_NEXT'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_BACK' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_BACK'], 'TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_STOP' => $_ARRAYLANG['TXT_CORE_MODULE_TEMPLATEEDITOR_INTRO_STOP'], 'themeid' => $this->theme->getId(), 'iframeUrl' => Url::fromModuleAndCmd('home', '', null, array('preview' => $this->theme->getId(), 'templateEditor' => 1))->toString(), 'domainUrl' => $_CONFIG['domainUrl']), 'TemplateEditor');
 }
Пример #4
0
 /**
  * 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);
 }