Example #1
0
 /**
  * Renders the layout and includes the css stylesheet for inlining the styles
  *
  * @param string $content_for_layout
  * @param string $layout
  * @return string
  */
 public function renderLayout($content_for_layout, $layout = null)
 {
     $output = parent::renderLayout($content_for_layout, $layout);
     $css = file_get_contents(CSS . 'email.css');
     $inliner = new CssToInlineStyles($output, $css);
     return $inliner->convert();
 }
Example #2
0
 /**
  * Process css blocks to inline css
  * Also works for html snippets (without <html>)
  *
  * @return string HTML output
  */
 protected function _processCssToInline($html, $css)
 {
     App::import('Vendor', 'Tools.CssToInlineStyles', array('file' => 'CssToInlineStyles' . DS . 'CssToInlineStyles.php'));
     //fix issue with <html> being added
     $separator = '~~~~~~~~~~~~~~~~~~~~';
     if (strpos($html, '<html') === false) {
         $incomplete = true;
         $html = $separator . $html . $separator;
     }
     $CssToInlineStyles = new CssToInlineStyles($html, $css);
     if ($this->config['cleanup']) {
         $CssToInlineStyles->setCleanup();
     }
     if ($this->config['useInlineStylesBlock']) {
         $CssToInlineStyles->setUseInlineStylesBlock();
     }
     if ($this->config['removeCss']) {
         $CssToInlineStyles->setStripOriginalStyleTags();
     }
     if ($this->config['correctUtf8']) {
         $CssToInlineStyles->setCorrectUtf8();
     }
     if ($this->config['debug']) {
         CakeLog::write('css', $html);
     }
     $html = $CssToInlineStyles->convert($this->config['xhtmlOutput']);
     if ($this->config['removeCss']) {
         //$html = preg_replace('/\<style(.*)\>(.*)\<\/style\>/i', '', $html);
         $html = $this->stripOnly($html, array('style', 'script'), true);
         //CakeLog::write('css', $html);
     }
     if (!empty($incomplete)) {
         $html = substr($html, strpos($html, $separator) + 20);
         $html = substr($html, 0, strpos($html, $separator));
         $html = trim($html);
     }
     return $html;
 }
 /**
  * setup body for email
  *
  * @param bool $preview will etermine whether this is preview template or not.
  * @return string formatted body for email.
  */
 protected function _body($preview = FALSE)
 {
     //setup template args!
     $this->_template_args = array('subject' => $this->_subject, 'from' => $this->_from, 'main_body' => wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8"))));
     $body = $this->_get_main_template($preview);
     //now if this isn't a preview, let's setup the body so it has inline styles
     if (!$preview) {
         require_once EE_LIBRARIES . 'messages/messenger/assets/email/CssToInlineStyles.php';
         $CSS = new CssToInlineStyles($body);
         $CSS->setUseInlineStylesBlock();
         $body = ltrim($CSS->convert(), ">\n");
         //for some reason the library has a bracket and new line at the beginning.  This takes care of that.
     } else {
         if ($preview && defined('DOING_AJAX')) {
             require_once EE_LIBRARIES . 'messages/messenger/assets/email/CssToInlineStyles.php';
             $style = file_get_contents($this->get_inline_css_template(FALSE, TRUE));
             $CSS = new CssToInlineStyles(utf8_decode($body), $style);
             $body = ltrim($CSS->convert(), ">\n");
             //let's attempt to fix width's for ajax preview
             /*$i_width = '/width:[ 0-9%]+;|width:[ 0-9px]+;/';
             		$s_width = '/width="[ 0-9]+"/';
             		$body = preg_replace( $i_width, 'width:100%;', $body );
             		$body = preg_replace( $s_width, 'width=100%', $body );/**/
         }
     }
     return $body;
 }
 /**
  * Prepare inline styles
  **/
 function do_inline_styles($contents, $styles)
 {
     if ($contents && $styles) {
         if (!class_exists('CssToInlineStyles')) {
             require_once $this->plugin_dir . 'email-newsletter-files/builder/lib/css-inline.php';
         }
         $css_inline = new CssToInlineStyles($contents, $styles);
         $contents = $css_inline->convert();
     }
     return $contents;
 }