diff --git a/.gitignore b/.gitignore index a09c56d..c1759d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.idea +vendor/ diff --git a/composer.json b/composer.json index 824066e..f56dcf6 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,9 @@ "minimum-stability": "dev", "require": { "php": ">=5.4.0", - "pelago/emogrifier": "^2.0.0" + "pelago/emogrifier": "^5.0.0", + "ext-dom": "*", + "ext-fileinfo": "*" }, "autoload": { diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..dd840b2 --- /dev/null +++ b/composer.lock @@ -0,0 +1,165 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "286f06695a694fc254cbf565c3110639", + "packages": [ + { + "name": "pelago/emogrifier", + "version": "v5.0.1", + "source": { + "type": "git", + "url": "https://github.com/MyIntervals/emogrifier.git", + "reference": "37595a9bb62c3c25969bdd9e8d7dd24c3ac62bc9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/MyIntervals/emogrifier/zipball/37595a9bb62c3c25969bdd9e8d7dd24c3ac62bc9", + "reference": "37595a9bb62c3c25969bdd9e8d7dd24c3ac62bc9", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "php": "~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0", + "symfony/css-selector": "^3.4.32 || ^4.4 || ^5.1" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "rawr/cross-data-providers": "^2.3.0", + "slevomat/coding-standard": "^6.4.1", + "squizlabs/php_codesniffer": "^3.5.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Pelago\\Emogrifier\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Klee", + "email": "github@oliverklee.de" + }, + { + "name": "Zoli Szabó", + "email": "zoli.szabo+github@gmail.com" + }, + { + "name": "John Reeve", + "email": "jreeve@pelagodesign.com" + }, + { + "name": "Jake Hotson", + "email": "jake@qzdesign.co.uk" + }, + { + "name": "Cameron Brooks" + }, + { + "name": "Jaime Prado" + } + ], + "description": "Converts CSS styles into inline style attributes in your HTML code", + "homepage": "https://www.myintervals.com/emogrifier.php", + "keywords": [ + "css", + "email", + "pre-processing" + ], + "support": { + "issues": "https://github.com/MyIntervals/emogrifier/issues", + "source": "https://github.com/MyIntervals/emogrifier" + }, + "time": "2021-04-06T08:18:22+00:00" + }, + { + "name": "symfony/css-selector", + "version": "5.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/css-selector.git", + "reference": "59a684f5ac454f066ecbe6daecce6719aed283fb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/59a684f5ac454f066ecbe6daecce6719aed283fb", + "reference": "59a684f5ac454f066ecbe6daecce6719aed283fb", + "shasum": "" + }, + "require": { + "php": ">=7.2.5" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\CssSelector\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Jean-François Simon", + "email": "jeanfrancois.simon@sensiolabs.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Converts CSS selectors to XPath expressions", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/css-selector/tree/v5.3.0-BETA1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-04-07T16:07:52+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.4.0" + }, + "platform-dev": [], + "plugin-api-version": "2.0.0" +} diff --git a/src/Html.php b/src/Html.php index 37bbd69..eeed013 100644 --- a/src/Html.php +++ b/src/Html.php @@ -10,7 +10,7 @@ use DOMDocument; use DOMXPath; -use Pelago\Emogrifier; +use Pelago\Emogrifier\CssInliner; /** * This class creates a collection of html pages with some improvements. @@ -30,7 +30,7 @@ class Html extends Base 'outputDir' => '' ]; - public function __construct($options=[]) + public function __construct($options = []) { $this->setOptions(array_replace_recursive($this->defaultOptions, $options)); } @@ -81,12 +81,12 @@ public function getAllPages() * The method replaces css class to inline css rules. * @param $content * @return string + * @throws \Symfony\Component\CssSelector\Exception\ParseException */ private function setInlineCss($content) { $content = str_replace([''], '', $content); - $parser = new Emogrifier($content); - return $parser->emogrify(); + return CssInliner::fromHtml($content)->inlineCss()->render(); } /** @@ -102,7 +102,8 @@ private function setInlineImages($content) $xpath->registerNamespace("xml", "http://www.w3.org/1999/xhtml"); $images = $xpath->query("//img"); - foreach ($images as $img) { /** @var \DOMNode $img */ + foreach ($images as $img) { + /** @var \DOMNode $img */ $attrImage = $img->getAttribute('src'); $pi = pathinfo($attrImage); $image = $this->getOutputDir() . '/' . $pi['basename']; @@ -128,7 +129,7 @@ private function setOnlyContent($content) $html = ''; $body = $xpath->query("//body")->item(0); - foreach($body->childNodes as $node) { + foreach ($body->childNodes as $node) { $html .= $dom->saveHTML($node); } unset($dom, $xpath, $body, $content);