diff --git a/Classes/Domain/Model/FormElements/CaptchaElement.php b/Classes/Domain/Model/FormElements/CaptchaElement.php
index 24834b1..99b85c5 100644
--- a/Classes/Domain/Model/FormElements/CaptchaElement.php
+++ b/Classes/Domain/Model/FormElements/CaptchaElement.php
@@ -5,10 +5,14 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
+use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
use TYPO3\CMS\Form\Domain\Model\FormElements\AbstractFormElement;
class CaptchaElement extends AbstractFormElement
{
+ /**
+ * @throws InvalidConfigurationTypeException
+ */
public function initializeFormElement(): void
{
parent::initializeFormElement();
diff --git a/Classes/Middleware/Audio.php b/Classes/Middleware/Audio.php
index a8cb216..3c4475e 100644
--- a/Classes/Middleware/Audio.php
+++ b/Classes/Middleware/Audio.php
@@ -44,7 +44,7 @@ public function process(
return $handler->handle($request);
}
- $languageCode = $request->getAttribute('language')->getTwoLetterIsoCode();
+ $languageCode = $request->getAttribute('language')?->getTwoLetterIsoCode() ?? '';
$body = $request->getParsedBody();
$ts = $this->configurationManager->getConfiguration(
diff --git a/Classes/Utility/AudioBuilderUtility.php b/Classes/Utility/AudioBuilderUtility.php
index e993643..093713d 100644
--- a/Classes/Utility/AudioBuilderUtility.php
+++ b/Classes/Utility/AudioBuilderUtility.php
@@ -50,7 +50,7 @@ public static function joinwavs(array $wavs): string
$info = unpack($fields, $header);
// read optional extra stuff
if (isset($info['Subchunk1Size']) && $info['Subchunk1Size'] > 16) {
- $header .= fread($fp, ($info['Subchunk1Size'] - 16));
+ $header .= fread($fp, max(0, (int)$info['Subchunk1Size'] - 16));
}
// read SubChunk2ID
$header .= fread($fp, 4);
diff --git a/Classes/Utility/CaptchaBuilderUtility.php b/Classes/Utility/CaptchaBuilderUtility.php
index 62ff866..69f91f8 100644
--- a/Classes/Utility/CaptchaBuilderUtility.php
+++ b/Classes/Utility/CaptchaBuilderUtility.php
@@ -98,7 +98,7 @@ public static function getRandomFontFileFromSettings(array $settings): ?string
// check 1: file storage path
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
try {
- $randomFontFile = $resourceFactory->retrieveFileOrFolderObject($fontFiles[0])->getPublicUrl();
+ $randomFontFile = $resourceFactory->retrieveFileOrFolderObject($fontFiles[0])?->getPublicUrl() ?? '';
$randomFontFile = Environment::getPublicPath() . $randomFontFile;
} catch (\Exception $e) {
}
diff --git a/Libraries/Captcha/composer.json b/Libraries/Captcha/composer.json
index 2d0752d..4b1ad58 100644
--- a/Libraries/Captcha/composer.json
+++ b/Libraries/Captcha/composer.json
@@ -1,6 +1,6 @@
{
"name": "gregwar/captcha",
- "type": "captcha",
+ "type": "library",
"description": "Captcha generator",
"keywords": ["captcha", "spam", "bot"],
"homepage": "https://github.com/Gregwar/Captcha",
diff --git a/Libraries/Captcha/src/Gregwar/Captcha/CaptchaBuilder.php b/Libraries/Captcha/src/Gregwar/Captcha/CaptchaBuilder.php
index fcdaa0c..ab8d93f 100644
--- a/Libraries/Captcha/src/Gregwar/Captcha/CaptchaBuilder.php
+++ b/Libraries/Captcha/src/Gregwar/Captcha/CaptchaBuilder.php
@@ -140,7 +140,7 @@ public function __construct($phrase = null, PhraseBuilderInterface $builder = nu
} else {
$this->builder = $builder;
}
-
+
$this->phrase = is_string($phrase) ? $phrase : $this->builder->build($phrase);
}
@@ -341,12 +341,12 @@ protected function writePhrase($image, $phrase, $font, $width, $height)
}
// Gets the text size and start position
- $size = $width / $length - $this->rand(0, 3) - 1;
+ $size = (int) round($width / $length) - $this->rand(0, 3) - 1;
$box = \imagettfbbox($size, 0, $font, $phrase);
$textWidth = $box[2] - $box[0];
$textHeight = $box[1] - $box[7];
- $x = ($width - $textWidth) / 2;
- $y = ($height - $textHeight) / 2 + $size;
+ $x = (int) round(($width - $textWidth) / 2);
+ $y = (int) round(($height - $textHeight) / 2) + $size;
if (!$this->textColor) {
$textColor = array($this->rand(0, 150), $this->rand(0, 150), $this->rand(0, 150));
@@ -362,7 +362,7 @@ protected function writePhrase($image, $phrase, $font, $width, $height)
$w = $box[2] - $box[0];
$angle = $this->rand(-$this->maxAngle, $this->maxAngle);
$offset = $this->rand(-$this->maxOffset, $this->maxOffset);
- \imagettftext($image, $size, $angle, (int)$x, (int)($y + $offset), $col, $font, $symbol);
+ \imagettftext($image, $size, $angle, $x, $y + $offset, $col, $font, $symbol);
$x += $w;
}
@@ -427,7 +427,6 @@ public function build($width = 150, $height = 40, $font = null, $fingerprint = n
$color = $this->backgroundColor;
$bg = imagecolorallocate($image, $color[0], $color[1], $color[2]);
}
- $this->background = $bg;
imagefill($image, 0, 0, $bg);
} else {
// use a random background image
@@ -605,7 +604,7 @@ protected function rand($min, $max)
$value = current($this->fingerprint);
next($this->fingerprint);
} else {
- $value = mt_rand($min, $max);
+ $value = mt_rand((int)$min, (int)$max);
$this->fingerprint[] = $value;
}
@@ -731,7 +730,6 @@ protected function createBackgroundImageFromType($backgroundImage, $imageType)
default:
throw new Exception('Not supported file type for background image!');
- break;
}
return $image;
diff --git a/README.md b/README.md
index 62879b7..bf16348 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
# Captcha extension for TYPO3 form
-This extension adds a captcha element for the TYPO3 form component. The captcha generation uses [Gregwar/Captcha](https://github.com/Gregwar/Captcha), **no Google or 3rd party** includes.
+This extension adds a captcha element for the TYPO3 form component. The captcha generation
+uses [Gregwar/Captcha](https://github.com/Gregwar/Captcha), **no Google or 3rd party** includes.
![Frontend Captcha example](Documentation/Images/Example.jpg)
@@ -11,7 +12,7 @@ This extension adds a captcha element for the TYPO3 form component. The captcha
## Usage
-Add the captcha element via Form Editor to your form or directly to your yaml form.
+Add the captcha element via Form Editor to your form or directly to your yaml form.
### Via Form Editor
@@ -21,14 +22,13 @@ Add the captcha element via Form Editor to your form or directly to your yaml fo
```yaml
renderables:
- -
- type: Captcha
- identifier: captcha
- label: Captcha
- properties:
- fluidAdditionalAttributes:
- required: required
- autocomplete: 'off'
+ - type: Captcha
+ identifier: captcha
+ label: Captcha
+ properties:
+ fluidAdditionalAttributes:
+ required: required
+ autocomplete: 'off'
```
### Configuration
@@ -43,49 +43,49 @@ plugin.tx_bwcaptcha {
# Show audio button for speech output
audioButton =
-
+
# The length of the captcha
length =
-
+
# The charset of the captcha
charset =
-
+
# The width of the image
width =
-
+
# The height of the image
height =
-
+
# Custom font file(s) to use (comma-separated)
fontFiles =
-
+
# Text color (e.g. 255,0,0)
textColor =
-
+
# Line color (e.g. 0,0,0)
lineColor =
-
+
# Background color (e.g. 255,255,255)
backgroundColor =
-
+
# Distortion
distortion =
-
+
# The maximum number of lines to draw in front of
maxFrontLines =
-
+
# The maximum number of lines to draw behind
maxBehindLines =
-
+
# The maximum angle of char
maxAngle =
-
+
# The maximum offset of char
maxOffset =
-
+
# Is the interpolation enabled?
interpolation =
-
+
# Ignore all effects
ignoreAllEffects =
}
@@ -94,7 +94,8 @@ plugin.tx_bwcaptcha {
### Overriding the captcha element
-To override the captcha partial, copy it to your extension and add the partial path to your [form setup](https://docs.typo3.org/c/typo3/cms-form/main/en-us/I/Concepts/Configuration/Index.html#yaml-registration-for-the-frontend):
+To override the captcha partial, copy it to your extension and add the partial path to
+your [form setup](https://docs.typo3.org/c/typo3/cms-form/main/en-us/I/Concepts/Configuration/Index.html#yaml-registration-for-the-frontend):
```yaml
TYPO3:
@@ -111,26 +112,32 @@ TYPO3:
## Migration from version 3.x to 4.x
-This version aims to make solving the captcha more accessible. It introduces a new audio feature that reads out the current captcha code. Missing `ARIA` properties have been added.
+This version aims to make solving the captcha more accessible. It introduces a new audio feature that reads out the
+current captcha code. Missing `ARIA` properties have been added.
-* Check out the [new captcha partial](https://github.com/maikschneider/bw_captcha/blob/master/Resources/Private/Frontend/Partials/Captcha.html)
+* Check out
+ the [new captcha partial](https://github.com/maikschneider/bw_captcha/blob/master/Resources/Private/Frontend/Partials/Captcha.html)
* Audio button is enabled by default (can be disabled via `plugin.tx_bwcaptcha.settings.audioButton`)
-## Migration from version 2.x to 3.x
+## Migration from version 2.x to 3.x
-The generation of the captcha moved to a middleware, which solves a lot of caching issues. Therefore, adjustments to the form element partial have been made. If you've modified the partial, you need to update the image tag and refresh button link.
+The generation of the captcha moved to a middleware, which solves a lot of caching issues. Therefore, adjustments to the
+form element partial have been made. If you've modified the partial, you need to update the image tag and refresh button
+link.
**tl;dr**:
-* Check out the [new captcha partial](https://github.com/maikschneider/bw_captcha/blob/master/Resources/Private/Frontend/Partials/Captcha.html)
+* Check out
+ the [new captcha partial](https://github.com/maikschneider/bw_captcha/blob/master/Resources/Private/Frontend/Partials/Captcha.html)
* Reload button is enabled by default (can be disabled via `plugin.tx_bwcaptcha.settings.refreshButton`)
-* You can re-enable the page cache, if disabled it because of this element
+* You can re-enable the page cache, if disabled it because of this element
## Troubleshooting
### Refresh button not working
-If your site is configured to use trailing slashes, the refresh url cannot be resolved. A simple fix is to add a setting for the pageType 3413, e.g.:
+If your site is configured to use trailing slashes, the refresh url cannot be resolved. A simple fix is to add a setting
+for the pageType 3413, e.g.:
```yaml
routeEnhancers:
diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf
index a8dc5ea..11c00f0 100644
--- a/Resources/Private/Language/de.locallang.xlf
+++ b/Resources/Private/Language/de.locallang.xlf
@@ -1,33 +1,33 @@
-
-
-
-
-
-
-
- Das eingegebene Captcha ist nicht korrekt.
-
-
-
- Captcha
-
-
-
- Neues Captcha laden
-
-
-
- Erneuern
-
-
-
- Captcha vorlesen
-
-
-
- Vorlesen
-
-
-
-
+
+
+
+
+
+
+
+ Das eingegebene Captcha ist nicht korrekt.
+
+
+
+ Captcha
+
+
+
+ Neues Captcha laden
+
+
+
+ Erneuern
+
+
+
+ Captcha vorlesen
+
+
+
+ Vorlesen
+
+
+
+
diff --git a/Resources/Private/Language/fr.locallang.xlf b/Resources/Private/Language/fr.locallang.xlf
index 4e5e046..eed1229 100644
--- a/Resources/Private/Language/fr.locallang.xlf
+++ b/Resources/Private/Language/fr.locallang.xlf
@@ -1,17 +1,17 @@
-
-
-
-
-
-
-
- Le captcha saisi n'est pas correct.
-
-
-
- Captcha
-
-
-
-
+
+
+
+
+
+
+
+ Le captcha saisi n'est pas correct.
+
+
+
+ Captcha
+
+
+
+
diff --git a/Resources/Private/Language/nl.locallang.xlf b/Resources/Private/Language/nl.locallang.xlf
index 366fcbe..e5ba5f0 100644
--- a/Resources/Private/Language/nl.locallang.xlf
+++ b/Resources/Private/Language/nl.locallang.xlf
@@ -1,17 +1,17 @@
-
-
-
-
-
-
-
- De ingevoerde captcha is niet correct.
-
-
-
- Captcha
-
-
-
-
+
+
+
+
+
+
+
+ De ingevoerde captcha is niet correct.
+
+
+
+ Captcha
+
+
+
+
diff --git a/composer.json b/composer.json
index b98c672..5fc7bd2 100644
--- a/composer.json
+++ b/composer.json
@@ -14,19 +14,13 @@
"MaikSchneider\\Steganography\\": "Libraries/Steganography/src"
}
},
- "repositories": [
- {
- "type": "git",
- "url": "https://github.com/linawolf/phpstan-typo3"
- }
- ],
"require-dev": {
"roave/security-advisories": "dev-latest",
"typo3/cms-base-distribution": "^12.0",
"typo3/cms-lowlevel": "^12.0",
"bk2k/bootstrap-package": "dev-master",
"friendsofphp/php-cs-fixer": "^3.12",
- "saschaegerer/phpstan-typo3": "12.0.x-dev",
+ "saschaegerer/phpstan-typo3": "^1.9",
"helhum/typo3-console": "^8.0"
},
"extra": {
diff --git a/ext_emconf.php b/ext_emconf.php
index a4f5a35..65444c7 100644
--- a/ext_emconf.php
+++ b/ext_emconf.php
@@ -9,7 +9,7 @@
'author_email' => 'maik.schneider@xima.de',
'state' => 'stable',
'clearCacheOnLoad' => true,
- 'version' => '4.0.1',
+ 'version' => '4.0.2',
'constraints' => [
'depends' => [
'typo3' => '11.0.0-13.99.99',