Skip to content

Commit

Permalink
Merge branch 'release/35.11.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Jul 25, 2024
2 parents a978496 + 23619fa commit b6bfe1f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 42 deletions.
9 changes: 8 additions & 1 deletion Classes/Controller/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Throwable;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
Expand Down Expand Up @@ -193,11 +194,17 @@ public function email4LinkRequestAction(string $identificator, array $arguments)
);
$attributeTracker->addAttributes($values, $allowedFields);
}
try {
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$file = $resourceFactory->retrieveFileOrFolderObject($arguments['href']);
} catch (Throwable $exception) {
$file = null;
}
$downloadTracker = GeneralUtility::makeInstance(DownloadTracker::class, $visitor);
$downloadTracker->addDownload($arguments['href'], (int)$arguments['pageUid']);
if ($arguments['sendEmail'] === 'true') {
GeneralUtility::makeInstance(SendAssetEmail4LinkService::class, $visitor, $this->settings)
->sendMail($arguments['href']);
->sendMail($arguments['href'], $file);
}
return $this->jsonResponse(json_encode($this->afterAction($visitor)));
} catch (Throwable $exception) {
Expand Down
73 changes: 34 additions & 39 deletions Classes/Domain/Service/Email/SendAssetEmail4LinkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use In2code\Lux\Utility\UrlUtility;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Security\FileNameValidator;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -22,6 +23,8 @@
class SendAssetEmail4LinkService
{
protected ?Visitor $visitor = null;
protected ?File $file = null;
protected string $href = '';

/**
* TypoScript settings
Expand All @@ -43,42 +46,44 @@ public function __construct(Visitor $visitor, array $settings)

/**
* @param string $href
* @param File|null $file
* @return void
* @throws InvalidConfigurationTypeException
*/
public function sendMail(string $href): void
public function sendMail(string $href, ?File $file): void
{
$this->href = $href;
$this->file = $file;
if ($this->visitor->isNotBlacklisted()) {
if ($this->isActivatedAndAllowed($href)) {
$this->send($href);
if ($this->isActivatedAndAllowed()) {
$this->send();
$this->eventDispatcher->dispatch(
GeneralUtility::makeInstance(LogEmail4linkSendEmailEvent::class, $this->visitor, $href)
GeneralUtility::makeInstance(LogEmail4linkSendEmailEvent::class, $this->visitor, $this->href)
);
} else {
$this->eventDispatcher->dispatch(
GeneralUtility::makeInstance(LogEmail4linkSendEmailFailedEvent::class, $this->visitor, $href)
GeneralUtility::makeInstance(LogEmail4linkSendEmailFailedEvent::class, $this->visitor, $this->href)
);
}
}
}

/**
* @param string $href
* @return void
* @throws InvalidConfigurationTypeException
*/
protected function send(string $href): void
protected function send(): void
{
$message = GeneralUtility::makeInstance(MailMessage::class);
$message
->setTo([$this->visitor->getEmail() => 'Receiver'])
->setFrom($this->getSender())
->setSubject($this->getSubject())
->attachFromPath(GeneralUtility::getFileAbsFileName(UrlUtility::convertToRelative($href)))
->html($this->getMailTemplate($href));
->attachFromPath(GeneralUtility::getFileAbsFileName(UrlUtility::convertToRelative($this->href)))
->html($this->getMailTemplate());
$this->setBcc($message);
$this->eventDispatcher->dispatch(
GeneralUtility::makeInstance(SetAssetEmail4LinkEvent::class, $this->visitor, $message, $href)
GeneralUtility::makeInstance(SetAssetEmail4LinkEvent::class, $this->visitor, $message, $this->href)
);
$message->send();
}
Expand Down Expand Up @@ -106,20 +111,20 @@ protected function setBcc(MailMessage $message): void
}

/**
* @param string $href
* @return string
* @throws InvalidConfigurationTypeException
*/
protected function getMailTemplate(string $href): string
protected function getMailTemplate(): string
{
$mailTemplatePath = $this->configurationService->getTypoScriptSettingsByPath(
'identification.email4link.mail.mailTemplate'
);
$standaloneView = GeneralUtility::makeInstance(StandaloneView::class);
$standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($mailTemplatePath));
$standaloneView->assignMultiple([
'href' => $href,
'href' => $this->href,
'visitor' => $this->visitor,
'file' => $this->file,
]);
return $standaloneView->render();
}
Expand All @@ -144,14 +149,17 @@ protected function getSubject(): string
}

