From 59b59d57b1910093cad0eea081df09b7e113599d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 8 Sep 2021 08:51:04 +0200 Subject: [PATCH 1/4] Ensure proper argument type --- .../ext/ep_track/Classes/Middleware/TrackingMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/typo3conf/ext/ep_track/Classes/Middleware/TrackingMiddleware.php b/public/typo3conf/ext/ep_track/Classes/Middleware/TrackingMiddleware.php index 0ab3839f..2a4f08e7 100644 --- a/public/typo3conf/ext/ep_track/Classes/Middleware/TrackingMiddleware.php +++ b/public/typo3conf/ext/ep_track/Classes/Middleware/TrackingMiddleware.php @@ -109,7 +109,7 @@ class TrackingMiddleware implements MiddlewareInterface /** @var SiteFinder $siteFinder */ $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); - $site = $siteFinder->getSiteByPageId($targetPage); + $site = $siteFinder->getSiteByPageId((int)$targetPage); $params = []; From 0a0788d360c8086f95f4a955f628eb6b287e1211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Wed, 8 Sep 2021 11:49:46 +0200 Subject: [PATCH 2/4] Make ep-track middleware failure-tolerant --- .../Classes/Middleware/TrackingMiddleware.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/public/typo3conf/ext/ep_track/Classes/Middleware/TrackingMiddleware.php b/public/typo3conf/ext/ep_track/Classes/Middleware/TrackingMiddleware.php index 0ab3839f..b21c408d 100644 --- a/public/typo3conf/ext/ep_track/Classes/Middleware/TrackingMiddleware.php +++ b/public/typo3conf/ext/ep_track/Classes/Middleware/TrackingMiddleware.php @@ -35,6 +35,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\Http\NormalizedParams; use TYPO3\CMS\Core\Http\RedirectResponse; use TYPO3\CMS\Core\Site\SiteFinder; @@ -107,9 +108,24 @@ class TrackingMiddleware implements MiddlewareInterface $targetPage = $redirect['target_page_uid']; $responseCode = $redirect['response_code']; + // Fallback for old t3:// links + if (1 === preg_match('/^t3:\/\/page\?uid=(\d+)$/', $targetPage, $matches)) { + $targetPage = $matches[1]; + } + + // Skip redirecting of non-numeric page uids like full urls + if (false === is_numeric($targetPage)) { + return null; + } + /** @var SiteFinder $siteFinder */ $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); - $site = $siteFinder->getSiteByPageId($targetPage); + try { + $site = $siteFinder->getSiteByPageId((int)$targetPage); + } + catch (SiteNotFoundException $exception) { + return null; + } $params = []; From 481f1d132b515b5fc64aa2ddafa43151acbf23d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Fri, 10 Sep 2021 10:00:18 +0200 Subject: [PATCH 3/4] Ensure proper type of argument --- .../ext/ep_products/Classes/Controller/AjaxSearchController.php | 2 +- .../typo3conf/ext/ep_products/Classes/Service/DateService.php | 2 +- .../ext/ep_products/Classes/Service/SearchResultUrlService.php | 2 +- .../ext/ep_theme/Classes/Controller/FormController.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Controller/AjaxSearchController.php b/public/typo3conf/ext/ep_products/Classes/Controller/AjaxSearchController.php index 6aeb00c3..3cf2e05e 100644 --- a/public/typo3conf/ext/ep_products/Classes/Controller/AjaxSearchController.php +++ b/public/typo3conf/ext/ep_products/Classes/Controller/AjaxSearchController.php @@ -125,7 +125,7 @@ class AjaxSearchController extends ActionController $referringPageUri = $this ->uriBuilder ->reset() - ->setTargetPageUid($this->settings['defaultSearchPageUid']) + ->setTargetPageUid((int)$this->settings['defaultSearchPageUid']) ->uriFor( 'searchresult', ['filterSettings' => $encodedFilterSettings], diff --git a/public/typo3conf/ext/ep_products/Classes/Service/DateService.php b/public/typo3conf/ext/ep_products/Classes/Service/DateService.php index fe64ba45..53b741c6 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/DateService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/DateService.php @@ -424,7 +424,7 @@ class DateService implements SingletonInterface $hotelUid = $row['hotelUid']; $hotelUri = $this->uriBuilder ->reset() - ->setTargetPageUid($row['hotelDetailPageUid']) + ->setTargetPageUid((int)$row['hotelDetailPageUid']) ->buildFrontendUri(); if (!array_key_exists($hotelUid, $priceTable[$categoryUid])) { diff --git a/public/typo3conf/ext/ep_products/Classes/Service/SearchResultUrlService.php b/public/typo3conf/ext/ep_products/Classes/Service/SearchResultUrlService.php index 91039a12..f31f24ce 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/SearchResultUrlService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/SearchResultUrlService.php @@ -72,7 +72,7 @@ class SearchResultUrlService implements SingletonInterface $uri = $this ->uriBuilder ->reset() - ->setTargetPageUid($detailPageUid) + ->setTargetPageUid((int)$detailPageUid) ->setCreateAbsoluteUri(true) ->uriFor('detail', $arguments, 'Product', 'epproducts', 'product_detail') ; diff --git a/public/typo3conf/ext/ep_theme/Classes/Controller/FormController.php b/public/typo3conf/ext/ep_theme/Classes/Controller/FormController.php index e5c08194..50d7acac 100644 --- a/public/typo3conf/ext/ep_theme/Classes/Controller/FormController.php +++ b/public/typo3conf/ext/ep_theme/Classes/Controller/FormController.php @@ -69,7 +69,7 @@ class FormController extends ActionController return $this->uriBuilder ->reset() ->setCreateAbsoluteUri(true) - ->setTargetPageUid($pageUid) + ->setTargetPageUid((int)$pageUid) ->build() ; } From 27c070aed1e2cba6b77ad1275ab3df1c22184df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Fri, 10 Sep 2021 10:38:49 +0200 Subject: [PATCH 4/4] Implement fluidemail --- .../Classes/Service/EmailService.php | 60 +++---------- .../Classes/Controller/AjaxFormController.php | 2 +- .../ep_theme/Classes/Service/EmailService.php | 88 ++++++------------- .../Private/Templates/Email/Autoreply.html | 2 +- .../Private/Templates/Email/ContactForm.html | 2 +- .../Private/Templates/Email/GroupsPrice.html | 2 +- .../typo3conf/ext/ep_theme/ext_localconf.php | 3 + 7 files changed, 49 insertions(+), 110 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Service/EmailService.php b/public/typo3conf/ext/ep_products/Classes/Service/EmailService.php index c05afe99..94bfda06 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/EmailService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/EmailService.php @@ -26,34 +26,25 @@ namespace EP\EpProducts\Service; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use Symfony\Component\Mime\Address; use Symfony\Component\OptionsResolver\OptionsResolver; -use TYPO3\CMS\Core\Mail\MailMessage; +use TYPO3\CMS\Core\Mail\FluidEmail; +use TYPO3\CMS\Core\Mail\Mailer; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; -use TYPO3\CMS\Fluid\View\StandaloneView; class EmailService implements SingletonInterface { - - /** - * @var ConfigurationManagerInterface - */ - protected $configurationManager; - /** * @var array */ protected $settings; - /** - * @param ConfigurationManagerInterface $manager - */ - public function injectConfigurationManager(ConfigurationManagerInterface $manager) + public function __construct(ConfigurationManagerInterface $manager) { - $this->configurationManager = $manager; $settings = GeneralUtility::removeDotsFromTS( - $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT) + $manager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT) ); $this->settings = $settings['plugin']['tx_eptheme']; } @@ -67,40 +58,17 @@ class EmailService implements SingletonInterface { $resolvedOptions = $this->resolveOptions($options); - /** @var MailMessage $message */ - $message = GeneralUtility::makeInstance(MailMessage::class); - $message - ->setTo([$resolvedOptions['toEmail'] => $resolvedOptions['toName']]) - ->setFrom([$resolvedOptions['fromEmail'] => $resolvedOptions['fromName']]) - ->setSubject($resolvedOptions['subject']) + /** @var FluidEmail $email */ + $email = GeneralUtility::makeInstance(FluidEmail::class); + $email + ->to(new Address($resolvedOptions['toEmail'], $resolvedOptions['toName'])) + ->from(new Address($resolvedOptions['fromEmail'], $resolvedOptions['fromName'])) + ->subject($resolvedOptions['subject']) + ->setTemplate($resolvedOptions['templateName']) + ->assignMultiple($variables) ; - $view = $this->getView($resolvedOptions['templateName']); - $view->assignMultiple($variables); - $message->setBody($view->render(), 'text/html'); - - return $message->send(); - } - - /** - * @param string $templateName - * @param string $format - * @return StandaloneView - */ - protected function getView($templateName, $format = 'html') - { - /** @var StandaloneView $view */ - $view = GeneralUtility::makeInstance(StandaloneView::class); - $view->setFormat($format); - - $view->setTemplateRootPaths($this->settings['view']['templateRootPaths']); - $view->setLayoutRootPaths($this->settings['view']['layoutRootPaths']); - $view->setPartialRootPaths($this->settings['view']['partialRootPaths']); - - $template = GeneralUtility::getFileAbsFileName('EXT:ep_theme/Resources/Private/Templates/Email/'.$templateName.'.'.$format); - $view->setTemplatePathAndFilename($template); - - return $view; + GeneralUtility::makeInstance(Mailer::class)->send($email); } /** diff --git a/public/typo3conf/ext/ep_theme/Classes/Controller/AjaxFormController.php b/public/typo3conf/ext/ep_theme/Classes/Controller/AjaxFormController.php index 5a119831..39202814 100644 --- a/public/typo3conf/ext/ep_theme/Classes/Controller/AjaxFormController.php +++ b/public/typo3conf/ext/ep_theme/Classes/Controller/AjaxFormController.php @@ -73,7 +73,7 @@ class AjaxFormController extends ActionController $this->settings['contactFormToEmail'], $this->settings['contactFormToName'], 'Kontaktformular E&P Reisen', - 'Email/ContactForm', + 'ContactForm', [ 'contactForm' => $contactForm ] ); diff --git a/public/typo3conf/ext/ep_theme/Classes/Service/EmailService.php b/public/typo3conf/ext/ep_theme/Classes/Service/EmailService.php index 267ddc0e..180804ee 100644 --- a/public/typo3conf/ext/ep_theme/Classes/Service/EmailService.php +++ b/public/typo3conf/ext/ep_theme/Classes/Service/EmailService.php @@ -26,33 +26,24 @@ namespace EP\EpTheme\Service; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use TYPO3\CMS\Core\Mail\MailMessage; +use Symfony\Component\Mime\Address; +use TYPO3\CMS\Core\Mail\FluidEmail; +use TYPO3\CMS\Core\Mail\Mailer; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; -use TYPO3\CMS\Fluid\View\StandaloneView; class EmailService implements SingletonInterface { - - /** - * @var ConfigurationManagerInterface - */ - protected $configurationManager; - /** * @var array */ protected $settings; - /** - * @param ConfigurationManagerInterface $manager - */ - public function injectConfigurationManager(ConfigurationManagerInterface $manager) + public function __construct(ConfigurationManagerInterface $manager) { - $this->configurationManager = $manager; $settings = GeneralUtility::removeDotsFromTS( - $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT) + $manager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT) ); $this->settings = $settings['plugin']['tx_eptheme']; } @@ -63,72 +54,49 @@ class EmailService implements SingletonInterface * @param string $subject * @param string $templateName * @param array $variables - * @return bool */ public function send($toEmail, $toName, $subject, $templateName, array $variables = []) { + /** @var Mailer $mailer */ + $mailer = GeneralUtility::makeInstance(Mailer::class); $fromEmail = $this->settings['settings']['contactFormToEmail']; $fromName = $this->settings['settings']['contactFormToName']; - $enableAutoreply = $this->settings['settings']['enableContactFormAutoreply']; + $enableAutoreply = (bool)$this->settings['settings']['enableContactFormAutoreply']; $autoreplySubject = $this->settings['settings']['contactFormAutoreplySubject']; - /** @var MailMessage $message */ - $message = GeneralUtility::makeInstance(MailMessage::class); + /** @var FluidEmail $message */ + $message = GeneralUtility::makeInstance(FluidEmail::class); $message - ->setTo([$toEmail => $toName]) - ->setFrom([$fromEmail => $fromName]) - ->setSubject($subject) + ->to(new Address($toEmail, $toName)) + ->from(new Address($fromEmail, $fromName)) + ->format('html') + ->subject($subject) + ->setTemplate($templateName) + ->assignMultiple($variables) ; - $view = $this->getView($templateName); - $view->assignMultiple($variables); - $message->setBody($view->render(), 'text/html'); - - $messageSent = $message->send(); - $autoreplySent = false; + $mailer->send($message); if ($enableAutoreply) { $contactForm = $variables['contactForm']; $toEmail = $contactForm->getEmail(); $toName = $contactForm->getName(); - $templateName = 'Email/Autoreply'; + $templateName = 'Autoreply'; - /** @var MailMessage $message */ - $message = GeneralUtility::makeInstance(MailMessage::class); + /** @var FluidEmail $message */ + $message = GeneralUtility::makeInstance(FluidEmail::class); $message - ->setTo([$toEmail => $toName]) - ->setFrom([$fromEmail => $fromName]) - ->setSubject($autoreplySubject) + ->to(new Address($toEmail, $toName)) + ->from(new Address($fromEmail, $fromName)) + ->format('html') + ->subject($autoreplySubject) + ->setTemplate($templateName) + ->assignMultiple($variables) ; - $view = $this->getView($templateName); - $view->assignMultiple($variables); - $message->setBody($view->render(), 'text/html'); - - $autoreplySent = $message->send(); + $mailer->send($message); } - return $messageSent && $autoreplySent; + return true; } - - /** - * @param string $templateName - * @param string $format - * @return StandaloneView - */ - protected function getView($templateName, $format = 'html') - { - /** @var StandaloneView $view */ - $view = GeneralUtility::makeInstance(StandaloneView::class); - $view->setFormat($format); - $view->getRequest()->setControllerExtensionName('ep_events'); - - $view->setTemplateRootPaths($this->settings['view']['templateRootPaths']); - $view->setLayoutRootPaths($this->settings['view']['layoutRootPaths']); - $view->setPartialRootPaths($this->settings['view']['partialRootPaths']); - $view->setTemplate($templateName); - - return $view; - } - } diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/Autoreply.html b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/Autoreply.html index 9a4cd583..cbb9c75b 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/Autoreply.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/Autoreply.html @@ -2,7 +2,7 @@ xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers" xmlns:f="http://typo3.org/ns/fluid/ViewHelpers"> - +

