the regexes used are bloated, but a quickie fix would be:
if ($this->allow_magic_urls) {
for ($i = 0; $i < 3; $i++) {
$body = preg_replace('#(\n|\r|\]|^|\s|\(|<)([a-zA-Z0-9]+?)://(([a-zA-Z0-9\.\+\,\-\%\_\?=\:\@\#/&\$]|&)+)(>|<|\n|\r|$|,(\s|$)|\?(\s|$)|\)|\s|\.(\s|$))#ie', '\'$1\'.$this->handle_url(\'$2://$3\').\'$5\'', $body);
}
$body = preg_replace('#(\n|\r|\]|^|\s|<|\()www\.(([a-zA-Z0-9\.\+\-\:\,\%\_\@\?&/\#=\$]|&)+)($|>|\)|,(\s|$)|\?(\s|$)|\)(\s|$)|\s|\.(\s|$))#ie', '\'$1\'.$this->handle_url(\'http://www.$2\',\'www.$2\').\'$4\'', $body);
}
search for "if ($this->allow_magic_urls) {"
you'll see the current code there..
if i have time, i can shorten up that code to be cleaner.. i brute force added parsing the '$' and ':' in there.. there is too much escaping than needed, but it works..