From 61c255564fe14278d93f4c7d84c953c8b07ba277 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 6 Nov 2016 18:46:56 -0500 Subject: [PATCH 1/2] - Fixes 'Using $this when not in object context' error in PHP 5.3 --- lib/Config/Migrator.php | 5 +++-- lib/Newsletter/Renderer/Blocks/Renderer.php | 7 ++++--- lib/Newsletter/Renderer/Renderer.php | 7 ++++--- lib/Newsletter/Shortcodes/Shortcodes.php | 17 +++++++++-------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/Config/Migrator.php b/lib/Config/Migrator.php index ca0b23c560..04a6faee47 100644 --- a/lib/Config/Migrator.php +++ b/lib/Config/Migrator.php @@ -52,8 +52,9 @@ class Migrator { function down() { global $wpdb; - $drop_table = function($model) use($wpdb) { - $table = $this->prefix . $model; + $_this = $this; + $drop_table = function($model) use($wpdb, $_this) { + $table = $_this->prefix . $model; $wpdb->query("DROP TABLE {$table}"); }; diff --git a/lib/Newsletter/Renderer/Blocks/Renderer.php b/lib/Newsletter/Renderer/Blocks/Renderer.php index 89333b0135..e977e81f5a 100644 --- a/lib/Newsletter/Renderer/Blocks/Renderer.php +++ b/lib/Newsletter/Renderer/Blocks/Renderer.php @@ -38,10 +38,11 @@ class Renderer { function render($data, $column_count) { $block_content = ''; - array_map(function($block) use (&$block_content, &$column_content, $column_count) { - $rendered_block_element = $this->createElementFromBlockType($block, $column_count); + $_this = $this; + array_map(function($block) use (&$block_content, &$column_content, $column_count, $_this) { + $rendered_block_element = $_this->createElementFromBlockType($block, $column_count); if(isset($block['blocks'])) { - $rendered_block_element = $this->render($block, $column_count); + $rendered_block_element = $_this->render($block, $column_count); } // vertical orientation denotes column container if($block['type'] === 'container' && $block['orientation'] === 'vertical') { diff --git a/lib/Newsletter/Renderer/Renderer.php b/lib/Newsletter/Renderer/Renderer.php index 901e773454..354bff23ea 100644 --- a/lib/Newsletter/Renderer/Renderer.php +++ b/lib/Newsletter/Renderer/Renderer.php @@ -59,13 +59,14 @@ class Renderer { ? $content['blocks'] : array(); - $rendered_content = array_map(function($content_block) { + $_this = $this; + $rendered_content = array_map(function($content_block) use($_this) { $column_count = count($content_block['blocks']); - $column_data = $this->blocks_renderer->render( + $column_data = $_this->blocks_renderer->render( $content_block, $column_count ); - return $this->columns_renderer->render( + return $_this->columns_renderer->render( $content_block['styles'], $column_count, $column_data diff --git a/lib/Newsletter/Shortcodes/Shortcodes.php b/lib/Newsletter/Shortcodes/Shortcodes.php index e123c14960..d555fdc089 100644 --- a/lib/Newsletter/Shortcodes/Shortcodes.php +++ b/lib/Newsletter/Shortcodes/Shortcodes.php @@ -48,9 +48,10 @@ class Shortcodes { } function process($shortcodes, $content = false) { + $_this = $this; $processed_shortcodes = array_map( - function($shortcode) use ($content) { - $shortcode_details = $this->match($shortcode); + function($shortcode) use ($content, $_this) { + $shortcode_details = $_this->match($shortcode); $shortcode_category = !empty($shortcode_details['category']) ? ucfirst($shortcode_details['category']) : false; @@ -66,9 +67,9 @@ class Shortcodes { $custom_shortcode = apply_filters( 'mailpoet_newsletter_shortcode', $shortcode, - $this->newsletter, - $this->subscriber, - $this->queue, + $_this->newsletter, + $_this->subscriber, + $_this->queue, $content ); return ($custom_shortcode === $shortcode) ? @@ -78,9 +79,9 @@ class Shortcodes { return $shortcode_class::process( $shortcode_action, $shortcode_default_value, - $this->newsletter, - $this->subscriber, - $this->queue, + $_this->newsletter, + $_this->subscriber, + $_this->queue, $content ); }, $shortcodes); From 1db8626e35e88668b405922b4e432aa767793ff8 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 6 Nov 2016 18:49:10 -0500 Subject: [PATCH 2/2] - Fixes 'Cannot access self:: when no class scope is active' error in PHP 5.3 --- lib/Newsletter/Renderer/Columns/Renderer.php | 2 +- lib/Newsletter/Renderer/StylesHelper.php | 2 +- lib/Newsletter/Shortcodes/Shortcodes.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Newsletter/Renderer/Columns/Renderer.php b/lib/Newsletter/Renderer/Columns/Renderer.php index 6a396a69fa..6c486c8461 100644 --- a/lib/Newsletter/Renderer/Columns/Renderer.php +++ b/lib/Newsletter/Renderer/Columns/Renderer.php @@ -11,7 +11,7 @@ class Renderer { $this->getOneColumnTemplate($styles, $class) : $this->getMultipleColumnsTemplate($styles, $width, $alignment, $class); $result = array_map(function($content) use ($template) { - $content = self::removePaddingFromLastElement($content); + $content = Renderer::removePaddingFromLastElement($content); return $template['content_start'] . $content . $template['content_end']; }, $columns_data); $result = implode('', $result); diff --git a/lib/Newsletter/Renderer/StylesHelper.php b/lib/Newsletter/Renderer/StylesHelper.php index 85ab35a80b..37b14a6838 100644 --- a/lib/Newsletter/Renderer/StylesHelper.php +++ b/lib/Newsletter/Renderer/StylesHelper.php @@ -41,7 +41,7 @@ class StylesHelper { static function getStyles($data, $type, $ignore_specific_styles = false) { $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;'; + return StylesHelper::translateCSSAttribute($attribute) . ': ' . $style . ' !important;'; } }, array_keys($data[$type]), $data[$type]); return implode('', $styles); diff --git a/lib/Newsletter/Shortcodes/Shortcodes.php b/lib/Newsletter/Shortcodes/Shortcodes.php index d555fdc089..e90302d07c 100644 --- a/lib/Newsletter/Shortcodes/Shortcodes.php +++ b/lib/Newsletter/Shortcodes/Shortcodes.php @@ -59,7 +59,7 @@ class Shortcodes { $shortcode_details['action'] : false; $shortcode_class = - self::SHORTCODE_CATEGORY_NAMESPACE . $shortcode_category; + Shortcodes::SHORTCODE_CATEGORY_NAMESPACE . $shortcode_category; $shortcode_default_value = !empty($shortcode_details['default']) ? $shortcode_details['default'] : false;