From 64e84ff2963caf867e8de5e555410be436578b5e Mon Sep 17 00:00:00 2001 From: fram Date: Wed, 20 Nov 2013 17:35:09 +0100 Subject: [PATCH 1/5] // when adding a translation pack, do not install translations for modules that are not on the disk --- classes/Language.php | 4 +- .../admin/AdminTranslationsController.php | 54 ++++++++++++++++--- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/classes/Language.php b/classes/Language.php index be53bf8f5..37b66f699 100644 --- a/classes/Language.php +++ b/classes/Language.php @@ -809,8 +809,8 @@ class LanguageCore extends ObjectModel if (file_exists($file)) { $gz = new Archive_Tar($file, true); - $files_list = $gz->listContent(); - if (!$gz->extract(_PS_TRANSLATIONS_DIR_.'../', false)) + $files_list = AdminTranslationsController::filterTranslationFiles($gz->listContent()); + if (!$gz->extractList(AdminTranslationsController::filesListToPaths($files_list), _PS_TRANSLATIONS_DIR_.'../')) $errors[] = Tools::displayError('Cannot decompress the translation file for the following language: ').(string)$iso; // Clear smarty modules cache Tools::clearCache(); diff --git a/controllers/admin/AdminTranslationsController.php b/controllers/admin/AdminTranslationsController.php index 02f8a238f..3bdfe74d0 100644 --- a/controllers/admin/AdminTranslationsController.php +++ b/controllers/admin/AdminTranslationsController.php @@ -699,11 +699,12 @@ class AdminTranslationsControllerCore extends AdminController if (Validate::isLangIsoCode($iso_code)) { $themes_selected = Tools::getValue('theme', array(self::DEFAULT_THEME_NAME)); - $files_list = $gz->listContent(); - + $files_list = AdminTranslationsController::filterTranslationFiles($gz->listContent()); + $files_paths = AdminTranslationsController::filesListToPaths($files_list); + $uniqid = uniqid(); $sandbox = _PS_CACHE_DIR_.'sandbox'.DIRECTORY_SEPARATOR.$uniqid.DIRECTORY_SEPARATOR; - if ($gz->extract($sandbox, false)) + if ($gz->extractList($files_paths, $sandbox)) { foreach ($files_list as $file2check) { @@ -725,7 +726,7 @@ class AdminTranslationsControllerCore extends AdminController if (count($this->errors)) return false; - if ($gz->extract(_PS_TRANSLATIONS_DIR_.'../', false)) + if ($gz->extractList($files_paths, _PS_TRANSLATIONS_DIR_.'../')) { foreach ($files_list as $file2check) if (pathinfo($file2check['filename'], PATHINFO_BASENAME) == 'index.php' && file_put_contents(_PS_TRANSLATIONS_DIR_.'../'.$file2check['filename'], Tools::getDefaultIndexContent())) @@ -763,6 +764,47 @@ class AdminTranslationsControllerCore extends AdminController } } + /** + * Filter the translation files contained in a .gzip pack + * and return only the ones that we want. + * + * Right now the function only needs to check that + * the modules for which we want to add translations + * are present on the shop (installed or not). + * + * $list is the output of Archive_Tar::listContent() + */ + public static function filterTranslationFiles($list) + { + $kept = array(); + foreach ($list as $file) + { + $m = array(); + if (preg_match('#^modules/([^/]+)/#', $file['filename'], $m)) + { + if (is_dir(_PS_MODULE_DIR_.$m[1])) + $kept[] = $file; + } + else + $kept[] = $file; + } + return $kept; + } + + /** + * Turn the list returned by + * AdminTranslationsController::filterTranslationFiles() + * into a list of paths that can be passed to + * Archive_Tar::extractList() + */ + public static function filesListToPaths($list) + { + $paths = array(); + foreach ($list as $item) + $paths[] = $item['filename']; + return $paths; + } + public function submitAddLang() { $arr_import_lang = explode('|', Tools::getValue('params_import_language')); /* 0 = Language ISO code, 1 = PS version */ @@ -776,8 +818,8 @@ class AdminTranslationsControllerCore extends AdminController if ((bool)@file_put_contents($file, $content)) { $gz = new Archive_Tar($file, true); - $files_list = $gz->listContent(); - if ($error = $gz->extract(_PS_TRANSLATIONS_DIR_.'../', false)) + $files_list = AdminTranslationsController::filterTranslationFiles($gz->listContent()); + if ($error = $gz->extractList(AdminTranslationsController::filesListToPaths($files_list), _PS_TRANSLATIONS_DIR_.'../')) { if (is_object($error) && !empty($error->message)) $this->errors[] = Tools::displayError('The archive cannot be extracted.'). ' '.$error->message; From 690b6b160a5091c29f08f84e36c5e443419b4bc6 Mon Sep 17 00:00:00 2001 From: Vincent Augagneur Date: Tue, 26 Nov 2013 10:24:19 +0100 Subject: [PATCH 2/5] //small js fix --- modules/dashactivity/dashactivity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dashactivity/dashactivity.php b/modules/dashactivity/dashactivity.php index 053c26033..9e09299f9 100644 --- a/modules/dashactivity/dashactivity.php +++ b/modules/dashactivity/dashactivity.php @@ -72,7 +72,7 @@ class Dashactivity extends Module $this->context->controller->addJquery(); $this->context->controller->addJs($this->_path.'views/js/'.$this->name.'.js'); - $this->context->controller->addJs(_PS_JS_DIR_.'date.js'); + $this->context->controller->addJs(array(_PS_JS_DIR_.'date.js', _PS_JS_DIR_.'tools.js'); } } From e3f3f8a58f2ba50e94a0732b42467e17bb116b27 Mon Sep 17 00:00:00 2001 From: Vincent Augagneur Date: Tue, 26 Nov 2013 10:25:03 +0100 Subject: [PATCH 3/5] //oups --- modules/dashactivity/dashactivity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dashactivity/dashactivity.php b/modules/dashactivity/dashactivity.php index 9e09299f9..ba67e4e10 100644 --- a/modules/dashactivity/dashactivity.php +++ b/modules/dashactivity/dashactivity.php @@ -72,7 +72,7 @@ class Dashactivity extends Module $this->context->controller->addJquery(); $this->context->controller->addJs($this->_path.'views/js/'.$this->name.'.js'); - $this->context->controller->addJs(array(_PS_JS_DIR_.'date.js', _PS_JS_DIR_.'tools.js'); + $this->context->controller->addJs(array(_PS_JS_DIR_.'date.js', _PS_JS_DIR_.'tools.js')); } } From 926286eaf9c593fa560cc74ccaa22f9a89e7907c Mon Sep 17 00:00:00 2001 From: Kevin Granger Date: Tue, 26 Nov 2013 10:33:35 +0100 Subject: [PATCH 4/5] // fix switch --- admin-dev/themes/default/template/helpers/form/form.tpl | 1 - 1 file changed, 1 deletion(-) diff --git a/admin-dev/themes/default/template/helpers/form/form.tpl b/admin-dev/themes/default/template/helpers/form/form.tpl index 5da765a26..a11d0d49c 100644 --- a/admin-dev/themes/default/template/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/helpers/form/form.tpl @@ -385,7 +385,6 @@ {if isset($input.disabled) && $input.disabled}disabled="disabled"{/if} />