public static function downloadAndInstallLanguagePack($iso, $version = null, $params = null, $install = true)
 {
     if (!Validate::isLanguageIsoCode((string) $iso)) {
         return false;
     }
     if ($version == null) {
         $version = _PS_VERSION_;
     }
     $lang_pack = false;
     $lang_pack_ok = false;
     $errors = array();
     $file = _PS_TRANSLATIONS_DIR_ . (string) $iso . '.gzip';
     if (!($lang_pack_link = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . $version . '&iso_lang=' . Tools::strtolower((string) $iso)))) {
         $errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
     } elseif (!($lang_pack = Tools::jsonDecode($lang_pack_link))) {
         $errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
     } elseif (empty($lang_pack->error) && ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . Tools::strtolower($lang_pack->iso_code . '.gzip')))) {
         if (!@file_put_contents($file, $content)) {
             if (is_writable(dirname($file))) {
                 @unlink($file);
                 @file_put_contents($file, $content);
             } elseif (!is_writable($file)) {
                 $errors[] = Tools::displayError('Server does not have permissions for writing.') . ' (' . $file . ')';
             }
         }
     }
     if (!file_exists($file)) {
         $errors[] = Tools::displayError('No language pack is available for your version.');
     } elseif ($install) {
         require_once _PS_TOOL_DIR_ . 'tar/Archive_Tar.php';
         $gz = new Archive_Tar($file, true);
         $files_list = AdminTranslationsController::filterTranslationFiles(Language::getLanguagePackListContent((string) $iso, $gz));
         $files_paths = AdminTranslationsController::filesListToPaths($files_list);
         $i = 0;
         $tmp_array = array();
         foreach ($files_paths as $files_path) {
             $path = dirname($files_path);
             if (is_dir(_PS_TRANSLATIONS_DIR_ . '../' . $path) && !is_writable(_PS_TRANSLATIONS_DIR_ . '../' . $path) && !in_array($path, $tmp_array)) {
                 $errors[] = (!$i++ ? Tools::displayError('The archive cannot be extracted.') . ' ' : '') . Tools::displayError('The server does not have permissions for writing.') . ' ' . sprintf(Tools::displayError('Please check rights for %s'), $path);
                 $tmp_array[] = $path;
             }
         }
         if (defined('_PS_HOST_MODE_')) {
             $mails_files = array();
             $other_files = array();
             foreach ($files_list as $key => $data) {
                 if (substr($data['filename'], 0, 5) == 'mails') {
                     $mails_files[] = $data;
                 } else {
                     $other_files[] = $data;
                 }
             }
             $files_list = $other_files;
         }
         if (!$gz->extractList(AdminTranslationsController::filesListToPaths($files_list), _PS_TRANSLATIONS_DIR_ . '../')) {
             $errors[] = sprintf(Tools::displayError('Cannot decompress the translation file for the following language: %s'), (string) $iso);
         }
         // Clear smarty modules cache
         Tools::clearCache();
         if (!Language::checkAndAddLanguage((string) $iso, $lang_pack, false, $params)) {
             $errors[] = sprintf(Tools::displayError('An error occurred while creating the language: %s'), (string) $iso);
         } else {
             // Reset cache
             Language::loadLanguages();
             AdminTranslationsController::checkAndAddMailsFiles((string) $iso, $files_list);
             AdminTranslationsController::addNewTabs((string) $iso, $files_list);
         }
     }
     return count($errors) ? $errors : true;
 }
 public function submitAddLang()
 {
     $arr_import_lang = explode('|', Tools::getValue('params_import_language'));
     /* 0 = Language ISO code, 1 = PS version */
     if (Validate::isLangIsoCode($arr_import_lang[0])) {
         $array_stream_context = @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 10)));
         $content = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/' . $arr_import_lang[1] . '/' . Tools::strtolower($arr_import_lang[0]) . '.gzip', false, $array_stream_context);
         if ($content) {
             $file = _PS_TRANSLATIONS_DIR_ . $arr_import_lang[0] . '.gzip';
             if ((bool) @file_put_contents($file, $content)) {
                 require_once _PS_TOOL_DIR_ . '/tar/Archive_Tar.php';
                 $gz = new Archive_Tar($file, true);
                 $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;
                     } else {
                         if (!Language::checkAndAddLanguage($arr_import_lang[0])) {
                             $conf = 20;
                         } else {
                             // Reset cache
                             Language::loadLanguages();
                             // Clear smarty modules cache
                             Tools::clearCache();
                             AdminTranslationsController::checkAndAddMailsFiles($arr_import_lang[0], $files_list);
                             if ($tab_errors = AdminTranslationsController::addNewTabs($arr_import_lang[0], $files_list)) {
                                 $this->errors += $tab_errors;
                             }
                         }
                         if (!unlink($file)) {
                             $this->errors[] = sprintf(Tools::displayError('Cannot delete the archive %s.'), $file);
                         }
                         $this->redirect(false, isset($conf) ? $conf : '15');
                     }
                 } elseif (!unlink($file)) {
                     $this->errors[] = sprintf(Tools::displayError('Cannot delete the archive %s.'), $file);
                 }
             } else {
                 $this->errors[] = Tools::displayError('The server does not have permissions for writing.') . ' ' . sprintf(Tools::displayError('Please check rights for %s'), dirname($file));
             }
         } else {
             $this->errors[] = Tools::displayError('Language not found.');
         }
     } else {
         $this->errors[] = Tools::displayError('Invalid parameter');
     }
 }
 public function submitAddLang()
 {
     $arr_import_lang = explode('|', Tools::getValue('params_import_language'));
     /* 0 = Language ISO code, 1 = PS version */
     if (Validate::isLangIsoCode($arr_import_lang[0])) {
         if ($content = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/' . $arr_import_lang[1] . '/' . $arr_import_lang[0] . '.gzip', false, @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 5))))) {
             $file = _PS_TRANSLATIONS_DIR_ . $arr_import_lang[0] . '.gzip';
             if (file_put_contents($file, $content)) {
                 $gz = new Archive_Tar($file, true);
                 $files_list = $gz->listContent();
                 if ($gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) {
                     AdminTranslationsController::checkAndAddMailsFiles($arr_import_lang[0], $files_list);
                     AdminTranslationsController::addNewTabs($arr_import_lang[0], $files_list);
                     if (!Language::checkAndAddLanguage($arr_import_lang[0])) {
                         $conf = 20;
                     }
                     if (!unlink($file)) {
                         $this->errors[] = Tools::displayError('Cannot delete archive');
                     }
                     $this->redirect(false, isset($conf) ? $conf : '15');
                 }
                 $this->errors[] = Tools::displayError('Archive cannot be extracted.');
                 if (!unlink($file)) {
                     $this->errors[] = Tools::displayError('Cannot delete archive');
                 }
             } else {
                 $this->errors[] = Tools::displayError('Server does not have permissions for writing.');
             }
         } else {
             $this->errors[] = Tools::displayError('Language not found');
         }
     } else {
         $this->errors[] = Tools::displayError('Invalid parameter');
     }
 }
 protected function _installLanguages($xml, $install_mode = false)
 {
     $attributes = array();
     if (isset($xml->languages->language)) {
         foreach ($xml->languages->language as $data) {
             $attributes = $data->attributes();
             if (Language::getIdByIso($attributes['iso_code'])) {
                 continue;
             }
             $native_lang = Language::getLanguages();
             $native_iso_code = array();
             foreach ($native_lang as $lang) {
                 $native_iso_code[] = $lang['iso_code'];
             }
             // if we are not in an installation context or if the pack is not available in the local directory
             if (!$install_mode || !in_array((string) $attributes['iso_code'], $native_iso_code)) {
                 $errno = 0;
                 $errstr = '';
                 if (!@fsockopen('api.prestashop.com', 80, $errno, $errstr, 5)) {
                     $this->_errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
                 } elseif (!($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . _PS_VERSION_ . '&iso_lang=' . $attributes['iso_code'])))) {
                     $this->_errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
                 } elseif ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . $attributes['iso_code'] . '.gzip')) {
                     $file = _PS_TRANSLATIONS_DIR_ . $attributes['iso_code'] . '.gzip';
                     if (file_put_contents($file, $content)) {
                         $gz = new Archive_Tar($file, true);
                         $files_list = $gz->listContent();
                         if (!$gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) {
                             $this->_errors[] = Tools::displayError('Cannot decompress the translation file for the following language: ') . (string) $attributes['iso_code'];
                             return false;
                         } else {
                             AdminTranslationsController::checkAndAddMailsFiles($attributes['iso_code'], $files_list);
                             AdminTranslationsController::addNewTabs($attributes['iso_code'], $files_list);
                         }
                         if (!Language::checkAndAddLanguage((string) $attributes['iso_code'])) {
                             $this->_errors[] = Tools::displayError('An error occurred while creating the language: ') . (string) $attributes['iso_code'];
                             return false;
                         }
                         @unlink($file);
                     } else {
                         $this->_errors[] = Tools::displayError('Server does not have permissions for writing.');
                     }
                 }
             }
         }
     }
     // change the default language if there is only one language in the localization pack
     if (!count($this->_errors) && $install_mode && isset($attributes['iso_code']) && count($xml->languages->language) == 1) {
         $this->iso_code_lang = $attributes['iso_code'];
     }
     return true;
 }
