Skip to content

Commit

Permalink
v1.0.2-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriyzhuk committed Oct 2, 2016
1 parent d3128d8 commit b2a61e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand All @@ -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"
}
}
25 changes: 25 additions & 0 deletions src/InkyPremailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Hampe\Inky\Inky;
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
use PHPHtmlParser\Dom;

class InkyPremailer
{
Expand All @@ -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)){
Expand Down

0 comments on commit b2a61e6

Please sign in to comment.