/** * 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); }
/** * Generate a component.yml for one theme available on the system * * @param \Cx\Core\View\Model\Entity\Theme $theme */ public function convertThemeToComponent(\Cx\Core\View\Model\Entity\Theme $theme) { if ($theme->getComponentData()) { return; } $themePath = \Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername(); $infoFile = null; $themeInformation = array('DlcInfo' => array()); if (file_exists($themePath . '/info.xml')) { try { // check for old info file $infoFile = new \Cx\Lib\FileSystem\File($themePath . '/info.xml'); $this->xmlParseFile($infoFile); $themeInformation['DlcInfo'] = array('name' => $theme->getThemesname(), 'description' => $this->xmlDocument['THEME']['DESCRIPTION']['cdata'], 'type' => 'template', 'publisher' => $this->xmlDocument['THEME']['AUTHORS']['AUTHOR']['USER']['cdata'], 'subtype' => null, 'versions' => array('state' => 'stable', 'number' => $this->xmlDocument['THEME']['VERSION']['cdata'], 'releaseDate' => '')); unset($this->xmlDocument); } catch (\Exception $e) { // not critical, ignore } } else { // create new data for new component.yml file $themeInformation['DlcInfo'] = array('name' => $theme->getThemesname(), 'description' => '', 'type' => 'template', 'publisher' => 'Cloudrexx AG', 'subtype' => null, 'versions' => array('state' => 'stable', 'number' => '1.0.0', 'releaseDate' => '')); } // Add default dependencies $themeInformation['DlcInfo']['dependencies'] = array(array('name' => 'jquery', 'type' => 'lib', 'minimumVersionNumber' => '1.6.1', 'maximumVersionNumber' => '1.6.1')); // write components yaml $theme->setComponentData($themeInformation['DlcInfo']); try { $this->saveComponentData($theme); } catch (\Exception $e) { // could not write new component.yml file, try next time throw new $e(); } if ($infoFile) { try { // delete existing info.xml file $infoFile->delete(); } catch (\Exception $e) { // not critical, ignore } } }
/** * @param Theme $theme * * @return OptionSet */ public function get(Theme $theme) { $componentData = $this->storage->retrieve($theme->getFoldername()); return new OptionSet($theme, $componentData); }
/** * Create default theme files * * \Cx\Core\View\Model\Entity\Theme $theme */ private function createDefaultFiles(\Cx\Core\View\Model\Entity\Theme $theme) { global $_ARRAYLANG; foreach ($this->directories as $dir) { if (!\Cx\Lib\FileSystem\FileSystem::make_folder($this->path . $theme->getFoldername() . '/' . $dir)) { \Message::add(sprintf($_ARRAYLANG['TXT_UNABLE_TO_CREATE_FILE'], contrexx_raw2xhtml($theme->getFoldername() . '/' . $dir)), \Message::CLASS_ERROR); return false; } } //copy "not available" preview.gif as default preview image $previewImage = $this->path . $theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_PREVIEW_FILE; if (!file_exists($previewImage)) { try { $objFile = new \Cx\Lib\FileSystem\File(\Env::get('cx')->getCodeBaseDocumentRootPath() . \Cx\Core\View\Model\Entity\Theme::THEME_DEFAULT_PREVIEW_FILE); $objFile->copy($previewImage); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); \Message::add(sprintf($_ARRAYLANG['TXT_UNABLE_TO_CREATE_FILE'], contrexx_raw2xhtml($theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_PREVIEW_FILE)), \Message::CLASS_ERROR); return false; } } foreach ($this->filenames as $file) { // skip component.yml, will be created later if ($file == 'component.yml') { continue; } $filePath = $this->path . $theme->getFoldername() . '/' . $file; if (!file_exists($filePath)) { try { $objFile = new \Cx\Lib\FileSystem\File($filePath); $objFile->touch(); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); \Message::add(sprintf($_ARRAYLANG['TXT_UNABLE_TO_CREATE_FILE'], contrexx_raw2xhtml($theme->getFoldername() . '/' . $file)), \Message::CLASS_ERROR); return false; } } } // write component.yml file // this line will create a default component.yml file try { $this->themeRepository->loadComponentData($theme); $this->themeRepository->convertThemeToComponent($theme); } catch (\Exception $e) { \DBG::msg($e->getMessage()); \Message::add($_ARRAYLANG['TXT_UNABLE_TO_CONVERT_THEME_TO_COMPONENT'], \Message::CLASS_ERROR); } return true; }
/** * @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); }