cssInliner = $cssInliner; $this->settingsController = $settingsController; $this->contentRenderer = $contentRenderer; $this->cdnAssetUrl = $cdnAssetUrl; $this->templates = $templates; $this->themeController = $themeController; $this->servicesChecker = $servicesChecker; $this->themeController = $themeController; } public function render(\WP_Post $post, string $subject, string $preHeader, string $language, $metaRobots = ''): array { $layout = $this->settingsController->getLayout(); $themeStyles = $this->settingsController->getEmailStyles(); $width = $layout['contentSize']; $paddingTop = $themeStyles['spacing']['padding']['top'] ?? '0px'; $paddingBottom = $themeStyles['spacing']['padding']['bottom'] ?? '0px'; $contentBackground = $themeStyles['color']['background']['content'] ?? 'inherit'; $layoutBackground = $themeStyles['color']['background']['layout'] ?? 'inherit'; $contentFontFamily = $themeStyles['typography']['fontFamily'] ?? 'inherit'; $logoHtml = $this->servicesChecker->isPremiumPluginActive() ? '' : 'MailPoet'; $templateStyles = file_get_contents(dirname(__FILE__) . '/' . self::TEMPLATE_STYLES_FILE); $templateStyles = apply_filters('mailpoet_email_renderer_styles', $templateStyles . $this->themeController->getStylesheetForRendering(), $post); $templateHtml = $this->contentRenderer->render($post, $this->templates->getBlockTemplateFromFile('email-general.html')); ob_start(); include self::TEMPLATE_FILE; $renderedTemplate = (string)ob_get_clean(); $renderedTemplate = $this->inlineCSSStyles($renderedTemplate); $renderedTemplate = $this->postProcessTemplate($renderedTemplate); return [ 'html' => $renderedTemplate, 'text' => $this->renderTextVersion($renderedTemplate), ]; } /** * @param string $template * @return DomNode */ private function inlineCSSStyles($template) { return $this->cssInliner->inlineCSS($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); } /** * @param DomNode $templateDom * @return string */ private function postProcessTemplate(DomNode $templateDom) { // because tburry/pquery contains a bug and replaces the opening non mso condition incorrectly we have to replace the opening tag with correct value $template = $templateDom->__toString(); $template = str_replace('', '', $template); return $template; } }