From 84d7271d109133286915df102e303488b42c648b Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 11 Apr 2016 18:39:19 -0700 Subject: [PATCH] Merged core mailout routine into e107_plugins/user/e_mailout.php. Fixed pop3 error messages from phpmailer. Corrected email preview when no template selected. Corrected mailout Email source names. --- e107_admin/mailout.php | 22 +- e107_handlers/mail.php | 21 +- e107_handlers/mailout_admin_class.php | 14 +- e107_handlers/mailout_class.php | 12 +- e107_handlers/mysql_class.php | 3 +- e107_handlers/phpmailer/class.pop3.php | 6 +- e107_plugins/faqs/admin_config.php | 2 +- e107_plugins/user/e_mailout.php | 340 +++++++++++++++++++++++-- 8 files changed, 359 insertions(+), 61 deletions(-) diff --git a/e107_admin/mailout.php b/e107_admin/mailout.php index dbc329067..a03d93d94 100644 --- a/e107_admin/mailout.php +++ b/e107_admin/mailout.php @@ -81,7 +81,7 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_mailout.php'); require_once(e_HANDLER.'ren_help.php'); require_once(e_HANDLER.'userclass_class.php'); -require_once(e_HANDLER.'mailout_class.php'); // Class handler for core mailout functions +// require_once(e_HANDLER.'mailout_class.php'); // Class handler for core mailout functions require_once(e_HANDLER.'mailout_admin_class.php'); // Admin tasks handler require_once(e_HANDLER.'mail_manager_class.php'); // Mail DB API @@ -291,9 +291,9 @@ class mailout_main_ui extends e_admin_ui 'mail_source_id' => array('title' => LAN_MAILOUT_137, 'width' =>'5%', 'thclass' => 'center', 'class'=>'center', 'forced' => TRUE), 'mail_selectors' => array('title' => LAN_MAILOUT_03, 'type'=>'method', 'data'=>false, 'nolist' => true, 'writeParms'=>'nolabel=0'), - 'mail_title' => array('title' => LAN_TITLE, 'type'=>'text', 'forced' => TRUE, 'data'=>'str', 'inline'=>true, 'writeParms'=>'size=xxlarge&required=1', 'help'=>'whatever'), + 'mail_title' => array('title' => LAN_TITLE, 'type'=>'text', 'forced' => TRUE, 'data'=>'str', 'inline'=>true, 'writeParms'=>'size=xxlarge&required=1', 'help'=>''), 'mail_sender_name' => array('title' => LAN_MAILOUT_150, 'type'=>'method', 'data'=>false), - 'mail_sender_email' => array('title' => LAN_ID,'type'=>'method','data'=>false), + 'mail_sender_email' => array('title' => LAN_MAILOUT_149,'type'=>'method','data'=>false), 'mail_copy_to' => array('title' => LAN_MAILOUT_151,'tab'=>1, 'type'=>'method','data'=>false), 'mail_bcopy_to' => array('title' => LAN_MAILOUT_152,'tab'=>1, 'type'=>'method','data'=>false), 'mail_subject' => array('title' => LAN_MAILOUT_06, 'type'=>'text', 'forced' => TRUE,'data'=>'str', 'inline'=>true, 'writeParms'=>'size=xxlarge&required=1'), @@ -1063,15 +1063,16 @@ class mailout_main_ui extends e_admin_ui $mail_enable = explode(',',vartrue($pref['mailout_enabled'],'core')); $coreCheck = (in_array('core',$mail_enable)) ? "checked='checked'" : ""; - $text .= $frm->checkbox('mail_mailer_enabled[]','core', $coreCheck, 'users'); - + // $text .= $frm->checkbox('mail_mailer_enabled[]','core', $coreCheck, 'users'); + if(!empty($pref['e_mailout_list'])) { foreach ($pref['e_mailout_list'] as $mailer => $v) { + $addon = e107::getAddon($v,'e_mailout'); + $name = $addon->mailerName; $check = (in_array($mailer,$mail_enable)) ? "checked='checked'" : ""; - $text .= $frm->checkbox('mail_mailer_enabled[]',$mailer,$check,$mailer); - // $text .= "  {$mailer}
"; + $text .= $frm->checkbox('mail_mailer_enabled[]',$mailer,$check,$name); } } @@ -1398,6 +1399,12 @@ class mailout_main_ui extends e_admin_ui $temp['mailout_enabled'] = implode(',', varset($_POST['mail_mailer_enabled'], '')); $temp['mail_log_options'] = intval($_POST['mail_log_option']).','.intval($_POST['mail_log_email']); + + if(empty($temp['mailout_enabled'])) + { + $temp['mailout_enabled'] = 'user'; + } + foreach ($temp as &$t) { @@ -1434,6 +1441,7 @@ class mailout_admin_form_ui extends e_admin_form_ui break; case 'write': + return $this->getController()->mailAdmin->emailSelector('all', varset($data['mail_selectors'], FALSE)); break; diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index ca2077be0..6a4762fb0 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -697,9 +697,16 @@ class e107Email extends PHPMailer } } - + + + $text = $this->Body; - + + if($eml['template'] == 'textonly') + { + $text = strip_tags($text); + } + if(!empty($this->previewAttachments)) { $text .= "
Attachments:"; @@ -710,7 +717,12 @@ class e107Email extends PHPMailer $text .= ""; } } - + + if($eml['template'] == 'texthtml' || $eml['template'] == 'textonly' ) + { + $text = "".$text.""; + } + return $text; } @@ -1192,6 +1204,9 @@ class e107Email extends PHPMailer } + + + } // End of e107Mailer class diff --git a/e107_handlers/mailout_admin_class.php b/e107_handlers/mailout_admin_class.php index aa5faa995..f6d06480c 100644 --- a/e107_handlers/mailout_admin_class.php +++ b/e107_handlers/mailout_admin_class.php @@ -544,16 +544,18 @@ class mailoutAdminClass extends e107MailManager { $pref = e107::getPref(); + $pref['mailout_enabled'] = str_replace('core','user',$pref['mailout_enabled']); // BC fix. + $ret = 0; $toLoad = explode(',', $options); - $active_mailers = explode(',', varset($pref['mailout_enabled'], 'core')); + $active_mailers = explode(',', varset($pref['mailout_enabled'], 'user')); if((in_array('core', $toLoad) || ($options == 'all')) && in_array('core', $active_mailers)) { - require_once (e_HANDLER . 'mailout_class.php'); - $this->mailHandlers['core'] = new core_mailout; // Start by loading the core mailout class - $ret++; + // require_once (e_HANDLER . 'mailout_class.php'); + // $this->mailHandlers['core'] = new core_mailout; // Start by loading the core mailout class + // $ret++; } if(empty($pref['e_mailout_list'])) @@ -627,7 +629,7 @@ class mailoutAdminClass extends e107MailManager if(is_array($content)) { - $text = " + $text = "
@@ -638,7 +640,7 @@ class mailoutAdminClass extends e107MailManager { $text .= " - + "; } diff --git a/e107_handlers/mailout_class.php b/e107_handlers/mailout_class.php index ae204b1cc..18c34d0a7 100644 --- a/e107_handlers/mailout_class.php +++ b/e107_handlers/mailout_class.php @@ -8,20 +8,10 @@ * * Mailout handling - selector for 'core' users * - * $Source: /cvs_backup/e107_0.8/e107_handlers/mailout_class.php,v $ - * $Revision: 11315 $ - * $Date: 2010-02-10 18:18:01 +0000 (Wed, 10 Feb 2010) $ - * $Author: secretr $ + * */ -/** - * e107 Mail handling - core selector for users - * - * @package e107 - * @subpackage e107_handlers - * @version $Id: mailout_class.php 11315 2010-02-10 18:18:01Z secretr $; - */ if (!defined('e107_INIT')) { exit; } diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php index 3b41fcde7..80026a7bd 100644 --- a/e107_handlers/mysql_class.php +++ b/e107_handlers/mysql_class.php @@ -1309,8 +1309,7 @@ class e_db_mysql } - - e107::getMessage()->addDebug("MySQL Missing Field-Type: ".$type); + // e107::getMessage()->addDebug("MySQL Missing Field-Type: ".$type); return PDO::PARAM_STR; } diff --git a/e107_handlers/phpmailer/class.pop3.php b/e107_handlers/phpmailer/class.pop3.php index 63c818435..64dd11ca8 100644 --- a/e107_handlers/phpmailer/class.pop3.php +++ b/e107_handlers/phpmailer/class.pop3.php @@ -368,11 +368,11 @@ class POP3 { $this->errors[] = $error; if ($this->do_debug >= 1) { - echo '
';
+        //    echo '
';
             foreach ($this->errors as $error) {
-                print_r($error);
+         //       print_r($error);
             }
