From 3a0468879f106d6f6e25c7f38870bda4e5d29d3d Mon Sep 17 00:00:00 2001 From: Isabelle Date: Wed, 19 Nov 2025 13:43:08 +0100 Subject: [PATCH 1/2] FEAT: Add checks to prevent re-registering Smarty plugins --- .gitignore | 2 ++ is_themecore/src/Hook/Smarty.php | 50 +++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a906403 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +is_themecore/vendor/ diff --git a/is_themecore/src/Hook/Smarty.php b/is_themecore/src/Hook/Smarty.php index 70796a4..368380b 100644 --- a/is_themecore/src/Hook/Smarty.php +++ b/is_themecore/src/Hook/Smarty.php @@ -8,14 +8,48 @@ class Smarty extends AbstractHook 'actionDispatcherBefore', ]; - public function hookActionDispatcherBefore(): void +public function hookActionDispatcherBefore(): void { - $this->context->smarty->registerPlugin('function', 'generateImagesSources', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'generateImagesSources']); - $this->context->smarty->registerPlugin('function', 'generateImageSvgPlaceholder', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'generateImageSvgPlaceholder']); - $this->context->smarty->registerPlugin('function', 'appendParamToUrl', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'appendParamToUrl']); - $this->context->smarty->registerPlugin('block', 'images_block', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'imagesBlock']); - $this->context->smarty->registerPlugin('block', 'cms_images_block', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'cmsImagesBlock']); - $this->context->smarty->registerPlugin('block', 'display_mobile', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'displayMobileBlock']); - $this->context->smarty->registerPlugin('block', 'display_desktop', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'displayDesktopBlock']); + if (!isset($this->context->smarty->registered_plugins['function']['generateImagesSources'])) { + $this->context->smarty->registerPlugin('function', 'generateImagesSources', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'generateImagesSources']); + } else { + return; + } + + if (!isset($this->context->smarty->registered_plugins['function']['generateImageSvgPlaceholder'])) { + $this->context->smarty->registerPlugin('function', 'generateImageSvgPlaceholder', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'generateImageSvgPlaceholder']); + } else { + return; + } + + if (!isset($this->context->smarty->registered_plugins['function']['appendParamToUrl'])) { + $this->context->smarty->registerPlugin('function', 'appendParamToUrl', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'appendParamToUrl']); + } else { + return; + } + + if (!isset($this->context->smarty->registered_plugins['block']['images_block'])) { + $this->context->smarty->registerPlugin('block', 'images_block', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'imagesBlock']); + } else { + return; + } + + if (!isset($this->context->smarty->registered_plugins['block']['cms_images_block'])) { + $this->context->smarty->registerPlugin('block', 'cms_images_block', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'cmsImagesBlock']); + } else { + return; + } + + if (!isset($this->context->smarty->registered_plugins['block']['display_mobile'])) { + $this->context->smarty->registerPlugin('block', 'display_mobile', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'displayMobileBlock']); + } else { + return; + } + + if (!isset($this->context->smarty->registered_plugins['block']['display_desktop'])) { + $this->context->smarty->registerPlugin('block', 'display_desktop', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'displayDesktopBlock']); + } else { + return; + } } } From 60e57a5df6870d25da7c6ca249d02c8714d34ad8 Mon Sep 17 00:00:00 2001 From: Isabelle Date: Wed, 19 Nov 2025 17:17:10 +0100 Subject: [PATCH 2/2] fix: Add new IsBright helper to replace old Tools::GetBrightness This is used from prestashop itself but I needed to add it as a smarty helper --- is_themecore/src/Core/Smarty/SmartyHelperFunctions.php | 6 ++++++ is_themecore/src/Hook/Smarty.php | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php b/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php index ab209ff..a28ea5f 100644 --- a/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php +++ b/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php @@ -4,6 +4,7 @@ namespace Oksydan\Module\IsThemeCore\Core\Smarty; use Oksydan\Module\IsThemeCore\Core\Webp\WebpPictureGenerator; use Oksydan\Module\IsThemeCore\Form\Settings\WebpConfiguration; +use PrestaShop\PrestaShop\Core\Util\ColorBrightnessCalculator; class SmartyHelperFunctions { @@ -189,4 +190,9 @@ class SmartyHelperFunctions return $content; } + public static function isBright($hexColor) + { + $calculator = new ColorBrightnessCalculator(); + return $calculator->isBright($hexColor); + } } diff --git a/is_themecore/src/Hook/Smarty.php b/is_themecore/src/Hook/Smarty.php index 368380b..7a9fc00 100644 --- a/is_themecore/src/Hook/Smarty.php +++ b/is_themecore/src/Hook/Smarty.php @@ -51,5 +51,10 @@ public function hookActionDispatcherBefore(): void } else { return; } + if (!isset($this->context->smarty->registered_plugins['modifier']['is_bright'])) { + $this->context->smarty->registerPlugin('modifier', 'is_bright', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'isBright']); + } else { + return; + } } }