diff --git a/Changes.md b/Changes.md index 4a33734..89a07e7 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,7 @@ Version Information =================== -25th July 2017 - Version 3.3.0.2 +26th July 2017 - Version 3.3.0.2 + 1. Add custom header and footer settings for HTML forum eMails. 19th July 2017 - Version 3.3.0.1 1. Initial Moodle 3.3 version. diff --git a/classes/output/mod_forum/email/renderer_htmlemail.php b/classes/output/mod_forum/email/renderer_htmlemail.php new file mode 100644 index 0000000..670e41d --- /dev/null +++ b/classes/output/mod_forum/email/renderer_htmlemail.php @@ -0,0 +1,60 @@ +. + +/** + * Settings block renderers + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace theme_campus\output\mod_forum\email; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Forum post renderable. + * + * @since Moodle 3.0 + * @package theme_campus + * @copyright 2017 David Bogner and Gareth Barnard + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class renderer_htmlemail extends \mod_forum\output\email\renderer { + + /** + * Display a forum post in the relevant context. + * + * @param \mod_forum\output\forum_post $post The post to display. + * @return string + */ + public function render_forum_post_email(\mod_forum\output\forum_post_email $post) { + // Was ($this, $this->target === RENDERER_TARGET_TEXTEMAIL) and as we are already 'htmlemail' it will always be false. + $data = $post->export_for_template($this, false); + // Add our new data. + $data['enabletemplate'] = \theme_campus\toolbox::get_setting('forumcustomtemplate'); + $forumhtmlemailheader = \theme_campus\toolbox::get_setting('forumhtmlemailheader', 'format_html'); + if ($forumhtmlemailheader) { + $data['messageheader'] = $forumhtmlemailheader; + } + $forumhtmlemailfooter = \theme_campus\toolbox::get_setting('forumhtmlemailfooter', 'format_html'); + if ($forumhtmlemailfooter) { + $data['messagefooter'] = $forumhtmlemailfooter; + } + + return $this->render_from_template('mod_forum/' . $this->forum_post_template(), $data); + } + +} \ No newline at end of file diff --git a/lang/en/theme_campus.php b/lang/en/theme_campus.php index c068731..9b8a654 100644 --- a/lang/en/theme_campus.php +++ b/lang/en/theme_campus.php @@ -408,7 +408,7 @@ $string['imageleft'] = 'Left'; $string['imageright'] = 'Right'; -// Forum header. +// Forum header colour. $string['forumheadertextcolour'] = 'Forum header text colour'; $string['forumheadertextcolourdesc'] = 'Set the forum header text colour.'; @@ -441,3 +441,13 @@ // admin_setting_configinteger. $string['asconfigintlower'] = '{$a->value} is less than the lower range limit of {$a->lower}'; $string['asconfigintupper'] = '{$a->value} is greater than the upper range limit of {$a->upper}'; + +// Forum. +$string['forumsettings'] = 'Forum general'; +$string['forumsettingsdesc'] = 'Configure the general forum settings for the theme here.'; +$string['forumhtmlemailheader'] = 'Forum html email header'; +$string['forumhtmlemailheaderdesc'] = 'Configure the forum html email header for the theme here.'; +$string['forumhtmlemailfooter'] = 'Forum html email footer'; +$string['forumhtmlemailfooterdesc'] = 'Configure the forum html email footer for the theme here.'; +$string['forumcustomtemplate'] = 'Use a pretty template for forum mails'; +$string['forumcustomtemplatedesc'] = 'Enable that in order to use a pretty template for sending forum mails. Put an image in the header section of max-width 300px. If not enabled standard formatting of forum mails will be used.'; diff --git a/settings.php b/settings.php index 7fbb0eb..d99884c 100644 --- a/settings.php +++ b/settings.php @@ -1267,3 +1267,38 @@ } } $ADMIN->add('theme_campus', $settingpage); + +// Forum page.... +$settingpage = new admin_settingpage('theme_campus_forum', get_string('forumsettings', 'theme_campus')); +if ($ADMIN->fulltree) { + $settingpage->add(new admin_setting_heading('theme_campus_forumheading', null, + format_text(get_string('forumsettingsdesc', 'theme_campus'), FORMAT_MARKDOWN))); + + // Enable custom template + $name = 'theme_campus/forumcustomtemplate'; + $title = get_string('forumcustomtemplate', 'theme_campus'); + $description = get_string('forumcustomtemplatedesc', 'theme_campus'); + $default = 0; + $setting = new admin_setting_configcheckbox($name, $title, $description, $default); + // No CSS change, so no need to reset caches. + $settingpage->add($setting); + + // Header setting. + $name = 'theme_campus/forumhtmlemailheader'; + $title = get_string('forumhtmlemailheader', 'theme_campus'); + $description = get_string('forumhtmlemailheaderdesc', 'theme_campus'); + $default = ''; + $setting = new admin_setting_confightmleditor($name, $title, $description, $default); + // No CSS change, so no need to reset caches. + $settingpage->add($setting); + + // Footer setting. + $name = 'theme_campus/forumhtmlemailfooter'; + $title = get_string('forumhtmlemailfooter', 'theme_campus'); + $description = get_string('forumhtmlemailfooterdesc', 'theme_campus'); + $default = ''; + $setting = new admin_setting_confightmleditor($name, $title, $description, $default); + // No CSS change, so no need to reset caches. + $settingpage->add($setting); +} +$ADMIN->add('theme_campus', $settingpage); diff --git a/templates/mod_forum/forum_post_email_htmlemail.mustache b/templates/mod_forum/forum_post_email_htmlemail.mustache new file mode 100644 index 0000000..e63d329 --- /dev/null +++ b/templates/mod_forum/forum_post_email_htmlemail.mustache @@ -0,0 +1,107 @@ +{{! + 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 . +}} +{{! + @template mod_forum/forum_post_email_htmlemail + + Template which defines a forum post for sending in a single-post HTML email. + + Classes required for JS: + * none + + Data attributes required for JS: + * none + + Context variables required for this template: + * enabletemplate + * courselink + * coursename + * forumindexlink + * forumviewlink + * forumname + * discussionlink + * discussionname + * showdiscussionname + * firstpost + * subject + * authorlink + * authorpicture + * authorfullname + * postdate + * grouppicture + * attachments + * message + * parentpostlink + * canreply + * replylink + * permalink + * unsubscribeforumlink + * unsubscribediscussionlink + + Example context (json): + { + "enabletemplate": 1, + "courselink": "https://example.com/course/view.php?id=2", + "coursename": "Example course", + "forumindexlink": "https://example.com/mod/forum/index.php?id=2", + "forumviewlink": "https://example.com/mod/forum/view.php?f=2", + "forumname": "Lorem ipsum dolor", + "discussionlink": "https://example.com/mod/forum/discuss.php?d=70", + "discussionname": "Is Lorem ipsum Latin?", + "showdiscussionname": 1, + "firstpost": 1, + "subject": "Is Lorem ipsum Latin?", + "authorlink": "https://example.com/user/view.php?id=2&course=2", + "authorpicture": "\"Picture", + "authorfullname": "Lucius Caecilius lucundus", + "postdate": "Sunday, 13 September 2015, 2:22 pm", + "grouppicture": "", + "attachments": "", + "message": "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum et auctor libero. Quisque porta egestas neque, et bibendum libero dignissim at. Nulla facilisi. Morbi eget accumsan felis. Nunc et vulputate odio, vel venenatis nisl. Nunc maximus ipsum sed tincidunt mollis. Integer nunc erat, luctus sit amet arcu tincidunt, volutpat dignissim mi. Sed ut magna quam. Mauris accumsan porta turpis sed aliquam. Etiam at justo tristique, imperdiet augue quis, consectetur sapien. Ut nec erat malesuada sem suscipit lobortis. Vivamus posuere nibh eu ipsum porta fringilla. Sed vitae dapibus ipsum, ac condimentum enim. Sed dignissim ante at elit mollis, ac tempor lacus iaculis. Etiam nec lectus vitae nibh vulputate volutpat. Nulla quis tellus aliquam, commodo nisi et, dictum est.


", + "parentpostlink": "", + "canreply": 1, + "replylink": "https://example.com/mod/forum/post.php?reply=2", + "permalink": "https://example.com/mod/forum/discuss.php?d=2#2", + "unsubscribeforumlink": "https://example.com/mod/forum/subscribe.php?id=2", + "unsubscribediscussionlink": "https://example.com/mod/discussion/subscribe.php?id=2&d=2" + } +}} +{{^enabletemplate}} + +{{/enabletemplate}} + +{{> mod_forum/forum_post_email_htmlemail_body }} + +
+ diff --git a/templates/mod_forum/forum_post_email_htmlemail_body.mustache b/templates/mod_forum/forum_post_email_htmlemail_body.mustache new file mode 100644 index 0000000..12396e5 --- /dev/null +++ b/templates/mod_forum/forum_post_email_htmlemail_body.mustache @@ -0,0 +1,572 @@ +{{! + 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 . +}} +{{! + @template mod_forum/forum_post_emaildigestfull_htmlemail_body + + Template which defines the body component of a forum post for sending in a single-post HTML email. + + Classes required for JS: + * none + + Data attributes required for JS: + * none + + Context variables required for this template: + * enabletemplate + * courselink + * coursename + * forumindexlink + * forumviewlink + * forumname + * discussionlink + * discussionname + * showdiscussionname + * firstpost + * subject + * authorlink + * authorpicture + * authorfullname + * postdate + * grouppicture + * attachments + * messageheader + * message + * messagefooter + * parentpostlink + * canreply + * replylink + * permalink + * unsubscribeforumlink + * unsubscribediscussionlink + + Example context (json): + { + "enabletemplate": 1, + "courselink": "https://example.com/course/view.php?id=2", + "coursename": "Example course", + "forumindexlink": "https://example.com/mod/forum/index.php?id=2", + "forumviewlink": "https://example.com/mod/forum/view.php?f=2", + "forumname": "Lorem ipsum dolor", + "discussionlink": "https://example.com/mod/forum/discuss.php?d=70", + "discussionname": "Is Lorem ipsum Latin?", + "showdiscussionname": 1, + "firstpost": 1, + "subject": "Is Lorem ipsum Latin?", + "authorlink": "https://example.com/user/view.php?id=2&course=2", + "authorpicture": "\"Picture", + "authorfullname": "Lucius Caecilius lucundus", + "postdate": "Sunday, 13 September 2015, 2:22 pm", + "grouppicture": "", + "attachments": "", + "measageheader": "

Message header

", + "message": "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum et auctor libero. Quisque porta egestas neque, et bibendum libero dignissim at. Nulla facilisi. Morbi eget accumsan felis. Nunc et vulputate odio, vel venenatis nisl. Nunc maximus ipsum sed tincidunt mollis. Integer nunc erat, luctus sit amet arcu tincidunt, volutpat dignissim mi. Sed ut magna quam. Mauris accumsan porta turpis sed aliquam. Etiam at justo tristique, imperdiet augue quis, consectetur sapien. Ut nec erat malesuada sem suscipit lobortis. Vivamus posuere nibh eu ipsum porta fringilla. Sed vitae dapibus ipsum, ac condimentum enim. Sed dignissim ante at elit mollis, ac tempor lacus iaculis. Etiam nec lectus vitae nibh vulputate volutpat. Nulla quis tellus aliquam, commodo nisi et, dictum est.


", + "messagefooter": "

Message footer

", + "parentpostlink": "", + "canreply": 1, + "replylink": "https://example.com/mod/forum/post.php?reply=2", + "permalink": "https://example.com/mod/forum/discuss.php?d=2#2", + "unsubscribeforumlink": "https://example.com/mod/forum/subscribe.php?id=2", + "unsubscribediscussionlink": "https://example.com/mod/discussion/subscribe.php?id=2&d=2" + } +}} +{{#enabletemplate}} + + + + + + + +
+
+ + + + + + +
+ + + + + + +
+ + + + + + + +
+ + + + + + +
+ {{ #messageheader }}{{{ messageheader }}}{{ /messageheader }} +
+
+ + + + + + +
+

{{{ authorpicture }}}

+
+
+
+
+ + + + + + +
+ + + + + + +
 
+ + + + + + +
+ + + + + + + +
+

{{{ subject }}}

+

{{{ message }}}

+ + + + + + + +
+

{{# str }} bynameondate, forum, { "name": {{# quote }}{{ authorfullname }}{{/ quote }}, "date": {{# quote }}{{ postdate }}{{/ quote }} } {{/ str }}
{{# str }} postincontext, forum {{/ str }}

+ +
+
+
+ + + + + + +
+ + + + + + +
 
+ + + + + + + +
+ + + + + + +
+ + + + + + + +
+
+ + + + + + +
+

{{# attachments }}

{{{ attachments }}}
{{/ attachments }}

+

{{# grouppicture }}{{{ grouppicture }}}{{/ grouppicture }}{{^ grouppicture }} {{/ grouppicture }}

+
+
+
+
+
+
+ {{ #messagefooter }}{{{ messagefooter }}}{{ /messagefooter }} +{{/enabletemplate}} +{{^enabletemplate}} + + + + + + + + + +
+ {{{ authorpicture }}} + +
+ {{{ subject }}} +
+
+ {{# str }} bynameondate, forum, { + "name": {{# quote }}{{ authorfullname }}{{/ quote }}, + "date": {{# quote }}{{ postdate }}{{/ quote }} + } {{/ str }} +
+
+ {{# grouppicture }} + {{{ grouppicture }}} + {{/ grouppicture }} + {{^ grouppicture }} +   + {{/ grouppicture }} + + {{# attachments }} +
+ {{{ attachments }}} +
+ {{/ attachments }} + {{ #messageheader }}{{{ messageheader }}}{{ /messageheader }} + {{{ message }}} + {{ #messagefooter }}{{{ messagefooter }}}{{ /messagefooter }} + +
+ {{^ firstpost }} + + {{# str }} parent, forum {{/ str }} + + {{# canreply }} + | + {{/ canreply }} + {{/ firstpost }} + {{# canreply }} + + {{# str }} reply, forum {{/ str }} + + {{/ canreply }} +
+ + +
+{{/enabletemplate}}