Print Page | Close Window

Auto link URLs

Printed From: Web Wiz Forums
Category: Web Wiz Web App Support Forums
Forum Name: Web Wiz Forums Modifications
Forum Description: Mod's and Add-on's for Web Wiz Forums.
URL: https://forums.webwiz.net/forum_posts.asp?TID=23023
Printed Date: 30 March 2026 at 5:57am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Auto link URLs
Posted By: User123
Subject: Auto link URLs
Date Posted: 31 March 2007 at 6:58am
Unless I'm missing an option somewhere it appears that WebWiz does not auto detect URLs in posts and make them hyperlinks.  Is there a mod already to do this?  Just wanted to check before I embarked on adding this feature on my own Smile

TIA



Replies:
Posted By: User123
Date Posted: 02 April 2007 at 5:52am
Well I guess no one has done this.  I've added this feature on my own to the functions_format_post.asp file.


Posted By: wistex
Date Posted: 02 April 2007 at 7:17am
I think IE automatically turns it into a link, but Firefox does not, if I recall.

-------------
http://www.wistex.com" rel="nofollow - WisTex Solutions
http://www.caribbeanchoice.com/forums" rel="nofollow - CaribbeanChoice Forums


Posted By: User123
Date Posted: 02 April 2007 at 10:09pm
Neither IE nor FF find URLs and make them clickable without add-ons.

If anyone wants it, here is my current code for converting URLs typed into messages without [ URL ] [ / URL ] tags.

As always, use at your own risk - it may not be fully debugged or handle every scenario.

This goes in the file functions\functions_format_post.asp at the end of the FormatForumCodes function right before the final return value assignment (FormatForumCodes = strMessage).


Edit: (4/17/07) See post below for current source code.


Posted By: freakyfred
Date Posted: 03 April 2007 at 11:17am
thanks mate. Good of you to share :)


Posted By: User123
Date Posted: 05 April 2007 at 4:44am
Well, if you used that piece of code above please copy it again and overwrite the previous code.  I was referencing the wrong variable in both preprocessing loops which would in some cases cause an infinite loop.  I also reversed the preprocessing steps (images first, then anchors) for better performance.


Posted By: freakyfred
Date Posted: 11 April 2007 at 1:35pm
For some reason(not sure why) if you install this it will disrupt the flash tags.


Posted By: User123
Date Posted: 11 April 2007 at 4:41pm
Anything that uses URLs in it needs to be stripped before looking for un-coded URLs.  That's why the pre-processing loops remove img and anchor tags.  We don't allow Flash and other embedded objects on our forums so I hadn't accounted for that.

