Keyword Links - Last Update 6/9/08

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/67151?pagenum=1
05 November 2025, 03:13

Topic


cripto9t
Keyword Links - Last Update 6/9/08
28 May 2008, 16:55


I'm sure you've been to some web sites where certain keywords are links. Thats what this mod does.

The keywords and urls are stored in an xml file that you will have to create and edit.
Here's a sample
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<keywords>

<!-- Start Keywords -->
<key>
<phrase>xml</phrase>
<url>http://some/site.xml</url>
</key>
<key>
<phrase>html</phrase>
<url>http://some/site.html</url>
</key>
<b><font color="red"><key>
<phrase>css</phrase>
<url>http://some/site.css</url>
</key></font id="red"></b>
</keywords>
Just copy and paste that into your word editor and save it with a .xml extension. The part in <b><font color="red">red</font id="red"></b> is what you need to worry about when you add a keyword. Just add another <key> tag within the <keywords> tag.
The tag structure is very important and must be maintained.
Make sure the tags are in that order and they all have the closing tags.
Now the easy part. Open "inc_function_common.asp"
<ul>
<li>Find the FormatStr function. find these lines
Code:
function FormatStr(fString)
on Error resume next
ADD this line right under that
Code:
        fString = ChkKeys(fString)
</li><li>
Add this code before this line "%>" near the bottom of the file.
Code:
Function ChkKeys(fString)
dim strKeys,strReplace,keywords,keyreplace,objRegex

'file check
if ShowKeyWords = False then
ChkKeys = fString
Exit Function
end if

if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then
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

Sub LoadKeywordApps()
dim strPath,xmlDoc,strErr,NumOfKeys,strKeys,strReplace,iKey

strPath = "<b><font color="green">Absolute address of your Xml file</font id="green"></b>"
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 <b><font color="red">id=""keywords""</font id="red"></b> 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 <b><font color="red">id=""keywords""</font id="red"></b> 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
The part in <b><font color="green">green</font id="green"></b> has to be replaced with the <b><u>absolute path</u></b> to your xml file. <b><u>The whole address</u></b>. The part in <b><font color="red">red</font id="red"></b> adds some style to the links so they will stand out from other links. If your not interested in that just omit the parts in <b><font color="red">red</font id="red"></b>.</li>
<li>Add this line to the files you want to keywords
Code:
Dim ShowKeyWords : ShowKeyWords = True
Somewhere after <font color="red"><%</font id="red">. In "topic.asp" I added it after these lines
Code:
%>
<!--#INCLUDE FILE="config.asp"-->
<%
<font color="red">Dim ShowKeyWords : ShowKeyWords = True</font id="red">
</li>
<li>
You only need this part if want to add style to your links. Open "inc_header.asp" and find this line
Code:
".spnSearchHighlight {background-color:" & strSearchHiLiteColor & "}" & vbNewLine & _
Add this line right after that
Code:
"#keywords{color:yellow;font-weight:bold;background-color:yellow;)" & vbNewLine & _
</li></ul>Thats it.
Three problems I encountered. 1. An ampersand in the url caused a xml parsing error, so you need to replace it with "& amp;" (without the space). 2. <s>The css class won't trump the existing class, i.e. color and text-decoration.</s> Updated with Bobbys id fix. 3. If the keyword is in a hyperlink it will mess up the link. <ul>
<li>
<u>Updated: 5/29</u> - Links now open in new windows
css bug fixed
xml bug fixed
<s>add a file exclude list to the function</s> Reworked excludes update 6/9
</li>
<li>
<u>Update 5/30</u> - "word within word" <s>and "link within link"</s> bug fixed (theres still problems with links)
</li>
<li>
<u>Update 6/9</u> - Reworked excludes so hopefully it works for everyone. Moved chkKeys() call to the top of formatStr() to check for carrage returns, line feeds before they are replaced. Added more checks to catch more words. </li>
</ul>

 

Replies ...


leatherlips
28 May 2008, 19:11


This looks like a really cool mod. I tried to add it but now my forum looks like this:


Not sure what I did wrong.<
leatherlips
28 May 2008, 19:33


I tried it again but this time I added a <% above the code and the %> below the code. It got rid of the formatting issue but then every post had the error message you have in the inc_func_common.asp code including the bios in the profiles.<
cripto9t
28 May 2008, 20:04


What is the error? The xml errors I've got so far have been pretty straight forward, so it's been pretty easy figuring out what's wrong.
I need to handle the error msg better, so it doesn't shut down the thread.

I tried it again but this time I added a <% above the code and the %> below the code.
What code did you add that too?<
leatherlips
28 May 2008, 20:25


This is the error I am getting:

ERROR!
XML File - Failed to validate.
No data is available for the requested resource.
Error code: -2146697209
Line: 0
Character: 0
Source: ""
5/28/2008 5:28:04 PM

I added the <% and %> before and after the code added near the bottom of inc_func_common.asp

Here is a link so you can see what it is doing:

http://www.mangionemagic.com/forumfortesting/topic.asp?TOPIC_ID=765<
AnonJr
28 May 2008, 20:31


Post a link to the xml file, I bet your problem is in there...<
leatherlips
28 May 2008, 20:34


Here is my xml file:

http://www.mangionemagic.com/forumfortesting/autolinkterms.xml

I only added a few keywords while testing.<
bobby131313
28 May 2008, 20:52


It's working for me but now my forum variables are stuck on the contents of the first xml file I uploaded. I can't get it to change (ran setup.asp, no go) as I add phrases. Nothing seems to change it and new phrases don't work.
Oh, and thank you very much for putting this together!<
AnonJr
28 May 2008, 22:59


Originally posted by leatherlips
Here is my xml file:

http://www.mangionemagic.com/forumfortesting/autolinkterms.xml