/**
* @param string $href
* @return bool
* @throws InvalidConfigurationTypeException
*/
protected function isActivatedAndAllowed(string $href): bool
protected function isActivatedAndAllowed(): bool
{
return $this->isEnabled() && $this->isAllowedFileExtension($href) && $this->isAllowedStorage($href)
&& $this->isNotMalicious($href) && $this->isFileExisting($href) && $this->visitor->isIdentified();
return $this->isEnabled()
&& $this->isAllowedFileExtension()
&& $this->isAllowedStorage()
&& $this->isNotMalicious()
&& $this->isFileExisting()
&& $this->visitor->isIdentified();
}

/**
Expand All @@ -165,14 +173,13 @@ protected function isEnabled(): bool
}

/**
* @param string $href
* @return bool
* @throws InvalidConfigurationTypeException
*/
protected function isAllowedFileExtension(string $href): bool
protected function isAllowedFileExtension(): bool
{
$allowed = false;
$thisExtension = StringUtility::getExtensionFromPathAndFilename($href);
$thisExtension = StringUtility::getExtensionFromPathAndFilename($this->href);
$extensionList = $this->configurationService->getTypoScriptSettingsByPath(
'identification.email4link.mail.allowedFileExtensions'
);
Expand All @@ -186,11 +193,7 @@ protected function isAllowedFileExtension(string $href): bool
return $allowed;
}

/**
* @param string $href
* @return bool
*/
protected function isAllowedStorage(string $href): bool
protected function isAllowedStorage(): bool
{
$allowed = false;
$storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
Expand All @@ -199,7 +202,7 @@ protected function isAllowedStorage(string $href): bool
if ($storage->isOnline()) {
$configuration = $storage->getConfiguration();
$basePath = $configuration['basePath'];
if (StringUtility::startsWith(UrlUtility::convertToRelative($href), $basePath)) {
if (StringUtility::startsWith(UrlUtility::convertToRelative($this->href), $basePath)) {
$allowed = true;
break;
}
Expand All @@ -208,22 +211,14 @@ protected function isAllowedStorage(string $href): bool
return $allowed;
}

/**
* @param string $href
* @return bool
*/
protected function isNotMalicious(string $href): bool
protected function isNotMalicious(): bool
{
return GeneralUtility::makeInstance(FileNameValidator::class)->isValid($href)
&& GeneralUtility::validPathStr($href);
return GeneralUtility::makeInstance(FileNameValidator::class)->isValid($this->href)
&& GeneralUtility::validPathStr($this->href);
}

/**
* @param string $href
* @return bool
*/
protected function isFileExisting(string $href): bool
protected function isFileExisting(): bool
{
return file_exists(GeneralUtility::getFileAbsFileName(UrlUtility::convertToRelative($href)));
return file_exists(GeneralUtility::getFileAbsFileName(UrlUtility::convertToRelative($this->href)));
}
}
1 change: 1 addition & 0 deletions Documentation/Technical/Changelog/Index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Double check if you have cleared all caches after installing a new LUX version t

| Version | Date | State | TYPO3 | Description |
|------------|------------|----------|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 35.11.0 | 2024-07-25 | Feature | `11.5 + 12.4` | Add {file} variable in Email4LinkMail.html email template for a better extendability |
| 35.10.0 | 2024-07-24 | Feature | `11.5 + 12.4` | Add quarter interval support in FilterDto to allow quarterly evaluation, added some unit tests |
| 35.9.0 | 2024-07-22 | Task | `11.5 + 12.4` | Extend available views for A/B testing controller, add new TypoScript constants settings to be able to set additional TypoScript only if LUX TS is loaded |
| 35.8.0 | 2024-07-18 | Feature | `11.5 + 12.4` | Add new event to extend ReadableReferrer class, bugfix for additional checkboxes in email4link popup |
Expand Down
16 changes: 15 additions & 1 deletion Resources/Private/Templates/Mail/Email4LinkMail.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
<f:comment>
Available variables:
- {href} like "fileadmin/file.pdf"
- {file} File object: {file.publicUrl} for complete URL, {file.name} for filename, etc...
- {visitor} Visitor object
</f:comment>
<h2>Your requested asset</h2>

<p>We have sent you the wanted whitepaper (see attachment). Please feel free to contact us if you have any questions.</p>
<p>
We have sent you the wanted whitepaper as attachment to this email.
<f:if condition="{file}">
You can also directly <f:link.typolink parameter="{file.publicUrl}" absolute="1">download the file</f:link.typolink>.
</f:if>
</p>
<p>
Please feel free to contact us if you have any questions.
</p>

<p>
--<br /><br />
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'description' => 'Living User Experience - LUX - the Marketing Automation tool for TYPO3.
Turn your visitors to leads. Identification and profiling of your visitors within your TYPO3 website.',
'category' => 'plugin',
'version' => '35.10.0',
'version' => '35.11.0',
'author' => 'Alex Kellner',
'author_email' => '[email protected]',
'author_company' => 'in2code.de',
Expand Down

0 comments on commit b6bfe1f

Please sign in to comment.