/**
  * Load the component data from component.yml file
  * 
  * @param \Cx\Core\View\Model\Entity\Theme $theme
  */
 public function loadComponentData(\Cx\Core\View\Model\Entity\Theme &$theme)
 {
     $websiteFilePath = \Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_COMPONENT_FILE;
     $codeBaseFilePath = \Env::get('cx')->getCodeBaseThemesPath() . '/' . $theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_COMPONENT_FILE;
     $filePath = file_exists($websiteFilePath) ? $websiteFilePath : (file_exists($codeBaseFilePath) ? $codeBaseFilePath : '');
     if ($filePath) {
         try {
             $objYaml = new \Symfony\Component\Yaml\Yaml();
             $objFile = new \Cx\Lib\FileSystem\File($filePath);
             $themeInformation = $objYaml->load($objFile->getData());
             $theme->setComponentData($themeInformation['DlcInfo']);
         } catch (\Exception $e) {
             \DBG::log($e->getMessage());
         }
     }
 }
 /**
  * Create zip install package for this component
  * @param string $path Path to store zip file at
  * @todo add data files (db)
  * @todo create meta.yml
  * @todo allow template files
  * @todo test $customized
  */
 public function pack($path, $customized = false)
 {
     $pathParts = explode('.', $path);
     if (empty($path) || end($pathParts) != 'zip') {
         throw new ReflectionComponentException('Invalid file name passed. Provide a valid zip file name');
     }
     $websitePath = \Env::get('cx')->getWebsiteDocumentRootPath();
     // Create temp working folder and copy ZIP contents
     $filesystem = new \Cx\Lib\FileSystem\FileSystem();
     // clean up tmp dir
     $filesystem->delete_folder(ASCMS_APP_CACHE_FOLDER, true);
     echo "Copying files ... ";
     $filesystem->make_folder(ASCMS_APP_CACHE_FOLDER . '/DLC_FILES' . SystemComponent::getPathForType($this->componentType), true);
     $cacheComponentFolderPath = ASCMS_APP_CACHE_FOLDER . '/DLC_FILES' . SystemComponent::getPathForType($this->componentType) . '/' . $this->componentName;
     $cacheComponentFolderWebPath = ASCMS_APP_CACHE_FOLDER_WEB_PATH . '/DLC_FILES' . SystemComponent::getPathForType($this->componentType) . '/' . $this->componentName;
     $filesystem->copyDir($this->getDirectory(false), preg_replace('#' . $websitePath . '#', '', $this->getDirectory(false)), '', $cacheComponentFolderPath, $cacheComponentFolderWebPath, '', true);
     echo "Done \n";
     if ($customized) {
         // overwrite with contents of $this->getDirectory(true, true)
         echo "Copying customizing files ... ";
         $filesystem->copyDir($this->getDirectory(true, true), preg_replace('#' . $websitePath . '#', '', $this->getDirectory(true, true)), '', $cacheComponentFolderPath, $cacheComponentFolderWebPath, '', true);
         echo "Done \n";
     }
     echo "Writing component data (structure & data) ... ";
     $this->writeDatabaseStructureAndData();
     echo "Done \n";
     $componentFolder = $this->getDirectory($customized);
     if (!file_exists($componentFolder . '/meta.yml')) {
         echo "Meta file not exist. \n";
         echo "Creating meta file ... ";
         // Create meta.yml
         $this->writeMetaDataToFile($cacheComponentFolderPath . '/meta.yml');
         echo "Done \n";
     } else {
         echo "Copying additional files ...";
         // Read meta file
         $yaml = new \Symfony\Component\Yaml\Yaml();
         $content = file_get_contents($componentFolder . '/meta.yml');
         $meta = $yaml->load($content);
         if (isset($meta['DlcInfo']['additionalFiles'])) {
             foreach ($meta['DlcInfo']['additionalFiles'] as $additionalFile) {
                 $srcPath = $websitePath . '/' . $additionalFile;
                 if ($filesystem->exists($srcPath)) {
                     if (is_dir($srcPath)) {
                         $filesystem->copyDir($srcPath, preg_replace('#' . $websitePath . '#', '', $srcPath), '', ASCMS_APP_CACHE_FOLDER . '/DLC_FILES/' . $additionalFile, ASCMS_APP_CACHE_FOLDER_WEB_PATH . '/DLC_FILES/' . $additionalFile, '', true);
                     } else {
                         $folder = dirname($srcPath);
                         $folderPath = preg_replace('#' . $websitePath . '#', '', $folder);
                         $filesystem->make_folder(ASCMS_APP_CACHE_FOLDER . '/DLC_FILES' . $folderPath, true);
                         $filesystem->copy_file($srcPath, ASCMS_APP_CACHE_FOLDER . '/DLC_FILES/' . $additionalFile);
                     }
                 } else {
                     echo "WARNING: File missing - " . $additionalFile;
                 }
             }
         }
         echo "Done \n";
     }
     $filesystem->copy_file($cacheComponentFolderPath . '/meta.yml', ASCMS_APP_CACHE_FOLDER . '/meta.yml');
     $filesystem->copy_file($websitePath . '/core/Core/Data/README.txt', ASCMS_APP_CACHE_FOLDER . '/README.txt');
     echo "Exporting component ... ";
     // Compress
     $file = new \PclZip($path);
     $file->create(ASCMS_APP_CACHE_FOLDER, PCLZIP_OPT_REMOVE_PATH, ASCMS_APP_CACHE_FOLDER);
     echo "Done \n";
 }
 /**
  * Get update websiteDetailsFromYml
  * 
  * @param string $file yml file name
  * 
  * @return array website details
  */
 public function getUpdateWebsiteDetailsFromYml($file)
 {
     if (!file_exists($file)) {
         return;
     }
     $objFile = new \Cx\Lib\FileSystem\File($file);
     $yaml = new \Symfony\Component\Yaml\Yaml();
     return $yaml->load($objFile->getData());
 }
