$style = $this->styleToArray($node->style); $style[$key] = $value; $node->style = $this->arrayToStyle($style); // remove all !important tags (inlined styles take precedent over others anyway) $node->style = str_replace("!important", "", $node->style); } } } return $html; } function parseCSS($text) { $css = new csstidy(); $css->settings['compress_colors'] = false; // Disable shorthand optimisation--this breaks `padding: calc() calc()` style rules. $css->settings['optimise_shorthands'] = 0; $css->parse($text); $rules = []; $position = 0; foreach ($css->css as $declarations) { foreach ($declarations as $selectors => $properties) { foreach (explode(",", $selectors) as $selector) { $rules[] = [ 'position' => $position, 'specificity' => $this->calculateCSSSpecifity($selector), 'selector' => $selector, 'properties' => $properties, ]; } $position += 1; } } usort($rules, function($a, $b) { if ($a['specificity'] > $b['specificity']) { return -1; } else if ($a['specificity'] < $b['specificity']) { return 1; } else { if ($a['position'] > $b['position']) { return -1; } else { return 1; } } }); return $rules; } /* * Merges two CSS inline styles strings into one. * If both styles defines same property the property from second styles will be used. */ function mergeInlineStyles($styles_1, $styles_2) { $merged_styles = array_merge($this->styleToArray($styles_1), $this->styleToArray($styles_2)); return $this->arrayToStyle($merged_styles); } private function splitMediaQueries($css) { $start = 0; $queries = ''; while (($start = strpos($css, "@media", $start)) !== false) { // stack to manage brackets $s = []; // get the first opening bracket $i = strpos($css, "{", $start); // if $i is false, then there is probably a css syntax error if ($i !== false) { // push bracket onto stack array_push($s, $css[$i]); // move past first bracket $i++; while (!empty($s)) { // if the character is an opening bracket, push it onto the stack, otherwise pop the stack if ($css[$i] == "{") { array_push($s, "{"); } else if ($css[$i] == "}") { array_pop($s); } $i++; } $queries .= substr($css, $start - 1, $i + 1 - $start) . "\n"; $css = substr($css, 0, $start - 1) . substr($css, $i); $i = $start; } } return [$css, $queries]; } /** * The following function fomes from CssToInlineStyles.php - here is the original licence FOR THIS FUNCTION * * CSS to Inline Styles class * * @author Tijs Verkoyen * @version 1.2.1 * @copyright Copyright (c), Tijs Verkoyen. All rights reserved. * @license BSD License */ private function calculateCSSSpecifity($selector) { // cleanup selector $selector = str_replace(['>', '+'], [' > ', ' + '], $selector); // init var $specifity = 0; // split the selector into chunks based on spaces $chunks = explode(' ', $selector); // loop chunks foreach ($chunks as $chunk) { // an ID is important, so give it a high specifity if (strstr($chunk, '#') !== false) $specifity += 100; // classes are more important than a tag, but less important then an ID elseif (strstr($chunk, '.')) $specifity += 10; // anything else isn't that important else $specifity += 1; } // return return $specifity; } /* * Turns a CSS style string (like: "border: 1px solid black; color:red") * into an array of properties (like: array("border" => "1px solid black", "color" => "red")) */ private function styleToArray($str) { $str = EHelper::unescapeHtmlStyleAttr($str); $array = []; if (trim($str) === '') return $array; foreach (explode(';', $str) as $kv) { $line = trim($kv); if ($line === '') { continue; } list($selector, $rule) = explode(':', $line, 2); $array[trim($selector)] = trim($rule); } return $array; } /* * Reverses what styleToArray does, see above. * array("border" => "1px solid black", "color" => "red") yields "border: 1px solid black; color:red" */ private function arrayToStyle($array) { $parts = []; foreach ($array as $k => $v) { $parts[] = "$k:$v"; } return EHelper::escapeHtmlStyleAttr(implode(';', $parts)); } }
Fatal error: Uncaught Error: Class "MailPoetVendor\CSS" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:4031 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5088): MailPoetGenerated\FreeCachedContainer->getRenderer6Service() #1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5098): MailPoetGenerated\FreeCachedContainer->getConfirmationEmailCustomizerService() #2 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5198): MailPoetGenerated\FreeCachedContainer->getConfirmationEmailMailerService() #3 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5368): MailPoetGenerated\FreeCachedContainer->getSubscriberActionsService() #4 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2612): MailPoetGenerated\FreeCachedContainer->getCommentService() #5 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2640): MailPoetGenerated\FreeCachedContainer->getHooks2Service() #6 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService() #7 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1) #8 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...') #9 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...') #10 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(194): require_once('/htdocs/wp-cont...') #11 /htdocs/wp-settings.php(526): include_once('/htdocs/wp-cont...') #12 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...') #13 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #14 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #15 /htdocs/index.php(17): require('/htdocs/wp-blog...') #16 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 4031