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 Using this plugin costs you nearly nothing (not slower), because
9 there most often isn't a "?q=" from a search engine in the referer
12 Modified 20040811 by Jochen Schuh
15 Different search words are now marked different so they could
16 (but must not) styled individually.
19 - I prefer to highlight only in the contents of the page, not in the
20 menu or the list of modules or the footer. This is done with:
24 - To style all of the searchwords the same you can use this rule. Using
25 only this rule would be enough to style all searchwords. But also if
26 you want to style individually such a styling rule is heavily
27 recommended as fallback to style a possible 10. or 42. searchword:
28 .text-body em.highlight {
34 border-color: #000000;
35 background-color: #EEEEEE;
37 - The first few searchwords _can_ easily styled different with:
38 .text-body em.searchword-0 {
39 border-color: #0066FF;
40 background-color: #E8F4FF;
42 .text-body em.searchword-1 {
43 border-color: #FF6600;
44 background-color: #FFF4E8;
49 $ewiki_plugins["page_final"][] = "ewiki_search_highlight";
52 function ewiki_search_highlight(&$o, &$id, &$data, &$action) {
54 $ref = $_SERVER["HTTP_REFERER"];
55 if (strpos($ref, "q=") || strpos($ref, "search=")) {
59 $uu = substr($uu, strpos($uu, "?"));
61 if (($q = $q["q"]) || ($q = $q["search"])) {
63 #-- get words out of it
64 $q = preg_replace('/[^-_\d'.EWIKI_CHARS_L.EWIKI_CHARS_U.']+/', " ", $q);
65 $q = array_unique(explode(" ", $q));
67 #-- walk through words
68 foreach ($q as $key => $word) {
74 while ($l = strpos(strtolower($o), strtolower($word), $l)) {
76 #-- check for html-tags
77 $t0 = strpos($o, "<", $l);
78 $t1 = strpos($o, ">", $l);
79 $found = substr($o, $l, strlen($word));
80 if ((!$t0) || ($t0 < $t1)) {
82 $repl = '<em class="highlight marker searchword-' . $key . '">' . $found . '</em>';
83 $o = substr($o, 0, $l)
85 . substr($o, $l + strlen($word));
90 $l++; // advance strpos