Merge pull request #6116 from beganovich/v5-2306-swap-bottom-text-for-signature

(v5) E-mail improvements
This commit is contained in:
Benjamin Beganović 2021-06-23 15:32:11 +02:00 committed by GitHub
commit cb338141eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 73 deletions

View File

@ -49,8 +49,11 @@ class TemplateEmail extends Mailable
public function build() public function build()
{ {
// $template_name = 'email.template.'.$this->build_email->getTemplate(); $template_name = 'email.template.'.$this->build_email->getTemplate();
$template_name = 'email.template.client';
if ($this->build_email->getTemplate() == 'light' || $this->build_email->getTemplate() == 'dark') {
$template_name = 'email.template.client';
}
if($this->build_email->getTemplate() == 'custom') { if($this->build_email->getTemplate() == 'custom') {
$this->build_email->setBody(str_replace('$body', $this->build_email->getBody(), $this->client->getSetting('email_style_custom'))); $this->build_email->setBody(str_replace('$body', $this->build_email->getBody(), $this->client->getSetting('email_style_custom')));
@ -62,10 +65,6 @@ class TemplateEmail extends Mailable
$this->build_email->setBody( $this->build_email->setBody(
DesignHelpers::parseMarkdownToHtml($this->build_email->getBody()) DesignHelpers::parseMarkdownToHtml($this->build_email->getBody())
); );
$this->build_email->setBody(
TemplateEngine::wrapElementsIntoTables('<div id="content-wrapper"></div>', $this->build_email->getBody(), $settings)
);
} }
$company = $this->client->company; $company = $this->client->company;

View File

@ -212,7 +212,7 @@ class TemplateEngine
} else { } else {
$wrapper = ''; $wrapper = '';
} }
} }
elseif ($email_style == 'plain') { elseif ($email_style == 'plain') {
$wrapper = view($this->getTemplatePath($email_style), $data)->render(); $wrapper = view($this->getTemplatePath($email_style), $data)->render();
$injection = ''; $injection = '';
@ -226,7 +226,7 @@ class TemplateEngine
$data = [ $data = [
'subject' => $this->subject, 'subject' => $this->subject,
'body' => $email_style == 'custom' ? $this->body : self::wrapElementsIntoTables(strtr('<div id="content-wrapper"></div>', ['$body' => '']), $this->body, $this->entity_obj->client->getMergedSettings()), 'body' => $this->body,
'wrapper' => $wrapper, 'wrapper' => $wrapper,
'raw_body' => $this->raw_body, 'raw_body' => $this->raw_body,
'raw_subject' => $this->raw_subject 'raw_subject' => $this->raw_subject
@ -279,50 +279,4 @@ class TemplateEngine
{ {
DB::rollBack(); 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) ? '<div></div>' : mb_convert_encoding((new CssToInlineStyles())->convert($body, $styles), 'HTML-ENTITIES', 'UTF-8'));
$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" class="content-contrast-color"></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'));
}
} }

View File

@ -236,7 +236,7 @@ $LANG = array(
'archived_vendors' => 'Successfully archived :count vendors', 'archived_vendors' => 'Successfully archived :count vendors',
'deleted_vendor' => 'Successfully deleted vendor', 'deleted_vendor' => 'Successfully deleted vendor',
'deleted_vendors' => 'Successfully deleted :count vendors', 'deleted_vendors' => 'Successfully deleted :count vendors',
'confirmation_subject' => 'Invoice Ninja Account Confirmation', 'confirmation_subject' => 'Account Confirmation',
'confirmation_header' => 'Account Confirmation', 'confirmation_header' => 'Account Confirmation',
'confirmation_message' => 'Please access the link below to confirm your account.', 'confirmation_message' => 'Please access the link below to confirm your account.',
'invoice_subject' => 'New invoice :number from :account', 'invoice_subject' => 'New invoice :number from :account',
@ -887,7 +887,7 @@ $LANG = array(
'custom_invoice_charges_helps' => 'Add a field when creating an invoice and include the charge in the invoice subtotals.', 'custom_invoice_charges_helps' => 'Add a field when creating an invoice and include the charge in the invoice subtotals.',
'token_expired' => 'Validation token was expired. Please try again.', 'token_expired' => 'Validation token was expired. Please try again.',
'invoice_link' => 'Invoice Link', 'invoice_link' => 'Invoice Link',
'button_confirmation_message' => 'Click to confirm your email address.', 'button_confirmation_message' => 'Click to confirm your email.',
'confirm' => 'Confirm', 'confirm' => 'Confirm',
'email_preferences' => 'Email Preferences', 'email_preferences' => 'Email Preferences',
'created_invoices' => 'Successfully created :count invoice(s)', 'created_invoices' => 'Successfully created :count invoice(s)',

View File

@ -25,7 +25,7 @@
@endisset @endisset
@isset($signature) @isset($signature)
{!! $signature !!} {!! nl2br($signature) !!}
@endisset @endisset
</div> </div>
@endcomponent @endcomponent

View File

@ -90,6 +90,10 @@
#content .center { #content .center {
text-align: center; text-align: center;
} }
#content .left {
text-align: left !important;
}
</style> </style>
</head> </head>
@ -116,15 +120,11 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<div style="border: 1px solid #c2c2c2; border-top: none; border-bottom: none; padding: 20px;" id="content"> <div style="border: 1px solid #c2c2c2; border-top: none; border-bottom: none; padding: 20px; text-align: center" id="content">
<div style="padding-top: 10px;"></div> <div style="padding-top: 10px;"></div>
{{ $slot ?? '' }} {{ $slot ?? '' }}
{!! $body ?? '' !!} {!! $body ?? '' !!}
@isset($signature)
{{ nl2br($signature) }}
@endisset
<div> <div>
<a href="#" <a href="#"
@ -135,24 +135,27 @@
</td> </td>
</tr> </tr>
@if(isset($company) && $company instanceof \App\Models\Company)
<tr> <tr>
<td> <td>
<div class="dark-bg dark-text-white" <div class="dark-bg dark-text-white"
style="text-align: center; padding-top: 10px; padding-bottom: 25px; background-color: #f9f9f9; border: 1px solid #c2c2c2; border-top: none; border-bottom-color: #f9f9f9;"> style="text-align: center; padding-top: 10px; padding-bottom: 25px; background-color: #f9f9f9; border: 1px solid #c2c2c2; border-top: none; border-bottom-color: #f9f9f9;">
<p style="font-size: 15px; color: #2e2e2e; font-family: 'roboto', Arial, Helvetica, sans-serif; font-weight: 400; margin-bottom: 30px;"> @isset($signature)
{{ ctrans('texts.client_email_company_contact_label') }} <p style="font-size: 15px; color: #2e2e2e; font-family: 'roboto', Arial, Helvetica, sans-serif; font-weight: 400; margin-bottom: 30px;">
</p> {!! nl2br($signature) !!}
<p style="font-size: 15px; color: #2e2e2e; font-family: 'roboto', Arial, Helvetica, sans-serif; font-weight: 500; margin-bottom:0;"> </p>
{{ $company->present()->name() }}</p> @endisset
<p style="font-size: 15px; color: #2e2e2e; font-family: 'roboto', Arial, Helvetica, sans-serif; font-weight: 400; margin-top: 5px;">
<span>{{ $company->settings->phone }}</span> @if(isset($company) && $company instanceof \App\Models\Company)
<span style="font-weight: 500"> {{ $company->settings->website }}</span> <p style="font-size: 15px; color: #2e2e2e; font-family: 'roboto', Arial, Helvetica, sans-serif; font-weight: 500; margin-bottom:0;">
</p> {{ $company->present()->name() }}</p>
<p style="font-size: 15px; color: #2e2e2e; font-family: 'roboto', Arial, Helvetica, sans-serif; font-weight: 400; margin-top: 5px;">
<span>{{ $company->settings->phone }}</span>
<span style="font-weight: 500"> {{ $company->settings->website }}</span>
</p>
@endif
</div> </div>
</td> </td>
</tr> </tr>
@endif
<tr> <tr>
<td> <td>