Skip to content

Commit 8b2c08a

Browse files
committed
INT-18599: Fix simple text format
1 parent 8547953 commit 8b2c08a

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

lib.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8806,6 +8806,25 @@ function hsuforum_check_updates_since(cm_info $cm, $from, $filter = array()) {
88068806
return $updates;
88078807
}
88088808

8809+
/**
8810+
* Update the post format to the preferred format.
8811+
* @param $messagecontent
8812+
* @param $prefilledpostformat
8813+
* @param $modcontext
8814+
* @return mixed|string
8815+
*/
8816+
function hsuforum_change_format($messagecontent, $prefilledpostformat, $modcontext) {
8817+
$preferredformat = editors_get_preferred_format();
8818+
// Only if there are prefilled contents coming.
8819+
if (!empty($messagecontent)) {
8820+
// If the prefilled post is not HTML and the preferred format is HTML, convert to it.
8821+
if ($prefilledpostformat != FORMAT_HTML and $preferredformat == FORMAT_HTML) {
8822+
$messagecontent = format_text($messagecontent, $prefilledpostformat, ['context' => $modcontext]);
8823+
}
8824+
}
8825+
return $messagecontent;
8826+
}
8827+
88098828
/**
88108829
* Check if the user can create attachments in a forum.
88118830
* @param stdClass $forum forum object

post.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
// Retrieve the contexts.
118118
$modcontext = context_module::instance($cm->id);
119119
$coursecontext = context_course::instance($course->id);
120+
$PAGE->set_cm($cm, $course, $forum);
120121

121122
if (! hsuforum_user_can_post_discussion($forum, $groupid, -1, $cm)) {
122123
if (!isguestuser()) {
@@ -139,6 +140,7 @@
139140

140141
$SESSION->fromurl = get_local_referer(false);
141142

143+
$messagecontent = hsuforum_change_format($messagecontent, $prefilledpostformat, $modcontext);
142144
// Load up the $post variable.
143145

144146
$post = new stdClass();
@@ -222,14 +224,7 @@
222224
print_error("activityiscurrentlyhidden");
223225
}
224226

225-
$preferredformat = editors_get_preferred_format();
226-
// Only if there are prefilled contents coming.
227-
if (!empty($messagecontent)) {
228-
// If the prefilled post is not HTML and the preferred format is HTML, convert to it.
229-
if ($prefilledpostformat != FORMAT_HTML and $preferredformat == FORMAT_HTML) {
230-
$messagecontent = format_text($messagecontent, $prefilledpostformat, ['context' => $modcontext]);
231-
}
232-
}
227+
$messagecontent = hsuforum_change_format($messagecontent, $prefilledpostformat, $modcontext);
233228
// Load up the $post variable.
234229

235230
$post = new stdClass();

0 commit comments

Comments
 (0)