From 6cb4d685839f1fd2115786aeb69ec8b693d5b422 Mon Sep 17 00:00:00 2001 From: Arnaud Rolland Date: Tue, 22 Dec 2020 11:08:29 +0100 Subject: [PATCH] chore: prestashop validator fixes --- alma/composer.lock | 525 +++++++++++++++++- .../controllers/admin/AdminAlmaCategories.php | 20 +- alma/controllers/front/payment.php | 10 +- .../hook/DisplayPaymentHookController.php | 2 +- ...DisplayProductPriceBlockHookController.php | 8 +- alma/views/js/alma-product.js | 23 + .../templates/hook/_partials/exclusionMsg.tpl | 2 +- .../templates/hook/excludedCategories.tpl | 6 +- 8 files changed, 561 insertions(+), 35 deletions(-) diff --git a/alma/composer.lock b/alma/composer.lock index a64286ab5..c9a0bd57c 100644 --- a/alma/composer.lock +++ b/alma/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "755d3be6005eed93ef8bb1b4f0e0e1ae", + "content-hash": "65b733c38170acc49a5cb2b4d120fb43", "packages": [ { "name": "alma/alma-php-client", - "version": "v1.0.11", + "version": "v1.0.13", "source": { "type": "git", "url": "https://github.com/alma/alma-php-client.git", - "reference": "bc7d362f0f7606369cc1ef5c04fbb05b1cc740db" + "reference": "e0439011226d695f252904e5c6123e52a38a1a9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/alma/alma-php-client/zipball/bc7d362f0f7606369cc1ef5c04fbb05b1cc740db", - "reference": "bc7d362f0f7606369cc1ef5c04fbb05b1cc740db", + "url": "https://api.github.com/repos/alma/alma-php-client/zipball/e0439011226d695f252904e5c6123e52a38a1a9d", + "reference": "e0439011226d695f252904e5c6123e52a38a1a9d", "shasum": "" }, "require": { @@ -50,7 +50,7 @@ } ], "description": "PHP API client for the Alma payments API", - "time": "2020-07-07T11:39:11+00:00" + "time": "2020-12-06T14:37:34+00:00" }, { "name": "psr/log", @@ -100,12 +100,521 @@ "time": "2020-09-18T06:44:51+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "nikic/php-parser", + "version": "3.x-dev", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "~4.0|~5.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "time": "2018-02-28T20:30:58+00:00" + }, + { + "name": "prestashop/autoindex", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PrestaShopCorp/autoindex.git", + "reference": "92e10242f94a99163dece280f6bd7b7c2b79c158" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PrestaShopCorp/autoindex/zipball/92e10242f94a99163dece280f6bd7b7c2b79c158", + "reference": "92e10242f94a99163dece280f6bd7b7c2b79c158", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^3.1", + "php": ">=5.6", + "symfony/console": "^3.4", + "symfony/finder": "^3.4" + }, + "bin": [ + "bin/autoindex" + ], + "type": "library", + "autoload": { + "psr-4": { + "PrestaShop\\AutoIndex\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AFL-3.0" + ], + "authors": [ + { + "name": "PrestaShop SA", + "email": "contact@prestashop.com" + } + ], + "description": "Automatically add an 'index.php' in all the current or specified directories and all sub-directories.", + "homepage": "https://github.com/PrestaShopCorp/autoindex", + "time": "2020-03-11T13:37:03+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "9bcb29cce831a8f9b2c8aee0bba1a57445f9dbf1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/9bcb29cce831a8f9b2c8aee0bba1a57445f9dbf1", + "reference": "9bcb29cce831a8f9b2c8aee0bba1a57445f9dbf1", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2020-12-15T02:38:00+00:00" + }, + { + "name": "symfony/console", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "a10b1da6fc93080c180bba7219b5ff5b7518fe81" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/a10b1da6fc93080c180bba7219b5ff5b7518fe81", + "reference": "a10b1da6fc93080c180bba7219b5ff5b7518fe81", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/debug": "~2.8|~3.0|~4.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.4", + "symfony/process": "<3.3" + }, + "provide": { + "psr/log-implementation": "1.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.3|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/event-dispatcher": "~2.8|~3.0|~4.0", + "symfony/lock": "~3.4|~4.0", + "symfony/process": "~3.3|~4.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-24T10:57:07+00:00" + }, + { + "name": "symfony/debug", + "version": "4.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "5dfc7825f3bfe9bb74b23d8b8ce0e0894e32b544" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/5dfc7825f3bfe9bb74b23d8b8ce0e0894e32b544", + "reference": "5dfc7825f3bfe9bb74b23d8b8ce0e0894e32b544", + "shasum": "" + }, + "require": { + "php": ">=7.1.3", + "psr/log": "~1.0", + "symfony/polyfill-php80": "^1.15" + }, + "conflict": { + "symfony/http-kernel": "<3.4" + }, + "require-dev": { + "symfony/http-kernel": "^3.4|^4.0|^5.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-12-10T16:34:26+00:00" + }, + { + "name": "symfony/finder", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "b6b6ad3db3edb1b4b1c1896b1975fb684994de6e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/b6b6ad3db3edb1b4b1c1896b1975fb684994de6e", + "reference": "b6b6ad3db3edb1b4b1c1896b1975fb684994de6e", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-11-16T17:02:08+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "401c9d9d3400c53a8f1a39425f0543406c137a43" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/401c9d9d3400c53a8f1a39425f0543406c137a43", + "reference": "401c9d9d3400c53a8f1a39425f0543406c137a43", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.21-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-26T13:35:45+00:00" + }, + { + "name": "symfony/polyfill-php80", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "3a11f3dfb34ad50f978cb2b8cf936933b87739aa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/3a11f3dfb34ad50f978cb2b8cf936933b87739aa", + "reference": "3a11f3dfb34ad50f978cb2b8cf936933b87739aa", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.21-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-26T13:35:45+00:00" + } + ], "aliases": [], "minimum-stability": "dev", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": [], - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" } diff --git a/alma/controllers/admin/AdminAlmaCategories.php b/alma/controllers/admin/AdminAlmaCategories.php index 27970ef54..f405452cd 100644 --- a/alma/controllers/admin/AdminAlmaCategories.php +++ b/alma/controllers/admin/AdminAlmaCategories.php @@ -92,9 +92,7 @@ public function init() { parent::init(); - $this->_select = ( - 'a.`id_category`, b.`name`, b.`description`, cpl.`name` as `parent`, a.`id_category` as `excluded`' - ); + $this->_select = ('a.`id_category`, b.`name`, b.`description`, cpl.`name` as `parent`, a.`id_category` as `excluded`'); $this->_use_found_rows = false; if (Shop::getContext() == Shop::CONTEXT_SHOP) { @@ -186,10 +184,8 @@ public function processFilter() foreach ($filters as $key => $value) { /* Extracting filters from $_POST on key filter_ */ - if ( - $value != null - && !strncmp($key, $prefix . $this->list_id . 'Filter_', 7 + Tools::strlen($prefix . $this->list_id)) - ) { + // phpcs:ignore + if ($value != null && !strncmp($key, $prefix . $this->list_id . 'Filter_', 7 + Tools::strlen($prefix . $this->list_id))) { $key = Tools::substr($key, 7 + Tools::strlen($prefix . $this->list_id)); /* Table alias could be specified using a ! eg. alias!field */ $tmp_tab = explode('!', $key); @@ -225,9 +221,7 @@ public function processFilter() 'Admin.Notifications.Error' ); } else { - $sql_filter .= ( - ' AND ' . pSQL($key) . ' >= \'' . pSQL(Tools::dateFrom($value[0])) . '\'' - ); + $sql_filter .= (' AND ' . pSQL($key) . ' >= \'' . pSQL(Tools::dateFrom($value[0])) . '\''); } } @@ -343,7 +337,7 @@ protected function processBulkEnable() } // need to force page refresh here for obscure reason - header('Location:' . $this->context->link->getAdminLink('AdminAlmaCategories')); + Tools::redirectAdmin($this->context->link->getAdminLink('AdminAlmaCategories')); } /** @@ -362,7 +356,7 @@ protected function processBulkDisable() } // need to force page refresh here for obscure reason - header('Location:' . $this->context->link->getAdminLink('AdminAlmaCategories')); + Tools::redirectAdmin($this->context->link->getAdminLink('AdminAlmaCategories')); } public static function getExcluded($id_category) @@ -386,7 +380,7 @@ public static function getDescriptionClean($description) if (version_compare(_PS_VERSION_, '1.7', '>=')) { return Tools::getDescriptionClean($description); } else { - return strip_tags(stripslashes($description)); + return strip_tags(Tools::stripslashes($description)); } } } diff --git a/alma/controllers/front/payment.php b/alma/controllers/front/payment.php index 5377245a4..e2679fb23 100644 --- a/alma/controllers/front/payment.php +++ b/alma/controllers/front/payment.php @@ -112,11 +112,11 @@ public function postProcess() } // Check that the selected installments count is indeed enabled - if ( - !Settings::isInstallmentPlanEnabled($installmentsCount) || - Settings::installmentPlanMinAmount($installmentsCount) > $data['payment']['purchase_amount'] || - Settings::installmentPlanMaxAmount($installmentsCount) < $data['payment']['purchase_amount'] - ) { + $disabled = !Settings::isInstallmentPlanEnabled($installmentsCount) + || Settings::installmentPlanMinAmount($installmentsCount) > $data['payment']['purchase_amount'] + || Settings::installmentPlanMaxAmount($installmentsCount) < $data['payment']['purchase_amount']; + + if ($disabled) { $this->genericErrorAndRedirect(); return; diff --git a/alma/controllers/hook/DisplayPaymentHookController.php b/alma/controllers/hook/DisplayPaymentHookController.php index 658c2c8e6..c7329ab9d 100644 --- a/alma/controllers/hook/DisplayPaymentHookController.php +++ b/alma/controllers/hook/DisplayPaymentHookController.php @@ -70,7 +70,7 @@ public function run($params) } $paymentButtonDescription = Settings::getPaymentButtonDescription(); - + $sortOrders = []; foreach ($installmentPlans as $plan) { $n = $plan->installmentsCount; if (!$plan->isEligible && Settings::isInstallmentPlanEnabled($n)) { diff --git a/alma/controllers/hook/DisplayProductPriceBlockHookController.php b/alma/controllers/hook/DisplayProductPriceBlockHookController.php index f3db20dee..22a2dbc6e 100644 --- a/alma/controllers/hook/DisplayProductPriceBlockHookController.php +++ b/alma/controllers/hook/DisplayProductPriceBlockHookController.php @@ -45,11 +45,11 @@ public function canRun() public function run($params) { + if (array_key_exists('type', $params)) { - if ( - (version_compare(_PS_VERSION_, '1.6.0', '>') && $params['type'] === 'price') || - (!in_array($params['type'], ['price', 'after_price'])) - ) { + $skip = (version_compare(_PS_VERSION_, '1.6.0', '>') && $params['type'] === 'price') || + (!in_array($params['type'], ['price', 'after_price'])); + if ($skip) { return null; } } diff --git a/alma/views/js/alma-product.js b/alma/views/js/alma-product.js index 630e67421..4d3b08ddb 100644 --- a/alma/views/js/alma-product.js +++ b/alma/views/js/alma-product.js @@ -1,3 +1,26 @@ +/** + * 2018-2020 Alma SAS + * + * THE MIT LICENSE + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * @author Alma SAS + * @copyright 2018-2020 Alma SAS + * @license https://opensource.org/licenses/MIT The MIT License + */ + (function ($) { $(function () { var selectors = window.__alma_widgetQuerySelectors; diff --git a/alma/views/templates/hook/_partials/exclusionMsg.tpl b/alma/views/templates/hook/_partials/exclusionMsg.tpl index 580312c45..0725ef9a0 100644 --- a/alma/views/templates/hook/_partials/exclusionMsg.tpl +++ b/alma/views/templates/hook/_partials/exclusionMsg.tpl @@ -21,5 +21,5 @@ * @license https://opensource.org/licenses/MIT The MIT License *} - + {$msg|escape:'html':'UTF-8'} diff --git a/alma/views/templates/hook/excludedCategories.tpl b/alma/views/templates/hook/excludedCategories.tpl index ceae5a544..a6ff895b8 100644 --- a/alma/views/templates/hook/excludedCategories.tpl +++ b/alma/views/templates/hook/excludedCategories.tpl @@ -1,5 +1,5 @@ {* - * 2018-2019 Alma SAS + * 2018-2020 Alma SAS * * THE MIT LICENSE * @@ -17,7 +17,7 @@ * IN THE SOFTWARE. * * @author Alma SAS - * @copyright 2018-2019 Alma SAS + * @copyright 2018-2020 Alma SAS * @license https://opensource.org/licenses/MIT The MIT License *} @@ -37,6 +37,6 @@

{l s='Categories currently excluded : ' mod='alma'} - {$excludedCategories} + {$excludedCategories|escape}