Beispiel #1
0
 /**
  * create skin folder
  * @access   public
  */
 private function createdir()
 {
     global $_ARRAYLANG;
     \Permission::checkAccess(47, 'static');
     $themeName = !empty($_POST['dbName']) && !stristr($_POST['dbName'], '..') ? contrexx_input2raw($_POST['dbName']) : null;
     $copyFromTheme = !empty($_POST['fromTheme']) && !stristr($_POST['fromTheme'], '..') ? contrexx_input2raw($_POST['fromTheme']) : null;
     $createFromDatabase = !empty($_POST['fromDB']) && !stristr($_POST['fromDB'], '..') ? contrexx_input2raw($_POST['fromDB']) : null;
     $dirName = !empty($_POST['dirName']) && !stristr($_POST['dirName'], '..') ? contrexx_input2raw($_POST['dirName']) : null;
     $dirName = \Cx\Lib\FileSystem\FileSystem::replaceCharacters($dirName);
     if (!$themeName) {
         $this->strErrMessage = $_ARRAYLANG['TXT_STATUS_CHECK_INPUTS'];
         $this->newdir();
         return;
     }
     $this->validateThemeName($themeName);
     if (!empty($dirName)) {
         // ensure that we're creating a new directory and not trying to overwrite an existing one
         $suffix = '';
         while (file_exists($this->path . $dirName . $suffix)) {
             $suffix++;
         }
         $dirName .= $suffix;
         $theme = new \Cx\Core\View\Model\Entity\Theme();
         $theme->setThemesname($themeName);
         $theme->setFoldername($dirName);
         switch (true) {
             case empty($copyFromTheme) && empty($createFromDatabase):
                 // Create new empty theme
                 if (\Cx\Lib\FileSystem\FileSystem::make_folder($this->path . $theme->getFoldername())) {
                     if ($this->createDefaultFiles($theme) && $this->insertSkinIntoDb($theme)) {
                         \Message::add(contrexx_raw2xhtml($themeName) . ' ' . $_ARRAYLANG['TXT_STATUS_SUCCESSFULLY_CREATE']);
                     } else {
                         \Message::add($_ARRAYLANG['TXT_MSG_ERROR_NEW_DIR'], \Message::CLASS_ERROR);
                         $this->newdir();
                         return;
                     }
                 }
                 break;
             case !empty($copyFromTheme) && empty($createFromDatabase):
                 //check Whether the folder exists in both codebase
                 if ($this->codeBaseThemesPath != $this->websiteThemesPath && file_exists($this->codeBaseThemesPath . $copyFromTheme)) {
                     if (!\Cx\Lib\FileSystem\FileSystem::copy_folder($this->codeBaseThemesPath . $copyFromTheme, $this->websiteThemesPath . $dirName, true)) {
                         \Message::add($_ARRAYLANG['TXT_MSG_ERROR_NEW_DIR'], \Message::CLASS_ERROR);
                         $this->newdir();
                         return;
                     }
                 }
                 //check Whether the folder exists in website data repository
                 if (file_exists($this->websiteThemesPath . $copyFromTheme)) {
                     if (!\Cx\Lib\FileSystem\FileSystem::copy_folder($this->websiteThemesPath . $copyFromTheme, $this->websiteThemesPath . $dirName, true)) {
                         \Message::add($_ARRAYLANG['TXT_MSG_ERROR_NEW_DIR'], \Message::CLASS_ERROR);
                         $this->newdir();
                         return;
                     }
                 }
                 $this->replaceThemeName($copyFromTheme, $dirName, $this->websiteThemesPath . $dirName);
                 //convert theme to component
                 try {
                     $this->themeRepository->loadComponentData($theme);
                     if (!$theme->isComponent()) {
                         // create a new one if no component.yml exists
                         try {
                             $this->themeRepository->convertThemeToComponent($theme);
                         } catch (\Exception $ex) {
                             \DBG::log($ex->getMessage());
                             \DBG::log($theme->getThemesname() . ' : Unable to convert theme to component');
                         }
                         $this->themeRepository->loadComponentData($theme);
                     }
                     // change the theme name in component data
                     $themeInformation = $theme->getComponentData();
                     if ($themeInformation) {
                         $themeInformation['name'] = $theme->getThemesname();
                         $theme->setComponentData($themeInformation);
                         $this->themeRepository->saveComponentData($theme);
                     }
                 } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                     \Message::add('Error in coverting component file', \Message::CLASS_ERROR);
                 }
                 if ($this->insertSkinIntoDb($theme)) {
                     \Message::add(contrexx_raw2xhtml($themeName) . ' ' . $_ARRAYLANG['TXT_STATUS_SUCCESSFULLY_CREATE']);
                 }
                 break;
             case empty($copyFromTheme) && !empty($createFromDatabase):
                 // TODO: remove this function -> migrate all pending themes in the update process
                 // Create new theme from database (migrate existing theme from database to filesystem)
                 if (\Cx\Lib\FileSystem\FileSystem::make_folder($this->path . $dirName)) {
                     $this->insertIntoDb($theme, $createFromDatabase);
                     $this->createFilesFromDB($dirName, intval($createFromDatabase));
                 }
                 break;
             default:
                 break;
         }
         // Theme build successfully
         \Cx\Core\Csrf\Controller\Csrf::redirect('index.php?cmd=ViewManager&act=templates&themes=' . $theme->getFoldername());
     } else {
         $this->strErrMessage = $_ARRAYLANG['TXT_STATUS_CHECK_INPUTS'];
         $this->newdir();
     }
 }