I only added a few keywords while testing.
Nothing jumps out as being wrong... but something is causing the XML parser some heartburn. I wonder if its a problem with the version of the XML parser you're using.<
phy1729
28 May 2008, 23:24


Other than the fact that there's no DTD or Schema I don't see anything wrong.<
cripto9t
29 May 2008, 09:21


leatherlips, this is the solution ms support gives for that error.
After this line in LoadKeywordApps()
Code:
xmlDoc.async="false"
Add this line
Code:
xmlDoc.setProperty "ServerHTTPRequest", true
Hope that helps

Bobby, for testing, comment out the "if" and "end if" lines.
Code:
    'if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then
LoadKeywordApps
'end if
That way the apps will reload every refresh or page view. Be sure to uncomment when your through smile.

phy, DTD schema, maybe later wink.<
bobby131313
29 May 2008, 09:48


Still stuck. sad I've commented out the lines as you said. I've deleted all cookies and cache, run setup.... variables are still stuck. sad<
bobby131313
29 May 2008, 09:53


Do the 2 variables need to be dimmed in config.asp?<
cripto9t
29 May 2008, 10:09


Two bugs sad both are pretty obvious.
Word within a word. Cent - Centennial
I'm sure I can fix that by checking for spaces with regular expressions.
Link within a link. regex?<
cripto9t
29 May 2008, 10:29


Originally posted by bobby131313
Do the 2 variables need to be dimmed in config.asp?
No
It works fine for me. Thats how I'm doing my testing. You left the "LoadKeywordApps" line unncommented didn't you?<
bobby131313
29 May 2008, 10:35


I commented them out, reuploaded my XML file, loaded a few pages with keywords on them and the variables and keywords did not change at all.... commented or uncommented.<
cripto9t
29 May 2008, 10:46


LoadKeywordApps needs to be left uncommented. The line above it and below it need to be commented.
You can try this
uncommment all the lines and in the FormatStr function where you added fString = ChkKeys(fString) Add that above this
Code:
    Application.Lock
Application(strCookieURL & "STRKEYWORDS") = ""
Application(strCookieURL & "STRKEYREPLACE") = ""
Application.UnLock
<
leatherlips
29 May 2008, 11:02


leatherlips, this is the solution ms support gives for that error.
After this line in LoadKeywordApps()
xmlDoc.async="false"
Add this line
xmlDoc.setProperty "ServerHTTPRequest", true
Hope that helps
cripto9t,

That fixed my issue! Thank you!
I have another question now. I have replaced my URL codes with the help of Shaggy awhile ago. If a link is pointing to anywhere in my site it opens in the same window. If it points to outside of my site it opens in a new window. The links generated with the auto linking mod makes all links regardless of where they point open in the same window. Can this be adjusted?<
bobby131313
29 May 2008, 11:04


Cool cripto, I was commenting all 3, duh. Now I have LL's issue I need to fix.<
leatherlips
29 May 2008, 11:12


I found an issue with the automatic links.
I plan on having album names auto link to there corresoponding details page. However, if a member typed the album name and linked it to somewhere else such as an ebay listing for that album the auto link takes over and ignores the ebay link.
Is this something that can be sorted?<
bobby131313
29 May 2008, 11:21


Sorry but there seems to be another bug also.
If one of the phrases is in a forum description, it's throwing a monkeywrench in things. One of my phrases is large cent which is in the description for my classic coin forum. Heres what it does...





Here's how it really looks.<
cripto9t
29 May 2008, 11:29


leatherlips, that's the bug I pointed out above - link within a link.
There should be a way to do it with regular expressions. Which I don't have much experience with. But I'll give it a try :).
To have the link open in a new window you need to add target=""blank"" to the anchor tag.
Code:
strReplace = "<span class=""keywords""><a href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""blank"">"
and this line
Code:
strReplace = strReplace & ", <span class=""keywords""><a href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""blank"">"
<
cripto9t
29 May 2008, 11:37


Bobby I'll see if I can recreate that and see whats going on. That's wierd<
cripto9t
29 May 2008, 11:48


Bobby do you want mod to work on default.asp? I was thinking of writing a check to exclude some files.<
bobby131313
29 May 2008, 11:51


I would rather have it not work on default.asp at all.
Now I just started over from scratch and that error is not happening now. So I guess it was my error somehow. blush<
cripto9t
29 May 2008, 12:07


Originally posted by bobby131313
I would rather have it not work on default.asp at all.
Now I just started over from scratch and that error is not happening now. So I guess it was my error somehow. blush
Yea I added ten keywords to a description and it worked allright. Maybe a parsing error because it looks like it just quit right there and jumped to the next cell.
I'll write a little check for the file names. Would it be better to have an "exclude" list or an "include" list?<
bobby131313
29 May 2008, 12:24


Well, that's a good question. I'm leaning towards exclude for purely selfish reasons. I'm already wondering what files would need to be included to make this work on non-forum pages. tongue
BTW, I think I know what was causing the error. I added the blank target before it was brought up here and it was stuck in my variables with a missing quote without me realizing it. Coulda been it I guess. question<
bobby131313
29 May 2008, 12:58


Ha! CSS will indeed override if you use an id like so...
Code:
    for iKey = 0 to cLng(NumOfKeys)
if strKeys = "" then
strKeys = xmlKeyList.item(iKey).childNodes(0).text
strReplace = "<a id=""keywords"" 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 id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""blank"">"
strReplace = strReplace & xmlKeyList.item(iKey).childNodes(0).text & "</a>"
end if
next

Css....
Code:

#keywords {color: #336633; text-decoration:underline; font-weight:bold}
#keywords:hover {color: #FF0000}

Links are green and red on hover with bolding overriding my normal blue links.<
cripto9t
29 May 2008, 13:04