Assuming the Flash codes uses the "embed" tags to insert videos the following code should fix the problems:

    'CLAN MOD START - find uncoded URLs and turn into clickable URLs
    dim testMsg, testPos
    testMsg = strMessage
    'PRE-PROCESS STEPS (remove URLs which already have valid codes around them)
    'remove images
    lngStartPos = InStr(1, testMsg, "<img", 1)
    While lngStartPos > 0
        lngEndPos = Instr(lngStartPos, testMsg, ">", 1)
        if lngEndPos = 0 then
            lngEndPos = len(testMsg)+1
        else
            lngEndPos = lngEndPos + 1
        end if
        strMessageLink = Mid(testMsg,lngStartPos,lngEndPos-lngStartPos)
        testMsg = replace(testMsg, strMessageLink, "")
        lngStartPos = InStr(1, testMsg, "<img", 1)
    Wend
    'remove linked URLs
    lngStartPos = InStr(1, testMsg, "<a", 1)
    While lngStartPos > 0
        lngEndPos = Instr(lngStartPos, testMsg, "</a", 1)
        if lngEndPos = 0 then
            lngEndPos = len(testMsg)+1
        else
            lngEndPos = lngEndPos + 4
        end if
        strMessageLink = Mid(testMsg,lngStartPos,lngEndPos-lngStartPos)
        testMsg = replace(testMsg, strMessageLink, "")
        lngStartPos = InStr(1, testMsg, "<a", 1)
    Wend
    'remove Flash links
    lngStartPos = InStr(1, testMsg, "[flash", 1)
    While lngStartPos > 0
        lngEndPos = Instr(lngStartPos, testMsg, "[/flash", 1)
        if lngEndPos = 0 then
            lngEndPos = len(testMsg)+1
        else
            lngEndPos = lngEndPos + 8
        end if
        strMessageLink = Mid(testMsg,lngStartPos,lngEndPos-lngStartPos)
        testMsg = replace(testMsg, strMessageLink, "")
        lngStartPos = InStr(1, testMsg, "[flash", 1)
    Wend
    'look for uncoded URLs
    lngStartPos = InStr(1, testMsg, "http://", 1)
    if lngStartPos = 0 then lngStartPos = InStr(1, testMsg, "https://", 1)
    if lngStartPos = 0 then lngStartPos = InStr(1, testMsg, "ftp://", 1)
    if lngStartPos = 0 then lngStartPos = InStr(1, testMsg, "mailto:", 1)
    While lngStartPos > 0
        'determine full URL by finding the first "break" type character
        lngEndPos = Instr(lngStartPos, testMsg, " ", 1)
        testPos = Instr(lngStartPos, testMsg, "&nbsp;", 1)
        if lngEndPos = 0 or (testPos > 0 and testPos < lngEndPos) then lngEndPos = testPos
        testPos = Instr(lngStartPos, testMsg, VbCr)
        if lngEndPos = 0 or (testPos > 0 and testPos < lngEndPos) then lngEndPos = testPos
        testPos = Instr(lngStartPos, testMsg, "<", 1)
        if lngEndPos = 0 or (testPos > 0 and testPos < lngEndPos) then lngEndPos = testPos
        if lngEndPos = 0 then    'no break character found, assume end of message
            lngEndPos = len(testMsg)+1
        end if
        'extract link
        strMessageLink = Mid(testMsg,lngStartPos,lngEndPos-lngStartPos)
        'remove from test message so we don't process it again
        testMsg = replace(testMsg, strMessageLink, "")
        'turn into clickable URL in main message
        strMessage = replace(strMessage,strMessageLink, "<a href=""" & strMessageLink & """>" & strMessageLink & "</a>", 1, -1, 1)
        'look for next link
        lngStartPos = InStr(1, testMsg, "http://", 1)
        if lngStartPos = 0 then lngStartPos = InStr(1, testMsg, "https://", 1)
        if lngStartPos = 0 then lngStartPos = InStr(1, testMsg, "ftp://", 1)
        if lngStartPos = 0 then lngStartPos = InStr(1, testMsg, "mailto:", 1)
    wend
    'CLAN MOD END - find uncoded URLs and turn into clickable URLs



Edit: (4/18/07) Fixed bug in Flash tag processing


Posted By: freakyfred
Date Posted: 12 April 2007 at 9:01am
nope it still does not work. There is part of the code being stripped i think.

http://www.youtube.com/v/Ms_ZBPvjVO0" quality=high width=400 height=400 type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">

is what i get


Posted By: User123
Date Posted: 12 April 2007 at 4:35pm
Ok 3rd time's a charm maybe? I changed the post above (the 2nd one with the "Edit: added removal of object tags") to have yet another pre-processing step which removes all "< object ></ object >" blocks.  I looked on YouTube and it appears ShockWave and other plug-ins use these blocks to reference their material.  By removing them prior to looking for the un-coded URLs it should prevent the post from being messed up.  When you get a chance feel free to try the latest mod code once again and let me know if you have further problems.


Posted By: freakyfred
Date Posted: 13 April 2007 at 2:23pm
No still the same i'm afraid. Thanks for the input and time on this though, much appreciated.  Smile


Posted By: User123
Date Posted: 13 April 2007 at 6:16pm
Not a problem   I'm going to enable Flash file support on my forum and test it out.  My other thought is the flash tags aren't processed until a later step so this routine is causing problems "before" the flash tags are interpreted.  I can work around that if it turns out to be the case.  It will probably be Monday before I can post an update to the code.


Posted By: freakyfred
Date Posted: 14 April 2007 at 10:24am
cool thanks for the info.


Posted By: User123
Date Posted: 17 April 2007 at 10:23am
Ok Freaky, I've updated the code once again on the post from 4/11 (there's an edit note showing it was changed today - 4/17).  As I surmised, the Flash tags are not processed yet when that function is called.  I've modified the script to properly ignore the flash tags.

Let me know if you still run into problems.


Posted By: freakyfred
Date Posted: 17 April 2007 at 10:52am
seems perfect now. thanks again for your help.


Posted By: freakyfred
Date Posted: 18 April 2007 at 9:14am
still bringing up errors mate. Just had reports from some members.. seems that only the http:// is showing up as a link and the rest is just text. Also it has messed up the images bit.


Posted By: User123
Date Posted: 18 April 2007 at 2:43pm
Some day I'll get it right   There was yet another cut'n'paste error on my part in the flash preprocessing loop.  I've corrected it.  Maybe, just maybe, it will be solid now.


Posted By: freakyfred
Date Posted: 19 April 2007 at 10:10pm
lol k thanks i wil try it first thing tomoro.

Practice makes perfect and all that.

Again. thanks for your help.Thumbs%20Up


Posted By: freakyfred
Date Posted: 20 April 2007 at 1:23pm
seems to be working fine mate. I have tested it as much as i think i can. Thanks for the help


Posted By: freakyfred
Date Posted: 26 April 2007 at 3:48pm
This mod is not compatible with the Vide Mod created by Scotty.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net