1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 01:19:44 +01:00

Additional changes so email templates conform to v2 specifications.

This commit is contained in:
Cameron 2014-08-16 17:19:50 -07:00
parent 5b473a1c75
commit 734a954228
3 changed files with 213 additions and 86 deletions

View File

@ -2,25 +2,14 @@
/*
* e107 website system
*
* Copyright (C) 2008-2013 e107 Inc (e107.org)
* Copyright (C) 2008-2014 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Templates for all emails
*
* $URL: $
* $Revision: 11315 $
* $Id: $
*/
/**
*
* @package e107
* @subpackage e107_templates
* @version $Id: mail_manager_class.php 11315 2010-02-10 18:18:01Z secretr $;
*
*/
/**
* This file defines the default templates for each type of email which may be sent.
@ -318,13 +307,7 @@ $MONTHLYUPDATE_TEMPLATE = array(
);
/*
* QUICK ADD USER EMAIL TEMPLATE - BODY.
* This is the email that is sent when an admin creates a user account in admin. "Quick Add User"
USRLAN_185 = A user account has been created for you at {SITEURL} with the following login:<br />Login Name: {LOGIN}<br />Password: {PASSWORD}<br/><br />
USRLAN_186 = Please go to the site as soon as possible and log in, then change your password using the \'Settings\' option.<br /><br />
You can also change other settings at the same time.<br /><br />Note that your password cannot be recovered if you lose it.
*/
$QUICKADDUSER_TEMPLATE = array(
'template_name' => 'Quick-Add-User',
@ -351,14 +334,13 @@ $QUICKADDUSER_TEMPLATE = array(
// Default - test email and when no template specified.
$EMAIL_TEMPLATE['default']['name'] = 'Default';
$EMAIL_TEMPLATE['default']['overrides'] = '';
$EMAIL_TEMPLATE['default']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
<html xmlns='http://www.w3.org/1999/xhtml' >
<head>
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<style>
body { padding:10px; background-color: #E1E1E1 }
div#body { padding:10px; width: 600px; background-color: #FFFFFF; border-radius: 5px }
div#body { padding:10px; width: 800px; background-color: #FFFFFF; border-radius: 5px }
</style>
</head>
@ -374,4 +356,63 @@ $EMAIL_TEMPLATE['default']['footer'] = "<br /><br />
</body>
</html>";
// Signup Template.
$EMAIL_TEMPLATE['signup']['subject'] = LAN_SIGNUP_96.' {SITENAME}';
$EMAIL_TEMPLATE['signup']['header'] = $EMAIL_TEMPLATE['default']['header'];
$EMAIL_TEMPLATE['signup']['body'] = "
<div style='text-align:left'>
".LAN_EMAIL_01." {USERNAME},<br />
<br />".
LAN_SIGNUP_97." {SITENAME}<br />
".LAN_SIGNUP_21."<br />
<br />
{ACTIVATION_LINK}<br />
<br />
<small>".LAN_SIGNUP_59."</small><br />
<br />
".LAN_SIGNUP_18."<br />
<br />
".LAN_LOGINNAME.": <b> {LOGINNAME} </b><br />
".LAN_PASSWORD.": <b> {PASSWORD} </b><br />
<br />
".LAN_EMAIL_04."<br />
".LAN_EMAIL_05."<br />
<br />
".LAN_EMAIL_06."<br />
<br />
{SITENAME=link}<br />
{SITEURL}
<br /><br />".($includeSiteButton ? "<a href='".SITEURL."' title=''><img src='".e_IMAGE_ABS.str_replace('{e_IMAGE}', '', $includeSiteButton)."' alt='' /></a>" : '')."
</div>
";
$EMAIL_TEMPLATE['signup']['footer'] = "</div>
</body>
</html>";
$EMAIL_TEMPLATE['signup']['cc'] = "";
$EMAIL_TEMPLATE['signup']['bcc'] = "";
$EMAIL_TEMPLATE['signup']['attachments'] = "";
/*
* QUICK ADD USER EMAIL TEMPLATE - BODY.
* This is the email that is sent when an admin creates a user account in admin. "Quick Add User"
USRLAN_185 = A user account has been created for you at {SITEURL} with the following login:<br />Login Name: {LOGIN}<br />Password: {PASSWORD}<br/><br />
USRLAN_186 = Please go to the site as soon as possible and log in, then change your password using the \'Settings\' option.<br /><br />
You can also change other settings at the same time.<br /><br />Note that your password cannot be recovered if you lose it.
*/
$EMAIL_TEMPLATE['quickadd']['header'] = $EMAIL_TEMPLATE['default']['header']; // will use default header above.
$EMAIL_TEMPLATE['quickadd']['body'] = USRLAN_185.USRLAN_186;
$EMAIL_TEMPLATE['quickadd']['footer'] = $EMAIL_TEMPLATE['default']['footer']; // will use default footer above.
// Notify (@see admin-> notify) // TODO
$EMAIL_TEMPLATE['notify']['header'] = $EMAIL_TEMPLATE['default']['header']; // will use default header above.
$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.
?>

View File

@ -137,24 +137,24 @@ define('MAIL_LOG_PATH',e_LOG);
class e107Email extends PHPMailer
{
private $general_opts = array();
private $logEnable = 0; // 0 = log disabled, 1 = 'dry run' (debug and log, no send). 2 = 'log all' (send, and log result)
private $logHandle = FALSE; // Save handle of log file if opened
private $general_opts = array();
private $logEnable = 0; // 0 = log disabled, 1 = 'dry run' (debug and log, no send). 2 = 'log all' (send, and log result)
private $logHandle = FALSE; // Save handle of log file if opened
private $localUseVerp = FALSE; // Use our own variable - PHPMailer one doesn't work with all mailers
private $save_bouncepath = ''; // Used with VERP
private $localUseVerp = FALSE; // Use our own variable - PHPMailer one doesn't work with all mailers
private $save_bouncepath = ''; // Used with VERP
private $add_email = 0; // 1 includes email detail in log (if logging enabled, of course)
private $allow_html = 1; // Flag for HTML conversion - '1' = default, FALSE = disable, TRUE = force.
private $add_HTML_header = FALSE; // If TRUE, inserts a standard HTML header at the front of the HTML part of the email (set FALSE for BC)
private $SendCount = 0; // Keep track of how many emails sent since last SMTP open/connect (used for SMTP KeepAlive)
private $TotalSent = 0; // Info might be of interest
private $TotalErrors = 0; // Count errors in sending emails
private $pause_amount = 10; // Number of emails to send before pausing/resetting (or closing if SMTPkeepAlive set)
private $pause_time = 1; // Time to pause after sending a block of emails
public $legacyBody = FALSE; // TRUE enables legacy conversion of plain text body to HTML in HTML emails
private $add_email = 0; // 1 includes email detail in log (if logging enabled, of course)
private $allow_html = 1; // Flag for HTML conversion - '1' = default, FALSE = disable, TRUE = force.
private $add_HTML_header = FALSE; // If TRUE, inserts a standard HTML header at the front of the HTML part of the email (set FALSE for BC)
private $SendCount = 0; // Keep track of how many emails sent since last SMTP open/connect (used for SMTP KeepAlive)
private $TotalSent = 0; // Info might be of interest
private $TotalErrors = 0; // Count errors in sending emails
private $pause_amount = 10; // Number of emails to send before pausing/resetting (or closing if SMTPkeepAlive set)
private $pause_time = 1; // Time to pause after sending a block of emails
public $legacyBody = false; // TRUE enables legacy conversion of plain text body to HTML in HTML emails
private $debug = false; // echos various debug info when set to true.
/**
* Constructor sets up all the global options, and sensible defaults - it should be the only place the prefs are accessed
@ -170,6 +170,11 @@ class e107Email extends PHPMailer
$e107 = e107::getInstance();
$pref = e107::pref('core');
$tp = e107::getParser();
if(defined('MAIL_DEBUG'))
{
$this->debug = true;
}
$this->CharSet = 'utf-8';
$this->SetLanguage(CORE_LC);
@ -188,7 +193,7 @@ class e107Email extends PHPMailer
$this->allow_html = varset($pref['mail_sendstyle'],'textonly') == 'texthtml' ? true : 1;
if (varsettrue($pref['mail_options'])) $this->general_opts = explode(',',$pref['mail_options'],'');
if (defined('MAIL_DEBUG')) echo 'Mail_options: '.$pref['mail_options'].' Count: '.count($this->general_opts).'<br />';
if ($this->debug) echo 'Mail_options: '.$pref['mail_options'].' Count: '.count($this->general_opts).'<br />';
foreach ($this->general_opts as $k => $v)
{
$v = trim($v);
@ -196,7 +201,7 @@ class e107Email extends PHPMailer
if (strpos($v,'hostname') === 0)
{
list(,$this->HostName) = explode('=',$v);
if (defined('MAIL_DEBUG')) echo "Host name set to: {$this->HostName}<br />";
if ($this->debug) echo "Host name set to: {$this->HostName}<br />";
}
}
@ -248,7 +253,7 @@ class e107Email extends PHPMailer
$this->Port = 465;
break;
default :
if (defined('MAIL_DEBUG')) echo "Invalid option: {$smtp_options['secure']}<br />";
if ($this->debug) echo "Invalid option: {$smtp_options['secure']}<br />";
}
}
$this->SMTPKeepAlive = varset($smtp_options['keepalive'],FALSE); // ***** Control this
@ -485,9 +490,11 @@ class e107Email extends PHPMailer
break;
}
$message = str_replace("\t", "", $message); // filter out tabs from templates;
if ($want_HTML !== FALSE)
{
if (defined('MAIL_DEBUG')) echo "Generating multipart email<br />";
if ($this->debug) echo "Generating multipart email<br />";
if ($add_HTML_header)
{
$message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n
@ -495,6 +502,12 @@ class e107Email extends PHPMailer
}
if ($this->legacyBody && !preg_match('/<(font|br|a|img|b)/i', $message)) // Assume html if it includes one of these tags
{ // Otherwise assume its a plain text message which needs some conversion to render in HTML
if($this->debug == true)
{
echo 'Running legacyBody mode<br />';
}
$message = htmlspecialchars($message,ENT_QUOTES,$this->CharSet);
$message = preg_replace('%(http|ftp|https)(://\S+)%', '<a href="\1\2">\1\2</a>', $message);
$message = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '\\1<a href="http://\\2">\\2</a>', $message);
@ -508,7 +521,7 @@ class e107Email extends PHPMailer
}
else
{ // generate the plain text as the sole part of the email
if (defined('MAIL_DEBUG')) echo "Generating plain text email<br />";
if ($this->debug) echo "Generating plain text email<br />";
if (strpos($message,'</style>') !== FALSE)
{
$text = strstr($message,'</style>');
@ -586,11 +599,17 @@ class e107Email extends PHPMailer
public function arraySet($eml)
{
if($this->debug)
{
print_a($eml);
}
if(vartrue($eml['template'])) // @see e107_core/templates/email_template.php
{
$tp = e107::getParser();
if($tmpl = e107::getCoreTemplate('email','default', true, true)) // $EMAIL_TEMPLATE['default']
if($tmpl = e107::getCoreTemplate('email',$eml['template'], true, true)) // $EMAIL_TEMPLATE['default']
{
$filter = array("\n", "\t");
$tmpl['header'] = str_replace($filter,'', $tmpl['header']);
@ -790,6 +809,12 @@ class e107Email extends PHPMailer
preg_match_all("/(src|background)=([\"\'])(.*)\\2/Ui", $message, $images); // Modified to accept single quotes as well
if(isset($images[3]))
{
if($this->debug)
{
print_a($images[3]);
}
foreach($images[3] as $i => $url)
{
// do not change urls for absolute images (thanks to corvuscorax)
@ -818,7 +843,7 @@ class e107Email extends PHPMailer
}
else
{
if (defined('MAIL_DEBUG')) echo "Add embedded image {$url} failed<br />";
if ($this->debug) echo "Add embedded image {$url} failed<br />";
}
}
}

View File

@ -995,6 +995,7 @@ class e_user_model extends e_admin_model
// TODO - add some more useful methods, sc_* methods support
class e_system_user extends e_user_model
{
public $debug = false;
/**
* Constructor
*
@ -1047,17 +1048,36 @@ class e_system_user extends e_user_model
}
$eml = $this->renderEmail($type, $userInfo);
if(empty($eml)) return false;
if(empty($eml))
{
if($this->debug)
{
echo '$eml returned nothing';
}
return false;
}
else
{
if($this->debug)
{
echo '<h3>$eml array</h3>';
print_a($eml);
}
}
$mailer = e107::getEmail();
$mailer->template = $eml['template'];
unset($eml['template']);
// Custom e107 Header
if($userInfo['user_id'])
{
$mailer->AddCustomHeader("X-e107-id: {$userInfo['user_id']}");
$eml['e107_header'] = $userInfo['user_id'];
// $mailer->AddCustomHeader("X-e107-id: {$userInfo['user_id']}");
}
return $mailer->sendEmail($userInfo['user_email'], $userInfo['user_name'], $eml, false);
@ -1082,7 +1102,9 @@ class e_system_user extends e_user_model
{
$pref = e107::getPref();
$ret = array();
$tp = e107::getParser();
// mailer options
if(isset($userInfo['mail_options']) && is_array($userInfo['mail_options']))
{
@ -1092,41 +1114,58 @@ class e_system_user extends e_user_model
// required for signup and quickadd email type
e107::coreLan('signup');
// FIXME convert to the new template to avoid include on every call
// BC
if (file_exists(THEME.'email_template.php'))
$EMAIL_TEMPLATE = e107::getCoreTemplate('email');
if(!is_array($EMAIL_TEMPLATE)) //BC Fixes. pre v2 alpha3.
{
include(THEME.'email_template.php');
}
else
{
// new standards
include(e107::coreTemplatePath('email'));
// load from old location. (root of theme folder if it exists)
if (file_exists(THEME.'email_template.php'))
{
include(THEME.'email_template.php');
}
else
{
// include core default.
include(e107::coreTemplatePath('email'));
}
// BC Fixes.
$EMAIL_TEMPLATE['signup']['subject'] = $SIGNUPEMAIL_SUBJECT;
$EMAIL_TEMPLATE['signup']['cc'] = $SIGNUPEMAIL_CC;
$EMAIL_TEMPLATE['signup']['bcc'] = $SIGNUPEMAIL_BCC;
$EMAIL_TEMPLATE['signup']['attachments']= $SIGNUPEMAIL_ATTACHMENTS;
$EMAIL_TEMPLATE['signup']['body'] = $SIGNUPEMAIL_TEMPLATE;
$EMAIL_TEMPLATE['quickadd']['body'] = $QUICKADDUSER_TEMPLATE['email_body'];
$EMAIL_TEMPLATE['notify']['body'] = $NOTIFY_TEMPLATE['email_body'];
}
// FIXME by SecretR - email template mess - there are changes to emails and templates that need to be implemented here
$template = '';
switch ($type)
{
case 'signup':
if(vartrue($SIGNUPPROVIDEREMAIL_TEMPLATE)) $template = $SIGNUPPROVIDEREMAIL_TEMPLATE;
else $template = $SIGNUPEMAIL_TEMPLATE;
$ret['template'] = false; // Don't allow additional headers (mailer)
$template = (vartrue($SIGNUPPROVIDEREMAIL_TEMPLATE)) ? $SIGNUPPROVIDEREMAIL_TEMPLATE : $EMAIL_TEMPLATE['signup']['body'];
$ret['template'] = false;// 'signup'; // false; // Don't allow additional headers (mailer) ??
break;
case 'quickadd':
$template = $QUICKADDUSER_TEMPLATE['email_body']; // XXX quick fix - add the email templating engine
$ret['template'] = 'email'; // Don't allow additional headers (mailer)
$template = $EMAIL_TEMPLATE['quickadd']['body'];
$ret['template'] = 'quickadd'; // Don't allow additional headers (mailer)
break;
case 'notify': //emailer changes
if(vartrue($userInfo['mail_body'])) $template = $userInfo['mail_body'];//$NOTIFY_HEADER.$userInfo['mail_body'].$NOTIFY_FOOTER;
case 'notify':
if(vartrue($userInfo['mail_body'])) $template = $userInfo['mail_body']; //$NOTIFY_HEADER.$userInfo['mail_body'].$NOTIFY_FOOTER;
$ret['template'] = 'notify';
break;
case 'email'://emailer changes
case 'email':
case 'default':
if(vartrue($userInfo['mail_body'])) $template = $userInfo['mail_body']; //$EMAIL_HEADER.$userInfo['mail_body'].$EMAIL_FOOTER;
$ret['template'] = 'email';
$ret['template'] = 'default';
break;
}
@ -1137,11 +1176,15 @@ class e_system_user extends e_user_model
// signup email only
if($type == 'signup')
{
$HEAD = '';
$FOOT = '';
$ret['e107_header'] = $userInfo['user_id'];
if (vartrue($SIGNUPEMAIL_CC)) { $ret['email_copy_to'] = $SIGNUPEMAIL_CC; }
if (vartrue($SIGNUPEMAIL_BCC)) { $ret['email_bcopy_to'] = $SIGNUPEMAIL_BCC; }
if (vartrue($EMAIL_TEMPLATE['signup']['cc'])) { $ret['email_copy_to'] = $EMAIL_TEMPLATE['signup']['cc']; }
if (vartrue($EMAIL_TEMPLATE['signup']['bcc'])) { $ret['email_bcopy_to'] = $EMAIL_TEMPLATE['signup']['bcc']; }
if (vartrue($userInfo['email_attach'])) { $ret['email_attach'] = $userInfo['mail_attach']; }
elseif (vartrue($SIGNUPEMAIL_ATTACHMENTS)) { $ret['email_attach'] = $SIGNUPEMAIL_ATTACHMENTS; }
elseif (vartrue($EMAIL_TEMPLATE['signup']['attachments'])) { $ret['email_attach'] = $EMAIL_TEMPLATE['signup']['attachments']; }
$style = vartrue($SIGNUPEMAIL_LINKSTYLE) ? "style='{$SIGNUPEMAIL_LINKSTYLE}'" : "";
@ -1164,7 +1207,7 @@ class e_system_user extends e_user_model
$replace[5] = $userInfo['user_name'];
$search[6] = '{USERURL}';
$replace[6] = varsettrue($userInfo['user_website']) ? $userInfo['user_website'] : "";
$replace[6] = vartrue($userInfo['user_website']) ? $userInfo['user_website'] : "";
$search[7] = '{DISPLAYNAME}';
$replace[7] = $userInfo['user_login'] ? $userInfo['user_login'] : $userInfo['user_name'];
@ -1175,32 +1218,50 @@ class e_system_user extends e_user_model
$search[9] = '{ACTIVATION_URL}';
$replace[9] = $userInfo['activation_url'];
$subject = str_replace($search, $replace, $SIGNUPEMAIL_SUBJECT);
$subject = str_replace($search, $replace, $EMAIL_TEMPLATE['signup']['subject']);
$ret['email_subject'] = $subject;
$ret['send_html'] = TRUE;
$HEAD = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
$HEAD .= "<html xmlns='http://www.w3.org/1999/xhtml' >\n";
$HEAD .= "<head><meta http-equiv='content-type' content='text/html; charset=utf-8' />\n";
$HEAD .= ($SIGNUPEMAIL_USETHEME == 1) ? "<link rel=\"stylesheet\" href=\"".SITEURLBASE.THEME_ABS."style.css\" type=\"text/css\" />\n" : "";
$HEAD .= "<title>".LAN_SIGNUP_58."</title>\n";
if($SIGNUPEMAIL_USETHEME == 2)
if(!varset($EMAIL_TEMPLATE['signup']['header']))
{
$CSS = file_get_contents(THEME."style.css");
$HEAD .= "<style>\n".$CSS."\n</style>";
}
$HEAD .= "</head>\n";
if(vartrue($SIGNUPEMAIL_BACKGROUNDIMAGE))
{
$HEAD .= "<body background=\"".$SIGNUPEMAIL_BACKGROUNDIMAGE."\" >\n";
$HEAD = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
$HEAD .= "<html xmlns='http://www.w3.org/1999/xhtml' >\n";
$HEAD .= "<head><meta http-equiv='content-type' content='text/html; charset=utf-8' />\n";
$HEAD .= ($SIGNUPEMAIL_USETHEME == 1) ? "<link rel=\"stylesheet\" href=\"".SITEURLBASE.THEME_ABS."style.css\" type=\"text/css\" />\n" : "";
$HEAD .= "<title>".LAN_SIGNUP_58."</title>\n";
if($SIGNUPEMAIL_USETHEME == 2) // @deprecated in favor of {STYLESHEET}
{
$CSS = file_get_contents(THEME."style.css");
$HEAD .= "<style>\n".$CSS."\n</style>";
}
$HEAD .= "</head>\n";
if(vartrue($SIGNUPEMAIL_BACKGROUNDIMAGE)) // @deprecated.
{
$HEAD .= "<body background=\"".$SIGNUPEMAIL_BACKGROUNDIMAGE."\" >\n";
}
else
{
$HEAD .= "<body>\n";
}
}
else
{
$HEAD .= "<body>\n";
$HEAD = $tp->parseTemplate($EMAIL_TEMPLATE['signup']['header'], true);
}
if(!varset($EMAIL_TEMPLATE['signup']['footer']))
{
$FOOT = "\n</body>\n</html>\n";
}
else
{
$FOOT = $tp->parseTemplate($EMAIL_TEMPLATE['signup']['footer'], true);
}
$FOOT = "\n</body>\n</html>\n";
$ret['send_html'] = TRUE;
$ret['email_body'] = e107::getParser()->parseTemplate(str_replace($search,$replace,$HEAD.$template.$FOOT), true);