From 20b4feda1ad0a6ca55cb1d544202cb07419acd45 Mon Sep 17 00:00:00 2001 From: Rafal Jania Date: Thu, 12 Oct 2023 11:52:24 +0200 Subject: [PATCH 01/10] [TASK] Add support for powermail 11 --- Classes/FieldValidator/PowermailValidator.php | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/Classes/FieldValidator/PowermailValidator.php b/Classes/FieldValidator/PowermailValidator.php index 88d2cc7..9de92c0 100644 --- a/Classes/FieldValidator/PowermailValidator.php +++ b/Classes/FieldValidator/PowermailValidator.php @@ -6,34 +6,26 @@ use In2code\Powermail\Domain\Validator\AbstractValidator; use StudioMitte\FriendlyCaptcha\Service\Api; -use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Error\Error; -use TYPO3\CMS\Extbase\Error\Result; class PowermailValidator extends AbstractValidator { /** * @param Mail $mail - * @return Result */ - public function validate($mail): Result + protected function isValid($mail): void { - $result = new Result(); if (!$this->isFormWithCaptchaField($mail) || $this->isCaptchaCheckToSkip()) { - return $result; + return; } $friendlyCaptchaService = GeneralUtility::makeInstance(Api::class); if (!$friendlyCaptchaService->verify()) { - $result->addError( - new Error( - $this->getLanguageService()->sL('LLL:EXT:friendlycaptcha_official/Resources/Private/Language/locallang.xlf:message.invalid'), - 1689157219 - ) + $this->addError( + $this->translateErrorMessage('message.invalid', 'friendlycaptcha_official'), + 1689157219, ); } - return $result; } protected function isFormWithCaptchaField($mail): bool @@ -70,9 +62,4 @@ protected function getActionName(): string $pluginVariables = GeneralUtility::_GPmerged('tx_powermail_pi1'); return $pluginVariables['action']; } - - private function getLanguageService(): LanguageService - { - return $GLOBALS['LANG']; - } } From 3e16641f4d30dd9acb96cec7e230b7405558ffcc Mon Sep 17 00:00:00 2001 From: Rafal Jania Date: Thu, 12 Oct 2023 13:48:49 +0200 Subject: [PATCH 02/10] [TASK] Add two powermail validators --- .../FieldValidator/PowermailV11Validator.php | 65 +++++++++++++++++++ Classes/FieldValidator/PowermailValidator.php | 25 +++++-- .../TypoScript/Powermail/setup.typoscript | 15 ++++- 3 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 Classes/FieldValidator/PowermailV11Validator.php diff --git a/Classes/FieldValidator/PowermailV11Validator.php b/Classes/FieldValidator/PowermailV11Validator.php new file mode 100644 index 0000000..3f277ce --- /dev/null +++ b/Classes/FieldValidator/PowermailV11Validator.php @@ -0,0 +1,65 @@ +isFormWithCaptchaField($mail) || $this->isCaptchaCheckToSkip()) { + return; + } + + $friendlyCaptchaService = GeneralUtility::makeInstance(Api::class); + if (!$friendlyCaptchaService->verify()) { + $this->addError( + $this->translateErrorMessage('message.invalid', 'friendlycaptcha_official'), + 1689157219, + ); + } + } + + protected function isFormWithCaptchaField($mail): bool + { + foreach ($mail->getForm()->getPages() as $page) { + foreach ($page->getFields() as $field) { + if ($field->getType() === 'friendlycaptcha') { + return true; + } + } + } + return false; + } + + /** + * Captcha check should be skipped on createAction if there was a confirmationAction where the captcha was + * already checked before + * Note: $this->flexForm is only available in powermail 3.9 or newer + */ + protected function isCaptchaCheckToSkip(): bool + { + if (property_exists($this, 'flexForm')) { + $confirmationActive = $this->flexForm['settings']['flexform']['main']['confirmation'] === '1'; + return $this->getActionName() === 'create' && $confirmationActive; + } + return false; + } + + /** + * @return string "confirmation" or "create" + */ + protected function getActionName(): string + { + $pluginVariables = GeneralUtility::_GPmerged('tx_powermail_pi1'); + return $pluginVariables['action']; + } +} diff --git a/Classes/FieldValidator/PowermailValidator.php b/Classes/FieldValidator/PowermailValidator.php index 9de92c0..2bdbc4b 100644 --- a/Classes/FieldValidator/PowermailValidator.php +++ b/Classes/FieldValidator/PowermailValidator.php @@ -6,26 +6,34 @@ use In2code\Powermail\Domain\Validator\AbstractValidator; use StudioMitte\FriendlyCaptcha\Service\Api; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Error\Error; +use TYPO3\CMS\Extbase\Error\Result; class PowermailValidator extends AbstractValidator { /** * @param Mail $mail + * @return Result */ - protected function isValid($mail): void + public function validate($mail): Result { + $result = new Result(); if (!$this->isFormWithCaptchaField($mail) || $this->isCaptchaCheckToSkip()) { - return; + return $result; } $friendlyCaptchaService = GeneralUtility::makeInstance(Api::class); if (!$friendlyCaptchaService->verify()) { - $this->addError( - $this->translateErrorMessage('message.invalid', 'friendlycaptcha_official'), - 1689157219, + $result->addError( + new Error( + $this->getLanguageService()->sL('LLL:EXT:friendlycaptcha_official/Resources/Private/Language/locallang.xlf:message.invalid'), + 1689157219 + ) ); } + return $result; } protected function isFormWithCaptchaField($mail): bool @@ -62,4 +70,9 @@ protected function getActionName(): string $pluginVariables = GeneralUtility::_GPmerged('tx_powermail_pi1'); return $pluginVariables['action']; } -} + + private function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } +} \ No newline at end of file diff --git a/Configuration/TypoScript/Powermail/setup.typoscript b/Configuration/TypoScript/Powermail/setup.typoscript index fec9e06..25cf71f 100644 --- a/Configuration/TypoScript/Powermail/setup.typoscript +++ b/Configuration/TypoScript/Powermail/setup.typoscript @@ -4,8 +4,19 @@ plugin.tx_powermail { 981818 = EXT:friendlycaptcha_official/Resources/Private/Powermail/Partials } } +} + +[typo3.branch == "12.4"] + plugin.tx_powermail.settings.setup.validators { + 981818 { + class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailV11Validator + config { - settings.setup.validators { + } + } + } +[ELSE] + plugin.tx_powermail.settings.setup.validators { 981818 { class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailValidator config { @@ -13,4 +24,4 @@ plugin.tx_powermail { } } } -} +[END] From cfb58785ddc0c89f57942ea7160b28172ed96a91 Mon Sep 17 00:00:00 2001 From: Rafal Jania Date: Mon, 16 Oct 2023 15:12:11 +0200 Subject: [PATCH 03/10] [TASK] Support for both powermail 10 & 11 --- Classes/FieldValidator/PowermailV11Validator.php | 2 +- Classes/FieldValidator/PowermailValidator.php | 5 +++++ Configuration/TypoScript/Powermail/setup.typoscript | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Classes/FieldValidator/PowermailV11Validator.php b/Classes/FieldValidator/PowermailV11Validator.php index 3f277ce..fee83a8 100644 --- a/Classes/FieldValidator/PowermailV11Validator.php +++ b/Classes/FieldValidator/PowermailV11Validator.php @@ -13,7 +13,7 @@ class PowermailV11Validator extends AbstractValidator /** * @param Mail $mail */ - protected function isValid($mail): void + public function isValid($mail): void { if (!$this->isFormWithCaptchaField($mail) || $this->isCaptchaCheckToSkip()) { return; diff --git a/Classes/FieldValidator/PowermailValidator.php b/Classes/FieldValidator/PowermailValidator.php index 2bdbc4b..800d4b9 100644 --- a/Classes/FieldValidator/PowermailValidator.php +++ b/Classes/FieldValidator/PowermailValidator.php @@ -36,6 +36,11 @@ public function validate($mail): Result return $result; } + public function isValid(mixed $mail): void + { + return; + } + protected function isFormWithCaptchaField($mail): bool { foreach ($mail->getForm()->getPages() as $page) { diff --git a/Configuration/TypoScript/Powermail/setup.typoscript b/Configuration/TypoScript/Powermail/setup.typoscript index 25cf71f..0ba23df 100644 --- a/Configuration/TypoScript/Powermail/setup.typoscript +++ b/Configuration/TypoScript/Powermail/setup.typoscript @@ -6,7 +6,7 @@ plugin.tx_powermail { } } -[typo3.branch == "12.4"] +[compatVersion("12.4")] plugin.tx_powermail.settings.setup.validators { 981818 { class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailV11Validator From bd1659c874b8007122e7e189ea8435c19859835c Mon Sep 17 00:00:00 2001 From: Rafal Jania Date: Wed, 18 Oct 2023 15:46:49 +0200 Subject: [PATCH 04/10] [BUGFIX] powermail validator condition --- .../TypoScript/Powermail/setup.typoscript | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Configuration/TypoScript/Powermail/setup.typoscript b/Configuration/TypoScript/Powermail/setup.typoscript index 0ba23df..50f5e42 100644 --- a/Configuration/TypoScript/Powermail/setup.typoscript +++ b/Configuration/TypoScript/Powermail/setup.typoscript @@ -4,24 +4,20 @@ plugin.tx_powermail { 981818 = EXT:friendlycaptcha_official/Resources/Private/Powermail/Partials } } -} - -[compatVersion("12.4")] - plugin.tx_powermail.settings.setup.validators { + settings.setup.validators { 981818 { - class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailV11Validator + class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailValidator config { } } } -[ELSE] +} + +[compatVersion("12.4")] plugin.tx_powermail.settings.setup.validators { 981818 { - class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailValidator - config { - - } + class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailV11Validator } } -[END] +[global] From 9d4126639766faba3f3c3120538bc45d3e1e408b Mon Sep 17 00:00:00 2001 From: Rafal Jania Date: Wed, 18 Oct 2023 16:01:29 +0200 Subject: [PATCH 05/10] [TASK] Plugin version up --- ext_emconf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_emconf.php b/ext_emconf.php index 50691e8..e214733 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -17,5 +17,5 @@ ], ], 'state' => 'beta', - 'version' => '0.0.1', + 'version' => '0.0.2', ]; From 1d9c9e56956433770568a9ab9dd3e84a7c9ad445 Mon Sep 17 00:00:00 2001 From: Rafal Jania Date: Thu, 19 Oct 2023 14:01:42 +0200 Subject: [PATCH 06/10] [FEATURE] Load ts and tsconfig automatically for powermail --- ext_localconf.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ext_localconf.php b/ext_localconf.php index 7f907cf..01650d2 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -21,6 +21,11 @@ '); } +if(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('powermail')) { + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup('@import "EXT:friendlycaptcha_official/Configuration/TypoScript/Powermail/setup.typoscript'); + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('@import "EXT:friendlycaptcha_official/Configuration/PageTsConfig/powermail.typoscript"'); +} + if (!isset($GLOBALS['TYPO3_CONF_VARS']['LOG']['StudioMitte']['FriendlyCaptcha']['writerConfiguration'])) { $GLOBALS['TYPO3_CONF_VARS']['LOG']['StudioMitte']['FriendlyCaptcha']['writerConfiguration'] = [ \TYPO3\CMS\Core\Log\LogLevel::WARNING => [ From 95785e35fa59d359075f77f31bc02eae9197ce95 Mon Sep 17 00:00:00 2001 From: Rafal Jania Date: Thu, 19 Oct 2023 14:03:06 +0200 Subject: [PATCH 07/10] [TASK] version up --- ext_emconf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_emconf.php b/ext_emconf.php index e214733..37d2b89 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -17,5 +17,5 @@ ], ], 'state' => 'beta', - 'version' => '0.0.2', + 'version' => '0.1.0', ]; From 68d2d7db48bfeba6aa7ba3ced8cc807fbc3f0065 Mon Sep 17 00:00:00 2001 From: Rafal Jania Date: Thu, 19 Oct 2023 14:20:52 +0200 Subject: [PATCH 08/10] [TASK] Fix csfixer --- Build/php-cs-fixer/php-cs-fixer.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Build/php-cs-fixer/php-cs-fixer.php b/Build/php-cs-fixer/php-cs-fixer.php index 30b10da..862b76f 100644 --- a/Build/php-cs-fixer/php-cs-fixer.php +++ b/Build/php-cs-fixer/php-cs-fixer.php @@ -25,18 +25,25 @@ '@PER' => true, 'array_syntax' => ['syntax' => 'short'], 'blank_line_after_opening_tag' => true, - 'braces' => ['allow_single_line_closure' => true], + 'single_space_around_construct' => true, + 'control_structure_braces' => true, + 'control_structure_continuation_position' => true, + 'declare_parentheses' => true, + 'no_multiple_statements_per_line' => true, + 'braces_position' => true, + 'statement_indentation' => true, + 'no_extra_blank_lines' => true, 'cast_spaces' => ['space' => 'none'], - 'compact_nullable_typehint' => true, + 'compact_nullable_type_declaration' => true, 'concat_space' => ['spacing' => 'one'], 'declare_equal_normalize' => ['space' => 'none'], 'dir_constant' => true, - 'function_typehint_space' => true, + 'type_declaration_spaces' => true, 'lowercase_cast' => true, 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], 'modernize_types_casting' => true, 'native_function_casing' => true, - 'new_with_braces' => true, + 'new_with_parentheses' => true, 'no_alias_functions' => true, 'no_blank_lines_after_phpdoc' => true, 'no_empty_phpdoc' => true, From 7da45c0fc2c8f101ca9736131cace45a42752fd5 Mon Sep 17 00:00:00 2001 From: Rafal Jania Date: Thu, 19 Oct 2023 14:21:12 +0200 Subject: [PATCH 09/10] [TASK] csfixer fix --- Classes/FieldValidator/PowermailValidator.php | 2 +- Tests/Unit/ViewHelpers/ConfigurationViewHelperTest.php | 4 +--- ext_localconf.php | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Classes/FieldValidator/PowermailValidator.php b/Classes/FieldValidator/PowermailValidator.php index 800d4b9..8e9e0ee 100644 --- a/Classes/FieldValidator/PowermailValidator.php +++ b/Classes/FieldValidator/PowermailValidator.php @@ -80,4 +80,4 @@ private function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } -} \ No newline at end of file +} diff --git a/Tests/Unit/ViewHelpers/ConfigurationViewHelperTest.php b/Tests/Unit/ViewHelpers/ConfigurationViewHelperTest.php index dbf1e37..d26cb60 100644 --- a/Tests/Unit/ViewHelpers/ConfigurationViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/ConfigurationViewHelperTest.php @@ -21,9 +21,7 @@ public function viewHelperReturnsProperConfiguration() self::setupRequest(); $renderingContext = new class () extends RenderingContext { - public function __construct() - { - } + public function __construct() {} }; self::assertSame([ 'languageIsoCode' => 'en', diff --git a/ext_localconf.php b/ext_localconf.php index 01650d2..e328034 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -21,7 +21,7 @@ '); } -if(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('powermail')) { +if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('powermail')) { \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup('@import "EXT:friendlycaptcha_official/Configuration/TypoScript/Powermail/setup.typoscript'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('@import "EXT:friendlycaptcha_official/Configuration/PageTsConfig/powermail.typoscript"'); } From 328491f22adb53bc8bf55434034ea1a51d7a1dc3 Mon Sep 17 00:00:00 2001 From: Rafal Jania Date: Thu, 19 Oct 2023 14:29:37 +0200 Subject: [PATCH 10/10] [TASK] fix csfixer --- Build/php-cs-fixer/php-cs-fixer.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Build/php-cs-fixer/php-cs-fixer.php b/Build/php-cs-fixer/php-cs-fixer.php index 862b76f..accb557 100644 --- a/Build/php-cs-fixer/php-cs-fixer.php +++ b/Build/php-cs-fixer/php-cs-fixer.php @@ -25,7 +25,6 @@ '@PER' => true, 'array_syntax' => ['syntax' => 'short'], 'blank_line_after_opening_tag' => true, - 'single_space_around_construct' => true, 'control_structure_braces' => true, 'control_structure_continuation_position' => true, 'declare_parentheses' => true, @@ -34,16 +33,14 @@ 'statement_indentation' => true, 'no_extra_blank_lines' => true, 'cast_spaces' => ['space' => 'none'], - 'compact_nullable_type_declaration' => true, 'concat_space' => ['spacing' => 'one'], 'declare_equal_normalize' => ['space' => 'none'], 'dir_constant' => true, - 'type_declaration_spaces' => true, + 'new_with_parentheses' => true, 'lowercase_cast' => true, 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], 'modernize_types_casting' => true, 'native_function_casing' => true, - 'new_with_parentheses' => true, 'no_alias_functions' => true, 'no_blank_lines_after_phpdoc' => true, 'no_empty_phpdoc' => true,