diff --git a/e107_files/bbcode/file.bb b/e107_files/bbcode/file.bb
index c5901b49d..90f136027 100644
--- a/e107_files/bbcode/file.bb
+++ b/e107_files/bbcode/file.bb
@@ -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 " ".$code_text."";
}
diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php
index 0decf05ca..254804545 100644
--- a/e107_handlers/e107_class.php
+++ b/e107_handlers/e107_class.php
@@ -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}";
diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php
index 0d7b645b1..7368178dc 100644
--- a/e107_handlers/e_parse_class.php
+++ b/e107_handlers/e_parse_class.php
@@ -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),
diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php
index 26f8546ca..b5859f411 100644
--- a/e107_handlers/mail.php
+++ b/e107_handlers/mail.php
@@ -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}
";
+ $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}
";
+ 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
";
+ }
+ }
+ }
+ }
+ $this->IsHTML(true);
+ $this->Body = $message;
+ // print_a($message);
+ $textMsg = str_replace(array('
', '
'), "\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
diff --git a/e107_handlers/mail_manager_class.php b/e107_handlers/mail_manager_class.php
index 4c076b9e5..801c54fb2 100644
--- a/e107_handlers/mail_manager_class.php
+++ b/e107_handlers/mail_manager_class.php
@@ -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}
";
// 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 = "\n";
$mail_head .= "\n";
@@ -1139,17 +1147,30 @@ class e107MailManager
if ($format == 'texttheme')
{
$message_body .= "