diff --git a/packages/php/email-editor/src/Engine/Patterns/Library/class-abstract-pattern.php b/packages/php/email-editor/src/Engine/Patterns/Library/class-abstract-pattern.php index e005a5f04b..55c2a09ca4 100644 --- a/packages/php/email-editor/src/Engine/Patterns/Library/class-abstract-pattern.php +++ b/packages/php/email-editor/src/Engine/Patterns/Library/class-abstract-pattern.php @@ -5,39 +5,39 @@ namespace MailPoet\EmailEditor\Engine\Patterns\Library; use MailPoet\EmailEditor\Utils\Cdn_Asset_Url; abstract class Abstract_Pattern { - protected $cdnAssetUrl; - protected $blockTypes = []; - protected $templateTypes = []; - protected $inserter = true; - protected $source = 'plugin'; - protected $categories = ['mailpoet']; - protected $viewportWidth = 620; + protected $cdnAssetUrl; + protected $blockTypes = array(); + protected $templateTypes = array(); + protected $inserter = true; + protected $source = 'plugin'; + protected $categories = array( 'mailpoet' ); + protected $viewportWidth = 620; - public function __construct( - Cdn_Asset_Url $cdnAssetUrl - ) { - $this->cdnAssetUrl = $cdnAssetUrl; - } + public function __construct( + Cdn_Asset_Url $cdnAssetUrl + ) { + $this->cdnAssetUrl = $cdnAssetUrl; + } - public function getProperties() { - return [ - 'title' => $this->getTitle(), - 'content' => $this->getContent(), - 'description' => $this->getDescription(), - 'categories' => $this->categories, - 'inserter' => $this->inserter, - 'blockTypes' => $this->blockTypes, - 'templateTypes' => $this->templateTypes, - 'source' => $this->source, - 'viewportWidth' => $this->viewportWidth, - ]; - } + public function getProperties() { + return array( + 'title' => $this->getTitle(), + 'content' => $this->getContent(), + 'description' => $this->getDescription(), + 'categories' => $this->categories, + 'inserter' => $this->inserter, + 'blockTypes' => $this->blockTypes, + 'templateTypes' => $this->templateTypes, + 'source' => $this->source, + 'viewportWidth' => $this->viewportWidth, + ); + } - abstract protected function getContent(): string; + abstract protected function getContent(): string; - abstract protected function getTitle(): string; + abstract protected function getTitle(): string; - protected function getDescription(): string { - return ''; - } + protected function getDescription(): string { + return ''; + } } diff --git a/packages/php/email-editor/src/Engine/Patterns/Library/class-default-content-full.php b/packages/php/email-editor/src/Engine/Patterns/Library/class-default-content-full.php index 30eada0f28..c2fe519e96 100644 --- a/packages/php/email-editor/src/Engine/Patterns/Library/class-default-content-full.php +++ b/packages/php/email-editor/src/Engine/Patterns/Library/class-default-content-full.php @@ -3,45 +3,45 @@ namespace MailPoet\EmailEditor\Engine\Patterns\Library; class Default_Content_Full extends Abstract_Pattern { - protected $blockTypes = [ - 'core/post-content', - ]; + protected $blockTypes = array( + 'core/post-content', + ); - protected $templateTypes = [ - 'email-general-template', - ]; + protected $templateTypes = array( + 'email-general-template', + ); - protected function getContent(): string { - return ' + protected function getContent(): string { + return '
' . esc_html__('A one-column layout is great for simplified and concise content, like announcements or newsletters with brief updates. Drag blocks to add content and customize your styles from the styles panel on the top right.', 'mailpoet') . '
+' . esc_html__( 'A one-column layout is great for simplified and concise content, like announcements or newsletters with brief updates. Drag blocks to add content and customize your styles from the styles panel on the top right.', 'mailpoet' ) . '
-' . esc_html__('You received this email because you are subscribed to the [site:title]', 'mailpoet') . '
+' . esc_html__( 'You received this email because you are subscribed to the [site:title]', 'mailpoet' ) . '
-' . esc_html__('Unsubscribe', 'mailpoet') . ' | ' . esc_html__('Manage subscription', 'mailpoet') . '
+' . esc_html__( 'Unsubscribe', 'mailpoet' ) . ' | ' . esc_html__( 'Manage subscription', 'mailpoet' ) . '
' . esc_html__('A one-column layout is great for simplified and concise content, like announcements or newsletters with brief updates. Drag blocks to add content and customize your styles from the styles panel on the top right.', 'mailpoet') . '
+' . esc_html__( 'A one-column layout is great for simplified and concise content, like announcements or newsletters with brief updates. Drag blocks to add content and customize your styles from the styles panel on the top right.', 'mailpoet' ) . '
' . render_block($block) . ' | '; - } - $outputHtml .= '
'; - //var_dump($styles); - //echo ''; + // Debugging for content styles. Remember these get inlined. + // echo '
'; + // var_dump($styles); + // echo ''; - $styles = ''; + $styles = ''; - return CssInliner::fromHtml($styles . $html)->inlineCss()->render(); - } + return CssInliner::fromHtml( $styles . $html )->inlineCss()->render(); + } } diff --git a/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-process-manager.php b/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-process-manager.php index 6c0bcc23d1..883dcd4621 100644 --- a/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-process-manager.php +++ b/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-process-manager.php @@ -12,53 +12,53 @@ use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Spacing_P use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\Typography_Preprocessor; class Process_Manager { - /** @var Preprocessor[] */ - private $preprocessors = []; + /** @var Preprocessor[] */ + private $preprocessors = array(); - /** @var Postprocessor[] */ - private $postprocessors = []; + /** @var Postprocessor[] */ + private $postprocessors = array(); - public function __construct( - Cleanup_Preprocessor $cleanupPreprocessor, - Blocks_Width_Preprocessor $blocksWidthPreprocessor, - Typography_Preprocessor $typographyPreprocessor, - Spacing_Preprocessor $spacingPreprocessor, - Highlighting_Postprocessor $highlightingPostprocessor, - Variables_Postprocessor $variablesPostprocessor - ) { - $this->registerPreprocessor($cleanupPreprocessor); - $this->registerPreprocessor($blocksWidthPreprocessor); - $this->registerPreprocessor($typographyPreprocessor); - $this->registerPreprocessor($spacingPreprocessor); - $this->registerPostprocessor($highlightingPostprocessor); - $this->registerPostprocessor($variablesPostprocessor); - } + public function __construct( + Cleanup_Preprocessor $cleanupPreprocessor, + Blocks_Width_Preprocessor $blocksWidthPreprocessor, + Typography_Preprocessor $typographyPreprocessor, + Spacing_Preprocessor $spacingPreprocessor, + Highlighting_Postprocessor $highlightingPostprocessor, + Variables_Postprocessor $variablesPostprocessor + ) { + $this->registerPreprocessor( $cleanupPreprocessor ); + $this->registerPreprocessor( $blocksWidthPreprocessor ); + $this->registerPreprocessor( $typographyPreprocessor ); + $this->registerPreprocessor( $spacingPreprocessor ); + $this->registerPostprocessor( $highlightingPostprocessor ); + $this->registerPostprocessor( $variablesPostprocessor ); + } - /** - * @param array $parsedBlocks - * @param array{contentSize: string} $layout - * @param array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles - * @return array - */ - public function preprocess(array $parsedBlocks, array $layout, array $styles): array { - foreach ($this->preprocessors as $preprocessor) { - $parsedBlocks = $preprocessor->preprocess($parsedBlocks, $layout, $styles); - } - return $parsedBlocks; - } + /** + * @param array $parsedBlocks + * @param array{contentSize: string} $layout + * @param array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles + * @return array + */ + public function preprocess( array $parsedBlocks, array $layout, array $styles ): array { + foreach ( $this->preprocessors as $preprocessor ) { + $parsedBlocks = $preprocessor->preprocess( $parsedBlocks, $layout, $styles ); + } + return $parsedBlocks; + } - public function postprocess(string $html): string { - foreach ($this->postprocessors as $postprocessor) { - $html = $postprocessor->postprocess($html); - } - return $html; - } + public function postprocess( string $html ): string { + foreach ( $this->postprocessors as $postprocessor ) { + $html = $postprocessor->postprocess( $html ); + } + return $html; + } - public function registerPreprocessor(Preprocessor $preprocessor): void { - $this->preprocessors[] = $preprocessor; - } + public function registerPreprocessor( Preprocessor $preprocessor ): void { + $this->preprocessors[] = $preprocessor; + } - public function registerPostprocessor(Postprocessor $postprocessor): void { - $this->postprocessors[] = $postprocessor; - } + public function registerPostprocessor( Postprocessor $postprocessor ): void { + $this->postprocessors[] = $postprocessor; + } } diff --git a/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/content.css b/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/content.css index 87cf55f04c..075bdb0b11 100644 --- a/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/content.css +++ b/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/content.css @@ -1,28 +1,28 @@ /** - CSS reset for email clients for elements used in email content - StyleLint is disabled because some rules contain properties that linter marks as unknown (e.g. mso- prefix), but they are valid for email rendering +CSS reset for email clients for elements used in email content +StyleLint is disabled because some rules contain properties that linter marks as unknown (e.g. mso- prefix), but they are valid for email rendering */ /* stylelint-disable property-no-unknown */ table, td { - border-collapse: collapse; - mso-table-lspace: 0; - mso-table-rspace: 0; + border-collapse: collapse; + mso-table-lspace: 0; + mso-table-rspace: 0; } img { - border: 0; - height: auto; - -ms-interpolation-mode: bicubic; - line-height: 100%; - max-width: 100%; - outline: none; - text-decoration: none; + border: 0; + height: auto; + -ms-interpolation-mode: bicubic; + line-height: 100%; + max-width: 100%; + outline: none; + text-decoration: none; } p { - display: block; - margin: 0; + display: block; + margin: 0; } h1, @@ -31,25 +31,25 @@ h3, h4, h5, h6 { - margin-bottom: 0; - margin-top: 0; + margin-bottom: 0; + margin-top: 0; } /* Ensure border style is set when a block has a border */ .has-border-color { - border-style: solid; + border-style: solid; } /* We want ensure the same design for all email clients */ ul, ol { - /* When margin attribute is set to zero, Outlook doesn't render the list properly. As a possible workaround, we can reset only margin for top and bottom */ - margin-bottom: 0; - margin-top: 0; - padding: 0 0 0 40px; + /* When margin attribute is set to zero, Outlook doesn't render the list properly. As a possible workaround, we can reset only margin for top and bottom */ + margin-bottom: 0; + margin-top: 0; + padding: 0 0 0 40px; } /* Outlook was adding weird spaces around lists in some versions. Resetting vertical margin for list items solved it */ li { - margin-bottom: 0; - margin-top: 0; + margin-bottom: 0; + margin-top: 0; } diff --git a/packages/php/email-editor/src/Engine/Renderer/class-renderer.php b/packages/php/email-editor/src/Engine/Renderer/class-renderer.php index 10749f9e6c..42ff263183 100644 --- a/packages/php/email-editor/src/Engine/Renderer/class-renderer.php +++ b/packages/php/email-editor/src/Engine/Renderer/class-renderer.php @@ -11,94 +11,94 @@ use WP_Style_Engine; use WP_Theme_JSON; class Renderer { - private Theme_Controller $themeController; - private Content_Renderer $contentRenderer; - private Templates $templates; - /** @var WP_Theme_JSON|null */ - private static $theme = null; + private Theme_Controller $themeController; + private Content_Renderer $contentRenderer; + private Templates $templates; + /** @var WP_Theme_JSON|null */ + private static $theme = null; - const TEMPLATE_FILE = 'template-canvas.php'; - const TEMPLATE_STYLES_FILE = 'template-canvas.css'; + const TEMPLATE_FILE = 'template-canvas.php'; + const TEMPLATE_STYLES_FILE = 'template-canvas.css'; - public function __construct( - Content_Renderer $contentRenderer, - Templates $templates, - Theme_Controller $themeController - ) { - $this->contentRenderer = $contentRenderer; - $this->templates = $templates; - $this->themeController = $themeController; - } + public function __construct( + Content_Renderer $contentRenderer, + Templates $templates, + Theme_Controller $themeController + ) { + $this->contentRenderer = $contentRenderer; + $this->templates = $templates; + $this->themeController = $themeController; + } - /** - * During rendering, this stores the theme data for the template being rendered. - */ - public static function getTheme() { - return self::$theme; - } + /** + * During rendering, this stores the theme data for the template being rendered. + */ + public static function getTheme() { + return self::$theme; + } - public function render(\WP_Post $post, string $subject, string $preHeader, string $language, $metaRobots = ''): array { - $templateId = 'mailpoet/mailpoet//' . (get_page_template_slug($post) ?: 'email-general'); - $template = $this->templates->getBlockTemplate($templateId); - $theme = $this->templates->getBlockTemplateTheme($templateId, $template->wp_id); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + public function render( \WP_Post $post, string $subject, string $preHeader, string $language, $metaRobots = '' ): array { + $templateId = 'mailpoet/mailpoet//' . ( get_page_template_slug( $post ) ?: 'email-general' ); + $template = $this->templates->getBlockTemplate( $templateId ); + $theme = $this->templates->getBlockTemplateTheme( $templateId, $template->wp_id ); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - // Set the theme for the template. This is merged with base theme.json and core json before rendering. - self::$theme = new WP_Theme_JSON($theme, 'default'); + // Set the theme for the template. This is merged with base theme.json and core json before rendering. + self::$theme = new WP_Theme_JSON( $theme, 'default' ); - $emailStyles = $this->themeController->getStyles($post, $template); - $templateHtml = $this->contentRenderer->render($post, $template); - $layout = $this->themeController->getLayoutSettings(); + $emailStyles = $this->themeController->getStyles( $post, $template ); + $templateHtml = $this->contentRenderer->render( $post, $template ); + $layout = $this->themeController->getLayoutSettings(); - ob_start(); - include self::TEMPLATE_FILE; - $renderedTemplate = (string)ob_get_clean(); + ob_start(); + include self::TEMPLATE_FILE; + $renderedTemplate = (string) ob_get_clean(); - $templateStyles = - WP_Style_Engine::compile_css( - [ - 'background-color' => $emailStyles['color']['background'] ?? 'inherit', - 'color' => $emailStyles['color']['text'] ?? 'inherit', - 'padding-top' => $emailStyles['spacing']['padding']['top'] ?? '0px', - 'padding-bottom' => $emailStyles['spacing']['padding']['bottom'] ?? '0px', - 'padding-left' => $emailStyles['spacing']['padding']['left'] ?? '0px', - 'padding-right' => $emailStyles['spacing']['padding']['right'] ?? '0px', - 'font-family' => $emailStyles['typography']['fontFamily'] ?? 'inherit', - 'line-height' => $emailStyles['typography']['lineHeight'] ?? '1.5', - 'font-size' => $emailStyles['typography']['fontSize'] ?? 'inherit', - ], - 'body, .email_layout_wrapper' - ); - $templateStyles .= '.email_layout_wrapper { box-sizing: border-box;}'; - $templateStyles .= file_get_contents(dirname(__FILE__) . '/' . self::TEMPLATE_STYLES_FILE); - $templateStyles = ''; - $renderedTemplate = $this->inlineCSSStyles($templateStyles . $renderedTemplate); + $templateStyles = + WP_Style_Engine::compile_css( + array( + 'background-color' => $emailStyles['color']['background'] ?? 'inherit', + 'color' => $emailStyles['color']['text'] ?? 'inherit', + 'padding-top' => $emailStyles['spacing']['padding']['top'] ?? '0px', + 'padding-bottom' => $emailStyles['spacing']['padding']['bottom'] ?? '0px', + 'padding-left' => $emailStyles['spacing']['padding']['left'] ?? '0px', + 'padding-right' => $emailStyles['spacing']['padding']['right'] ?? '0px', + 'font-family' => $emailStyles['typography']['fontFamily'] ?? 'inherit', + 'line-height' => $emailStyles['typography']['lineHeight'] ?? '1.5', + 'font-size' => $emailStyles['typography']['fontSize'] ?? 'inherit', + ), + 'body, .email_layout_wrapper' + ); + $templateStyles .= '.email_layout_wrapper { box-sizing: border-box;}'; + $templateStyles .= file_get_contents( __DIR__ . '/' . self::TEMPLATE_STYLES_FILE ); + $templateStyles = ''; + $renderedTemplate = $this->inlineCSSStyles( $templateStyles . $renderedTemplate ); - // This is a workaround to support link :hover in some clients. Ideally we would remove the ability to set :hover - // however this is not possible using the color panel from Gutenberg. - if (isset($emailStyles['elements']['link'][':hover']['color']['text'])) { - $renderedTemplate = str_replace('', '', $renderedTemplate); - } + // This is a workaround to support link :hover in some clients. Ideally we would remove the ability to set :hover + // however this is not possible using the color panel from Gutenberg. + if ( isset( $emailStyles['elements']['link'][':hover']['color']['text'] ) ) { + $renderedTemplate = str_replace( '', '', $renderedTemplate ); + } - return [ - 'html' => $renderedTemplate, - 'text' => $this->renderTextVersion($renderedTemplate), - ]; - } + return array( + 'html' => $renderedTemplate, + 'text' => $this->renderTextVersion( $renderedTemplate ), + ); + } - /** - * @param string $template - * @return string - */ - private function inlineCSSStyles($template) { - return CssInliner::fromHtml($template)->inlineCss()->render(); - } + /** + * @param string $template + * @return string + */ + private function inlineCSSStyles( $template ) { + return CssInliner::fromHtml( $template )->inlineCss()->render(); + } - /** - * @param string $template - * @return string - */ - private function renderTextVersion($template) { - $template = (mb_detect_encoding($template, 'UTF-8', true)) ? $template : mb_convert_encoding($template, 'UTF-8', mb_list_encodings()); - return @Html2Text::convert($template); - } + /** + * @param string $template + * @return string + */ + private function renderTextVersion( $template ) { + $template = ( mb_detect_encoding( $template, 'UTF-8', true ) ) ? $template : mb_convert_encoding( $template, 'UTF-8', mb_list_encodings() ); + return @Html2Text::convert( $template ); + } } diff --git a/packages/php/email-editor/src/Engine/Renderer/template-canvas.css b/packages/php/email-editor/src/Engine/Renderer/template-canvas.css index 4932f35606..6a77cf3adf 100644 --- a/packages/php/email-editor/src/Engine/Renderer/template-canvas.css +++ b/packages/php/email-editor/src/Engine/Renderer/template-canvas.css @@ -3,89 +3,89 @@ /* StyleLint is disabled because some rules contain properties that linter marks as unknown (e.g. mso- prefix), but they are valid for email rendering */ /* stylelint-disable property-no-unknown */ body { - margin: 0; - padding: 0; - -webkit-text-size-adjust: 100%; /* From MJMJ - Automatic test adjustment on mobile max to 100% */ - -ms-text-size-adjust: 100%; /* From MJMJ - Automatic test adjustment on mobile max to 100% */ - word-spacing: normal; + margin: 0; + padding: 0; + -webkit-text-size-adjust: 100%; /* From MJMJ - Automatic test adjustment on mobile max to 100% */ + -ms-text-size-adjust: 100%; /* From MJMJ - Automatic test adjustment on mobile max to 100% */ + word-spacing: normal; } a { - text-decoration: none; + text-decoration: none; } .email_layout_wrapper { - margin: 0 auto; - width: 100%; + margin: 0 auto; + width: 100%; } .email_content_wrapper { - direction: ltr; - font-size: inherit; - text-align: left; + direction: ltr; + font-size: inherit; + text-align: left; } .email_footer { - direction: ltr; - text-align: center; + direction: ltr; + text-align: center; } /* https://www.emailonacid.com/blog/article/email-development/tips-for-coding-email-preheaders */ .email_preheader, .email_preheader * { - color: #fff; - display: none; - font-size: 1px; - line-height: 1px; - max-height: 0; - max-width: 0; - mso-hide: all; - opacity: 0; - overflow: hidden; - -webkit-text-size-adjust: none; - visibility: hidden; + color: #fff; + display: none; + font-size: 1px; + line-height: 1px; + max-height: 0; + max-width: 0; + mso-hide: all; + opacity: 0; + overflow: hidden; + -webkit-text-size-adjust: none; + visibility: hidden; } @media screen and (max-width: 660px) { - .email-block-column-content { - max-width: 100% !important; - } - .block { - display: block; - width: 100% !important; - } + .email-block-column-content { + max-width: 100% !important; + } + .block { + display: block; + width: 100% !important; + } - /* Ensure proper width of columns on mobile when we set 100% and a border is set */ - .email-block-column { - box-sizing: border-box; - } + /* Ensure proper width of columns on mobile when we set 100% and a border is set */ + .email-block-column { + box-sizing: border-box; + } - /* We set width to some tables e.g. for wrappers of horizontally aligned images and we force width 100% on mobile */ - .email-table-with-width { - width: 100% !important; - } + /* We set width to some tables e.g. for wrappers of horizontally aligned images and we force width 100% on mobile */ + .email-table-with-width { + width: 100% !important; + } - /* Flex Layout */ - .layout-flex-wrapper, - .layout-flex-wrapper tbody, - .layout-flex-wrapper tr { - display: block !important; - width: 100% !important; - } + /* Flex Layout */ + .layout-flex-wrapper, + .layout-flex-wrapper tbody, + .layout-flex-wrapper tr { + display: block !important; + width: 100% !important; + } - .layout-flex-item { - display: block !important; - padding-bottom: 8px !important; /* Half of the flex gap between blocks */ - padding-left: 0 !important; - width: 100% !important; - } + .layout-flex-item { + display: block !important; + padding-bottom: 8px !important; /* Half of the flex gap between blocks */ + padding-left: 0 !important; + width: 100% !important; + } - .layout-flex-item table, - .layout-flex-item td { - box-sizing: border-box !important; - display: block !important; - width: 100% !important; - } - /* Flex Layout End */ + .layout-flex-item table, + .layout-flex-item td { + box-sizing: border-box !important; + display: block !important; + width: 100% !important; + } + /* Flex Layout End */ } /* stylelint-enable property-no-unknown */ diff --git a/packages/php/email-editor/src/Engine/Renderer/template-canvas.php b/packages/php/email-editor/src/Engine/Renderer/template-canvas.php index 4754f4e0bc..53a773329e 100644 --- a/packages/php/email-editor/src/Engine/Renderer/template-canvas.php +++ b/packages/php/email-editor/src/Engine/Renderer/template-canvas.php @@ -6,6 +6,7 @@ * Template file to render the current 'wp_template', specifcally for emails. * * Variables passed to this template: + * * @var $subject string * @var $preHeader string * @var $templateHtml string @@ -15,33 +16,33 @@ ?> > -
- - | -
- - | -
+ + | +
+ + | +
empty
'; - $template->slug = $templateSlug; - $template->source = 'custom'; - $template->type = $post->post_type; - $template->description = $post->post_excerpt; - $template->title = $post->post_title; - $template->status = $post->post_status; - $template->has_theme_file = false; - $template->is_custom = true; - $template->post_types = []; + $template = new WP_Block_Template(); + $template->wp_id = $post->ID; + $template->id = $templateId; + $template->theme = $templatePrefix; + $template->content = $post->post_content ? $post->post_content : 'empty
'; + $template->slug = $templateSlug; + $template->source = 'custom'; + $template->type = $post->post_type; + $template->description = $post->post_excerpt; + $template->title = $post->post_title; + $template->status = $post->post_status; + $template->has_theme_file = false; + $template->is_custom = true; + $template->post_types = array(); - if ('wp_template_part' === $post->post_type) { - $type_terms = get_the_terms($post, 'wp_template_part_area'); + if ( 'wp_template_part' === $post->post_type ) { + $type_terms = get_the_terms( $post, 'wp_template_part_area' ); - if (!is_wp_error($type_terms) && false !== $type_terms) { - $template->area = $type_terms[0]->name; - } - } + if ( ! is_wp_error( $type_terms ) && false !== $type_terms ) { + $template->area = $type_terms[0]->name; + } + } - return $template; - } + return $template; + } - public function buildBlockTemplateFromFile($templateObject): WP_Block_Template { - $template = new WP_Block_Template(); - $template->id = $templateObject->id; - $template->theme = $templateObject->theme; - $template->content = (string)file_get_contents($templateObject->path); - $template->source = $templateObject->source; - $template->slug = $templateObject->slug; - $template->type = $templateObject->type; - $template->title = $templateObject->title; - $template->description = $templateObject->description; - $template->status = 'publish'; - $template->has_theme_file = false; - $template->post_types = $templateObject->post_types; - $template->is_custom = false; // Templates are only custom if they are loaded from the DB. - $template->area = 'uncategorized'; - return $template; - } + public function buildBlockTemplateFromFile( $templateObject ): WP_Block_Template { + $template = new WP_Block_Template(); + $template->id = $templateObject->id; + $template->theme = $templateObject->theme; + $template->content = (string) file_get_contents( $templateObject->path ); + $template->source = $templateObject->source; + $template->slug = $templateObject->slug; + $template->type = $templateObject->type; + $template->title = $templateObject->title; + $template->description = $templateObject->description; + $template->status = 'publish'; + $template->has_theme_file = false; + $template->post_types = $templateObject->post_types; + $template->is_custom = false; // Templates are only custom if they are loaded from the DB. + $template->area = 'uncategorized'; + return $template; + } } diff --git a/packages/php/email-editor/src/Engine/class-email-api-controller.php b/packages/php/email-editor/src/Engine/class-email-api-controller.php index de3b26d27d..95f84ec089 100644 --- a/packages/php/email-editor/src/Engine/class-email-api-controller.php +++ b/packages/php/email-editor/src/Engine/class-email-api-controller.php @@ -5,22 +5,22 @@ namespace MailPoet\EmailEditor\Engine; use MailPoet\EmailEditor\Validator\Builder; class Email_Api_Controller { - /** - * @return array - Email specific data such styles. - */ - public function getEmailData(): array { - // Here comes code getting Email specific data that will be passed on 'email_data' attribute - return []; - } + /** + * @return array - Email specific data such styles. + */ + public function getEmailData(): array { + // Here comes code getting Email specific data that will be passed on 'email_data' attribute + return array(); + } - /** - * Update Email specific data we store. - */ - public function saveEmailData(array $data, \WP_Post $emailPost): void { - // Here comes code saving of Email specific data that will be passed on 'email_data' attribute - } + /** + * Update Email specific data we store. + */ + public function saveEmailData( array $data, \WP_Post $emailPost ): void { + // Here comes code saving of Email specific data that will be passed on 'email_data' attribute + } - public function getEmailDataSchema(): array { - return Builder::object()->toArray(); - } + public function getEmailDataSchema(): array { + return Builder::object()->toArray(); + } } diff --git a/packages/php/email-editor/src/Engine/class-email-editor.php b/packages/php/email-editor/src/Engine/class-email-editor.php index 07255951f9..7044ef915f 100644 --- a/packages/php/email-editor/src/Engine/class-email-editor.php +++ b/packages/php/email-editor/src/Engine/class-email-editor.php @@ -13,116 +13,123 @@ use WP_Theme_JSON; * See register_post_type for details about EmailPostType args. */ class Email_Editor { - public const MAILPOET_EMAIL_META_THEME_TYPE = 'mailpoet_email_theme'; + public const MAILPOET_EMAIL_META_THEME_TYPE = 'mailpoet_email_theme'; - private Email_Api_Controller $emailApiController; - private Templates $templates; - private Template_Preview $templatePreview; - private Patterns $patterns; - private Settings_Controller $settingsController; + private Email_Api_Controller $emailApiController; + private Templates $templates; + private Template_Preview $templatePreview; + private Patterns $patterns; + private Settings_Controller $settingsController; - public function __construct( - Email_Api_Controller $emailApiController, - Templates $templates, - Template_Preview $templatePreview, - Patterns $patterns, - Settings_Controller $settingsController - ) { - $this->emailApiController = $emailApiController; - $this->templates = $templates; - $this->templatePreview = $templatePreview; - $this->patterns = $patterns; - $this->settingsController = $settingsController; - } + public function __construct( + Email_Api_Controller $emailApiController, + Templates $templates, + Template_Preview $templatePreview, + Patterns $patterns, + Settings_Controller $settingsController + ) { + $this->emailApiController = $emailApiController; + $this->templates = $templates; + $this->templatePreview = $templatePreview; + $this->patterns = $patterns; + $this->settingsController = $settingsController; + } - public function initialize(): void { - do_action('mailpoet_email_editor_initialized'); - add_filter('mailpoet_email_editor_rendering_theme_styles', [$this, 'extendEmailThemeStyles'], 10, 2); - $this->registerBlockTemplates(); - $this->registerBlockPatterns(); - $this->registerEmailPostTypes(); - $this->registerEmailPostSendStatus(); - $isEditorPage = apply_filters('mailpoet_is_email_editor_page', false); - if ($isEditorPage) { - $this->extendEmailPostApi(); - $this->settingsController->init(); - } - } + public function initialize(): void { + do_action( 'mailpoet_email_editor_initialized' ); + add_filter( 'mailpoet_email_editor_rendering_theme_styles', array( $this, 'extendEmailThemeStyles' ), 10, 2 ); + $this->registerBlockTemplates(); + $this->registerBlockPatterns(); + $this->registerEmailPostTypes(); + $this->registerEmailPostSendStatus(); + $isEditorPage = apply_filters( 'mailpoet_is_email_editor_page', false ); + if ( $isEditorPage ) { + $this->extendEmailPostApi(); + $this->settingsController->init(); + } + } - private function registerBlockTemplates(): void { - // Since we cannot currently disable blocks in the editor for specific templates, disable templates when viewing site editor. @see https://github.com/WordPress/gutenberg/issues/41062 - if (strstr(wp_unslash($_SERVER['REQUEST_URI'] ?? ''), 'site-editor.php') === false) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - $this->templates->initialize(); - $this->templatePreview->initialize(); - } - } + private function registerBlockTemplates(): void { + // Since we cannot currently disable blocks in the editor for specific templates, disable templates when viewing site editor. @see https://github.com/WordPress/gutenberg/issues/41062 + if ( strstr( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ), 'site-editor.php' ) === false ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + $this->templates->initialize(); + $this->templatePreview->initialize(); + } + } - private function registerBlockPatterns(): void { - $this->patterns->initialize(); - } + private function registerBlockPatterns(): void { + $this->patterns->initialize(); + } - /** - * Register all custom post types that should be edited via the email editor - * The post types are added via mailpoet_email_editor_post_types filter. - */ - private function registerEmailPostTypes(): void { - foreach ($this->getPostTypes() as $postType) { - register_post_type( - $postType['name'], - array_merge($this->getDefaultEmailPostArgs(), $postType['args']) - ); - } - } + /** + * Register all custom post types that should be edited via the email editor + * The post types are added via mailpoet_email_editor_post_types filter. + */ + private function registerEmailPostTypes(): void { + foreach ( $this->getPostTypes() as $postType ) { + register_post_type( + $postType['name'], + array_merge( $this->getDefaultEmailPostArgs(), $postType['args'] ) + ); + } + } - /** - * @phpstan-return EmailPostType[] - */ - private function getPostTypes(): array { - $postTypes = []; - return apply_filters('mailpoet_email_editor_post_types', $postTypes); - } + /** + * @phpstan-return EmailPostType[] + */ + private function getPostTypes(): array { + $postTypes = array(); + return apply_filters( 'mailpoet_email_editor_post_types', $postTypes ); + } - private function getDefaultEmailPostArgs(): array { - return [ - 'public' => false, - 'hierarchical' => false, - 'show_ui' => true, - 'show_in_menu' => false, - 'show_in_nav_menus' => false, - 'supports' => ['editor', 'title', 'custom-fields'], // 'custom-fields' is required for loading meta fields via API - 'has_archive' => true, - 'show_in_rest' => true, // Important to enable Gutenberg editor - ]; - } + private function getDefaultEmailPostArgs(): array { + return array( + 'public' => false, + 'hierarchical' => false, + 'show_ui' => true, + 'show_in_menu' => false, + 'show_in_nav_menus' => false, + 'supports' => array( 'editor', 'title', 'custom-fields' ), // 'custom-fields' is required for loading meta fields via API + 'has_archive' => true, + 'show_in_rest' => true, // Important to enable Gutenberg editor + ); + } - private function registerEmailPostSendStatus(): void { - register_post_status('sent', [ - 'public' => false, - 'exclude_from_search' => true, - 'internal' => true, // for now, we hide it, if we use the status in the listings we may flip this and following values - 'show_in_admin_all_list' => false, - 'show_in_admin_status_list' => false, - ]); - } + private function registerEmailPostSendStatus(): void { + register_post_status( + 'sent', + array( + 'public' => false, + 'exclude_from_search' => true, + 'internal' => true, // for now, we hide it, if we use the status in the listings we may flip this and following values + 'show_in_admin_all_list' => false, + 'show_in_admin_status_list' => false, + ) + ); + } - public function extendEmailPostApi() { - $emailPostTypes = array_column($this->getPostTypes(), 'name'); - register_rest_field($emailPostTypes, 'email_data', [ - 'get_callback' => [$this->emailApiController, 'getEmailData'], - 'update_callback' => [$this->emailApiController, 'saveEmailData'], - 'schema' => $this->emailApiController->getEmailDataSchema(), - ]); - } + public function extendEmailPostApi() { + $emailPostTypes = array_column( $this->getPostTypes(), 'name' ); + register_rest_field( + $emailPostTypes, + 'email_data', + array( + 'get_callback' => array( $this->emailApiController, 'getEmailData' ), + 'update_callback' => array( $this->emailApiController, 'saveEmailData' ), + 'schema' => $this->emailApiController->getEmailDataSchema(), + ) + ); + } - public function getEmailThemeDataSchema(): array { - return (new Email_Styles_Schema())->getSchema(); - } + public function getEmailThemeDataSchema(): array { + return ( new Email_Styles_Schema() )->getSchema(); + } - public function extendEmailThemeStyles(WP_Theme_JSON $theme, WP_Post $post): WP_Theme_JSON { - $emailTheme = get_post_meta($post->ID, Email_Editor::MAILPOET_EMAIL_META_THEME_TYPE, true); - if ($emailTheme && is_array($emailTheme)) { - $theme->merge(new WP_Theme_JSON($emailTheme)); - } - return $theme; - } + public function extendEmailThemeStyles( WP_Theme_JSON $theme, WP_Post $post ): WP_Theme_JSON { + $emailTheme = get_post_meta( $post->ID, self::MAILPOET_EMAIL_META_THEME_TYPE, true ); + if ( $emailTheme && is_array( $emailTheme ) ) { + $theme->merge( new WP_Theme_JSON( $emailTheme ) ); + } + return $theme; + } } diff --git a/packages/php/email-editor/src/Engine/class-email-styles-schema.php b/packages/php/email-editor/src/Engine/class-email-styles-schema.php index 3382770e28..f649ae6720 100644 --- a/packages/php/email-editor/src/Engine/class-email-styles-schema.php +++ b/packages/php/email-editor/src/Engine/class-email-styles-schema.php @@ -5,64 +5,96 @@ namespace MailPoet\EmailEditor\Engine; use MailPoet\EmailEditor\Validator\Builder; class Email_Styles_Schema { - public function getSchema(): array { - $typographyProps = Builder::object([ - 'fontFamily' => Builder::string()->nullable(), - 'fontSize' => Builder::string()->nullable(), - 'fontStyle' => Builder::string()->nullable(), - 'fontWeight' => Builder::string()->nullable(), - 'letterSpacing' => Builder::string()->nullable(), - 'lineHeight' => Builder::string()->nullable(), - 'textTransform' => Builder::string()->nullable(), - 'textDecoration' => Builder::string()->nullable(), - ])->nullable(); - return Builder::object([ - 'version' => Builder::integer(), - 'styles' => Builder::object([ - 'spacing' => Builder::object([ - 'padding' => Builder::object([ - 'top' => Builder::string(), - 'right' => Builder::string(), - 'bottom' => Builder::string(), - 'left' => Builder::string(), - ])->nullable(), - 'blockGap' => Builder::string()->nullable(), - ])->nullable(), - 'color' => Builder::object([ - 'background' => Builder::string()->nullable(), - 'text' => Builder::string()->nullable(), - ])->nullable(), - 'typography' => $typographyProps, - 'elements' => Builder::object([ - 'heading' => Builder::object([ - 'typography' => $typographyProps, - ])->nullable(), - 'button' => Builder::object([ - 'typography' => $typographyProps, - ])->nullable(), - 'link' => Builder::object([ - 'typography' => $typographyProps, - ])->nullable(), - 'h1' => Builder::object([ - 'typography' => $typographyProps, - ])->nullable(), - 'h2' => Builder::object([ - 'typography' => $typographyProps, - ])->nullable(), - 'h3' => Builder::object([ - 'typography' => $typographyProps, - ])->nullable(), - 'h4' => Builder::object([ - 'typography' => $typographyProps, - ])->nullable(), - 'h5' => Builder::object([ - 'typography' => $typographyProps, - ])->nullable(), - 'h6' => Builder::object([ - 'typography' => $typographyProps, - ])->nullable(), - ])->nullable(), - ])->nullable(), - ])->toArray(); - } + public function getSchema(): array { + $typographyProps = Builder::object( + array( + 'fontFamily' => Builder::string()->nullable(), + 'fontSize' => Builder::string()->nullable(), + 'fontStyle' => Builder::string()->nullable(), + 'fontWeight' => Builder::string()->nullable(), + 'letterSpacing' => Builder::string()->nullable(), + 'lineHeight' => Builder::string()->nullable(), + 'textTransform' => Builder::string()->nullable(), + 'textDecoration' => Builder::string()->nullable(), + ) + )->nullable(); + return Builder::object( + array( + 'version' => Builder::integer(), + 'styles' => Builder::object( + array( + 'spacing' => Builder::object( + array( + 'padding' => Builder::object( + array( + 'top' => Builder::string(), + 'right' => Builder::string(), + 'bottom' => Builder::string(), + 'left' => Builder::string(), + ) + )->nullable(), + 'blockGap' => Builder::string()->nullable(), + ) + )->nullable(), + 'color' => Builder::object( + array( + 'background' => Builder::string()->nullable(), + 'text' => Builder::string()->nullable(), + ) + )->nullable(), + 'typography' => $typographyProps, + 'elements' => Builder::object( + array( + 'heading' => Builder::object( + array( + 'typography' => $typographyProps, + ) + )->nullable(), + 'button' => Builder::object( + array( + 'typography' => $typographyProps, + ) + )->nullable(), + 'link' => Builder::object( + array( + 'typography' => $typographyProps, + ) + )->nullable(), + 'h1' => Builder::object( + array( + 'typography' => $typographyProps, + ) + )->nullable(), + 'h2' => Builder::object( + array( + 'typography' => $typographyProps, + ) + )->nullable(), + 'h3' => Builder::object( + array( + 'typography' => $typographyProps, + ) + )->nullable(), + 'h4' => Builder::object( + array( + 'typography' => $typographyProps, + ) + )->nullable(), + 'h5' => Builder::object( + array( + 'typography' => $typographyProps, + ) + )->nullable(), + 'h6' => Builder::object( + array( + 'typography' => $typographyProps, + ) + )->nullable(), + ) + )->nullable(), + ) + )->nullable(), + ) + )->toArray(); + } } diff --git a/packages/php/email-editor/src/Engine/class-settings-controller.php b/packages/php/email-editor/src/Engine/class-settings-controller.php index 4c2be2ef87..4fa8e076fe 100644 --- a/packages/php/email-editor/src/Engine/class-settings-controller.php +++ b/packages/php/email-editor/src/Engine/class-settings-controller.php @@ -4,130 +4,130 @@ namespace MailPoet\EmailEditor\Engine; class Settings_Controller { - const ALLOWED_BLOCK_TYPES = [ - 'core/button', - 'core/buttons', - 'core/paragraph', - 'core/heading', - 'core/column', - 'core/columns', - 'core/image', - 'core/list', - 'core/list-item', - 'core/group', - 'core/spacer' - ]; + const ALLOWED_BLOCK_TYPES = array( + 'core/button', + 'core/buttons', + 'core/paragraph', + 'core/heading', + 'core/column', + 'core/columns', + 'core/image', + 'core/list', + 'core/list-item', + 'core/group', + 'core/spacer', + ); - const DEFAULT_SETTINGS = [ - 'enableCustomUnits' => ['px', '%'], - ]; + const DEFAULT_SETTINGS = array( + 'enableCustomUnits' => array( 'px', '%' ), + ); - private Theme_Controller $themeController; + private Theme_Controller $themeController; - private array $iframeAssets = []; + private array $iframeAssets = array(); - /** - * @param Theme_Controller $themeController - */ - public function __construct( - Theme_Controller $themeController - ) { - $this->themeController = $themeController; - } + /** + * @param Theme_Controller $themeController + */ + public function __construct( + Theme_Controller $themeController + ) { + $this->themeController = $themeController; + } - public function init() { - // We need to initialize these assets early because they are read from global variables $wp_styles and $wp_scripts - // and in later WordPress page load pages they contain stuff we don't want (e.g. html for admin login popup) - // in the post editor this is called directly in post.php - $this->iframeAssets = _wp_get_iframed_editor_assets(); - } + public function init() { + // We need to initialize these assets early because they are read from global variables $wp_styles and $wp_scripts + // and in later WordPress page load pages they contain stuff we don't want (e.g. html for admin login popup) + // in the post editor this is called directly in post.php + $this->iframeAssets = _wp_get_iframed_editor_assets(); + } - public function getSettings(): array { - $coreDefaultSettings = \get_default_block_editor_settings(); - $themeSettings = $this->themeController->getSettings(); + public function getSettings(): array { + $coreDefaultSettings = \get_default_block_editor_settings(); + $themeSettings = $this->themeController->getSettings(); - $settings = array_merge($coreDefaultSettings, self::DEFAULT_SETTINGS); - $settings['allowedBlockTypes'] = self::ALLOWED_BLOCK_TYPES; - // Assets for iframe editor (component styles, scripts, etc.) - $settings['__unstableResolvedAssets'] = $this->iframeAssets; - $editorContentStyles = file_get_contents(__DIR__ . '/content-editor.css'); - $sharesContentStyles = file_get_contents(__DIR__ . '/content-shared.css'); - $settings['styles'] = [ - ['css' => $editorContentStyles], - ['css' => $sharesContentStyles], - ]; + $settings = array_merge( $coreDefaultSettings, self::DEFAULT_SETTINGS ); + $settings['allowedBlockTypes'] = self::ALLOWED_BLOCK_TYPES; + // Assets for iframe editor (component styles, scripts, etc.) + $settings['__unstableResolvedAssets'] = $this->iframeAssets; + $editorContentStyles = file_get_contents( __DIR__ . '/content-editor.css' ); + $sharesContentStyles = file_get_contents( __DIR__ . '/content-shared.css' ); + $settings['styles'] = array( + array( 'css' => $editorContentStyles ), + array( 'css' => $sharesContentStyles ), + ); - $settings['__experimentalFeatures'] = $themeSettings; - // Controls which alignment options are available for blocks - $settings['supportsLayout'] = true; // Allow using default layouts - $settings['__unstableIsBlockBasedTheme'] = true; // For default setting this to true disables wide and full alignments - return $settings; - } + $settings['__experimentalFeatures'] = $themeSettings; + // Controls which alignment options are available for blocks + $settings['supportsLayout'] = true; // Allow using default layouts + $settings['__unstableIsBlockBasedTheme'] = true; // For default setting this to true disables wide and full alignments + return $settings; + } - /** - * @return array{contentSize: string, wideSize: string} - */ - public function getLayout(): array { - $layoutSettings = $this->themeController->getLayoutSettings(); - return [ - 'contentSize' => $layoutSettings['contentSize'], - 'wideSize' => $layoutSettings['wideSize'], - ]; - } + /** + * @return array{contentSize: string, wideSize: string} + */ + public function getLayout(): array { + $layoutSettings = $this->themeController->getLayoutSettings(); + return array( + 'contentSize' => $layoutSettings['contentSize'], + 'wideSize' => $layoutSettings['wideSize'], + ); + } - /** - * @return array{ - * spacing: array{ - * blockGap: string, - * padding: array{bottom: string, left: string, right: string, top: string} - * }, - * color: array{ - * background: string - * }, - * typography: array{ - * fontFamily: string - * } - * } - */ - public function getEmailStyles(): array { - $theme = $this->getTheme(); - return $theme->get_data()['styles']; - } + /** + * @return array{ + * spacing: array{ + * blockGap: string, + * padding: array{bottom: string, left: string, right: string, top: string} + * }, + * color: array{ + * background: string + * }, + * typography: array{ + * fontFamily: string + * } + * } + */ + public function getEmailStyles(): array { + $theme = $this->getTheme(); + return $theme->get_data()['styles']; + } - public function getLayoutWidthWithoutPadding(): string { - $styles = $this->getEmailStyles(); - $layout = $this->getLayout(); - $width = $this->parseNumberFromStringWithPixels($layout['contentSize']); - $width -= $this->parseNumberFromStringWithPixels($styles['spacing']['padding']['left']); - $width -= $this->parseNumberFromStringWithPixels($styles['spacing']['padding']['right']); - return "{$width}px"; - } + public function getLayoutWidthWithoutPadding(): string { + $styles = $this->getEmailStyles(); + $layout = $this->getLayout(); + $width = $this->parseNumberFromStringWithPixels( $layout['contentSize'] ); + $width -= $this->parseNumberFromStringWithPixels( $styles['spacing']['padding']['left'] ); + $width -= $this->parseNumberFromStringWithPixels( $styles['spacing']['padding']['right'] ); + return "{$width}px"; + } - public function parseStylesToArray(string $styles): array { - $styles = explode(';', $styles); - $parsedStyles = []; - foreach ($styles as $style) { - $style = explode(':', $style); - if (count($style) === 2) { - $parsedStyles[trim($style[0])] = trim($style[1]); - } - } - return $parsedStyles; - } + public function parseStylesToArray( string $styles ): array { + $styles = explode( ';', $styles ); + $parsedStyles = array(); + foreach ( $styles as $style ) { + $style = explode( ':', $style ); + if ( count( $style ) === 2 ) { + $parsedStyles[ trim( $style[0] ) ] = trim( $style[1] ); + } + } + return $parsedStyles; + } - public function parseNumberFromStringWithPixels(string $string): float { - return (float)str_replace('px', '', $string); - } + public function parseNumberFromStringWithPixels( string $string ): float { + return (float) str_replace( 'px', '', $string ); + } - public function getTheme(): \WP_Theme_JSON { - return $this->themeController->getTheme(); - } + public function getTheme(): \WP_Theme_JSON { + return $this->themeController->getTheme(); + } - public function translateSlugToFontSize(string $fontSize): string { - return $this->themeController->translateSlugToFontSize($fontSize); - } + public function translateSlugToFontSize( string $fontSize ): string { + return $this->themeController->translateSlugToFontSize( $fontSize ); + } - public function translateSlugToColor(string $colorSlug): string { - return $this->themeController->translateSlugToColor($colorSlug); - } + public function translateSlugToColor( string $colorSlug ): string { + return $this->themeController->translateSlugToColor( $colorSlug ); + } } diff --git a/packages/php/email-editor/src/Engine/class-theme-controller.php b/packages/php/email-editor/src/Engine/class-theme-controller.php index c51ed422d5..1d9cf4966e 100644 --- a/packages/php/email-editor/src/Engine/class-theme-controller.php +++ b/packages/php/email-editor/src/Engine/class-theme-controller.php @@ -11,233 +11,233 @@ use WP_Theme_JSON_Resolver; * This class is responsible for accessing data defined by the theme.json. */ class Theme_Controller { - private WP_Theme_JSON $coreTheme; - private WP_Theme_JSON $baseTheme; + private WP_Theme_JSON $coreTheme; + private WP_Theme_JSON $baseTheme; - public function __construct() { - $this->coreTheme = WP_Theme_JSON_Resolver::get_core_data(); - $this->baseTheme = new WP_Theme_JSON((array)json_decode((string)file_get_contents(dirname(__FILE__) . '/theme.json'), true), 'default'); - } + public function __construct() { + $this->coreTheme = WP_Theme_JSON_Resolver::get_core_data(); + $this->baseTheme = new WP_Theme_JSON( (array) json_decode( (string) file_get_contents( __DIR__ . '/theme.json' ), true ), 'default' ); + } - /** - * Gets combined theme data from the core and base theme, merged with the currently rendered template. - * - * @return WP_Theme_JSON - */ - public function getTheme(): WP_Theme_JSON { - $theme = new WP_Theme_JSON(); - $theme->merge($this->coreTheme); - $theme->merge($this->baseTheme); + /** + * Gets combined theme data from the core and base theme, merged with the currently rendered template. + * + * @return WP_Theme_JSON + */ + public function getTheme(): WP_Theme_JSON { + $theme = new WP_Theme_JSON(); + $theme->merge( $this->coreTheme ); + $theme->merge( $this->baseTheme ); - if (Renderer::getTheme() !== null) { - $theme->merge(Renderer::getTheme()); - } + if ( Renderer::getTheme() !== null ) { + $theme->merge( Renderer::getTheme() ); + } - return apply_filters('mailpoet_email_editor_theme_json', $theme); - } + return apply_filters( 'mailpoet_email_editor_theme_json', $theme ); + } - private function recursiveReplacePresets($values, $presets) { - foreach ($values as $key => $value) { - if (is_array($value)) { - $values[$key] = $this->recursiveReplacePresets($value, $presets); - } elseif (is_string($value)) { - $values[$key] = preg_replace(array_keys($presets), array_values($presets), $value); - } else { - $values[$key] = $value; - } - } - return $values; - } + private function recursiveReplacePresets( $values, $presets ) { + foreach ( $values as $key => $value ) { + if ( is_array( $value ) ) { + $values[ $key ] = $this->recursiveReplacePresets( $value, $presets ); + } elseif ( is_string( $value ) ) { + $values[ $key ] = preg_replace( array_keys( $presets ), array_values( $presets ), $value ); + } else { + $values[ $key ] = $value; + } + } + return $values; + } - private function recursiveExtractPresetVariables($styles) { - foreach ($styles as $key => $styleValue) { - if (is_array($styleValue)) { - $styles[$key] = $this->recursiveExtractPresetVariables($styleValue); - } elseif (strpos($styleValue, 'var:preset|') === 0) { - $styles[$key] = 'var(--wp--' . str_replace('|', '--', str_replace('var:', '', $styleValue)) . ')'; - } else { - $styles[$key] = $styleValue; - } - } - return $styles; - } + private function recursiveExtractPresetVariables( $styles ) { + foreach ( $styles as $key => $styleValue ) { + if ( is_array( $styleValue ) ) { + $styles[ $key ] = $this->recursiveExtractPresetVariables( $styleValue ); + } elseif ( strpos( $styleValue, 'var:preset|' ) === 0 ) { + $styles[ $key ] = 'var(--wp--' . str_replace( '|', '--', str_replace( 'var:', '', $styleValue ) ) . ')'; + } else { + $styles[ $key ] = $styleValue; + } + } + return $styles; + } - /** - * Get styles for the e-mail. - * - * @param \WP_Post|null $post Post object. - * @param \WP_Block_Template|null $template Template object. - * @param bool $convertPresets Convert presets to valid CSS values. - * @return array{ - * spacing: array{ - * blockGap: string, - * padding: array{bottom: string, left: string, right: string, top: string} - * }, - * color: array{ - * background: string - * }, - * typography: array{ - * fontFamily: string - * } - * } - */ - public function getStyles($post = null, $template = null): array { - $themeStyles = $this->getTheme()->get_data()['styles']; + /** + * Get styles for the e-mail. + * + * @param \WP_Post|null $post Post object. + * @param \WP_Block_Template|null $template Template object. + * @param bool $convertPresets Convert presets to valid CSS values. + * @return array{ + * spacing: array{ + * blockGap: string, + * padding: array{bottom: string, left: string, right: string, top: string} + * }, + * color: array{ + * background: string + * }, + * typography: array{ + * fontFamily: string + * } + * } + */ + public function getStyles( $post = null, $template = null ): array { + $themeStyles = $this->getTheme()->get_data()['styles']; - // Replace template styles. - if ($template && $template->wp_id) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - $templateTheme = (array)get_post_meta($template->wp_id, 'mailpoet_email_theme', true); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - $templateStyles = (array)($templateTheme['styles'] ?? []); - $themeStyles = array_replace_recursive($themeStyles, $templateStyles); - } + // Replace template styles. + if ( $template && $template->wp_id ) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + $templateTheme = (array) get_post_meta( $template->wp_id, 'mailpoet_email_theme', true ); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + $templateStyles = (array) ( $templateTheme['styles'] ?? array() ); + $themeStyles = array_replace_recursive( $themeStyles, $templateStyles ); + } - // Extract preset variables - $themeStyles = $this->recursiveExtractPresetVariables($themeStyles); + // Extract preset variables + $themeStyles = $this->recursiveExtractPresetVariables( $themeStyles ); - // Replace preset values. - $variables = $this->getVariablesValuesMap(); - $presets = []; + // Replace preset values. + $variables = $this->getVariablesValuesMap(); + $presets = array(); - foreach ($variables as $varName => $varValue) { - $varPattern = '/var\(' . preg_quote($varName, '/') . '\)/i'; - $presets[$varPattern] = $varValue; - } + foreach ( $variables as $varName => $varValue ) { + $varPattern = '/var\(' . preg_quote( $varName, '/' ) . '\)/i'; + $presets[ $varPattern ] = $varValue; + } - $themeStyles = $this->recursiveReplacePresets($themeStyles, $presets); + $themeStyles = $this->recursiveReplacePresets( $themeStyles, $presets ); - return $themeStyles; - } + return $themeStyles; + } - public function getSettings(): array { - $emailEditorThemeSettings = $this->getTheme()->get_settings(); - $siteThemeSettings = WP_Theme_JSON_Resolver::get_theme_data()->get_settings(); - $emailEditorThemeSettings['color']['palette']['theme'] = []; - if (isset($siteThemeSettings['color']['palette']['theme'])) { - $emailEditorThemeSettings['color']['palette']['theme'] = $siteThemeSettings['color']['palette']['theme']; - } - return $emailEditorThemeSettings; - } + public function getSettings(): array { + $emailEditorThemeSettings = $this->getTheme()->get_settings(); + $siteThemeSettings = WP_Theme_JSON_Resolver::get_theme_data()->get_settings(); + $emailEditorThemeSettings['color']['palette']['theme'] = array(); + if ( isset( $siteThemeSettings['color']['palette']['theme'] ) ) { + $emailEditorThemeSettings['color']['palette']['theme'] = $siteThemeSettings['color']['palette']['theme']; + } + return $emailEditorThemeSettings; + } - public function getLayoutSettings(): array { - return $this->getTheme()->get_settings()['layout']; - } + public function getLayoutSettings(): array { + return $this->getTheme()->get_settings()['layout']; + } - public function getStylesheetFromContext($context, $options = []): string { - return function_exists('gutenberg_style_engine_get_stylesheet_from_context') ? gutenberg_style_engine_get_stylesheet_from_context($context, $options) : wp_style_engine_get_stylesheet_from_context($context, $options); - } + public function getStylesheetFromContext( $context, $options = array() ): string { + return function_exists( 'gutenberg_style_engine_get_stylesheet_from_context' ) ? gutenberg_style_engine_get_stylesheet_from_context( $context, $options ) : wp_style_engine_get_stylesheet_from_context( $context, $options ); + } - public function getStylesheetForRendering($post = null, $template = null): string { - $emailThemeSettings = $this->getSettings(); + public function getStylesheetForRendering( $post = null, $template = null ): string { + $emailThemeSettings = $this->getSettings(); - $cssPresets = ''; - // Font family classes - foreach ($emailThemeSettings['typography']['fontFamilies']['default'] as $fontFamily) { - $cssPresets .= ".has-{$fontFamily['slug']}-font-family { font-family: {$fontFamily['fontFamily']}; } \n"; - } - // Font size classes - foreach ($emailThemeSettings['typography']['fontSizes']['default'] as $fontSize) { - $cssPresets .= ".has-{$fontSize['slug']}-font-size { font-size: {$fontSize['size']}; } \n"; - } - // Color palette classes - $colorDefinitions = array_merge($emailThemeSettings['color']['palette']['theme'], $emailThemeSettings['color']['palette']['default']); - foreach ($colorDefinitions as $color) { - $cssPresets .= ".has-{$color['slug']}-color { color: {$color['color']}; } \n"; - $cssPresets .= ".has-{$color['slug']}-background-color { background-color: {$color['color']}; } \n"; - $cssPresets .= ".has-{$color['slug']}-border-color { border-color: {$color['color']}; } \n"; - } + $cssPresets = ''; + // Font family classes + foreach ( $emailThemeSettings['typography']['fontFamilies']['default'] as $fontFamily ) { + $cssPresets .= ".has-{$fontFamily['slug']}-font-family { font-family: {$fontFamily['fontFamily']}; } \n"; + } + // Font size classes + foreach ( $emailThemeSettings['typography']['fontSizes']['default'] as $fontSize ) { + $cssPresets .= ".has-{$fontSize['slug']}-font-size { font-size: {$fontSize['size']}; } \n"; + } + // Color palette classes + $colorDefinitions = array_merge( $emailThemeSettings['color']['palette']['theme'], $emailThemeSettings['color']['palette']['default'] ); + foreach ( $colorDefinitions as $color ) { + $cssPresets .= ".has-{$color['slug']}-color { color: {$color['color']}; } \n"; + $cssPresets .= ".has-{$color['slug']}-background-color { background-color: {$color['color']}; } \n"; + $cssPresets .= ".has-{$color['slug']}-border-color { border-color: {$color['color']}; } \n"; + } - // Block specific styles - $cssBlocks = ''; - $blocks = $this->getTheme()->get_styles_block_nodes(); - foreach ($blocks as $blockMetadata) { - $cssBlocks .= $this->getTheme()->get_styles_for_block($blockMetadata); - } + // Block specific styles + $cssBlocks = ''; + $blocks = $this->getTheme()->get_styles_block_nodes(); + foreach ( $blocks as $blockMetadata ) { + $cssBlocks .= $this->getTheme()->get_styles_for_block( $blockMetadata ); + } - // Element specific styles - $elementsStyles = $this->getTheme()->get_raw_data()['styles']['elements'] ?? []; + // Element specific styles + $elementsStyles = $this->getTheme()->get_raw_data()['styles']['elements'] ?? array(); - // Because the section styles is not a part of the output the `get_styles_block_nodes` method, we need to get it separately - if ($template && $template->wp_id) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - $templateTheme = (array)get_post_meta($template->wp_id, 'mailpoet_email_theme', true); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - $templateStyles = (array)($templateTheme['styles'] ?? []); - $templateElements = $templateStyles['elements'] ?? []; - $elementsStyles = array_replace_recursive((array)$elementsStyles, (array)$templateElements); - } + // Because the section styles is not a part of the output the `get_styles_block_nodes` method, we need to get it separately + if ( $template && $template->wp_id ) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + $templateTheme = (array) get_post_meta( $template->wp_id, 'mailpoet_email_theme', true ); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + $templateStyles = (array) ( $templateTheme['styles'] ?? array() ); + $templateElements = $templateStyles['elements'] ?? array(); + $elementsStyles = array_replace_recursive( (array) $elementsStyles, (array) $templateElements ); + } - if ($post) { - $postTheme = (array)get_post_meta($post->ID, 'mailpoet_email_theme', true); - $postStyles = (array)($postTheme['styles'] ?? []); - $postElements = $postStyles['elements'] ?? []; - $elementsStyles = array_replace_recursive((array)$elementsStyles, (array)$postElements); - } + if ( $post ) { + $postTheme = (array) get_post_meta( $post->ID, 'mailpoet_email_theme', true ); + $postStyles = (array) ( $postTheme['styles'] ?? array() ); + $postElements = $postStyles['elements'] ?? array(); + $elementsStyles = array_replace_recursive( (array) $elementsStyles, (array) $postElements ); + } - $cssElements = ''; - foreach ($elementsStyles as $key => $elementsStyle) { - $selector = $key; + $cssElements = ''; + foreach ( $elementsStyles as $key => $elementsStyle ) { + $selector = $key; - if ($key === 'button') { - $selector = '.wp-block-button'; - $cssElements .= wp_style_engine_get_styles($elementsStyle, ['selector' => '.wp-block-button'])['css']; - // Add color to link element. - $cssElements .= wp_style_engine_get_styles(['color' => ['text' => $elementsStyle['color']['text'] ?? '']], ['selector' => '.wp-block-button a'])['css']; - continue; - } + if ( $key === 'button' ) { + $selector = '.wp-block-button'; + $cssElements .= wp_style_engine_get_styles( $elementsStyle, array( 'selector' => '.wp-block-button' ) )['css']; + // Add color to link element. + $cssElements .= wp_style_engine_get_styles( array( 'color' => array( 'text' => $elementsStyle['color']['text'] ?? '' ) ), array( 'selector' => '.wp-block-button a' ) )['css']; + continue; + } - switch ($key) { - case 'heading': - $selector = 'h1, h2, h3, h4, h5, h6'; - break; - case 'link': - $selector = 'a:not(.button-link)'; - break; - } + switch ( $key ) { + case 'heading': + $selector = 'h1, h2, h3, h4, h5, h6'; + break; + case 'link': + $selector = 'a:not(.button-link)'; + break; + } - $cssElements .= wp_style_engine_get_styles($elementsStyle, ['selector' => $selector])['css']; - } + $cssElements .= wp_style_engine_get_styles( $elementsStyle, array( 'selector' => $selector ) )['css']; + } - $result = $cssPresets . $cssBlocks . $cssElements; - // Because font-size can by defined by the clamp() function that is not supported in the e-mail clients, we need to replace it to the value. - // Regular expression to match clamp() function and capture its max value - $pattern = '/clamp\([^,]+,\s*[^,]+,\s*([^)]+)\)/'; - // Replace clamp() with its maximum value - $result = (string)preg_replace($pattern, '$1', $result); - return $result; - } + $result = $cssPresets . $cssBlocks . $cssElements; + // Because font-size can by defined by the clamp() function that is not supported in the e-mail clients, we need to replace it to the value. + // Regular expression to match clamp() function and capture its max value + $pattern = '/clamp\([^,]+,\s*[^,]+,\s*([^)]+)\)/'; + // Replace clamp() with its maximum value + $result = (string) preg_replace( $pattern, '$1', $result ); + return $result; + } - public function translateSlugToFontSize(string $fontSize): string { - $settings = $this->getSettings(); - foreach ($settings['typography']['fontSizes']['default'] as $fontSizeDefinition) { - if ($fontSizeDefinition['slug'] === $fontSize) { - return $fontSizeDefinition['size']; - } - } - return $fontSize; - } + public function translateSlugToFontSize( string $fontSize ): string { + $settings = $this->getSettings(); + foreach ( $settings['typography']['fontSizes']['default'] as $fontSizeDefinition ) { + if ( $fontSizeDefinition['slug'] === $fontSize ) { + return $fontSizeDefinition['size']; + } + } + return $fontSize; + } - public function translateSlugToColor(string $colorSlug): string { - $settings = $this->getSettings(); - $colorDefinitions = array_merge($settings['color']['palette']['theme'], $settings['color']['palette']['default']); - foreach ($colorDefinitions as $colorDefinition) { - if ($colorDefinition['slug'] === $colorSlug) { - return strtolower($colorDefinition['color']); - } - } - return $colorSlug; - } + public function translateSlugToColor( string $colorSlug ): string { + $settings = $this->getSettings(); + $colorDefinitions = array_merge( $settings['color']['palette']['theme'], $settings['color']['palette']['default'] ); + foreach ( $colorDefinitions as $colorDefinition ) { + if ( $colorDefinition['slug'] === $colorSlug ) { + return strtolower( $colorDefinition['color'] ); + } + } + return $colorSlug; + } - public function getVariablesValuesMap(): array { - $variablesCss = $this->getTheme()->get_stylesheet(['variables']); - $map = []; - // Regular expression to match CSS variable definitions - $pattern = '/--(.*?):\s*(.*?);/'; + public function getVariablesValuesMap(): array { + $variablesCss = $this->getTheme()->get_stylesheet( array( 'variables' ) ); + $map = array(); + // Regular expression to match CSS variable definitions + $pattern = '/--(.*?):\s*(.*?);/'; - if (preg_match_all($pattern, $variablesCss, $matches, PREG_SET_ORDER)) { - foreach ($matches as $match) { - // '--' . $match[1] is the variable name, $match[2] is the variable value - $map['--' . $match[1]] = $match[2]; - } - } + if ( preg_match_all( $pattern, $variablesCss, $matches, PREG_SET_ORDER ) ) { + foreach ( $matches as $match ) { + // '--' . $match[1] is the variable name, $match[2] is the variable value + $map[ '--' . $match[1] ] = $match[2]; + } + } - return $map; - } + return $map; + } } diff --git a/packages/php/email-editor/src/Engine/content-editor.css b/packages/php/email-editor/src/Engine/content-editor.css index 25027e318d..e87c44e5a8 100644 --- a/packages/php/email-editor/src/Engine/content-editor.css +++ b/packages/php/email-editor/src/Engine/content-editor.css @@ -1,28 +1,28 @@ /* - * Styles for the email editor. + * Styles for the email editor. */ /* * Flex layout used for buttons block for email editor. */ .is-layout-email-flex { - flex-wrap: nowrap; + flex-wrap: nowrap; } :where(body .is-layout-flex) { - gap: var(--wp--style--block-gap, 16px); + gap: var(--wp--style--block-gap, 16px); } .is-mobile-preview .is-layout-email-flex { - display: block; + display: block; } .is-mobile-preview .is-layout-email-flex .block-editor-block-list__block { - padding: 5px 0; - width: 100%; + padding: 5px 0; + width: 100%; } .is-mobile-preview .is-layout-email-flex .wp-block-button__link { - width: 100%; + width: 100%; } /* @@ -30,61 +30,61 @@ * This is needed because we disable layout for core/group, core/column and core/columns blocks, and .is-layout-flex is not applied. */ .wp-block-columns:not(.is-not-stacked-on-mobile) - > .wp-block-column - > .wp-block:first-child, + > .wp-block-column + > .wp-block:first-child, .wp-block-group > .wp-block:first-child { - margin-top: 0; + margin-top: 0; } .wp-block-columns:not(.is-not-stacked-on-mobile) > .wp-block-column > .wp-block, .wp-block-group > .wp-block { - margin-bottom: var(--wp--style--block-gap, 16px); - margin-top: var(--wp--style--block-gap, 16px); + margin-bottom: var(--wp--style--block-gap, 16px); + margin-top: var(--wp--style--block-gap, 16px); } .wp-block-columns:not(.is-not-stacked-on-mobile) - > .wp-block-column - > .wp-block:last-child, + > .wp-block-column + > .wp-block:last-child, .wp-block-group > .wp-block:last-child { - margin-bottom: 0; + margin-bottom: 0; } /* * Use box sizing border box for columns that have defined a width (they have flex-basis set). */ .wp-block-columns:not(.is-not-stacked-on-mobile) - > .wp-block-column[style*='flex-basis'] { - box-sizing: border-box; + > .wp-block-column[style*='flex-basis'] { + box-sizing: border-box; } /* * For the WYSIWYG experience we don't want to display any margins between blocks in the editor */ .wp-block { - clear: both; // for ensuring that floated elements (images) are cleared + clear: both; // for ensuring that floated elements (images) are cleared } /* * Image block enhancements */ .wp-block-image figcaption { - /* Resetting the margin for images in the editor to avoid unexpected spacing */ - margin: 0; + /* Resetting the margin for images in the editor to avoid unexpected spacing */ + margin: 0; } .wp-block-image.alignleft, .wp-block-image.alignright { - margin-inline: 0 0; - text-align: center; + margin-inline: 0 0; + text-align: center; } .wp-block-image.aligncenter { - margin-left: auto; - margin-right: auto; + margin-left: auto; + margin-right: auto; } .wp-block-image.alignright { - margin-left: auto; + margin-left: auto; } /* @@ -95,31 +95,31 @@ ul, ol, ul.has-background, ol.has-background { - padding-left: 40px; + padding-left: 40px; } /* * Override default button border radius which is set in core to 9999px */ .wp-block-button__link { - border-radius: 0; + border-radius: 0; } /* * Mobile preview fixes */ .is-mobile-preview figure > div { - height: auto !important; - width: auto !important; + height: auto !important; + width: auto !important; } .is-mobile-preview .wp-block-columns { - display: flex; - flex-direction: column; + display: flex; + flex-direction: column; } .is-mobile-preview .wp-block-column { - box-sizing: border-box; - /* override flex-basis set in style attribute to fix the height of the column in mobile preview. Blocks overriding is as a part of style.css in blocks-library */ - flex-basis: auto !important; + box-sizing: border-box; + /* override flex-basis set in style attribute to fix the height of the column in mobile preview. Blocks overriding is as a part of style.css in blocks-library */ + flex-basis: auto !important; } diff --git a/packages/php/email-editor/src/Engine/content-shared.css b/packages/php/email-editor/src/Engine/content-shared.css index 9c36c90c59..e550eb1bfc 100644 --- a/packages/php/email-editor/src/Engine/content-shared.css +++ b/packages/php/email-editor/src/Engine/content-shared.css @@ -11,5 +11,5 @@ h3.has-background, h4.has-background, h5.has-background, h6.has-background { - padding: 16px 24px; + padding: 16px 24px; } diff --git a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-abstract-block-renderer.php b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-abstract-block-renderer.php index 2c4cd6ee97..f8ee5e8124 100644 --- a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-abstract-block-renderer.php +++ b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-abstract-block-renderer.php @@ -10,56 +10,59 @@ use WP_Style_Engine; * Shared functionality for block renderers. */ abstract class Abstract_Block_Renderer implements Block_Renderer { - /** - * Wrapper for wp_style_engine_get_styles which ensures all values are returned. - * - * @param array $block_styles Array of block styles. - * @param bool $skip_convert_vars If true, --wp_preset--spacing--x type values will be left in the original var:preset:spacing:x format. - * @return array - */ - protected function getStylesFromBlock(array $block_styles, $skip_convert_vars = false) { - $styles = wp_style_engine_get_styles($block_styles, ['convert_vars_to_classnames' => $skip_convert_vars]); - return wp_parse_args($styles, [ - 'css' => '', - 'declarations' => [], - 'classnames' => '', - ]); - } + /** + * Wrapper for wp_style_engine_get_styles which ensures all values are returned. + * + * @param array $block_styles Array of block styles. + * @param bool $skip_convert_vars If true, --wp_preset--spacing--x type values will be left in the original var:preset:spacing:x format. + * @return array + */ + protected function getStylesFromBlock( array $block_styles, $skip_convert_vars = false ) { + $styles = wp_style_engine_get_styles( $block_styles, array( 'convert_vars_to_classnames' => $skip_convert_vars ) ); + return wp_parse_args( + $styles, + array( + 'css' => '', + 'declarations' => array(), + 'classnames' => '', + ) + ); + } - /** - * Compile objects containing CSS properties to a string. - * - * @param array ...$styles Style arrays to compile. - * @return string - */ - protected function compileCss(...$styles): string { - return WP_Style_Engine::compile_css(array_merge(...$styles), ''); - } + /** + * Compile objects containing CSS properties to a string. + * + * @param array ...$styles Style arrays to compile. + * @return string + */ + protected function compileCss( ...$styles ): string { + return WP_Style_Engine::compile_css( array_merge( ...$styles ), '' ); + } - protected function addSpacer($content, $emailAttrs): string { - $gapStyle = WP_Style_Engine::compile_css(array_intersect_key($emailAttrs, array_flip(['margin-top'])), ''); - $paddingStyle = WP_Style_Engine::compile_css(array_intersect_key($emailAttrs, array_flip(['padding-left', 'padding-right'])), ''); + protected function addSpacer( $content, $emailAttrs ): string { + $gapStyle = WP_Style_Engine::compile_css( array_intersect_key( $emailAttrs, array_flip( array( 'margin-top' ) ) ), '' ); + $paddingStyle = WP_Style_Engine::compile_css( array_intersect_key( $emailAttrs, array_flip( array( 'padding-left', 'padding-right' ) ) ), '' ); - if (!$gapStyle && !$paddingStyle) { - return $content; - } + if ( ! $gapStyle && ! $paddingStyle ) { + return $content; + } - return sprintf( - ' + return sprintf( + '%8$s |
+
|
';
- }
+ }
}
diff --git a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-columns.php b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-columns.php
index d009194b5c..fd21160ea8 100644
--- a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-columns.php
+++ b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-columns.php
@@ -8,68 +8,75 @@ use MailPoet\EmailEditor\Integrations\Utils\Dom_Document_Helper;
use WP_Style_Engine;
class Columns extends Abstract_Block_Renderer {
- protected function renderContent(string $blockContent, array $parsedBlock, Settings_Controller $settingsController): string {
- $content = '';
- foreach ($parsedBlock['innerBlocks'] ?? [] as $block) {
- $content .= render_block($block);
- }
+ protected function renderContent( string $blockContent, array $parsedBlock, Settings_Controller $settingsController ): string {
+ $content = '';
+ foreach ( $parsedBlock['innerBlocks'] ?? array() as $block ) {
+ $content .= render_block( $block );
+ }
- return str_replace(
- '{columns_content}',
- $content,
- $this->getBlockWrapper($blockContent, $parsedBlock, $settingsController)
- );
- }
+ return str_replace(
+ '{columns_content}',
+ $content,
+ $this->getBlockWrapper( $blockContent, $parsedBlock, $settingsController )
+ );
+ }
- /**
- * Based on MJML
' . $renderedColumns . ' |
@@ -65,11 +74,11 @@ class Group extends Abstract_Block_Renderer { |
{caption_content} | +{caption_content} |
+ |
%2$s ',
- esc_attr($wrapperStyle),
- $blockContent
- );
- }
+ return sprintf(
+ '%2$s ',
+ esc_attr( $wrapperStyle ),
+ $blockContent
+ );
+ }
}
diff --git a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-list-item.php b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-list-item.php
index 4b420fa574..c8c508daae 100644
--- a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-list-item.php
+++ b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-list-item.php
@@ -5,14 +5,14 @@ namespace MailPoet\EmailEditor\Integrations\Core\Renderer\Blocks;
use MailPoet\EmailEditor\Engine\Settings_Controller;
class List_Item extends Abstract_Block_Renderer {
- /**
- * Override this method to disable spacing (block gap) for list items.
- */
- protected function addSpacer($content, $emailAttrs): string {
- return $content;
- }
+ /**
+ * Override this method to disable spacing (block gap) for list items.
+ */
+ protected function addSpacer( $content, $emailAttrs ): string {
+ return $content;
+ }
- protected function renderContent($blockContent, array $parsedBlock, Settings_Controller $settingsController): string {
- return $blockContent;
- }
+ protected function renderContent( $blockContent, array $parsedBlock, Settings_Controller $settingsController ): string {
+ return $blockContent;
+ }
}
diff --git a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-text.php b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-text.php
index 71729c728d..b474f1f1bd 100644
--- a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-text.php
+++ b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-text.php
@@ -8,53 +8,58 @@ use MailPoet\EmailEditor\Engine\Settings_Controller;
* This renderer covers both core/paragraph and core/heading blocks
*/
class Text extends Abstract_Block_Renderer {
- protected function renderContent(string $blockContent, array $parsedBlock, Settings_Controller $settingsController): string {
- // Do not render empty blocks.
- if (empty(trim(strip_tags($blockContent)))) {
- return '';
- }
+ protected function renderContent( string $blockContent, array $parsedBlock, Settings_Controller $settingsController ): string {
+ // Do not render empty blocks.
+ if ( empty( trim( strip_tags( $blockContent ) ) ) ) {
+ return '';
+ }
- $blockContent = $this->adjustStyleAttribute($blockContent);
- $blockAttributes = wp_parse_args($parsedBlock['attrs'] ?? [], [
- 'textAlign' => 'left',
- 'style' => [],
- ]);
- $html = new \WP_HTML_Tag_Processor($blockContent);
- $classes = 'email-text-block';
- if ($html->next_tag()) {
- $blockClasses = $html->get_attribute('class') ?? '';
- $classes .= ' ' . $blockClasses;
- // remove has-background to prevent double padding applied for wrapper and inner element
- $blockClasses = str_replace('has-background', '', $blockClasses);
- // remove border related classes because we handle border on wrapping table cell
- $blockClasses = preg_replace('/[a-z-]+-border-[a-z-]+/', '', $blockClasses);
- $html->set_attribute('class', trim($blockClasses));
- $blockContent = $html->get_updated_html();
- }
+ $blockContent = $this->adjustStyleAttribute( $blockContent );
+ $blockAttributes = wp_parse_args(
+ $parsedBlock['attrs'] ?? array(),
+ array(
+ 'textAlign' => 'left',
+ 'style' => array(),
+ )
+ );
+ $html = new \WP_HTML_Tag_Processor( $blockContent );
+ $classes = 'email-text-block';
+ if ( $html->next_tag() ) {
+ $blockClasses = $html->get_attribute( 'class' ) ?? '';
+ $classes .= ' ' . $blockClasses;
+ // remove has-background to prevent double padding applied for wrapper and inner element
+ $blockClasses = str_replace( 'has-background', '', $blockClasses );
+ // remove border related classes because we handle border on wrapping table cell
+ $blockClasses = preg_replace( '/[a-z-]+-border-[a-z-]+/', '', $blockClasses );
+ $html->set_attribute( 'class', trim( $blockClasses ) );
+ $blockContent = $html->get_updated_html();
+ }
- $blockStyles = $this->getStylesFromBlock([
- 'color' => $blockAttributes['style']['color'] ?? [],
- 'spacing' => $blockAttributes['style']['spacing'] ?? [],
- 'typography' => $blockAttributes['style']['typography'] ?? [],
- 'border' => $blockAttributes['style']['border'] ?? [],
- ]);
+ $blockStyles = $this->getStylesFromBlock(
+ array(
+ 'color' => $blockAttributes['style']['color'] ?? array(),
+ 'spacing' => $blockAttributes['style']['spacing'] ?? array(),
+ 'typography' => $blockAttributes['style']['typography'] ?? array(),
+ 'border' => $blockAttributes['style']['border'] ?? array(),
+ )
+ );
- $styles = [
- 'min-width' => '100%', // prevent Gmail App from shrinking the table on mobile devices
- ];
+ $styles = array(
+ 'min-width' => '100%', // prevent Gmail App from shrinking the table on mobile devices
+ );
- $styles['text-align'] = 'left';
- if (isset($parsedBlock['attrs']['textAlign'])) {
- $styles['text-align'] = $parsedBlock['attrs']['textAlign'];
- } elseif (in_array($parsedBlock['attrs']['align'] ?? null, ['left', 'center', 'right'])) {
- $styles['text-align'] = $parsedBlock['attrs']['align'];
- }
+ $styles['text-align'] = 'left';
+ if ( isset( $parsedBlock['attrs']['textAlign'] ) ) {
+ $styles['text-align'] = $parsedBlock['attrs']['textAlign'];
+ } elseif ( in_array( $parsedBlock['attrs']['align'] ?? null, array( 'left', 'center', 'right' ) ) ) {
+ $styles['text-align'] = $parsedBlock['attrs']['align'];
+ }
- $compiledStyles = $this->compileCss($blockStyles['declarations'], $styles);
- $tableStyles = 'border-collapse: separate;'; // Needed because of border radius
+ $compiledStyles = $this->compileCss( $blockStyles['declarations'], $styles );
+ $tableStyles = 'border-collapse: separate;'; // Needed because of border radius
- return sprintf(
- ' |