Esempio n. 1
0
 /**
  * @param Theme $theme
  * @param       $data
  */
 public function __construct($theme, $data)
 {
     $this->name = $theme->getFoldername();
     $this->data = $data;
     $this->theme = $theme;
     $presetStorage = new \Cx\Core_Modules\TemplateEditor\Model\PresetFileStorage($this->cx->getWebsiteThemesPath() . '/' . $theme->getFoldername());
     $this->presetRepository = new PresetRepository($presetStorage);
     if (!isset($data['activePreset'])) {
         $data['activePreset'] = 'Default';
     }
     $activePreset = $data['activePreset'];
     try {
         $this->activePreset = $this->presetRepository->getByName($activePreset);
     } catch (PresetRepositoryException $e) {
         $this->activePreset = $this->presetRepository->getByName('Default');
     } catch (ParserException $e) {
         $this->activePreset = $this->presetRepository->getByName('Default');
     }
     $this->applyPreset($this->activePreset);
 }
 /**
  * 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);
 }