function add_version_folders(&$archive, $base_upload_dir, $user_template_dir, $preview_template_folder, $userThemeName, $includeThemler)
{
    $preview_files = array();
    foreach (get_support_versions() as $version) {
        $preview_files[$version] = FilesHelper::enumerateFiles($preview_template_folder . '/' . $version);
    }
    $preview_name = $userThemeName . _PREVIEW_SUFFIX_;
    $version_folders = get_support_versions_folder($user_template_dir);
    $cms_version = get_cms_version();
    $dirs = array('themes', 'modules');
    $modules = array('designerpreview', 'blocktopmenu_mod');
    if ($includeThemler) {
        $modules[] = 'designer';
    }
    foreach ($version_folders as $version => $folder) {
        $root = $base_upload_dir . (strpos($cms_version, $version) !== false ? '' : '/' . $version);
        foreach ($dirs as $name) {
            $dir = $root . '/' . $name;
            $arch_dirs[$name] = $dir;
            FilesHelper::createDir($dir);
        }
        FilesHelper::copyRecursive($user_template_dir, $arch_dirs['themes'] . '/' . $userThemeName);
        foreach ($modules as $module) {
            FilesHelper::copyRecursive(_PS_MODULE_DIR_ . $module, $arch_dirs['modules'] . '/' . $module);
        }
        // current version files in preview folder doesn't need to be copied
        if (strpos($cms_version, $version) !== false) {
            continue;
        }
        $files = $preview_files[$version];
        $pattern = '/(.*?\\/themes\\/' . $preview_name . '\\/' . $version . '\\/)(.*?)/si';
        foreach ($files as $file) {
            $path = $file['path'];
            $isThemler = strpos($path, 'designer/');
            if ($isThemler && !$includeThemler) {
                continue;
            }
            $isModule = $isThemler || strpos($path, 'designerpreview/') || strpos($path, 'blocktopmenu_mod/');
            $to_replace = ($isModule ? $arch_dirs['modules'] : $arch_dirs['themes'] . '/' . $userThemeName) . '/$2';
            $r_path = preg_replace($pattern, $to_replace, $path);
            $r_path = FilesHelper::normalizePath($r_path);
            FilesHelper::writeFile($r_path, $file['content']);
        }
        // add version folder as root folder to archive file
        addToArchive($archive, $root, $base_upload_dir);
        FilesHelper::removeDir($root, true);
    }
    if ($includeThemler) {
        $inner_preview_dir = $base_upload_dir . '/themes/' . $userThemeName . '/' . $userThemeName . _PREVIEW_SUFFIX_;
        FilesHelper::copyRecursive($preview_template_folder, $inner_preview_dir);
    }
    foreach ($dirs as $dir) {
        addToArchive($archive, $base_upload_dir . '/' . $dir, $base_upload_dir);
    }
    clearDirs($base_upload_dir, $dirs);
    return;
}
function correct_version_path($path)
{
    $support_versions = get_support_versions();
    $cms_version = get_cms_version();
    foreach ($support_versions as $version) {
        if (strpos($path, $version) !== false) {
            // has version in path
            if (strpos($cms_version, $version) !== false) {
                // current version CMS control export with and without version folder
                return array($path, str_replace($version, '', $path));
            }
            return array($path);
            // ohterwise export to version folder
        }
    }
    return array($path);
    // export common control file as usual
}
 private function _saveThumbnails($thumbnails)
 {
     if (is_array($thumbnails)) {
         ProviderLog::start('_saveThumbnails');
         $cms_version = get_cms_version();
         foreach ($thumbnails as $thumbnail) {
             $name = $thumbnail['name'];
             $img = base64_decode(str_replace('data:image/jpeg;base64,', '', $thumbnail['data']));
             $version = '';
             if (isset($thumbnail['version'])) {
                 $version = $thumbnail['version'];
                 FilesHelper::writeFile($this->_previewThemeDir . '/' . $version . '/' . $name, $img);
             }
             if (empty($version) || strpos($cms_version, $version) !== false) {
                 FilesHelper::writeFile($this->_themeDir . '/' . $name, $img);
                 FilesHelper::writeFile($this->_previewThemeDir . '/' . $name, $img);
             }
         }
         ProviderLog::end('_saveThumbnails');
     }
 }