public function afterLayout(\Cake\Event\Event $event)
 {
     $content = $event->subject->Blocks->get('content');
     $parser = new \InlineStyle\InlineStyle();
     libxml_use_internal_errors(true);
     $parser->loadHTML($content);
     libxml_use_internal_errors(false);
     $parser->applyStylesheet($parser->extractStylesheets());
     $content = $parser->getHtml();
     $event->subject->Blocks->set('content', $content);
 }
Esempio n. 2
0
 static function InlineCSS(&$body, &$type, array &$headers, MiMeil $email)
 {
     if ($type === 'html' and $email->inlineCSS !== false) {
         $lib = __DIR__ . '/vendor/autoload.php';
         if (!is_file($lib)) {
             if ($email->inlineCSS === true) {
                 throw new MiMeilError('MiMeil requires inlinestyle/inlinestyle for inline' . ' CSS. Install it via Composer (getcomposer.org).');
             } else {
                 return;
             }
         }
         require_once $lib;
         $body = '<?xml encoding="UTF-8"> ' . static::cutXmlDecl($body);
         $inline = new InlineStyle\InlineStyle($body);
         $inline->applyStylesheet($inline->extractStylesheets());
         // Removing XML declaration because target encoding might be different from
         // UTF-8 (see $this->bodyCharsets). Plus I don't think XHTML in use these days.
         $body = static::cutXmlDecl($inline->getHTML());
         $body = html_entity_decode($body, ENT_QUOTES, 'utf-8');
     }
 }