Smilie filter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • petvampire
    New Member
    • Jul 2009
    • 8

    Smilie filter

    hey there. im new to the coding side of asp as i learnt html before hand. What im trying to do is intergreat a smilie filter in to a small chat i building for me and and some mates. The chat is using a SQL database and IIS. my current source code for it is here:
    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="../../../../Connections/databasechat.asp" -->
    <%
    Dim chatmsg__MMColParam
    chatmsg__MMColParam = "3"
    If (Request("MM_EmptyValue") <> "") Then 
      chatmsg__MMColParam = Request("MM_EmptyValue")
    End If
    %>
    <%
    Dim chatmsg
    Dim chatmsg_numRows
    
    Set chatmsg = Server.CreateObject("ADODB.Recordset")
    chatmsg.ActiveConnection = MM_databasechat_STRING
    chatmsg.Source = "SELECT * FROM dbo.TBLmainroom WHERE TBLroom = '" + Replace(chatmsg__MMColParam, "'", "''") + "' ORDER BY ID DESC"
    chatmsg.CursorType = 0
    chatmsg.CursorLocation = 2
    chatmsg.LockType = 1
    chatmsg.Open()
    
    chatmsg_numRows = 0
    %>
    <%
    Dim Repeat1__numRows
    Dim Repeat1__index
    
    Repeat1__numRows = 100
    Repeat1__index = 0
    chatmsg_numRows = chatmsg_numRows + Repeat1__numRows
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <%Response.Expires=-1%>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script>
    <!--
    function timedRefresh(timeoutPeriod) {
    	setTimeout("location.reload(true);",timeoutPeriod);
    }
    //   -->
    </script>
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    body {
    	margin: 0px 0px 0px 0px;
    .style2 {color: #0000FF}
    .style3 {
    	font-size: 9px;
    	font-family: Arial, Helvetica, sans-serif;
    }
    .style6 {color: #FF00FF}
    .style7 {font-family: Arial, Helvetica, sans-serif}
    .style8 {
    	color: #FFFFFF;
    	font-style: italic;
    }
    .style10 {
    	font-family: Arial, Helvetica, sans-serif;
    	font-weight: bold;
    	font-style: italic;
    	color: #FF00FF;
    }
    -->
    </style>
    </head>
    <body onload="JavaScript:timedRefresh(3000);">
    <% If Not chatmsg.EOF Or Not chatmsg.BOF Then %>
      <% 
    While ((Repeat1__numRows <> 0) AND (NOT chatmsg.EOF)) 
    %>
        <strong><span class="style7"><font color="#00FF00"><%=(chatmsg.Fields.Item("TBLuser").Value)%></font></span></span> </strong><span class="style7"></span>
        <span class="style7"><font color="#9900FF"><%=(chatmsg.Fields.Item("TBLmessage").Value)%></font></span><br />
        <% 
      Repeat1__index=Repeat1__index+1
      Repeat1__numRows=Repeat1__numRows-1
      chatmsg.MoveNext()
    Wend
    %>
      <% End If ' end Not chatmsg.EOF Or NOT chatmsg.BOF %>
    </body>
    </html>
    <%
    chatmsg.Close()
    Set chatmsg = Nothing
    %>
    I want to post the smiles where the <%=(chatmsg.Fie lds.Item("TBLme ssage").Value)% > is as this displays the message. Any ideas how i go about doing this as the chat does not have any filter yet. thanks in advance.
    Last edited by Frinavale; Jul 14 '09, 02:16 PM. Reason: Added code tags. Please post code in [code] [/code] tags. Merged duplicate threads.
  • petvampire
    New Member
    • Jul 2009
    • 8

    #2
    Smilie filter

    hey there. im new to the coding side of asp as i learnt html before hand. What im trying to do is intergreat a smilie filter in to a small chat i building for me and and some mates. The chat is using a SQL database and IIS. my current source code for it is here:
    [code=asp]
    <%@LANGUAGE="VB SCRIPT" CODEPAGE="1252" %>
    <!--#include file="../../../../Connections/databasechat.as p" -->
    <%
    Dim chatmsg__MMColP aram
    chatmsg__MMColP aram = "3"
    If (Request("MM_Em ptyValue") <> "") Then
    chatmsg__MMColP aram = Request("MM_Emp tyValue")
    End If
    %>
    <%
    Dim chatmsg
    Dim chatmsg_numRows

    Set chatmsg = Server.CreateOb ject("ADODB.Rec ordset")
    chatmsg.ActiveC onnection = MM_databasechat _STRING
    chatmsg.Source = "SELECT * FROM dbo.TBLmainroom WHERE TBLroom = '" + Replace(chatmsg __MMColParam, "'", "''") + "' ORDER BY ID DESC"
    chatmsg.CursorT ype = 0
    chatmsg.CursorL ocation = 2
    chatmsg.LockTyp e = 1
    chatmsg.Open()

    chatmsg_numRows = 0
    %>
    <%
    Dim Repeat1__numRow s
    Dim Repeat1__index

    Repeat1__numRow s = 100
    Repeat1__index = 0
    chatmsg_numRows = chatmsg_numRows + Repeat1__numRow s
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <%Response.Expi res=-1%>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitl ed Document</title>
    <script>
    <!--
    function timedRefresh(ti meoutPeriod) {
    setTimeout("loc ation.reload(tr ue);",timeoutPe riod);
    }
    // -->
    </script>
    <title>Untitl ed Document</title>
    <style type="text/css">
    <!--
    body {
    margin: 0px 0px 0px 0px;
    .style2 {color: #0000FF}
    .style3 {
    font-size: 9px;
    font-family: Arial, Helvetica, sans-serif;
    }
    .style6 {color: #FF00FF}
    .style7 {font-family: Arial, Helvetica, sans-serif}
    .style8 {
    color: #FFFFFF;
    font-style: italic;
    }
    .style10 {
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    font-style: italic;
    color: #FF00FF;
    }
    -->
    </style>
    </head>
    <body onload="JavaScr ipt:timedRefres h(3000);">
    <% If Not chatmsg.EOF Or Not chatmsg.BOF Then %>
    <%
    While ((Repeat1__numR ows <> 0) AND (NOT chatmsg.EOF))
    %>
    <strong><span class="style7"> <font color="#00FF00" ><%=(chatmsg.Fi elds.Item("TBLu ser").Value)%> </font></span></span> </strong><span class="style7"> </span>
    <span class="style7"> <font color="#9900FF" ><%=(chatmsg.Fi elds.Item("TBLm essage").Value) %></font></span><br />
    <%
    Repeat1__index= Repeat1__index+ 1
    Repeat1__numRow s=Repeat1__numR ows-1
    chatmsg.MoveNex t()
    Wend
    %>
    <% End If ' end Not chatmsg.EOF Or NOT chatmsg.BOF %>
    </body>
    </html>
    <%
    chatmsg.Close()
    Set chatmsg = Nothing
    %>[/code]

    I want to post the smiles where the <%=(chatmsg.Fie lds.Item("TBLme ssage").Value)% > is as this displays the message. Any ideas how i go about doing this as the chat does not have any filter yet. thanks in advance.
    Last edited by jhardman; Jul 13 '09, 04:41 PM. Reason: added code tags

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      Originally posted by petvampire
      ...
      I want to post the smiles where the <%=(chatmsg.Fie lds.Item("TBLme ssage").Value)% > is as this displays the message. Any ideas how i go about doing this as the chat does not have any filter yet. thanks in advance.
      Hi Vamp, and welcome to Bytes.

      A couple things before I get into your question: first, we use code tags to make our posts more readable, [ code ] code goes here [ /code ] (remove the spaces to see how it works), please do the same in the future. Second, the longhand you have used for pulling up the field value is very long. The following two lines are equivalent:
      Code:
      <%=(chatmsg.Fields.Item("TBLmessage").Value)%>
      <%=chatmsg("TBLmessage")%>
      Hopefully if you figure that out now it will make your future coding a little easier.

      So to make sure I understand you, when you response.write chatmsg("TBLmes sage") you might get someting like this:
      Code:
      UR tre fun-E LOL :)
      and you want the script to replace the last two characters with a smilie graphic, right?

      The code to make the replacement is going to look something like this:
      Code:
      <%=replace(chatmsg("TBLmessage"), ":)", "<img src='smile1.gif'>")%>
      Does this make sense? Now depending on the number of smileys you want to recognize you might want to make this significantly more complicated, maybe put the replace statement in a loop in a separate function call (and now my mind is going blank on how you write functions in ASP, something like this):
      Code:
      function smilify(chatText)
         dim smileys(10)
         dim smileyGraphics(10)
         smileys(0) = ":)"
         smileys(1) = ":S"
         smileys(2) = ";)"
         '...
         smileyGraphics(0) = "<img src='smiley0.gif'>"
         smileyGraphics(1) = "<img src='smiley1.gif'>"
         smileyGraphics(2) = "<img src='smiley2.gif'>"
         '...
      
         dim fixedText
         for x = 0 to 9
            fixedText = replace(chatText, smileys(x), smileyGraphics(x))
         next
      
         response.write fixed text
      end function
      
      '...
      
      smilify(chatmsg("TBLmessage"))
      Of course you can get much fancier by keeping your smileys in a db or something, but this should work for your app. Let me know if this helps.

      Jared

      Comment

      • petvampire
        New Member
        • Jul 2009
        • 8

        #4
        still did not work

        i could not get the script to work. i got the firsrt one to work as such. i try again and i post some more

        Comment

        • petvampire
          New Member
          • Jul 2009
          • 8

          #5
          wait both them did not work. i got this error

          " microsoft VBScript runtime error '800a005e'
          Invalid use of Null: 'Replace@

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            Originally posted by petvampire
            wait both them did not work. i got this error

            " microsoft VBScript runtime error '800a005e'
            Invalid use of Null: 'Replace@
            post that exact line of code. It sounds like you have a typo there.

            Jared

            Comment

            • petvampire
              New Member
              • Jul 2009
              • 8

              #7
              Code:
               <%=(chatmsg.Fields.Item("TBLusername").Value)%></span>
                    <span class="style7"><font color="#9900FF">
              	  <%function smilify(chatText) 
                 dim smileys(10) 
                 dim smileyGraphics(10) 
                 smileys(0) = ":)" 
                 smileys(1) = ":S" 
                 smileys(2) = ";)" 
                 '... 
                 smileyGraphics(0) = "<img src='smiley0.gif'>" 
                 smileyGraphics(1) = "<img src='smiley1.gif'>" 
                 smileyGraphics(2) = "<img src='smiley2.gif'>" 
                 '... 
                
                 dim fixedText 
                 for x = 0 to 9 
                    fixedText = replace(chatText, smileys(x), smileyGraphics(x)) 
                 next 
                
                 response.write fixed text 
              end function 
                
              '... 
              %>
              <% smilify(chatmsg("TBLmessage")) %></font>
              thats how i tried to implement it. not sure if i done it correctly as my .asp know how is still limited.

              Comment

              • jhardman
                Recognized Expert Specialist
                • Jan 2007
                • 3405

                #8
                Originally posted by petvampire
                Code:
                 <%=(chatmsg.Fields.Item("TBLusername").Value)%></span>
                      <span class="style7"><font color="#9900FF">
                	  <%function smilify(chatText) 
                   dim smileys(10) 
                   dim smileyGraphics(10) 
                   smileys(0) = ":)" 
                   smileys(1) = ":S" 
                   smileys(2) = ";)" 
                   '... 
                   smileyGraphics(0) = "<img src='smiley0.gif'>" 
                   smileyGraphics(1) = "<img src='smiley1.gif'>" 
                   smileyGraphics(2) = "<img src='smiley2.gif'>" 
                   '... 
                  
                   dim fixedText 
                   for x = 0 to 9 
                      fixedText = replace(chatText, smileys(x), smileyGraphics(x)) 
                   next 
                  
                   response.write fixed text 
                end function 
                  
                '... 
                %>
                <% smilify(chatmsg("TBLmessage")) %></font>
                thats how i tried to implement it. not sure if i done it correctly as my .asp know how is still limited.
                sorry if I wasn't clear, my ellipses (...) were supposed to be other lines you wrote if you wanted to replace more smilies with graphics. the code I wrote that you copied only replaces 3. also the code that says "for x = 0 to 9", those are supposed to be the nu8mbers for which you have smilies listed in the lines where I put ellipses. for the code you copied from my post, it only makes sense to say "for x = 0 to 2" since there are only smilies 0, 1, and 2 defined. Does this make sense? The error probably just means that it tried to find a definition for smilie(3) and you never defined it.

                Let me know if this makes sense, I can probably explain it a little clearer.

                Jared

                Comment

                • petvampire
                  New Member
                  • Jul 2009
                  • 8

                  #9
                  Microsoft VBScript compilation error '800a03ea'

                  Syntax error

                  /apps/chat/room/thelocal/chat-display-push.asp, line 134

                  function smilify(chatTex t)
                  ^


                  thats the error im now getting

                  Comment

                  • jhardman
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3405

                    #10
                    Ah, I looked back over your code, and I actually gave you the code as a subroutine even though I said to use "function ... end function". Change the word "function" both at the beginning and end of that block of code to "sub" and see if it works.

                    Jared

                    Comment

                    • petvampire
                      New Member
                      • Jul 2009
                      • 8

                      #11
                      still no joy. this is the error now

                      Microsoft VBScript compilation error '800a03ea'

                      Syntax error

                      /apps/chat/room/thelocal/chat-display-push.asp, line 144

                      sub smilify(chatTex t)
                      ^

                      Comment

                      • jhardman
                        Recognized Expert Specialist
                        • Jan 2007
                        • 3405

                        #12
                        hmm. It works for me. here is the complete code I tested, and I got no error.
                        Code:
                        <%
                         sub smilify(chatText) 
                            dim smileys(10) 
                            dim smileyGraphics(10) 
                            smileys(0) = ":)" 
                            smileys(1) = ":S" 
                            smileys(2) = ";)" 
                            '... 
                            smileyGraphics(0) = "<img src='smiley0.gif'>" 
                            smileyGraphics(1) = "<img src='smiley1.gif'>" 
                            smileyGraphics(2) = "<img src='smiley2.gif'>" 
                            '... 
                          
                            dim fixedText 
                            fixedText = chatText
                            for x = 0 to 9 
                               fixedText = replace(fixedText, smileys(x), smileyGraphics(x)) 
                               response.write "<!--  -->" & vbNewLine
                            next 
                          
                            response.write fixedText & "<br>" & vbnewline
                         end sub 
                        
                        %>
                        <html>
                        <head><title></title>
                        </head>
                        <body>
                        <%
                        dim chatMsg
                        chatmsg="hi there LOL :)"
                        
                        smilify(chatMsg)
                        
                        'response.write chatMsg & "<br>" & vbNewLine
                        response.write "hello world"%>
                        </body>
                        </html>

                        Comment

                        Working...