diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php
index 68350ecb1298..8a85af8f5aeb 100644
--- a/app/Mail/TemplateEmail.php
+++ b/app/Mail/TemplateEmail.php
@@ -14,7 +14,9 @@ namespace App\Mail;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\User;
+use App\Services\PdfMaker\Designs\Utilities\DesignHelpers;
use App\Utils\HtmlEngine;
+use App\Utils\TemplateEngine;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
@@ -53,8 +55,16 @@ 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)
+ );
+
$company = $this->client->company;
if($this->invitation)
@@ -64,10 +74,10 @@ class TemplateEmail extends Mailable
}
else
$signature = $settings->email_signature;
-
+
$this->from(config('mail.from.address'), $this->company->present()->name());
-
- if (strlen($settings->bcc_email) > 1)
+
+ if (strlen($settings->bcc_email) > 1)
$this->bcc($settings->bcc_email, $settings->bcc_email);
$this->subject($this->build_email->getSubject())
diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php
index 3081a0c5595a..9f9e2e9033ed 100644
--- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php
+++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php
@@ -16,6 +16,7 @@ use App\Utils\Traits\MakesHash;
use DOMDocument;
use DOMXPath;
use Exception;
+use League\CommonMark\CommonMarkConverter;
trait DesignHelpers
{
@@ -308,4 +309,13 @@ trait DesignHelpers
$this->client
);
}
+
+ public static function parseMarkdownToHtml(string $markdown): ?string
+ {
+ $converter = new CommonMarkConverter([
+ 'allow_unsafe_links' => false,
+ ]);
+
+ return $converter->convertToHtml($markdown);
+ }
}
diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php
index 61f3601029f5..49b77217b171 100644
--- a/app/Utils/TemplateEngine.php
+++ b/app/Utils/TemplateEngine.php
@@ -16,6 +16,7 @@ use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Invoice;
use App\Models\InvoiceInvitation;
+use App\Services\PdfMaker\Designs\Utilities\DesignHelpers;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml;
@@ -24,6 +25,7 @@ use DB;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Lang;
use League\CommonMark\CommonMarkConverter;
+use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
class TemplateEngine
{
@@ -168,17 +170,12 @@ class TemplateEngine
$this->body = strtr($this->body, $data['labels']);
$this->body = strtr($this->body, $data['values']);
- $this->body = str_replace("\n", "
", $this->body);
-
+// $this->body = str_replace("\n", "
", $this->body);
$this->subject = strtr($this->subject, $data['labels']);
$this->subject = strtr($this->subject, $data['values']);
- $converter = new CommonMarkConverter([
- 'allow_unsafe_links' => false,
- ]);
-
- $this->body = $converter->convertToHtml($this->body);
+ $this->body = DesignHelpers::parseMarkdownToHtml($this->body);
}
private function renderTemplate()
@@ -209,7 +206,7 @@ class TemplateEngine
$data = [
'subject' => $this->subject,
- 'body' => $this->body,
+ 'body' => self::wrapElementsIntoTables(strtr($wrapper, ['$body' => '']), $this->body, $this->entity_obj->client->getMergedSettings()),
'wrapper' => $wrapper,
'raw_body' => $this->raw_body,
'raw_subject' => $this->raw_subject
@@ -262,4 +259,50 @@ class TemplateEngine
{
DB::rollBack();
}
+
+ public static function wrapElementsIntoTables(string $wrapper, string $body, $settings): ?string
+ {
+ $documents['wrapper'] = new \DOMDocument();
+ $documents['wrapper']->loadHTML($wrapper);
+
+ $documents['master'] = new \DOMDocument();
+
+ $documents['master']->loadHTML(
+ view('email.template.master', ['header' => '', 'slot' => '', 'settings' => $settings])->render()
+ );
+
+ $styles = $documents['master']->getElementsByTagName('style')->item(0)->nodeValue;
+
+ $documents['wrapper']->saveHTML();
+
+ $documents['body'] = new \DOMDocument();
+ $documents['body']->loadHTML(empty($body) ? '' : (new CssToInlineStyles())->convert($body, $styles));
+
+ $table_html ='
+ ';
+
+ foreach ($documents['body']->getElementsByTagName('body')->item(0)->childNodes as $element) {
+ $table = new \DOMDocument();
+
+ $table->loadHTML($table_html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
+
+ $element = $table->importNode($element, true);
+
+ $table->getElementById('table-content')->appendChild($element);
+
+ $node = $documents['wrapper']->importNode($table->documentElement, true);
+
+ $documents['wrapper']->getElementById('content-wrapper')->appendChild($node);
+ }
+
+ return $documents['wrapper']->getElementById('content-wrapper')->ownerDocument->saveHTML($documents['wrapper']->getElementById('content-wrapper'));
+ }
}
diff --git a/composer.json b/composer.json
index 29da3c0fb585..12254fd48628 100644
--- a/composer.json
+++ b/composer.json
@@ -65,6 +65,7 @@
"sentry/sentry-laravel": "^2",
"stripe/stripe-php": "^7.50",
"symfony/http-client": "^5.2",
+ "tijsverkoyen/css-to-inline-styles": "^2.2",
"turbo124/beacon": "^1.0",
"turbo124/laravel-gmail": "^5",
"webpatser/laravel-countries": "dev-master#75992ad",
diff --git a/composer.lock b/composer.lock
index 27906d3c6663..25bd1c789eee 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "7ccb8d2434343dfb0ba62866f0ee919a",
+ "content-hash": "f01381d3d00f0bd84acbda078ad1b99e",
"packages": [
{
"name": "authorizenet/authorizenet",
@@ -11718,103 +11718,6 @@
],
"time": "2021-01-25T15:34:13+00:00"
},
- {
- "name": "nunomaduro/larastan",
- "version": "v0.7.3",
- "source": {
- "type": "git",
- "url": "https://github.com/nunomaduro/larastan.git",
- "reference": "9c515d46851dca5a99fc82c0a69392c362b7affd"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/nunomaduro/larastan/zipball/9c515d46851dca5a99fc82c0a69392c362b7affd",
- "reference": "9c515d46851dca5a99fc82c0a69392c362b7affd",
- "shasum": ""
- },
- "require": {
- "composer/composer": "^1.0 || ^2.0",
- "ext-json": "*",
- "illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0",
- "illuminate/container": "^6.0 || ^7.0 || ^8.0 || ^9.0",
- "illuminate/contracts": "^6.0 || ^7.0 || ^8.0 || ^9.0",
- "illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0",
- "illuminate/http": "^6.0 || ^7.0 || ^8.0 || ^9.0",
- "illuminate/pipeline": "^6.0 || ^7.0 || ^8.0 || ^9.0",
- "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0",
- "mockery/mockery": "^0.9 || ^1.0",
- "php": "^7.2 || ^8.0",
- "phpstan/phpstan": "^0.12.83",
- "symfony/process": "^4.3 || ^5.0"
- },
- "require-dev": {
- "orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0",
- "phpunit/phpunit": "^7.3 || ^8.2 || ^9.3"
- },
- "suggest": {
- "orchestra/testbench": "^4.0 || ^5.0"
- },
- "type": "phpstan-extension",
- "extra": {
- "branch-alias": {
- "dev-master": "0.6-dev"
- },
- "phpstan": {
- "includes": [
- "extension.neon"
- ]
- }
- },
- "autoload": {
- "psr-4": {
- "NunoMaduro\\Larastan\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Nuno Maduro",
- "email": "enunomaduro@gmail.com"
- }
- ],
- "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel",
- "keywords": [
- "PHPStan",
- "code analyse",
- "code analysis",
- "larastan",
- "laravel",
- "package",
- "php",
- "static analysis"
- ],
- "support": {
- "issues": "https://github.com/nunomaduro/larastan/issues",
- "source": "https://github.com/nunomaduro/larastan/tree/v0.7.3"
- },
- "funding": [
- {
- "url": "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L",
- "type": "custom"
- },
- {
- "url": "https://github.com/canvural",
- "type": "github"
- },
- {
- "url": "https://github.com/nunomaduro",
- "type": "github"
- },
- {
- "url": "https://www.patreon.com/nunomaduro",
- "type": "patreon"
- }
- ],
- "time": "2021-04-12T11:01:46+00:00"
- },
{
"name": "openlss/lib-array2xml",
"version": "1.0.0",
@@ -12259,66 +12162,6 @@
},
"time": "2021-03-17T13:42:18+00:00"
},
- {
- "name": "phpstan/phpstan",
- "version": "0.12.83",
- "source": {
- "type": "git",
- "url": "https://github.com/phpstan/phpstan.git",
- "reference": "4a967cec6efb46b500dd6d768657336a3ffe699f"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan/zipball/4a967cec6efb46b500dd6d768657336a3ffe699f",
- "reference": "4a967cec6efb46b500dd6d768657336a3ffe699f",
- "shasum": ""
- },
- "require": {
- "php": "^7.1|^8.0"
- },
- "conflict": {
- "phpstan/phpstan-shim": "*"
- },
- "bin": [
- "phpstan",
- "phpstan.phar"
- ],
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "0.12-dev"
- }
- },
- "autoload": {
- "files": [
- "bootstrap.php"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "description": "PHPStan - PHP Static Analysis Tool",
- "support": {
- "issues": "https://github.com/phpstan/phpstan/issues",
- "source": "https://github.com/phpstan/phpstan/tree/0.12.83"
- },
- "funding": [
- {
- "url": "https://github.com/ondrejmirtes",
- "type": "github"
- },
- {
- "url": "https://www.patreon.com/phpstan",
- "type": "patreon"
- },
- {
- "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
- "type": "tidelift"
- }
- ],
- "time": "2021-04-03T15:35:45+00:00"
- },
{
"name": "phpunit/php-code-coverage",
"version": "9.2.6",
diff --git a/resources/views/email/template/master.blade.php b/resources/views/email/template/master.blade.php
index c9cfad3a08cb..93b15102580c 100644
--- a/resources/views/email/template/master.blade.php
+++ b/resources/views/email/template/master.blade.php
@@ -2,113 +2,303 @@
if(!isset($design)) {
$design = 'light';
}
+
$primary_color = isset($settings) ? $settings->primary_color : '#4caf50';
@endphp
-
-
-
+
+
-
-
+
+
+
+
+
+
+
-
+
+
+
+ {{ $header }}
+ |
+
+
-
-
-
-
-
-
-
- {{ $header }}
- |
-
-
-
-
-
-
- @yield('greeting')
+ |
+
+
+
- {{ $slot }}
+
+
+
+
+
+
+
+
- @yield('signature')
- @yield('footer')
- |
-
-
- |
-
-
- @isset($whitelabel)
- @if(!$whitelabel)
-
-
-
-
-
-
- |
- @endif
- @endif
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+ @yield('greeting')
+
+ {{ $slot }}
+
+ @yield('signature')
+ @yield('footer')
+
+
+
+
+
+
+
+
+
+ @isset($whitelabel)
+ @if(!$whitelabel)
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+ @endif
+ @endisset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+