From b2a61e69fdbe7744039f904156335f55a198edb8 Mon Sep 17 00:00:00 2001 From: Dmitriy Zhuk Date: Sun, 2 Oct 2016 16:11:11 +0300 Subject: [PATCH] v1.0.2-beta --- composer.json | 5 +++-- src/InkyPremailer.php | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3ec1d1a..16eeec7 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "dreamvention/inky-premailer", "description": "Implementation of ZURB Inky + CssToInlineStyles. Compile responsive emails on the fly with ease.", - "version": "1.0.1", + "version": "1.0.2", "license": "MIT", "authors": [ { @@ -17,6 +17,7 @@ "require": { "php": ">=5.4.0", "tijsverkoyen/css-to-inline-styles": "^2.2", - "hampe/inky": "1.3.6.2" + "hampe/inky": "1.3.6.2", + "paquettg/php-html-parser": "^1.7" } } diff --git a/src/InkyPremailer.php b/src/InkyPremailer.php index 7171cfc..bc7ef2b 100644 --- a/src/InkyPremailer.php +++ b/src/InkyPremailer.php @@ -15,6 +15,7 @@ use Hampe\Inky\Inky; use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles; +use PHPHtmlParser\Dom; class InkyPremailer { @@ -35,6 +36,30 @@ public function render($html, $links = false, $styles = false) { $html = $this->inky->releaseTheKraken($html); $css = ''; + $dom = new Dom; + $dom->setOptions([ + 'removeStyles' => false, + ]); + + $dom->load($html); + $html_links = $dom->find('link'); + foreach($html_links as $html_link){ + $href = $html_link->getAttribute('href'); + if($href){ + if(strpos($href, '//') === false){ + $css .= file_get_contents('./'.$href); + }else{ + $css .= file_get_contents($href); + } + } + } + + $html_styles = $dom->find('style'); + + foreach($html_styles as $html_style){ + $css .= $html_style->innerHtml; + } + if($links){ // styles can be only an array . if(is_array($links)){