Exemple #5
0
 public static function installLanguagePack($iso, $params, &$errors = array())
 {
     $file = _PS_TRANSLATIONS_DIR_ . (string) $iso . '.gzip';
     $gz = new \Archive_Tar($file, true);
     $files_list = AdminTranslationsController::filterTranslationFiles(Language::getLanguagePackListContent((string) $iso, $gz));
     $files_paths = AdminTranslationsController::filesListToPaths($files_list);
     $tmp_array = array();
     foreach ($files_paths as $files_path) {
         $path = dirname($files_path);
         if (is_dir(_PS_TRANSLATIONS_DIR_ . '../' . $path) && !is_writable(_PS_TRANSLATIONS_DIR_ . '../' . $path) && !in_array($path, $tmp_array)) {
             $error = Tools::displayError('The server does not have permissions for writing.') . ' ' . sprintf(Tools::displayError('Please check permissions for %s'), $path);
             $errors[] = count($tmp_array) == 0 ? Tools::displayError('The archive cannot be extracted.') . ' ' . $error : $error;
             $tmp_array[] = $path;
         }
     }
     if (defined('_PS_HOST_MODE_')) {
         $mails_files = array();
         $other_files = array();
         foreach ($files_list as $key => $data) {
             if (substr($data['filename'], 0, 5) == 'mails') {
                 $mails_files[] = $data;
             }
         }
         $files_list = array_diff($files_list, $mails_files);
     }
     if (!$gz->extractList(AdminTranslationsController::filesListToPaths($files_list), _PS_TRANSLATIONS_DIR_ . '../')) {
         $errors[] = sprintf(Tools::displayError('Cannot decompress the translation file for the following language: %s'), (string) $iso);
     }
     // Clear smarty modules cache
     Tools::clearCache();
     if (!Language::checkAndAddLanguage((string) $iso, false, false, $params)) {
         $errors[] = sprintf(Tools::displayError('An error occurred while creating the language: %s'), (string) $iso);
     } else {
         // Reset cache
         Language::loadLanguages();
         AdminTranslationsController::checkAndAddMailsFiles((string) $iso, $files_list);
         AdminTranslationsController::addNewTabs((string) $iso, $files_list);
     }
     self::installSfLanguagePack(self::getLocaleByIso($iso), $errors);
     return count($errors) ? $errors : true;
 }
 public function submitAddLang()
 {
     $arr_import_lang = explode('|', Tools::getValue('params_import_language'));
     /* 0 = Language ISO code, 1 = PS version */
     if (Validate::isLangIsoCode($arr_import_lang[0])) {
         $array_stream_context = @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 10)));
         $content = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/' . $arr_import_lang[1] . '/' . Tools::strtolower($arr_import_lang[0]) . '.gzip', false, $array_stream_context);
         if ($content) {
             $file = _PS_TRANSLATIONS_DIR_ . $arr_import_lang[0] . '.gzip';
             if ((bool) @file_put_contents($file, $content)) {
                 $gz = new \Archive_Tar($file, true);
                 if (_PS_MODE_DEV_) {
                     $gz->setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_WARNING);
                 }
                 $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[] = $this->trans('The archive cannot be extracted.', array(), 'Admin.International.Notification') . ' ' . $error->message;
                     } else {
                         if (!Language::checkAndAddLanguage($arr_import_lang[0])) {
                             $conf = 20;
                         } else {
                             // Reset cache
                             Language::loadLanguages();
                             // Clear smarty modules cache
                             Tools::clearCache();
                             AdminTranslationsController::checkAndAddMailsFiles($arr_import_lang[0], $files_list);
                             if ($tab_errors = AdminTranslationsController::addNewTabs($arr_import_lang[0], $files_list)) {
                                 $this->errors += $tab_errors;
                             }
                         }
                         if (!unlink($file)) {
                             $this->errors[] = sprintf($this->trans('Cannot delete the archive %s.', array(), 'Admin.International.Notification'), $file);
                         }
                         //fetch cldr datas for the new imported locale
                         $languageCode = explode('-', Language::getLanguageCodeByIso($arr_import_lang[0]));
                         $cldrUpdate = new Update(_PS_TRANSLATIONS_DIR_);
                         $cldrUpdate->fetchLocale($languageCode[0] . '-' . Tools::strtoupper($languageCode[1]));
                         $this->redirect(false, isset($conf) ? $conf : '15');
                     }
                 } else {
                     $this->errors[] = sprintf($this->trans('Cannot decompress the translation file for the following language: %s', array(), 'Admin.International.Notification'), $arr_import_lang[0]);
                     $checks = array();
                     foreach ($files_list as $f) {
                         if (isset($f['filename'])) {
                             if (is_file(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $f['filename']) && !is_writable(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $f['filename'])) {
                                 $checks[] = dirname($f['filename']);
                             } elseif (is_dir(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $f['filename']) && !is_writable(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . dirname($f['filename']))) {
                                 $checks[] = dirname($f['filename']);
                             }
                         }
                     }
                     $checks = array_unique($checks);
                     foreach ($checks as $check) {
                         $this->errors[] = sprintf($this->trans('Please check rights for folder and files in %s', array(), 'Admin.Notifications.Error'), $check);
                     }
                     if (!unlink($file)) {
                         $this->errors[] = sprintf($this->trans('Cannot delete the archive %s.', array(), 'Admin.International.Notification'), $file);
                     }
                 }
             } else {
                 $this->errors[] = $this->trans('The server does not have permissions for writing.', array(), 'Admin.Notifications.Error') . ' ' . sprintf($this->trans('Please check rights for %s', array(), 'Admin.Notifications.Error'), dirname($file));
             }
         } else {
             $this->errors[] = $this->trans('Language not found.', array(), 'Admin.International.Notification');
         }
     } else {
         $this->errors[] = $this->trans('Invalid parameter.', array(), 'Admin.Notifications.Error');
     }
 }
