[svn] r6178: nemerle/trunk/snippets/blogComments.n

nazgul svnadmin at nemerle.org
Sun Apr 9 16:33:40 CEST 2006


Log:
Antyspam improvement

Author: nazgul
Date: Sun Apr  9 16:33:39 2006
New Revision: 6178

Modified:
   nemerle/trunk/snippets/blogComments.n

Modified: nemerle/trunk/snippets/blogComments.n
==============================================================================
--- nemerle/trunk/snippets/blogComments.n	(original)
+++ nemerle/trunk/snippets/blogComments.n	Sun Apr  9 16:33:39 2006
@@ -152,20 +152,29 @@
        .Replace ("\n", "<br/>")
     }
 
+    antyspam_pattern (mutable content : string) : bool {
+      content = content.ToLower ();
+
+      content.IndexOf ("href=") != -1 || 
+      content.IndexOf ("[url]http") != -1 || 
+      content.IndexOf ("[url=") != -1 || {
+        mutable count = 0;
+        mutable last = 0;
+        while (last < content.Length && {last = content.IndexOf ("http"); last != -1 })
+          count++;
+        count > 2
+      }
+    }
 
     store_comment () : void
     {
-      def f = File.AppendText (output_path + ".body.html");
       def body = quote (get_with_default (post, "body"));
       def ip = getenv ("REMOTE_ADDR");
       def nick = quote (get_with_default (post, "nick"));
-      def lbody = body.ToLower ();
-      if (lbody.IndexOf ("href=") != -1 || 
-          lbody.IndexOf ("[url]http") != -1 || 
-          lbody.IndexOf ("[url=") != -1) {
+      if (antyspam_pattern (nick) || antyspam_pattern (body))
         comment_rejected = true;
-        f.Close ();
-      } else {
+      else {
+        def f = File.AppendText (output_path + ".body.html");
         f.Write ($ "<p class='poster'>From: $nick ($ip)</p>\n<p class='body'>$body</p>\n");
         f.Close ();
       }



More information about the svn mailing list