PDA

View Full Version : [Can't fix] URLs getting messed up if highlighted


Thomas P
Sat 6th Dec '03, 12:58pm
Hello,

if someone does a search on a word in an URL and goes to that thread the URL is getting messed up.

Look: http://www.mcseboard.de/showthread.php?threadid=17061&highlight=%2Akuma%2A

Versus:
http://www.mcseboard.de/showthread.php?threadid=17061

That's the link

http://www.mcseboard.de/ads/adclick.php?bannerID=25&dest=http%3A%2F%2Fwww.kumagroup.de%2Fseminare%2F&ismap=

tubedogg
Sat 6th Dec '03, 1:00pm
It's because it's trying to highlight the word 'kuma' in the post and apparently having some issues doing it.

Thomas P
Sat 6th Dec '03, 1:08pm
Yeah, I'm getting you so far, is there a fix?

tubedogg
Sat 6th Dec '03, 1:42pm
Not that I'm aware of. Moving to bugs...

Mike Sullivan
Wed 24th Dec '03, 4:35pm
This is unfortunatley unfixable in vB2 as it requires "nested regular expressions", which require the /e flag. This flag didn't appear until PHP4 and vB2 still needs to work in PHP3.

This is fixed in vB3 though.

Thomas P
Sun 28th Dec '03, 10:13am
Could you please post a fix for those who run PHP4 & vb2?

This would be very helpful :)

Mike Sullivan
Mon 5th Jan '04, 12:35pm
Untested, use at your own risk. This is not an official fix.

Add this to functions.php:
// ###################### Start process_highlight_postbit #######################
function process_highlight_postbit($text, $words, $prepend)
{
$text = str_replace('\"', '"', $text);
foreach ($words AS $replaceword)
{
$text = preg_replace('#(?<=[\s"\'\]>()]|^)(' . $replaceword . ')(([.,:;-?!()\s"\'<\[]|$))#siU', '<highlight>\\1</highlight>\\2', $text);
//$text = preg_replace('#(?<=[^\w=])(' . $replaceword . ')(?=[^\w=])#siU', '<highlight>\\1</highlight>', $text);
}
return "$prepend$text";
}

Find:
while (list($key,$val)=each($replacewords)) {
$post['message']=preg_replace('#(?<=[\s"\]>()]|^)(' . $val . ')(([\.,;-?!()]+)?([\s"<\[]|$))#siU', "<highlight>\\1</highlight>\\2", $post['message']);
}
Replace with:
$post['message'] = preg_replace('#(^|>)([^<]+)(?=<|$)#sUe', "process_highlight_postbit('\\2', \$replacewords, '\\1')", $post['message']);

Thomas P
Mon 5th Jan '04, 5:32pm
Thanks a bunch!!