// Clean Language::checkAndAddLanguage()

This commit is contained in:
Rémi Gaillard committed 2013-03-15 11:14:29 +01:00
1 parent f9feec981a
commit 564aafd10d
2 files changed
+16 -21

No files matched your search

+15 -20
View File
@@ -681,48 +681,45 @@ class LanguageCore extends ObjectModel
return Tools::generateHtaccess(); return Tools::generateHtaccess();
} }
public static function checkAndAddLanguage($iso_code) public static function checkAndAddLanguage($iso_code, $lang_pack = false)
{ {
if (Language::getIdByIso($iso_code)) if (Language::getIdByIso($iso_code))
return true; return true;
else
{
if (@fsockopen('www.prestashop.com', 80))
{
$lang = new Language(); $lang = new Language();
$lang->iso_code = $iso_code; $lang->iso_code = $iso_code;
$lang->active = true; $lang->active = true;
if ($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$iso_code))) if (!$lang_pack)
$lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$iso_code));
if ($lang_pack)
{ {
if (isset($lang_pack->name) if (isset($lang_pack->name)
&& isset($lang_pack->version) && isset($lang_pack->version)
&& isset($lang_pack->iso_code)) && isset($lang_pack->iso_code))
$lang->name = $lang_pack->name; $lang->name = $lang_pack->name;
} }
if (!$lang->name || !$lang->add()) else
return false;
if (!$lang->add())
return false; return false;
$insert_id = (int)$lang->id;
if ($lang_pack)
{
$flag = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/flags/jpeg/'.$iso_code.'.jpg'); $flag = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/flags/jpeg/'.$iso_code.'.jpg');
if ($flag != null && !preg_match('/<body>/', $flag)) if ($flag != null && !preg_match('/<body>/', $flag))
{ {
$file = fopen(dirname(__FILE__).'/../img/l/'.$insert_id.'.jpg', 'w'); $file = fopen(dirname(__FILE__).'/../img/l/'.(int)$lang->id.'.jpg', 'w');
if ($file) if ($file)
{ {
fwrite($file, $flag); fwrite($file, $flag);
fclose($file); fclose($file);
} }
else else
Language::_copyNoneFlag($insert_id); Language::_copyNoneFlag((int)$lang->id);
} }
else else
Language::_copyNoneFlag($insert_id); Language::_copyNoneFlag((int)$lang->id);
}
else
Language::_copyNoneFlag($insert_id);
$files_copy = array( $files_copy = array(
'/en.jpg', '/en.jpg',
@@ -733,15 +730,13 @@ class LanguageCore extends ObjectModel
'/en-default-'.ImageType::getFormatedName('small').'.jpg', '/en-default-'.ImageType::getFormatedName('small').'.jpg',
'/en-default-'.ImageType::getFormatedName('scene').'.jpg' '/en-default-'.ImageType::getFormatedName('scene').'.jpg'
); );
foreach (array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_) as $to) foreach (array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_) as $to)
foreach ($files_copy as $file) foreach ($files_copy as $file)
@copy(dirname(__FILE__).'/../img/l'.$file, $to.str_replace('/en', '/'.$iso_code, $file)); @copy(dirname(__FILE__).'/../img/l'.$file, $to.str_replace('/en', '/'.$iso_code, $file));
return true; return true;
} }
else
return false;
}
}
protected static function _copyNoneFlag($id) protected static function _copyNoneFlag($id)
{ {
+1 -1
View File
@@ -320,7 +320,7 @@ class LocalizationPackCore
AdminTranslationsController::checkAndAddMailsFiles($attributes['iso_code'], $files_list); AdminTranslationsController::checkAndAddMailsFiles($attributes['iso_code'], $files_list);
AdminTranslationsController::addNewTabs($attributes['iso_code'], $files_list); AdminTranslationsController::addNewTabs($attributes['iso_code'], $files_list);
} }
if (!Language::checkAndAddLanguage((string)$attributes['iso_code'])) if (!Language::checkAndAddLanguage((string)$attributes['iso_code'], $lang_pack))
{ {
$this->_errors[] = Tools::displayError('An error occurred while creating the language: ').(string)$attributes['iso_code']; $this->_errors[] = Tools::displayError('An error occurred while creating the language: ').(string)$attributes['iso_code'];
return false; return false;