Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/Code)
 Keyword Links - Last Update 6/9/08
 New Topic  Reply to Topic
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 7

cripto9t
Average Member

USA
881 Posts

Posted - 28 May 2008 :  16:55:41  Show Profile  Reply with Quote
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
<?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
function FormatStr(fString)
 on Error resume next

ADD this line right under that
fString = ChkKeys(fString)
</li><li>
Add this code before this line "%>" near the bottom of the file.
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
Dim ShowKeyWords : ShowKeyWords = True
Somewhere after <font color="red"><%</font id="red">. In "topic.asp" I added it after these lines
%>
<!--#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
".spnSearchHighlight {background-color:" & strSearchHiLiteColor & "}" & vbNewLine & _
Add this line right after that
"#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>


    _-/Cripto9t\-_

Edited by - cripto9t on 09 June 2008 15:29:55

leatherlips
Senior Member

USA
1838 Posts

Posted - 28 May 2008 :  19:11:31  Show Profile  Visit leatherlips's Homepage  Reply with Quote
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.<

Mangione Magic Forum - The Music of Chuck Mangione

My Mods: Googiespell MOD | Link To Reply MOD | Petition MOD | Contact Page MOD | Share This Topic MOD | MP3 MOD | PageEar MOD | Google Viewer MOD

Edited by - leatherlips on 28 May 2008 19:11:54
Go to Top of Page

leatherlips
Senior Member

USA
1838 Posts

Posted - 28 May 2008 :  19:33:18  Show Profile  Visit leatherlips's Homepage  Reply with Quote
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.<

Mangione Magic Forum - The Music of Chuck Mangione

My Mods: Googiespell MOD | Link To Reply MOD | Petition MOD | Contact Page MOD | Share This Topic MOD | MP3 MOD | PageEar MOD | Google Viewer MOD

Edited by - leatherlips on 28 May 2008 19:33:50
Go to Top of Page

cripto9t
Average Member

USA
881 Posts

Posted - 28 May 2008 :  20:04:10  Show Profile  Reply with Quote
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.

quote:
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?<

    _-/Cripto9t\-_
Go to Top of Page

leatherlips
Senior Member

USA
1838 Posts

Posted - 28 May 2008 :  20:25:34  Show Profile  Visit leatherlips's Homepage  Reply with Quote
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<

Mangione Magic Forum - The Music of Chuck Mangione

My Mods: Googiespell MOD | Link To Reply MOD | Petition MOD | Contact Page MOD | Share This Topic MOD | MP3 MOD | PageEar MOD | Google Viewer MOD
Go to Top of Page

AnonJr
Moderator

United States
5768 Posts

Posted - 28 May 2008 :  20:31:41  Show Profile  Visit AnonJr's Homepage  Reply with Quote
Post a link to the xml file, I bet your problem is in there...<
Go to Top of Page

leatherlips
Senior Member

USA
1838 Posts

Posted - 28 May 2008 :  20:34:57  Show Profile  Visit leatherlips's Homepage  Reply with Quote
Here is my xml file:

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

I only added a few keywords while testing.<

Mangione Magic Forum - The Music of Chuck Mangione

My Mods: Googiespell MOD | Link To Reply MOD | Petition MOD | Contact Page MOD | Share This Topic MOD | MP3 MOD | PageEar MOD | Google Viewer MOD
Go to Top of Page

bobby131313
Senior Member

USA
1163 Posts

Posted - 28 May 2008 :  20:52:43  Show Profile  Visit bobby131313's Homepage  Reply with Quote
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!<

Switch the order of your title tags
Go to Top of Page

AnonJr
Moderator

United States
5768 Posts

Posted - 28 May 2008 :  22:59:21  Show Profile  Visit AnonJr's Homepage  Reply with Quote
quote:
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.<
Go to Top of Page

phy1729
Average Member

USA
589 Posts

Posted - 28 May 2008 :  23:24:09  Show Profile  Reply with Quote
Other than the fact that there's no DTD or Schema I don't see anything wrong.<
Go to Top of Page

cripto9t
Average Member

USA
881 Posts

Posted - 29 May 2008 :  09:21:53  Show Profile  Reply with Quote
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


Bobby, for testing, comment out the "if" and "end if" lines.
'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 .


phy, DTD schema, maybe later .<

    _-/Cripto9t\-_
Go to Top of Page

bobby131313
Senior Member

USA
1163 Posts

Posted - 29 May 2008 :  09:48:28  Show Profile  Visit bobby131313's Homepage  Reply with Quote
Still stuck. I've commented out the lines as you said. I've deleted all cookies and cache, run setup.... variables are still stuck. <

Switch the order of your title tags
Go to Top of Page

bobby131313
Senior Member

USA
1163 Posts

Posted - 29 May 2008 :  09:53:03  Show Profile  Visit bobby131313's Homepage  Reply with Quote
Do the 2 variables need to be dimmed in config.asp?<

Switch the order of your title tags
Go to Top of Page

cripto9t
Average Member

USA
881 Posts

Posted - 29 May 2008 :  10:09:56  Show Profile  Reply with Quote
Two bugs 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\-_
Go to Top of Page

cripto9t
Average Member

USA
881 Posts

Posted - 29 May 2008 :  10:29:28  Show Profile  Reply with Quote
quote:
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?<

    _-/Cripto9t\-_
Go to Top of Page

bobby131313
Senior Member

USA
1163 Posts

Posted - 29 May 2008 :  10:35:15  Show Profile  Visit bobby131313's Homepage  Reply with Quote
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.<

Switch the order of your title tags

Edited by - bobby131313 on 29 May 2008 10:35:39
Go to Top of Page
Page: of 7 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000 Version 3.4.07