Ok this is for exluding files in the ChkKeys() function. Replace this code
Code:
Function ChkKeys(fString)
dim strKeys,strReplace,keywords,keyreplace
with this
Code:
Function ChkKeys(fString)
dim strFiles,iCnt,strKeys,strReplace,keywords,keyreplace

strFiles = array("admin_","default","forum","profile","active","register","members","search","faq")
for iCnt = 0 to Ubound(strFiles)
if Instr(lcase(strScriptName),strFiles(iCnt)) > 0 then
ChkKeys = fString
Exit Function
end if
next
I think I've got all the files on there except topics. If you add a file make sure it has parenthesis around it and seperated from the others with a comma. And if you want to make it an "include" file just change "> 0" with "= 1".
To add it to a non form page, the file has to an asp file with the "inc_func_common" file included and the text you check has to (maybe not has but should) be stored in a variable. And then ChkKeys(text_to_check).<
cripto9t
29 May 2008, 13:08


Thanks Bobby. I knew there had to be a wa :). I'm goin to update the original code and add
the css fix, new window, and the xml issue leatherlips was having<
bobby131313
29 May 2008, 13:35


Hmmm... seems to be blocking topic.asp too.<
bobby131313
29 May 2008, 13:50


You need to assign the id to the <a> tag and you don't need the </id> tag. wink<
bobby131313
29 May 2008, 14:26


Also need to change...
Code:

".keywords a {color:yellow;font-weight:bold;background-color:yellow;)" & vbNewLine & _
to...
Code:

"#keywords {color:yellow;font-weight:bold;background-color:yellow;}" & vbNewLine & _
<
cripto9t
29 May 2008, 14:31


I think I got it right now, thanks.
Are your topics still being blocked?

<
cripto9t
29 May 2008, 14:34


Originally posted by bobby131313
Also need to change...
Code:

".keywords a {color:yellow;font-weight:bold;background-color:yellow;)" & vbNewLine & _
to...
Code:

"#keywords {color:yellow;font-weight:bold;background-color:yellow;}" & vbNewLine & _
Aaah yea that would help to smile
Done<
bobby131313
29 May 2008, 14:47


Are your topics still being blocked?
Yeah, yours are working?<
cripto9t
29 May 2008, 16:53


Yea, I only tested default, forum and topic and it blocked default and forum but checks topic. I know your forum is pretty modded up, do you still have this line of code in "inc_header" (near the top)?
Code:
strScriptName = request.servervariables("script_name")
That's the variable I'm using to check the page.<
bobby131313
29 May 2008, 17:13


Hmmm... yeah still there intact.<
bobby131313
29 May 2008, 17:57


Just double checked everything and it looks good, but still unlinked on topic.asp. I'll keep pokin' around.<
cripto9t
30 May 2008, 08:08


This should fix the "word within word" and "link within link" bugs.
In the ChkKey() function replace this line
Code:
 fString = Replace(fString,keywords(i),keyreplace(i), 1, -1, 1) 
with this
Code:
 fString = Replace(fString, " " & keywords(i) & " ", " " & keyreplace(i) & " ", 1, -1, 1) 
<
leatherlips
30 May 2008, 10:15


Does the code in the first post of this topic already include all of the changes mentioned throughout the thread?<
leatherlips
30 May 2008, 11:17


I applied the new code and like bobby131313 it is not showing the links on topic.asp. sad<
cripto9t
30 May 2008, 17:50


The original code has been updated with all the bug fixes mentioned so far.
Give me a little time, I think I have a fool proof way or restricting it to certian files.
Also, I just thought of a few things that could go wrong with the "word within word" and "link within link" fix I posted (but its still better than it was). So give me some time and I'll see if can come up with something better.<
leatherlips
30 May 2008, 19:59


Sure, I'll wait. This is a pretty neat mod. I really appreciate your hard work on this!<
bobby131313
31 May 2008, 12:30


One other little thing that's not that important really.
Is there any way to preserve the originally posted case? It converts everything to lower case.
Thanks for your work, it is appreciated. bigsmile<
bobby131313
01 June 2008, 19:17


Another odd little quirk. It seems that it recognizes spaces just fine in the middle of a link phrase, but will not recognize leading or trailing spaces which would be very helpful in resolving some conflicts.<
weeweeslap
07 June 2008, 15:27


I applied what you posted in the first post and it doesn't seem to be working and oddly I am getting a jscript error which I can't make sense of. Here is the li9nk to the test topic:
http://www.coastercrazy.com/forum/topic.asp?TOPIC_ID=17825
here is the xml file
http://www.coastercrazy.com/keywords.xml
and here is my inc_func_common.asp
http://www.coastercrazy.com/forum/inc_func_common.txt
For absolute path I did the url above and also tried the whole directory line (c:\etc..etc...)
Help? smile<
Carefree
07 June 2008, 17:13


I tried all the settings & updates; spaces (and all following the first space in a phrase are eliminated).<
Carefree
08 June 2008, 19:38


Add this line right after that
Code:

"#keywords a {color:yellow;font-weight:bold;background-color:yellow;)" & vbNewLine & _
<
bobby131313
08 June 2008, 20:46


No the a is not needed, the id is added directly to the a tag.<
leatherlips
08 June 2008, 22:06


Do you guys have this working now? The last time I tried it did not show the links.<
cripto9t
09 June 2008, 11:56


Guys, I haven't forgot this smile. I put a few hours into it this morning. I'll post an update after a little more testing and I get a post wrote up.
Got a new way of checking files so hopefully it should work for everyone. Also put a lot more checks in so it catches a lot more words.
Theres still a link within a link problem, but I haven't give up.
Just noticed this morning that carrage returns and line feeds were being replaced before checking for keywords. So that should solve alot of the problems I was haveing with regex for a future update.
bobby, when (if?) this switched over to regular expressions, maybe I'll be able to fix the letter case problem. But I don't think I can do it using the replace function.<
cripto9t
09 June 2008, 15:47


