diff --git a/lib/Newsletter/Renderer/Blocks/Footer.php b/lib/Newsletter/Renderer/Blocks/Footer.php
index 4147d4514d..cff57f1bf0 100644
--- a/lib/Newsletter/Renderer/Blocks/Footer.php
+++ b/lib/Newsletter/Renderer/Blocks/Footer.php
@@ -5,21 +5,23 @@ use MailPoet\Newsletter\Renderer\StylesHelper;
class Footer {
static function render($element) {
- if(isset($element['styles']['link'])) {
- $element['text'] = str_replace(
- '
', $element['text']);
- $element['text'] = preg_replace('/(<\/?p>)/', '', $element['text']);
+ $element['text'] = preg_replace('/(<\/?p.*?>)/i', '', $element['text']);
+ $DOM_parser = new \pQuery();
+ $DOM = $DOM_parser->parseStr($element['text']);
+ if(isset($element['styles']['link'])) {
+ $links = $DOM->query('a');
+ if($links->count()) {
+ foreach($links as $link) {
+ $link->style = StylesHelper::getStyles($element['styles'], 'link');
+ }
+ }
+ }
$template = '
(.*?)<\/p>/', ' -
- $1
- - |
-
(.*?)<\/p>/', ' -
- $2
- - |
-
@@ -63,48 +46,90 @@ class Text { |
- $1 + ' . implode('', $contents) . ' |
.*?<\/blockquote>/s', $html, $blockquotes); - foreach($blockquotes as $index => $blockquote) { - $blockquote = preg_replace('/<\/p>\n/', '
', $blockquote); - $blockquote = preg_replace('/<\/?p>/', '', $blockquote); - $blockquote = preg_replace( - '/(.*?)<\/blockquote>/s', - $template, - $blockquote - ); - $html = preg_replace( - '/' . preg_quote($blockquotes[$index], '/') . '/', - $blockquote, - $html + ' ); } - return $html; + return $DOM->__toString(); } - static function styleHeadings($html) { - return preg_replace( - '/<(h[1-6])(?:.+style=\"(.*)?\")?>/', - '<$1 style="margin:0;font-style:normal;font-weight:normal;$2">', - $html - ); + static function convertParagraphsToTables($html) { + $DOM_parser = new \pQuery(); + $DOM = $DOM_parser->parseStr($html); + $paragraphs = $DOM->query('p'); + if(!$paragraphs->count()) return $html; + foreach($paragraphs as $paragraph) { + // remove empty paragraphs + if(!trim($paragraph->html())) { + $paragraph->remove(); + continue; + } + $style = $paragraph->style; + $contents = $paragraph->html(); + $paragraph->setTag('table'); + $paragraph->style = 'border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;'; + $paragraph->width = '100%'; + $paragraph->cellpadding = 0; + $paragraph->html(' ++ ' + ); + } + return $DOM->__toString(); } static function styleLists($html) { - $html = preg_replace( - '/<(ul|ol)>/', - '<$1 class="mailpoet_paragraph" style="padding-top:0;padding-bottom:0;margin-top:0;margin-bottom:0;">', - $html - ); - $html = preg_replace('/+ ' . $contents . ' + +
+/', ' ', $html); - return $html; + $DOM_parser = new \pQuery(); + $DOM = $DOM_parser->parseStr($html); + $lists = $DOM->query('ol, ul, li'); + if(!$lists->count()) return $html; + foreach($lists as $list) { + if($list->tag === 'li') { + $list->class = 'mailpoet_paragraph'; + } else { + $list->class = 'mailpoet_paragraph'; + $list->style .= 'padding-top:0;padding-bottom:0;margin-top:0;margin-bottom:0;'; + } + } + return $DOM->__toString(); + } + + static function styleHeadings($html) { + $DOM_parser = new \pQuery(); + $DOM = $DOM_parser->parseStr($html); + $headings = $DOM->query('h1, h2, h3, h4'); + if(!$headings->count()) return $html; + foreach($headings as $heading) { + $heading->style .= 'margin:0;font-style:normal;font-weight:normal;'; + } + return $DOM->__toString(); + } + + static function addLineBreakAfterTags($html) { + $DOM_parser = new \pQuery(); + $DOM = $DOM_parser->parseStr($html); + $tags = $DOM->query('ul, ol, h1, h2, h3, h4, table.mailpoet_blockquote'); + if(!$tags->count()) return $html; + foreach($tags as $tag) { + $tag->parent->insertChild( + array( + 'tag_name' => 'br', + 'self_close' => true, + 'attributes' => array() + ), + $tag->index() + 1 + ); + } + // remove last line break + return preg_replace('/(^)?( )+$/i', '', $DOM->__toString()); } } \ No newline at end of file diff --git a/lib/Newsletter/Renderer/Renderer.php b/lib/Newsletter/Renderer/Renderer.php index 83487f4099..dde46a0f2e 100644 --- a/lib/Newsletter/Renderer/Renderer.php +++ b/lib/Newsletter/Renderer/Renderer.php @@ -69,7 +69,7 @@ class Renderer { $selector = 'h3'; break; case 'text': - $selector = '.mailpoet_paragraph, .mailpoet_blockquote'; + $selector = '.mailpoet_paragraph, td.mailpoet_blockquote'; break; case 'body': $selector = 'body, .mailpoet-wrapper';