From ca15b03eda16a4993ca1455f721e314163fc94cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 21 Apr 2021 17:56:18 +0200 Subject: [PATCH 1/3] wip --- app/Utils/TemplateEngine.php | 4 ++ .../views/email/template/plain.blade.php | 57 ++++++------------- 2 files changed, 21 insertions(+), 40 deletions(-) diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index 33ee07c3c212..5780ec1b1da8 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -262,6 +262,10 @@ class TemplateEngine public static function wrapElementsIntoTables(string $wrapper, string $body, $settings): ?string { + $wrapper = $wrapper == strip_tags($wrapper) + ? '
' + : $wrapper; + $documents['wrapper'] = new \DOMDocument(); $documents['wrapper']->loadHTML($wrapper); diff --git a/resources/views/email/template/plain.blade.php b/resources/views/email/template/plain.blade.php index 910e93e31ad5..c896a646f184 100644 --- a/resources/views/email/template/plain.blade.php +++ b/resources/views/email/template/plain.blade.php @@ -8,47 +8,24 @@ Invoice Ninja - - +
+ {!! $body !!} +
+ +@if($signature) - -
- - - - - @if($signature) - - - - @endif - - @isset($whitelabel) - @if(!$whitelabel) - - @endif - @endif - -
- - - - -
- {!! $body !!} -
-
-

{!! $signature !!}

-
-

- - {{ __('texts.ninja_email_footer', ['site' => 'Invoice Ninja']) }} - -

-
+
+

{!! $signature !!}

- - - +@endif +@isset($whitelabel) + @if(!$whitelabel) +

+ + {{ __('texts.ninja_email_footer', ['site' => 'Invoice Ninja']) }} + +

+ @endif +@endisset From 6d0c2ec5ca51f34b25dd7492a8de2307954930a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 22 Apr 2021 12:29:00 +0200 Subject: [PATCH 2/3] wip --- app/Mail/TemplateEmail.php | 16 ++++++++------- app/Utils/TemplateEngine.php | 40 +++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 8a85af8f5aeb..f9e3196c2fe7 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -55,15 +55,17 @@ class TemplateEmail extends Mailable $this->build_email->setBody(str_replace('$body', $this->build_email->getBody(), $this->client->getSetting('email_style_custom'))); } - $this->build_email->setBody( - DesignHelpers::parseMarkdownToHtml($this->build_email->getBody()) - ); - $settings = $this->client->getMergedSettings(); - $this->build_email->setBody( - TemplateEngine::wrapElementsIntoTables('
', $this->build_email->getBody(), $settings) - ); + if ($this->build_email->getTemplate() !== 'custom') { + $this->build_email->setBody( + DesignHelpers::parseMarkdownToHtml($this->build_email->getBody()) + ); + + $this->build_email->setBody( + TemplateEngine::wrapElementsIntoTables('
', $this->build_email->getBody(), $settings) + ); + } $company = $this->client->company; diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index 5780ec1b1da8..d207bdaaf736 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -52,6 +52,10 @@ class TemplateEngine private $raw_body; private $raw_subject; + /** + * @var array + */ + private $labels_and_values; public function __construct($body, $subject, $entity, $entity_id, $template) { @@ -165,17 +169,24 @@ class TemplateEngine private function entityValues($contact) { + $this->labels_and_values = (new HtmlEngine($this->entity_obj->invitations->first()))->generateLabelsAndValues(); - $data = (new HtmlEngine($this->entity_obj->invitations->first()))->generateLabelsAndValues(); - - $this->body = strtr($this->body, $data['labels']); - $this->body = strtr($this->body, $data['values']); + $this->body = strtr($this->body, $this->labels_and_values['labels']); + $this->body = strtr($this->body, $this->labels_and_values['values']); // $this->body = str_replace("\n", "
", $this->body); - $this->subject = strtr($this->subject, $data['labels']); - $this->subject = strtr($this->subject, $data['values']); + $this->subject = strtr($this->subject, $this->labels_and_values['labels']); + $this->subject = strtr($this->subject, $this->labels_and_values['values']); - $this->body = DesignHelpers::parseMarkdownToHtml($this->body); + $email_style = $this->settings_entity->getSetting('email_style'); + + if ($email_style !== 'custom') { + $this->body = DesignHelpers::parseMarkdownToHtml($this->body); + } + + if ($email_style == 'custom') { + + } } private function renderTemplate() @@ -192,6 +203,11 @@ class TemplateEngine if ($email_style == 'custom') { $wrapper = $this->settings_entity->getSetting('email_style_custom'); + // In order to parse variables such as $signature in the body, + // we need to replace strings with the values from HTMLEngine. + + $wrapper = strtr($wrapper, $this->labels_and_values['values']); + /*If no custom design exists, send back a blank!*/ if (strlen($wrapper) > 1) { $wrapper = $this->renderView($wrapper, $data); @@ -204,9 +220,13 @@ class TemplateEngine $wrapper = str_replace('', $injection, $wrapper); } +// $body = $email_style == 'custom' +// ? $this->body +// : self::wrapElementsIntoTables(strtr($wrapper, ['$body' => '']), $this->body, $this->entity_obj->client->getMergedSettings()); + $data = [ 'subject' => $this->subject, - 'body' => self::wrapElementsIntoTables(strtr($wrapper, ['$body' => '']), $this->body, $this->entity_obj->client->getMergedSettings()), + 'body' => $this->body, 'wrapper' => $wrapper, 'raw_body' => $this->raw_body, 'raw_subject' => $this->raw_subject @@ -262,10 +282,6 @@ class TemplateEngine public static function wrapElementsIntoTables(string $wrapper, string $body, $settings): ?string { - $wrapper = $wrapper == strip_tags($wrapper) - ? '
' - : $wrapper; - $documents['wrapper'] = new \DOMDocument(); $documents['wrapper']->loadHTML($wrapper); From b9ee87b1246cbe22ec9b946d25c053ee779216b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 22 Apr 2021 13:03:30 +0200 Subject: [PATCH 3/3] wip --- app/Utils/TemplateEngine.php | 12 ++---------- resources/views/email/template/master.blade.php | 6 +++++- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index d207bdaaf736..f335d7604b46 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -183,10 +183,6 @@ class TemplateEngine if ($email_style !== 'custom') { $this->body = DesignHelpers::parseMarkdownToHtml($this->body); } - - if ($email_style == 'custom') { - - } } private function renderTemplate() @@ -220,13 +216,9 @@ class TemplateEngine $wrapper = str_replace('', $injection, $wrapper); } -// $body = $email_style == 'custom' -// ? $this->body -// : self::wrapElementsIntoTables(strtr($wrapper, ['$body' => '']), $this->body, $this->entity_obj->client->getMergedSettings()); - $data = [ 'subject' => $this->subject, - 'body' => $this->body, + 'body' => $email_style == 'custom' ? $this->body : self::wrapElementsIntoTables(strtr('
', ['$body' => '']), $this->body, $this->entity_obj->client->getMergedSettings()), 'wrapper' => $wrapper, 'raw_body' => $this->raw_body, 'raw_subject' => $this->raw_subject @@ -283,7 +275,7 @@ class TemplateEngine public static function wrapElementsIntoTables(string $wrapper, string $body, $settings): ?string { $documents['wrapper'] = new \DOMDocument(); - $documents['wrapper']->loadHTML($wrapper); + @$documents['wrapper']->loadHTML($wrapper); $documents['master'] = new \DOMDocument(); diff --git a/resources/views/email/template/master.blade.php b/resources/views/email/template/master.blade.php index 93b15102580c..8bbcde4d83ac 100644 --- a/resources/views/email/template/master.blade.php +++ b/resources/views/email/template/master.blade.php @@ -224,11 +224,15 @@
-
+
@yield('greeting') +
+
{{ $slot }} +
+
@yield('signature') @yield('footer')