The code in the topic has been updated.
For those that are using this.

1. In the function FormatStr(), move this line "fString = ChkKeys(fString)" to here
Code:
function FormatStr(fString)
on Error resume next
fString = ChkKeys(fString)

2. Replace function ChkKeys() with the new one.

3. Then you'll need to add this line of code to the files you want keywords on.
Code:
Dim ShowKeyWords : ShowKeyWords = True
Add it somewhere after this "<%". This is "topic.asp".
Code:
%>
<!--#INCLUDE FILE="config.asp"-->
<%
Dim ShowKeyWords : ShowKeyWords = True
This takes the place of the exclude list and hopefully it will work for everyone.
<edit>6/10/08 Some of the instructions were left out. There all there now</edit><
leatherlips
09 June 2008, 17:47


Seems pretty good so far. I have a couple of questions.
You have it now to open all links in a new window. I would rather not do that. Before you had it open in the same window. I tried removing the part in red from both lines that have it but they still open in a new window:

strReplace = "<a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""blank"">"

Am I removing the correct section of code? Also, I'm wonder if the target frame could be set in the xml file when you specify the url for the phrase?
Another thing I notice is that if I update the xml file with a new phrase it does not seem to take effect. What is causing that?
Thanks again for all your work. I really like this mod!<
cripto9t
09 June 2008, 19:10


Also, I'm wonder if the target frame could be set in the xml file when you specify the url for the phrase?
Thats a good idea and I think I have a good idea on how to do it smile.<
Carefree
09 June 2008, 19:46


Ok - one minor bug that I can live with. If a keyword or key-phrase starts a sentence, it doesn't get selected. If it is at any other point in the sentence, it does.<
Carefree
09 June 2008, 20:16


Originally posted by leatherlips
I tried removing the part in red from both lines that have it but they still open in a new window:

strReplace = "<a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""blank"">"

Am I removing the correct section of code?

Yes, but not doing the right thing to the code. Change the word "blank" to "_self" and they'll open in the same window.<
leatherlips
09 June 2008, 20:40


Thanks guys.
It seems that this needs to be made clear in the instructions for future users of this mod. Each time you upate your xml file or even change the target of the keyword links in the inc_func_common.asp file you must first uncomment the lines you mentioned, save the file and then uncomment the lines and then save again:

Code:
'if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then
LoadKeywordApps
'end if

Now if you can share how to control the target of the links in the xml file itself this mod will work perfectly for me. tongue<
Carefree
09 June 2008, 21:32


Read my response above yours to edit the targets.
I don't think it can be done in the XML file, it will not validate if you modify the format.<
weeweeslap
09 June 2008, 21:39


Yeah minor bug same as carefree, if it starts the sentence it doesn't get linked, if it ends the sentence and not followed by a period or another sentence then it doesn't get linked either. Minor but figured I'd post them. Thank you very much for this. It is very much needed and I greatly appreciate your work! -Oscar

http://www.coastercrazy.com/forum/topic.asp?TOPIC_ID=17825 <-- this is the topic so you can see what I am talking about above.
-edit
in my reply you can see I just wroe the single word trivia and it did get linked. Sooo not sure why that one worked and the others didn't. Thanks!<
leatherlips
09 June 2008, 21:48


I fixed my links Carefree. Thanks. It looks like it is either all same window or all new window. I was trying to have links in my own site open in the same window while links outside of my site would open in a new window. I can live with it the way it is unless someone knows how to do it.
I am not having the same issues with the keywords not linking if at the beginning or end etc. Mine links no matter where it is. You can see this post if you want to see:

http://www.mangionemagic.com/forumbeta/topic.asp?TOPIC_ID=881

Log in is demo/demo. The second post in the above link will show the variations.
One other thing, I am trying to get the keyword links to have a dashed underline under them but can not get it to work. Any ideas? What I currently have is just playing around with different things.<
weeweeslap
09 June 2008, 22:01


http://www.mangionemagic.com/forumbeta/topic.asp?TOPIC_ID=881
hmm I logge din and made some sample posts and see the results, neither worked and I didn't do any tricks!<
leatherlips
09 June 2008, 22:35


Originally posted by weeweeslap
hmm I logge din and made some sample posts and see the results, neither worked and I didn't do any tricks!
You typed the wrong phrase. smile
You typed Feel So Good. The phrase I have is Feels So Good.<
weeweeslap
09 June 2008, 22:48


ah yes, I made another post testing spring fever, I noticed that it changes the capitalization to whatever capitalization you have set in the XML file.<
Carefree
10 June 2008, 02:45


I figured out the settings for you, Leather. For pages on your server, use relative paths in the Keywords.xml page. For external pages, use complete (http) paths in the Keywords.xml page. It'll work.
Code:

		for iKey = 0 to cLng(NumOfKeys)
if strKeys = "" then
strKeys = xmlKeyList.item(iKey).childNodes(0).text
strDiv = xmlKeyList.item(iKey).childNodes(1).text
if left(strDiv,4)<> "http" and left(strDiv,3) <> "ftp" then
strReplace = "<a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""_self"">"
else
strReplace = "<a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""_blank"">"
end if
strReplace = strReplace & xmlKeyList.item(iKey).childNodes(0).text & "</a>"
else
strKeys = strKeys & "," & xmlKeyList.item(iKey).childNodes(0).text
strDiv = xmlKeyList.item(iKey).childNodes(1).text
strDiz = xmlKeyList.item(iKey).childNodes(0).text
if left(strDiv,4)= "http" or left(strDiv,3) = "ftp" then
strReplace = strReplace & ", <a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""_blank"">"
else
strReplace = strReplace & ", <a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""_self"">"
end if
strReplace = strReplace & xmlKeyList.item(iKey).childNodes(0).text & "</a>"
end if
next
<
cripto9t
10 June 2008, 08:07


