adding some strings
[moodle-linuxchix.git] / mod / wiki / ewiki / plugins / moodle / moodle_highlight.php
blob01e7c17ea01b076468f49ec6009004a936496e15
1 <?php // $Id$
3 /*
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:
10 em.highlight {
11 color: red;
14 em.marker {
15 background: yellow;
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
20 url.
25 $ewiki_plugins["page_final"][] = "ewiki_moodle_highlight";
28 function ewiki_moodle_highlight(&$o, &$id, &$data, &$action) {
30 if (strpos($_SERVER["HTTP_REFERER"], "q=")) {
32 #-- PHP versions
33 $stripos = function_exists("stripos") ? "stripos" : "strpos";
35 #-- get ?q=...
36 $uu = $_SERVER["HTTP_REFERER"];
37 $uu = substr($uu, strpos($uu, "?"));
38 parse_str($uu, $q);
39 if ($q = $q["q"]) {
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) {
47 if (empty($word)) {
48 continue;
51 #-- search for 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)
61 . $repl
62 . substr($o, 1 + $l + strlen($word)-1);
64 $l += strlen($repl);
67 $l++; // advance strpos
70 } // foreach(word)
74 } // if(q)
76 } // func