Skip to content
Browse files

MDL-23335 mod_forum: allow multi-lang filtering of shortened messages

MDL-23335 mod_forum: Correct ordering of filtering and shortening
  • Loading branch information...
1 parent 6cef890 commit 557b8de4cf6b770cef1218a4caef3c35da3cb12e @deraadt deraadt committed Jul 26, 2013
Showing with 5 additions and 45 deletions.
  1. +5 −45 mod/forum/lib.php
View
50 mod/forum/lib.php
@@ -3455,9 +3455,10 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
$options->trusted = $post->messagetrust;
$options->context = $modcontext;
if ($shortenpost) {
- // Prepare shortened version
+ // Prepare shortened version by filtering the text then shortening it.
$postclass = 'shortenedpost';
- $postcontent = format_text(forum_shorten_post($post->message), $post->messageformat, $options, $course->id);
+ $postcontent = format_text($post->message, $post->messageformat, $options);
+ $postcontent = forum_shorten_post($postcontent);
$postcontent .= html_writer::link($discussionlink, get_string('readtherest', 'forum'));
$postcontent .= html_writer::tag('span', '('.get_string('numwords', 'moodle', count_words(strip_tags($post->message))).')...', array('class'=>'post-word-count'));
} else {
@@ -3795,50 +3796,9 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
* @return string
*/
function forum_shorten_post($message) {
+ global $CFG;
- global $CFG;
-
- $i = 0;
- $tag = false;
- $length = strlen($message);
- $count = 0;
- $stopzone = false;
- $truncate = 0;
-
- for ($i=0; $i<$length; $i++) {
- $char = $message[$i];
-
- switch ($char) {
- case "<":
- $tag = true;
- break;
- case ">":
- $tag = false;
- break;
- default:
- if (!$tag) {
- if ($stopzone) {
- if ($char == ".") {
- $truncate = $i+1;
- break 2;
- }
- }
- $count++;
- }
- break;
- }
- if (!$stopzone) {
- if ($count > $CFG->forum_shortpost) {
- $stopzone = true;
- }
- }
- }
-
- if (!$truncate) {
- $truncate = $i;
- }
-
- return substr($message, 0, $truncate);
+ return shorten_text($message, $CFG->forum_shortpost);
}
/**

0 comments on commit 557b8de

Please sign in to comment.
Something went wrong with that request. Please try again.