summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/common.php7
-rw-r--r--inc/fulltext.php26
-rw-r--r--inc/html.php6
-rw-r--r--inc/parser/xhtml.php9
4 files changed, 27 insertions, 21 deletions
diff --git a/inc/common.php b/inc/common.php
index 7f550dbde..127276475 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 a0be280bf..59053cb59 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -11,23 +11,20 @@
/**
- * 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 a0ae0110d..5811fd141 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 8add04363..b45e310ca 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'].='&amp;s=';
- $link['url'] .= rawurlencode($search);
+ ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&amp;';
+ if(is_array($search)){
+ $search = array_map('rawurlencode',$search);
+ $link['url'] .= 's[]='.join('&amp;s[]=',$search);
+ }else{
+ $link['url'] .= 's='.rawurlencode($search);
+ }
}
//keep hash