|
|
|

|

|
Dicas
|

|
ASP - Active Server Page (Miscelâneas)
|
|
 |
Título da Dica: Mini Chat
|
 |
|
|
Postada em 3/10/2003 por ^HEAVY-METAL^
Um mini chat com filtros de palavras , ou seja nada de palavrões hehe
responsexml.asp
<% Function FilterWords(Text) Dim Temp, WordsArray, ForbiddenWords, Replacement, i Replacement = "***" ForbiddenWords = "buceta#cu#puta#viado#caralho#porra#xexeca#vagina#corno#merda#" Temp = Text WordsArray = Split(ForbiddenWords, "#") ', -1, 1) For i = 0 To UBound(WordsArray) Temp = Replace(Temp, WordsArray(i), Replacement, 1, -1, 1) Next FilterWords = Temp End Function
ACTION = Request.QueryString("action") USER = Request.QueryString("name") BODY = FilterWords(Request.QueryString("msg")) BODY = Replace(BODY,":-)","<img src=smile.gif>") BODY = Replace(BODY,":-(","<img src=mad.gif>") NUMERO_POST = 10 Set objXML = server.CreateObject("Microsoft.XMLDOM") objXML.async = False blnFileExist = objXML.load(server.MapPath("msg.xml")) NUM = objXML.documentElement.childNodes.length if NUM > NUMERO_POST then objXML.documentElement.removechild(objXML.documentElement.childNodes(0)) objXML.save(server.MapPath("msg.xml")) end if if ACTION = "add" then if USER <> "" AND BODY <> "" then Dim objXML, blnFileExist Dim objXMLv Dim intID Set objXML = server.CreateObject("Microsoft.XMLDOM") objXML.async = False blnFileExist = objXML.load(server.MapPath("msg.xml")) Set objXMLv = objXML.createElement("note") objXMLv.appendChild(objXML.createElement("from")) objXMLv.appendChild(objXML.createElement("body")) objXMLv.childNodes(0).text = USER objXMLv.childNodes(1).text = BODY objXML.documentElement.appendChild(objXMLv.cloneNode(True)) objXML.save(server.MapPath("msg.xml")) end if end if
Response.redirect("msg.xml")
%>
chat.asp
<%
Function FilterWords(Text) Dim Temp, WordsArray, ForbiddenWords, Replacement, i Replacement = "***" ForbiddenWords = "buceta#cu#puta#viado#caralho#porra#xexeca#vagina#corno#merda#" Temp = Text WordsArray = Split(ForbiddenWords, "#") ', -1, 1) For i = 0 To UBound(WordsArray) Temp = Replace(Temp, WordsArray(i), Replacement, 1, -1, 1) Next FilterWords = Temp End Function
ACTION = Request.QueryString("action") if ACTION = "logout" then Session.abandon response.redirect "default.asp" end if if Session("user") = "" then response.redirect "default.asp" end if %> <html> <head> <style> .text { font-family: Verdana; font-size: 12px; }
input { font-family: Verdana; font-size: 12px; } </style>
<script type="text/javascript">
function processXML() { xmlDoc=new ActiveXObject( "microsoft.xmldom" ); xmlDoc.async=false; xmlDoc.load("responsexml.asp");
makeDocument(); }
function appendXML() {
if ( document.sender.message.value == "" ) { return false; }
xmlDoc.load( "responsexml.asp?action=add&name="+ document.sender.nome.value +"&msg="+ document.sender.message.value ); document.sender.message.value = ""; document.sender.message.focus();
}
function makeDocument() { tableStr='<table border="0" class="text">'; people=xmlDoc.documentElement.childNodes; for ( i=0;i<people.length;i++ ) tableStr+='<tr><td>'+people[ i].childNodes[0].text+':</td><td>'+people[ i].childNodes[1].text+'</td></tr>'; tableStr+='</table>'; document.getElementById( "mainTable" ).innerHTML = tableStr;
Timer(); }
function Timer() { setTimeout( "processXML();",1000 ); }
function doKey(tasto) { Key=tasto.keyCode; if ( Key == 13) { appendXML(); } }
</script>
</head> <body onload="processXML();"> <br> <font class="text">SuperASP</font> <table style="border: solid 1px #000000" width="150" height="40%"> <tr> <td valign="top" nowrap> <div id="mainTable" > </div></td> </tr> </table> <table width="122" border="0"> <tr> <td width="122" align="left" valign="top" ><form name="sender"> <div align="center"> <input type="hidden" name="nome" value="<%=FilterWords(Session("user"))%>"> <input type="text" name="vis_nome" size="12" value="<%=FilterWords(Session("user"))%>:" readonly style="border: 0px; text-align: right;"> <br> <input type="text" name="message" size="23" maxlength="100" onKeyPress="return doKey(event)";> <br> <input type="button" value="Send" onclick="appendXML()"> <input type="button" value="Logout" onclick="document.location.href='chat.asp?action=logout'";> </div> </form></td> </tr> </table> <font class="text">Digite :-) ou :-(<br> para exibir os smiles.</font> </body> </html>
default.asp
<% ACTION = Request.QueryString("action") if ACTION = "login" then Session("user") = Request.form("login") response.redirect "chat.asp" end if %> <html> <head> <style> .text { font-family: Verdana; font-size: 12px; }
input { font-family: Verdana; font-size: 12px; } </style> </head> <body>
<br><br> <table width="100%" height="100%"> <tr> <td valign="middle" align="center"><font class="text">Digite seu nick.</font> <form action="default.asp?action=login" method="post"><input type="text" name="login" maxlength="10"> <input type="submit" value="Entrar"> </form></td> </tr> </table>
</body> </html>
T+,
|
|
|
|

|