Commit 044fc9a1 authored by Nigel McNie's avatar Nigel McNie
Browse files

Allow notifications to override the message contents for email notifications...

Allow notifications to override the message contents for email notifications entirely if they choose.
parent 5bdace7e
......@@ -275,6 +275,7 @@ abstract class ActivityType {
protected $type;
protected $activityname;
protected $cron;
protected $overridemessagecontents;
public function get_id() {
if (!isset($this->id)) {
......
......@@ -32,39 +32,42 @@ class PluginNotificationEmail extends PluginNotification {
public static function notify_user($user, $data) {
$lang = (empty($user->lang) || $user->lang == 'default') ? get_config('lang') : $user->lang;
$separator = str_repeat('-', 72);
$sitename = get_config('sitename');
$subject = get_string_from_language($lang, 'emailsubject', 'notification.email', $sitename);
if (!empty($data->subject)) {
$subject .= ': ' . $data->subject;
if (!empty($data->overridemessagecontents)) {
$subject = $data->subject;
$messagebody = $data->message;
}
else {
$lang = (empty($user->lang) || $user->lang == 'default') ? get_config('lang') : $user->lang;
$separator = str_repeat('-', 72);
$messagebody = get_string_from_language($lang, 'emailheader', 'notification.email', $sitename) . "\n";
$messagebody .= $separator . "\n\n";
$sitename = get_config('sitename');
$subject = get_string_from_language($lang, 'emailsubject', 'notification.email', $sitename);
if (!empty($data->subject)) {
$subject .= ': ' . $data->subject;
}
$messagebody .= get_string_from_language($lang, 'subject') . ': ' . $data->subject . "\n\n";
if ($data->activityname == 'usermessage') {
// Do not include the message body in user messages when they are sent by email
// because it encourages people to reply to the email.
$messagebody .= get_string_from_language($lang, 'newusermessageemailbody', 'group', display_name($data->userfrom), $data->url);
}
else {
$messagebody .= $data->message;
if (!empty($data->url)) {
$messagebody .= "\n\n" . get_string_from_language($lang, 'referurl', 'notification.email', $data->url);
$messagebody = get_string_from_language($lang, 'emailheader', 'notification.email', $sitename) . "\n";
$messagebody .= $separator . "\n\n";
$messagebody .= get_string_from_language($lang, 'subject') . ': ' . $data->subject . "\n\n";
if ($data->activityname == 'usermessage') {
// Do not include the message body in user messages when they are sent by email
// because it encourages people to reply to the email.
$messagebody .= get_string_from_language($lang, 'newusermessageemailbody', 'group', display_name($data->userfrom), $data->url);
}
else {
$messagebody .= $data->message;
if (!empty($data->url)) {
$messagebody .= "\n\n" . get_string_from_language($lang, 'referurl', 'notification.email', $data->url);
}
}
}
if (isset($data->unsubscribeurl) && isset($data->unsubscribename)) {
$messagebody .= "\n\n" . get_string_from_language($lang, 'unsubscribemessage', 'notification.email', $data->unsubscribename, $data->unsubscribeurl);
}
$messagebody .= "\n\n$separator";
$messagebody .= "\n\n$separator";
$prefurl = get_config('wwwroot') . 'account/activity/preferences/';
$messagebody .= "\n\n" . get_string_from_language($lang, 'emailfooter', 'notification.email', $sitename, $prefurl);
}
$prefurl = get_config('wwwroot') . 'account/activity/preferences/';
$messagebody .= "\n\n" . get_string_from_language($lang, 'emailfooter', 'notification.email', $sitename, $prefurl);
email_user($user, null, $subject, $messagebody, null, !empty($data->customheaders) ? $data->customheaders : null);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment