From 9acc933deaa87ae937b400c021c85005a173c871 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 18 Aug 2014 23:16:10 -0700 Subject: [PATCH] Fixed - mail handler now embedding images with the {THEME} constant correctly. --- e107_core/templates/email_template.php | 26 +++++++++++++++++--- e107_handlers/mail.php | 33 +++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/e107_core/templates/email_template.php b/e107_core/templates/email_template.php index 69700a81a..54f853a38 100644 --- a/e107_core/templates/email_template.php +++ b/e107_core/templates/email_template.php @@ -191,12 +191,11 @@ $MAILOUT_FOOTER = " */ -// FIXME clean up the whole email template/render tempalte mess //------------------------------------------------------------- // 'SIGNUP' TEMPLATE //------------------------------------------------------------- - +//@Deprecated $SIGNUPEMAIL_TEMPLATE = "
@@ -357,6 +356,8 @@ $EMAIL_TEMPLATE['default']['footer'] = "

"; +// ------------------------------- + /** * Signup Template. @@ -392,7 +393,7 @@ $EMAIL_TEMPLATE['signup']['body'] = " {SITENAME=link}
{SITEURL} -

".($includeSiteButton ? "" : '')." +

".($includeSiteButton ? "{SITEBUTTON}" : '')."
"; @@ -402,6 +403,11 @@ $EMAIL_TEMPLATE['signup']['footer'] = "
$EMAIL_TEMPLATE['signup']['cc'] = ""; $EMAIL_TEMPLATE['signup']['bcc'] = ""; $EMAIL_TEMPLATE['signup']['attachments'] = ""; + +//TODO FIXME {SITEBUTTON} not working at the moment. (broken path) + +// ----------------------------- + /* * QUICK ADD USER EMAIL TEMPLATE - BODY. @@ -415,6 +421,9 @@ $EMAIL_TEMPLATE['quickadduser']['header'] = $EMAIL_TEMPLATE['default']['header' $EMAIL_TEMPLATE['quickadduser']['body'] = USRLAN_185.USRLAN_186; $EMAIL_TEMPLATE['quickadduser']['footer'] = $EMAIL_TEMPLATE['default']['footer']; // will use default footer above. +// --------------------------------- + + // Notify (@see admin-> notify) // TODO $EMAIL_TEMPLATE['notify']['subject'] = '{SITENAME}: {SUBJECT} '; @@ -422,4 +431,15 @@ $EMAIL_TEMPLATE['notify']['header'] = $EMAIL_TEMPLATE['default']['header']; / $EMAIL_TEMPLATE['notify']['body'] = $EMAIL_TEMPLATE['default']['body']; // will use default header above. $EMAIL_TEMPLATE['notify']['footer'] = $EMAIL_TEMPLATE['default']['footer']; // will use default header above. +// A Dummy Example for theme developers. +$EMAIL_TEMPLATE['example']['subject'] = '{SITENAME}: {SUBJECT} '; +$EMAIL_TEMPLATE['example']['header'] = $EMAIL_TEMPLATE['default']['header']; // will use default header above. +$EMAIL_TEMPLATE['example']['body'] = $EMAIL_TEMPLATE['default']['body']; // will use default header above. +$EMAIL_TEMPLATE['example']['footer'] = "

+ + {SITENAME} + + + "; + ?> \ No newline at end of file diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index d4ee98a49..ed792d9d2 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -825,20 +825,28 @@ class e107Email extends PHPMailer */ public function MsgHTML($message, $basedir = '') { + + preg_match_all("/(src|background)=([\"\'])(.*)\\2/Ui", $message, $images); // Modified to accept single quotes as well if(isset($images[3])) { if($this->debug) { + echo "

Detected Image Paths

"; print_a($images[3]); } + $tp = e107::getParser(); + foreach($images[3] as $i => $url) { // do not change urls for absolute images (thanks to corvuscorax) if (!preg_match('#^[A-z]+://#',$url)) { + $url = $tp->replaceConstants($url); + + $delim = $images[2][$i]; // Will be single or double quote $filename = basename($url); $directory = dirname($url); @@ -848,7 +856,12 @@ class e107Email extends PHPMailer $directory = substr(SERVERBASE, 0, -1).$directory; // Convert to absolute server reference $basedir = ''; } - //echo "CID file {$filename} in {$directory}. Base = ".SERVERBASE."< BaseDir = {$basedir}
"; + + if ($this->debug) + { + echo "
CID file {$filename} in {$directory}. Base = ".SERVERBASE."< BaseDir = {$basedir}
"; + } + $cid = 'cid:' . md5($filename); $ext = pathinfo($filename, PATHINFO_EXTENSION); $mimeType = self::_mime_types($ext); @@ -858,15 +871,29 @@ class e107Email extends PHPMailer if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { // $images[1][$i] contains 'src' or 'background' - $message = preg_replace("/".$images[1][$i]."=".$delim.preg_quote($url, '/').$delim."/Ui", $images[1][$i]."=".$delim.$cid.$delim, $message); + $message = preg_replace("/".$images[1][$i]."=".$delim.preg_quote($images[3][$i], '/').$delim."/Ui", $images[1][$i]."=".$delim.$cid.$delim, $message); } else { - if ($this->debug) echo "Add embedded image {$url} failed
"; + if ($this->debug) + { + echo "Add embedded image {$url} failed
"; + echo "
basedir=".$basedir; + echo "
dir=".$directory; + echo "
file=".$filename; + echo "
"; + } } } + elseif($this->debug) + { + echo "
Absolute Image: ".$url; + + } } } + + $this->IsHTML(true); $this->Body = $message; //print_a($message);