67 |
67 |
}
|
68 |
68 |
|
69 |
69 |
//function to highlight search results
|
70 |
|
if (!function_exists('search_highlight')) {
|
|
70 |
if(!function_exists('search_highlight')) {
|
71 |
71 |
function search_highlight($foo='', $arr_string=array()) {
|
72 |
72 |
require_once(WB_PATH.'/framework/functions.php');
|
73 |
73 |
static $string_ul_umlaut = FALSE;
|
... | ... | |
75 |
75 |
if($string_ul_umlaut===FALSE || $string_ul_regex===FALSE)
|
76 |
76 |
require(WB_PATH.'/search/search_convert.php');
|
77 |
77 |
$foo = entities_to_umlauts($foo, 'UTF-8');
|
78 |
|
array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'/\');'));
|
|
78 |
array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'~\');'));
|
79 |
79 |
$search_string = implode("|", $arr_string);
|
80 |
80 |
$string = str_replace($string_ul_umlaut, $string_ul_regex, $search_string);
|
81 |
81 |
// the highlighting
|
82 |
82 |
// match $string, but not inside <style>...</style>, <script>...</script>, <!--...--> or HTML-Tags
|
83 |
83 |
// split $string into pieces - "cut away" styles, scripts, comments, HTML-tags and eMail-addresses
|
|
84 |
// we have to cut <pre> and <code> as well.
|
84 |
85 |
// for HTML-Tags use <(?:[^<]|<.*>)*> which will match strings like <input ... value="<b>value</b>" >
|
85 |
|
$matches = preg_split("/(<style.*<\/style>|<script.*<\/script>|<!--.*-->|<(?:[^<]|<.*>)*>|\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}\b)/iUs",$foo,-1,(PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY));
|
|
86 |
$matches = preg_split("~(<style.*</style>|<script.*</script>|<pre.*</pre>|<code.*</code>|<!--.*-->|<(?:[^<]|<.*>)*>|\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}\b)~iUs",$foo,-1,(PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY));
|
86 |
87 |
if(is_array($matches) && $matches != array()) {
|
87 |
88 |
$foo = "";
|
88 |
89 |
foreach($matches as $match) {
|
89 |
90 |
if($match{0}!="<" && !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}$/i', $match)) {
|
90 |
91 |
$match = str_replace(array('<', '>', '&', '"', ''', ' '), array('<', '>', '&', '"', '\'', "\xC2\xA0"), $match);
|
91 |
|
$match = preg_replace('/('.$string.')/ui', '_span class=_highlight__$1_/span_',$match);
|
92 |
|
$match = str_replace(array('<', '>', '&', '"', '\'', "\xC2\xA0"), array('<', '>', '&', '"', ''', ' '), $match);
|
|
92 |
$match = preg_replace('~('.$string.')~ui', '_span class=_highlight__$1_/span_',$match);
|
|
93 |
$match = str_replace(array('&', '<', '>', '"', '\'', "\xC2\xA0"), array('&', '<', '>', '"', ''', ' '), $match);
|
93 |
94 |
$match = str_replace(array('_span class=_highlight__', '_/span_'), array('<span class="highlight">', '</span>'), $match);
|
94 |
95 |
}
|
95 |
96 |
$foo .= $match;
|
fixed two issues with searchresult-highlighting: do not highlight in