/** * 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); }
/** * <p>Templates controller</p> * <p>This function is the controller to view the templates view</p> * @author Joobi Limited <wwww.joobi.co> */ function templates($action, $task, $template_id) { $my = JFactory::getUser(); $css = '.icon-48-templates { background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/templates.png)}'; $doc = JFactory::getDocument(); $doc->addStyleDeclaration($css, $type = 'text/css'); $img = 'templates.png'; $templatesearch = JRequest::getVar('templatesearch', ''); $showTemplates = true; // defined toggle for publish and unpublish of mailings $willRedirect = false; $checkToggle = false; $cid = JRequest::getVar('cid'); if (empty($template_id)) { if (!empty($cid) && is_array($cid)) { $template_id = $cid[key($cid)]; } } else { if (empty($cid)) { $cid[] = $template_id; } } if (!empty($task) && $task == 'togle') { $checkToggle = true; // $id = JRequest::getVar( 'templateid' ); $id = $template_id; $col = JRequest::getVar('col'); $template_id = !empty($id) && !empty($col) ? $id : $template_id; $task = !empty($template_id) && !empty($col) ? $col : $task; $willRedirect = true; } switch ($task) { case 'new': case 'add': $showTemplates = false; $template = null; $form['main'] = " <form action='index.php' method='post' name='adminForm' enctype='multipart/form-data' id=\"adminForm\"> \n"; $message = isset($message) ? $message : ''; backHTML::_header(_JNEWS_TEMPLATES, 'templates.png', $message, $task, $action); backHTML::formStart('template', 0, ''); echo jNews_TemplatesHTML::createTemplate($template, $form); $go[] = jnews::makeObj('act', $action); backHTML::formEnd($go); break; case 'edit': $showTemplates = false; $template = jNews_Templates::loadOneTemplate('*', $template_id); $form['main'] = " <form action='index.php' method='post' name='adminForm' enctype='multipart/form-data' id=\"adminForm\">"; $message = isset($message) ? $message : ''; backHTML::_header(_JNEWS_TEMPLATES, 'templates.png', $message, $task, $action); backHTML::formStart('template', 0, ''); echo jNews_TemplatesHTML::createTemplate($template, $form); $go[] = jnews::makeObj('act', $action); $go[] = jnews::makeObj('template_id', $template_id); backHTML::formEnd($go); break; case 'save': JRequest::checkToken() or die('Invalid Token'); $message = jnews::printYN(jNews_Templates::saveTemplate($task, $template_id), _JNEWS_TEMPLATE_SAVED, _JNEWS_ERROR); jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates', $message); break; case 'apply': JRequest::checkToken() or die('Invalid Token'); $message = ''; $message .= jnews::printYN(jNews_Templates::saveTemplate($task, $template_id), _JNEWS_TEMPLATE_SAVED, _JNEWS_ERROR); $id = empty($template_id) ? jNews_Templates::loadOneTemplate('template_id', '', 'template_id', 'DESC') : $template_id; $converMessage = JRequest::getVar('message', '', '', 'string', JREQUEST_ALLOWRAW); if (!empty($converMessage)) { $message .= '<br/>'; $message .= implode("", $converMessage); } jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates&task=edit&template_id=' . $id, $message); break; case 'publish': if (!$checkToggle) { JRequest::checkToken() or die('Invalid Token'); } $message = jnews::printYN(jNews_Templates::updateTemplate($cid, 'published', true), 'Successfully published template!', 'Error publishing the template!'); jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates', $message); break; case 'unpublish': if (!$checkToggle) { JRequest::checkToken() or die('Invalid Token'); } $condition = jNews_Templates::updateTemplate($cid, 'published', false); if ($condition) { $message = jnews::printM('ok', 'Successfully unpublished template!'); } else { $message = jnews::printM('defaulterror', 'Unable to unpublished default template!'); } // $message = jnews::defaultYN( jNews_Templates::updateTemplate($template_id,'published', false) , 'Successfully unpublished template!' , 'Unable to unpublished default template!' ); if ($willRedirect) { jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates', $message); } break; case 'copy': JRequest::checkToken() or die('Invalid Token'); $message = jnews::printYN(jNews_Templates::copyTemplate($template_id), _JNEWS_TEMPLATE . _JNEWS_SUCCESS_COPIED, _JNEWS_ERROR); $showTemplates = true; break; case 'default': $success = false; //set all the templates to premium = 0 if (jNews_Templates::updateTemplate($template_id, 'default', false, false)) { $success = true; } //set the template published and premium if ($success) { jNews_Templates::updateTemplate($template_id, 'default', true, true); } $message = jnews::printYN($success, 'Successfully set the template to default!', 'Unable to set template to default!'); jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates', $message); break; case 'delete': JRequest::checkToken() or die('Invalid Token'); $showTemplates = true; $isDefault = jNews_Templates::loadOneTemplate('premium', $template_id); if (!$isDefault) { $message = jnews::printYN(jNews_Templates::deleteTemplate($cid), _JNEWS_TEMPLATE . _JNEWS_SUCCESS_DELETED, _JNEWS_ERROR); } else { $message = jnews::printM('red', _JNEWS_TEMPLATE_DEFAULT_NODEL); } break; case 'cpanel': backHTML::controlPanel(); return true; break; case 'toggle': JRequest::checkToken() or die('Invalid Token'); // main toggle for all usage $listid = JRequest::getVar('listid'); $column = JRequest::getVar('col'); if (!empty($listid) && !empty($column)) { $passObj = new stdClass(); $passObj->tableName = '#__jnews_lists'; $passObj->columnName = $column; $passObj->whereColumn = 'id'; $passObj->whereColumnValue = $listid; jnews::toggle($passObj); } jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates'); break; case 'tempupload': // HTML for upload template // JRequest::checkToken() or die( 'Invalid Token' ); $html = '<form action="index.php?option=' . JNEWS_OPTION . '&act=templates&task=upload" method="post" name="adminForm" enctype="multipart/form-data" id="adminForm">'; $html .= '<table style="width:100%;padding:100px;">'; $html .= '<tr>'; $html .= '<td style="text-align:center;"> <input type="FILE" name="tempupload"> </td>'; $html .= '</tr><tr">'; $html .= '<td style="text-align:center;padding:20px;"> <input type="submit" value="Upload Template" style="width:130px;height:25px;"> </td>'; $html .= '</tr>'; $html .= '</table>'; if (version_compare(JVERSION, '3.0.0', '<')) { $html .= JHTML::_('form.token'); } else { $html .= JHtml::_('form.token'); } $html .= '</form><br/><br/>'; echo $html; $showTemplates = false; break; case 'sendtest': JRequest::checkToken() or die('Invalid Token'); //we save first the template $saveStatus = jNews_Templates::saveTemplate($task, $template_id); //then we send it if the template is successfully saved if ($saveStatus) { $message = jnews::printM('ok', _JNEWS_TEMPLATE_SAVED); $my = JFactory::getUser(); $mailing = new stdClass(); $receiver = new stdClass(); $status = false; $mailing->id = 1; $mailing->html = 1; $mailing->images = ''; $mailing->attachments = ''; $mailing->subject = jNews_Templates::loadOneTemplate('name', $template_id); $mailing->htmlcontent = jNews_Templates::loadOneTemplate('body', $template_id); $mailing->template_id = $template_id; $receiver->name = $my->name; $receiver->email = $my->email; $receiver->receive_html = 1; $receiver->user_id = $my->id; $mailerC = new jNews_ProcessMail(); $sendStatus = $mailerC->send($mailing, $receiver); $success = 'Template ' . $mailing->subject . ' successfully sent to ' . $receiver->email; $error = 'There is a problem in sending the template ' . $mailing->subject . ' <br/>' . _JNEWS_SENDTEST_CONFIGERROR; $message = $sendStatus ? jnews::printM('ok', $success) : jnews::printM('error', $error); } else { //otherwise we give an error message $message = jnews::printM('error', _JNEWS_ERROR); } jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=templates&task=edit&template_id=' . $template_id, $message); break; case 'upload': JRequest::checkToken() or die('Invalid Token'); $db = JFactory::getDBO(); $fileName = $_FILES['tempupload']['name']; $folderName = substr($fileName, 0, -4); // explode to array to compare and check if the uploaded file is a zip file $type = $_FILES['tempupload']['type']; // if zip is not found then return to previous upload page if (strtolower($type) != 'application/zip') { if (strtolower(substr($fileName, -4)) != '.zip') { if (version_compare(JVERSION, '1.6.0', '<')) { //j15 echo "<script> alert('" . addslashes(_JNEWS_UPLOAD_ZIP_INVALID) . "'); document.location.href='index.php?option='.JNEWS_OPTION.'&act=templates';</script>"; } else { if (version_compare(JVERSION, '3.0.0', '<')) { echo "<script> alert('" . addslashes(_JNEWS_UPLOAD_ZIP_INVALID) . "'); window.parent.SqueezeBox.close();</script>"; } else { echo "<script> alert('" . addslashes(_JNEWS_UPLOAD_ZIP_INVALID) . "'); jQuery(window.top.document).find(\"div.modal-backdrop\").click(); </script>"; } } break; } } $result = jNews_Templates::uploadTemplate(); if ($result) { // if success // read index.html of file for template body content $tempPath = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS; $file = fopen($tempPath . $folderName . DS . 'index.html', "r") or exit("Unable to open file!"); $tempbody = array(); while (!feof($file)) { $tempbody[] = fgets($file); } //endwhile fclose($file); $tempbody = implode(' ', $tempbody); $standardCSSA = array(); $extraCSSStyles = ''; if (is_file($tempPath . $folderName . DS . 'css' . DS . 'style.css')) { //new template package with style.css file //we get here the css codes from the uploaded template $cssfile = fopen($tempPath . $folderName . DS . 'css' . DS . 'style.css', "r") or exit("Unable to open file!"); $cssstyle = array(); while (!feof($cssfile)) { $cssstyle[] = fgets($cssfile); } //endwhile fclose($cssfile); $cssstyle = implode(' ', $cssstyle); $cleanCSSstyle = jNews_Templates::cleanCSSComments($cssstyle); //cleancsscomments @(require_once JNEWSPATH_CLASS . 'class.cssinlinestyles.php'); if (class_exists('CSSToInlineStyles')) { $newCSSProcess = new CSSToInlineStyles(); $newCSSProcess->setCSS($cleanCSSstyle); $newCSSProcess->processCSS(); //we define the predefined selectors for the css $standardSelectorsA = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'a', 'ul', 'li', '.unsubscribe', '.subscriptions', '.content', '.title', '.readmore', '.online', '.aca_content', '.aca_title', '.aca_readmore', '.aca_online', '.aca_subscribe', '.aca_unsubscribe', '.aca_subscriptions'); $standardCSSA = $newCSSProcess->getStandardCSSTag($newCSSProcess->cssRules, $standardSelectorsA); $extraCSSStyles = $newCSSProcess->getExtraCSSTag($newCSSProcess->cssRules, $standardSelectorsA); } } // replace source image paths from 'images/' to 'media/.../templates/$FOLDERNAME/' $bodyImgA = JRequest::getVar('bodyImg'); if (is_file($tempPath . $folderName . DS . 'css' . DS . 'style.css')) { //new template package // $body = preg_replace('#images\/#', JNEWS_JPATH_LIVE . '/media/'. JNEWS_OPTION . '/templates/' . $folderName .'/images/', $tempbody); $origin = '"images/'; $destination = '"' . JNEWS_JPATH_LIVE . '/media/' . JNEWS_OPTION . '/templates/' . $folderName . '/images/'; $body = str_replace($origin, $destination, $tempbody); } else { // $body = preg_replace('#images\/#', JNEWS_JPATH_LIVE . '/media/'. JNEWS_OPTION . '/templates/'. $folderName.'/' , $tempbody); $origin = 'media/' . JNEWS_OPTION . '/templates/' . $folderName . '/'; $destination = JNEWS_JPATH_LIVE . '/media/' . JNEWS_OPTION . '/templates/' . $folderName . '/'; $body = str_replace($origin, $destination, $tempbody); } $template = null; $template->name = ucfirst($folderName); $template->description = ''; $template->created = time(); $template->body = addslashes($body); $template->altbody = ''; $template->premium = 0; $template->namekey = $folderName; $template->published = 1; $template->styles = addslashes(serialize($standardCSSA)); $template->csstyle = addslashes($extraCSSStyles); $template->thumbnail = ''; $templateA = (array) $template; $query = 'SELECT * FROM `#__jnews_templates` WHERE `namekey` = \'' . $template->namekey . '\' '; $db->setQuery($query); $findresult = $db->loadObject(); if (empty($findresult)) { // store template $status = jNews_Templates::storeTemplate($templateA); } else { //update template $query = 'UPDATE `#__jnews_templates` SET `body` = \'' . $template->body . '\' , `availability` = 1 WHERE `namekey`= \'' . $template->namekey . '\' AND `template_id`=' . $findresult->template_id; $db->setQuery($query); $status = $db->query(); } // upload success // display success message if ($status) { if (version_compare(JVERSION, '1.6.0', '<')) { //j15 echo "<script> alert('" . addslashes(_JNEWS_TEMPLATE_UPLOAD_SUCCESS) . "'); document.location.href='index.php?option=" . JNEWS_OPTION . "&act=templates';</script>"; } else { //j16 echo "<script> alert('" . addslashes(_JNEWS_TEMPLATE_UPLOAD_SUCCESS) . "'); window.parent.location.reload();</script>"; } } } else { // failed uploading // display an error message if (version_compare(JVERSION, '1.6.0', '<')) { //j15 echo "<script> alert('" . addslashes(_JNEWS_TEMPLATE_UPLOAD_FAIL) . "'); document.location.href='index.php?option=" . JNEWS_OPTION . "&act=templates';</script>"; } else { if (version_compare(JVERSION, '3.0.0', '<')) { echo "<script> alert('" . addslashes(_JNEWS_TEMPLATE_UPLOAD_FAIL) . "'); window.parent.SqueezeBox.close();</script>"; } else { echo "<script> alert('" . addslashes(_JNEWS_TEMPLATE_UPLOAD_FAIL) . "'); jQuery(window.top.document).find(\"div.modal-backdrop\").click(); </script>"; } } } $showTemplates = false; break; case 'preview': $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">"; $forms['filter'] = " <form name='jnewsFilterForm' method='POST' action='index.php'> \n"; $id = JRequest::getInt('template_id', 0, 'request'); $body = jNews_Templates::loadOneTemplate('body', $id); jNews_Templates::includeStyles($body, $id); jNews_TemplatesHTML::previewTemplate($body, $forms); $showTemplates = false; break; case 'assign': $templatesearch = JRequest::getVar('templatesearch', ''); $linkTh = jNews_Tools::completeLink('option=' . JNEWS_OPTION, true, false, true); $forms['main'] = "<form action=" . $linkTh . " method='post' name='adminForm' id=\"adminForm\">"; $paginationStart = JRequest::getVar('pg'); if (!empty($paginationStart)) { $limitstart = 0; $limitend = $paginationStart; } else { $app = JFactory::getApplication(); $limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', 0, 'int'); $limitend = $app->getUserStateFromRequest('limit', 'limit', 0, 'int'); } $limittotal = jNews_Templates::countTemplates(1, 1); $setLimit = new stdClass(); $setLimit->total = !empty($limittotal) ? $limittotal : 0; $setLimit->start = !empty($limitstart) ? $limitstart : 0; $setLimit->end = !empty($limitend) ? $limitend : 20; $templates = jNews_Templates::getTemplates(true, false, $templatesearch, $setLimit->start, $setLimit->end, null, 1); //first param to true to show only the published jNews_TemplatesHTML::assignTemplate($templates, $forms, $setLimit, $templatesearch); $showTemplates = false; break; } if ($showTemplates) { $start = JRequest::getVar('start', '0'); $templatesearch = JRequest::getVar('templatesearch', ''); $limit = -1; $message = isset($message) ? $message : ''; backHTML::_header(_JNEWS_TEMPLATES, $img, $message, $task, $action); $forms['main'] = " <form action='index.php' method='post' name='adminForm' id=\"adminForm\">"; $forms['filter'] = " <form name='jnewsFilterForm' method='POST' action='index.php'> \n"; backHTML::formStart('show_template', '', ''); // added this code for pagination =========================== $paginationStart = JRequest::getVar('pg'); $app = JFactory::getApplication(); if (!empty($paginationStart)) { $limitstart = 0; $limitend = $paginationStart; } else { $limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', 0, 'int'); $limitend = $app->getUserStateFromRequest('limit', 'limit', 0, 'int'); } $setSort = new stdClass(); $setSort->orderValue = $app->getUserStateFromRequest(JNEWS_OPTION . '.templates.filter_order', 'filter_order', 'premium', 'cmd'); $setSort->orderDir = $app->getUserStateFromRequest(JNEWS_OPTION . '.templates.filter_order_Dir', 'filter_order_Dir', 'desc', 'word'); $limittotal = jNews_Templates::countTemplates(); $setLimit = new stdClass(); $setLimit->total = !empty($limittotal) ? $limittotal : 0; $setLimit->start = !empty($limitstart) ? $limitstart : 0; $setLimit->end = !empty($limitend) ? $limitend : $limittotal; // recheck start if ($setLimit->total == $setLimit->end) { $setLimit->start = 0; } $templates = jNews_Templates::getTemplates(false, false, $templatesearch, $setLimit->start, $setLimit->end, $setSort); //recheck limit total [pagination] if (isset($setLimit->total) && !empty($templatesearch)) { $setLimit->total = !empty($temps) ? count($templates) : $setLimit->total; } jNews_TemplatesHTML::displayTemplateList($templates, $forms, $setLimit->start, $setLimit->end, $templatesearch, $action, $setLimit, $setSort); $go[] = jnews::makeObj('act', 'templates'); $go[] = jnews::makeObj('filter_order', $setSort->orderValue); $go[] = jnews::makeObj('filter_order_Dir', $setSort->orderDir); backHTML::formEnd($go); } return true; }
<?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);