I left out one of the changes in my update post.
I noticed that it changes the capitalization to whatever capitalization you have set in the XML file.
Thats the way it works. I may be able to solve that using regular expressions. Most of the sites I visit use all caps for the keywords. Thats probably why I never thought this would be an issue.
Thanks carefree, I was thinking in a different direction, but I like your solution better smile.
<
weeweeslap
10 June 2008, 18:06


looking good cripto9t! I really like it. I appreciate it alot! Many sincere thanks!<
leatherlips
10 June 2008, 19:52


Thanks Carefree for the code. Now my links open the way I want them.
I'm still having trouble with the dashed underline links.
I finally got them to work but then all of a sudden they reverted back to my default forum link style. Here is what I have in inc_header.asp concerning the links:

Code:
"#autokeywords{color:#333399;font-weight:normal;text-decoration:none;border-bottom:1px dashed;}" & vbNewLine & _
"#autokeywords:hover{color:red;font-weight:normal;text-decoration:none;border-bottom:1px dashed;}" & vbNewLine & _
It worked for a little bit then stopped. Any ideas?
(I also renamed the id autokeywords in the code in inc_func_common.asp)

Edit: I got it to work again. I commented out those two lines found earlier in this thread and then recommented them. It seems to be working now.
The only thing left IMO is to maintain the case of the letters if possible. <
Carefree
10 June 2008, 21:49


Originally posted by leatherlips The only thing left IMO is to maintain the case of the letters if possible.

If a hexadecimal conversion of the string (rather than a straight comparison without regard to capitalization) is used, that could be done - though I'm not sure whether it would still recognize keywords which used different capitalization. Would have to experiment a bit, unless somebody knows a quick/dirty way....<
Carefree
10 June 2008, 21:54


Originally posted by leatherlips
Each time you upate your xml file or even change the target of the keyword links in the inc_func_common.asp file you must first uncomment the lines you mentioned, save the file and then uncomment the lines and then save again:

Code:
'if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then
LoadKeywordApps
'end if

Not quite, Leather.
To modify "on the fly", you should:
  1. Comment the two lines.
  2. Save the file.
  3. Make your changes.
  4. Test the changes.
  5. Un-comment the two lines.
  6. Save the file again.
That way, your changes will be evident immediately and not contingent on a replacement of your cookie.<
leatherlips
10 June 2008, 21:54


I've just discovered a new odd issue. For some reason, not all of the links take on the id set in inc_header.asp. My auto terms links are set to be dashed. However in this post the last key phrase ignores the id:


But if I edit it and add a phrase after it, it takes on the id but then the new last one does not:


And then again:


It does not do this in every post. What would be causing this?<
Carefree
10 June 2008, 22:01


I have the same issue with first/last occasionally not following set behaviour. Not sure what's causing it. I'm going to experiment & see if I can fix it, though.<
leatherlips
10 June 2008, 22:26


Originally posted by Carefree
I have the same issue with first/last occasionally not following set behaviour. Not sure what's causing it. I'm going to experiment & see if I can fix it, though.
I'm not sure, but I just checked my page on my MacBook using Safari and Firefox and the links were all correctly taking on the id.
Could it be a browser issue that causes some of the links not to behave correctly? <
cripto9t
11 June 2008, 08:15


Maybe there's just not enough room.
Leatherlips, for the bottom border try setting the line-height up. I added a border to mine and like yours some worked and some didn't,
especially when they were on consecutive lines. Mine started working at 18px.
line-height:18px;<
leatherlips
11 June 2008, 09:31


Originally posted by cripto9t
Maybe there's just not enough room.
Leatherlips, for the bottom border try setting the line-height up. I added a border to mine and like yours some worked and some didn't,
especially when they were on consecutive lines. Mine started working at 18px.
line-height:18px;
Good call! 18 was the magic number!
I have had one of my users testing this out for me and they really love this new feature! Thanks again for all of your work!<
cripto9t
11 June 2008, 10:05


Switched everything over to regular expressions and words now keep thier structure (upper and lower case).
I'm not going to update the topic yet because I want to add carefrees window addon to it
and a better way of handling the xml error message and maybe a few other things. So for anyone that wants to test it out, I'll post the code here for now. Just replace the ChkKeys() function and the LoadKeywordApps() sub.
Code:
Function ChkKeys(fString)
dim strFiles,iCnt,strKeys,strReplace,strClose,keywords,keyreplace,objRegex

if ShowKeyWords = False then
ChkKeys = fString
Exit Function
end if

if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then
LoadKeywordApps
end if

strKeys = Application(strCookieURL & "STRKEYWORDS")
strReplace = Application(strCookieURL & "STRKEYREPLACE")
strClose = "</a>"
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) & "$1" & strClose & "$2"
objRegex.pattern= strPattern
fString = objRegex.replace(fString,strReplace)

strPattern = "(" & keywords(i) & ")$"
strReplace = keyreplace(i) & "$1" & strClose
objRegex.pattern= strPattern
fString = objRegex.replace(fString,strReplace)

strPattern = "(""|'|\(|\[|{)(" & keywords(i) & ")(}|\]|\)|'|"")"
strReplace = "$1" & keyreplace(i) & "$2" & strClose & "$3"
objRegex.pattern= strPattern
fString = objRegex.replace(fString,strReplace)

strPattern = "(\s)(" & keywords(i) & ")(\s|\.|,|;|'|\?|!|\)|\]|}|"")"
strReplace = "$1" & keyreplace(i) & "$2" & strClose & "$3"
objRegex.pattern= strPattern
fString = objRegex.replace(fString,strReplace)
next

