/** * Parse the content editor */ private function parseTemplateContent() { // require the css to inline styles parser require 'external/css_to_inline_styles.php'; // template content is empty if (!isset($this->template['content'])) { $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $this->id . '&step=2&exclude_id=' . $this->id . '&error=template-does-not-exist'); } // set CSS object $css = new CSSToInlineStyles($this->template['content'], $this->template['css']); $HTML = urldecode($css->convert()); /* I realise this is a bit confusing, so let me elaborate: 1. edit_mailing_iframe.tpl contains a var {$templateHtml}. This is where $this->template['content'] goes. 2. Inside $this->template['content'] should be a textarea with a variable {$contentHtml} inside. This will become the editor field which will contain our stored content HTML. 3. We need everything inside the <body> tags so we don't end up with two <body>s. */ // find the body element if (preg_match('/<body.*>.*?<\\/body>/is', $HTML, $match)) { // search values $search = array(); $search[] = 'body'; $search[] = '{$contentHtml}'; $search[] = '{$siteURL}'; $search[] = '"'; // replace values $replace = array(); $replace[] = 'div'; $replace[] = $this->record['content_html']; $replace[] = SITE_URL; $replace[] = '"'; // replace $HTML = str_replace($search, $replace, $match[0]); } // parse the inline styles $this->tpl->assign('templateHtml', $HTML); }
<?php if (isset($_REQUEST['tupiSendEmail'])) { $msg = $tpl->showString(); //carregando o arquivo css // get contents of a file into a string $filename = "css/bootstrap.css"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); $CssConverte = new CSSToInlineStyles($msg, $contents); $html = $CssConverte->convert(); $result = $tupi->mail_html($_REQUEST['tupiSendEmail'], $tupi->REMETENTE, $tupi->TITULO, $html); $oMensagem = new Mensagem(); if ($result) { $oMensagem->getMensagem(53); } else { $oMensagem->getMensagem(54); } $tipo = ""; if ($oMensagem->tipo != "") { $tipo = 'alert-' . $oMensagem->tipo; } $tpl->ALERT = '<div class="alert ' . $tipo . '"><a class="close" data-dismiss="alert">x</a>' . utf8_decode($oMensagem->mensagem) . '</div>'; $tpl->block("BLOCK_ENVIO_EMAIL"); $tpl->show(); } else { $tpl->show(); }
/** * Returns the fully parsed e-mail content * * @return string * @param string $template The template to use. * @param string $contentHTML The content. * @param string $fullContentHTML The full content. */ private function getEmailContent($template, $contentHTML, $fullContentHTML) { // require the CSSToInlineStyles class require 'external/css_to_inline_styles.php'; // fetch the template contents for this mailing $template = BackendMailmotorModel::getTemplate($this->mailing['language'], $template); // template content is empty if (!isset($template['content'])) { $this->output(self::ERROR, array('mailing_id' => $this->mailing['id'], 'error' => true), BL::err('TemplateDoesNotExist', $this->getModule())); } // remove TinyMCE $fullContentHTML = preg_replace('/<!-- tinymce -->.*?<!-- \\/tinymce -->/is', $contentHTML, $fullContentHTML); // replace bracketed entities with their proper counterpart $fullContentHTML = preg_replace('/\\[ent=(.*?)]/', '&${1};', $fullContentHTML); // add Google UTM parameters to all anchors $fullContentHTML = $this->addUTMParameters($fullContentHTML); // search values $search[] = '{$siteURL}'; $search[] = '"'; $search[] = 'src="/'; // replace values $replace[] = SITE_URL; $replace[] = '"'; $replace[] = 'src="' . SITE_URL . '/'; // replace some variables $fullContentHTML = str_replace($search, $replace, $fullContentHTML); // set CSS object $css = new CSSToInlineStyles($fullContentHTML, $template['css']); $fullContentHTML = $css->convert(); // return the content return $fullContentHTML; }
/** * Render mail content using a view and template * * @param string $template * @param array $substitutions * @param array $placeholders * @param string $mode * @param string $layout * @param string $layoutPath */ public function getMailContent($template, $substitutions, $placeholders = array(), $mode = 'html', $layout = null, $layoutPath = null) { // Create the return variable $return = ''; // Create a view renderer $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $view = clone $viewRenderer->view; // Create a layout object and set it to app_path/emails/layouts if ($layoutPath === null || $layoutPath == '') { $layoutPath = PUBLIC_PATH . $view->templateUrl('') . 'email' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; } // Create the layout object $layoutObject = new Zend_Layout($layoutPath); // Add the script path to the view that overrules the default path $application = $this->getFrontController()->getParam('application'); $module = $this->getRequest()->getModuleName(); $scriptPath = $view->layout()->getViewScriptPath() . '/views/' . $application . '/modules/' . $module . '/'; if (!in_array($scriptPath, $view->getScriptPaths())) { $view->addScriptPath($scriptPath); } // Add the default email folder for the layout/template $view->addScriptPath(PUBLIC_PATH . $view->templateUrl('') . 'email' . DIRECTORY_SEPARATOR . 'views'); // Assign all substitutions (e.g. view variables) to the view view foreach ($substitutions as $key => $sub) { $view->{$key} = $sub; } // Replace all placeholders if (is_array($placeholders)) { foreach ($placeholders as $key => $sub) { } } // Set the view object to the layout object $layoutObject->setView($view); // Initialize a default layout if ($layout === null || $layout == '') { $layout = 'default'; } switch ($mode) { case 'html': // Render html version of template & assign to $return $layoutObject->content = $view->render($template . '.html.phtml'); // Set the layout $layoutObject->setLayout('' . $layout . '.html'); // Render the layout output $return = $layoutObject->render(); // Assimilate the stylesheet in the html $stylesheet = $layoutPath . $layout . '.css'; if (file_exists($stylesheet)) { $stylesheetContent = file_get_contents($stylesheet); $test = new CSSToInlineStyles($return, $stylesheetContent); $return = $test->convert(true); } break; case 'text': // Render text version of template & assign to $return $layoutObject->content = $view->render($template . '.text.phtml'); // Set the layout $layoutObject->setLayout('' . $layout . '.text'); // Render the layout output $return = $layoutObject->render(); break; } // Replace the placeholders in the content $return = $this->_replacePlaceholders($return, $placeholders); // all done, return output return $return; }
/** * Returns the content from a given template * * @param string $template The template to use. * @param array[optional] $variables The variabled to assign. * @return string */ private static function getTemplateContent($template, $variables = null) { // new template instance $tpl = new BackendTemplate(false); // set some options $tpl->setForceCompile(true); // variables were set if (!empty($variables)) { $tpl->assign($variables); } // grab the content $content = $tpl->getContent($template); // replace internal links/images $search = array('href="/', 'src="/'); $replace = array('href="' . SITE_URL . '/', 'src="' . SITE_URL . '/'); $content = str_replace($search, $replace, $content); // require CSSToInlineStyles require_once 'external/css_to_inline_styles.php'; // create instance $cssToInlineStyles = new CSSToInlineStyles(); // set some properties $cssToInlineStyles->setHTML($content); $cssToInlineStyles->setUseInlineStylesBlock(true); $cssToInlineStyles->setEncoding(SPOON_CHARSET); // return the content return (string) $cssToInlineStyles->convert(); }
function replace_special_characters($body) { //Correção para exibir style inline do MSO if (preg_match('~Mso~i', $body)) { $body = preg_replace_callback('~(style=\\")(.*?)(\\">)~i', array('self', 'mso_style'), $body); } if (trim($body) === '') { return; } $body = str_ireplace('POSITION: ABSOLUTE;', '', $body); $body = str_ireplace('<o:p> </o:p>', '<br />', $body); //Qubra de linha do MSO $body = preg_replace('/<(meta|base|link|html|\\/html)[^>]*>/i', '', $body); // Malicious Code Remove $dirtyCodePattern = "/(<([\\w]+[\\w0-9]*)(.*)on(mouse(move|over|down|up)|load|blur|change|error|click|dblclick|focus|key(down|up|press)|select)([\n\\ ]*)=([\n\\ ]*)[\"'][^>\"']*[\"']([^>]*)>)(.*)(<\\/\\2>)?/misU"; preg_match_all($dirtyCodePattern, $body, $rest, PREG_PATTERN_ORDER); foreach ($rest[0] as $i => $val) { if (!(preg_match("/javascript:window\\.open\\(\"([^'\"]*)\\/index\\.php\\?menuaction=calendar\\.uicalendar\\.set_action\\&cal_id=([^;'\"]+);?['\"]/i", $rest[1][$i]) && strtoupper($rest[4][$i]) == "CLICK")) { //Calendar events $body = str_replace($rest[1][$i], "<" . $rest[2][$i] . $rest[3][$i] . $rest[7][$i] . ">", $body); } } require_once dirname(__FILE__) . '/../../prototype/library/CssToInlineStyles/css_to_inline_styles.php'; $cssToInlineStyles = new CSSToInlineStyles($body); $cssToInlineStyles->setUseInlineStylesBlock(true); $cssToInlineStyles->setCleanup(TRUE); $body = $cssToInlineStyles->convert(); //Converte as tag style em inline styles ///--------------------------------// // tags to be removed doe to security reasons $tag_list = array('blink', 'object', 'frame', 'iframe', 'layer', 'ilayer', 'plaintext', 'script', 'applet', 'embed', 'frameset', 'xml', 'xmp', 'style', 'head'); foreach ($tag_list as $index => $tag) { $body = @mb_eregi_replace("<{$tag}\\b[^>]*>(.*?)</{$tag}>", '', $body); } /* * Remove deslocamento a esquerda colocado pelo Outlook. * Este delocamento faz com que algumas palavras fiquem escondidas atras da barra lateral do expresso. */ $body = mb_ereg_replace("(<p[^>]*)(text-indent:[^>;]*-[^>;]*;)([^>]*>)", "\\1\\3", $body); $body = mb_ereg_replace("(<p[^>]*)(margin-right:[^>;]*-[^>;]*;)([^>]*>)", "\\1\\3", $body); $body = mb_ereg_replace("(<p[^>]*)(margin-left:[^>;]*-[^>;]*;)([^>]*>)", "\\1\\3", $body); //--------------------------------------------------------------------------------------------// $body = str_ireplace('position:absolute;', '', $body); //Remoção de tags <span></span> para correção de erro no firefox //Comentado pois estes replaces geram erros no html da msg, não se pode garantir que o os </span></span> sejam realmente os fechamentos dos <span><span>. //Caso realmente haja a nescessidade de remover estes spans deve ser repensado a forma de como faze-lo. // $body = mb_eregi_replace("<span><span>","",$body); // $body = mb_eregi_replace("</span></span>","",$body); //Correção para compatibilização com Outlook, ao visualizar a mensagem $body = mb_ereg_replace('<!--\\[', '<!-- [', $body); $body = mb_ereg_replace('<!\\[endif\\]-->', '<![endif]-->', $body); $body = preg_replace("/<p[^\\/>]*>([\\s]?)*<\\/p[^>]*>/", '', $body); //Remove paragrafos vazios (evita duplo espaçamento em emails do MSO) return $body; }
/** * This method parses the template css in the template by using Tijs Verkoyen's CSSToInlineStyles parser. * * @param string $body * @return string */ protected function processCSS($body) { $css = $this->getCSS(); // stop here if no template CSS was set if (empty($css)) { return $body; } $css = new CSSToInlineStyles($body, $css); return $css->convert(); }
<?php header("Content-Type: text/html; charset=iso-8859-1"); include "../tupi.inicializar.php"; //carregando o arquivo css // get contents of a file into a string $filename = "../css/bootstrap.css"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); $msg = utf8_decode($_REQUEST['textoEmailRelat']); $CssConverte = new CSSToInlineStyles($msg, $contents); $html = $_REQUEST['infoEmailRelat'] . "<br><br>" . $CssConverte->convert(); $result = $tupi->mail_html($_REQUEST['destinatario'], $tupi->REMETENTE, $tupi->TITULO, $html); $oMensagem = new Mensagem(); if ($result) { $oMensagem->getMensagem(53); } else { $oMensagem->getMensagem(54); } echo utf8_decode($oMensagem->mensagem);