Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/Code)
 MOD: Alternate edit_hrefs function in VBScript
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 12 November 2004 :  15:54:17  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
This is a stable function

I wrote this due to certain issues that apply to url linking and snitz, that have been addressed in different ways, maybe this is the answer, maybe it isnt. Might as well give it a try.

Note!:
If you have used either one of my previous "fixes" for either punctuation or the www issue, remove them first!

Description
This should address the issue of punctuation after links, and should also address the issue of "awww..."; also some users who may be concerned about a performance hit by switching server side scripting languages for the edit hrefs function might be interested in this (although I dont think there is much of a performance hit).

Step 1
Either comment out, or delete, or re-name the old edit_hrefs function, found in inc_func_common.asp (I recommend re-naming it)

Step 2
Put the following 2 functions in your inc_func_common.asp file

Step 3
Test it. I've tested it both outside and inside of snitz, and it seems to work the way it is supposed to. Let me know if anything different pops up.

Updates
11/12/04 - updated to be less code; maintaining functionality
11/12/04 - updated again to be less code...
11/13/04 - updated a couple little bugs


'#### Start new edit_hrefs function (by Stimmy)
Function edit_hrefs(fURLstr, fType)
Dim sURLArr, endChar, atLoc, dotLoc, fPrefix
  fURLstr = replace(fURLstr, "<br />", " <br>")
    sURLArr = Split(fURLstr, " ")
