1 (edited by chrizz 2006-01-10 14:02)

Topic: bbc code and urls

This might not be considered as bug, but rather a strange behaviour. At least thats my opinion.

I posted a link recently this way:

[url=http://www.dn.se/DNet/jsp/polopoly.jsp?d=1298&a=511671&previousRenderType=6]KRÖNIKA: Rika bilförare är de verkliga vinnarna (www.dn.se)[/url]

And it becomes this way:
KRÖNIKA: Rika bilförare är de verkliga vinnarna ([url=http://www.dn.se]www.dn.se)[/url]

Notice that the short URL becomes an own url in the title of the long one. Two in one that is.

My opinion is that any text between the url tags (if it's written to be title like above) should be just that; a title. It should not be able to be parsed as an url itself.

Well, the world may have bigger problems than this, but I thought it could be worth mentioning anyway.

Re: bbc code and urls

In Admin/Options you can deselect the checkbox that makes this happen... [shrug /]

Re: bbc code and urls

It's not as easy as it sounds to fix, but I'll put it on the list.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: bbc code and urls

CableGuy wrote:

In Admin/Options you can deselect the checkbox that makes this happen... [shrug /]

That disables it everywhere, and thats not wanted.

Re: bbc code and urls

Ok, heres an attempt

//
// Make hyperlinks clickable
//
function do_clickable($text)
{
    global $pun_user;

    $text = "[a] ".$text;

    $text = preg_replace('#(\[(?!url)[^\]]*?\][^\]]*?[\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.handle_url_tag(\'$2://$3\')', $text);
    $text = preg_replace('#(\[(?!url)[^\]]*?\][^\]]*?[\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.handle_url_tag(\'$2.$3\', \'$2.$3\')', $text);

    return substr($text, 4);
}

How it works is it forces the last bit of bbcode before the clickable link to not be [url.....], the catch is we have to prepend a dummy bbcode to the text then remove it at the end or any links added before bbcode won't get parsed.

If anyone is interested
(\[(?!url)[^\]]*?\][^\]]*?[\s\(\)])
is the important bit is
and its in ( ) as it needs to be added back, and it means
[ not followed by url, then followed by any number of characters except ], then a ], then any characters except ] (this is so it doesn't find another bbcode before the [url]and match that), then the space/(/) that is allowed before the url.

Also out of interest why "global $pun_user;"? Its on a couple of others that don't use it too i think.

Re: bbc code and urls

I think initially it was used in handle_url_tag() which is called via the regex, so it needed to be there, but now I don't think it's used anymore.

"Programming is like sex: one mistake and you have to support it for the rest of your life."