From 968c6115dc452f85cf5385b7ada2a6811aa763ba Mon Sep 17 00:00:00 2001 From: Michael Hawkins Date: Tue, 18 Dec 2018 14:19:53 +0800 Subject: [PATCH 1/2] MDL-64240 mod_forum: Update word count to use current message length Previously this used the length of the message stored in the database, before scripts etc are cleaned to display the content. That resulted in cases where the count would seem much larger than the message size. --- mod/forum/lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 83a83869347..7e397c56551 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3523,7 +3523,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa $postcontent = highlight($highlight, $postcontent); } if (!empty($forum->displaywordcount)) { - $postcontent .= html_writer::tag('div', get_string('numwords', 'moodle', count_words($post->message)), + $postcontent .= html_writer::tag('div', get_string('numwords', 'moodle', count_words($postcontent)), array('class'=>'post-word-count')); } $postcontent .= html_writer::tag('div', $attachedimages, array('class'=>'attachedimages')); From 9d046294fb635393fa0c034b38194e86cf9bf0a5 Mon Sep 17 00:00:00 2001 From: Michael Hawkins Date: Tue, 18 Dec 2018 14:21:58 +0800 Subject: [PATCH 2/2] MDL-64240 mod_forum: Clean forum post text before storing Previously only edited messages were cleaned, so longer strings could be stored in the database, which would never be displayed. This update takes into account trusted text before cleaning (as editing does). --- mod/forum/post.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mod/forum/post.php b/mod/forum/post.php index 4f79679b41b..5683a233fb9 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -683,6 +683,9 @@ if ($mform_post->is_cancelled()) { // WARNING: the $fromform->message array has been overwritten, do not use it anymore! $fromform->messagetrust = trusttext_trusted($modcontext); + // Clean message text. + $fromform = trusttext_pre_edit($fromform, 'message', $modcontext); + if ($fromform->edit) { // Updating a post unset($fromform->groupid); $fromform->id = $fromform->edit;