1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

Mailer next update - inline files should work

This commit is contained in:
e107steved
2009-11-17 20:34:50 +00:00
parent 3e55ad2dad
commit 52faad8c2e
9 changed files with 147 additions and 51 deletions

View File

@@ -15,22 +15,25 @@ if ((e_PAGE == 'page.php') || (array_key_exists('forum_attach', $pref) && $pref[
if(is_readable(THEME.'images/'.$ext.'.png'))
{
$image = THEME.'images/'.$ext.'.png';
$image = THEME_ABS.'images/'.$ext.'.png';
}
elseif(is_readable(e_IMAGE.'/generic/'.$ext.'.png'))
{
$image = e_IMAGE.'generic/'.$ext.'.png';
$image = e_IMAGE_ABS.'generic/'.$ext.'.png';
}
elseif(is_readable(THEME.'images/file.png'))
{
$image = THEME.'images/file.png';
$image = THEME_ABS.'images/file.png';
}
else
{
$image = e_IMAGE.'generic/lite/file.png';
$image = e_IMAGE_ABS.'generic/lite/file.png';
}
if (strpos($fname, '{e_BASE}') === 0)
{
$fname = str_replace('{e_BASE}', SITEURL, $fname); // Translate into an absolute URL
}
return "<a href='".$tp -> toAttribute($fname)."'><img src='".$image."' alt='' style='border:0; vertical-align:middle' /></a> <a href='".$tp -> toAttribute($fname)."'>".$code_text."</a>";
}

View File

@@ -9,9 +9,9 @@
* e107 Main
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/e107_class.php,v $
* $Revision: 1.71 $
* $Date: 2009-11-17 09:17:08 $
* $Author: marj_nl_fr $
* $Revision: 1.72 $
* $Date: 2009-11-17 20:34:50 $
* $Author: e107steved $
*/
if (!defined('e107_INIT')) { exit; }
@@ -1189,7 +1189,8 @@ class e107
}
// Absolute file-path of directory containing class2.php
define("e_ROOT", realpath(dirname(__FILE__)."/../")."/");
// define("e_ROOT", realpath(dirname(__FILE__)."/../")."/");
define("e_ROOT", realpath(dirname(__FILE__)."/../")); // Specified format gives trailing slash already (at least on Windows)
$this->relative_base_path = (!isset($_E107['cli'])) ? $path : e_ROOT;
$this->http_path = "http://{$_SERVER['HTTP_HOST']}{$this->server_path}";

View File

@@ -9,9 +9,9 @@
* Text processing and parsing functions
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $
* $Revision: 1.83 $
* $Date: 2009-11-17 11:00:40 $
* $Author: marj_nl_fr $
* $Revision: 1.84 $
* $Date: 2009-11-17 20:34:50 $
* $Author: e107steved $
*
*/
if (!defined('e107_INIT')) { exit(); }
@@ -189,6 +189,8 @@ class e_parse
'consts_rel' => array('constants' => 'rel'),
// Absolute path replacement
'consts_abs' => array('constants' => 'abs'),
// Full path replacement
'consts_full' => array('constants' => 'full'),
// No shortcode parsing
'scparse_off' => array('parse_sc' => FALSE),

View File

@@ -9,8 +9,8 @@
* e107 Main
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/mail.php,v $
* $Revision: 1.15 $
* $Date: 2009-11-16 20:40:39 $
* $Revision: 1.16 $
* $Date: 2009-11-17 20:34:50 $
* $Author: e107steved $
*/
@@ -553,7 +553,7 @@ class e107Email extends PHPMailer
$tempName = basename($attach);
if(is_readable($attach) && $tempName)
{ // First parameter is complete path + filename; second parameter is 'name' of file to send
$ext = substr(strrchr($attach, "."), 1);
$ext = pathinfo($attach, PATHINFO_EXTENSION);
$this->AddAttachment($attach, $tempName,'base64',$this->_mime_types($ext));
}
}
@@ -569,7 +569,7 @@ class e107Email extends PHPMailer
{
if(is_readable($inline_img) && !is_dir($inline_img))
{
$ext = substr(strrchr($inline_img, "."), 1);
$ext = pathinfo($inline_img, PATHINFO_EXTENSION);
$this->AddEmbeddedImage($inline_img, md5($inline_img), basename($inline_img),'base64',$this->_mime_types($ext));
}
}
@@ -729,7 +729,69 @@ class e107Email extends PHPMailer
$this->SendCount = 0;
}
}
}
/**
* Evaluates the message and returns modifications for inline images and backgrounds
* Also creates an alternative plain text part (unless $this->AltBody already non-empty)
* Modification of standard PHPMailer function (which it overrides)
* @access public
* @return $message
*/
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]))
{
foreach($images[3] as $i => $url)
{
// do not change urls for absolute images (thanks to corvuscorax)
if (!preg_match('#^[A-z]+://#',$url))
{
$delim = $images[2][$i]; // Will be single or double quote
$filename = basename($url);
$directory = dirname($url);
if ($directory == '.') $directory='';
if (strpos($directory, e_HTTP) === 0)
{
$directory = str_replace(e_HTTP, '', $directory);
$basedir = e_ROOT;
}
//echo "CID file {$filename} in {$directory}. Base = ".e_HTTP." BaseDir = {$basedir}<br />";
$cid = 'cid:' . md5($filename);
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$mimeType = self::_mime_types($ext);
if ( (strlen($basedir) > 1) && (substr($basedir,-1) != '/') && (substr($basedir,-1) != '\\')) { $basedir .= '/'; }
if ( strlen($directory) > 1 && substr($directory,-1) != '/' && substr($directory,-1) != '\\') { $directory .= '/'; }
//echo "Add image: {$basedir}|{$directory}|{$filename}<br />";
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);
}
else
{
echo "Add embedded image {$url} failed<br />";
}
}
}
}
$this->IsHTML(true);
$this->Body = $message;
// print_a($message);
$textMsg = str_replace(array('<br />', '<br>'), "\n", $message); // Modified to make sure newlines carried through
$textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$textMsg)));
if (!empty($textMsg) && empty($this->AltBody))
{
$this->AltBody = html_entity_decode($textMsg);
}
if (empty($this->AltBody))
{
$this->AltBody = 'To view this email message, enable HTML!' . "\n\n";
}
}
} // End of e107Mailer class