Select Case Cint(fType)
  Case 1
    fPrefix = "http://"
  Case 2
    fPrefix = "https://"
  Case 3
    fPrefix = "www."
  Case 4
    For i=0 to Ubound(sURLArr)
	  atLoc = Cint(InStr(sURLArr(i), "@"))
	  dotLoc = InStrRev(sURLArr(i), ".")
	  if atLoc>1 And dotLoc>0 then
	    endChar = Right(sURLArr(i),1)
		Select Case endChar
		  Case ".",",","!","?",":",";"
		    sURLArr(i) = Left(sURLArr(i), Len(sURLArr(i))-1)
		  Case else
		    endChar = ""
		End Select
	   sURLArr(i) = "<a href=""mailto:" & sURLArr(i) & """ target=""_blank"">" & _
	   sURLArr(i) & endChar & "</a>"
	  end if
	Next
  Case 5
    fPrefix = "ftp://"
  Case 6
    fPrefix = "file://"
End Select
Select Case Cint(fType)
  Case 1,2,3,5,6
    For i=0 to Ubound(sURLArr)
	 if ((Left(sURLArr(i), len(fPrefix)) = fPrefix) and  (len(sURLArr(i))>(len(fPrefix)+1)) and (InStr(sURLArr(i), ".")>0)) then
	   endChar = Right(sURLArr(i),1)
	   Select Case endChar
	     Case ".",",","!","?",":",";"
		   sURLArr(i) = Left(sURLArr(i), Len(sURLArr(i))-1)
		 Case else
		   endChar = ""
	   End Select
       
	   if ((fType=3) and (VerifyWWW(sURLArr(i))=True)) then
	     sURLArr(i) = "http://" & sURLArr(i)
		 sURLArr(i) = "<a href=""" & sURLArr(i) & """ target=""_blank"">" & _
		 sURLArr(i) & endChar & "</a>"
	   end if
	   if not(fTYpe=3) then
	     sURLArr(i) = "<a href=""" & sURLArr(i) & """ target=""_blank"">" & _
	     sURLArr(i) & endChar & "</a>"
	   end if
	 end if
	Next
End Select  
edit_hrefs = Join(sURLArr, " ")
edit_hrefs = replace(edit_hrefs, " <br>", "<br />")
End Function
'#### end new_edit_hrefs function

The below function is required for the above to work

'#### Start verify WWW function (required for edit_hrefs to work)
Function VerifyWWW(fString)
Dim tStr
VerifyWWW = False
if Left(fString, 4)="www." then
  if InStr(6, fString, ".")>0 Then
    if Not(InStr(5, fString, "..")>0) Then
      VerifyWWW = True
	end if
  end if
end if
End Function

-Stim

Edited by - Da_Stimulator on 28 November 2004 04:07:07

PeeWee.Inc
Senior Member

United Kingdom
1893 Posts

Posted - 12 November 2004 :  17:06:56  Show Profile  Visit PeeWee.Inc's Homepage
The code seems quite bloated for what it does. Cant the two code edits (fix) do everything this does or am i missing something?

De Priofundus Calmo Ad Te Damine
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 12 November 2004 :  17:45:29  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
I just updated it to take up less space, still the same functionality however.

If you remove those other fixes I posted, and use this, it actually evens out to be about the same amount of code, if not less (because you are removing the extra javascript function)

-Stim
Go to Top of Page

Carefree
Advanced Member

Philippines
4207 Posts

Posted - 13 November 2004 :  00:04:57  Show Profile
works well, thx
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 13 November 2004 :  00:07:59  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
I just updated both of the functions after you posted, you might wanna update it otherwise you may come across some problems.

-Stim

Edited by - Da_Stimulator on 13 November 2004 01:50:19
Go to Top of Page

PeeWee.Inc
Senior Member

United Kingdom
1893 Posts

Posted - 13 November 2004 :  06:47:17  Show Profile  Visit PeeWee.Inc's Homepage
The code looks alot clearner now.

When i have a little time later i'll add this to speedball and test it out.

De Priofundus Calmo Ad Te Damine
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 14 November 2004 :  02:00:37  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
How'd it go PeeWee?

Has anyone else used it? thoughts, opinions, fixes.... I'm not used to not having to debug with in 2 days.... i guess thats a good thing

-Stim

Edited by - Da_Stimulator on 15 November 2004 00:00:48
Go to Top of Page

aspwiz
Junior Member

250 Posts

Posted - 15 November 2004 :  04:40:06  Show Profile  Visit aspwiz's Homepage
I still think the whole link handling process could be a lot cleaner by using regular expressions.... although this code is a big improvement!

Way to go Stim!
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 15 November 2004 :  06:23:34  Show Profile  Visit HuwR's Homepage
we tried with regular expressions before, but a lot of users complained that there hosts had versions of ASP that didn't support them.
Go to Top of Page

Gargoyle
Junior Member

USA
280 Posts

Posted - 22 November 2004 :  19:47:54  Show Profile  Visit Gargoyle's Homepage
This rocks!!! Great job stimy!!

Here is a link to my Snitz powered Drag Racing site.
Go to Top of Page

pixuk
Starting Member

United Kingdom
7 Posts

Posted - 02 December 2004 :  13:36:14  Show Profile  Visit pixuk's Homepage
Is there a mod (or can this mod be tweaked) to wrap all links up in javascript? ie, if there's an active link to be rendered, you can get the code to pass the url to a javascript function that will open the window and display the link?

I have a standard Javascript window opener on my main site, and like to use it in the forum too, but any mods I've made so far while tinkering have just produced a string of code including the javascript where the link should be.

Any tips where to look to make mods?

Thanks,

Pete

The Virgin Atlantic Flyer Resource using Snitz Forums since Nov 03, and lovin' it.
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 02 December 2004 :  14:07:44  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
Could be done easily probably, mind if I see the javascript functions you've already got going on your site? I'll see what I can do :)

-Stim
Go to Top of Page

pixuk
Starting Member

United Kingdom
7 Posts

Posted - 02 December 2004 :  14:55:11  Show Profile  Visit pixuk's Homepage
Well, it's called by using a function called open_win('[url-goes-here]')

In other places, I just use the HTML a href="javascript:open_win('[url-goes-here]');"

So I guess what I need to do is look for the bit of code in Snitz which pulls the URLs out, and then put the appropriate code into that (although early attempts have so far proved fruitless! - possibly because I don't know where to add the mod).

Thanks,

Pete

The Virgin Atlantic Flyer Resource using Snitz Forums since Nov 03, and lovin' it.
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 02 December 2004 :  15:01:26  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
The below should do the trick, however it will only work when someone just puts in the http:// whatever . ext, if they use the [url="stuff tag, then it might not work... You'd have to do some other editing in order to get that to work.

anyhow, here's your customized function (make sure you include the VerifyWWW function in the first post)

Put this (and VerifyWWW) in your inc_func_common.asp file, and rename the old one (at the very bottom of the file) to something like 'edit_hrefs_old'


'#### Start new edit_hrefs function (by Stimmy)
Function edit_hrefs(fURLstr, fType)
Dim sURLArr, endChar, atLoc, dotLoc, fPrefix
  fURLstr = replace(fURLstr, "<br />", " <br>")
    sURLArr = Split(fURLstr, " ")
Select Case Cint(fType)
  Case 1
    fPrefix = "http://"
  Case 2
    fPrefix = "https://"
  Case 3
    fPrefix = "www."
  Case 4
    For i=0 to Ubound(sURLArr)
	  atLoc = Cint(InStr(sURLArr(i), "@"))
	  dotLoc = InStrRev(sURLArr(i), ".")
	  if atLoc>1 And dotLoc>0 then
	    endChar = Right(sURLArr(i),1)
		Select Case endChar
		  Case ".",",","!","?",":",";"
		    sURLArr(i) = Left(sURLArr(i), Len(sURLArr(i))-1)
		  Case else
		    endChar = ""
		End Select
	   sURLArr(i) = "<a href=""mailto:" & sURLArr(i) & """ target=""_blank"">" & _
	   sURLArr(i) & endChar & "</a>"
	  end if
	Next
  Case 5
    fPrefix = "ftp://"
  Case 6
    fPrefix = "file://"
