]> git.mjollnir.org Git - s9y.git/commitdiff
Add search term highlighting, in the form of <span> tags with
authorslothman <slothman>
Wed, 27 Sep 2006 02:36:37 +0000 (02:36 +0000)
committerslothman <slothman>
Wed, 27 Sep 2006 02:36:37 +0000 (02:36 +0000)
both foundterm and foundtermN class.

include/functions_entries.inc.php

index d29a5bbda86958dd2c415a3cd4c8bad3e509ff9d..7282df82f9cd97f070a27e5655fb7cdc225a7b92 100644 (file)
@@ -920,6 +920,18 @@ function serendipity_printEntries($entries, $extended = 0, $preview = false, $sm
                 $entry['is_cached'] = true;
             }
 
+           //--JAM: Highlight-span search terms
+           if ($serendipity['action'] == 'search') {
+               $searchterms = str_replace('"', '', $serendipity['GET']['searchterms']);
+               $searchterms = explode($searchterms, ' ');
+               foreach($searchterms as $searchdx => $searchterm) {
+                   $searchclass = "foundterm foundterm".$searchdx;
+                   $entry['body'] = preg_replace('/('.$searchterm.')/mi',
+                       '<span class="'.$searchclass.'">\1</span>',
+                       $entry['body']);
+               }
+           }
+
             if (!empty($entry['properties']['ep_cache_extended'])) {
                 $entry['extended']  = &$entry['properties']['ep_cache_extended'];
                 $entry['is_cached'] = true;
@@ -1509,4 +1521,4 @@ function serendipity_getTotalCount($what) {
             return $res['sum'];
 
     }
-}
\ No newline at end of file
+}