function generateArchive($themeName, $userThemeName = '', $includeThemler = true)
{
    register_shutdown_function('fatalErrorShutdownHandler');
    $themeDir = FilesHelper::normalizePath(getThemeDir($themeName));
    if (!file_exists($themeDir)) {
        die('Error : No Theme Folder');
    }
    $userThemeName = $userThemeName ? $userThemeName : $themeName;
    $uniqid = uniqid();
    $base_upload_dir = get_base_upload_dir() . '/' . $uniqid;
    $user_template_dir = $base_upload_dir . '/' . $userThemeName;
    FilesHelper::copyRecursive($themeDir, $user_template_dir);
    if (!$includeThemler) {
        $dirs = array('export', 'project');
        clearDirs($user_template_dir, $dirs);
    }
    $previewThemeDir = FilesHelper::normalizePath(getThemeDir($themeName . _PREVIEW_SUFFIX_));
    $archiveName = 'theme_' . uniqid(time()) . '.zip';
    $archiveFile = $base_upload_dir . '/' . $archiveName;
    $archive = new PclZip($archiveFile);
    add_version_folders($archive, $base_upload_dir, $user_template_dir, $previewThemeDir, $userThemeName, $includeThemler);
    add_files_to_archive_root($archive, $base_upload_dir, $user_template_dir, $previewThemeDir, $userThemeName);
    // Temporary fix to support Prestashop Cloud Install
    deleteFromArchive($archive, 'modules/designer/override/controllers/admin/AdminLoginController.php');
    if (is_readable($archiveFile)) {
        $archiveContent = array('ext' => 'zip', 'content' => base64_encode(FilesHelper::readFile($archiveFile)));
        FilesHelper::removeDir($base_upload_dir, true);
        return $archiveContent;
    }
    die('Archive file: ' . $archiveFile . ' is not readable');
}
function getThemeArchive($themeName, $userThemeName, $includeThemler)
{
    $themeDir = FilesHelper::normalizePath(getThemeDir($themeName));
    if (!file_exists($themeDir)) {
        die('Error : No Theme Folder');
    }
    $userThemeName = $userThemeName ? $userThemeName : $themeName;
    $base_upload_dir = get_base_upload_dir();
    $user_template_dir = $base_upload_dir . '/' . $userThemeName;
    FilesHelper::copyRecursive($themeDir, $user_template_dir);
    if (!$includeThemler) {
        $dirs = array('export', 'project');
        clearDirs($user_template_dir, $dirs);
    }
    $previewThemeDir = FilesHelper::normalizePath(getThemeDir($themeName . _PREVIEW_SUFFIX_));
    $archive_name = 'theme_' . uniqid(time()) . '.zip';
    $archive_file = $base_upload_dir . '/' . $archive_name;
    $archive = new PclZip($archive_file);
    add_version_folders($archive, $base_upload_dir, $user_template_dir, $previewThemeDir, $userThemeName, $includeThemler);
    add_files_to_archive_root($archive, $base_upload_dir, $user_template_dir, $previewThemeDir, $userThemeName);
    // Temporary fix to support Prestashop Cloud Install
    deleteFromArchive($archive, 'modules/designer/override/controllers/admin/AdminLoginController.php');
    FilesHelper::removeDir($user_template_dir, true);
    return $archive_file;
}
function unZip($themeName, $filename, $tmp_path)
{
    $base_upload_dir = get_base_upload_dir();
    $archive_file = $base_upload_dir . '/' . $filename . '.tmp';
    $tmp_dir = $base_upload_dir . '/zip-data.tmp';
    FilesHelper::emptyDirRecursive($tmp_dir);
    $archive = new PclZip($archive_file);
    if (0 == $archive->extract(PCLZIP_OPT_PATH, $tmp_dir)) {
        return array('status' => 'error', 'message' => "<p><b>Invalid zip</b></p>Extract error : " . $archive->errorInfo(true));
    }
    $fso = FilesHelper::generateFso($tmp_dir);
    FilesHelper::deleteFile($archive_file);
    FilesHelper::emptyDirRecursive($tmp_dir);
    return array('status' => 'done', 'fso' => $fso);
}
 public function zipFso($data)
 {
     $base_upload_dir = get_base_upload_dir();
     $tmp_dir = $base_upload_dir . '/zip-data.tmp';
     $zip_file = $base_upload_dir . '/zip-data.zip';
     FilesHelper::emptyDirRecursive($tmp_dir);
     $changed_files = array();
     $replace_data = array();
     $this->_fillThemeStorage($data['fso'], $changed_files, $replace_data, false, $tmp_dir);
     $archive = new PclZip($zip_file);
     if (0 == $archive->create($tmp_dir, PCLZIP_OPT_REMOVE_PATH, $tmp_dir)) {
         throw new Exception("Extract error : " . $archive->errorInfo(true));
     }
     $result = array('result' => 'done', 'data' => base64_encode(FilesHelper::readFile($zip_file)));
     FilesHelper::emptyDirRecursive($tmp_dir);
     FilesHelper::deleteFile($zip_file);
     return $result;
 }