<%
' AddLinks.asp: Converts
http://.../ in text into live hyperlinks'
' Version 1.1
' Copyright (C) 1998 John Watson
'
' E-mail: john@watson-net.com
'
' Get the latest version and full documentation
' at
http://www.watson-net.com/'
' PURPOSE
'
'
' INPUTS
'
' sInput: The string to be converted.
' sTarget: The target window that all links should go to.
'
' RETURNS
'
' sInput with live hyperlinks in it.
'
' LICENSE
'
' This library is free software; you can redistribute it and/or
' modify it under the terms of the GNU Library General Public
' License as published by the Free Software Foundation; either
' version 2 of the License, or (at your option) any later version.
'
' This library is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
' Library General Public License for more details.
'
' You should have received a copy of the GNU Library General Public
' License along with this library; if not, write to the
' Free Software Foundation, Inc., 59 Temple Place - Suite 330,
' Boston, MA 02111-1307, USA.
Function addLinks(sInput, sTarget)
Dim sNew, sPunct
' Define punctuation characters
sPunct = "_-+=!?.,;:`~'""*^$%()[]{}<>|"
' Assign input string to local variable so we don't change the
' original string.
sNew = sInput
' Split the string by whitespace: spaces, carriage returns, line feeds,
' and tabs. Then, for each "word" in the string...
For Each sVal1 in Split(sNew, " ")
For Each sVal2 in Split(sVal1, vbcr)
For Each sVal3 in Split(sVal2, vblf)
For Each sVal4 in Split(sVal3, Chr(9))
' Remove beginning and ending punctuation
bStop = FALSE
Do While (Not bStop)
If (Instr(sPunct, Left(sVal4, 1)) <> 0 And Len(sVal4) > 2) Then
sVal4 = Mid(sVal4, 2)
Else
bStop = TRUE
End If
Loop
bStop = FALSE
Do While (Not bStop)
If (Instr(sPunct, Right(sVal4, 1)) <> 0 And Len(sVal4) > 2) Then
sVal4 = Left(sVal4, Len(sVal4) - 1)
Else
bStop = TRUE
End If
Loop
' If the word begins with http:// then convert all occurrences
' of this word to a hyperlink.
If (LCase(Left(sVal4, 7) = "
http://") Or LCase(Left(sVal4, 4) = "www.")) Then
If (LCase(Left(sVal4, 4) = "www.")) Then
If (sTarget = "") then
sNew = Replace(sNew, sVal4, "<A HREF=""
http://" & sVal4 & """>" & sVal4 & "</A>")
Else
sNew = Replace(sNew, sVal4, "<A HREF=""
http://" & sVal4 & """ TARGET=""" & sTarget & """>" & sVal4 & "</A>")
End If
Else
If (sTarget = "") then
sNew = Replace(sNew, sVal4, "<A HREF=""" & sVal4 & """>" & sVal4 & "</A>")
Else
sNew = Replace(sNew, sVal4, "<A HREF=""" & sVal4 & """ TARGET=""" & sTarget & """>" & sVal4 & "</A>")
End If
End If
End If
' If this word looks like an e-mail address then convert all
' occurrences into a mailto: link.
If (Instr(sVal4, "@") >= 2 And Instr(sVal4, ".") <> 0 And Len(sVal4) >= 5) Then
sNew = Replace(sNew, sVal4, "<A HREF=""mailto:" & sVal4 & """>" & sVal4 & "</A>")
End If
Next
Next
Next
Next
' Return converted string
addLinks = sNew
End Function
%>