Compare commits

...

8 Commits

Author SHA1 Message Date
Tautvidas Sipavičius
8b96854f39 Bump up release version to 0.0.22 2016-04-01 14:57:11 +03:00
Tautvidas Sipavičius
28d8600078 Merge pull request #408 from mailpoet/rendering_engine_update
Rendering engine update
2016-04-01 12:37:11 +03:00
Vlad
4f30158722 - Updates button height calculation
- Removes background color when it's set to "transparent"
- Removes second line break from paragraphs
- Introduces other changes based on Becks's testing
- Updates unit tests
2016-03-31 19:19:58 -04:00
Tautvidas Sipavičius
4486f9c5b0 Merge pull request #407 from mailpoet/scheduled_sending
Prevents welcome emails to be sent to unconfirmed subsribers
2016-03-31 14:53:41 +03:00
Tautvidas Sipavičius
8515dcf29b Merge pull request #406 from mailpoet/rendering_engine_update
Rendering engine update
2016-03-31 14:05:18 +03:00
Vlad
d16eb87782 - Prevents welcome emails to be sent to unconfirmed subscribers
- Closes #384
2016-03-30 20:59:55 -04:00
Vlad
3c77e5d25e - Removes dynamic line-height based on column width
- Updates logic behind removing last element bottom padding
- Properly sets font size for H1-4 tags, header, footer and text
2016-03-30 20:09:06 -04:00
Vlad
aa1a2a0da9 - Updates button padding 2016-03-30 20:09:06 -04:00
16 changed files with 112 additions and 252 deletions

View File

