From 08962926221baa751a437bdbf0668010c1e19d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Mon, 30 Jul 2012 20:05:34 +0200 Subject: [PATCH] MDL-34635 support multilang in self enrol course welcome message Includes also new help string for the custom multilang placeholders by Helen Foster. --- enrol/self/edit_form.php | 1 + enrol/self/lang/en/enrol_self.php | 6 ++++++ enrol/self/lib.php | 20 +++++++++++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/enrol/self/edit_form.php b/enrol/self/edit_form.php index 3b252210a45..7f77cfce25b 100644 --- a/enrol/self/edit_form.php +++ b/enrol/self/edit_form.php @@ -105,6 +105,7 @@ class enrol_self_edit_form extends moodleform { $mform->addHelpButton('customint4', 'sendcoursewelcomemessage', 'enrol_self'); $mform->addElement('textarea', 'customtext1', get_string('customwelcomemessage', 'enrol_self'), array('cols'=>'60', 'rows'=>'8')); + $mform->addHelpButton('customtext1', 'customwelcomemessage', 'enrol_self'); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); diff --git a/enrol/self/lang/en/enrol_self.php b/enrol/self/lang/en/enrol_self.php index af2c54c80bf..5c96f78fbf5 100644 --- a/enrol/self/lang/en/enrol_self.php +++ b/enrol/self/lang/en/enrol_self.php @@ -25,6 +25,12 @@ */ $string['customwelcomemessage'] = 'Custom welcome message'; +$string['customwelcomemessage_help'] = 'A custom welcome message may be added as plain text or Moodle-auto format, including HTML tags and multi-lang tags. + +The following placeholders may be included in the message: + +* Course name {$a->coursename} +* Link to user\'s profile page {$a->profileurl}'; $string['defaultrole'] = 'Default role assignment'; $string['defaultrole_desc'] = 'Select role which should be assigned to users during self enrolment'; $string['editenrolment'] = 'Edit enrolment'; diff --git a/enrol/self/lib.php b/enrol/self/lib.php index 4c9246b3c2b..771ec763e0b 100644 --- a/enrol/self/lib.php +++ b/enrol/self/lib.php @@ -267,22 +267,32 @@ class enrol_self_plugin extends enrol_plugin { global $CFG, $DB; $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); + $context = context_course::instance($course->id); $a = new stdClass(); - $a->coursename = format_string($course->fullname); + $a->coursename = format_string($course->fullname, true, array('context'=>$context)); $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id"; if (trim($instance->customtext1) !== '') { $message = $instance->customtext1; $message = str_replace('{$a->coursename}', $a->coursename, $message); $message = str_replace('{$a->profileurl}', $a->profileurl, $message); + if (strpos($message, '<') === false) { + // Plain text only. + $messagetext = $message; + $messagehtml = text_to_html($messagetext, null, false, true); + } else { + // This is most probably the tag/newline soup known as FORMAT_MOODLE. + $messagehtml = format_text($message, FORMAT_MOODLE, array('context'=>$context, 'para'=>false, 'newlines'=>true, 'filter'=>true)); + $messagetext = html_to_text($messagehtml); + } } else { - $message = get_string('welcometocoursetext', 'enrol_self', $a); + $messagetext = get_string('welcometocoursetext', 'enrol_self', $a); + $messagehtml = text_to_html($messagetext, null, false, true); } - $subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname)); + $subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname, true, array('context'=>$context))); - $context = context_course::instance($course->id); $rusers = array(); if (!empty($CFG->coursecontact)) { $croles = explode(',', $CFG->coursecontact); @@ -295,7 +305,7 @@ class enrol_self_plugin extends enrol_plugin { } //directly emailing welcome message rather than using messaging - email_to_user($user, $contact, $subject, $message); + email_to_user($user, $contact, $subject, $messagetext, $messagehtml); } /**