Sehr geehrte Damen und Herren,

diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/ContactForm.html b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/ContactForm.html index 8a7b1c8d..cacd7aec 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/ContactForm.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/ContactForm.html @@ -2,7 +2,7 @@ xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers" xmlns:f="http://typo3.org/ns/fluid/ViewHelpers"> - +

Anfrage E&P Reisen vom

diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/GroupsPrice.html b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/GroupsPrice.html index 6a165088..b3247f1b 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/GroupsPrice.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Email/GroupsPrice.html @@ -2,7 +2,7 @@ xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers" xmlns:f="http://typo3.org/ns/fluid/ViewHelpers"> - +

Anfrage Gruppenhaus vom

diff --git a/public/typo3conf/ext/ep_theme/ext_localconf.php b/public/typo3conf/ext/ep_theme/ext_localconf.php index 2858eafe..9a21f00c 100644 --- a/public/typo3conf/ext/ep_theme/ext_localconf.php +++ b/public/typo3conf/ext/ep_theme/ext_localconf.php @@ -22,6 +22,9 @@ $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] = 'tx_eptheme_slides'; $GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['default'] = 'EXT:ep_theme/Configuration/RTE/Default.yaml'; $GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['ep-reisen'] = 'EXT:ep_theme/Configuration/RTE/Default.yaml'; +$GLOBALS['TYPO3_CONF_VARS']['MAIL']['layoutRootPaths'][700] = 'EXT:ep_theme/Resources/Private/Layouts/Email/'; +$GLOBALS['TYPO3_CONF_VARS']['MAIL']['templateRootPaths'][700] = 'EXT:ep_theme/Resources/Private/Templates/Email/'; + $metaTagManagerRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry::class); $metaTagManagerRegistry->registerManager( 'ep_opengraph',