Webbo
Average Member
United Kingdom
982 Posts |
Posted - 22 October 2011 : 18:12:07
|
Thanks Bobby, just what I was looking for and now integrated within our site
If anyone else is to use it though be aware that some forum formatting has somehow leached into the code and requires removing first.
Below is a clean version of the bulk of the code to go into inc_function_common.asp
Function ChkKeys(fString) dim strKeys,strReplace,keywords,keyreplace,objRegex
'file check if ShowKeyWords = False then ChkKeys = fString Exit Function end if
if mLev < 3 then if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then LoadKeywordApps end if else LoadKeywordApps end if
strKeys = Application(strCookieURL & "STRKEYWORDS") strReplace = Application(strCookieURL & "STRKEYREPLACE") if fString = "" or IsNull(fString) then fString = " " keywords = split(strKeys, ",") keyreplace = split(strReplace, ",")
set objRegex = new RegExp objRegex.ignorecase = true objRegex.global = true
for i = 0 to ubound(keywords)
strPattern = "^(" & keywords(i) & ")(\s)" strReplace = keyreplace(i) & "$2" objRegex.pattern= strPattern fString = objRegex.replace(fString,strReplace)
strPattern = "(" & keywords(i) & ")$" strReplace = keyreplace(i) objRegex.pattern= strPattern fString = objRegex.replace(fString,strReplace)
fString = Replace(fString, " " & keywords(i) & " ", " " & keyreplace(i) & " ", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & ",", " " & keyreplace(i) & ",", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & ".", " " & keyreplace(i) & ".", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & ":", " " & keyreplace(i) & ":", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & ";", " " & keyreplace(i) & ";", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & "!", " " & keyreplace(i) & "!", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & "?", " " & keyreplace(i) & "?", 1, -1, 1)
fString = Replace(fString, "-" & keywords(i) & "-", "-" & keyreplace(i) & "-", 1, -1, 1) fString = Replace(fString, "-" & keywords(i) & " ", "-" & keyreplace(i) & " ", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & "-", " " & keyreplace(i) & "-", 1, -1, 1)
fString = Replace(fString, "_" & keywords(i) & "_", "_" & keyreplace(i) & "_", 1, -1, 1) fString = Replace(fString, "_" & keywords(i) & " ", "_" & keyreplace(i) & " ", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & "_", " " & keyreplace(i) & "_", 1, -1, 1)
fString = Replace(fString, "'" & keywords(i) & "'", "'" & keyreplace(i) & "'", 1, -1, 1) fString = Replace(fString, "'" & keywords(i) & " ", "'" & keyreplace(i) & " ", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & "'", " " & keyreplace(i) & "'", 1, -1, 1)
fString = Replace(fString, """" & keywords(i) & """", """" & keyreplace(i) & """", 1, -1, 1) fString = Replace(fString, """" & keywords(i) & " ", """" & keyreplace(i) & " ", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & """", " " & keyreplace(i) & """", 1, -1, 1)
fString = Replace(fString, "(" & keywords(i) & ")", "(" & keyreplace(i) & ")", 1, -1, 1) fString = Replace(fString, "(" & keywords(i) & " ", "(" & keyreplace(i) & " ", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & ")", " " & keyreplace(i) & ")", 1, -1, 1)
fString = Replace(fString, "[" & keywords(i) & "]", "[" & keyreplace(i) & "]", 1, -1, 1) fString = Replace(fString, "[" & keywords(i) & " ", "[" & keyreplace(i) & " ", 1, -1, 1) fString = Replace(fString, " " & keywords(i) & "]", " " & keyreplace(i) & "]", 1, -1, 1)
'This line needs repeated parsing misses every other word when a word is repeated fString = Replace(fString, " " & keywords(i) & " ", " " & keyreplace(i) & " ", 1, -1, 1)
'scenario - first word in line fString = Replace(fString, chr(13) & chr(10) & keywords(i) & " ", chr(13) & chr(10) & keyreplace(i) & " ", 1, -1, 1)
'scenario - last word in line fString = Replace(fString, " " & keywords(i) & chr(13) & chr(10), " " & keyreplace(i) & chr(13) & chr(10), 1, -1, 1)
'scenarion - first and only word in line fString = Replace(fString, chr(13) & chr(10) & keywords(i) & chr(13) & chr(10), chr(13) & chr(10) & keyreplace(i) & chr(13) & chr(10), 1, -1, 1)
'scenario - first word in line followed by a character fString = Replace(fString, chr(10) & keywords(i) & ".", chr(10) & keyreplace(i) & ".", 1, -1, 1) fString = Replace(fString, chr(10) & keywords(i) & ",", chr(10) & keyreplace(i) & ",", 1, -1, 1) fString = Replace(fString, chr(10) & keywords(i) & "?", chr(10) & keyreplace(i) & "?", 1, -1, 1) fString = Replace(fString, chr(10) & keywords(i) & "!", chr(10) & keyreplace(i) & "!", 1, -1, 1) fString = Replace(fString, chr(10) & keywords(i) & ":", chr(10) & keyreplace(i) & ":", 1, -1, 1) fString = Replace(fString, chr(10) & keywords(i) & ";", chr(10) & keyreplace(i) & ";", 1, -1, 1) fString = Replace(fString, chr(10) & keywords(i) & """", chr(10) & keyreplace(i) & """", 1, -1, 1) fString = Replace(fString, chr(10) & keywords(i) & "'", chr(10) & keyreplace(i) & "'", 1, -1, 1) fString = Replace(fString, chr(10) & keywords(i) & ")", chr(10) & keyreplace(i) & ")", 1, -1, 1) fString = Replace(fString, chr(10) & keywords(i) & "]", chr(10) & keyreplace(i) & "]", 1, -1, 1)
next set objRegex = nothing
ChkKeys = fString End Function
' ####Edit strPath to your xml file location
Sub LoadKeywordApps() dim strPath,xmlDoc,strErr,NumOfKeys,strKeys,strReplace,iKey
strPath = "http://www.yourdomain.com/forum_folder/filename.xml" set xmlDoc=CreateObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDOc.setProperty "ServerHTTPRequest", true xmlDoc.load(strPath)
if xmlDoc.parseError.errorCode <> 0 Then strErr = "<div><b>" & vbNewLine & _ "<ul>" & vbNewLine & _ "<li>ERROR!</li>" & vbNewLine & _ "<li>XML File " & strFileName & " - Failed to validate.</li>" & vbNewLine & _ "<li>" & xmlDoc.parseError.reason & "</li>" & vbNewLine & _ "<li>Error code: " & xmlDoc.parseError.errorCode & "</li>" & vbNewLine & _ "<li>Line: " & xmlDoc.parseError.line & "</li>" & vbNewLine & _ "<li>Character: " & xmlDoc.parseError.linepos & "</li>" & vbNewLine & _ "<li>Source: " & Chr(34) & xmlDoc.parseError.srcText & Chr(34) & "</li>" & vbNewLine & _ "<li>" & Now & "</li>" & vbNewLine & _ "</ul>" & vbNewLine & _ "</b></div>" & vbNewLine
Response.Write strErr Response.End end if
set xmlKeyList = xmlDoc.getElementsByTagName("key")
NumOfKeys = ((xmlKeyList.length) - 1) '0 based
strKeys = "" strReplace = ""
for iKey = 0 to cLng(NumOfKeys) if strKeys = "" then strKeys = xmlKeyList.item(iKey).childNodes(0).text strReplace = "<a href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""blank"">" strReplace = strReplace & xmlKeyList.item(iKey).childNodes(0).text & "</a>" else strKeys = strKeys & "," & xmlKeyList.item(iKey).childNodes(0).text strReplace = strReplace & ", <a href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""blank"">" strReplace = strReplace & xmlKeyList.item(iKey).childNodes(0).text & "</a>" end if next
set xmlDoc = nothing
Application.Lock Application(strCookieURL & "STRKEYWORDS") = strKeys Application(strCookieURL & "STRKEYREPLACE") = strReplace Application.UnLock End Sub
Also Dim ShowKeyWords : ShowKeyWords = True
needs to be added to topic.asp etc without the forum formatting as shown in the original post
|
|
|