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);