Exemple #1
0
 /**
  * Apply a preset
  *
  * @param Preset $preset
  */
 public function applyPreset(Preset $preset)
 {
     $this->appliedPreset = $preset;
     /* Saving data so later on we can reuse it
        without worrying about older applied presets */
     $data = $this->data;
     foreach ($data['options'] as &$emptyOption) {
         if ($presetOption = $preset->getOption($emptyOption['name'])) {
             if (!is_array($emptyOption['specific'])) {
                 $emptyOption['specific'] = array();
             }
             $emptyOption['specific'] = array_merge($emptyOption['specific'], $presetOption->getValue());
         }
     }
     //        $this->options = array();
     foreach ($data['options'] as $option) {
         $optionReflection = new \ReflectionClass($option['type']);
         if ($optionReflection->isSubclassOf('Cx\\Core_Modules\\TemplateEditor\\Model\\Entity\\Option')) {
             if ($this->cx->getMode() == Cx::MODE_BACKEND || $this->cx->getUser()->getFWUserObject()->objUser->login() && isset($_GET['templateEditor'])) {
                 if (isset($_SESSION['TemplateEditor'][$this->theme->getId()][$option['name']])) {
                     $option['specific'] = array_merge($option['specific'], $_SESSION['TemplateEditor'][$this->theme->getId()][$option['name']]->toArray());
                 }
             }
             $this->options[$option['name']] = $optionReflection->newInstance($option['name'], $option['translation'], $option['specific']);
         }
     }
 }
 /**
  * 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');
 }
 /**
  * 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
         }
     }
 }
 /**
  * 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
  *
  * @return OptionSet
  */
 public function get(Theme $theme)
 {
     $componentData = $this->storage->retrieve($theme->getFoldername());
     return new OptionSet($theme, $componentData);
 }