diff --git a/lib/Newsletter/Blocks/Button.php b/lib/Newsletter/Blocks/Button.php index 0f931426a3..8f82f21756 100644 --- a/lib/Newsletter/Blocks/Button.php +++ b/lib/Newsletter/Blocks/Button.php @@ -5,6 +5,8 @@ use MailPoet\Newsletter\Blocks\Renderer as BlocksRenderer; class Button { static function render($element) { + $blocksRenderer = new Renderer(); + $template = ' @@ -32,7 +34,7 @@ class Button { ' . $element['text'] . ' + style="display:inline-block;text-align:center;text-decoration:none;-webkit-text-size-adjust:none;mso-hide:all;' . $blocksRenderer->getBlockStyles($element, array('textAlign')) . '"> ' . $element['text'] . ' diff --git a/lib/Newsletter/Blocks/Footer.php b/lib/Newsletter/Blocks/Footer.php index 3b818c29c4..1cd1842e1e 100644 --- a/lib/Newsletter/Blocks/Footer.php +++ b/lib/Newsletter/Blocks/Footer.php @@ -1,23 +1,23 @@ getStyles($element['styles'], 'link') . '"', $element['text']); } // apply text styles if(isset($element['styles']['link'])) { - $element['text'] = str_replace(' +
' . $element['text'] . '
'; diff --git a/lib/Newsletter/Blocks/Header.php b/lib/Newsletter/Blocks/Header.php index 6e92e1c434..c4c3359b5f 100644 --- a/lib/Newsletter/Blocks/Header.php +++ b/lib/Newsletter/Blocks/Header.php @@ -1,28 +1,28 @@ getStyles($element['styles'], 'link') . '"', $element['text']); } - + // apply text styles if(isset($element['styles']['link'])) { - $element['text'] = str_replace(' +
' . $element['text'] . '
'; - + return $template; } - + } \ No newline at end of file diff --git a/lib/Newsletter/Blocks/Image.php b/lib/Newsletter/Blocks/Image.php index b1b02d09a9..2810983204 100644 --- a/lib/Newsletter/Blocks/Image.php +++ b/lib/Newsletter/Blocks/Image.php @@ -5,11 +5,13 @@ use MailPoet\Newsletter\Blocks\Renderer as BlocksRenderer; class Image { static function render($element) { + $blocksRenderer = new Renderer(); + $element['width'] = (int) $element['width']; $template = ' - + diff --git a/lib/Newsletter/Blocks/Renderer.php b/lib/Newsletter/Blocks/Renderer.php index 80054b6509..978dddd41c 100644 --- a/lib/Newsletter/Blocks/Renderer.php +++ b/lib/Newsletter/Blocks/Renderer.php @@ -2,7 +2,7 @@ class Renderer { - static $typeFace = array( + public $typeFace = array( 'Arial' => "Arial, 'Helvetica Neue', Helvetica, sans-serif", 'Comic Sans MS' => "'Comic Sans MS', 'Marker Felt-Thin', Arial, sans-serif", 'Courier New' => "'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace", @@ -14,7 +14,7 @@ class Renderer { 'Verdana' => "Verdana, Geneva, sans-serif" ); - static $cssAtributesTable = array( + public $cssAtributesTable = array( 'backgroundColor' => 'background-color', 'fontColor' => 'color', 'fontFamily' => 'font-family', @@ -28,14 +28,14 @@ class Renderer { 'lineHeight' => 'line-height' ); - static function render($data, $column = null) { + function render($data, $column = null) { $blockContent = ''; $blockCount = count($data['blocks']); foreach ($data['blocks'] as $i => $block) { - $blockContent .= self::createElementFromBlockType($block); + $blockContent .= $this->createElementFromBlockType($block); if(isset($block['blocks']) && is_array($block['blocks'])) { - $blockContent = self::render($block); + $blockContent = $this->render($block); } // vertical orientation denotes column container @@ -47,7 +47,7 @@ class Renderer { return (isset($columns)) ? $columns : $blockContent; } - static function createElementFromBlockType($block) { + function createElementFromBlockType($block) { switch ($block['type']) { case 'header': $element = Header::render($block); @@ -81,27 +81,27 @@ class Renderer { return $element; } - static function getBlockStyles($element, $ignore = false) { + function getBlockStyles($element, $ignore = false) { if(!isset($element['styles']['block'])) { return; } - return self::getStyles($element['styles'], 'block', $ignore); + return $this->getStyles($element['styles'], 'block', $ignore); } - static function getStyles($styles, $type, $ignore = false) { + function getStyles($styles, $type, $ignore = false) { $css = ''; foreach ($styles[$type] as $attribute => $style) { if($ignore && in_array($attribute, $ignore)) { continue; } - $css .= self::translateCSSAttribute($attribute) . ': ' . $style . ' !important;'; + $css .= $this->translateCSSAttribute($attribute) . ': ' . $style . ' !important;'; } return $css; } - static function translateCSSAttribute($attribute) { - return (isset(self::$cssAtributesTable[$attribute])) ? self::$cssAtributesTable[$attribute] : $attribute; + function translateCSSAttribute($attribute) { + return (isset($this->cssAtributesTable[$attribute])) ? $this->cssAtributesTable[$attribute] : $attribute; } } diff --git a/lib/Newsletter/Blocks/Social.php b/lib/Newsletter/Blocks/Social.php index 704ce34c10..909ab799a4 100644 --- a/lib/Newsletter/Blocks/Social.php +++ b/lib/Newsletter/Blocks/Social.php @@ -4,11 +4,17 @@ class Social { static function render($element) { $iconsBlock = ''; + if(is_array($element['icons'])) { foreach ($element['icons'] as $icon) { - $iconsBlock .= '' . $icon['iconType'] . ''; + $iconsBlock .= ' + + ' . $icon['iconType'] . ' + +'; } } + $template = ' diff --git a/lib/Newsletter/Blocks/Spacer.php b/lib/Newsletter/Blocks/Spacer.php index 558b2d319b..14ff428f94 100644 --- a/lib/Newsletter/Blocks/Spacer.php +++ b/lib/Newsletter/Blocks/Spacer.php @@ -5,6 +5,9 @@ use MailPoet\Newsletter\Blocks\Renderer as BlocksRenderer; class Spacer { static function render($element) { + + $blocksRenderer = new Renderer(); + // if the parent container (column) has background set and the divider element has a transparent background, // it will assume the newsletter background, not that of the parent container if($element['styles']['block']['backgroundColor'] === 'transparent') { @@ -13,7 +16,7 @@ class Spacer { $template = ' - + '; return $template; diff --git a/lib/Newsletter/Columns/Renderer.php b/lib/Newsletter/Columns/Renderer.php index 7386e6b909..af10762303 100644 --- a/lib/Newsletter/Columns/Renderer.php +++ b/lib/Newsletter/Columns/Renderer.php @@ -2,19 +2,22 @@ class Renderer { - static function render($columnsCount, $columnsData) { - $columnWidths = array( - 1 => 600, - 2 => 300, - 3 => 200 - ); - $columnClasses = array( - 1 => 'mailpoet_col-one', - 2 => 'mailpoet_col-two', - 3 => 'mailpoet_col-three' - ); - $columnWidth = $columnWidths[$columnsCount]; - $columnClass = $columnClasses[$columnsCount]; + public $columnWidths = array( + 1 => 600, + 2 => 300, + 3 => 200 + ); + + public $columnClasses = array( + 1 => 'mailpoet_col-one', + 2 => 'mailpoet_col-two', + 3 => 'mailpoet_col-three' + ); + + function render($columnsCount, $columnsData) { + + $columnWidth = $this->columnWidths[$columnsCount]; + $columnClass = $this->columnClasses[$columnsCount]; // open column container $columnContainerTemplate = ' @@ -30,12 +33,14 @@ class Renderer { '; + $columnOpenTemplate = ' '; + $columnCloseTemplate = '
diff --git a/lib/Newsletter/Renderer.php b/lib/Newsletter/Renderer.php index a426f435e5..01737cd8b9 100644 --- a/lib/Newsletter/Renderer.php +++ b/lib/Newsletter/Renderer.php @@ -4,9 +4,13 @@ if(!defined('ABSPATH')) exit; class Renderer { - public $template = 'NewsletterTemplate.html'; + public $template = 'Template.html'; function __construct($newsletterData) { + $this->blocksRenderer = new Blocks\Renderer(); + $this->columnsRenderer = new Columns\Renderer(); + $this->DOMQuery = new \pQuery(); + $this->CSSInliner = new \MailPoet\Util\CSS(); $this->data = $newsletterData; $this->template = file_get_contents(dirname(__FILE__) . '/' . $this->template); } @@ -29,8 +33,8 @@ class Renderer { foreach ($content['blocks'] as $contentBlock) { if(isset($contentBlock['blocks']) && is_array($contentBlock['blocks'])) { $columnCount = count($contentBlock['blocks']); - $columnData = Blocks\Renderer::render($contentBlock); - $newsletterContent .= Columns\Renderer::render($columnCount, $columnData); + $columnData = $this->blocksRenderer->render($contentBlock); + $newsletterContent .= $this->columnsRenderer->render($columnCount, $columnData); } } @@ -56,7 +60,7 @@ class Renderer { } $newsletterStyles .= $selector . '{' . PHP_EOL; foreach ($style as $attribute => $individualStyle) { - $newsletterStyles .= Blocks\Renderer::translateCSSAttribute($attribute) . ':' . $individualStyle . ';' . PHP_EOL; + $newsletterStyles .= $this->blocksRenderer->translateCSSAttribute($attribute) . ':' . $individualStyle . ';' . PHP_EOL; } $newsletterStyles .= '}' . PHP_EOL; } @@ -71,14 +75,12 @@ class Renderer { } function inlineCSSStyles($template) { - $inliner = new \MailPoet\Util\CSS(); - - return $inliner->inlineCSS(null, $template); + return $this->CSSInliner->inlineCSS(null, $template); } function postProcessRenderedTemplate($template) { // remove padding from last element inside each column - $DOM = \pQuery::parseStr($template); + $DOM = $this->DOMQuery->parseStr($template); $lastColumnElement = $DOM->query('.mailpoet_col > tbody > tr:last-child > td'); foreach ($lastColumnElement as $element) { $element->setAttribute('style', str_replace('padding-bottom:20px;', '', $element->attributes['style'])); diff --git a/lib/Newsletter/NewsletterTemplate.html b/lib/Newsletter/Template.html similarity index 100% rename from lib/Newsletter/NewsletterTemplate.html rename to lib/Newsletter/Template.html diff --git a/lib/Newsletter/NewsletterData.json b/lib/Newsletter/TestData.json similarity index 100% rename from lib/Newsletter/NewsletterData.json rename to lib/Newsletter/TestData.json