AbandonedCartContent.php
1 year ago
AutomatedLatestContentBlock.php
3 years ago
Button.php
1 year ago
Coupon.php
3 years ago
Divider.php
2 years ago
DynamicProductsBlock.php
11 months ago
Footer.php
2 months ago
Header.php
2 months ago
Image.php
3 years ago
Placeholder.php
4 years ago
Renderer.php
2 months ago
Social.php
2 months ago
Spacer.php
3 years ago
Text.php
2 months ago
index.php
3 years ago
Footer.php
66 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Newsletter\Renderer\Blocks; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Newsletter\NewsletterHtmlSanitizer; |
| 9 | use MailPoet\Newsletter\Renderer\EscapeHelper as EHelper; |
| 10 | use MailPoet\Newsletter\Renderer\StylesHelper; |
| 11 | use MailPoet\Util\pQuery\pQuery; |
| 12 | use MailPoet\WP\Functions as WPFunctions; |
| 13 | use MailPoetVendor\CSS; |
| 14 | |
| 15 | class Footer { |
| 16 | private NewsletterHtmlSanitizer $htmlSanitizer; |
| 17 | private WPFunctions $wp; |
| 18 | |
| 19 | public function __construct( |
| 20 | NewsletterHtmlSanitizer $htmlSanitizer, |
| 21 | WPFunctions $wp |
| 22 | ) { |
| 23 | $this->htmlSanitizer = $htmlSanitizer; |
| 24 | $this->wp = $wp; |
| 25 | } |
| 26 | |
| 27 | public function render($element, bool $isRtl = false) { |
| 28 | $element = StylesHelper::applyTextAlignment($element, $isRtl ? 'right' : 'left', 'text'); |
| 29 | $element['text'] = preg_replace('/\n/', '<br />', $element['text']); |
| 30 | $element['text'] = preg_replace('/(<\/?p.*?>)/i', '', $element['text']); |
| 31 | $lineHeight = sprintf( |
| 32 | '%spx', |
| 33 | StylesHelper::$defaultLineHeight * (int)$element['styles']['text']['fontSize'] |
| 34 | ); |
| 35 | if (!is_string($element['text'])) { |
| 36 | throw new \RuntimeException('$element[\'text\'] should be a string.'); |
| 37 | } |
| 38 | $dOMParser = new pQuery(); |
| 39 | $DOM = $dOMParser->parseStr($element['text']); |
| 40 | if (isset($element['styles']['link'])) { |
| 41 | $links = $DOM->query('a'); |
| 42 | if ($links->count()) { |
| 43 | $css = new CSS(); |
| 44 | foreach ($links as $link) { |
| 45 | $elementLinkStyles = StylesHelper::getStyles($element['styles'], 'link'); |
| 46 | $link->style = $css->mergeInlineStyles($elementLinkStyles, $link->style); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | $backgroundColor = $element['styles']['block']['backgroundColor']; |
| 51 | $backgroundColor = ($backgroundColor !== 'transparent') ? |
| 52 | 'bgcolor="' . $this->wp->escAttr($backgroundColor) . '"' : |
| 53 | false; |
| 54 | if (!$backgroundColor) unset($element['styles']['block']['backgroundColor']); |
| 55 | $style = 'line-height: ' . $lineHeight . ';' . StylesHelper::getBlockStyles($element) . StylesHelper::getStyles($element['styles'], 'text'); |
| 56 | $style = EHelper::escapeHtmlStyleAttr($style); |
| 57 | $template = ' |
| 58 | <tr> |
| 59 | <td class="mailpoet_header_footer_padded mailpoet_footer" ' . $backgroundColor . ' style="' . $style . '"> |
| 60 | ' . $this->htmlSanitizer->sanitize($DOM->__toString()) . ' |
| 61 | </td> |
| 62 | </tr>'; |
| 63 | return $template; |
| 64 | } |
| 65 | } |
| 66 |