diff --git a/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/TypographyPreprocessor.php b/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/TypographyPreprocessor.php index 018f164360..ddbc221599 100644 --- a/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/TypographyPreprocessor.php +++ b/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/TypographyPreprocessor.php @@ -12,7 +12,6 @@ class TypographyPreprocessor implements Preprocessor { private const TYPOGRAPHY_STYLES = [ 'color', 'font-size', - 'font-family', 'text-decoration', ]; @@ -54,9 +53,6 @@ class TypographyPreprocessor implements Preprocessor { if (isset($block['attrs']['style']['color']['text'])) { $emailAttrs['color'] = $block['attrs']['style']['color']['text']; } - if (isset($block['attrs']['fontFamily'])) { - $emailAttrs['font-family'] = $this->getFontFamilyBySlug($block['attrs']['fontFamily']); - } if (isset($block['attrs']['style']['typography']['fontSize'])) { $emailAttrs['font-size'] = $block['attrs']['style']['typography']['fontSize']; } @@ -80,20 +76,6 @@ class TypographyPreprocessor implements Preprocessor { if (!($block['email_attrs']['font-size'] ?? '')) { $block['email_attrs']['font-size'] = $contentStyles['typography']['fontSize']; } - if (!($block['email_attrs']['font-family'] ?? '')) { - $block['email_attrs']['font-family'] = $contentStyles['typography']['fontFamily']; - } return $block; } - - private function getFontFamilyBySlug(string $slug): ?string { - $themeData = $this->settingsController->getTheme()->get_data(); - $fontFamilies = $themeData['settings']['typography']['fontFamilies'] ?? []; - foreach ($fontFamilies as $fontFamily) { - if ($fontFamily['slug'] === $slug) { - return $fontFamily['fontFamily']; - } - } - return null; - } } diff --git a/mailpoet/lib/EmailEditor/Engine/Renderer/Renderer.php b/mailpoet/lib/EmailEditor/Engine/Renderer/Renderer.php index 744ba8f2d4..dcf74ac08e 100644 --- a/mailpoet/lib/EmailEditor/Engine/Renderer/Renderer.php +++ b/mailpoet/lib/EmailEditor/Engine/Renderer/Renderer.php @@ -49,6 +49,7 @@ class Renderer { $renderedBody = $this->renderBlocks($parsedBlocks); $styles = (string)file_get_contents(dirname(__FILE__) . '/' . self::TEMPLATE_STYLES_FILE); + $styles .= $this->settingsController->getStylesheetForRendering(); $styles = apply_filters('mailpoet_email_renderer_styles', $styles, $post); $template = (string)file_get_contents(dirname(__FILE__) . '/' . self::TEMPLATE_FILE); diff --git a/mailpoet/lib/EmailEditor/Engine/SettingsController.php b/mailpoet/lib/EmailEditor/Engine/SettingsController.php index 54c0ce4aa7..6fa125d3df 100644 --- a/mailpoet/lib/EmailEditor/Engine/SettingsController.php +++ b/mailpoet/lib/EmailEditor/Engine/SettingsController.php @@ -236,4 +236,14 @@ class SettingsController { /** @var array $themeJson */ return new \WP_Theme_JSON($themeJson); } + + public function getStylesheetForRendering(): string { + $settings = $this->getTheme()->get_settings(); + $css = ''; + // Font family classes + foreach ($settings['typography']['fontFamilies']['theme'] as $fontFamily) { + $css .= ".has-{$fontFamily['slug']}-font-family { font-family: {$fontFamily['fontFamily']}; } \n"; + } + return $css; + } } diff --git a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Button.php b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Button.php index d6c776949e..df2a3547a1 100644 --- a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Button.php +++ b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Button.php @@ -25,7 +25,11 @@ class Button implements BlockRenderer { return ''; } + $buttonOriginalWrapper = $buttonDom->getElementsByTagName('div')->item(0); + $buttonClasses = $buttonOriginalWrapper instanceof \DOMElement ? $buttonOriginalWrapper->getAttribute('class') : ''; + $markup = $this->getMarkup(); + $markup = str_replace('{classes}', $buttonClasses, $markup); // Add Link Text $markup = str_replace('{linkText}', $buttonLink->textContent ?: '', $markup); @@ -91,8 +95,6 @@ class Button implements BlockRenderer { // Escaping $wrapperStyles = array_map('esc_attr', $wrapperStyles); $linkStyles = array_map('esc_attr', $linkStyles); - // Font family may contain single quotes - $linkStyles['font-family'] = str_replace(''', "'", esc_attr("{$parsedBlock['email_attrs']['font-family']}")); $markup = str_replace('{linkStyles}', $settingsController->convertStylesToString($linkStyles), $markup); $markup = str_replace('{wrapperStyles}', $settingsController->convertStylesToString($wrapperStyles), $markup); @@ -103,7 +105,7 @@ class Button implements BlockRenderer { private function getMarkup(): string { return ' - diff --git a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Heading.php b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Heading.php index 53b9393717..b9c704a614 100644 --- a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Heading.php +++ b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Heading.php @@ -42,9 +42,6 @@ class Heading implements BlockRenderer { if (!isset($styles['font-size'])) { $styles['font-size'] = $contentStyles['typography']['fontSize']; } - if (!isset($styles['font-family'])) { - $styles['font-family'] = $contentStyles['typography']['fontFamily']; - } $styles = array_merge($styles, $this->fetchStylesFromBlockAttrs($availableStylesheets, $parsedBlock['attrs'])); diff --git a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/ListBlock.php b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/ListBlock.php index 9479202258..a8959a40e4 100644 --- a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/ListBlock.php +++ b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/ListBlock.php @@ -23,9 +23,6 @@ class ListBlock implements BlockRenderer { if (!isset($styles['font-size'])) { $styles['font-size'] = $contentStyles['typography']['fontSize']; } - if (!isset($styles['font-family'])) { - $styles['font-family'] = $contentStyles['typography']['fontFamily']; - } $html->set_attribute('style', $settingsController->convertStylesToString($styles)); $blockContent = $html->get_updated_html(); diff --git a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Paragraph.php b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Paragraph.php index 718544e23a..54a5ed8ea3 100644 --- a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Paragraph.php +++ b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Paragraph.php @@ -41,9 +41,6 @@ class Paragraph implements BlockRenderer { if (!isset($styles['font-size'])) { $styles['font-size'] = $contentStyles['typography']['fontSize']; } - if (!isset($styles['font-family'])) { - $styles['font-family'] = $contentStyles['typography']['fontFamily']; - } $styles = array_merge($styles, $this->fetchStylesFromBlockAttrs($availableStylesheets, $parsedBlock['attrs'] ?? [])); diff --git a/mailpoet/tests/integration/EmailEditor/Engine/SettingsControllerTest.php b/mailpoet/tests/integration/EmailEditor/Engine/SettingsControllerTest.php new file mode 100644 index 0000000000..766da5a255 --- /dev/null +++ b/mailpoet/tests/integration/EmailEditor/Engine/SettingsControllerTest.php @@ -0,0 +1,19 @@ +settingsController = $this->diContainer->get(SettingsController::class); + } + + public function testItGeneratesCssStylesForThemeWithFontFamilies() { + $css = $this->settingsController->getStylesheetForRendering(); + verify($css)->stringContainsString('.has-system-sans-serif-font-family'); + verify($css)->stringContainsString('.has-system-Serif-font-family'); + } +} diff --git a/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/ButtonTest.php b/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/ButtonTest.php index faee7d77df..08ed96bddb 100644 --- a/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/ButtonTest.php +++ b/mailpoet/tests/integration/EmailEditor/Integration/Core/Renderer/Blocks/ButtonTest.php @@ -150,15 +150,4 @@ class ButtonTest extends \MailPoetTest { verify($output)->stringContainsString('border-bottom-left-radius:3px;'); verify($output)->stringContainsString('border-bottom-right-radius:4px;'); } - - public function testItAllowsSingleQuotesInFontFamilyDefinition(): void { - $settingsControllerMock = $this->createPartialMock(SettingsController::class, ['getEmailContentStyles']); - $settingsControllerMock->method('getEmailContentStyles')->willReturn([ - 'typography' => [ - 'fontFamily' => '"Font\'", serif', - ], - ]); - $output = $this->buttonRenderer->render($this->parsedButton['innerHTML'], $this->parsedButton, $settingsControllerMock); - verify($output)->stringContainsString('"Font\'", serif'); - } } diff --git a/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/TypographyPreprocessorTest.php b/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/TypographyPreprocessorTest.php index d318cb0ea5..3bdfd01e2c 100644 --- a/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/TypographyPreprocessorTest.php +++ b/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/TypographyPreprocessorTest.php @@ -81,7 +81,6 @@ class TypographyPreprocessorTest extends \MailPoetUnitTest { ]]; $expectedEmailAttrs = [ 'color' => '#aa00dd', - 'font-family' => 'Arial', 'font-size' => '12px', 'text-decoration' => 'underline', ]; @@ -121,8 +120,8 @@ class TypographyPreprocessorTest extends \MailPoetUnitTest { $result = $this->preprocessor->preprocess($blocks, []); $result = $result[0]; verify($result['innerBlocks'])->arrayCount(2); - verify($result['email_attrs'])->equals(['width' => '640px', 'color' => '#000000', 'font-size' => '13px', 'font-family' => 'Arial']); - $defaultFontStyles = ['color' => '#000000', 'font-size' => '13px', 'font-family' => 'Arial']; + verify($result['email_attrs'])->equals(['width' => '640px', 'color' => '#000000', 'font-size' => '13px']); + $defaultFontStyles = ['color' => '#000000', 'font-size' => '13px']; verify($result['innerBlocks'][0]['email_attrs'])->equals($defaultFontStyles); verify($result['innerBlocks'][1]['email_attrs'])->equals($defaultFontStyles); verify($result['innerBlocks'][1]['innerBlocks'][0]['email_attrs'])->equals($defaultFontStyles); @@ -207,12 +206,10 @@ class TypographyPreprocessorTest extends \MailPoetUnitTest { ]; $expectedEmailAttrs1 = [ 'color' => '#aa00dd', - 'font-family' => 'Arial', 'font-size' => '12px', ]; $expectedEmailAttrs2 = [ 'color' => '#cc22aa', - 'font-family' => 'Georgia', 'font-size' => '18px', ]; $result = $this->preprocessor->preprocess($blocks, []); @@ -225,7 +222,7 @@ class TypographyPreprocessorTest extends \MailPoetUnitTest { verify($child1['innerBlocks'][1]['email_attrs'])->equals($expectedEmailAttrs1); verify($child1['innerBlocks'][1]['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs1); verify($child2['innerBlocks'])->arrayCount(1); - verify($child2['email_attrs'])->equals(['color' => '#000000', 'font-size' => '13px', 'font-family' => 'Arial']); + verify($child2['email_attrs'])->equals(['color' => '#000000', 'font-size' => '13px']); verify($child2['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs2); verify($child2['innerBlocks'][0]['innerBlocks'][0]['email_attrs'])->equals($expectedEmailAttrs2); }
+