-            echo '
'; + // echo '
'; } } diff --git a/e107_plugins/faqs/admin_config.php b/e107_plugins/faqs/admin_config.php index 148fa0eec..c8cb9ddfe 100644 --- a/e107_plugins/faqs/admin_config.php +++ b/e107_plugins/faqs/admin_config.php @@ -317,7 +317,7 @@ class faq_main_ui extends e_admin_ui } - public function beforeCreate($new_data) + public function beforeCreate($new_data, $old_data) { // trim spaces if(!empty($new_data['faq_tags'])) diff --git a/e107_plugins/user/e_mailout.php b/e107_plugins/user/e_mailout.php index 5d4439e08..9553e321b 100644 --- a/e107_plugins/user/e_mailout.php +++ b/e107_plugins/user/e_mailout.php @@ -12,57 +12,49 @@ */ -/** - * e107 Newsletter plugin - * - * @package e107_plugins - * @subpackage newsletter - * @version $Id$; - */ if (!defined('e107_INIT')) { exit; } - /* -Class for newsletter mailout function +Class for user mailout function Allows admins to send mail to those subscribed to one or more newsletters */ // These variables determine the circumstances under which this class is loaded (only used during loading, and may be overwritten later) - $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 + $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 user_mailout { -// protected $mailCount = 0; -// protected $mailRead = 0; - //public $mailerSource = 'newsletter'; // Plugin name (core mailer is special case) Must be directory for this file - public $mailerName = LAN_PLUGIN_NEWSLETTER_NAME; // Text to identify the source of selector (displayed on left of admin page) - public $mailerEnabled = TRUE; // Mandatory - set to FALSE to disable this plugin (e.g. due to permissions restrictions) -// private $selectorActive = FALSE; // Set TRUE if we've got a valid selector to start returning entries -// private $targets = array(); // Used to store potential recipients -// private $ourDB; + public $mailerSource = 'user'; // Plugin name (core mailer is special case) Must be directory for this file + public $mailerName = LAN_MAILOUT_68; // Text to identify the source of selector (displayed on left of admin page) + public $mailerEnabled = true; // Mandatory - set to FALSE to disable this plugin (e.g. due to permissions restrictions) + + protected $mailCount = 0; + protected $mailRead = 0; + + // List of fields used by selectors + private $selectFields = array('email_to', + 'extended_1_name','extended_1_value', + 'extended_2_name', 'extended_2_value', + 'user_search_name', 'user_search_value', + 'last_visit_match', 'last_visit_date' + ); - // Constructor - public function __construct() - { - // BAD FOR PERFORMANCE - //$this->e107 = e107::getInstance(); - //$this->adminHandler = e107::getRegistry('_mailout_admin'); // Get the mailer admin object - we want to use some of its functions - } - /** * Manage Bounces. */ public function bounce($data) { - e107::getLog()->add('Newsletter Bounce', $data, E_LOG_INFORMATIVE, 'BOUNCE'); + e107::getLog()->add('User Bounce', $data, E_LOG_INFORMATIVE, 'BOUNCE'); } + + /** * @param $mode - check || process * @param array $data - usually email, date, id - but dependent on unsubscribe link above. @@ -90,6 +82,298 @@ class user_mailout } + + + /** + * Return data representing the user's selection criteria as entered in the $_POST array. + * + * The value returned can be as simple as an array of chosen fields from the $_POST array, or it may be processed to make it more + * convenient to use later. (In general, at least basic sanitising should be performed) + * Conflicting selection criteria can also be resolved here. + * The returned data is stored in the DB with a saved email. (Just return an empty string or array if this is undesirable) + * The returned value is passed back to selectInit() and showSelect when needed. + * + * @return mixed Selection data - may be string, array or whatever suits + */ + public function returnSelectors() + { + $tp = e107::getParser(); + + $res = array(); + foreach ($this->selectFields as $k) + { + if (vartrue($_POST[$k])) + { + $res[$k] = $tp->toDB($_POST[$k]); + } + } + return $res; + } + + + /** + * Called to initialise data selection routine. + * Needs to save any queries or other information into internal variables, do initial DB queries as appropriate. + * Could in principle read all addresses and buffer them for later routines, if this is more convenient + * + * @param mixed $selectVals - selection criteria as returned by returnSelectors() (so format is whatever is chosen by the coder) + * + * @return int|boolean number of records available (or 1 if unknown) on success, FALSE on failure + */ + public function selectInit($selectVals = FALSE) + { + $sql = e107::getDb(); + + $where = array(); + $incExtended = array(); + + $emailTo = vartrue($selectVals['email_to'], false); + + switch ($emailTo) + { + // Build the query for the user database + case 'all' : + $where[] = 'u.`user_ban`=0'; + break; + case 'admin' : + $where[] = 'u.`user_admin`=1'; + break; + case 'unverified' : + $where[] = 'u.`user_ban`=2'; + break; + case 'self' : + $where[] = 'u.`user_id`='.USERID; + break; + default : + if (is_numeric($selectVals['email_to'])) + { + $where[] = "u.`user_class` REGEXP concat('(^|,)',{$selectVals['email_to']},'(,|$)')"; + } + + } + + if (vartrue($selectVals['extended_1_name']) && vartrue($selectVals['extended_1_value'])) + { + $where[] = '`'.$selectVals['extended_1_name']."` = '".$selectVals['extended_1_value']."' "; + $incExtended[] = $selectVals['extended_1_name']; + } + + if (vartrue($selectVals['extended_2_name']) && vartrue($selectVals['extended_2_value'])) + { + $where[] = "ue.`".$selectVals['extended_2_name']."` = '".$selectVals['extended_2_value']."' "; + $incExtended[] = $selectVals['extended_2_name']; + } + + if (vartrue($selectVals['user_search_name']) && vartrue($selectVals['user_search_value'])) + { + $where[]= "u.`".$selectVals['user_search_name']."` LIKE '%".$selectVals['user_search_value']."%' "; + } + + if (vartrue($selectVals['last_visit_match']) && vartrue($selectVals['last_visit_date'])) + { + foreach(array(':', '-', ',') as $sep) + { + if (strpos($selectVals['last_visit_date'], ':')) + { + $tmp = explode($sep, $selectVals['last_visit_date']); + break; + } + } + $lvDate = gmmktime(0, 0, 0, $tmp[1], $tmp[0], $tmp[2]); // Require dd-mm-yy for now + if (($lvDate > 0) && ($lvDate <= time())) + { + switch ($selectVals['last_visit_match']) + { + case '<' : + case '>' : + $where[]= "u.`user_lastvisit`".$selectVals['last_visit_match'].$lvDate; + break; + case '=' : + $where[]= "u.`user_lastvisit`>=".$lvDate; + $where[]= "u.`user_lastvisit`<=".intval($lvDate + 86400); + break; + } + } + } + + if(empty($where) && empty($incExtended)) + { + $this->mail_read = 0; + $this->mail_count = 0; + return $this->mail_count; + } + + + $where[] = "u.`user_email` != ''"; // Ignore all records with empty email address + + + + // Now assemble the query from the pieces + // Determine which fields we actually need (u.user_sess is the signup link) + $qry = 'SELECT u.user_id, u.user_name, u.user_email, u.user_loginname, u.user_sess, u.user_lastvisit'; + if (count($incExtended)) + { + foreach ($incExtended as $if) + { + $qry .= ', ue.`'.$if.'`'; + } + } + $qry .= " FROM `#user` AS u "; + if (count($incExtended)) + { + $qry .= "LEFT JOIN `#user_extended` AS ue ON ue.`user_extended_id` = u.`user_id`"; + } + + $qry .= ' WHERE '.implode(' AND ',$where).' ORDER BY u.user_name'; +// echo "Selector query: ".$qry.'
'; + + e107::getMessage()->addDebug("Selector query: ".$qry); + + if (!( $this->mail_count = $sql->gen($qry))) return FALSE; + $this->mail_read = 0; + return $this->mail_count; + } + + + + /** + * Return one email address to add to the recipients list. Return FALSE if no more addresses to add + * + * @return boolean|array FALSE if no more addresses available; else an array: + * 'mail_recipient_id' - non-zero if a registered user, zero if a non-registered user. (Always non-zero from this class) + * 'mail_recipient_name' - user name + * 'mail_recipient_email' - email address to use + * 'mail_target_info' - array of info which might be substituted into email, usually using the codes defined by the editor. + * Array key is the code within '|...|', value is the string for substitution + */ + public function selectAdd() + { + $sql = e107::getDb(); + + if (!($row = $sql->fetch())) return FALSE; + $ret = array('mail_recipient_id' => $row['user_id'], + 'mail_recipient_name' => $row['user_name'], // Should this use realname? + 'mail_recipient_email' => $row['user_email'], + 'mail_target_info' => array( + 'USERID' => $row['user_id'], + 'DISPLAYNAME' => $row['user_name'], + 'SIGNUP_LINK' => $row['user_sess'], + 'USERNAME' => $row['user_loginname'], + 'USERLASTVISIT' => $row['user_lastvisit'] + ) + ); + $this->mail_read++; + return $ret; + } + + + /** + * Called once all email addresses read, to do any housekeeping needed + * + * @return none + */ + public function select_close() + { + // Nothing to do here + } + + + /** + * Called to show current selection criteria, and optionally allow edit + * + * @param $allow_edit is TRUE to allow user to change the selection; FALSE to just display current settings + * @param $selectVals is the current selection information - in the same format as returned by returnSelectors() + * + * @return Returns HTML which is displayed in a table cell. Typically we return a complete table + */ + public function showSelect($allow_edit = FALSE, $selectVals = FALSE) + { + $frm = e107::getForm(); + $sql = e107::getDb(); + $admin = e107::getRegistry('_mailout_admin'); + + $var = array(); + + $var[0]['caption'] = LAN_USERCLASS; // User class select + + if ($allow_edit) + { + $u_array = array('user_name'=>LAN_MAILOUT_43,'user_login'=>LAN_MAILOUT_44,'user_email'=>LAN_MAILOUT_45); + + $var[0]['html'] = $admin->userClassesTotals('email_to', varset($selectVals['email_to'], '')); + $var[1]['html'] = $frm->select('user_search_name', $u_array, varset($selectVals['user_search_name'], ''),'',TRUE)." ".LAN_MAILOUT_47." ".$frm->text('user_search_value', varset($selectVals['user_search_value'], '')); + //$var[2]['html'] = $admin->comparisonSelect('last_visit_match', varset($selectVals['last_visit_match'], ''))." ".$frm->text('last_visit_date', varset($selectVals['last_visit_date'], 0)); + $var[2]['html'] = $admin->comparisonSelect('last_visit_match', varset($selectVals['last_visit_match'], ''))." ".$admin->makeCalendar('last_visit_date', varset($selectVals['last_visit_date'], 0)); + $var[1]['caption'] = LAN_MAILOUT_46; // User Search Field. + $var[2]['caption'] = LAN_MAILOUT_56; // User last visit + + $extFields = $admin->ret_extended_field_list('extended_1_name', varset($selectVals['extended_1_name'], ''), TRUE); + if ($extFields !== FALSE) // Only display next bit if UEFs defined + { + $var[3]['html'] = $extFields.LAN_MAILOUT_48." ".$frm->text('extended_1_value',varset($selectVals['extended_1_value'], '')); + $var[4]['html'] = $admin->ret_extended_field_list('extended_2_name', varset($selectVals['extended_2_name'], ''), TRUE).LAN_MAILOUT_48." ".$frm->text('extended_2_value',varset($selectVals['extended_2_value'],'')); + + $var[3]['caption'] = LAN_MAILOUT_46; // Extended user field + $var[4]['caption'] = LAN_MAILOUT_46; // Extended user field + } + } + else // Display existing values + { + if (!vartrue($selectVals['email_to'])) + { + return null; + } + + if (is_numeric($selectVals['email_to'])) + { + $_to = LAN_MAILOUT_23.e107::getUserClass()->uc_get_classname(intval($selectVals['email_to'])); + } + else + { + $_to = $selectVals['email_to']; + } + + $var_0 = $_to.' '; + if ($selectVals['email_to'] == 'self') + { + $var_0 .= '<'.USEREMAIL.'>'; + } + + $var[0]['html'] = $var_0; + if (vartrue($selectVals['user_search_name']) && vartrue($selectVals['user_search_value'])) + { + $var[1]['html'] = $selectVals['user_search_name'].' '.$selectVals['user_search_value']; + $var[1]['caption'] = LAN_MAILOUT_46; // User Search Field. + } + if (vartrue($selectVals['last_visit_match']) && vartrue($selectVals['last_visit_date'])) + { + $var[2]['html'] = $selectVals['last_visit_match'].' '.gmstrftime("%D-%M-%Y",$selectVals['last_visit_date']); //FIXME use e107 date function. + $var[2]['caption'] = LAN_MAILOUT_56; // User last visit + } + $extFields = $admin->ret_extended_field_list('extended_1_name', varset($selectVals['extended_1_name'], ''), TRUE); + if ($extFields !== FALSE) + { + if (vartrue($selectVals['extended_1_name']) && vartrue($selectVals['extended_1_value'])) + { + $var[3]['html'] = $selectVals['extended_1_name'].' '.$selectVals['extended_1_value']; + $var[3]['caption'] = LAN_MAILOUT_46; // Extended user field + } + if (vartrue($selectVals['extended_2_name']) && vartrue($selectVals['extended_2_value'])) + { + $var[4]['html'] = $selectVals['extended_2_name'].' '.$selectVals['extended_2_value']; + $var[4]['caption'] = LAN_MAILOUT_46; // Extended user field + } + } + + } + + return $var; + } + + + + + }
" . $var['caption'] . "" . $var['caption'] . " " . $var['html'] . "