mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
wip
This commit is contained in:
parent
df6718a31e
commit
331b49ff04
@ -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,6 +55,14 @@ 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())
|
||||
);
|
||||
|
||||
$this->build_email->setBody(
|
||||
TemplateEngine::wrapElementsIntoTables('<style></style><div id="content-wrapper"></div>', $this->build_email->getBody())
|
||||
);
|
||||
|
||||
$settings = $this->client->getMergedSettings();
|
||||
|
||||
$company = $this->client->company;
|
||||
@ -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())
|
||||
|
@ -198,46 +198,9 @@ class TemplateEngine
|
||||
$wrapper = str_replace('<head>', $injection, $wrapper);
|
||||
}
|
||||
|
||||
$documents['wrapper'] = new \DOMDocument();
|
||||
$documents['wrapper']->loadHTML($wrapper);
|
||||
|
||||
$styles = $documents['wrapper']->getElementsByTagName('style')->item(0)->nodeValue;
|
||||
|
||||
$documents['wrapper']->saveHTML();
|
||||
|
||||
$documents['body'] = new \DOMDocument();
|
||||
$documents['body']->loadHTML(empty($this->body) ? '<div></div>' : (new CssToInlineStyles())->convert($this->body, $styles));
|
||||
|
||||
$table_html ='
|
||||
<table style="font-family:arial,helvetica,sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="overflow-wrap:break-word;word-break:break-word;padding:5px;font-family:arial,helvetica,sans-serif;" align="left">
|
||||
<div style="color: #000000; line-height: 140%; text-align: left; word-wrap: break-word;" id="table-content"></div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>';
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
$body = $documents['wrapper']->getElementById('content-wrapper')->ownerDocument->saveHTML($documents['wrapper']->getElementById('content-wrapper'));
|
||||
|
||||
$data = [
|
||||
'subject' => $this->subject,
|
||||
'body' => $body,
|
||||
'body' => self::wrapElementsIntoTables(strtr($wrapper, ['$body' => '']), $this->body),
|
||||
'wrapper' => $wrapper,
|
||||
'raw_body' => $this->raw_body,
|
||||
'raw_subject' => $this->raw_subject
|
||||
@ -291,13 +254,43 @@ class TemplateEngine
|
||||
DB::rollBack();
|
||||
}
|
||||
|
||||
private static function cssToInlineStyles(string $css, string $html): ?string
|
||||
public static function wrapElementsIntoTables(string $wrapper, string $body): ?string
|
||||
{
|
||||
return (new CssToInlineStyles())->convert($html, $css);
|
||||
}
|
||||
$documents['wrapper'] = new \DOMDocument();
|
||||
$documents['wrapper']->loadHTML($wrapper);
|
||||
|
||||
private static function wrapElementsIntoTables()
|
||||
{
|
||||
$styles = $documents['wrapper']->getElementsByTagName('style')->item(0)->nodeValue;
|
||||
|
||||
$documents['wrapper']->saveHTML();
|
||||
|
||||
$documents['body'] = new \DOMDocument();
|
||||
$documents['body']->loadHTML(empty($body) ? '<div></div>' : (new CssToInlineStyles())->convert($body, $styles));
|
||||
|
||||
$table_html ='
|
||||
<table style="font-family:arial,helvetica,sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="overflow-wrap:break-word;word-break:break-word;padding:5px;font-family:arial,helvetica,sans-serif;" align="left">
|
||||
<div style="color: #000000; line-height: 140%; text-align: left; word-wrap: break-word;" id="table-content"></div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>';
|
||||
|
||||
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'));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user