ContentPreprocessor.php
1 year ago
FontFamilyValidator.php
10 months ago
Renderer.php
10 months ago
Template.php
1 year ago
index.php
3 years ago
ContentPreprocessor.php
65 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\WooCommerce\TransactionalEmails; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Newsletter\Editor\LayoutHelper; |
| 9 | use MailPoet\WooCommerce\TransactionalEmails; |
| 10 | |
| 11 | class ContentPreprocessor { |
| 12 | public const WC_HEADING_PLACEHOLDER = '[mailpoet_woocommerce_heading_placeholder]'; |
| 13 | public const WC_CONTENT_PLACEHOLDER = '[mailpoet_woocommerce_content_placeholder]'; |
| 14 | |
| 15 | public const WC_HEADING_BEFORE = ' |
| 16 | <table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0"> |
| 17 | <tr> |
| 18 | <td class="mailpoet_text" valign="top" style="padding-top:20px;padding-bottom:20px;word-break:break-word;word-wrap:break-word;">'; |
| 19 | public const WC_HEADING_AFTER = ' |
| 20 | </td> |
| 21 | </tr> |
| 22 | </table>'; |
| 23 | |
| 24 | /** @var TransactionalEmails */ |
| 25 | private $transactionalEmails; |
| 26 | |
| 27 | public function __construct( |
| 28 | TransactionalEmails $transactionalEmails |
| 29 | ) { |
| 30 | $this->transactionalEmails = $transactionalEmails; |
| 31 | } |
| 32 | |
| 33 | public function preprocessContent() { |
| 34 | return $this->renderPlaceholderBlock(self::WC_CONTENT_PLACEHOLDER); |
| 35 | } |
| 36 | |
| 37 | public function preprocessHeader() { |
| 38 | $wcEmailSettings = $this->transactionalEmails->getWCEmailSettings(); |
| 39 | $content = self::WC_HEADING_BEFORE . '<h1 id="mailpoet-woo-email-header" style="color:' . $wcEmailSettings['base_text_color'] . ';">' . self::WC_HEADING_PLACEHOLDER . '</h1>' . self::WC_HEADING_AFTER; |
| 40 | return $this->renderTextBlock($content, ['backgroundColor' => $wcEmailSettings['base_color']]); |
| 41 | } |
| 42 | |
| 43 | private function renderTextBlock(string $text, array $styles = []): array { |
| 44 | return [ |
| 45 | LayoutHelper::row([ |
| 46 | LayoutHelper::col([[ |
| 47 | 'type' => 'text', |
| 48 | 'text' => $text, |
| 49 | ]]), |
| 50 | ], $styles), |
| 51 | ]; |
| 52 | } |
| 53 | |
| 54 | private function renderPlaceholderBlock(string $placeholder): array { |
| 55 | return [ |
| 56 | LayoutHelper::row([ |
| 57 | LayoutHelper::col([[ |
| 58 | 'type' => 'placeholder', |
| 59 | 'placeholder' => $placeholder, |
| 60 | ]]), |
| 61 | ]), |
| 62 | ]; |
| 63 | } |
| 64 | } |
| 65 |