[pLog-svn] r3558 - in plog/trunk/class/data/validator: . rules

mark at devel.lifetype.net mark at devel.lifetype.net
Thu Jun 8 17:33:01 GMT 2006


Author: mark
Date: 2006-06-08 17:33:01 +0000 (Thu, 08 Jun 2006)
New Revision: 3558

Added:
   plog/trunk/class/data/validator/rules/filteredpatternsrule.class.php
Modified:
   plog/trunk/class/data/validator/usernamevalidator.class.php
Log:
Implement http://bugs.lifetype.net/view.php?id=904.

I use strpos and stripos. I think it faster then regexp.

And the best is it won't break the original forbidden words in config setting.

Added: plog/trunk/class/data/validator/rules/filteredpatternsrule.class.php
===================================================================
--- plog/trunk/class/data/validator/rules/filteredpatternsrule.class.php	2006-06-08 10:58:26 UTC (rev 3557)
+++ plog/trunk/class/data/validator/rules/filteredpatternsrule.class.php	2006-06-08 17:33:01 UTC (rev 3558)
@@ -0,0 +1,57 @@
+<?php
+
+    include_once( PLOG_CLASS_PATH."class/data/validator/rules/rule.class.php");
+    
+    define( "DEFAULT_PATTERN_CASE_SENSITIVE", true);
+
+    class FilteredPatternsRule extends Rule
+    {
+		var $_filteredPatterns;
+		
+        /**
+         * The constructor does nothing.
+         */
+        function FilteredPatternsRule( $filteredPatterns, $caseSensitive = DEFAULT_PATTERN_CASE_SENSITIVE )
+        {
+            $this->Rule();
+
+			$this->_caseSensitive = $caseSensitive;
+			$this->_filteredPatterns = $filteredPatterns;
+        }
+
+        /**
+         * Add function info here
+         */
+        function isCaseSensitive()
+        {
+            return $this->_caseSensitive;
+        }
+
+        /**
+         * Add function info here
+         */
+        function setCaseSensitive( $caseSensitive = DEFAULT_PATTERN_CASE_SENSITIVE )
+        {
+            $this->_caseSensitive = $caseSensitive;
+        }
+
+        /**
+		 * validates that none of the pattern in the given string
+         */
+        function validate($value)
+        {
+			foreach( $this->_filteredPatterns as $filteredPattern ) {
+				if( $this->_caseSensitive )
+				{
+					if( strpos( $value, $filteredPattern ) !== false )
+						return false;
+				} else {
+					if( stripos( $value, $filteredPattern ) !== false )
+						return false;
+				}
+			}
+			
+			return true;
+        }
+    }
+?>

Modified: plog/trunk/class/data/validator/usernamevalidator.class.php
===================================================================
--- plog/trunk/class/data/validator/usernamevalidator.class.php	2006-06-08 10:58:26 UTC (rev 3557)
+++ plog/trunk/class/data/validator/usernamevalidator.class.php	2006-06-08 17:33:01 UTC (rev 3558)
@@ -3,7 +3,7 @@
 	include_once( PLOG_CLASS_PATH."class/data/validator/validator.class.php" );
 	include_once( PLOG_CLASS_PATH."class/data/validator/rules/nonemptyrule.class.php" );
 	include_once( PLOG_CLASS_PATH."class/data/validator/rules/regexprule.class.php" );
-	include_once( PLOG_CLASS_PATH."class/data/validator/rules/filteredwordsrule.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/rules/filteredpatternsrule.class.php" );
 	
 	define( "ONLY_ALPHANUMERIC_REGEXP", "^([A-Za-z0-9]*)$" );
 
@@ -32,7 +32,7 @@
 			$config =& Config::getConfig();
 			$forbiddenUsernames = $config->getValue( "forbidden_usernames", "" );
 			$forbiddenUsernamesArray = explode( " ", $forbiddenUsernames );
-			$this->addRule( new FilteredWordsRule( $forbiddenUsernamesArray ));
+			$this->addRule( new FilteredPatternsRule( $forbiddenUsernamesArray, false ));
         }
     }
 ?>
\ No newline at end of file



More information about the pLog-svn mailing list