diff --git a/Classes/Domain/Service/Image/VisitorImageService.php b/Classes/Domain/Service/Image/VisitorImageService.php index a18f7976..a084a237 100644 --- a/Classes/Domain/Service/Image/VisitorImageService.php +++ b/Classes/Domain/Service/Image/VisitorImageService.php @@ -3,7 +3,10 @@ declare(strict_types=1); namespace In2code\Lux\Domain\Service\Image; +use In2code\Lux\Domain\Model\Visitor; +use In2code\Lux\Domain\Service\Provider\CustomerMail; use In2code\Lux\Utility\ConfigurationUtility; +use In2code\Lux\Utility\EmailUtility; use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; @@ -16,7 +19,7 @@ class VisitorImageService extends AbstractImageService public const CACHE_KEY = 'lux_visitor_imageurl'; protected int $size = 150; - public function __construct() + public function __construct(protected readonly CustomerMail $customerMail) { $this->cacheInstance = GeneralUtility::makeInstance(CacheManager::class)->getCache(self::CACHE_KEY); } @@ -28,11 +31,13 @@ public function __construct() */ protected function buildImageUrl(): string { + /** @var Visitor $visitor */ + $visitor = $this->arguments['visitor']; $url = ''; $url = $this->getImageUrlFromFrontenduser($url); $url = $this->getImageUrlFromGravatar($url); - if ($this->arguments['visitor']->isIdentified()) { - $url = $this->getImageFromBing($url, $this->arguments['visitor']->getEmail()); + if ($visitor->isIdentified() && $this->customerMail->isB2bEmail($visitor->getEmail())) { + $url = $this->getImageFromBing($url, EmailUtility::getDomainFromEmail($visitor->getEmail())); } $url = $this->getDefaultUrl($url); return $url; @@ -47,8 +52,8 @@ protected function getImageUrlFromFrontenduser(string $url): string $imageService = GeneralUtility::makeInstance(ImageService::class); $image = $imageService->getImage('', $file, false); $processConfiguration = [ - 'width' => (string)$this->size . 'c', - 'height' => (string)$this->size . 'c', + 'width' => $this->size . 'c', + 'height' => $this->size . 'c', ]; $processedImage = $imageService->applyProcessingInstructions($image, $processConfiguration); $url = $imageService->getImageUri($processedImage, true); diff --git a/Classes/Domain/Service/Provider/CustomerMail.php b/Classes/Domain/Service/Provider/CustomerMail.php new file mode 100644 index 00000000..cc7125c5 --- /dev/null +++ b/Classes/Domain/Service/Provider/CustomerMail.php @@ -0,0 +1,76 @@ +b2cEmailDomains) || $this->allowedMail->isEmailAllowed($email) === false; + } + + public function isB2bEmail(string $email): bool + { + return $this->isB2cEmail($email) === false; + } +} diff --git a/Classes/Utility/EmailUtility.php b/Classes/Utility/EmailUtility.php index 971d9d39..272f3348 100644 --- a/Classes/Utility/EmailUtility.php +++ b/Classes/Utility/EmailUtility.php @@ -13,4 +13,9 @@ public static function extendEmailReceiverArray(array $emails, string $receiverN } return $extendedArray; } + + public static function getDomainFromEmail(string $email): string + { + return strtolower(substr(strrchr($email, '@') ?: '', 1)); + } } diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 8bfcb67c..4ac3b80b 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -132,6 +132,12 @@ services: - name: event.listener identifier: 'lux/preventReferenceIndex' + In2code\Lux\Domain\Service\Image\VisitorImageService: + public: true + + In2code\Lux\Domain\Service\Provider\CustomerMail: + public: true + In2code\Lux\ViewHelpers\Lead\GetDateOfLatestPageVisitAndPageViewHelper: public: true diff --git a/Documentation/Technical/Installation/Index.md b/Documentation/Technical/Installation/Index.md index f10d4090..9697c275 100644 --- a/Documentation/Technical/Installation/Index.md +++ b/Documentation/Technical/Installation/Index.md @@ -63,7 +63,7 @@ If you click on the settings symbol for extension lux, you can change some basic | Advanced: Disable ckeditor configuration | Toggle if an automatic ckeditor configuration should be added or not (for email4link feature) | | Advanced: Disable ip logging | Disable the logging of the visitors IP address | | Advanced: Anonymize IP | As an alternative to disableIpLogging, you can anonymize the visitors IP-address when saving. The last part of the IP will be anonymized with "***" | -| Advanced: Lead picture | Decide if TYPO3 should try to find an image of a lead by searching on gravatar.com or on bing image search by given email address. | +| Advanced: Lead picture | Decide if TYPO3 should try to find an image of a lead by searching on gravatar.com (with hashed email) or on bing image search by given email domain (not full address). | | Advanced: Show render time | For an easier debugging all views in backend can be shown with render times. This is only visible for backend administrators. | | Advanced: Use cache layer | If you are facing performance issues with lux backend modules or with the page overview view (quick analysis), you can cache views (e.g. for 24h) when turning the feature on. In addition there is a command that can be executed via scheduler task to warmup caches (e.g. every night). | diff --git a/Tests/Unit/Utility/EmailUtilityTest.php b/Tests/Unit/Utility/EmailUtilityTest.php new file mode 100644 index 00000000..d85283eb --- /dev/null +++ b/Tests/Unit/Utility/EmailUtilityTest.php @@ -0,0 +1,72 @@ + 'receiver', + 'stefan@in2code.de' => 'receiver', + 'stefan.busemann@in2code.de' => 'receiver', + ], + ], + [ + [ + 'foobar@test.de', + 'foo@bar.co.uk', + ], + 'name', + [ + 'foobar@test.de' => 'name', + 'foo@bar.co.uk' => 'name', + ], + ], + ]; + } + + /** + * @param array $emails + * @param string|null $name + * @param array $expectedResult + * @return void + * @dataProvider extendEmailReceiverArrayDataProvider + * @covers ::extendEmailReceiverArray + */ + public function testExtendEmailReceiverArray(array $emails, ?string $name, array $expectedResult): void + { + if ($name !== null) { + $result = EmailUtility::extendEmailReceiverArray($emails, $name); + } else { + $result = EmailUtility::extendEmailReceiverArray($emails); + } + $this->assertSame($expectedResult, $result); + } + + /** + * @return void + * @covers ::getDomainFromEmail + */ + public function testGetDomainFromEmail(): void + { + $this->assertSame('in2code.de', EmailUtility::getDomainFromEmail('test@in2code.de')); + $this->assertSame('fuz.bayern', EmailUtility::getDomainFromEmail('foo.bar@fuz.bayern')); + $this->assertSame('', EmailUtility::getDomainFromEmail('')); + $this->assertSame('', EmailUtility::getDomainFromEmail('foobar')); + } +} diff --git a/ext_conf_template.txt b/ext_conf_template.txt index 0b1ead23..4317c697 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -46,7 +46,7 @@ disableIpLogging = 0 # cat=advanced/enable/240; type=boolean; label= Anonymize IP: As an alternative to disableIpLogging, you can anonymize the visitors IP-address when saving. The last part of the IP will be anonymized with "***". anonymizeIp = 1 -# cat=advanced/enable/250; type=options[all,nosearchengine,nogravatar,noexternal]; label= Lead pictures: Decide if TYPO3 should try to find an image of a lead by searching on gravatar.com or on bing image search by given email address. +# cat=advanced/enable/250; type=options[all,nosearchengine,nogravatar,noexternal]; label= Lead pictures: Decide if TYPO3 should try to find an image of a lead by searching on gravatar.com (with hashed email) or on bing image search by given email domain (not full address). leadImageFromExternalSources = all # cat=advanced/enable/260; type=boolean; label= Show render time: Show rendering times for all backend views for an easier performance debugging (only visible for administrators).