<? /* $Id: searchhighlight.php,v 1.11 2004/02/12 09:12:20 pts00065 Exp $ http://www.brambring.nl bram-a-t-brambring-d-o-t-nl $Log: searchhighlight.php,v $ Revision 1.11 2004/02/12 09:12:20 pts00065 Moved action check into searchhighlight Revision 1.10 2004/02/12 06:56:01 pts00065 Small changes for version 0.6. */ #If PageLayoutFMt is not (re)defined in your local.php or other #script include stdlayout.php here #include_once("scripts/stdlayout.php"); #This is one way to include the search high light. #Another method would be to create a wrapper function arround PrintText; if ( ! $action || ($action=='browse' ) ) { array_push($PageLayoutFmt['wikileft'],"function:highlight_capture_start"); array_unshift($PageLayoutFmt['wikifoot'],"function:highlight_capture_stop"); } function highlight_capture_start() { ob_start(); } function highlight_capture_stop() { # q,sa_q google;p yahoo;text pmwiki $ref_patterns=array("/^search_for=(.*)/","/^query=(.*)/","/^q=(.*)/","/^as_q=(.*)/","/^p=(.*)/","/^text=(.*)/"); $text = ob_get_clean(); $refer=preg_replace("/^.*\?(.*)/","$1",$_SERVER["HTTP_REFERER"]); #$refer="q=Kaasfondue+a+site:http://www.brambring.nl#1&num=20&hl=en&lr=lang_nl|lang_en&ie=UTF-8&oe=UTF-8&start=20&sa=N"; foreach ( explode ("&",$refer) as $qsa ) { $words=preg_replace($ref_patterns,"$1",$qsa); if ( $words != $qsa ) { $words=preg_replace("/[\+\-\"\']/"," ",urldecode($words)); foreach ( explode (" ",$words) as $word ) { if ( $word ) { # in case there where double spaces highlight($text,$word) ; } } } } echo $text; } function highlight(&$text,$word) { $word=preg_replace("/#/","\#",$word); $pregmatch="#(\b)($word)(\b)(?![^<]*>)#i"; $pregreplace="$1<font class='highlight'>$2</font>$3"; $text=preg_replace($pregmatch,$pregreplace,$text); } ?>