diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php
index fb6513a87..4335282f6 100644
--- a/e107_handlers/mail.php
+++ b/e107_handlers/mail.php
@@ -9,9 +9,9 @@
* e107 Main
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/mail.php,v $
- * $Revision: 1.18 $
- * $Date: 2009-11-19 10:07:32 $
- * $Author: e107coders $
+ * $Revision: 1.19 $
+ * $Date: 2009-11-19 20:24:21 $
+ * $Author: e107steved $
*/
/*
@@ -155,6 +155,7 @@ class e107Email extends PHPMailer
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
/**
* Constructor sets up all the global options, and sensible defaults - it should be the only place the prefs are accessed
@@ -450,11 +451,21 @@ class e107Email extends PHPMailer
$message = "\n
\n".$message;
}
+ 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
+ $message = htmlspecialchars($message);
+ $message = preg_replace('%(http|ftp|https)(://\S+)%', '\1\2', $message);
+ $message = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '\\1\\2', $message);
+ $message = preg_replace('/([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})/i', '\\1', $message);
+ $message = str_replace("\r\n","\n",$message); // Handle alternative newline characters
+ $message = str_replace("\n\r","\n",$message); // Handle alternative newline characters
+ $message = str_replace("\r","\n",$message); // Handle alternative newline characters
+ $message = str_replace("\n", "
\n", $message);
+ }
$this->MsgHTML($message); // Theoretically this should do everything, including handling of inline images.
}
else
- {
- // generate the plain text part
+ { // generate the plain text as the sole part of the email
if (defined('MAIL_DEBUG')) echo "Generating plain text email
";
if (strpos($message,'') !== FALSE)
{
@@ -471,75 +482,10 @@ class e107Email extends PHPMailer
// TODO: strip bbcodes here
$this->Body = $text;
+ $this->AltBody = ''; // Single part email
}
}
-
- // Legacy way of creating an HTML and a text part - as used in 0.7
- // $want_HTML= 1 uses default setting for HTML part. Set TRUE to enable, FALSE to disable
- function makeBodyLegacy($message,$want_HTML = 1, $add_HTML_header = FALSE)
- {
- switch (varset($this->general_opts['textonly'],'off'))
- {
- case 'pref' : // Disable HTML as default
- if ($want_HTML == 1) $want_HTML = FALSE;
- break;
- case 'force' : // Always disable HTML
- $want_HTML = FALSE;
- break;
- }
-
- if ($want_HTML)
- {
- if (preg_match('/<(font|br|a|img|b)/i', $message))
- {
- $Html = $message; // Assume html if it includes one of these tags
- }
- else
- {
- $Html = htmlspecialchars($message);
- $Html = preg_replace('%(http|ftp|https)(://\S+)%', '\1\2', $Html);
- $Html = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '\\1\\2', $Html);
- $Html = preg_replace('/([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})/i', '\\1', $Html);
- $Html = str_replace("\r\n","\n",$Html); // Handle alternative newline characters
- $Html = str_replace("\n\r","\n",$Html); // Handle alternative newline characters
- $Html = str_replace("\r","\n",$Html); // Handle alternative newline characters
- $Html = str_replace("\n", "
\n", $Html);
- }
- if ($add_HTML_header)
- {
- $this->Body = "\n
- \n".$Html;
- }
- else
- {
- $this->Body = $Html;
- }
- }
-
- // Now generate the plain text part - always have one
- if (strpos($message,"") !== FALSE)
- {
- $text = strstr($message,"");
- }
- else
- {
- $text = $message;
- }
-
- $text = str_replace("
", "\n", $text);
- $text = strip_tags(str_replace("
", "\n", $text));
-
- if ($want_HTML)
- {
- $this->AltBody = $text;
- $this->IsHTML = TRUE;
- }
- else
- {
- $this->Body = $text;
- }
- }
// Add attachments - either a single one as a string, or an array
@@ -859,8 +805,8 @@ function sendemail($send_to, $subject, $message, $to_name, $send_from='', $from_
if (varsettrue($mailheader_e107id)) $mail->AddCustomHeader("X-e107-id: {$mailheader_e107id}");
- //Legacy required - \n must be converted to
in HTML version of email.
- $mail->makeBodyLegacy($message); // Add body, with conversion if required
+ $mail->legacyBody = TRUE; // Need to handle plain text email conversion to HTML
+ $mail->makeBody($message); // Add body, with conversion if required
if($Cc) $mail->AddAddressList('cc', $Cc);
diff --git a/e107_handlers/mail_manager_class.php b/e107_handlers/mail_manager_class.php
index efb749873..2d6707395 100644
--- a/e107_handlers/mail_manager_class.php
+++ b/e107_handlers/mail_manager_class.php
@@ -9,9 +9,9 @@
* e107 Main
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/mail_manager_class.php,v $
- * $Revision: 1.4 $
- * $Date: 2009-11-18 01:04:43 $
- * $Author: e107coders $
+ * $Revision: 1.5 $
+ * $Date: 2009-11-19 20:24:21 $
+ * $Author: e107steved $
*/
/*
@@ -78,6 +78,7 @@ if (!defined('e107_INIT')) { exit; }
define('MAIL_STATUS_SENT', 0); // Mail sent. Email handler happy, but may have bounced (or may be yet to bounce)
define('MAIL_STATUS_BOUNCED', 1);
define('MAIL_STATUS_CANCELLED', 2);
+define('MAIL_STATUS_PARTIAL', 3); // A run which was abandoned - errors, out of time etc
define('MAIL_STATUS_FAILED', 5); // Failure on initial send - rejected by selected email handler
// This must be the numerically highest 'processing complete' code
define('MAIL_STATUS_PENDING', 10); // Mail which is in the sending list (even if outside valid sending window)
@@ -750,7 +751,7 @@ class e107MailManager
/**
* Delete an email from the DB, including (potential) recipients
* @param $mailID - number for email (assumed to be integral)
- * @param $actions - allows selection of whic DB to delete from
+ * @param $actions - allows selection of which DB to delete from
*
* @return FALSE on code error. Array of results on success.
*/
diff --git a/e107_handlers/mailout_admin_class.php b/e107_handlers/mailout_admin_class.php
index e4de1589b..fc84f1c90 100644
--- a/e107_handlers/mailout_admin_class.php
+++ b/e107_handlers/mailout_admin_class.php
@@ -9,9 +9,9 @@
* Administration - Site Maintenance
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/mailout_admin_class.php,v $
- * $Revision: 1.4 $
- * $Date: 2009-11-18 01:04:43 $
- * $Author: e107coders $
+ * $Revision: 1.5 $
+ * $Date: 2009-11-19 20:24:21 $
+ * $Author: e107steved $
*
*/
@@ -338,6 +338,8 @@ class mailoutAdminClass extends e107MailManager
return LAN_MAILOUT_213;
case MAIL_STATUS_CANCELLED :
return LAN_MAILOUT_218;
+ case MAIL_STATUS_PARTIAL :
+ return LAN_MAILOUT_219;
case MAIL_STATUS_FAILED :
return LAN_MAILOUT_212;
case MAIL_STATUS_PENDING :
diff --git a/e107_handlers/news_class.php b/e107_handlers/news_class.php
index b9f400394..f95e2fe6d 100644
--- a/e107_handlers/news_class.php
+++ b/e107_handlers/news_class.php
@@ -9,9 +9,9 @@
* News handler
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/news_class.php,v $
- * $Revision: 1.28 $
- * $Date: 2009-11-18 01:04:43 $
- * $Author: e107coders $
+ * $Revision: 1.29 $
+ * $Date: 2009-11-19 20:24:21 $
+ * $Author: e107steved $
*/
if (!defined('e107_INIT')) { exit; }
@@ -113,8 +113,13 @@ class news {
$data['error'] = true;
return $data;
}
-
- //XXX - Now hooks are executed only if no mysql error is found. Should it stay so?
+
+ // Calculate short strings for admin logging - no need to clog up the log with potentially long items
+ $logData = $data['data'];
+ if (isset($logData['news_body'])) $logData['news_body'] = $tp->text_truncate($tp->toDB($logData['news_body']),300,'...');
+ if (isset($logData['news_extended'])) $logData['news_extended'] = $tp->text_truncate($tp->toDB($logData['news_extended']),300,'...');
+
+ //XXX - Now hooks are executed only if no mysql error is found. Should it stay so? Seems sensible to me!
if ($news['news_id'])
{
// Updating existing item
@@ -123,8 +128,8 @@ class news {
//$vals = "news_datestamp = '".intval($news['news_datestamp'])."', ".$author_insert." news_title='".$news['news_title']."', news_body='".$news['news_body']."', news_extended='".$news['news_extended']."', news_category='".intval($news['cat_id'])."', news_allow_comments='".intval($news['news_allow_comments'])."', news_start='".intval($news['news_start'])."', news_end='".intval($news['news_end'])."', news_class='".$tp->toDB($news['news_class'])."', news_render_type='".intval($news['news_rendertype'])."' , news_summary='".$news['news_summary']."', news_thumbnail='".$tp->toDB($news['news_thumbnail'])."', news_sticky='".intval($news['news_sticky'])."' WHERE news_id='".intval($news['news_id'])."' ";
if ($sql->db_Update('news', $data))
{
- e107::getAdminLog()->logArrayAll('NEWS_09', $data['data']);
-
+ e107::getAdminLog()->logArrayAll('NEWS_09', $logData);
+
//manage rewrites
$data['data']['news_id'] = $news['news_id'];
if('error' === $this->handleRewriteSubmit('update', $data['data'], $datarw, $smessages))
@@ -185,13 +190,13 @@ class news {
//$news['news_id'] = $sql ->db_Insert('news', "0, '".$news['news_title']."', '".$news['news_body']."', '".$news['news_extended']."', ".intval($news['news_datestamp']).", ".intval($news['news_author']).", '".intval($news['cat_id'])."', '".intval($news['news_allow_comments'])."', '".intval($news['news_start'])."', '".intval($news['news_end'])."', '".$tp->toDB($news['news_class'])."', '".intval($news['news_rendertype'])."', '0' , '".$news['news_summary']."', '".$tp->toDB($news['news_thumbnail'])."', '".intval($news['news_sticky'])."' ")
if ($data['data']['news_id'])
{
- //
+ $data['news_id'] = $news['news_id'];
$message = LAN_NEWS_6;
$emessage->add(LAN_NEWS_6, E_MESSAGE_SUCCESS, $smessages);
e107::getCache()->clear('news.php');
//moved down - prevent wrong mysql_insert_id
- e107::getAdminLog()->logArrayAll('NEWS_08', $data['data']);
+ e107::getAdminLog()->logArrayAll('NEWS_08', $logData);
//manage rewrites
if('error' === $this->handleRewriteSubmit('insert', $data['data'], $datarw, $smessages))
@@ -201,7 +206,7 @@ class news {
e107::getEvent()->trigger('newspost', $data['data']);
- //XXX - triggetHook after trigger?
+ //XXX - triggerHook after trigger?
$evdata = array('method'=>'create', 'table'=>'news', 'id'=>$data['data']['news_id'], 'plugin'=>'news', 'function'=>'submit_item');
$emessage->add($e_event->triggerHook($evdata), E_MESSAGE_INFO, $smessages);
}
diff --git a/e107_handlers/notify_class.php b/e107_handlers/notify_class.php
index 6b091e954..cf5d5505a 100644
--- a/e107_handlers/notify_class.php
+++ b/e107_handlers/notify_class.php
@@ -9,9 +9,9 @@
* Forum plugin notify configuration
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/notify_class.php,v $
-* $Revision: 1.8 $
-* $Date: 2009-11-18 01:04:43 $
-* $Author: e107coders $
+* $Revision: 1.9 $
+* $Date: 2009-11-19 20:24:21 $
+* $Author: e107steved $
*
*/
@@ -40,42 +40,129 @@ class notify
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_notify.php');
}
+
+
+ /**
+ * Send an email notification following an event.
+ *
+ * For up to a (hard-coded) number of recipients, the mail is sent immediately.
+ * Otherwise its added to the queue
+ *
+ * @param string $id - identifies event actions
+ * @param string $subject - subject for email
+ * @param string $message - email message body
+ * @return none
+ */
+ // TODO: handle 'everyone except' clauses (email address filter done)
function send($id, $subject, $message)
{
- global $sql, $tp;
- e107_require_once(e_HANDLER.'mail.php');
- $subject = SITENAME.': '.$subject;
- if ($this->notify_prefs['event'][$id]['class'] == e_UC_MAINADMIN)
+ $e107 = e107::getInstance();
+
+ $subject = $e107->tp->toEmail(SITENAME.': '.$subject);
+ $message = $e107->tp->toEmail($message);
+ $emailFilter = '';
+ $notifyTarget = $this->notify_prefs['event'][$id]['class'];
+ if ($notifyTarget == '-email')
{
- sendemail(SITEADMINEMAIL, $tp->toEmail($subject), $tp->toEmail($message));
+ $emailFilter = $this->notify_prefs['event'][$id]['email'];
}
- elseif (is_numeric($this -> notify_prefs['event'][$id]['class']))
+ if (is_numeric($this -> notify_prefs['event'][$id]['class']))
{
- if ($this->notify_prefs['event'][$id]['class'] == e_UC_ADMIN)
+ switch ($notifyTarget)
{
- $sql->db_Select('user', 'user_email', "user_admin = 1 AND user_ban = 0");
+ case e_UC_MAINADMIN :
+ $qry = "`user_admin` = 1 AND `user_perms` = '0' AND `user_ban` = 0";
+ break;
+ case e_UC_ADMIN :
+ $qry = "`user_admin` = 1 AND `user_ban` = 0";
+ break;
+ case e_UC_MEMBER :
+ $qry = "`user_ban` = 0";
+ break;
+ default :
+ $qry = "user_ban = 0 AND user_class REGEXP '(^|,)(".$this->notify_prefs['event'][$id]['class'].")(,|$)'";
+ break;
}
- elseif ($this->notify_prefs['event'][$id]['class'] == e_UC_MEMBER)
+ $qry = 'SELECT user_id,user_name,user_email FROM `#user` WHERE '.$qry;
+ if (FALSE !== ($count = $e107->sql->db_Select_gen($qry)))
{
- $sql->db_Select('user', 'user_email', 'user_ban = 0');
- }
- else
- {
- $sql->db_Select('user', 'user_email', "user_ban = 0 AND user_class REGEXP '(^|,)(".$this->notify_prefs['event'][$id]['class'].")(,|$)'");
- }
- while ($email = $sql->db_Fetch())
- {
- sendemail($email['user_email'], $tp->toEmail($subject), $tp->toEmail($message));
+ if ($count <= 5)
+ { // Arbitrary number below which we send emails immediately
+ e107_require_once(e_HANDLER.'mail.php');
+ while ($email = $e107->sql->db_Fetch())
+ {
+ if ($email['user_email'] != $emailFilter)
+ {
+ sendemail($email['user_email'], $subject, $message, $email['user_name']);
+ }
+ }
+ }
+ else
+ { // Otherwise add to mailout queue
+ require(e_HANDLER.'mail_manager_class.php');
+ $mailer = new e107MailManager;
+
+
+ // Start by creating the mail body
+ $mailData = array(
+ 'mail_content_status' => MAIL_STATUS_TEMP,
+ 'mail_create_app' => 'notify',
+ 'mail_title' => 'NOTIFY',
+ 'mail_subject' => $subject,
+ 'mail_sender_email' => $pref['siteadminemail'],
+ 'mail_sender_name' => $pref['siteadmin'],
+ 'mail_send_style' => 'textonly',
+ 'mail_body' => $message
+ );
+ $result = $mailer->saveEmail($mailData, TRUE);
+ if (is_numeric($result))
+ {
+ $mailMainID = $mailData['mail_source_id'] = $result;
+ }
+ else
+ {
+ // TODO: Handle error
+ return; // Probably nothing else we can do
+ }
+ $mailer->mailInitCounters($mailMainID); // Initialise counters for emails added
+
+ // Now add email addresses to the list
+ while ($row = $e107->sql->db_Fetch(MYSQL_ASSOC))
+ {
+ if ($row['user_email'] != $emailFilter)
+ {
+ $uTarget = array('mail_recipient_id' => $row['user_id'],
+ 'mail_recipient_name' => $row['user_name'], // Should this use realname?
+ 'mail_recipient_email' => $row['user_email']
+ );
+ $result = $mailer->mailAddNoDup($mailMainID, $uTarget, MAIL_STATUS_TEMP);
+ }
+ }
+ $mailer->mailUpdateCounters($mailMainID); // Update the counters
+ $counters = $mailer->mailRetrieveCounters($mailMainID); // Retrieve the counters
+ if ($counters['add'] == 0)
+ {
+ $mailer->deleteEmail($mailMainID); // Probably a fault, but precautionary - delete email
+ }
+ else
+ {
+ $mailer->activateEmail($mailMainID, FALSE); // Actually mark the email for sending
+ }
+ }
+ $e107->admin_log->e_log_event(10,-1,'NOTIFY',$subject,$message,FALSE,LOG_TO_ROLLING);
}
}
- elseif ($this->notify_prefs['event'][$id]['class'] == 'email')
- {
- sendemail($this->notify_prefs['event'][$id]['email'], $tp->toEmail($subject), $tp->toEmail($message));
+ elseif ($notifyTarget == 'email')
+ { // Single email address - that can always go immediately
+ e107_require_once(e_HANDLER.'mail.php');
+ sendemail($this->notify_prefs['event'][$id]['email'], $subject, $message);
}
}
}
+
+
//DEPRECATED, BC, call the method only when needed, $e107->notify caught by __get()
global $nt;
$nt = e107::getNotify(); //TODO - find & replace $nt, $e107->notify
@@ -145,16 +232,20 @@ function notify_subnews($data)
function notify_newspost($data)
{
- global $nt;
- $message = ''.$data['news_title'].'
'.$data['news_summary'].'
'.$data['data'].'
'.$data['news_extended'];
- $nt->send('newspost', $data['news_title'], $message);
+ $message = ''.$data['news_title'].'';
+ if (vartrue($data['news_summary'])) $message .= '
'.$data['news_summary'];
+ if (vartrue($data['news_body'])) $message .= '
'.$data['news_body'];
+ if (vartrue($data['news_extended'])) $message.= '
'.$data['news_extended'];
+ e107::getNotify()->send('newspost', $data['news_title'], e107::getParser()->text_truncate(e107::getParser()->toDB($message), 400, '...'));
}
function notify_newsupd($data)
{
- global $nt;
- $message = ''.$data['news_title'].'
'.$data['news_summary'].'
'.$data['data'].'
'.$data['news_extended'];
- $nt->send('newsupd', NT_LAN_NU_1.': '.$data['news_title'], $message);
+ $message = ''.$data['news_title'].'';
+ if (vartrue($data['news_summary'])) $message .= '
'.$data['news_summary'];
+ if (vartrue($data['news_body'])) $message .= '
'.$data['news_body'];
+ if (vartrue($data['news_extended'])) $message.= '
'.$data['news_extended'];
+ e107::getNotify()->send('newsupd', NT_LAN_NU_1.': '.$data['news_title'], e107::getParser()->text_truncate(e107::getParser()->toDB($message), 400, '...'));
}
function notify_newsdel($data)
diff --git a/e107_languages/English/admin/lan_mailout.php b/e107_languages/English/admin/lan_mailout.php
index 849b16f73..5c9abb6c4 100644
--- a/e107_languages/English/admin/lan_mailout.php
+++ b/e107_languages/English/admin/lan_mailout.php
@@ -9,9 +9,9 @@
* Administration - Site Maintenance
*
* $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_mailout.php,v $
- * $Revision: 1.9 $
- * $Date: 2009-11-18 01:05:12 $
- * $Author: e107coders $
+ * $Revision: 1.10 $
+ * $Date: 2009-11-19 20:24:21 $
+ * $Author: e107steved $
*
*/
define('LAN_MAILOUT_01','From Name');
@@ -235,7 +235,7 @@ define('LAN_MAILOUT_215', 'Saved');
define('LAN_MAILOUT_216', 'Code error');
define('LAN_MAILOUT_217', 'Held');
define('LAN_MAILOUT_218', 'Cancelled');
-define('LAN_MAILOUT_219', '');
+define('LAN_MAILOUT_219', 'Partial');
// General messages continued
define('LAN_MAILOUT_220', 'Email ID --ID-- cancelled');
diff --git a/e107_plugins/newsletter/admin_config.php b/e107_plugins/newsletter/admin_config.php
index 43a84f73f..3c2a46611 100644
--- a/e107_plugins/newsletter/admin_config.php
+++ b/e107_plugins/newsletter/admin_config.php
@@ -6,26 +6,28 @@
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
- *
+ * Administration - Site Maintenance
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/newsletter/admin_config.php,v $
- * $Revision: 1.11 $
- * $Date: 2009-11-18 01:05:53 $
- * $Author: e107coders $
- */
-
+ * $Revision: 1.12 $
+ * $Date: 2009-11-19 20:24:21 $
+ * $Author: e107steved $
+ *
+*/
require_once('../../class2.php');
-if (!getperms("P"))
+if (!getperms('P'))
{
header('location:'.e_BASE.'index.php');
exit;
}
$e_sub_cat = 'newsletter';
-require_once(e_ADMIN."auth.php");
+require_once(e_ADMIN.'auth.php');
+// Include ren_help for display_help (while showing BBcodes)
+require_once(e_HANDLER.'ren_help.php');
if (e_QUERY)
{
- list($action, $id, $key) = explode(".", e_QUERY);
+ list($action, $id, $key) = explode('.', e_QUERY);
$key = intval($key);
$id = intval($id);
}
@@ -46,7 +48,7 @@ else
{
switch ($action)
{
- case 'vs' : // View subscribers of a newsletter
+ case 'vs' : // View subscribers of a newsletter
$nl -> view_subscribers($id);
break;
case 'remove' : // Remove subscriber
@@ -54,10 +56,10 @@ else
$nl -> view_subscribers($id);
break;
default:
- $function = $action."Newsletter";
+ $function = $action.'Newsletter';
if (method_exists($nl, $function))
{
- $nl -> $function();
+ $nl -> $function($id);
}
else
{
@@ -67,20 +69,19 @@ else
}
-
class newsletter
{
+ protected $e107;
var $message;
-
- function newsletter()
+ public function __construct()
{
- global $ns, $tp;
+ $this->e107 = e107::getInstance();
foreach($_POST as $key => $value)
{
- $key = $tp->toDB($key);
- if(strstr($key, "nlmailnow"))
+ $key = $this->e107->tp->toDB($key);
+ if(strpos($key, 'nlmailnow') === 0)
{
$this->releaseIssue($key);
break;
@@ -104,16 +105,15 @@ class newsletter
if($this -> message)
{
- $ns->tablerender("", "