% ' Return a formatted html link ' ************************************************************************************************ Function FormattedLink(text, location) FormattedLink = "" FormattedLink = FormattedLink & text & "" End Function ' Escape the HTML to avoid vulnerabilities ' ************************************************************************************************ Function H(str) H = Server.HTMLEncode(str) End Function ' Escape the URL to avoid vulnerabilities ' ************************************************************************************************ Function U(str) U = Server.URLEncode(str) End Function ' return the full location for URL ' ************************************************************************************************ Function AbsUrl(relative_path) AbsUrl = Application("AbsLinkUrl") & relative_path End Function ' Return the URL Path to a document ' ************************************************************************************************ Function DocumentTypeUrl(section, folder, basename, format) DocumentTypeUrl = "documents/" & section & "/" & folder & "/" & basename & "." & format End Function ' Return the breadcrumbs links ' ************************************************************************************************ Sub PrintBreadCrumbs() Dim rows, result, i result = FormattedLink("Home", "") & " | " & FormattedLink("Search", "") rows = RunQuery("SELECT secid, name FROM Section", null) For i=0 To UBound(rows,2) result = result & " | " & FormattedLink(H(rows(1,i)), "section.asp?secid=" & U(rows(0,i))) Next Response.write "
" End Sub ' Return an array of words from a string ' ************************************************************************************************ Function SplitWords(str) Dim regEx Set regEx = new RegExp regEx.Global = true regEx.Pattern = " +" SplitWords = Split(regEx.Replace(Trim(str), " ")) End Function ' Is the string a valid integer? ' ************************************************************************************************ Function IsValidInt(str) IsValidInt = Not IsEmpty(str) And IsNumeric(str) End Function ' Return a size in human readable units ' ************************************************************************************************ Function FormattedSizeUnits(size) Dim str, unit str = "" unit = "" if size > 1048576 then str = FormatNumber(size/1048576, 2) unit = "MB" elseif size > 1024 then str = FormatNumber(size/1024, 2) unit = "KB" else str = size unit = "B" end if FormattedSizeUnits = str & " " & unit End Function ' Return a formatted date string ' ************************************************************************************************ Function FormattedDateString(date) Dim myMon, myDay, str If IsNull(date) OR date = "" Then FormattedDateString = "--" Else FormattedDateString = Year(date) & "-" If Len(Month(date)) < 2 Then FormattedDateString = FormattedDateString & "0" End If FormattedDateString = FormattedDateString & Month(date) & "-" If Len(Day(date)) < 2 Then FormattedDateString = FormattedDateString & "0" End If FormattedDateString = FormattedDateString & Day(date) End If End Function ' Return a link to a document type ' ************************************************************************************************ Function FormattedDocumentType(location, doctype, size) Dim lead Select Case doctype case "pdf" lead = "PDF" case "doc" lead = "DOC" case "txt" lead = "TXT" case "rtf" lead = "RTF" case "zip" lead = "ZIP" case "docx" lead = "DOCX" End Select If IsNull(location) Then FormattedDocumentType = lead & " (" & _ FormattedSizeUnits(size) & ")" Else FormattedDocumentType = FormattedLink(lead, location) & _ " (" & FormattedSizeUnits(size) & ")" End If End Function ' Remove any illegal characters from the String ' ************************************************************************************************ Function RemoveIllegalChars(str) str = replace(str,"'", "''") Dim regEx Set regEx = New RegExp regEx.Global = true regEx.Pattern = "[^ :,._*()/\-'0-9a-zA-Z]" RemoveIllegalChars = regEx.Replace(str, "") End Function ' Print out a two column table ' ************************************************************************************************ Sub PrintTwoColumnTable(title, summary, entries) Dim max, middle, i, row Response.write "" & title & " | ||
---|---|---|
" Response.write entries(0) Response.write " | ||
" Response.write entries(i) Response.write " | " If (i+middle) < max Then Response.write "" & entries(i+middle) & " | " Else Response.write "" End If Response.write " |