End Select
Select Case Cint(fType)
  Case 1,2,3,5,6
    For i=0 to Ubound(sURLArr)
	 if ((Left(sURLArr(i), len(fPrefix)) = fPrefix) and  (len(sURLArr(i))>(len(fPrefix)+1)) and (InStr(sURLArr(i), ".")>0)) then
	   endChar = Right(sURLArr(i),1)
	   Select Case endChar
	     Case ".",",","!","?",":",";"
		   sURLArr(i) = Left(sURLArr(i), Len(sURLArr(i))-1)
		 Case else
		   endChar = ""
	   End Select
       
	   if ((fType=3) and (VerifyWWW(sURLArr(i))=True)) then
	     sURLArr(i) = "http://" & sURLArr(i)
		 sURLArr(i) = "<a href=""javascript:open_win('" & sURLArr(i) & "');"">" & _
		 sURLArr(i) & endChar & "</a>"
	   end if
	   if not(fTYpe=3) then
	     sURLArr(i) = "<a href=""javascript:open_win('" & sURLArr(i) & "');"">" & _
	     sURLArr(i) & endChar & "</a>"
	   end if
	 end if
	Next
End Select  
edit_hrefs = Join(sURLArr, " ")
edit_hrefs = replace(edit_hrefs, " <br>", "<br />")
End Function
'#### end new_edit_hrefs function

-Stim
Go to Top of Page

pixuk
Starting Member

United Kingdom
7 Posts

Posted - 02 December 2004 :  15:51:11  Show Profile  Visit pixuk's Homepage
Thanks,

Did some tests, and doing typing the URL without the http bit works, ie www.v-flyer.com - but if you add the http to the start it writes

');">www.v-flyer.com'" target="_blank">http://www.v-flyer.com');">www.v-flyer.com" target="_blank">http://www.v-flyer.com

I'm guessing the string has to go through some manipulation elsewhere in the forum code which post-processes the changes make in edit_hrefs

Pete

The Virgin Atlantic Flyer Resource using Snitz Forums since Nov 03, and lovin' it.
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 06 December 2004 :  05:49:00  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
quote:
Originally posted by pixuk

Thanks,

Did some tests, and doing typing the URL without the http bit works, ie www.v-flyer.com - but if you add the http to the start it writes

');">www.v-flyer.com'" target="_blank">http://www.v-flyer.com');">www.v-flyer.com" target="_blank">http://www.v-flyer.com

I'm guessing the string has to go through some manipulation elsewhere in the forum code which post-processes the changes make in edit_hrefs

Pete



Could you provide a forum url so I can check this out? maybe I could write you a workaround for this...

-Stim
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.21 seconds. Powered By: Snitz Forums 2000 Version 3.4.07