4 CSS-highlights the terms used as search patterns. This is done
5 by evaluating the REFERRER and using the QUERY_STRINGs "q="
6 parameter (which is used by Google and ewikis` PowerSearch).
8 Highlighting color should be controlled from CSS:
18 Using this plugin costs you nearly nothing (not slower), because
19 there most often isn't a "?q=" from a search engine in the referer
25 $ewiki_plugins["page_final"][] = "ewiki_moodle_highlight";
28 function ewiki_moodle_highlight(&$o, &$id, &$data, &$action) {
30 if (strpos($_SERVER["HTTP_REFERER"], "q=")) {
33 $stripos = function_exists("stripos") ?
"stripos" : "strpos";
36 $uu = $_SERVER["HTTP_REFERER"];
37 $uu = substr($uu, strpos($uu, "?"));
41 #-- get words out of it
42 $q = preg_replace('/[^-_\d'.EWIKI_CHARS_L
.EWIKI_CHARS_U
.']+/', " ", $q);
43 $q = array_unique(explode(" ", $q));
44 #-- walk through words
45 foreach ($q as $word) {
52 while ($l = $stripos(strtolower($o), strtolower($word), $l)) {
54 #-- check for html-tags
55 $t0 = strpos($o, "<", $l);
56 $t1 = strpos($o, ">", $l);
57 if ((!$t0) ||
($t0 < $t1)) {
59 $repl = '<em class="highlight marker">' . $word . '</em>';
60 $o = substr($o, 0, $l)
62 . substr($o, 1 +
$l +
strlen($word)-1);
67 $l++
; // advance strpos