/** * copies the temporary unzip'd files to their final destination * removes unzip'd files from system if $uninstall=true * @param bool uninstall true if uninstalling a language pack * @return array sugar_config */ function commitLanguagePack($uninstall = false) { global $sugar_config; global $mod_strings; global $base_upgrade_dir; global $base_tmp_upgrade_dir; $errors = array(); $manifest = urldecode($_REQUEST['manifest']); $zipFile = urldecode($_REQUEST['zipFile']); $version = ""; $show_files = true; $unzip_dir = mk_temp_dir($base_tmp_upgrade_dir); $zip_from_dir = "."; $zip_to_dir = "."; $zip_force_copy = array(); if ($uninstall == false && isset($_SESSION['INSTALLED_LANG_PACKS']) && in_array($zipFile, $_SESSION['INSTALLED_LANG_PACKS'])) { return; } // unzip lang pack to temp dir if (isset($zipFile) && !empty($zipFile)) { if (is_file($zipFile)) { unzip($zipFile, $unzip_dir); } else { echo $mod_strings['ERR_LANG_MISSING_FILE'] . $zipFile; die; // no point going any further } } // filter for special to/from dir conditions (langpacks generally don't have them) if (isset($manifest) && !empty($manifest)) { if (is_file($manifest)) { include $manifest; if (isset($manifest['copy_files']['from_dir']) && $manifest['copy_files']['from_dir'] != "") { $zip_from_dir = $manifest['copy_files']['from_dir']; } if (isset($manifest['copy_files']['to_dir']) && $manifest['copy_files']['to_dir'] != "") { $zip_to_dir = $manifest['copy_files']['to_dir']; } if (isset($manifest['copy_files']['force_copy']) && $manifest['copy_files']['force_copy'] != "") { $zip_force_copy = $manifest['copy_files']['force_copy']; } if (isset($manifest['version'])) { $version = $manifest['version']; } } else { $errors[] = $mod_strings['ERR_LANG_MISSING_FILE'] . $manifest; } } // find name of language pack: find single file in include/language/xx_xx.lang.php $d = dir("{$unzip_dir}/{$zip_from_dir}/include/language"); while ($f = $d->read()) { if ($f == "." || $f == "..") { continue; } else { if (preg_match("/(.*)\\.lang\\.php\$/", $f, $match)) { $new_lang_name = $match[1]; } } } if ($new_lang_name == "") { die($mod_strings['ERR_LANG_NO_LANG_FILE'] . $zipFile); } $new_lang_desc = getLanguagePackName("{$unzip_dir}/{$zip_from_dir}/include/language/{$new_lang_name}.lang.php"); if ($new_lang_desc == "") { die("No language pack description found at include/language/{$new_lang_name}.lang.php inside {$install_file}."); } // add language to available languages $sugar_config['languages'][$new_lang_name] = $new_lang_desc; // get an array of all files to be moved $filesFrom = array(); $filesFrom = findAllFiles($unzip_dir, $filesFrom); /////////////////////////////////////////////////////////////////////////// //// FINALIZE if ($uninstall) { // unlink all pack files foreach ($filesFrom as $fileFrom) { //echo "deleting: ".getcwd().substr($fileFrom, strlen($unzip_dir), strlen($fileFrom))."<br>"; @unlink(getcwd() . substr($fileFrom, strlen($unzip_dir), strlen($fileFrom))); } // remove session entry if (isset($_SESSION['INSTALLED_LANG_PACKS']) && is_array($_SESSION['INSTALLED_LANG_PACKS'])) { foreach ($_SESSION['INSTALLED_LANG_PACKS'] as $k => $langPack) { if ($langPack == $zipFile) { unset($_SESSION['INSTALLED_LANG_PACKS'][$k]); unset($_SESSION['INSTALLED_LANG_PACKS_VERSION'][$k]); unset($_SESSION['INSTALLED_LANG_PACKS_MANIFEST'][$k]); $removedLang = $k; } } // remove language from config $new_langs = array(); $old_langs = $sugar_config['languages']; foreach ($old_langs as $key => $value) { if ($key != $removedLang) { $new_langs += array($key => $value); } } $sugar_config['languages'] = $new_langs; } } else { // copy filesFrom to filesTo foreach ($filesFrom as $fileFrom) { @copy($fileFrom, getcwd() . substr($fileFrom, strlen($unzip_dir), strlen($fileFrom))); } $_SESSION['INSTALLED_LANG_PACKS'][$new_lang_name] = $zipFile; $_SESSION['INSTALLED_LANG_PACKS_VERSION'][$new_lang_name] = $version; $serial_manifest = array(); $serial_manifest['manifest'] = isset($manifest) ? $manifest : ''; $serial_manifest['installdefs'] = isset($installdefs) ? $installdefs : ''; $serial_manifest['upgrade_manifest'] = isset($upgrade_manifest) ? $upgrade_manifest : ''; $_SESSION['INSTALLED_LANG_PACKS_MANIFEST'][$new_lang_name] = base64_encode(serialize($serial_manifest)); } writeSugarConfig($sugar_config); return $sugar_config; }
// find name of language pack: find single file in include/language/xx_xx.lang.php $d = dir("{$unzip_dir}/{$zip_from_dir}/include/language"); while ($f = $d->read()) { if ($f == "." || $f == "..") { continue; } else { if (preg_match("/(.*)\\.lang\\.php\$/", $f, $match)) { $new_lang_name = $match[1]; } } } if ($new_lang_name == "") { die($mod_strings['ERR_UW_NO_LANGPACK'] . $install_file); } $hidden_fields .= "<input type=hidden name=\"new_lang_name\" value=\"{$new_lang_name}\"/>"; $new_lang_desc = getLanguagePackName("{$unzip_dir}/{$zip_from_dir}/include/language/{$new_lang_name}.lang.php"); if ($new_lang_desc == "") { die($mod_strings['ERR_UW_NO_LANG_DESC_1'] . "include/language/{$new_lang_name}.lang.php" . $mod_strings['ERR_UW_NO_LANG_DESC_2'] . "{$install_file}."); } $hidden_fields .= "<input type=hidden name=\"new_lang_desc\" value=\"{$new_lang_desc}\"/>"; if (!is_writable("config.php")) { die($mod_strings['ERR_UW_CONFIG']); } break; case "module": $previous_install = array(); if (!empty($id_name) & !empty($version)) { $previous_install = $uh->determineIfUpgrade($id_name, $version); } $previous_version = empty($previous_install['version']) ? '' : $previous_install['version']; $previous_id = empty($previous_install['id']) ? '' : $previous_install['id'];