From 89cffb6b79e7f29ad447a163608d2c6471f8ba5c Mon Sep 17 00:00:00 2001 From: Fabio Stegmeyer Date: Thu, 17 Dec 2020 11:17:27 +0100 Subject: [PATCH 1/4] [TASK] Add mail preview function --- Classes/Controller/QueueController.php | 50 ++++- Classes/Service/MailTemplateService.php | 2 +- Resources/Private/Language/de.locallang.xlf | 28 +++ Resources/Private/Language/locallang.xlf | 21 ++ Resources/Private/Layouts/Preview.html | 7 + Resources/Private/Templates/Queue/Index.html | 187 ++++++++++-------- .../Private/Templates/Queue/Preview.html | 76 +++++++ Resources/Public/StyleSheets/preview.css | 34 ++++ ext_tables.php | 2 +- 9 files changed, 324 insertions(+), 83 deletions(-) create mode 100644 Resources/Private/Layouts/Preview.html create mode 100644 Resources/Private/Templates/Queue/Preview.html create mode 100644 Resources/Public/StyleSheets/preview.css diff --git a/Classes/Controller/QueueController.php b/Classes/Controller/QueueController.php index 9b1178d..ebb1a45 100644 --- a/Classes/Controller/QueueController.php +++ b/Classes/Controller/QueueController.php @@ -182,6 +182,52 @@ class QueueController extends ActionController { $this->redirect('index', NULL, NULL, $this->request->getArguments()); } + /** + * Preview for a mail + * + * @param int $uid + */ + public function previewAction($uid) { + $mailService = new MailTemplateService(); + $mailToPreview = $mailService->getMailObjectByUid($uid); + + $mailBody = $mailToPreview->getMailBody(); + + // Unsafe HTML tags and attributes + $unsafeTags = [ + '//is', + '//is', + '//is', + '//is', + '//is', + '//is', + '//is', + '//is', + '//is', + '//is', + '//is', + '//is', + '//is', + '/<\/body>/is', + '//is', + '/<\/head>/is', + '/onclick="(.*?)"/is', + '/onClick="(.*?)"/is', + '/onload="(.*?)"/is', + '/onLoad="(.*?)"/is', + '/onunload="(.*?)"/is', + '/onUnload="(.*?)"/is', + '//is', + '/<\/html>/is' + ]; + + // parse out unsafe tags and attributes + $parsedMailBody = preg_replace($unsafeTags, "", $mailBody); + + $this->view->assign('mail', $mailToPreview); + $this->view->assign('parsedMailBody', $parsedMailBody); + } + /** * Download the queue data as a csv file, respecting the filter settings * @@ -225,7 +271,9 @@ class QueueController extends ActionController { // save the Template filter to the session if (!isset($_SESSION[$this->session->getSessionKey()]['filterTemplate']) - || (isset($_POST['filterTemplate']) && $this->session->getDataByKey('filterTemplate') !== $_POST['filterTemplate'])) { + || (isset($_POST['filterTemplate']) && $this->session->getDataByKey( + 'filterTemplate' + ) !== $_POST['filterTemplate'])) { $this->session->setDataByKey('filterTemplate', $_POST['filterTemplate']); } diff --git a/Classes/Service/MailTemplateService.php b/Classes/Service/MailTemplateService.php index 83676e3..4ff4910 100644 --- a/Classes/Service/MailTemplateService.php +++ b/Classes/Service/MailTemplateService.php @@ -1263,7 +1263,7 @@ class MailTemplateService { * @param int $uid * @return bool|object */ - private function getMailObjectByUid($uid) { + public function getMailObjectByUid($uid) { if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) { /** @var MailRepository $mailRepository */ $mailRepository = $this->objectManager->get(MailRepository::class); diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 98b68fb..0ce62e0 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -589,6 +589,34 @@ Die Templates declined und approved der Extension sg_comments sind für alle Dom + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 779454c..0fd9432 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -441,6 +441,27 @@ The templates declined and approved of the sg_comments extension are blacklisted + + + + + + + + + + + + + + + + + + + + + diff --git a/Resources/Private/Layouts/Preview.html b/Resources/Private/Layouts/Preview.html new file mode 100644 index 0000000..380ad79 --- /dev/null +++ b/Resources/Private/Layouts/Preview.html @@ -0,0 +1,7 @@ +{namespace sgm=SGalinski\SgMail\ViewHelpers} + + + + + + diff --git a/Resources/Private/Templates/Queue/Index.html b/Resources/Private/Templates/Queue/Index.html index 78f27d7..e2093e1 100644 --- a/Resources/Private/Templates/Queue/Index.html +++ b/Resources/Private/Templates/Queue/Index.html @@ -1,91 +1,118 @@ {namespace sgm=SGalinski\SgMail\ViewHelpers} - + - + - +
- + - - - - - - - - + + + + + + + + + - - - - - + + + - - - + + + - + + + + + + +

-
: -
-

-
+ +
+ +
+ + : + +
+ +
+ +
+ +
- - - {mail.from_address} -
- {mail.to_address} -
- {mail.extension_key}: {mail.template_name} -
- - - {mail.mail_subject} - - -   - - + +
+ + + {mail.from_address} +
+ {mail.to_address} +
+ {mail.extension_key}: {mail.template_name} +
+ + + {mail.mail_subject} + + +   + + -
- {mail.crdate} -
- - - {mail.last_sending_time} - - - - - -
- - - - - - - - - + + {mail.crdate} +
+ + + {mail.last_sending_time} + + + + + +
+ + + + + + + + + + + - + - - - - - + +
@@ -93,27 +120,27 @@
- + - +
- - - - - + + + + +
- - - {page._thePathFull} - -
+ + + {page._thePathFull} + +
diff --git a/Resources/Private/Templates/Queue/Preview.html b/Resources/Private/Templates/Queue/Preview.html new file mode 100644 index 0000000..548eb1c --- /dev/null +++ b/Resources/Private/Templates/Queue/Preview.html @@ -0,0 +1,76 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + {mail.sendingTime} + +
+ + + {mail.fromName} + <{mail.fromAddress}> +
+ + + + {mail.mailSubject} + +
+ + + {mail.toAddress} +
+ + + {mail.ccAddresses} +
+ + + {mail.bccAddresses} +
+
+ +
+ + {parsedMailBody} + +
+
diff --git a/Resources/Public/StyleSheets/preview.css b/Resources/Public/StyleSheets/preview.css new file mode 100644 index 0000000..75b1770 --- /dev/null +++ b/Resources/Public/StyleSheets/preview.css @@ -0,0 +1,34 @@ +* { + font-family: Sans-Serif; +} + +body { + margin: 0; +} + +.mail-header { + border-bottom: 1px solid #666; + padding: 5px 7px; +} + +.mail-header tbody td { + width: 100%; + font-size: 16px; +} + +.mail-header tbody th { + white-space: nowrap; + text-align: right; + color: #666; + font-weight: normal; + font-size: 16px; +} + +.mail-header table td, +.mail-header table th { + padding: 2px 7px; +} + +.mail-body { + padding: 15px; +} diff --git a/ext_tables.php b/ext_tables.php index 2b892c3..e1195c7 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -32,7 +32,7 @@ call_user_func( '', [ 'Mail' => 'index, sendTestMail, empty, reset', - 'Queue' => 'index, sendMail, export', + 'Queue' => 'index, sendMail, export, preview', 'Configuration' => 'index, create, edit, delete', 'Layout' => 'index', 'Newsletter' => 'index, sendTestMail, empty', -- GitLab From 07a00cd739c12fad6b901abf7ca4a4d173cd4919 Mon Sep 17 00:00:00 2001 From: Fabio Stegmeyer Date: Fri, 18 Dec 2020 11:03:45 +0100 Subject: [PATCH 2/4] [TASK] Display preview in sandbox iframe --- Classes/Controller/QueueController.php | 41 ++----------------- .../Private/Templates/Queue/Preview.html | 4 +- Resources/Public/StyleSheets/preview.css | 8 +++- 3 files changed, 11 insertions(+), 42 deletions(-) diff --git a/Classes/Controller/QueueController.php b/Classes/Controller/QueueController.php index ebb1a45..893b354 100644 --- a/Classes/Controller/QueueController.php +++ b/Classes/Controller/QueueController.php @@ -187,45 +187,11 @@ class QueueController extends ActionController { * * @param int $uid */ - public function previewAction($uid) { + public function previewAction($uid): void { $mailService = new MailTemplateService(); $mailToPreview = $mailService->getMailObjectByUid($uid); - $mailBody = $mailToPreview->getMailBody(); - - // Unsafe HTML tags and attributes - $unsafeTags = [ - '//is', - '//is', - '//is', - '//is', - '//is', - '//is', - '//is', - '//is', - '//is', - '//is', - '//is', - '//is', - '//is', - '/<\/body>/is', - '//is', - '/<\/head>/is', - '/onclick="(.*?)"/is', - '/onClick="(.*?)"/is', - '/onload="(.*?)"/is', - '/onLoad="(.*?)"/is', - '/onunload="(.*?)"/is', - '/onUnload="(.*?)"/is', - '//is', - '/<\/html>/is' - ]; - - // parse out unsafe tags and attributes - $parsedMailBody = preg_replace($unsafeTags, "", $mailBody); - $this->view->assign('mail', $mailToPreview); - $this->view->assign('parsedMailBody', $parsedMailBody); } /** @@ -271,9 +237,8 @@ class QueueController extends ActionController { // save the Template filter to the session if (!isset($_SESSION[$this->session->getSessionKey()]['filterTemplate']) - || (isset($_POST['filterTemplate']) && $this->session->getDataByKey( - 'filterTemplate' - ) !== $_POST['filterTemplate'])) { + || (isset($_POST['filterTemplate']) + && $this->session->getDataByKey('filterTemplate') !== $_POST['filterTemplate'])) { $this->session->setDataByKey('filterTemplate', $_POST['filterTemplate']); } diff --git a/Resources/Private/Templates/Queue/Preview.html b/Resources/Private/Templates/Queue/Preview.html index 548eb1c..ee57f58 100644 --- a/Resources/Private/Templates/Queue/Preview.html +++ b/Resources/Private/Templates/Queue/Preview.html @@ -69,8 +69,6 @@
- - {parsedMailBody} - +
diff --git a/Resources/Public/StyleSheets/preview.css b/Resources/Public/StyleSheets/preview.css index 75b1770..890abb0 100644 --- a/Resources/Public/StyleSheets/preview.css +++ b/Resources/Public/StyleSheets/preview.css @@ -30,5 +30,11 @@ body { } .mail-body { - padding: 15px; + padding: 10px; +} + +.mail-body-iframe{ + border: none; + width:100vw; + height:100vh; } -- GitLab From 60e730c22bf865c91e8371c83be2d2a3240e1c97 Mon Sep 17 00:00:00 2001 From: Fabio Stegmeyer Date: Fri, 18 Dec 2020 11:04:32 +0100 Subject: [PATCH 3/4] [TASK] Fix buttons --- Resources/Private/Language/de.locallang.xlf | 4 ---- Resources/Private/Language/locallang.xlf | 3 --- Resources/Private/Templates/Queue/Index.html | 9 ++------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 0ce62e0..0bdcf04 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -613,10 +613,6 @@ Die Templates declined und approved der Extension sg_comments sind für alle Dom - - - - diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 0fd9432..5634e05 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -459,9 +459,6 @@ The templates declined and approved of the sg_comments extension are blacklisted - - - diff --git a/Resources/Private/Templates/Queue/Index.html b/Resources/Private/Templates/Queue/Index.html index e2093e1..c6480a2 100644 --- a/Resources/Private/Templates/Queue/Index.html +++ b/Resources/Private/Templates/Queue/Index.html @@ -39,7 +39,6 @@ - @@ -96,20 +95,16 @@ - +
- - -- GitLab From 195391a9f8e31a27984a120202f530ef35bcbac3 Mon Sep 17 00:00:00 2001 From: Fabio Stegmeyer Date: Fri, 18 Dec 2020 11:24:01 +0100 Subject: [PATCH 4/4] [TASK] Add max-width to preview, make header a bit smaller for better look --- Resources/Private/Templates/Queue/Index.html | 2 +- Resources/Public/StyleSheets/preview.css | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Resources/Private/Templates/Queue/Index.html b/Resources/Private/Templates/Queue/Index.html index c6480a2..c75f7ee 100644 --- a/Resources/Private/Templates/Queue/Index.html +++ b/Resources/Private/Templates/Queue/Index.html @@ -103,7 +103,7 @@ diff --git a/Resources/Public/StyleSheets/preview.css b/Resources/Public/StyleSheets/preview.css index 890abb0..0ff0c1f 100644 --- a/Resources/Public/StyleSheets/preview.css +++ b/Resources/Public/StyleSheets/preview.css @@ -13,7 +13,7 @@ body { .mail-header tbody td { width: 100%; - font-size: 16px; + font-size: 15px; } .mail-header tbody th { @@ -21,7 +21,7 @@ body { text-align: right; color: #666; font-weight: normal; - font-size: 16px; + font-size: 15px; } .mail-header table td, @@ -35,6 +35,7 @@ body { .mail-body-iframe{ border: none; - width:100vw; + width: 100%; + max-width: 1280px; height:100vh; } -- GitLab