ChkKeys = fString
End Function

Sub LoadKeywordApps()
dim strPath,xmlDoc,strErr,xmlKeyList,NumOfKeys,strKeys,strReplace,iKey

strPath = "C:\Inetpub\wwwroot\pool\key_db.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 id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""blank"">"
else
strKeys = strKeys & "," & xmlKeyList.item(iKey).childNodes(0).text
strReplace = strReplace & ", <a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""blank"">"
end if
next

set xmlKeyList = nothing
set xmlDoc = nothing

Application.Lock
Application(strCookieURL & "STRKEYWORDS") = strKeys
Application(strCookieURL & "STRKEYREPLACE") = strReplace
Application.UnLock
End Sub
<
leatherlips
11 June 2008, 11:20


I just tried your newer code and there is a problem.
Now when I enter a phrase it adds the keyword link and keeps the original phrase entered by the user.
For example, if my keyword phrase is Snitz Forums and I type:

Snitz Forums

Then it will display the following:

Snitz ForumsSnitz Forums

I've also noticed with the older code and this newer code that if you put a phrase between quotes (double or single) it puts a space between the beginning quote and the key phrase. Also any keywords preceded by or followed by a hyphen will not auto link. These aren't big deals, I just wanted to point them out.
Doing more testing I've found that if a phrase is in a spoiler tag it will still show up.<
cripto9t
12 June 2008, 08:09


You need to replace the LoadKeywordApps() sub with the one I posted. The lines that add the keyword from the xml file have been edited out of it.
I noticed the quote space also. I have no idea why it is happening. I'll give it a closer look.
I'll add a hyphen to the pattern.

The spoiler tag probably runs along the same line as the anchr tag issue.<
leatherlips
12 June 2008, 09:22


Your code does work. I know what is causing issue. Because I want the target frames to be different depending on if they point to inside or outside of my site, I used Carefree's code to replace part of your code:

Code:
for iKey = 0 to cLng(NumOfKeys)
if strKeys = "" then
strKeys = xmlKeyList.item(iKey).childNodes(0).text
strDiv = xmlKeyList.item(iKey).childNodes(1).text
if left(strDiv,4)<> "http" and left(strDiv,3) <> "ftp" then
strReplace = "<a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""_self"">"
else
strReplace = "<a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""_blank"">"
end if
strReplace = strReplace & xmlKeyList.item(iKey).childNodes(0).text & "</a>"
else
strKeys = strKeys & "," & xmlKeyList.item(iKey).childNodes(0).text
strDiv = xmlKeyList.item(iKey).childNodes(1).text
strDiz = xmlKeyList.item(iKey).childNodes(0).text
if left(strDiv,4)= "http" or left(strDiv,3) = "ftp" then
strReplace = strReplace & ", <a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""_blank"">"
else
strReplace = strReplace & ", <a id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""_self"">"
end if
strReplace = strReplace & xmlKeyList.item(iKey).childNodes(0).text & "</a>"
end if
next
It worked with the other code but with your newer one it now has the symptom I posted above. sad<
cripto9t
12 June 2008, 12:28


Remove this line, its in there twice, so take both of them out.
Code:
strReplace = strReplace & xmlKeyList.item(iKey).childNodes(0).text & "</a>"
Thats all I did to the original so it should work smile.<
leatherlips
12 June 2008, 12:54


That did it cripto9t! Thanks!
Any further along with the quote space issue and the spoiler tag?
To add to the list (sorry blush)...
If any keyword or phrase is in any forum code tag it will not link. Unless a space is put before and after it. Also, if you use the keyword id (which I know is optional) then the forum code tags will not take effect.
Edit: It seems the spoiler tag will not work with any normal link either. I wonder if this could be a mod itself? Or at least revising the spoiler tag to include links to be hidden? I've modified my spoiler tag so this is no longer an issue.
Edit 2: It looks like you can still use the keyword id and have the forum tags work. You just need to remove the font-weight attribute from the id. (It still has to have a space before and after the phrase though.)<
leatherlips
12 June 2008, 22:42


I found a couple more quirks, although they are not a big deal, just thought I'd pass it on.
If you have a keyword phrase that has a comma in it then the links in the xml file below that keyword phrase will be off by one link. They will take the link of the one below them.
Also if you have a phrase that shares the first word, the first link in the xml will be the only one that works for that word.
My keyword phrases are album titles. One is called Together and the other is called Together Forever. The Together Forever will not work. Only the word Together gets linked, but to the other album titles page.<
leatherlips
14 June 2008, 15:32


If you were to add the forum tags to the exclusion list like you did with ", ' ? etc... I think the auto link will work.
Presently if you choose to make a keyword bold, then the forum tags are right next to the phrase which makes it not work.
I've tried adding and to your code but I can't figure it out so it will work. Can you show me how to do that? I would then be able to add the others such as [i] and [u] etc...<
leatherlips
15 June 2008, 15:23


Do you think there is a way to have this not work in members signatures? Some of my members use key words and phrases in their signatures and I would like for them to not have the auto links.<
leatherlips
16 June 2008, 21:03


Just bumping this up to hopefully get these last few minor bugs to be fixed. It's so close! smile<
Andy Humm
12 August 2008, 05:18


Originally posted by leatherlips
Each time you upate your xml file or even change the target of the keyword links in the inc_func_common.asp file you must first uncomment the lines you mentioned, save the file and then uncomment the lines and then save again:

Code:
'if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then
LoadKeywordApps
'end if

Not quite, Leather.
To modify "on the fly", you should:
  1. Comment the two lines.
  2. Save the file.
  3. Make your changes.
  4. Test the changes.
  5. Un-comment the two lines.
  6. Save the file again.