Exemple #7
0
 public static function downloadAndInstallLanguagePack($iso, $version = null, $params = null)
 {
     require_once _PS_TOOL_DIR_ . 'tar/Archive_Tar.php';
     if (!Validate::isLanguageIsoCode($iso)) {
         return false;
     }
     if ($version == null) {
         $version = _PS_VERSION_;
     }
     $lang_pack = false;
     $lang_pack_ok = false;
     $errors = array();
     $file = _PS_TRANSLATIONS_DIR_ . $iso . '.gzip';
     if (!($lang_pack_link = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . $version . '&iso_lang=' . $iso))) {
         $errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
     } elseif (!($lang_pack = Tools::jsonDecode($lang_pack_link))) {
         $errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
     } elseif ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . $lang_pack->iso_code . '.gzip')) {
         if (!@file_put_contents($file, $content)) {
             $errors[] = Tools::displayError('Server does not have permissions for writing.');
         }
     }
     if (file_exists($file)) {
         $gz = new Archive_Tar($file, true);
         $files_list = $gz->listContent();
         if (!$gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) {
             $errors[] = Tools::displayError('Cannot decompress the translation file for the following language: ') . (string) $iso;
         }
         if (!Language::checkAndAddLanguage((string) $iso, $lang_pack, false, $params)) {
             $errors[] = Tools::displayError('An error occurred while creating the language: ') . (string) $iso;
         } else {
             // Reset cache
             Language::loadLanguages();
             AdminTranslationsController::checkAndAddMailsFiles($iso, $files_list);
             AdminTranslationsController::addNewTabs($iso, $files_list);
         }
         @unlink($file);
     } else {
         $errors[] = Tools::displayError('No language pack is available for your version.');
     }
     return count($errors) ? $errors : true;
 }