Example #4
0
 /**
  * import themes from archive
  * @access   private
  * @param    string   $themes
  */
 private function importFile()
 {
     global $_ARRAYLANG;
     $this->_cleantmp();
     switch ($_GET['import']) {
         case 'remote':
             $archiveFile = $this->_fetchRemoteFile($_POST['importremote']);
             if ($archiveFile === false) {
                 return false;
             }
             $archive = new \PclZip($archiveFile);
             //no break
         //no break
         case 'local':
             if (empty($archive)) {
                 if (($archiveFile = $this->checkUpload()) === false) {
                     return false;
                 }
                 $archive = new \PclZip($this->_archiveTempPath . $archiveFile);
             }
             $content = $archive->listContent();
             $themeName = '';
             $themeDirectory = '';
             $themeDirectoryFromArchive = '';
             $arrDirectories = array();
             // analyze theme archive
             if (!$this->validateArchiveStructure($content, $themeDirectory, $themeDirectoryFromArchive, $themeName, $arrDirectories, $archiveFile)) {
                 return false;
             }
             // prepare directory structure of new theme
             if (!$this->createDirectoryStructure($themeDirectory, $arrDirectories)) {
                 return false;
             }
             // try to get the theme name from yml
             $themeInfoContent = $archive->extract(PCLZIP_OPT_BY_NAME, $themeDirectoryFromArchive . \Cx\Core\View\Model\Entity\Theme::THEME_COMPONENT_FILE, PCLZIP_OPT_EXTRACT_AS_STRING);
             if (!empty($themeInfoContent)) {
                 $yaml = new \Symfony\Component\Yaml\Yaml();
                 $themeInfo = $yaml->load($themeInfoContent[0]['content']);
                 $themeName = isset($themeInfo['DlcInfo']['name']) ? $themeInfo['DlcInfo']['name'] : $themeName;
             }
             //create database entry
             $this->validateThemeName($themeName);
             $theme = new \Cx\Core\View\Model\Entity\Theme();
             $theme->setThemesname($themeName);
             $theme->setFoldername($themeDirectory);
             //extract archive files
             $this->extractArchive($archive, $theme, $themeDirectoryFromArchive);
             $this->replaceThemeName($themeDirectoryFromArchive, $themeDirectory, $this->websiteThemesPath . $arrDirectories[0]);
             $this->insertSkinIntoDb($theme);
             \Message::add(contrexx_raw2xhtml($themeName) . ' (' . $themeDirectory . ') ' . $_ARRAYLANG['TXT_THEME_SUCCESSFULLY_IMPORTED']);
             break;
         case 'filesystem':
             $themeName = null;
             $existingThemeInFilesystem = !empty($_POST['existingdirName']) ? contrexx_input2raw($_POST['existingdirName']) : null;
             $themePath = file_exists(\Env::get('cx')->getWebsiteThemesPath() . '/' . $existingThemeInFilesystem) ? \Env::get('cx')->getWebsiteThemesPath() . '/' . $existingThemeInFilesystem : \Env::get('cx')->getCodeBaseThemesPath() . '/' . $existingThemeInFilesystem;
             if (!file_exists($themePath)) {
                 \Message::add($_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_EMPTY_PARAMS'], \Message::CLASS_ERROR);
                 return false;
             }
             $yamlFile = file_exists(\Env::get('cx')->getWebsiteThemesPath() . '/' . $existingThemeInFilesystem . '/component.yml') ? \Env::get('cx')->getWebsiteThemesPath() . '/' . $existingThemeInFilesystem . '/component.yml' : (file_exists(\Env::get('cx')->getCodeBaseThemesPath() . '/' . $existingThemeInFilesystem . '/component.yml') ? \Env::get('cx')->getCodeBaseThemesPath() . '/' . $existingThemeInFilesystem . '/component.yml' : '');
             if ($yamlFile) {
                 $objFile = new \Cx\Lib\FileSystem\File($yamlFile);
                 $yaml = new \Symfony\Component\Yaml\Yaml();
                 $themeInformation = $yaml->load($objFile->getData());
                 $themeName = $themeInformation['DlcInfo']['name'];
             }
             $themeName = $themeName ?: $existingThemeInFilesystem;
             if (empty($themeName) || empty($existingThemeInFilesystem)) {
                 \Message::add($_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_EMPTY_PARAMS'], \Message::CLASS_ERROR);
                 return false;
             }
             $this->validateThemeName($themeName);
             $theme = new \Cx\Core\View\Model\Entity\Theme();
             $theme->setThemesname($themeName);
             $theme->setFoldername($existingThemeInFilesystem);
             if ($this->insertSkinIntoDb($theme)) {
                 \Message::add(contrexx_raw2xhtml($themeName) . ' ' . $_ARRAYLANG['TXT_STATUS_SUCCESSFULLY_CREATE']);
             }
             break;
         default:
             //everything else should never be the case
             \Message::add("GET Request Error. 'import' should be either 'local' or 'remote'", \Message::CLASS_ERROR);
             return false;
             break;
     }
     // Theme build successfully
     \Cx\Core\Csrf\Controller\Csrf::redirect('index.php?cmd=ViewManager&act=templates&themes=' . $theme->getFoldername());
 }