Don't highlight search terms inside url

darcs-hash:20080720033401-533db-05bf2c9ebe988ebda6a295447a958af66571a088.gz
This commit is contained in:
Mike Cochrane 2008-07-19 23:34:01 -04:00
parent a1515e5411
commit 58ae93a621
1 changed files with 7 additions and 0 deletions

View File

@ -139,8 +139,15 @@ class NoticesearchAction extends SearchAction {
}
function highlight($text, $terms) {
/* Highligh serach terms */
$pattern = '/('.implode('|',array_map('htmlspecialchars', $terms)).')/i';
$result = preg_replace($pattern, '<strong>\\1</strong>', $text);
/* Remove highlighting from inside links, loop incase multiple highlights in links */
$pattern = '/(href="[^"]*)<strong>('.implode('|',array_map('htmlspecialchars', $terms)).')<\/strong>([^"]*")/iU';
do {
$result = preg_replace($pattern, '\\1\\2\\3', $result, -1, $count);
} while ($count);
return $result;
}
}