mod-forum MDLSITE-1073 Fixed up the search highlighting in forum post messages
authorSam Hemelryk <sam@moodle.com>
Tue, 12 Oct 2010 01:59:32 +0000 (01:59 +0000)
committerSam Hemelryk <sam@moodle.com>
Tue, 12 Oct 2010 01:59:32 +0000 (01:59 +0000)
mod/forum/search.php

index ae02c98..d843779 100644 (file)
@@ -234,16 +234,19 @@ foreach ($posts as $post) {
 
     $options = new stdClass();
     $options->trusted = $post->messagetrust;
-    $message = highlight($strippedsearch,
+    $post->message = highlight($strippedsearch,
                     format_text($post->message, $post->messageformat, $options, $course->id),
                     0, '<fgw9sdpq4>', '</fgw9sdpq4>');
 
     foreach ($searchterms as $searchterm) {
-        if (preg_match("/$searchterm/i",$message) && !preg_match('/<fgw9sdpq4>'.$searchterm.'<\/fgw9sdpq4>/i',$message)) {
+        if (preg_match("/$searchterm/i",$post->message) && !preg_match('/<fgw9sdpq4>'.$searchterm.'<\/fgw9sdpq4>/i',$post->message)) {
             $missing_terms .= " $searchterm";
         }
     }
 
+    $post->message = str_replace('<fgw9sdpq4>', '<span class="highlight">', $post->message);
+    $post->message = str_replace('</fgw9sdpq4>', '</span>', $post->message);
+
     if ($missing_terms) {
         $strmissingsearchterms = get_string('missingsearchterms','forum');
         $post->message = '<p class="highlight2">'.$strmissingsearchterms.' '.$missing_terms.'</p>'.$post->message;
@@ -253,8 +256,8 @@ foreach ($posts as $post) {
     $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".get_string("postincontext", "forum")."</a>";
 
     // Now pring the post.
-    forum_print_post($post, $discussion, $forum, $cm, $course, false, false, false, false,
-            $fulllink, $strippedsearch, -99, false);
+    forum_print_post($post, $discussion, $forum, $cm, $course, false, false, false,
+            $fulllink, '', -99, false);
 }
 
 echo $OUTPUT->paging_bar($totalcount, $page, $perpage, $url);