That way, your changes will be evident immediately and not contingent on a replacement of your cookie.
The process of having to comment/uncomment the inc_func_common while xml file changes are being made seems a little clumsy. Could this requirement be done by an external file linked from the admin_home, so that you can make the changes to the xml file, upload it as normal. Then with the linked file, it automatically comments the appropriate lines, refreshes and then uncomments to bring the changed xml into affect.

The reason for this suggestion, I made my xml file changes uploaded the file. Then went through the comment process and the changes installed on the keywords.. I am sure it is possible with some if'thens etc..<
cripto9t
12 August 2008, 14:47


Sorry about the disappearance. Hopefully I'm back for awhile.
The reason for this suggestion, I made my xml file changes uploaded the file. Then went through the comment process and the changes installed on the keywords.. I am sure it is possible with some if'thens etc..
Andy, assuming you have admin status, try this
Code:
Code:
if mLev < 3 then
if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then
LoadKeywordApps
end if
else
LoadKeywordApps
end if



<
leatherlips
12 August 2008, 16:58


cripto9t,

Your suggestion of adding the one phrase above the other worked great! Also, doing:

Code:
if mLev < 3 then
if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then
LoadKeywordApps
end if
else
LoadKeywordApps
end if

Works great too! Now it automatically updates the xml files phrases without having to manually uncomment and re-comment those lines!
Your signature idea worked too!
Adding the html for bold, underline, italics and strikethrough worked too!
Thank you sooo much!! bigsmile<
Andy Humm
12 August 2008, 18:10


cripto9t, spot on and thank you...andy<
Andy Humm
13 August 2008, 03:45


Quote: Do you think there is a way to have this not work in members signatures? Some of my members use key words and phrases in their signatures and I would like for them to not have the auto links. I looked at this and a quick solution would be to add an unmodified "formatStr" function to "inc_func_common" and rename it "formatStr2". Then find the sigs part in "topic.asp" and rename it there. Remember 2 sigs, one for the topic and one for the replies.
I have added a new unmodified "formatStr" as "formatStr2" and I think I have amended the right reply sig's but the sig block still shows the keyword links
This is my formatstr2
Code:
function FormatStr2(fString)
on Error resume next
fString = Replace(fString, CHR(13), "")
'fString = Replace(fString, CHR(10) & CHR(10), "<br /><br />")
fString = Replace(fString, CHR(10), "<br />")
if strBadWordFilter = 1 or strBadWordFilter = "1" then
fString = ChkBadWords(fString)
end if

if strAllowForumCode = "1" then
fString = ReplaceURLs(fString)
fString = ReplaceCodeTags(fString)
if strIMGInPosts = "1" then
fString = ReplaceImageTags(fString)
end if
end if

fString = ChkURLs(fString, "http://", 1)
fString = ChkURLs(fString, "https://", 2)
fString = ChkURLs(fString, "www.", 3)
fString = ChkMail(fString)
fString = ChkURLs(fString, "ftp://", 5)
fString = ChkURLs(fString, "file:///", 6)

if strIcons = "1" then
fString = smile(fString)
end if
if strAllowForumCode = "1" then
fString = extratags(fString)
end if
FormatStr2 = fString
on Error goto 0
end function

And the two sig amendments are at lines 692 -698
Code:
		Response.Write	"</span id=""msg""></font></td>" & vbNewLine & _
