From 7e7833cbda268debe901a044682968fad81ca503 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 17 Apr 2016 12:04:35 -0700 Subject: [PATCH] Fixes #1532 PM notification template. --- e107_handlers/mail.php | 5 +++- e107_plugins/pm/admin_config.php | 40 +++++++++++++++++++++++++++++++ e107_plugins/pm/pm_class.php | 32 +++++++++++++++++++------ e107_plugins/pm/pm_shortcodes.php | 5 +++- e107_plugins/pm/pm_template.php | 2 +- 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index 3b596cb7f..b8bcdf2ac 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -577,7 +577,10 @@ 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 + + ; + // !preg_match('/<(table|div|font|br|a|img|b)/i', $message) + if ($this->legacyBody && e107::getParser()->isHtml($message) != true) // 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) diff --git a/e107_plugins/pm/admin_config.php b/e107_plugins/pm/admin_config.php index 648a487a1..7bc652022 100644 --- a/e107_plugins/pm/admin_config.php +++ b/e107_plugins/pm/admin_config.php @@ -134,6 +134,10 @@ class private_msg_ui extends e_admin_ui + + + + private function limitsPageAdd() { $sql = e107::getDb(); @@ -768,13 +772,49 @@ class private_msg_ui extends e_admin_ui } + function sendTestNotify() + { + e107::includeLan(e_PLUGIN.'pm/languages/'.e_LANGUAGE.'.php'); + require_once(e_PLUGIN."pm/pm_class.php"); + $pmInfo = array ( 'numsent' => '1', 'pm_to' => USERID, 'pm_sent'=>time(), 'pm_userclass' => false, 'pm_subject' => 'Test Subject Random:'.md5(time()), 'pm_message' => 'Test Message '.md5(time()), 'postpm' => 'Send Private Message', 'keyword' => NULL, + 'to_info' => array ( + 'user_id' => USERID, + 'user_name' => USERNAME, + 'user_class' => USERCLASS, + 'user_email' => USEREMAIL, + ), + 'uploaded' => array ( ), 'from_id' => 1, 'options' => '', ); + + $pm = new private_message; + + if($pm->pm_send_notify(null,$pmInfo, 1) === true) + { + e107::getMessage()->addSuccess("Test Email Sent"); + } + else + { + e107::getMessage()->addError("Test Email Failed"); + } + + + } public function init() { // $this->listQry = "SELECT p.*,u.user_name FROM #private_msg AS p LEFT JOIN #user AS u ON p.pm_from = u.user_id "; + if(deftrue('e_DEVELOPER') || deftrue('e_DEBUG')) + { + $this->prefs['notify_class']['writeParms']['post']= e107::getForm()->button('testNotify', 1, 'primary', "Test"); + + if(!empty($_POST['testNotify'])) + { + $this->sendTestNotify(); + } + } + if($this->getMode() == 'inbox') { $this->listQry = 'SELECT p.*, u.user_name, f.user_name AS fromuser FROM #private_msg AS p LEFT JOIN #user AS u ON u.user_id = p.pm_to diff --git a/e107_plugins/pm/pm_class.php b/e107_plugins/pm/pm_class.php index 09503a2ea..44259476a 100755 --- a/e107_plugins/pm/pm_class.php +++ b/e107_plugins/pm/pm_class.php @@ -32,7 +32,7 @@ class private_message * @param array $prefs - pref settings for PM plugin * @return none */ - public function __construct($prefs) + public function __construct($prefs=null) { $this->e107 = e107::getInstance(); $this->pmPrefs = $prefs; } @@ -117,6 +117,8 @@ class private_message $pm_options = ''; $ret = ''; $addOutbox = TRUE; + $timestamp = time(); + $maxSendNow = varset($this->pmPrefs['pm_max_send'],100); // Maximum number of PMs to send without queueing them if (isset($vars['pm_from'])) { // Doing bulk send off cron task @@ -161,7 +163,7 @@ class private_message // Most of the pm info is fixed - just need to set the 'to' user on each send $info = array( 'pm_from' => $vars['from_id'], - 'pm_sent' => time(), /* Date sent */ + 'pm_sent' => $timestamp, /* Date sent */ 'pm_read' => 0, /* Date read */ 'pm_subject' => $pm_subject, 'pm_text' => $pm_message, @@ -235,6 +237,7 @@ class private_message if(check_class($this->pmPrefs['notify_class'], null, $u['user_id'])) { $vars['to_info'] = $u; + $vars['pm_sent'] = $timestamp; $this->pm_send_notify($u['user_id'], $vars, $pmid, count($a_list)); } } @@ -262,6 +265,7 @@ class private_message if($pmid = $sql->insert('private_msg', $info)) { $info['pm_id'] = $pmid; + $info['pm_sent'] = $timestamp; e107::getEvent()->trigger('user_pm_sent', $info); @@ -366,7 +370,7 @@ class private_message */ function pm_send_notify($uid, $pmInfo, $pmid, $attach_count = 0) { - require_once(e_HANDLER.'mail.php'); + // require_once(e_HANDLER.'mail.php'); $tpl_file = THEME.'pm_template.php'; @@ -388,13 +392,14 @@ class private_message ".LAN_PM_108."{PM_DATE} ".LAN_PM_104."{PM_ATTACHMENTS} - +
".LAN_PM_105.": {PM_URL}
"; } + $url = e107::url('pm','index', null, array('mode'=>'full')).'?show.'.$pmid; $data = array(); $data['PM_SUBJECT'] = $pmInfo['pm_subject']; @@ -402,13 +407,26 @@ class private_message $data['PM_DATE'] = e107::getParser()->toDate($pmInfo['pm_sent'], 'long'); $data['SITENAME'] = SITENAME; $data['USERNAME'] = USERNAME; - $data['PM_URL'] = e107::url('pm','index', null, array('mode'=>'full')).'?show.'.$pmid;; + $data['PM_URL'] = "".$url."";// e107::url('pm','index', null, array('mode'=>'full')).'?show.'.$pmid; $text = e107::getParser()->simpleParse($template, $data); - $subject = LAN_PM_100.SITENAME; + $eml = array(); + $eml['email_subject'] = LAN_PM_100.USERNAME; + $eml['send_html'] = true; + $eml['email_body'] = $text; + $eml['template'] = 'default'; + $eml['e107_header'] = $pmInfo['to_info']['user_id']; + + if(e107::getEmail()->sendEmail($pmInfo['to_info']['user_email'], $pmInfo['to_info']['user_name'], $eml)) + { + return true; + } + else + { + return false; + } - sendemail($pmInfo['to_info']['user_email'], $subject, $text, $pmInfo['to_info']['user_name']); } diff --git a/e107_plugins/pm/pm_shortcodes.php b/e107_plugins/pm/pm_shortcodes.php index d6cd16e11..a1579898a 100644 --- a/e107_plugins/pm/pm_shortcodes.php +++ b/e107_plugins/pm/pm_shortcodes.php @@ -176,7 +176,10 @@ if(!class_exists('plugin_pm_pm_shortcodes')) else { $frm = e107::getForm(); - $ret = $frm->userlist('pm_to',null,array('excludeSelf'=>true, 'default'=>'blank', 'classes'=>varset($this->pmPrefs['send_to_class'], e_UC_MEMBER))); + + $exclude = (getperms('0') && e_DEBUG === true) ? false : true; + + $ret = $frm->userlist('pm_to',null,array('excludeSelf'=>$exclude, 'default'=>'blank', 'classes'=>varset($this->pmPrefs['send_to_class'], e_UC_MEMBER))); } diff --git a/e107_plugins/pm/pm_template.php b/e107_plugins/pm/pm_template.php index b08005313..1c16c7b41 100755 --- a/e107_plugins/pm/pm_template.php +++ b/e107_plugins/pm/pm_template.php @@ -277,7 +277,7 @@ $PM_NOTIFY = ".LAN_PM_108."{PM_DATE} ".LAN_PM_104."{PM_ATTACHMENTS} - +
".LAN_PM_105.": {PM_URL}
";