예제 #1
0
 /**
  * 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>&nbsp;</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('&lt;!\\[endif\\]--&gt;', '<![endif]-->', $body);
     $body = preg_replace("/<p[^\\/>]*>([\\s]?)*<\\/p[^>]*>/", '', $body);
     //Remove paragrafos vazios (evita duplo espaçamento em emails do MSO)
     return $body;
 }