Revision 881
Added by thorn about 16 years ago
frontend.functions.php | ||
---|---|---|
70 | 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 |
static $string_ul_umlauts=array(); |
|
74 |
if($string_ul_umlauts == array()) |
|
73 |
static $string_ul_umlaut = FALSE; |
|
74 |
static $string_ul_regex = FALSE; |
|
75 |
if($string_ul_umlaut===FALSE || $string_ul_regex===FALSE) |
|
75 | 76 |
require(WB_PATH.'/search/search_convert.php'); |
76 | 77 |
$foo = entities_to_umlauts($foo, 'UTF-8'); |
77 | 78 |
array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'/\');')); |
78 | 79 |
$search_string = implode("|", $arr_string); |
79 |
$string = strtr($search_string, $string_ul_umlauts);
|
|
80 |
$string = str_replace($string_ul_umlaut, $string_ul_regex, $search_string);
|
|
80 | 81 |
// the highlighting |
81 | 82 |
// match $string, but not inside <style>...</style>, <script>...</script>, <!--...--> or HTML-Tags |
82 | 83 |
// split $string into pieces - "cut away" styles, scripts, comments, HTML-tags and eMail-addresses |
... | ... | |
86 | 87 |
$foo = ""; |
87 | 88 |
foreach($matches as $match) { |
88 | 89 |
if($match{0}!="<" && !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}$/i', $match)) { |
89 |
$match = strtr($match, array('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"', '''=>'\'', ' '=>"\xC2\xA0"));
|
|
90 |
$match = preg_replace('/('.$string.')/iS', '_span class=_highlight__$1_/span_',$match);
|
|
91 |
$match = strtr($match, array('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"', '\''=>''', "\xC2\xA0"=>' '));
|
|
90 |
$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 | 93 |
$match = str_replace(array('_span class=_highlight__', '_/span_'), array('<span class="highlight">', '</span>'), $match); |
93 | 94 |
} |
94 | 95 |
$foo .= $match; |
... | ... | |
215 | 216 |
if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') { |
216 | 217 |
echo '<a class="section_anchor" id="'.SEC_ANCHOR.$section_id.'" name="'.SEC_ANCHOR.$section_id.'"></a>'; |
217 | 218 |
} |
219 |
|
|
220 |
// fetch content -- this is where to place possible output-filters (before highlighting) |
|
221 |
ob_start(); // fetch original content |
|
222 |
require(WB_PATH.'/modules/'.$module.'/view.php'); |
|
223 |
$content = ob_get_contents(); |
|
224 |
ob_end_clean(); |
|
225 |
|
|
218 | 226 |
// highlights searchresults |
219 |
if (isset($_GET['searchresult']) AND is_numeric($_GET['searchresult']) AND !isset($_GET['nohighlight'])) { |
|
220 |
if (isset($_GET['sstring']) AND !empty($_GET['sstring']) ){ |
|
221 |
$arr_string = explode(" ", $_GET['sstring']); |
|
222 |
if($_GET['searchresult'] == 2) { |
|
223 |
// exact match |
|
224 |
$arr_string[0] = strtr($arr_string[0], "_"," "); |
|
225 |
} |
|
226 |
ob_start(); //start output buffer |
|
227 |
require(WB_PATH.'/modules/'.$module.'/view.php'); |
|
228 |
$foo = ob_get_contents(); // put outputbuffer in $foo |
|
229 |
ob_end_clean(); // clear outputbuffer |
|
230 |
echo search_highlight($foo, $arr_string); |
|
227 |
if(isset($_GET['searchresult']) && is_numeric($_GET['searchresult']) && !isset($_GET['nohighlight']) && isset($_GET['sstring']) && !empty($_GET['sstring'])) { |
|
228 |
$arr_string = explode(" ", $_GET['sstring']); |
|
229 |
if($_GET['searchresult']==2) { // exact match |
|
230 |
$arr_string[0] = str_replace("_", " ", $arr_string[0]); |
|
231 | 231 |
} |
232 |
echo search_highlight($content, $arr_string); |
|
232 | 233 |
} else { |
233 |
require(WB_PATH.'/modules/'.$module.'/view.php');
|
|
234 |
echo $content;
|
|
234 | 235 |
} |
235 | 236 |
} |
236 | 237 |
} else { |
Also available in: Unified diff
search: replaced most of $string_ul_umlauts (from search_convert.php) through use of preg's u-switch. Replaced strtr() by str_replace() (it's just faster). Changed ' to '