diff --git a/inc/common.php b/inc/common.php index 7f550dbde95ad4da7cd07b1583caeba67fe4f2ab..1272764751e21f49cdbc196613d875d4cb2144f5 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1197,6 +1197,11 @@ function php_to_byte($v){ return $ret; } - +/** + * Wrapper around preg_quote adding the default delimiter + */ +function preg_quote_cb($string){ + return preg_quote($string,'/'); +} //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/fulltext.php b/inc/fulltext.php index a0be280bf57dde3ddfc5c658ba2ac82b1c3037a2..59053cb599e1d7afe45b5f7a32905ff56db49bcc 100644 --- a/inc/fulltext.php +++ b/inc/fulltext.php @@ -10,24 +10,21 @@ require_once(DOKU_INC.'inc/indexer.php'); -/** - * Wrapper around preg_quote adding the default delimiter - */ -function ft_preg_quote_cb($string){ - return preg_quote($string,'/'); -} - /** * The fulltext search * * Returns a list of matching documents for the given query * */ -function ft_pageSearch($query,&$regex){ +function ft_pageSearch($query,&$highlight){ $q = ft_queryParser($query); + $highlight = array(); + // remember for hilighting later - $regex = str_replace('*','',join('|',$q['words'])); + foreach($q['words'] as $wrd){ + $highlight[] = str_replace('*','',$wrd); + } // lookup all words found in the query $words = array_merge($q['and'],$q['not']); @@ -76,12 +73,10 @@ function ft_pageSearch($query,&$regex){ if(!count($docs)) return array(); // handle phrases if(count($q['phrases'])){ - //build a regexp $q['phrases'] = array_map('utf8_strtolower',$q['phrases']); - $q['phrases'] = array_map('ft_preg_quote_cb',$q['phrases']); // use this for higlighting later: - if($regex !== '') $regex .= '|'; - $regex .= join('|',$q['phrases']); + $highlight = array_merge($highlight,$q['phrases']); + $q['phrases'] = array_map('preg_quote_cb',$q['phrases']); // check the source of all documents for the exact phrases foreach(array_keys($docs) as $id){ $text = utf8_strtolower(rawWiki($id)); @@ -250,13 +245,16 @@ function ft_pageLookup($id,$pageonly=true){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function ft_snippet($id,$re){ +function ft_snippet($id,$highlight){ $text = rawWiki($id); $match = array(); $snippets = array(); $utf8_offset = $offset = $end = 0; $len = utf8_strlen($text); + // build a regexp from the phrases to highlight + $re = join('|',array_map('preg_quote_cb',array_filter((array) $highlight))); + for ($cnt=3; $cnt--;) { if (!preg_match('#('.$re.')#iu',$text,$match,PREG_OFFSET_CAPTURE,$offset)) break; diff --git a/inc/html.php b/inc/html.php index a0ae0110d29e5651667f18287f5f690b9428ad5f..5811fd141945acfcf3524afaff399e1fe457a427 100644 --- a/inc/html.php +++ b/inc/html.php @@ -262,10 +262,8 @@ function html_draft(){ * @author Andreas Gohr <andi@splitbrain.org> * @author Harry Fuecks <hfuecks@gmail.com> */ -function html_hilight($html,$regex){ - // strip everything that's special except pipes: - $regex = preg_replace('![\[\]()/\\\\?\.+*]+!','',$regex); - $regex = join('|',array_filter(array_map('trim',explode('|',$regex)))); +function html_hilight($html,$phrases){ + $regex = join('|',array_map('preg_quote_cb',array_filter((array) $phrases))); if ($regex === '') return $html; $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html); diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 8add0436388f53525d2c9a895aae248311737845..b45e310cad52b6a5bde9b08cf7dc69f7fce52068 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -517,8 +517,13 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['title'] = $id; //add search string if($search){ - ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&s='; - $link['url'] .= rawurlencode($search); + ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; + if(is_array($search)){ + $search = array_map('rawurlencode',$search); + $link['url'] .= 's[]='.join('&s[]=',$search); + }else{ + $link['url'] .= 's='.rawurlencode($search); + } } //keep hash