diff --git a/Build/php-cs-fixer/php-cs-fixer.php b/Build/php-cs-fixer/php-cs-fixer.php index 30b10da..accb557 100644 --- a/Build/php-cs-fixer/php-cs-fixer.php +++ b/Build/php-cs-fixer/php-cs-fixer.php @@ -25,18 +25,22 @@ '@PER' => true, 'array_syntax' => ['syntax' => 'short'], 'blank_line_after_opening_tag' => true, - 'braces' => ['allow_single_line_closure' => 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, 'concat_space' => ['spacing' => 'one'], 'declare_equal_normalize' => ['space' => 'none'], 'dir_constant' => true, - 'function_typehint_space' => 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_braces' => true, 'no_alias_functions' => true, 'no_blank_lines_after_phpdoc' => true, 'no_empty_phpdoc' => true, diff --git a/Classes/FieldValidator/PowermailV11Validator.php b/Classes/FieldValidator/PowermailV11Validator.php new file mode 100644 index 0000000..fee83a8 --- /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 88d2cc7..8e9e0ee 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 fec9e06..50f5e42 100644 --- a/Configuration/TypoScript/Powermail/setup.typoscript +++ b/Configuration/TypoScript/Powermail/setup.typoscript @@ -4,7 +4,6 @@ plugin.tx_powermail { 981818 = EXT:friendlycaptcha_official/Resources/Private/Powermail/Partials } } - settings.setup.validators { 981818 { class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailValidator @@ -14,3 +13,11 @@ plugin.tx_powermail { } } } + +[compatVersion("12.4")] + plugin.tx_powermail.settings.setup.validators { + 981818 { + class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailV11Validator + } + } +[global] 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_emconf.php b/ext_emconf.php index 50691e8..37d2b89 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -17,5 +17,5 @@ ], ], 'state' => 'beta', - 'version' => '0.0.1', + 'version' => '0.1.0', ]; diff --git a/ext_localconf.php b/ext_localconf.php index 7f907cf..e328034 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 => [