public function render($params = []) { $path = explode('.', $this->template); $filePath = Yii::getPathOfAlias($this->template) . '.php'; if (count($path) == 2) { $filePath = Yii::getPathOfAlias(($path[0] == 'plansys' ? 'application' : 'app') . ".views.layouts.email." . $path[1]) . ".php"; } if (!is_file($filePath)) { throw new CException('File `' . $filePath . '` not found'); } extract($params); ob_start(); include $filePath; $result = ob_get_clean(); $htmldoc = new InlineStyle($result); $htmldoc->applyStylesheet($htmldoc->extractStylesheets()); return $this->renderCache = $htmldoc->getHTML(); }
public function html($id) { $htmldoc = new InlineStyle(file_get_contents(url('campagne/' . $id))); $htmldoc->applyStylesheet($htmldoc->extractStylesheets()); $html = $htmldoc->getHTML(); $html = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html); return $html; }
function testLinkedMediaStylesheets31() { $htmldoc = new InlineStyle(file_get_contents($this->basedir . '/testLinkedMediaStylesheets31.html')); $htmldoc->applyStylesheet($htmldoc->extractStylesheets(null, $this->basedir)); $expected = <<<HTML <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <title>Example</title> <link rel="stylesheet" href="external.css" media="print"> </head> <body> <h1>An example title</h1> <p>Paragraph <strong style="font-weight: bold">1</strong></p> </body> </html> HTML; $this->assertEquals($expected, $htmldoc->getHTML()); }
/** * Generates the E-mail body * * @return $this */ private function generateBody() { if (!empty($this->htmlBody) && !empty($this->template)) { $mail = ['charset' => 'UTF-8', 'title' => $this->subject, 'body' => $this->htmlBody, 'signature' => $this->getHtmlSignature(), 'url_web_view' => $this->urlWeb]; $this->view->assign('mail', $mail); $htmlDocument = new InlineStyle($this->view->fetchTemplate($this->template)); $htmlDocument->applyStylesheet($htmlDocument->extractStylesheets()); $this->phpMailer->msgHTML($htmlDocument->getHTML()); // Fallback for E-mail clients which don't support HTML E-mails if (!empty($this->body)) { $this->phpMailer->AltBody = $this->decodeHtmlEntities($this->body . $this->getTextSignature()); } else { $this->phpMailer->AltBody = $this->phpMailer->html2text($this->htmlBody . $this->getHtmlSignature(), true); } } else { $this->phpMailer->Body = $this->decodeHtmlEntities($this->body . $this->getTextSignature()); } return $this; }