@@ -47,16 +47,16 @@ class Scheduler {
function processWelcomeNewsletter($newsletter, $queue) {
$subscriber = unserialize($queue->subscribers);
$subscriber_id = $subscriber['to_process'][0];
$result = false;
if($newsletter->event === 'segment') {
$result = $this->verifyMailPoetSubscriber($subscriber_id, $newsletter);
if ($this->verifyMailPoetSubscriber($subscriber_id, $newsletter, $queue) === false) {
return;
}
}
else if($newsletter->event === 'user') {
$result = $this->verifyWPSubscriber($subscriber_id, $newsletter);
}
if(!$result) {
$queue->delete();
return;
if ($this->verifyWPSubscriber($subscriber_id, $newsletter) === false) {
$queue->delete();
return;
}
}
$queue->status = null;
$queue->save();
@@ -95,14 +95,27 @@ class Scheduler {
$new_queue->save();
}
private function verifyMailPoetSubscriber($subscriber_id, $newsletter) {
private function verifyMailPoetSubscriber($subscriber_id, $newsletter, $queue) {
// check if subscriber is in proper segment
$subscriber_in_segment =
SubscriberSegment::where('subscriber_id', $subscriber_id)
->where('segment_id', $newsletter->segment)
->where('status', 'subscribed')
->findOne();
return ($subscriber_in_segment) ? true : false;
if (!$subscriber_in_segment) {
$queue->delete();
return false;
}
// check if subscriber is confirmed (subscribed)
$subscriber = $subscriber_in_segment->subscriber()->findOne();
if ($subscriber->status !== 'subscribed') {
// reschedule delivery in 5 minutes
$scheduled_at = Carbon::createFromTimestamp(current_time('timestamp'));
$queue->scheduled_at = $scheduled_at->addMinutes(5);
$queue->save();
return false;
}
return true;
}
private function verifyWPSubscriber($subscriber_id, $newsletter) {

View File

@@ -12,6 +12,10 @@ class SubscriberSegment extends Model {
parent::__construct();
}
function subscriber() {
return $this->has_one(__NAMESPACE__.'\Subscriber', 'id');
}
static function setSubscriptions($subscriber, $segment_ids = array()) {
if($subscriber->id > 0) {
// unsubscribe from current subscriptions

View File

@@ -7,20 +7,19 @@ use MailPoet\Newsletter\Renderer\StylesHelper;
class Button {
static function render($element, $column_count) {
$element['styles']['block']['width'] = self::calculateWidth($element, $column_count);
$element['styles']['block']['height'] = self::calculateHeight($element);
$template = '
<tr>
<td class="mailpoet_padded" valign="top">
<td class="mailpoet_padded_bottom mailpoet_padded_side" valign="top">
<div>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;">
<tr>
<td class="mailpoet_button-container" style="padding:8px 0;text-align:' . $element['styles']['block']['textAlign'] . ';"><!--[if mso]>
<td class="mailpoet_button-container" style="padding:8px 20px;text-align:' . $element['styles']['block']['textAlign'] . ';"><!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word"
href="' . $element['url'] . '"
style="height:' . $element['styles']['block']['height'] . ';
style="height:' . $element['styles']['block']['lineHeight'] . ';
width:' . $element['styles']['block']['width'] . ';
v-text-anchor:middle;"
arcsize="' . round($element['styles']['block']['borderRadius'] / $element['styles']['block']['height'] * 100) . '%"
arcsize="' . round($element['styles']['block']['borderRadius'] / $element['styles']['block']['lineHeight'] * 100) . '%"
strokeweight="1px"
strokecolor="' . $element['styles']['block']['borderColor'] . '"
fillcolor="' . $element['styles']['block']['backgroundColor'] . '">
@@ -52,10 +51,4 @@ class Button {
$button_width = $button_width - (2 * $border_width) . 'px';
return $button_width;
}
static function calculateHeight($element) {
$button_height = (int) $element['styles']['block']['lineHeight'];
$button_height = $button_height - (2 * $button_height) . 'px';
return $button_height;
}
}

View File

@@ -17,10 +17,15 @@ class Footer {
}
}
}
$background_color = $element['styles']['block']['backgroundColor'];
$background_color = ($background_color !== 'transparent') ?
'bgcolor="' . $background_color . '"' :
false;
if(!$background_color) unset($element['styles']['block']['backgroundColor']);
$template = '
<tr>
<td class="mailpoet_header_footer_padded mailpoet_footer" bgcolor="' . $element['styles']['block']['backgroundColor'] . '"
style="' . StylesHelper::getBlockStyles($element) . StylesHelper::getStyles($element['styles'], 'text') . '">
<td class="mailpoet_header_footer_padded mailpoet_footer" ' . $background_color . '
style="line-height: ' . StylesHelper::$line_height . ';' . StylesHelper::getBlockStyles($element) . StylesHelper::getStyles($element['styles'], 'text') . '">
' . $DOM->html() . '
</td>
</tr>';

View File

@@ -17,9 +17,14 @@ class Header {
}
}
}
$background_color = $element['styles']['block']['backgroundColor'];
$background_color = ($background_color !== 'transparent') ?
'bgcolor="' . $background_color . '"' :
false;
if(!$background_color) unset($element['styles']['block']['backgroundColor']);
$template = '
<tr>
<td class="mailpoet_header_footer_padded mailpoet_header" bgcolor="' . $element['styles']['block']['backgroundColor'] . '"
<td class="mailpoet_header_footer_padded mailpoet_header" ' . $background_color . '
style="' . StylesHelper::getBlockStyles($element) . StylesHelper::getStyles($element['styles'], 'text') . '">
' . $DOM->html() . '
</td>

View File

@@ -18,7 +18,7 @@ class Image {
}
$template = '
<tr>
<td class="mailpoet_image ' . (($element['fullWidth'] === false) ? 'mailpoet_padded' : '') . '" align="center" valign="top">
<td class="mailpoet_image ' . (($element['fullWidth'] === false) ? 'mailpoet_padded_bottom mailpoet_padded_side' : 'mailpoet_padded_bottom') . '" align="center" valign="top">
' . $image_template . '
</td>
</tr>';

View File

@@ -1,10 +1,12 @@
<?php
namespace MailPoet\Newsletter\Renderer\Blocks;
use MailPoet\Newsletter\Renderer\StylesHelper;
class Renderer {
function render($data, $column_count) {
$block_content = '';
array_map(function ($block) use (&$block_content, &$columns, $column_count) {
array_map(function($block) use (&$block_content, &$columns, $column_count) {
$block_content .= $this->createElementFromBlockType($block, $column_count);
if(isset($block['blocks'])) {
$block_content = $this->render($block, $column_count);
@@ -18,6 +20,7 @@ class Renderer {
}
function createElementFromBlockType($block, $column_count) {
$block = StylesHelper::setTextAlign($block);
$block_class = __NAMESPACE__ . '\\' . ucfirst($block['type']);
return (class_exists($block_class)) ? $block_class::render($block, $column_count) : '';
}

View File

@@ -13,7 +13,7 @@ class Social {
}
$template = '
<tr>
<td class="mailpoet_padded" valign="top" align="center">
<td class="mailpoet_padded_side maipoet_padded_bottom" valign="top" align="center">
' . $icons_block . '
</td>
</tr>';

View File

@@ -1,6 +1,8 @@
<?php
namespace MailPoet\Newsletter\Renderer\Blocks;
use MailPoet\Newsletter\Renderer\StylesHelper;
class Text {
static function render($element) {
$html = $element['text'];
@@ -11,7 +13,7 @@ class Text {
$html = self::addLineBreakAfterTags($html);
$template = '
<tr>
<td class="mailpoet_text mailpoet_padded" valign="top" style="word-break:break-word;word-wrap:break-word;">
<td class="mailpoet_text mailpoet_padded_bottom mailpoet_padded_side" valign="top" style="word-break:break-word;word-wrap:break-word;">
' . $html . '
</td>
</tr>';
@@ -77,9 +79,9 @@ class Text {
$paragraph->cellpadding = 0;
$paragraph->html('
<tr>
<td class="mailpoet_paragraph" style="word-break:break-word;word-wrap:break-word;' . $style . '">
<td class="mailpoet_paragraph" style="line-height:' . StylesHelper::$line_height . ';word-break:break-word;word-wrap:break-word;' . $style . '">
' . $contents . '
<br /><br />
<br />
</td>
</tr>'
);
@@ -97,7 +99,7 @@ class Text {
$list->class = 'mailpoet_paragraph';
} else {
$list->class = 'mailpoet_paragraph';
$list->style .= 'padding-top:0;padding-bottom:0;margin-top:0;margin-bottom:0;';
$list->style .= 'line-height:' . StylesHelper::$line_height . ';padding-top:0;padding-bottom:0;margin-top:0;margin-bottom:0;';
}
}
return $DOM->__toString();
@@ -109,7 +111,7 @@ class Text {
$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;';
$heading->style .= 'line-height:' . StylesHelper::$line_height . ';margin:0;font-style:normal;font-weight:normal;';
}
return $DOM->__toString();
}

View File

@@ -22,6 +22,7 @@ class Renderer {
}
function getOneColumnTemplate($styles, $class) {
$background_color = $this->getBackgroundColor($styles);
$template['content_start'] = '
<tr>
<td class="mailpoet_content" align="center" style="border-collapse:collapse">
@@ -29,7 +30,7 @@ class Renderer {
<tbody>
<tr>
<td style="padding-left:0;padding-right:0">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="mailpoet_' . $class . '" style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;table-layout:fixed;margin-left:auto;margin-right:auto;padding-left:0;padding-right:0;background-color:' . $styles['backgroundColor'] . '!important;" bgcolor="' . $styles['backgroundColor'] . '">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="mailpoet_' . $class . '" style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;table-layout:fixed;margin-left:auto;margin-right:auto;padding-left:0;padding-right:0;' . $background_color . '">
<tbody>';
$template['content_end'] = '
</tbody>
@@ -44,9 +45,10 @@ class Renderer {
}
function getMultipleColumnsTemplate($styles, $width, $alignment, $class) {
$background_color = $this->getBackgroundColor($styles);
$template['container_start'] = '
<tr>
<td class="mailpoet_content-' . $class . '" align="left" style="border-collapse:collapse;background-color:' . $styles['backgroundColor'] . '!important;" bgcolor="' . $styles['backgroundColor'] . '">
<td class="mailpoet_content-' . $class . '" align="left" style="border-collapse:collapse;' . $background_color . '">
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0">
<tbody>
<tr>
@@ -78,8 +80,14 @@ class Renderer {
}
function removePaddingFromLastElement($element) {
return (substr_count($element, 'mailpoet_padded') <= 1) ?
$element :
preg_replace('/mailpoet_padded(?!.*mailpoet_padded)/ism', '', $element);
return preg_replace('/mailpoet_padded_bottom(?!.*mailpoet_padded_bottom)/ism', '', $element);
}
function getBackgroundColor($styles) {
if(!isset($styles['backgroundColor'])) return false;
$background_color = $styles['backgroundColor'];
return ($background_color !== 'transparent') ?
sprintf('background-color:%s!important;" bgcolor="%s', $background_color, $background_color) :
false;
}
}

View File

@@ -63,7 +63,7 @@ class Renderer {
foreach($styles as $selector => $style) {
switch($selector) {
case 'text':
$selector = '.mailpoet_paragraph, td.mailpoet_blockquote, .mailpoet_footer, .mailpoet_header';
$selector = 'td.mailpoet_paragraph, td.mailpoet_blockquote';
break;
case 'body':
$selector = 'body, .mailpoet-wrapper';
@@ -75,13 +75,6 @@ class Renderer {
$selector = '.mailpoet_content-wrapper';
break;
}
if(isset($style['fontSize'])) {
$css .= StylesHelper::setFontSizeAndLineHeight(
(int) $style['fontSize'],
$selector
);
unset($style['fontSize']);
}
if(isset($style['fontFamily'])) {
$css .= StylesHelper::setFontFamily(
$style['fontFamily'],

View File

@@ -1,8 +1,6 @@
<?php
namespace MailPoet\Newsletter\Renderer;
use MailPoet\Newsletter\Renderer\Columns\ColumnsHelper;
class StylesHelper {
static $css_attributes = array(
'backgroundColor' => 'background-color',
@@ -29,174 +27,7 @@ class StylesHelper {
'Trebuchet MS' => "'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Tahoma, sans-serif",
'Verdana' => 'Verdana, Geneva, sans-serif'
);
static $line_height = array(
// font_size => array(columnCount => lineHeight);
8 => array(
1 => "20",
2 => "15",
3 => "13"
),
9 => array(
1 => "20",
2 => "16",
3 => "14"
),
10 => array(
1 => "20",
2 => "17",
3 => "15"
),
11 => array(
1 => "21",
2 => "18",
3 => "16"
),
12 => array(
1 => "22",
2 => "19",
3 => "17"
),
13 => array(
1 => "23",
2 => "20",
3 => "19"
),
14 => array(
1 => "24",
2 => "21",
3 => "20"
),
15 => array(
1 => "25",
2 => "22",
3 => "21"
),
16 => array(
1 => "26",
2 => "23",
3 => "22"
),
17 => array(
1 => "27",
2 => "24",
3 => "24"
),
18 => array(
1 => "28",
2 => "25",
3 => "25"
),
19 => array(
1 => "29",
2 => "27",
3 => "26"
),
20 => array(
1 => "30",
2 => "28",
3 => "27"
),
21 => array(
1 => "31",
2 => "29",
3 => "29"
),
22 => array(
1 => "32",
2 => "30",
3 => "30"
),
23 => array(
1 => "33",
2 => "32",
3 => "31"
),
24 => array(
1 => "34",
2 => "33",
3 => "32"
),
25 => array(
1 => "36",
2 => "34",
3 => "34"
),
26 => array(
1 => "37",
2 => "35",
3 => "35"
),
27 => array(
1 => "38",
2 => "37",
3 => "36"
),
28 => array(
1 => "39",
2 => "38",
3 => "37"
),
29 => array(
1 => "40",
2 => "39",
3 => "39"
),
30 => array(
1 => "42",
2 => "40",
3 => "40"
),
31 => array(
1 => "43",
2 => "42",
3 => "41"
),
32 => array(
1 => "44",
2 => "43",
3 => "43"
),
33 => array(
1 => "45",
2 => "44",
3 => "44"
),
34 => array(
1 => "47",
2 => "46",
3 => "45"
),
35 => array(
1 => "48",
2 => "47",
3 => "46"
),
36 => array(
1 => "49",
2 => "48",
3 => "48"
),
37 => array(
1 => "50",
2 => "49",
3 => "49"
),
38 => array(
1 => "52",
2 => "51",
3 => "50"
),
39 => array(
1 => "53",
2 => "52",
3 => "52"
),
40 => array(
1 => "54",
2 => "53",
3 => "53"
)
);
static $line_height = 1.61803398875;
static $padding_width = 20;
static function getBlockStyles($element, $ignore_specific_styles = false) {
@@ -207,7 +38,7 @@ class StylesHelper {
}
static function getStyles($data, $type, $ignore_specific_styles = false) {
$styles = array_map(function ($attribute, $style) use ($ignore_specific_styles) {
$styles = array_map(function($attribute, $style) use ($ignore_specific_styles) {
if(!$ignore_specific_styles || !in_array($attribute, $ignore_specific_styles)) {
return self::translateCSSAttribute($attribute) . ': ' . $style . ' !important;';
}
@@ -231,20 +62,6 @@ class StylesHelper {
return $css;
}
static function setFontSizeAndLineHeight($font_size, $selectors) {
$css = '';
foreach(ColumnsHelper::columnClasses() as $column_count => $column_class) {
$css = array_map(function($selector) use ($font_size, $column_count, $column_class) {
$css = '.mailpoet_content-' . $column_class . '.' . $selector . '{' . PHP_EOL;
if (!preg_match('/footer|header/', $selector)) $css .= 'font-size:' . $font_size . 'px !important;' . PHP_EOL;
$css .= 'line-height:' . StylesHelper::$line_height[$font_size][$column_count] . 'px !important;' . PHP_EOL;
$css .= '}' . PHP_EOL;
return $css;
}, explode(',', $selectors));
}
return implode('', $css);
}
static function setStyle($style, $selector) {
$css = $selector . '{' . PHP_EOL;
foreach($style as $attribute => $individual_style) {
@@ -253,4 +70,20 @@ class StylesHelper {
$css .= '}' . PHP_EOL;
return $css;
}
static function setTextAlign($block) {
$alignments = array(
'center',
'right',
'justify'
);
$text_alignment = isset($block['styles']['block']['textAlign']) ?
strtolower($block['styles']['block']['textAlign']) :
false;
if(!$text_alignment || !in_array($text_alignment, $alignments)) {
return $block;
}
$block['styles']['block']['textAlign'] = 'left';
return $block;
}
}

View File

@@ -35,10 +35,12 @@
outline: none;
text-align: center;
}
.mailpoet_padded {
.mailpoet_padded_bottom {
padding-bottom: 20px;
}
.mailpoet_padded_side {
padding-left: 20px;
padding-right: 20px;
padding-bottom: 20px;
}
.mailpoet_header_footer_padded {
padding: 10px 20px;

View File

@@ -120,11 +120,11 @@ class Scheduler {
case 'weeks':
$scheduled_at = $current_time->addWeeks($after_time_number);
break;
default:
$scheduled_at = $current_time;
}
if($scheduled_at) {
$queue->status = 'scheduled';
$queue->scheduled_at = $scheduled_at;
}
$queue->status = 'scheduled';
$queue->scheduled_at = $scheduled_at;
$queue->save();
}
}

View File

@@ -4,7 +4,7 @@ if(!defined('ABSPATH')) exit;
use \MailPoet\Config\Initializer;
/*
* Plugin Name: MailPoet
* Version: 0.0.21
* Version: 0.0.22
* Plugin URI: http://www.mailpoet.com
* Description: MailPoet Newsletters.
* Author: MailPoet
@@ -22,7 +22,7 @@ use \MailPoet\Config\Initializer;
require 'vendor/autoload.php';
define('MAILPOET_VERSION', '0.0.21');
define('MAILPOET_VERSION', '0.0.22');
$initializer = new Initializer(array(
'file' => __FILE__,

View File

@@ -23,7 +23,6 @@ class NewsletterRendererTest extends MailPoetTest {
$this->DOM_parser = new \pQuery();
}
function testItRendersCompleteNewsletter() {
$template = $this->renderer->render();
expect(isset($template['html']))->true();
@@ -107,10 +106,10 @@ class NewsletterRendererTest extends MailPoetTest {
function testItRemovesPaddingFromLastColumnElement() {
$column_content = array('
<tr><td class="mailpoet_padded"></td></tr>
<tr><td class="mailpoet_padded"></td></tr>
<tr><td class="mailpoet_padded"></td></tr>
<tr><td class="mailpoet_padded"></td></tr>'
<tr><td class="mailpoet_padded_bottom"></td></tr>
<tr><td class="mailpoet_padded_bottom"></td></tr>
<tr><td class="mailpoet_padded_bottom"></td></tr>
<tr><td class="mailpoet_padded_bottom"></td></tr>'
);
$column_styles = array(
'block' => array(
@@ -129,7 +128,7 @@ class NewsletterRendererTest extends MailPoetTest {
$newsletter = json_decode($this->newsletter['body'], true);
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][0];
$DOM = $this->DOM_parser->parseStr(Header::render($template));
// element should be proplerly nested, and styles should be applied
// element should be properly nested, and styles should be applied
expect(!empty($DOM('tr > td.mailpoet_header', 0)->html()))->true();
expect(!empty($DOM('tr > td > a', 0)->html()))->true();
expect($DOM('a', 0)->attr('style'))->notEmpty();
@@ -246,6 +245,14 @@ class NewsletterRendererTest extends MailPoetTest {
->equals('#ffff');
}
function testItCalculatesButtonWidth() {
$newsletter = json_decode($this->newsletter['body'], true);
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5];
$template['styles']['block']['width'] = '700px';
$button_width = Button::calculateWidth($template, $columnCunt = 1);
expect($button_width)->equals('618px'); //(width - (2 * border width)
}
function testItRendersButton() {
$newsletter = json_decode($this->newsletter['body'], true);
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5];
@@ -266,7 +273,7 @@ class NewsletterRendererTest extends MailPoetTest {
)->equals(1);
expect(
preg_match(
'/style="height:30px.*?width:100px/',
'/style="height:30px.*?width:98px/',
$DOM('tr > td > div > table > tr > td', 0)->text())
)->equals(1);
expect(
@@ -281,14 +288,6 @@ class NewsletterRendererTest extends MailPoetTest {
)->equals(1);
}
function testItCalculatesButtonWidth() {
$newsletter = json_decode($this->newsletter['body'], true);
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][5];
$template['styles']['block']['width'] = '700px';
$button_width = Button::calculateWidth($template, $columnCunt = 1);
expect($button_width)->equals('620px');
}
function testItRendersSocialIcons() {
$newsletter = json_decode($this->newsletter['body'], true);
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][6];