Skip to content

Commit

Permalink
Add custom header and footer settings for HTML forum eMails.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Jul 26, 2017
1 parent 21aa7f4 commit d89dff1
Show file tree
Hide file tree
Showing 6 changed files with 786 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Version Information
===================
26th July 2017 - Version 3.1.1.16
1. Add custom header and footer settings for HTML forum eMails.

8th May 2017 - Version 3.1.1.15
1. Fix side-post blocks underneath content area on three column Frontpage when no side-pre blocks.
Expand Down
60 changes: 60 additions & 0 deletions classes/output/mod_forum/email/renderer_htmlemail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
// 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/>.

/**
* 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 <info@edulabs.org> 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);
}

}
12 changes: 11 additions & 1 deletion lang/en/theme_campus.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,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.';

Expand Down Expand Up @@ -438,3 +438,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.';
35 changes: 35 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1257,3 +1257,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);
107 changes: 107 additions & 0 deletions templates/mod_forum/forum_post_email_htmlemail.mustache
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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": "<a href=\"https://example.com/user/view.php?id=2&amp;course=6\"><img src=\"https://example.com/theme/image.php?theme=clean&amp;component=core&amp;image=u%2Ff2&amp;svg=0\" alt=\"Picture of Admin User\" title=\"Picture of Admin User\" class=\"userpicture defaultuserpic\" width=\"35\" height=\"35\" /></a>",
"authorfullname": "Lucius Caecilius lucundus",
"postdate": "Sunday, 13 September 2015, 2:22 pm",
"grouppicture": "",
"attachments": "",
"message": "<p>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.</p><p><br /></p>",
"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}}
<div class="navbar">
<a target="_blank" href="{{{ courselink }}}">{{{ coursename }}}</a>
&raquo;
<a target="_blank" href="{{{ forumindexlink }}}">{{# str }} forums, forum {{/ str }}</a>
&raquo;
<a target="_blank" href="{{{ forumviewlink }}}">{{{ forumname }}}</a>
{{# showdiscussionname }}
&raquo;
<a target="_blank" href="{{{ discussionlink }}}">{{{ discussionname }}}</a>
{{/ showdiscussionname }}
</div>
{{/enabletemplate}}

{{> mod_forum/forum_post_email_htmlemail_body }}

<hr />
<div class="mdl-align unsubscribelink">
{{# unsubscribeforumlink }}
<a href="{{{ unsubscribeforumlink }}}">{{# str }} unsubscribe, forum {{/ str }}</a>&nbsp;
{{/ unsubscribeforumlink }}
{{# unsubscribediscussionlink }}
<a href="{{{ unsubscribediscussionlink }}}">{{# str }} unsubscribediscussion, forum {{/ str }}</a>&nbsp;
{{/ unsubscribediscussionlink }}
<a href="{{{ forumindexlink }}}">{{# str }} digestmailpost, forum {{/ str }}</a>
</div>
Loading

0 comments on commit d89dff1

Please sign in to comment.