diff --git a/classes/Address.php b/classes/Address.php index ad5cc7def..1992e7102 100644 --- a/classes/Address.php +++ b/classes/Address.php @@ -278,9 +278,12 @@ class AddressCore extends ObjectModel { if (isset(self::$_idCountries[$id_address])) return self::$_idCountries[$id_address]; - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' - SELECT `id_country`, `id_state`, `vat_number`, `postcode` FROM `'._DB_PREFIX_.'address` - WHERE `id_address` = '.(int)$id_address); + if ($id_address) + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' + SELECT `id_country`, `id_state`, `vat_number`, `postcode` FROM `'._DB_PREFIX_.'address` + WHERE `id_address` = '.(int)$id_address); + else + $result = false; self::$_idCountries[$id_address] = $result; return $result; } diff --git a/classes/Configuration.php b/classes/Configuration.php index d529d40f1..013ee482f 100644 --- a/classes/Configuration.php +++ b/classes/Configuration.php @@ -93,9 +93,9 @@ class ConfigurationCore extends ObjectModel */ public static function getIdByName($key, $id_shop_group = null, $id_shop = null) { - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Shop::getContextShopID(); - if (is_null($id_shop_group)) + if ($id_shop_group === null) $id_shop_group = Shop::getContextShopGroupID(); $sql = 'SELECT id_configuration @@ -147,9 +147,9 @@ class ConfigurationCore extends ObjectModel public static function get($key, $id_lang = null, $id_shop_group = null, $id_shop = null) { $id_lang = (int)$id_lang; - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Shop::getContextShopID(); - if (is_null($id_shop_group)) + if ($id_shop_group === null) $id_shop_group = Shop::getContextShopGroupID(); if (!isset(self::$_CONF[$id_lang])) @@ -203,9 +203,9 @@ class ConfigurationCore extends ObjectModel throw new PrestaShopException('keys var is not an array'); $id_lang = (int)$id_lang; - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Shop::getContextShopID(); - if (is_null($id_shop_group)) + if ($id_shop_group === null) $id_shop_group = Shop::getContextShopGroupID(); $results = array(); @@ -246,9 +246,9 @@ class ConfigurationCore extends ObjectModel if (!Validate::isConfigName($key)) die(Tools::displayError()); - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Shop::getContextShopID(); - if (is_null($id_shop_group)) + if ($id_shop_group === null) $id_shop_group = Shop::getContextShopGroupID(); if (!is_array($values)) @@ -293,9 +293,9 @@ class ConfigurationCore extends ObjectModel if (!Validate::isConfigName($key)) die(Tools::displayError()); - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Shop::getContextShopID(); - if (is_null($id_shop_group)) + if ($id_shop_group === null) $id_shop_group = Shop::getContextShopGroupID(); if (!is_array($values)) diff --git a/classes/Customer.php b/classes/Customer.php index e734aa09e..35b01fa47 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -531,7 +531,7 @@ class CustomerCore extends ObjectModel public static function getGroupsStatic($id_customer) { - if (!Group::isFeatureActive()) + if (!Group::isFeatureActive() || $id_customer = 0) return array(Configuration::get('PS_CUSTOMER_GROUP')); if (!isset(self::$_customer_groups[$id_customer])) diff --git a/classes/Media.php b/classes/Media.php index 220157fd9..c6477450e 100755 --- a/classes/Media.php +++ b/classes/Media.php @@ -209,7 +209,7 @@ class MediaCore */ public static function getJSPath($js_uri) { - if (is_array($js_uri) || is_null($js_uri) || empty($js_uri)) + if (is_array($js_uri) || $js_uri === null || empty($js_uri)) return false; $url_data = parse_url($js_uri); if (!array_key_exists('host', $url_data)) @@ -258,14 +258,14 @@ class MediaCore public static function getJqueryPath($version = null, $folder = null, $minifier = true) { $add_no_conflict = false; - if (is_null($version)) + if ($version === null) $version = _PS_JQUERY_VERSION_; //set default version else if (preg_match('/^([0-9]+\.)+[0-9]$/Ui', $version)) $add_no_conflict = true; else return false; - if (is_null($folder)) + if ($folder === null) $folder = _PS_JS_DIR_.'jquery/'; //set default folder //check if file exist $file = $folder.'jquery-'.$version.($minifier ? '.min.js' : '.js'); @@ -345,7 +345,7 @@ class MediaCore public static function getJqueryPluginPath($name, $folder) { $plugin_path = array('js' => array(), 'css' => array()); - if (is_null($folder)) + if ($folder === null) $folder = _PS_JS_DIR_.'jquery/plugins/'; //set default folder $file = 'jquery.'.$name.'.js'; diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index edd54eb1b..8f89447ea 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -166,7 +166,7 @@ abstract class ObjectModelCore $this->def = self::getDefinition($this); $this->setDefinitionRetrocompatibility(); - if (!is_null($id_lang)) + if ($id_lang !== null) $this->id_lang = (Language::getLanguage($id_lang) !== false) ? $id_lang : Configuration::get('PS_LANG_DEFAULT'); if ($id_shop && $this->isMultishop()) @@ -299,7 +299,7 @@ abstract class ObjectModelCore $is_lang_multishop = $this->isLangMultishop(); $fields = array(); - if (is_null($this->id_lang)) + if ($this->id_lang === null) foreach (Language::getLanguages(false) as $language) { $fields[$language['id_lang']] = $this->formatFields(self::FORMAT_LANG, $language['id_lang']); @@ -943,7 +943,7 @@ abstract class ObjectModelCore ), ); - if (is_null($ws_params_attribute_name)) + if ($ws_params_attribute_name === null) $ws_params_attribute_name = 'webserviceParameters'; if (!isset($this->{$ws_params_attribute_name}['objectNodeName'])) @@ -1068,7 +1068,7 @@ abstract class ObjectModelCore */ public function isAssociatedToShop($id_shop = null) { - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Context::getContext()->shop->id; $sql = 'SELECT id_shop diff --git a/classes/Tools.php b/classes/Tools.php index 0aa110639..cadda0887 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -963,8 +963,7 @@ class ToolsCore // Remove all non-whitelist chars. $str = preg_replace('/[^a-zA-Z0-9\s\'\:\/\[\]-\pL]/u', '', $str); $str = preg_replace('/[\s\'\:\/\[\]-]+/', ' ', $str); - $str = preg_replace('/[ ]/', '-', $str); - $str = preg_replace('/[\/]/', '-', $str); + $str = str_replace(array(' ', '/'), '-', $str); // If it was not possible to lowercase the string with mb_strtolower, we do it after the transformations. // This way we lose fewer special chars. diff --git a/classes/Validate.php b/classes/Validate.php index fb3946bec..049be4ef6 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -490,7 +490,7 @@ class ValidateCore */ public static function isBool($bool) { - return is_null($bool) || is_bool($bool) || preg_match('/^0|1$/', $bool); + return $bool === null || is_bool($bool) || preg_match('/^0|1$/', $bool); } /** @@ -655,7 +655,7 @@ class ValidateCore public static function isNullOrUnsignedId($id) { - return is_null($id) || Validate::isUnsignedId($id); + return $id === null || Validate::isUnsignedId($id); } /** @@ -803,7 +803,7 @@ class ValidateCore */ public static function isSortDirection($value) { - return (!is_null($value) && ($value === 'ASC' || $value === 'DESC')); + return ($value !== null && ($value === 'ASC' || $value === 'DESC')); } /** @@ -909,7 +909,7 @@ class ValidateCore */ public static function isSerializedArray($data) { - return is_null($data) || (is_string($data) && preg_match('/^a:[0-9]+:{.*;}$/s', $data)); + return $data === null || (is_string($data) && preg_match('/^a:[0-9]+:{.*;}$/s', $data)); } /** @@ -920,7 +920,7 @@ class ValidateCore */ public static function isCoordinate($data) { - return is_null($data) || preg_match('/^\-?[0-9]{1,8}\.[0-9]{1,8}$/s', $data); + return $data === null || preg_match('/^\-?[0-9]{1,8}\.[0-9]{1,8}$/s', $data); } /** diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index 67ab39a8a..17f5fb7f6 100755 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -841,7 +841,7 @@ class FrontControllerCore extends Controller return array(); $context = Context::getContext(); - if (!isset($context->customer)) + if (!isset($context->customer) || !$context->customer->id) return array(); if (!is_array(self::$currentCustomerGroups)) diff --git a/classes/db/DbQuery.php b/classes/db/DbQuery.php index 0e0c81b8e..53fa8ea99 100644 --- a/classes/db/DbQuery.php +++ b/classes/db/DbQuery.php @@ -96,7 +96,7 @@ class DbQueryCore */ public function leftJoin($table, $alias = null, $on = null) { - return $this->join('LEFT JOIN `'._DB_PREFIX_.bqSQL($table).'`'.($alias ? ' '.pSQL($alias) : '').($on ? ' ON '.$on : '')); + return $this->join('LEFT JOIN `'._DB_PREFIX_.bqSQL($table).'`'.($alias ? ' `'.pSQL($alias).'`' : '').($on ? ' ON '.$on : '')); } /** diff --git a/classes/module/Module.php b/classes/module/Module.php index f92739506..72822c945 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -1430,7 +1430,7 @@ abstract class ModuleCore protected static $exceptionsCache = null; public function getExceptions($hookID, $dispatch = false) { - if (is_null(self::$exceptionsCache)) + if (self::$exceptionsCache === null) { self::$exceptionsCache = array(); $sql = 'SELECT * FROM `'._DB_PREFIX_.'hook_module_exceptions` @@ -1557,7 +1557,7 @@ abstract class ModuleCore public function getTemplatePath($template) { $overloaded = $this->_isTemplateOverloaded($template); - if (is_null($overloaded)) + if ($overloaded === null) return null; if ($overloaded) return _PS_THEME_DIR_.'modules/'.$this->name.'/'.$template; diff --git a/classes/stock/StockAvailable.php b/classes/stock/StockAvailable.php index 16ae94ec3..46b9a6598 100644 --- a/classes/stock/StockAvailable.php +++ b/classes/stock/StockAvailable.php @@ -100,7 +100,7 @@ class StockAvailableCore extends ObjectModel $query->from('stock_available'); $query->where('id_product = '.(int)$id_product); - if (!is_null($id_product_attribute)) + if ($id_product_attribute !== null) $query->where('id_product_attribute = '.(int)$id_product_attribute); $query = StockAvailable::addSqlShopRestriction($query, $id_shop); @@ -219,7 +219,7 @@ class StockAvailableCore extends ObjectModel */ public static function setProductDependsOnStock($id_product, $depends_on_stock = true, $id_shop = null, $id_product_attribute = 0) { - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Context::getContext()->shop->id; $existing_id = StockAvailable::getStockAvailableIdByProductId((int)$id_product, (int)$id_product_attribute, (int)$id_shop); @@ -257,7 +257,7 @@ class StockAvailableCore extends ObjectModel */ public static function setProductOutOfStock($id_product, $out_of_stock = false, $id_shop = null, $id_product_attribute = 0) { - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Context::getContext()->shop->id; $existing_id = StockAvailable::getStockAvailableIdByProductId((int)$id_product, (int)$id_product_attribute, (int)$id_shop); @@ -295,11 +295,11 @@ class StockAvailableCore extends ObjectModel */ public static function getQuantityAvailableByProduct($id_product = null, $id_product_attribute = null, $id_shop = null) { - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Context::getContext()->shop->id; // if null, it's a product without attributes - if (is_null($id_product_attribute)) + if ($id_product_attribute === null) $id_product_attribute = 0; $query = new DbQuery(); @@ -307,7 +307,7 @@ class StockAvailableCore extends ObjectModel $query->from('stock_available'); // if null, it's a product without attributes - if (!is_null($id_product)) + if ($id_product !== null) $query->where('id_product = '.(int)$id_product); $query->where('id_product_attribute = '.(int)$id_product_attribute); @@ -415,7 +415,7 @@ class StockAvailableCore extends ObjectModel $context = Context::getContext(); // if there is no $id_shop, gets the context one - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = (int)$context->shop->id; $depends_on_stock = StockAvailable::dependsOnStock($id_product); @@ -529,7 +529,7 @@ class StockAvailableCore extends ObjectModel */ public static function dependsOnStock($id_product, $id_shop = null) { - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Context::getContext()->shop->id; $query = new DbQuery(); @@ -552,7 +552,7 @@ class StockAvailableCore extends ObjectModel */ public static function outOfStock($id_product, $id_shop = null) { - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = Context::getContext()->shop->id; $query = new DbQuery(); @@ -583,7 +583,7 @@ class StockAvailableCore extends ObjectModel $alias .= '.'; // if there is no $id_shop, gets the context one - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = $context->shop->id; // if we are in $shop_group context @@ -636,7 +636,7 @@ class StockAvailableCore extends ObjectModel $group_ok = false; // if there is no $id_shop, gets the context one - if (is_null($id_shop)) + if ($id_shop === null) $id_shop = $context->shop->id; $shop_group = new ShopGroup((int)Shop::getContextShopGroupID()); diff --git a/config/smartyfront.config.inc.php b/config/smartyfront.config.inc.php index c2f8f9e9d..8426ec0be 100644 --- a/config/smartyfront.config.inc.php +++ b/config/smartyfront.config.inc.php @@ -45,23 +45,23 @@ function smartyTranslate($params, &$smarty) if (isset($smarty->source) && (strpos($smarty->source->filepath, DIRECTORY_SEPARATOR.'override'.DIRECTORY_SEPARATOR) !== false)) $key = 'override_'.$key; - $lang_array = $_LANG; if ($params['mod']) return Translate::getModuleTranslation($params['mod'], $params['s'], $basename, $params['sprintf']); else if ($params['pdf']) return Translate::getPdfTranslation($params['s']); - if ($lang_array != null && isset($lang_array[$key])) - $msg = $lang_array[$key]; - elseif ($lang_array != null && isset($lang_array[Tools::strtolower($key)])) - $msg = $lang_array[Tools::strtolower($key)]; + if ($_LANG != null && isset($_LANG[$key])) + $msg = $_LANG[$key]; + elseif ($_LANG != null && isset($_LANG[Tools::strtolower($key)])) + $msg = $_LANG[Tools::strtolower($key)]; else $msg = $params['s']; if ($msg != $params['s']) $msg = $params['js'] ? addslashes($msg) : stripslashes($msg); - $msg = Translate::checkAndReplaceArgs($msg, $params['sprintf']); + if ($params['sprintf'] !== null) + $msg = Translate::checkAndReplaceArgs($msg, $params['sprintf']); return $params['js'] ? $msg : Tools::htmlentitiesUTF8($msg); } diff --git a/modules/blockreinsurance/blockreinsurance.php b/modules/blockreinsurance/blockreinsurance.php index ff0da4f84..6c98d74bb 100644 --- a/modules/blockreinsurance/blockreinsurance.php +++ b/modules/blockreinsurance/blockreinsurance.php @@ -45,49 +45,6 @@ class Blockreinsurance extends Module $this->displayName = $this->l('Bloc reinsurance'); $this->description = $this->l('Add a block to display more infos to reassure your customers'); - - $this->fields_list = array( - 'id_reinsurance' => array( - 'title' => $this->l('Id'), - 'width' => 120, - 'type' => 'text', - ), - 'text' => array( - 'title' => $this->l('Text'), - 'width' => 140, - 'type' => 'text', - 'filter_key' => 'a!lastname' - ), - ); - - if (Shop::isFeatureActive()) - $this->fields_list['id_shop'] = array('title' => $this->l('ID Shop'), 'align' => 'center', 'width' => 25, 'type' => 'int'); - - $this->fields_form[0]['form'] = array( - 'legend' => array( - 'title' => $this->l('Reinsurance new block'), - ), - 'input' => array( - array( - 'type' => 'file', - 'label' => $this->l('Image:'), - 'name' => 'image', - 'value' => true - ), - array( - 'type' => 'textarea', - 'label' => $this->l('Text:'), - 'lang' => true, - 'name' => 'text', - 'cols' => 40, - 'rows' => 10 - ) - ), - 'submit' => array( - 'title' => $this->l(' Save '), - 'class' => 'button' - ) - ); } public function install() @@ -254,6 +211,32 @@ class Blockreinsurance extends Module { $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); + $this->fields_form[0]['form'] = array( + 'legend' => array( + 'title' => $this->l('Reinsurance new block'), + ), + 'input' => array( + array( + 'type' => 'file', + 'label' => $this->l('Image:'), + 'name' => 'image', + 'value' => true + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Text:'), + 'lang' => true, + 'name' => 'text', + 'cols' => 40, + 'rows' => 10 + ) + ), + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ) + ); + $helper = new HelperForm(); $helper->module = $this; $helper->name_controller = 'blockreinsurance'; @@ -290,6 +273,23 @@ class Blockreinsurance extends Module protected function initList() { + $this->fields_list = array( + 'id_reinsurance' => array( + 'title' => $this->l('Id'), + 'width' => 120, + 'type' => 'text', + ), + 'text' => array( + 'title' => $this->l('Text'), + 'width' => 140, + 'type' => 'text', + 'filter_key' => 'a!lastname' + ), + ); + + if (Shop::isFeatureActive()) + $this->fields_list['id_shop'] = array('title' => $this->l('ID Shop'), 'align' => 'center', 'width' => 25, 'type' => 'int'); + $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = true; diff --git a/modules/favoriteproducts/FavoriteProduct.php b/modules/favoriteproducts/FavoriteProduct.php index 4b5b80dfb..830b550d0 100644 --- a/modules/favoriteproducts/FavoriteProduct.php +++ b/modules/favoriteproducts/FavoriteProduct.php @@ -96,6 +96,9 @@ class FavoriteProduct extends ObjectModel public static function isCustomerFavoriteProduct($id_customer, $id_product, Shop $shop = null) { + if (!$id_customer) + return false; + if (!$shop) $shop = Context::getContext()->shop;