Home
>
Outdated forums
>
Phorum 3 forums (READ ONLY)
>
Finished Mods and Plug-ins (READ ONLY)
>
Topic
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.
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.
Re: URL to Link-Hack July 07, 2001 09:36PM |
Re: URL to Link-Hack July 09, 2001 05:04AM |
Re: URL to Link-Hack - misunderstanding July 09, 2001 05:13AM |
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!
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
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 |
Registered: 22 years ago Posts: 10 |
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
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
<b>Re: Changes in Version 3.2.2a</b> February 20, 2002 06:13PM |
<b>Re: Changes in Version 3.2.2a</b> February 20, 2002 06:13PM |
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
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
Re: Changes in Version 3.2.2a February 21, 2002 05:32AM |
Registered: 22 years ago Posts: 3 |
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
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 |
Registered: 22 years ago Posts: 3 |
Re: URL to Link-Hack May 25, 2002 03:38AM |
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
$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
Re: URL to Link-Hack January 29, 2003 01:21PM |
Registered: 23 years ago Posts: 7 |
Re: URL to Link-Hack November 13, 2003 06:56PM |
Sorry, you do not have permission to post/reply in this forum.