From 779a705db5273d432c37cb96ca33cfe18e3e63eb Mon Sep 17 00:00:00 2001 From: mrded Date: Tue, 3 Sep 2013 12:03:15 +0100 Subject: [PATCH] Add Mail Editor support --- pm_email_notify/pm_email_notify.mail_edit.inc | 44 +++++++++++++++++++++++++++ pm_email_notify/pm_email_notify.module | 19 +++++++----- 2 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 pm_email_notify/pm_email_notify.mail_edit.inc diff --git a/pm_email_notify/pm_email_notify.mail_edit.inc b/pm_email_notify/pm_email_notify.mail_edit.inc new file mode 100644 index 0000000..73c37dd --- /dev/null +++ b/pm_email_notify/pm_email_notify.mail_edit.inc @@ -0,0 +1,44 @@ + t('Privatemsg e-mail notifications'), + ); +} + +/** + * Implements hook_mail_edit_text(). + * + * @param string $mailkey + * @param string $language + * + * @return array + */ +function pm_email_notify_mail_edit_text($mailkey, $language) { + switch ($mailkey) { + case 'notice': + return array( + 'subject' => variable_get('pm_email_notify_subject', _pm_email_notify_source_text('subject')), + 'body' => variable_get('pm_email_notify_body', _pm_email_notify_source_text('body')), + ); + + default : + return array(); + } +} + +/** + * Implements hook_mail_edit_token_types(). + * + * @param string $mailkey + * + * @return array + */ +function pm_email_notify_mail_edit_token_types($mailkey) { + return array('privatemsg_message'); +} diff --git a/pm_email_notify/pm_email_notify.module b/pm_email_notify/pm_email_notify.module index 7d8f128..870df4f 100644 --- a/pm_email_notify/pm_email_notify.module +++ b/pm_email_notify/pm_email_notify.module @@ -33,6 +33,13 @@ define('PM_EMAIL_NOTIFY_LEVEL_ALL', 12); define('PM_EMAIL_NOTIFY_LEVEL_DEFAULT', -1); /** + * Implements hook_init(). + */ +function pm_email_notify_init() { + module_load_include('mail_edit.inc', 'pm_email_notify'); +} + +/** * Implements hook_perm(). */ function pm_email_notify_permission() { @@ -216,8 +223,10 @@ function pm_email_notify_send_mail($recipient, $message) { // Check if the recipient enabled email notifications. if (isset($recipient->uid) && !empty($recipient->mail) && _pm_email_notify_send_check($recipient->uid, $message)) { // Send them a new pm notification email if they did. - $params['recipient'] = $recipient; - $params['message'] = $message; + $params = array(); + // Pass double variables for tokens & mail_alters. + $params['privatemsg_recipient'] = $params['recipient'] = $recipient; + $params['privatemsg_message'] = $params['message'] = $message; if (_pm_email_notify_show_sender($message->author->uid)) { // User author's email as a sender. @@ -225,10 +234,6 @@ function pm_email_notify_send_mail($recipient, $message) { } else { // Token replacements for email from address. - $data = array( - 'privatemsg_message' => $params['message'], - 'privatemsg_recipient' => $params['recipient'], - ); $options = array( 'language' => user_preferred_language($params['recipient']), // Don't sanitize output since this is used in an email, not a browser. @@ -236,7 +241,7 @@ function pm_email_notify_send_mail($recipient, $message) { // Custom token to avoid custom token handling. 'privatemsg-display-invalid' => FALSE, ); - $from = trim(token_replace(variable_get('pm_email_notify_from', ''), $data, $options)); + $from = trim(token_replace(variable_get('pm_email_notify_from', ''), $params, $options)); } drupal_mail('pm_email_notify', 'notice', $recipient->mail, user_preferred_language($recipient), $params, !empty($from) ? $from : NULL); } -- 1.7.12.4 (Apple Git-37)