Exemple #8
0
		GROUP BY c.id_category
		ORDER BY c.`position`
		LIMIT ' . (int) $limit);
    if ($results) {
        foreach ($results as $result) {
            echo trim($result['name']) . '|' . (int) $result['id_category'] . "\n";
        }
    }
}
if (Tools::isSubmit('getParentCategoriesId') && ($id_category = Tools::getValue('id_category'))) {
    $category = new Category((int) $id_category);
    $results = Db::getInstance()->executeS('SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category` c WHERE c.`nleft` < ' . (int) $category->nleft . ' AND c.`nright` > ' . (int) $category->nright . '');
    $output = array();
    foreach ($results as $result) {
        $output[] = $result;
    }
    die(json_encode($output));
}
if (Tools::isSubmit('getZones')) {
    $html = '<select id="zone_to_affect" name="zone_to_affect">';
    foreach (Zone::getZones() as $z) {
        $html .= '<option value="' . $z['id_zone'] . '">' . $z['name'] . '</option>';
    }
    $html .= '</select>';
    $array = array('hasError' => false, 'errors' => '', 'data' => $html);
    die(json_encode($array));
}
if (Tools::isSubmit('getEmailHTML') && ($email = Tools::getValue('email'))) {
    $email_html = AdminTranslationsController::getEmailHTML($email);
    die($email_html);
}