Firefox PHP

URL to Link-Hack

Posted by Norfolk 
URL to Link-Hack
June 13, 2001 07:15PM
i am not sure, if there was such a hack available or a similar function. anyway, here is one i have scripted today.

first it look, if there are urls like www.example.com and gives a http:// in front of it

second, it places <a...> and </a>-tags around the URLs, with a target to open the link in a new window.

no urls already in tags, like an <img src="..."> are modified.

if there are already <a...>-tags in the posting, no modifications are done. this is on one hand to avoid the problem of recognizing urls, which already have an <a>-tag around them, and on the other hand, it is the opinion of the author, that if someone uses anchor-tags in his posting, we should not interfere, because he will know, what he is doing.
Attachments:
open | download - url-to-link.txt (1.4 KB)
Re: URL to Link-Hack
July 07, 2001 09:36PM
Nice hack! I've added the function and called it from the READ.PHP file with great success. I've been looked for something like this for a while. Thanks for sharing it.

-Andre
Re: URL to Link-Hack
July 09, 2001 05:04AM
Could you tell us where you added it to read.php?

I don't see it working on a reply message, and if I choose to preview (the preview hack) it doesn't translate the url at all. If I start a new topic it works fine.

- Ståle
I'm sorry. I think I've misunderstood how this thing works.

If I combine <a..> </a> links with www.something.com it doesn't care about www.something.com since the users should know what he's doing due to the fact that he already has used a <a...> </a> link...? If a proper html link is found anywhere in the post it just skips the rest... is this so? If it is it works perfectly both on reply and on preview.

- Ståle

ps. Thanks for your great hack!
Changes in Version 3.2.2a
January 31, 2002 12:47PM
In Version 3.2.2a you have to add the following lines to the read_functions.php file so that the urls are converted correctly:


if(function_exists("preg_replace")){
// handle old legacy <> links by converting them into BB tags
$body=preg_replace("/<((http|https|ftp):\/\/[a-z0-9;\/\?:@=~\&\$\-_\.\+!*'\(\),]+?)>/i", "<a href=\"$1\" target=\"_blank\">$1</a>", $body);
$body=preg_replace("/<a href=\"((http|https|ftp):\/\/[a-z0-9;\/\?:@=~\&\$\-_\.\+!*'\(\),]+?)\" target=\"_blank\">([a-z0-9;\/\?:@=~\&\$\-_\.\+!*'\(\),]+?)<\/a>/i", "<a href=\"$1\" target=\"_blank\">$1</a>", $body);
$body=preg_replace("/[a-z0-9\-_\.\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+?)">([a-z0-9\-_\.\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+?)/i", "<a href=\"mailto:$1\">$1</a>", $body);
}

if you don't have opening the links in a new window enabled just delete the target="_blank" string

:-)

Ondrej
Re: Changes in Version 3.2.2a
February 20, 2002 05:03AM
Hiya Peeps!

Ok I've done this but it still won't work in 3.2.2a..?

Anyone got any ideas, for instance whereabouts do you insert the above code in the read_functions file..?

Any help would be greatfully appreciated.

If anyone is interested in what I'm up to then check out:

[www.elysium-music.com]

Cheers ears,

Bumblepuppy

<HTML>you can actually see where this target=_blank located in the above post.</HTML>

<HTML>you can actually see where this target=_blank located in the above post.</HTML>

Re: Changes in Version 3.2.2a
February 21, 2002 05:01AM
I changed the code so that it works now in 3.2.2a without any changes needed in read_functions.php

if you want to habe the links opened in new windows just change the two lines in read_functions.php to:

$body=preg_replace("/[url\]((http|https|ftp|mailto):\/\/[a-z0-9;\/?:@=\&\$\-_\.\+!*'\(\),]+?)[\/url\]/i", "<a href=\"$1\" arget=_blank>$1</a>", $body);

$body=preg_replace("/[url=((http|https|ftp|mailto):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),]+?)\](.+?)[\/url\]/i", "<a href=\"$1\" target=_blank>$3</a>",$body);

you can find these two lines next to if($ForumAllowHTML==1){

have fun with it
Ondrej

www.chemiestudent.de
Attachments:
open | download - url-to-link.txt (1.4 KB)
Re: Changes in Version 3.2.2a
February 21, 2002 05:32AM
sorry some typing mistakes and I always forget to register to be able to edit my posting, sorry guys!

I changed the code so that it works now in 3.2.2a without any changes needed in read_functions.php

if you want to have the links opened in new windows just change the two lines in read_functions.php to:

$body=preg_replace("/[url\]((http|https|ftp|mailto):\/\/[a-z0-9;\/?:@=\&\$\-_\.\+!*'\(\),]+?)[\/url\]/i", "<a href=\"$1\" target=_blank>$1</a>", $body);

$body=preg_replace("/[url=((http|https|ftp|mailto):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),]+?)\](.+?)[\/url\]/i", "<a href=\"$1\" target=_blank>$3</a>",$body);

you can find these two lines next to if($ForumAllowHTML==1){

have fun with it
Ondrej

www.chemiestudent.de
Re: Changes in Version 3.2.2a
May 18, 2002 06:33AM
Thanks for the hack worked well!
Re: URL to Link-Hack
May 25, 2002 03:38AM
hi .umm. the attachments don't seem to be working. i want to use this hack, but it won't let me download the code.

does this have to do with the hacking?

-j
Simplified Version
May 25, 2002 03:16PM
Maybe I am just a simpleton but with 3.3.2a all I needed to add to get the functionality I wanted was:

$body=eregi_replace("(http://[^ >\n\t]+)", "<a href=\"\\1\">\\1</a>", $body);

I just put that right before "// exec all read plugins" and got everything i need.

Thanks for all of your help!

-Jamund
KHL
Re: URL to Link-Hack
January 29, 2003 01:21PM
The Last post - does it work if you quete a [www.test.dk]

Re: URL to Link-Hack
November 13, 2003 06:56PM
I have Phorum 3.4.4 running on my website and I really would like to use this hack. but Phorum 3.4.4 doesn't support HTML tags any more. Could someone edit this hack with phorum codes so I can use it in phorum 3.4.4.

I hope somebody can do this....

thnx.

Rolo
Sorry, you do not have permission to post/reply in this forum.