// Normalize
This commit is contained in:
@@ -34,15 +34,15 @@ class LocalizationPackCore
|
||||
|
||||
protected $iso_code_lang;
|
||||
protected $iso_currency;
|
||||
protected $_errors = array();
|
||||
protected $_errors = array();
|
||||
|
||||
public function loadLocalisationPack($file, $selection, $install_mode = false)
|
||||
{
|
||||
if (!$xml = simplexml_load_string($file))
|
||||
return false;
|
||||
$mainAttributes = $xml->attributes();
|
||||
$this->name = strval($mainAttributes['name']);
|
||||
$this->version = strval($mainAttributes['version']);
|
||||
$main_attributes = $xml->attributes();
|
||||
$this->name = (string)$main_attributes['name'];
|
||||
$this->version = (string)$main_attributes['version'];
|
||||
if (empty($selection))
|
||||
{
|
||||
$res = true;
|
||||
@@ -54,13 +54,13 @@ class LocalizationPackCore
|
||||
$res &= $this->installModules($xml);
|
||||
$res &= $this->updateDefaultGroupDisplayMethod($xml);
|
||||
|
||||
if (!defined('_PS_MODE_DEV_') OR !_PS_MODE_DEV_)
|
||||
if (!defined('_PS_MODE_DEV_') || !_PS_MODE_DEV_)
|
||||
$res &= $this->_installLanguages($xml, $install_mode);
|
||||
|
||||
if ($res AND isset($this->iso_code_lang))
|
||||
if ($res && isset($this->iso_code_lang))
|
||||
Configuration::updateValue('PS_LANG_DEFAULT', (int)Language::getIdByIso($this->iso_code_lang));
|
||||
|
||||
if ($install_mode AND $res AND isset($this->iso_currency))
|
||||
if ($install_mode && $res && isset($this->iso_currency))
|
||||
{
|
||||
$res &= Configuration::updateValue('PS_CURRENCY_DEFAULT', (int)Currency::getIdByIsoCode($this->iso_currency));
|
||||
Currency::refreshCurrencies();
|
||||
@@ -68,8 +68,8 @@ class LocalizationPackCore
|
||||
|
||||
return $res;
|
||||
}
|
||||
foreach ($selection AS $selected)
|
||||
if (!Validate::isLocalizationPackSelection($selected) OR !$this->{'_install'.ucfirst($selected)}($xml))
|
||||
foreach ($selection as $selected)
|
||||
if (!Validate::isLocalizationPackSelection($selected) || !$this->{'_install'.ucfirst($selected)}($xml))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -149,8 +149,8 @@ class LocalizationPackCore
|
||||
if (Tax::getTaxIdByName($attributes['name']))
|
||||
continue;
|
||||
$tax = new Tax();
|
||||
$tax->name[(int)(Configuration::get('PS_LANG_DEFAULT'))] = strval($attributes['name']);
|
||||
$tax->rate = (float)($attributes['rate']);
|
||||
$tax->name[(int)Configuration::get('PS_LANG_DEFAULT')] = (string)$attributes['name'];
|
||||
$tax->rate = (float)$attributes['rate'];
|
||||
$tax->active = 1;
|
||||
|
||||
if (!$tax->validateFields())
|
||||
@@ -161,7 +161,7 @@ class LocalizationPackCore
|
||||
|
||||
if (!$tax->add())
|
||||
{
|
||||
$this->_errors[] = Tools::displayError('An error occurred while importing the tax: ').strval($attributes['name']);
|
||||
$this->_errors[] = Tools::displayError('An error occurred while importing the tax: ').(string)$attributes['name'];
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -238,26 +238,27 @@ class LocalizationPackCore
|
||||
{
|
||||
if (isset($xml->currencies->currency))
|
||||
{
|
||||
if (!$feed = Tools::simplexml_load_file('http://api.prestashop.com/xml/currencies.xml') AND !$feed = @simplexml_load_file(dirname(__FILE__).'/../localization/currencies.xml'))
|
||||
if (!$feed = Tools::simplexml_load_file('http://api.prestashop.com/xml/currencies.xml')
|
||||
&& !$feed = @simplexml_load_file(dirname(__FILE__).'/../localization/currencies.xml'))
|
||||
{
|
||||
$this->_errors[] = Tools::displayError('Cannot parse the currencies XML feed.');
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($xml->currencies->currency AS $data)
|
||||
foreach ($xml->currencies->currency as $data)
|
||||
{
|
||||
$attributes = $data->attributes();
|
||||
if(Currency::exists($attributes['iso_code']))
|
||||
if (Currency::exists($attributes['iso_code']))
|
||||
continue;
|
||||
$currency = new Currency();
|
||||
$currency->name = strval($attributes['name']);
|
||||
$currency->iso_code = strval($attributes['iso_code']);
|
||||
$currency->iso_code_num = (int)($attributes['iso_code_num']);
|
||||
$currency->sign = strval($attributes['sign']);
|
||||
$currency->blank = (int)($attributes['blank']);
|
||||
$currency->name = (string)$attributes['name'];
|
||||
$currency->iso_code = (string)$attributes['iso_code'];
|
||||
$currency->iso_code_num = (int)$attributes['iso_code_num'];
|
||||
$currency->sign = (string)$attributes['sign'];
|
||||
$currency->blank = (int)$attributes['blank'];
|
||||
$currency->conversion_rate = 1; // This value will be updated if the store is online
|
||||
$currency->format = (int)($attributes['format']);
|
||||
$currency->decimals = (int)($attributes['decimals']);
|
||||
$currency->format = (int)$attributes['format'];
|
||||
$currency->decimals = (int)$attributes['decimals'];
|
||||
$currency->active = $install_mode;
|
||||
if (!$currency->validateFields())
|
||||
{
|
||||
@@ -278,7 +279,7 @@ class LocalizationPackCore
|
||||
|
||||
Currency::refreshCurrencies();
|
||||
|
||||
if (!sizeof($this->_errors) AND $install_mode AND isset($attributes['iso_code']) AND sizeof($xml->currencies->currency) == 1)
|
||||
if (!count($this->_errors) && $install_mode && isset($attributes['iso_code']) && count($xml->currencies->currency) == 1)
|
||||
$this->iso_currency = $attributes['iso_code'];
|
||||
}
|
||||
|
||||
@@ -289,19 +290,20 @@ class LocalizationPackCore
|
||||
{
|
||||
$attributes = array();
|
||||
if (isset($xml->languages->language))
|
||||
foreach ($xml->languages->language AS $data)
|
||||
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)
|
||||
foreach ($native_lang as $lang)
|
||||
$native_iso_code[] = $lang['iso_code'];
|
||||
if ((in_array((string)$attributes['iso_code'], $native_iso_code) AND !$install_mode) OR !in_array((string)$attributes['iso_code'], $native_iso_code))
|
||||
if ((in_array((string)$attributes['iso_code'], $native_iso_code) && !$install_mode)
|
||||
|| !in_array((string)$attributes['iso_code'], $native_iso_code))
|
||||
$errno = 0;
|
||||
$errstr = '';
|
||||
if(@fsockopen('api.prestashop.com', 80, $errno, $errstr, 10))
|
||||
if (@fsockopen('api.prestashop.com', 80, $errno, $errstr, 10))
|
||||
{
|
||||
if ($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://api.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$attributes['iso_code'])))
|
||||
{
|
||||
@@ -338,7 +340,7 @@ class LocalizationPackCore
|
||||
}
|
||||
|
||||
// change the default language if there is only one language in the localization pack
|
||||
if (!sizeof($this->_errors) AND $install_mode AND isset($attributes['iso_code']) AND sizeof($xml->languages->language) == 1)
|
||||
if (!count($this->_errors) && $install_mode && isset($attributes['iso_code']) && count($xml->languages->language) == 1)
|
||||
$this->iso_code_lang = $attributes['iso_code'];
|
||||
|
||||
return true;
|
||||
@@ -348,7 +350,7 @@ class LocalizationPackCore
|
||||
{
|
||||
$varNames = array('weight' => 'PS_WEIGHT_UNIT', 'volume' => 'PS_VOLUME_UNIT', 'short_distance' => 'PS_DIMENSION_UNIT', 'base_distance' => 'PS_BASE_DISTANCE_UNIT', 'long_distance' => 'PS_DISTANCE_UNIT');
|
||||
if (isset($xml->units->unit))
|
||||
foreach ($xml->units->unit AS $data)
|
||||
foreach ($xml->units->unit as $data)
|
||||
{
|
||||
$attributes = $data->attributes();
|
||||
if (!isset($varNames[strval($attributes['type'])]))
|
||||
@@ -373,7 +375,7 @@ class LocalizationPackCore
|
||||
protected function installModules($xml)
|
||||
{
|
||||
if (isset($xml->modules))
|
||||
foreach($xml->modules->module as $data)
|
||||
foreach ($xml->modules->module as $data)
|
||||
{
|
||||
$attributes = $data->attributes();
|
||||
$name = (string)$attributes['name'];
|
||||
@@ -385,17 +387,17 @@ class LocalizationPackCore
|
||||
{
|
||||
if (!Module::isInstalled($name))
|
||||
if (!$module->install())
|
||||
$this->_errors[] = Tools::displayError('An error has occured during the module installation: '). $name;
|
||||
$this->_errors[] = Tools::displayError('An error has occured during the module installation: ').$name;
|
||||
}
|
||||
else
|
||||
if (Module::isInstalled($name))
|
||||
if (!$module->uninstall())
|
||||
$this->_errors[] = Tools::displayError('An error has occured during the module uninstall: '). $name;
|
||||
$this->_errors[] = Tools::displayError('An error has occured during the module uninstall: ').$name;
|
||||
|
||||
unset($module);
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('An error has occured, this module doesnt exists: '). $name;
|
||||
$this->_errors[] = Tools::displayError('An error has occured, this module doesnt exists: ').$name;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -409,14 +411,14 @@ class LocalizationPackCore
|
||||
protected function installConfiguration($xml)
|
||||
{
|
||||
if (isset($xml->configurations))
|
||||
foreach($xml->configurations->configuration as $data)
|
||||
foreach ($xml->configurations->configuration as $data)
|
||||
{
|
||||
$attributes = $data->attributes();
|
||||
$name = (string)$attributes['name'];
|
||||
|
||||
if (isset($name) && isset($attributes['value']) && Configuration::get($name) !== false)
|
||||
if (!Configuration::updateValue($name, (string)$attributes['value']))
|
||||
$this->_errors[] = Tools::displayError('An error has occured during the configuration setup: '. $name);
|
||||
$this->_errors[] = Tools::displayError('An error has occured during the configuration setup: '.$name);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user