" </tr>" & vbNewLine
if CanShowSignature = 1 and Reply_Sig = 1 and Reply_MemberSig <> "" then
Response.Write " <tr>" & vbNewLine & _
" <td valign=""bottom""><hr noshade size=""" & strFooterFontSize & """><font color=""" & strForumFontColor & """ face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><span class=""spnMessageText"">" & formatStr2(Reply_MemberSig) & "</span></font></td>" & vbNewLine & _
" </tr>" & vbNewLine
end if
and lines 918 -924
Code:
Response.Write	"</span id=""msg""></font></td>" & vbNewLine & _
" </tr>" & vbNewLine
if CanShowSignature = 1 and Topic_Sig = 1 and Topic_MemberSig <> "" then
Response.Write " <tr>" & vbNewLine & _
" <td valign=""bottom""><hr noshade size=""" & strFooterFontSize & """><font color=""" & strForumFontColor & """ face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><span class=""spnMessageText"">" & formatStr2(Topic_MemberSig) & "</span></font></td>" & vbNewLine & _
" </tr>" & vbNewLine
end if

Are these code changes the right ones?<
leatherlips
13 August 2008, 09:56


Those changes look right to me. Did you reload the keywords?<
Andy Humm
13 August 2008, 13:53


Did you reload the keywords? - I assume you mean upload the xml again, if yes, I have done that but still the same?<
leatherlips
13 August 2008, 14:13


No. I meant:

Code:
'if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then
LoadKeywordApps
'end if

Unless you replaced that with cripto9t's code:

Code:
if mLev < 3 then
if trim(Application(strCookieURL & "STRKEYWORDS")) = "" or trim(Application(strCookieURL & "STRKEYREPLACE")) = "" then
LoadKeywordApps
end if
else
LoadKeywordApps
end if
<
Andy Humm
13 August 2008, 17:33


Leatherlips, thank you for the PM, regarding dynamic signatures... Allow Dynamic Signatures -makes it work.. Thank You Andy<
bobby131313
13 August 2008, 18:07


Awesome crypto, thanks!
I think the only thing left is the conflict of a user initiated link and a keyword link. Obviously I would like a user initiated link to override an automated link.
That doesn't sound to my amateur mind like it would be easy though. sad<
Carefree
13 August 2008, 18:12


I never did get the KW working properly. Disabled it and went on to other things.<
leatherlips
13 August 2008, 18:21


Originally posted by bobby131313
Awesome crypto, thanks!
I think the only thing left is the conflict of a user initiated link and a keyword link. Obviously I would like a user initiated link to override an automated link.
That doesn't sound to my amateur mind like it would be easy though. sad
On my forum, a user initiated link does override the auto link. I didn't do anything different that what was provided in this thread.<
bobby131313
13 August 2008, 18:31


Really? Hmmm... let me investigate, it's been a little while since I played with it.<
Andy Humm
13 August 2008, 18:38


Ditto: On my forum, a user initiated link does override the auto link. I didn't do anything different that what was provided in this thread.<
bobby131313
13 August 2008, 19:47


I would appear you're correct. bigsmile<
Carefree
22 October 2011, 20:56


Here's a "Readers Digest Condensed Book" version of this thread:

Code:

Notes:

1. In "config.asp":

After this line (appx 473):

strShowQuickReply = Application(strCookieURL & "STRSHOWQUICKREPLY")

Insert the following:

' ## Keywords Below
IKey = Application(strCookieURL & "IKey")
KeyReplace = Application(strCookieURL & "KeyReplace")
KeyWords = Application(strCookieURL & "KeyWords")
NumOfKeys = Application(strCookieURL & "NumOfKeys")
ObjRegex = Application(strCookieURL & "ObjRegex")
ShowKeyWords = Application(strCookieURL & "ShowKeyWords")
strErr = Application(strCookieURL & "strErr")
strKeys = Application(strCookieURL & "strKeys")
strPath = Application(strCookieURL & "strPath")
strReplace = Application(strCookieURL & "strReplace")
XMLDoc = Application(strCookieURL & "XMLDoc")
' ## Keywords Above

After this line (appx 163):

Dim SubCount, MySubCount

Insert the following:

' ## Keywords Below
Dim IKey, KeyReplace, Keywords, NumOfKeys, objRegex, ShowKeyWords
Dim strErr, strKeys, strPath, strReplace, xmlDoc
' ## Keywords Above

2. In "topic.asp" (and in any other file you wish the keyword links to function):

Before this line (appx 95):

'## Forum_SQL - Get original topic and check for the Category, Forum or Topic Status and existence

Insert the following:

' ## Keywords Below
ShowKeyWords = True
' ## Keywords Above

3. In "inc_func_common.asp":

After these lines (appx 1560-1562):

Sub WriteFooterShort() %>
<!--#INCLUDE FILE="inc_footer_short.asp"-->
<% end sub

Insert the following:

' ## Keywords Below
Function ChkKeys(fString)
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
If fString = "" or IsNull(fString) Then
fString = " "
End If
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)
fString = Replace(fString, " " & keywords(i) & " ", " " & keyreplace(i) & " ", 1, -1, 1)
fString = Replace(fString, chr(13) & chr(10) & keywords(i) & " ", chr(13) & chr(10) & keyreplace(i) & " ", 1, -1, 1)
fString = Replace(fString, " " & keywords(i) & chr(13) & chr(10), " " & keyreplace(i) & chr(13) & chr(10), 1, -1, 1)
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)
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

Sub LoadKeywordApps()
strPath = strForumURL & "keywords.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)
strKeys = ""
strReplace = ""
For iKey = 0 to cLng(NumOfKeys)
If strKeys = "" Then
strKeys = xmlKeyList.item(iKey).childNodes(0).text
strReplace = "<a id=""keywords"" 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 id=""keywords"" href=""" & xmlKeyList.item(iKey).childNodes(1).text & """ target=""blank"">"
strReplace = strReplace & xmlKeyList.item(iKey).childNodes(0).text & "</a>"
End If
Next
Set xmlKeyList = Nothing
Set xmlDoc = Nothing
Application.Lock
Application(strCookieURL & "STRKEYWORDS") = strKeys
Application(strCookieURL & "STRKEYREPLACE") = strReplace
Application.UnLock
End Sub
' ## Keywords Above

Next, within "FormatStr" function:

After this line (appx 117):

on Error resume next

Insert the following:

' ## Keywords Below
If fString <> "Reply_MemberSig" and fString <> "Topic_MemberSig" Then
fString = ChkKeys(fString)
End If
' ## Keywords Above

4. keywords.xml file (You'll have to create this yourself, the file name must match the one above in green save to forum root directory):

NOTES:

a. Pattern is critical, nothing extra can be inserted.
b. If the URL is not within your forum, use the entire path (including http://),
if it is within your forum, just the internal address is sufficient (eg. topic.asp?topic_id=300)
c. If a phrase is repeated within a longer phrase (eg. "murder" and "mass murder"), then list the
longer phrase keyword first or the shorter recognized keyword will point both to the first URL.
<?xml version="1.0" encoding="ISO-8859-1"?>
<keywords>
<key>
<phrase>xml</phrase>
<url>http://some/site.xml</url>
</key>
<key>
<phrase>html</phrase>
<url>http://some/site.html</url>
</key>
<key>
<phrase>css</phrase>
<url>http://some/site.css</url>
</key>
</keywords>

Styling (optional): To add a style to the keyword links, make the following changes.
In "inc_header.asp", look for this line (appx 269):

".spnSearchHighlight {background-color:" & strSearchHiLiteColor & "}" & vbNewLine & _

After that, insert these:

"#keywords {color:" & strLinkColor & "; font-weight:normal; text-decoration:none; border-bottom-style:1px dashed; line-height:18px;}" & vbNewLine & _
"#keywords:hover {color:" & strHoverFontColor & "; font-weight:normal; text-decoration:none; border-bottom-style:1px dashed; line-height:18px;}" & vbNewLine & _

Note: I modified this to move all dimensioned variables into "config.asp" from "inc_func_common.asp", etc.
© 2000-2021 Snitz™ Communications