View File

@@ -9,8 +9,8 @@
* e107 Main
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/mail_manager_class.php,v $
* $Revision: 1.2 $
* $Date: 2009-11-16 20:40:39 $
* $Revision: 1.3 $
* $Date: 2009-11-17 20:34:50 $
* $Author: e107steved $
*/
@@ -30,8 +30,10 @@ will be included in preference to the current theme style.
TODO:
- Check handling of inline images
- optional notify flag
- Consider whether to extract links in text-only emails
- Better check on e107 ID - add encoded value
- makeEmailBody - could use regex to modify links
Database tables
@@ -161,7 +163,8 @@ class e107MailManager
'mail_bcopy_to' => 1,
'mail_attach' => 1,
'mail_send_style' => 1,
'mail_selectors' => 1 // Only used internally
'mail_selectors' => 1, // Only used internally
'mail_include_images' => 1 // Used to determine whether to embed images, or link to them
);
/**
@@ -350,8 +353,6 @@ class e107MailManager
* Given an array (row) of data retrieved from the DB table, converts to internal format.
* Combining/splitting of fields is done as necessary
* This version intended for 'Joined' reads which have both recipient and content data
* (This is essentially the translation between internal storage format and db storage format. If
* the DB format changes, only this routine and its counterpart should need changing)
*
* @param $data - array of DB-sourced target-related data
* @param $addMissing - if TRUE, undefined fields are added
@@ -359,11 +360,11 @@ class e107MailManager
* @return void
*/
public function dbToBoth(&$data, $addMissing = FALSE)
{ // Direct correspondence at present - but could change
{
$res = array();
$oneToOne = array_merge($this->dbTypes['mail_content'], $this->dbTypes['mail_recipients']);
$oneToOne = array_merge($this->dbTypes['mail_content'], $this->dbTypes['mail_recipients']); // List of valid elements
// Start with simpoe 'one to one' fields
// Start with simple 'one to one' fields
foreach ($oneToOne as $f => $v)
{
if (isset($data[$f]))
@@ -563,7 +564,7 @@ class e107MailManager
if (!$this->currentMailBody)
{
$this->currentMailBody = $this->makeEmailBody($email['mail_body'], $email['mail_send_style']);
$this->currentMailBody = $this->makeEmailBody($email['mail_body'], $email['mail_send_style'], varset($email['mail_include_images'], FALSE));
}
// Do any substitutions
$search = array();
@@ -581,7 +582,7 @@ class e107MailManager
{
$email['e107_header'] = intval($email['mail_source_id']).'/'.intval($email['mail_target_id']).'/'.md5($email['mail_source_id'].$email['mail_target_id'].$email['mail_recipient_email']); // Set up an ID
}
if (isset($email['mail_attach']))
if (isset($email['mail_attach']) && (trim($email['mail_attach']) || is_array($email['mail_attach'])))
{
$downDir = realpath(e_ROOT.$this->e107->getFolder('downloads'));
if (is_array($email['mail_attach']))
@@ -897,7 +898,9 @@ class e107MailManager
if ($firstTime > 0) $ft = ', `mail_send_date` = '.$firstTime;
$lt = ', `mail_end_send` = '.$lastTime;
}
$query = '`mail_content_status` = '.($hold ? MAIL_STATUS_HELD : MAIL_STATUS_PENDING).$lt.' WHERE `mail_source_id` = '.intval($handle);
$query = '';
if (!$hold) $query = '`mail_creator` = '.USERID.', `mail_create_date` = '.time().', '; // Update when we send - might be someone different
$query .= '`mail_content_status` = '.($hold ? MAIL_STATUS_HELD : MAIL_STATUS_PENDING).$lt.' WHERE `mail_source_id` = '.intval($handle);
// echo "Update mail body: {$query}<br />";
// Set status of email body first
if (!$this->db->db_Update('mail_content',$query))
@@ -1110,9 +1113,12 @@ class e107MailManager
* textonly - generate plain text email
* texthtml - HTML format email, no theme info
* texttheme - HTML format email, including current theme stylesheet etc
* @param boolean $incImages - valid only with HTML output;
* if true any 'absolute' format images are embedded in the source of the email.
* if FALSE, absolute links are converted to URLs on the local server
* @return string - updated body
*/
protected function makeEmailBody($text, $format = 'textonly')
protected function makeEmailBody($text, $format = 'textonly', $incImages = TRUE)
{
global $pref;
if ($format == 'textonly')
@@ -1121,6 +1127,8 @@ class e107MailManager
return stripslashes(strip_tags($temp)); // Have to do strip_tags() again in case bbcode added some
}
$consts = $incImages ? ',consts_abs' : 'consts_full'; // If inline images, absolute constants so we can change them
// HTML format email here
$mail_head = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
$mail_head .= "<html xmlns='http://www.w3.org/1999/xhtml' >\n";
@@ -1139,17 +1147,30 @@ class e107MailManager
if ($format == 'texttheme')
{
$message_body .= "<div style='padding:10px;width:97%'><div class='forumheader3'>\n";
$message_body .= $this->e107->tp->toEmail($text)."</div></div></body></html>";
//$message_body .= $this->e107->tp->toEmail($text)."</div></div></body></html>";
$message_body .= $this->e107->tp->toHTML($text, TRUE, 'E_BODY'.$consts)."</div></div></body></html>";
}
else
{
$message_body .= $this->e107->tp->toEmail($text)."</body></html>";
//$message_body .= $this->e107->tp->toEmail($text)."</body></html>";
$message_body .= $this->e107->tp->toHTML($text, TRUE, 'E_BODY'.$consts)."</body></html>";
$message_body = str_replace("&quot;", '"', $message_body);
}
$message_body = str_replace('<br />', "<br />\n", $message_body); // This gives a more readable alternate (plain text) part
$message_body = stripslashes($message_body);
return stripslashes($message_body);
if (!$incImages)
{
// Handle internally generated 'absolute' links - they need the full URL
$message_body = str_replace("src='".e_HTTP, "src='".SITEURL, $message_body);
$message_body = str_replace('src="'.e_HTTP, 'src="'.SITEURL, $message_body);
$message_body = str_replace("href='".e_HTTP, "src='".SITEURL, $message_body);
$message_body = str_replace('href="'.e_HTTP, 'src="'.SITEURL, $message_body);
}
// print_a($message_body);
return $message_body;
}
}

View File

@@ -9,8 +9,8 @@
* Administration - Site Maintenance
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/mailout_admin_class.php,v $
* $Revision: 1.2 $
* $Date: 2009-11-16 20:40:39 $
* $Revision: 1.3 $
* $Date: 2009-11-17 20:34:50 $
* $Author: e107steved $
*
*/
@@ -87,6 +87,7 @@ class mailoutAdminClass extends e107MailManager
'mail_attach' => array('title' => LAN_MAILOUT_153),
'mail_send_style' => array('title' => LAN_MAILOUT_154),
'mail_selectors' => array('title' => LAN_MAILOUT_155, 'proc' => 'selectors', 'nolist' => 'TRUE'),
'mail_include_images' => array('title' => LAN_MAILOUT_224, 'proc' => 'yesno'),
'options' => array('title' => LAN_OPTIONS, 'forced' => TRUE)
)
);
@@ -427,7 +428,7 @@ class mailoutAdminClass extends e107MailManager
if (in_array('core', $toLoad) || ($options == 'all'))
{
require_once(e_HANDLER.'mailout_class.php');
$this->mailHandlers[] = new mailout_core($this); // Start by loading the core mailout class
$this->mailHandlers[] = new core_mailout($this); // Start by loading the core mailout class
$ret++;
}
@@ -446,7 +447,7 @@ class mailoutAdminClass extends e107MailManager
require_once(e_PLUGIN.$mailer.'/e_mailout.php');
if (varset($mailerIncludeWithDefault,TRUE))
{ // Definitely need this plugin
$mailClass = 'mailout_'.$mailer;
$mailClass = $mailer.'_mailout';
$temp = new $mailClass;
if ($temp->mailerEnabled)
{
@@ -584,7 +585,8 @@ class mailoutAdminClass extends e107MailManager
'mail_copy_to' => $this->e107->tp->toDB($_POST['email_cc']),
'mail_bcopy_to' => $this->e107->tp->toDB($_POST['email_bcc']),
'mail_attach' => $this->e107->tp->toDB(trim($_POST['email_attachment'])),
'mail_send_style' => $this->e107->tp->toDB(varset($_POST['send_style'],'textonly'))
'mail_send_style' => $this->e107->tp->toDB(varset($_POST['send_style'],'textonly')),
'mail_include_images' => (isset($_POST['mail_include_images']) ? 1 : 0)
);
if (isset($_POST['mail_source_id']))
{
@@ -822,6 +824,8 @@ class mailoutAdminClass extends e107MailManager
<td >\n";
$text .= $this->sendStyleSelect($mailSource['mail_send_style']);
$checked = (isset($mailSource['mail_include_images']) && $mailSource['mail_include_images']) ? " checked='checked'" : '';
$text .= "&nbsp;&nbsp;<input type='checkbox' name='mail_include_images' value='1' {$checked} />".LAN_MAILOUT_225;
$text .="
</td></tr>\n
<tr>
@@ -1062,6 +1066,9 @@ class mailoutAdminClass extends e107MailManager
case 'selectors' :
$text .= 'cannot display';
break;
case 'yesno' :
$text .= $row[$fieldName] ? LAN_YES : LAN_NO;
break;
case 'default' :
default :
$text .= $row[$fieldName];

View File

@@ -9,8 +9,8 @@
* Administration - Site Maintenance
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/mailout_class.php,v $
* $Revision: 1.3 $
* $Date: 2009-11-15 17:38:04 $
* $Revision: 1.4 $
* $Date: 2009-11-17 20:34:50 $
* $Author: e107steved $
*
*/
@@ -22,7 +22,7 @@ if (!defined('e107_INIT')) { exit; }
Class for 'core' mailout function.
For plugins:
- the equivalent file must be called 'e_mailout.php', and reside in the root of the plugin directory.
- the classname must be 'mailout_'.$plugdir (e.g. 'mailout_calendar_menu')
- the classname must be $plugdir.'_mailout' (e.g. 'calendar_menu_mailout')
Additional mailout sources may replicate the functions of this class under a different name, or may use inheritance.
When managing bulk emails, class calls are made for each data handler.
@@ -43,7 +43,7 @@ TODO:
$mailerIncludeWithDefault = TRUE; // Mandatory - if false, show only when mailout for this specific plugin is enabled
$mailerExcludeDefault = TRUE; // Mandatory - if TRUE, when this plugin's mailout is active, the default (core) isn't loaded
class mailout_core
class core_mailout
{
protected $mailCount = 0;
protected $mailRead = 0;

View File

@@ -9,8 +9,8 @@
* Administration - Site Maintenance
*
* $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_mailout.php,v $
* $Revision: 1.7 $
* $Date: 2009-11-15 17:38:05 $
* $Revision: 1.8 $
* $Date: 2009-11-17 20:34:50 $
* $Author: e107steved $
*
*/
@@ -242,8 +242,8 @@ define('LAN_MAILOUT_220', 'Email ID --ID-- cancelled');
define('LAN_MAILOUT_221', 'Error cancelling email with ID --ID--');
define('LAN_MAILOUT_222', 'Default email format');
define('LAN_MAILOUT_223', '(Used for some non-bulk emails)');
define('LAN_MAILOUT_224', '');
define('LAN_MAILOUT_225', '');
define('LAN_MAILOUT_224', 'Inc. Images');
define('LAN_MAILOUT_225', 'Include images in email');
define('LAN_MAILOUT_226', '');
define('LAN_MAILOUT_227', '');
define('LAN_MAILOUT_228', '');

View File

@@ -9,9 +9,9 @@
* Administration - Site Maintenance
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/calendar_menu/e_mailout.php,v $
* $Revision: 1.3 $
* $Date: 2009-11-17 14:31:43 $
* $Author: marj_nl_fr $
* $Revision: 1.4 $
* $Date: 2009-11-17 20:34:50 $
* $Author: e107steved $
*
*/
@@ -30,7 +30,7 @@ Allows admins to send mail to those subscribed to calendar events
$mailerIncludeWithDefault = TRUE; // Mandatory - if false, show only when mailout for this specific plugin is enabled
$mailerExcludeDefault = FALSE; // Mandatory - if TRUE, when this plugin's mailout is active, the default (core) isn't loaded
class mailout_calendar_menu //FIXME <-- should be calendar_menu_mailout for consistency
class calendar_menu_mailout
{
protected $mailCount = 0;
protected $mailRead = 0;