Merge pull request #242 from shreesh-webkul/php-patch-1

Updating Core file for php 7 compatibility
This commit is contained in:
Rohit Jain
2021-10-14 18:00:59 +05:30
committed by GitHub
22 changed files with 46 additions and 101 deletions

View File

@@ -377,7 +377,7 @@ class Crypt_Blowfish
for ($i = 0; $i < 18; $i++) {
$data = 0;
for ($j = 4; $j > 0; $j--) {
$data = $data << 8 | ord($key{$k});
$data = $data << 8 | ord($key[$k]);
$k = ($k + 1) % $len;
}
$this->_P[$i] ^= $data;

View File

@@ -2632,6 +2632,9 @@ class CartCore extends ObjectModel
*/
public static function desintifier($int, $delimiter = ',')
{
if (!$int)
return;
$delimiter_len = $int[0];
$int = strrev(substr($int, 1));
$elm = explode(str_repeat('0', $delimiter_len + 1), $int);

View File

@@ -1220,7 +1220,7 @@ class CartRuleCore extends ObjectModel
if ($type == 'shop') {
$shops = Context::getContext()->employee->getAssociatedShops();
if (count($shops)) {
$shop_list = ' AND t.id_shop IN ('.implode(array_map('intval', $shops), ',').') ';
$shop_list = ' AND t.id_shop IN ('.implode(',', array_map('intval', $shops)).') ';
}
}

View File

@@ -180,7 +180,7 @@ class ConfigurationTestCore
public static function test_magicquotes()
{
return !get_magic_quotes_gpc();
return function_exists('get_magic_quotes_gpc') ? !get_magic_quotes_gpc() : true;
}
public static function test_upload()

View File

@@ -136,7 +136,7 @@ class ConnectionCore extends ObjectModel
'.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
ORDER BY `date_add` DESC';
$result = Db::getInstance()->getRow($sql, false);
if (!$result['id_guest'] && (int)$cookie->id_guest) {
if (!isset($result['id_guest']) && (int)$cookie->id_guest) {
// The old connections details are removed from the database in order to spare some memory
Connection::cleanConnectionsPages();

View File

@@ -66,7 +66,7 @@ class CookieCore
$this->_standalone = $standalone;
$this->_expire = is_null($expire) ? time() + 1728000 : (int)$expire;
$this->_path = trim(($this->_standalone ? '' : Context::getContext()->shop->physical_uri).$path, '/\\').'/';
if ($this->_path{0} != '/') {
if ($this->_path[0] != '/') {
$this->_path = '/'.$this->_path;
}
$this->_path = rawurlencode($this->_path);

View File

@@ -236,7 +236,7 @@ class ReferrerCore extends ObjectModel
if ($implode) {
$sql = 'SELECT COUNT(id_order) AS orders, SUM(total_paid_real / conversion_rate) AS sales
FROM '._DB_PREFIX_.'orders
WHERE id_order IN ('.implode($implode, ',').')
WHERE id_order IN ('.implode(',', $implode).')
'.Shop::addSqlRestriction(Shop::SHARE_ORDER).'
AND valid = 1';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);

View File

@@ -104,65 +104,7 @@ class ToolsCore
}
}
if (function_exists('mcrypt_create_iv')) {
$bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
if ($bytes !== false && strlen($bytes) === $length) {
return $bytes;
}
}
// Else try to get $length bytes of entropy.
// Thanks to Zend
$result = '';
$entropy = '';
$msec_per_round = 400;
$bits_per_round = 2;
$total = $length;
$hash_length = 20;
while (strlen($result) < $length) {
$bytes = ($total > $hash_length) ? $hash_length : $total;
$total -= $bytes;
for ($i=1; $i < 3; $i++) {
$t1 = microtime(true);
$seed = mt_rand();
for ($j=1; $j < 50; $j++) {
$seed = sha1($seed);
}
$t2 = microtime(true);
$entropy .= $t1 . $t2;
}
$div = (int) (($t2 - $t1) * 1000000);
if ($div <= 0) {
$div = 400;
}
$rounds = (int) ($msec_per_round * 50 / $div);
$iter = $bytes * (int) (ceil(8 / $bits_per_round));
for ($i = 0; $i < $iter; $i ++) {
$t1 = microtime();
$seed = sha1(mt_rand());
for ($j = 0; $j < $rounds; $j++) {
$seed = sha1($seed);
}
$t2 = microtime();
$entropy .= $t1 . $t2;
}
$result .= sha1($entropy, true);
}
return substr($result, 0, $length);
return false;
}
public static function strReplaceFirst($search, $replace, $subject, $cur = 0)
@@ -1822,10 +1764,10 @@ class ToolsCore
return Tools::strtoupper(Tools::substr($str, 0, 1)).Tools::substr($str, 1);
}
public static function ucwords($str)
public static function ucwords($str, $encoding = 'utf-8')
{
if (function_exists('mb_convert_case')) {
return mb_convert_case($str, MB_CASE_TITLE);
return mb_convert_case($str, MB_CASE_TITLE, $encoding);
}
return ucwords(Tools::strtolower($str));
}

View File

@@ -140,7 +140,7 @@ define('_PS_TMP_IMG_DIR_', _PS_IMG_DIR_.'tmp/');
define('_PS_TRANS_PATTERN_', '(.*[^\\\\])');
define('_PS_MIN_TIME_GENERATE_PASSWD_', '360');
if (!defined('_PS_MAGIC_QUOTES_GPC_')) {
define('_PS_MAGIC_QUOTES_GPC_', get_magic_quotes_gpc());
define('_PS_MAGIC_QUOTES_GPC_', function_exists('get_magic_quotes_gpc')? @get_magic_quotes_gpc() : false);
}
define('_CAN_LOAD_FILES_', 1);

View File

@@ -76,7 +76,7 @@ class AdminAttributeGeneratorControllerCore extends AdminController
protected static function createCombinations($list)
{
if (count($list) <= 1) {
return count($list) ? array_map(create_function('$v', 'return (array($v));'), $list[0]) : $list;
return count($list) ? array_map(function ($v) {return (array($v));}, $list[0]) : $list;
}
$res = array();
$first = array_pop($list);

View File

@@ -2925,7 +2925,9 @@ class AdminProductsControllerCore extends AdminController
public function renderForm()
{
// This nice code (irony) is here to store the product name, because the row after will erase product name in multishop context
$this->product_name = $this->object->name[$this->context->language->id];
if (Validate::isLoadedObject(($this->object))) {
$this->product_name = $this->object->name[$this->context->language->id];
}
if (!method_exists($this, 'initForm'.$this->tab_display)) {
return;

View File

@@ -36,7 +36,7 @@ class AdminShopControllerCore extends AdminController
$this->table = 'shop';
$this->className = 'Shop';
$this->multishop_context = Shop::CONTEXT_ALL;
$this->id_shop_group = (int)Tools::getValue('id_shop_group');
/* if $_GET['id_shop'] is transmitted, virtual url can be loaded in config.php, so we wether transmit shop_id in herfs */
@@ -250,7 +250,7 @@ class AdminShopControllerCore extends AdminController
elseif (Shop::getTotalShops() == 1)
$this->errors[] = Tools::displayError('You cannot disable the last shop.');
}*/
if (Tools::isSubmit('submitAddshopAndStay') || Tools::isSubmit('submitAddshop')) {
$shop_group = new ShopGroup((int)Tools::getValue('id_shop_group'));
if ($shop_group->shopNameExists(Tools::getValue('name'), (int)Tools::getValue('id_shop'))) {
@@ -475,7 +475,7 @@ class AdminShopControllerCore extends AdminController
$root_category = new Category($root_categories[0]['id_category']);
$children = $root_category->getAllChildren($this->context->language->id);
$selected_cat[] = $root_categories[0]['id_category'];
foreach ($children as $child) {
$selected_cat[] = $child->id;
}
@@ -576,7 +576,7 @@ class AdminShopControllerCore extends AdminController
'zone' => $this->l('Zones'),
'cart_rule' => $this->l('Cart rules'),
);
// Hook for duplication of shop data
$modules_list = Hook::getHookModuleExecList('actionShopDataDuplication');
if (is_array($modules_list) && count($modules_list) > 0) {
@@ -586,7 +586,7 @@ class AdminShopControllerCore extends AdminController
}
asort($import_data);
if (!$this->object->id) {
$this->fields_import_form = array(
'radio' => array(
@@ -615,9 +615,9 @@ class AdminShopControllerCore extends AdminController
$this->fields_value = array(
'id_shop_group' => (Tools::getValue('id_shop_group') ? Tools::getValue('id_shop_group') :
(isset($obj->id_shop_group)) ? $obj->id_shop_group : Shop::getContextShopGroupID()),
((isset($obj->id_shop_group)) ? $obj->id_shop_group : Shop::getContextShopGroupID())),
'id_category' => (Tools::getValue('id_category') ? Tools::getValue('id_category') :
(isset($obj->id_category)) ? $obj->id_category : (int)Configuration::get('PS_HOME_CATEGORY')),
((isset($obj->id_category)) ? $obj->id_category : (int)Configuration::get('PS_HOME_CATEGORY'))),
'id_theme_checked' => (isset($obj->id_theme) ? $obj->id_theme : $id_theme)
);
@@ -653,7 +653,7 @@ class AdminShopControllerCore extends AdminController
if (Tools::isSubmit('id_category_default')) {
$_POST['id_category'] = (int)Tools::getValue('id_category_default');
}
/* Checking fields validity */
$this->validateRules();
@@ -711,13 +711,13 @@ class AdminShopControllerCore extends AdminController
if (!array_key_exists('Edit', self::$cache_lang)) {
self::$cache_lang['Edit'] = $this->l('Edit', 'Helper');
}
$tpl->assign(array(
'href' => $this->context->link->getAdminLink('AdminShop').'&shop_id='.(int)$id.'&update'.$this->table,
'action' => self::$cache_lang['Edit'],
'id' => $id
));
return $tpl->fetch();
} else {
return;
@@ -738,7 +738,7 @@ class AdminShopControllerCore extends AdminController
$root_category = new Category($root_categories[0]['id_category']);
$children = $root_category->getAllChildren($this->context->language->id);
$selected_cat[] = $root_categories[0]['id_category'];
foreach ($children as $child) {
$selected_cat[] = $child->id;
}

View File

@@ -719,7 +719,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
}
$this->tpl_form_vars['products_list'] = $products;
$this->tpl_form_vars['product_ids'] = implode($product_ids, '|');
$this->tpl_form_vars['product_ids'] = implode('|', $product_ids);
$this->tpl_form_vars['product_ids_to_delete'] = '';
$this->tpl_form_vars['supplier_id'] = $supply_order->id_supplier;
$this->tpl_form_vars['currency'] = $currency;

View File

@@ -1019,7 +1019,7 @@ class AdminTranslationsControllerCore extends AdminController
$arr_good_ext = array('.tpl', '.php');
foreach ($files as $key => $file) {
if ($file{0} === '.' || in_array(substr($file, 0, strrpos($file, '.')), $this->all_iso_lang)) {
if ($file[0] === '.' || in_array(substr($file, 0, strrpos($file, '.')), $this->all_iso_lang)) {
unset($files[$key]);
} elseif ($type_clear === 'file' && !in_array(substr($file, strrpos($file, '.')), $arr_good_ext)) {
unset($files[$key]);
@@ -2872,7 +2872,7 @@ class AdminTranslationsControllerCore extends AdminController
$initial_root_dir = $root_dir;
foreach ($modules as $module) {
$root_dir = $initial_root_dir;
if ($module{0} == '.') {
if ($module[0] == '.') {
continue;
}

View File

@@ -86,7 +86,7 @@ class AddConfToFile
public function checkString($string)
{
if (get_magic_quotes_gpc()) {
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$string = stripslashes($string);
}
if (!is_numeric($string)) {

View File

@@ -25,7 +25,7 @@
*/
if (!defined('_PS_MAGIC_QUOTES_GPC_')) {
define('_PS_MAGIC_QUOTES_GPC_', get_magic_quotes_gpc());
define('_PS_MAGIC_QUOTES_GPC_', function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc());
}
if (!defined('_PS_MYSQL_REAL_ESCAPE_STRING_')) {
define('_PS_MYSQL_REAL_ESCAPE_STRING_', function_exists('mysql_real_escape_string'));

View File

@@ -1862,7 +1862,7 @@ class BlockLayered extends Module
break;
case 'manufacturer':
$query_filters_where .= ' AND p.id_manufacturer IN ('.implode($selected_filters['manufacturer'], ',').')';
$query_filters_where .= ' AND p.id_manufacturer IN ('.implode(',', $selected_filters['manufacturer']).')';
break;
case 'condition':
@@ -2005,7 +2005,7 @@ class BlockLayered extends Module
$this->products = array();
else
{
$product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE');
$product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int)$this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE');
$n = (int)Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE'));
$nb_day_new_product = (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20);
@@ -3049,8 +3049,8 @@ class BlockLayered extends Module
$query_filters = '';
else
{
array_walk($filter_value, create_function('&$id_manufacturer', '$id_manufacturer = (int)$id_manufacturer;'));
$query_filters = ' AND p.id_manufacturer IN ('.implode($filter_value, ',').')';
array_walk($filter_value, function (&$id_manufacturer) {$id_manufacturer = (int)$id_manufacturer;});
$query_filters = ' AND p.id_manufacturer IN ('.implode(',', $filter_value).')';
}
if ($ignore_join)
return array('where' => $query_filters);

View File

@@ -54,10 +54,8 @@ class HotelOrderRestrictDate extends ObjectModel
$obj_ord_rest = new self();
$order_restrict_data = $obj_ord_rest->getDataByHotelId($id_hotel);
$max_order_date_restr = $order_restrict_data['max_order_date'];
if (isset($max_order_date_restr) && $max_order_date_restr) {
$max_order_date = $max_order_date_restr;
if (isset($order_restrict_data['max_order_date']) && $order_restrict_data['max_order_date']) {
$max_order_date = $order_restrict_data['max_order_date'];
} elseif (isset($global_max_order_date) && $global_max_order_date) {
$max_order_date = $global_max_order_date;
} else {

View File

@@ -52,8 +52,8 @@ class Digest
$outerPad = str_repeat(chr(0x5C), 64);
for ($i = 0; $i < 20; $i++) {
$innerPad{$i} = $keyDigest{$i} ^ $innerPad{$i};
$outerPad{$i} = $keyDigest{$i} ^ $outerPad{$i};
$innerPad[$i] = $keyDigest[$i] ^ $innerPad[$i];
$outerPad[$i] = $keyDigest[$i] ^ $outerPad[$i];
}
return sha1($outerPad.pack($pack, sha1($innerPad.$message)));

View File

@@ -202,7 +202,7 @@ class Util
// every time this function is called.
static $callback = null;
if ($callback === null) {
$callback = create_function('$matches', 'return strtoupper($matches[1]);');
$callback = function ($matches) { return strtoupper($matches[1]); };
}
return preg_replace_callback('/' . $delimiter . '(\w)/', $callback, $string);

View File

@@ -2550,9 +2550,9 @@ class PayPal extends PaymentModule
// check digit-by-digit, if they have a difference, return 1 or -1 (greater/lower than)
for ($i = 0; $i < Tools::strlen($num1); $i++) {
if ((int) $num1{$i} > (int) $num2{$i}) {
if ((int) $num1[$i] > (int) $num2[$i]) {
return 1;
} elseif ((int) $num1{$i} < (int) $num2{$i}) {
} elseif ((int) $num1[$i] < (int) $num2[$i]) {
return -1;
}
@@ -2575,7 +2575,7 @@ class PayPal extends PaymentModule
'address_billing' => new Address($this->context->cart->id_address_invoice),
'cart' => $this->context->cart,
'patternRules' => array('avoid' => array()),
'cart_image_size' => version_compare(_PS_VERSION_, '1.5', '<') ? 'small' : version_compare(_PS_VERSION_, '1.6', '<') ? 'small_default' : 'cart_default',
'cart_image_size' => version_compare(_PS_VERSION_, '1.5', '<') ? 'small' : (version_compare(_PS_VERSION_, '1.6', '<') ? 'small_default' : 'cart_default'),
'useStyle14' => version_compare(_PS_VERSION_, '1.5', '<'),
'useStyle15' => version_compare(_PS_VERSION_, '1.5', '>') && version_compare(_PS_VERSION_, '1.6', '<'),
));

View File

@@ -89,7 +89,7 @@ class SEKeywords extends ModuleGraph
public function hookTop($params)
{
if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], Tools::getHttpHost(false, false) == 0)) {
if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], Tools::getHttpHost(false, false)) == 0) {
return;
}