Merge branch 'MDL-52990-email-themes' of https://github.com/brendanheywood/moodle

This commit is contained in:
Dan Poltawski 2016-02-16 11:17:54 +00:00
commit 0aefe91c50
7 changed files with 193 additions and 15 deletions

View File

@ -5480,7 +5480,7 @@ function email_should_be_diverted($email) {
function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '', $attachment = '', $attachname = '',
$usetrueaddress = true, $replyto = '', $replytoname = '', $wordwrapwidth = 79) {
global $CFG;
global $CFG, $PAGE, $SITE;
if (empty($user) or empty($user->id)) {
debugging('Can not send email to null user', DEBUG_DEVELOPER);
@ -5598,8 +5598,6 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '',
$tempreplyto[] = array($replyto, $replytoname);
}
$mail->Subject = substr($subject, 0, 900);
$temprecipients[] = array($user->email, fullname($user));
// Set word wrap.
@ -5639,6 +5637,51 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '',
$mail->Priority = $from->priority;
}
$renderer = $PAGE->get_renderer('core');
$context = array(
'sitefullname' => $SITE->fullname,
'siteshortname' => $SITE->shortname,
'sitewwwroot' => $CFG->wwwroot,
'subject' => $subject,
'to' => $user->email,
'toname' => fullname($user),
'from' => $mail->From,
'fromname' => $mail->FromName,
);
if (!empty($tempreplyto[0])) {
$context['replyto'] = $tempreplyto[0][0];
$context['replytoname'] = $tempreplyto[0][1];
}
if ($user->id > 0) {
$context['touserid'] = $user->id;
$context['tousername'] = $user->username;
}
if (!empty($user->mailformat) && $user->mailformat == 1) {
// Only process html templates if the user preferences allow html email.
if ($messagehtml) {
// If html has been given then pass it through the template.
$context['body'] = $messagehtml;
$messagehtml = $renderer->render_from_template('core/email_html', $context);
} else {
// If no html has been given, BUT there is an html wrapping template then
// auto convert the text to html and then wrap it.
$autohtml = trim(text_to_html($messagetext));
$context['body'] = $autohtml;
$temphtml = $renderer->render_from_template('core/email_html', $context);
if ($autohtml != $temphtml) {
$messagehtml = $temphtml;
}
}
}
$context['body'] = $messagetext;
$mail->Subject = $renderer->render_from_template('core/email_subject', $context);
$mail->FromName = $renderer->render_from_template('core/email_fromname', $context);
$messagetext = $renderer->render_from_template('core/email_text', $context);
if ($messagehtml && !empty($user->mailformat) && $user->mailformat == 1) {
// Don't ever send HTML to users who don't want it.
$mail->isHTML(true);

View File

@ -0,0 +1,35 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core/email_html
Template for all email subjects.
Context variables required for this template:
* sitefullname
* siteshortname
* sitewwwroot
* subject
* to
* toname
* touserid
* from
* fromname
* replyto
* replytoname
}}
{{{fromname}}}

View File

@ -0,0 +1,38 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core/email_html
Template for all html emails. Note that it may wrap content formatted
elsewhere in another a module template.
Context variables required for this template:
* sitefullname
* siteshortname
* sitewwwroot
* subject
* to
* toname
* touserid
* tousername
* from
* fromname
* replyto
* replytoname
* body
}}
{{{body}}}

View File

@ -0,0 +1,35 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core/email_html
Template for all email subjects.
Context variables required for this template:
* sitefullname
* siteshortname
* sitewwwroot
* subject
* to
* toname
* touserid
* from
* fromname
* replyto
* replytoname
}}
{{{subject}}}

View File

@ -0,0 +1,37 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core/email_text
Template for all html emails. Note that it may wrap content formatted
elsewhere in another a module template.
Context variables required for this template:
* sitefullname
* siteshortname
* sitewwwroot
* subject
* to
* toname
* touserid
* from
* fromname
* replyto
* replytoname
* body
}}
{{{body}}}

View File

@ -1013,13 +1013,8 @@ function forum_cron() {
$posttext = get_string('digestmailheader', 'forum', $headerdata)."\n\n";
$headerdata->userprefs = '<a target="_blank" href="'.$headerdata->userprefs.'">'.get_string('digestmailprefs', 'forum').'</a>';
$posthtml = "<head>";
/* foreach ($CFG->stylesheets as $stylesheet) {
//TODO: MDL-21120
$posthtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />'."\n";
}*/
$posthtml .= "</head>\n<body id=\"email\">\n";
$posthtml .= '<p>'.get_string('digestmailheader', 'forum', $headerdata).'</p><br /><hr size="1" noshade="noshade" />';
$posthtml = '<p>'.get_string('digestmailheader', 'forum', $headerdata).'</p>'
. '<br /><hr size="1" noshade="noshade" />';
foreach ($thesediscussions as $discussionid) {
@ -1166,7 +1161,6 @@ function forum_cron() {
$posthtml .= "\n<div class='mdl-right'><font size=\"1\">" . implode('&nbsp;', $footerlinks) . '</font></div>';
$posthtml .= '<hr size="1" noshade="noshade" /></p>';
}
$posthtml .= '</body>';
if (empty($userto->mailformat) || $userto->mailformat != 1) {
// This user DOESN'T want to receive HTML

View File

@ -77,9 +77,6 @@
"unsubscribediscussionlink": "https://example.com/mod/discussion/subscribe.php?id=2&d=2"
}
}}
<head>
</head>
<body id="email">
<div class="navbar">
<a target="_blank" href="{{{ courselink }}}">{{{ coursename }}}</a>
&raquo;
@ -104,4 +101,3 @@
{{/ unsubscribediscussionlink }}
<a href="{{{ forumindexlink }}}">{{# str }} digestmailpost, forum {{/ str }}</a>
</div>
</body>