%
' Quick Code:
function StripSpecialCharacters(strIn)
dim strTemp
strTemp = strIn
for x = 129 to 255
strTemp = replace(strTemp, chr(x), "" & x & ";")
next
strTemp = replace(strTemp, "'", "'")
StripSpecialCharacters = strTemp
End function
function RSC(strIn)
dim strOut
strOut = strIn
For i = 192 to 255
strOut = Replace(strOut, chr(i), ""&i&";")
Next
'For i = 7600 to 7900
' strOut = Replace(strOut, chr(i), ""&i&";")
'Next
RSC = strOut
End function
function StripSpecialCharacters_RSS(sIn)
dim strTemp
strTemp = sIn
for x = 129 to 255
if x = 146 then
strTemp = replace(strTemp, chr(x), "'")
else
strTemp = replace(strTemp, chr(x), "")
end if
Next
strTemp = replace(strTemp, "&", "&")
strTemp = replace(strTemp, chr(34), """)
strTemp = replace(strTemp, "'", "'")
strTemp = replace(strTemp, "<", "<")
strTemp = replace(strTemp, ">", ">")
StripSpecialCharacters_RSS = strTemp
End function
function StripSpecialCharacters_Flash(sIn)
dim strTemp
strTemp = sIn
for x = 129 to 255
if x = 146 then
strTemp = replace(strTemp, chr(x), "'")
else
strTemp = replace(strTemp, chr(x), "")
end if
Next
strTemp = replace(strTemp, "&", "&")
strTemp = replace(strTemp, chr(34), """)
strTemp = replace(strTemp, "'", "'")
strTemp = replace(strTemp, "<", "%3C")
strTemp = replace(strTemp, ">", "%3F")
StripSpecialCharacters_Flash = strTemp
End function
' request(
function request_clean(data_field)
request_clean = StripSpecialCharacters(request(data_field))
end function
' request.form(
function request_form_clean(data_field)
request_form_clean = StripSpecialCharacters(request.form(data_field))
end function
' request.querystring(
function request_querystring_clean(data_field)
request_querystring_clean = StripSpecialCharacters(Request.QueryString(data_field))
end function
'request.cookies(
function request_cookies_clean(data_field)
request_cookies_clean = StripSpecialCharacters(request.cookies(data_field))
end function
'request.servervariables(
function request_servervariables_clean(data_field)
request_servervariables_clean = StripSpecialCharacters(request.servervariables(data_field))
end function
'StripHTML
Function StripHTML( strText )
if strText <> "" or strText <> NULL then
StrText = cStr(StrText)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "<[^>]*>"
RegEx.Global = True
if strText <> "" then StripHTML = RegEx.Replace(strText, "") else StripHTML = ""
end if
End Function
Function RSSASCII(sIn)
dim strTemp
strTemp = sIn
strTemp = replace(strTemp, "’", "'")
strTemp = replace(strTemp, "‘", "'")
strTemp = replace(strTemp, "”", chr(34))
strTemp = replace(strTemp, "“", chr(34))
RSSASCII = strTemp
End Function
'lpad
Function lpad(arg,lambai,padchr)
Dim goloop
Dim cntloop
cntloop = 1
goloop = lambai - Len(Trim(arg))
Do While (cntloop <= goloop)
arg = padchr & Trim(arg)
cntloop = cntloop + 1
Loop
lpad = arg
End Function
function ereg(strOriginalString, strPattern, varIgnoreCase)
' Function matches pattern, returns true or false
' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
dim objRegExp : set objRegExp = new RegExp
with objRegExp
.Pattern = strPattern
.IgnoreCase = varIgnoreCase
.Global = True
end with
ereg = objRegExp.test(strOriginalString)
set objRegExp = nothing
end function
function ereg_replace(strOriginalString, strPattern, strReplacement, varIgnoreCase)
' Function replaces pattern with replacement
' varIgnoreCase must be TRUE (match is case insensitive) or FALSE (match is case sensitive)
dim objRegExp : set objRegExp = new RegExp
with objRegExp
.Pattern = strPattern
.IgnoreCase = varIgnoreCase
.Global = True
end with
ereg_replace = objRegExp.replace(strOriginalString, strReplacement)
set objRegExp = nothing
end function
'THIS FUNCTION IS FOR THE DATE/TIME FORMAT FUNCTION. PLEASE IGNORE UNTIL IT BREAKS SOMETHING
Function GetDateSuffix(iDate)
Select Case iDate
case 1, 21, 31
GetDateSuffix = "st"
case 2, 22
GetDateSuffix = "ed"
case 3, 23
GetDateSuffix = "rd"
case 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,24,25,26,27,28,29,30
GetDateSuffix = "th"
End Select
End Function
'THIS FUNCTION IS FOR THE DATE/TIME FORMAT FUNCTION. PLEASE IGNORE UNTIL IT BREAKS SOMETHING
Function GetDaysInMonth(iMonth, iYear)
Select Case iMonth
Case 1, 3, 5, 7, 8, 10, 12
GetDaysInMonth = 31
Case 4, 6, 9, 11
GetDaysInMonth = 30
Case 2
If IsDate("February 29, " & iYear) Then
GetDaysInMonth = 29
Else
GetDaysInMonth = 28
End If
End Select
End Function
'DATE AND TIME FORMATTING FUNCTION. WORKS LIKE PHPS DATE() FOR MORE INFORMATION PLEASE SEE http://us.php.net/date
'NOT ALL FORMATTING FLAGS ARE PORTED OVER YET HOWEVER ANYTHING YOU WILL PROBABLY NEED IS HERE
Function FormatDate(forstr, tdstr)
dim ia, d, shd, j, l, shs, w, z, shf, m, shm, n, t, shl, shy, y, a, sha, g, shg, h, i, s, u, newstr
if isdate(tdstr) then
hours = hour(tdstr)
length = len(forstr)
for ia = 1 to length
tmpstr = mid(forstr,ia,1)
dim regex
set regex = new RegExp
regex.pattern = "[A-Za-z]"
if tmpstr = "\" then
ia = ia+1
newstr = newstr&mid(forstr,ia,1)
end if
if regex.test(tmpstr) then
Select Case tmpstr
case "d"
d = lpad(day(tdstr),2,"0")
newstr = newstr&d
case "D"
ShD = weekdayname(weekday(tdstr),True)
newstr = newstr&ShD
case "j"
j = day(tdstr)
newstr = newstr&j
case "l"
l = weekdayname(weekday(tdstr))
newstr = newstr&l
case "S"
ShS = GetDateSuffix(day(tdstr))
newstr = newstr&ShS
case "w"
w = weekday(tdstr)
newstr = newstr&w
case "z"
z = DatePart("y",tdstr)
newstr = newstr&z
case "F"
ShF = monthname(month(tdstr))
newstr = newstr&ShF
case "m"
m = lpad(month(tdstr),2,"0")
newstr = newstr&m
case "M"
ShM = monthname(month(tdstr),True)
newstr = newstr&ShM
case "n"
n = month(tdstr)
newstr = newstr&n
case "t"
t = GetDaysInMonth(month(tdstr), year(tdstr))
newstr = newstr&t
case "L"
if IsDate("02/29/"&ShY) then ShL=1 else ShL=0
newstr = newstr&ShL
case "Y"
ShY = year(tdstr)
newstr = newstr&ShY
case "y"
y = right(year(tdstr),2)
newstr = newstr&y
case "a"
if hours < 12 then a = "am" else a = "pm"
newstr = newstr&a
case "A"
if hours < 12 then ShA = "AM" else ShA = "PM"
newstr = newstr&ShA
case "g"
if hours < 12 then g = hours else g = hours - 12
if g = 0 then g = 12
newstr = newstr&g
case "G"
ShG = hour(tdstr)
newstr = newstr&ShG
case "h"
if hours < 12 then h = hours else h = hours - 12
if h = 0 then h = 12
h = lpad(h,2,"0")
newstr = newstr&h
case "H"
ShH = lpad(hour(tdstr),2,"0")
newstr = newstr&ShH
case "i"
i = lpad(minute(tdstr),2,"0")
newstr = newstr&i
case "s"
s = lpad(second(tdstr),2,"0")
newstr = newstr&s
case "u"
newstr = newstr&u
case else
newstr = newster&tmpstr
end select
elseif tmpstr <> "\" then newstr = newstr&tmpstr
end if
next
FormatDate = CStr(newstr)
else
FormatDate = FALSE
end if
end function
' --- COUNT RECORDS IN SQL STATEMENT
Function SQLCount(SQL, Column)
CountSQL = "SELECT Count(a." & Column & ") FROM (" & SQL & ") a"
if isobject(objConn) then
set objCount = objConn.Execute(CountSQL)
elseif isobject(objAeonConn) then
set objCount = objAeonConn.Execute(CountSQL)
end if
if objCount.EOF then
SQLCount = 0
else
SQLCount = objCount(0)
end if
End Function
' --- LIMIT AND OFFEST REPLACEMENT FUNCTION FOR MSSQL
Function LimitOffset(SQL, Limit, Offset, SortColumns, SortOrders)
' SET DEFAULTS
OffsetOrder = "ORDER BY "
LimitOrder = "ORDER BY "
CorrectOrder = "ORDER BY "
Limit = Cint(Limit)
'response.write Limit&"
"
Offset = Cint(Offset)
' VERIFY VARIABLES
Columns = split(SortColumns, ",")
Orders = split(SortOrders, ",")
If Ubound(Columns) <> Ubound(Orders) then
LimitOffset = SQL
End If
' CREATE ORDER BY SQL FOR OFFSET
For i = 0 to Ubound(Columns)
If Columns(i) <> "" Then
If i > 0 then
OffsetOrder = OffsetOrder & "AND "
End If
if trim(ucase(Orders(i))) = "ASC" then
Order = "ASC"
else
Order = "DESC"
end if
OffsetOrder = OffsetOrder & "a." & trim(Columns(i)) & " " & Order
End If
Next
' CREATE ORDER BY SQL FOR CORRECTING
For i = 0 to Ubound(Columns)
If Columns(i) <> "" Then
If i > 0 then
CorrectOrder = CorrectOrder & "AND "
End If
if trim(ucase(Orders(i))) = "ASC" then
Order = "ASC"
else
Order = "DESC"
end if
CorrectOrder = CorrectOrder & "c." & trim(Columns(i)) & " " & Order
End If
Next
' CREATE ORDER BY SQL FOR LIMIT
For i = 0 to Ubound(Columns)
If Columns(i) <> "" Then
If i > 0 then
LimitOrder = LimitOrder & "AND "
End If
if trim(ucase(Orders(i))) = "ASC" then
Order = "DESC"
else
Order = "ASC"
end if
LimitOrder = LimitOrder & "b." & trim(Columns(i)) & " " & Order
End If
Next
' MICROSOFT SQL DOES NOT HAVE AN OFFSET COMMAND SO WE TRICK IT BY ADDING THE LIMIT ONTO THE OFFSET AND DOING SOME MAGIC
FullOffset = Limit+Offset
' IF THE CORRECTED OFFSET IS LARGER THAN THE NUMBER OF ITEMS IN THE FULL QUERY THAN CORRECT THE LIMIT AND OFFSET
'response.write SQL
'response.write Columns(0)
Count = SQLCount(SQL, Columns(0))
If Count <= 0 Then
'response.write "wha?"
Limit = 0
FullOffset = 0
ElseIf Count < FullOffset Then
'response.write Count&"
"
Limit = Count - Offset
FullOffset = Count
Else
Limit = Limit
FullOffset = FullOffset
End If
'response.write Limit
If Limit < 0 Then
Limit = 0
End If
' GRAB BOTH THE OFFSET PLUS THE NEXT LIMIT SET
OffsetSQL = "SELECT TOP " & FullOffset & " a.* FROM (" & SQL & ") a " & OffsetOrder
' REVERSE THE SET AND GRAB THE TOP RESULTS TO PROVIDE THE OFFSET AND LIMIT SET
LimitSQL = "SELECT TOP " & Limit & " b.* FROM (" & OffsetSQL & ") b " & LimitOrder
' REVERSE THE SET AGAIN TO RESET TO THE ORIGINAL ORDER
SQL = "SELECT c.* FROM (" & LimitSQL & ") c " & CorrectOrder
LimitOffset = SQL
End Function
Function StrCleaner(StrIn)
dim TempStr
if NOT isnull(StrIn) then
TempStr = StrIn
TempStr = ereg_replace(TempStr,"[^\x20-\x7e]","",true)
TempStr = ereg_replace(TempStr,"&","&",true)
TempStr = ereg_replace(TempStr,"'","'",true)
TempStr = ereg_replace(TempStr,"""",""",true)
TempStr = ereg_replace(TempStr,"<","<",true)
TempStr = ereg_replace(TempStr,"<",">",true)
StrCleaner = TempStr
else
StrCleaner = null
end if
End Function
Function DecToBin(intDec,intLength)
dim strResult
dim intTemp
dim intTempLen
while intDec > 0
if intDec mod 2 then
strResult = "1"+strResult
else
strResult = "0"+strResult
end if
intDec = int(intDec/2)
wend
if len(strResult) < intLength then
while len(strResult) < intLength
strResult = "0"+strResult
wend
end if
DecToBin= strResult
end function
Function URLDecode(sConvert)
Dim aSplit
Dim sOutput
Dim I
If IsNull(sConvert) Then
URLDecode = ""
Exit Function
End If
' convert all pluses to spaces
sOutput = REPLACE(sConvert, "+", " ")
' next convert %hexdigits to the character
aSplit = Split(sOutput, "%")
If IsArray(aSplit) Then
sOutput = aSplit(0)
For I = 0 to UBound(aSplit) - 1
sOutput = sOutput & _
Chr("&H" & Left(aSplit(i + 1), 2)) &_
Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
Next
End If
URLDecode = sOutput
End Function
function gmap(subjectString)
if subjectString <> "" then
dim gpatternArr(1)
dim greplaceArr
gpatternArr(0) = "\[gmap\](http://maps.google.com/.*?)\[/gmap\]"
gpatternArr(1) = "\[gcal\](http://www.google.com/calendar/embed?.*?)\[/gcal\]"
'response.write subjectString
'gmap
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "\[gmap\](http://maps.google.com/.*?)\[/gmap\]"
Set myMatches = myRegExp.Execute(subjectString)
For i=0 to myMatches.Count-1
replaceCode = "