[pLog-svn] r4703 - in plog/branches/lifetype-1.2: class/action/admin class/data/validator class/summary/action class/test/tests/data/validator locale templates/admin templates/summary

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sat Feb 10 04:05:34 EST 2007


Author: oscar
Date: 2007-02-10 04:05:34 -0500 (Sat, 10 Feb 2007)
New Revision: 4703

Added:
   plog/branches/lifetype-1.2/class/data/validator/blognamevalidator.class.php
   plog/branches/lifetype-1.2/class/test/tests/data/validator/blognamevalidator_test.class.php
Modified:
   plog/branches/lifetype-1.2/class/action/admin/adminaction.class.php
   plog/branches/lifetype-1.2/class/action/admin/adminaddblogaction.class.php
   plog/branches/lifetype-1.2/class/action/admin/admindoregisterblogaction.class.php
   plog/branches/lifetype-1.2/class/action/admin/adminupdateblogsettingsaction.class.php
   plog/branches/lifetype-1.2/class/action/admin/adminupdateeditblogaction.class.php
   plog/branches/lifetype-1.2/class/summary/action/doblogregistration.class.php
   plog/branches/lifetype-1.2/locale/locale_en_UK.php
   plog/branches/lifetype-1.2/locale/locale_es_ES.php
   plog/branches/lifetype-1.2/templates/admin/createblog.template
   plog/branches/lifetype-1.2/templates/admin/editblog.template
   plog/branches/lifetype-1.2/templates/admin/globalsettings_summary.template
   plog/branches/lifetype-1.2/templates/summary/registerstep2.template
Log:
Added a new validator class to take care of validating blog names, BlogNameValidator (and its tests) So far blog names were being validated as non-empty strings but that's too little... It uses the config key forbidden_bognames to aviod users having blogs called "www", "ftp" or admin and get blog names such as www.mysite.com if subdomains are enabled. In addition to that, it checks the that the domainized() version of the blog name is not empty to make sure that people don't end up with blog names like "//::--" that would result in an empty domainized blog name.


Modified: plog/branches/lifetype-1.2/class/action/admin/adminaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/adminaction.class.php	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/class/action/admin/adminaction.class.php	2007-02-10 09:05:34 UTC (rev 4703)
@@ -129,7 +129,7 @@
         {
             $session = HttpVars::getSession();
             $sessionInfo = $session["SessionInfo"];
-            $this->_userInfo = $sessionInfo->getValue("userInfo");           
+            $this->_userInfo = $sessionInfo->getValue("userInfo");
         }
 
         /**

Modified: plog/branches/lifetype-1.2/class/action/admin/adminaddblogaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/adminaddblogaction.class.php	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/class/action/admin/adminaddblogaction.class.php	2007-02-10 09:05:34 UTC (rev 4703)
@@ -4,6 +4,7 @@
     lt_include( PLOG_CLASS_PATH."class/view/admin/admincreateblogview.class.php" );
     lt_include( PLOG_CLASS_PATH."class/view/admin/adminsiteblogslistview.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/blognamevalidator.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/domainvalidator.class.php" );
     lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
@@ -28,7 +29,7 @@
         	$this->AdminAction( $actionInfo, $request );
         	
         	// data validation
-        	$this->registerFieldValidator( "blogName", new StringValidator());
+        	$this->registerFieldValidator( "blogName", new BlogNameValidator());
         	$this->registerFieldValidator( "userId", new IntegerValidator());
 			if( Subdomains::getSubdomainsEnabled()) {
 				$this->registerFieldValidator( "blogSubDomain", new DomainValidator());

Modified: plog/branches/lifetype-1.2/class/action/admin/admindoregisterblogaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/admindoregisterblogaction.class.php	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/class/action/admin/admindoregisterblogaction.class.php	2007-02-10 09:05:34 UTC (rev 4703)
@@ -4,6 +4,7 @@
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminregisterblogview.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/view/admin/admindashboardview.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/validator/blognamevalidator.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );	
     lt_include( PLOG_CLASS_PATH."class/data/validator/domainvalidator.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
@@ -22,7 +23,7 @@
 		{
 			$this->AdminAction( $actionInfo, $request );
 			
-			$this->registerFieldValidator( "blogName", new StringValidator());
+			$this->registerFieldValidator( "blogName", new BlogNameValidator());
             $this->registerFieldValidator( "blogSubDomain", new DomainValidator(), true );
             $this->registerFieldValidator( "blogMainDomain", new DomainValidator(), true );
             $this->registerFieldValidator( "blogLocale", new StringValidator());

Modified: plog/branches/lifetype-1.2/class/action/admin/adminupdateblogsettingsaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/adminupdateblogsettingsaction.class.php	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/class/action/admin/adminupdateblogsettingsaction.class.php	2007-02-10 09:05:34 UTC (rev 4703)
@@ -3,6 +3,7 @@
 	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
     lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/blognamevalidator.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/view/admin/adminblogsettingsview.class.php" );
@@ -33,7 +34,7 @@
 			$this->registerFieldValidator( "blogMaxMainPageItems", $val );			
 			// the rest of validators, as normal...
 			$this->registerFieldValidator( "blogMaxRecentItems", new IntegerValidator());
-			$this->registerFieldValidator( "blogName",  new StringValidator());
+			$this->registerFieldValidator( "blogName",  new BlogNameValidator());
 			$this->registerFieldValidator( "blogLocale", new StringValidator());
 			$this->registerFieldValidator( "blogTemplate", new StringValidator());
 			$this->registerFieldValidator( "blogCategory", new IntegerValidator());

Modified: plog/branches/lifetype-1.2/class/action/admin/adminupdateeditblogaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/adminupdateeditblogaction.class.php	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/class/action/admin/adminupdateeditblogaction.class.php	2007-02-10 09:05:34 UTC (rev 4703)
@@ -7,6 +7,7 @@
     lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
     lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/blognamevalidator.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/domainvalidator.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
@@ -41,7 +42,7 @@
 			
 			// data validation
 			$this->registerFieldValidator( "blogUsers", new ArrayValidator(), true );
-			$this->registerFieldValidator( "blogName", new StringValidator());
+			$this->registerFieldValidator( "blogName", new BlogNameValidator());
 			$this->registerFieldValidator( "blogId", new IntegerValidator());
 			$this->registerFieldValidator( "blogStatus", new IntegerValidator());
 			$this->registerFieldValidator( "blogLocale", new StringValidator());

Added: plog/branches/lifetype-1.2/class/data/validator/blognamevalidator.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/validator/blognamevalidator.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.2/class/data/validator/blognamevalidator.class.php	2007-02-10 09:05:34 UTC (rev 4703)
@@ -0,0 +1,47 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/data/validator/validator.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/validator/rules/nonemptyrule.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/validator/rules/filteredpatternsrule.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
+
+    /**
+     * \ingroup Validator
+     *
+     * Checks if a blog name is valid. Usernames have to comply with the following rules:
+     *
+	 * - They must not be empty
+	 * - They must not match any of the regular expressions set by administrators as forbidden_blogname_regexp
+     *
+     * @see NonEmptyRule
+     * @see RegExpRule
+     */
+    class BlogNameValidator extends Validator 
+    {
+    	function BlogNameValidator()
+        {
+        	$this->Validator();
+        	
+			// it can't be empty
+        	$this->addRule( new NonEmptyRule());
+
+			// it can't be any of the forbidden ones
+			$config =& Config::getConfig();			
+			$forbiddenBlognames = $config->getValue( "forbidden_blognames", "" );
+			$forbiddenBlognamesArray = explode( " ", $forbiddenBlognames );
+			$this->addRule( new FilteredPatternsRule( $forbiddenBlognamesArray, false ));
+        }
+
+		function validate( $value )
+		{
+			if( !parent::validate( $value )) 
+				return false;
+				
+			// in addition to the other rules, the blog name won't be valid if its domainized() version
+			// returns empty spaces, so this is what would happen if we set a blog name of
+			// things like non-characters for example
+			lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );			
+			return(( Textfilter::domainize( Textfilter::filterAllHTML( $value ))) != "" );
+		}
+    }
+?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/class/summary/action/doblogregistration.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/summary/action/doblogregistration.class.php	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/class/summary/action/doblogregistration.class.php	2007-02-10 09:05:34 UTC (rev 4703)
@@ -3,13 +3,14 @@
 	lt_include( PLOG_CLASS_PATH."class/summary/action/registeraction.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/blognamevalidator.class.php" );
     lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );	 		
 	lt_include( PLOG_CLASS_PATH."class/summary/view/doblogregistrationview.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/summary/view/blogtemplatechooserview.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/domainvalidator.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
-	include_once( PLOG_CLASS_PATH."class/config/config.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );	
 
 	/**
 	 * registers a blog
@@ -23,7 +24,7 @@
 	    	
 	    	// data validation
 	    	//$this->registerFieldValidator( "userId", new IntegerValidator());
-	    	$this->registerFieldValidator( "blogName", new StringValidator());
+	    	$this->registerFieldValidator( "blogName", new BlogNameValidator());
 	    	$this->registerFieldValidator( "blogCategoryId", new IntegerValidator());
 	    	$this->registerFieldValidator( "blogLocale", new StringValidator());
 			$config =& Config::getConfig();

Added: plog/branches/lifetype-1.2/class/test/tests/data/validator/blognamevalidator_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/data/validator/blognamevalidator_test.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.2/class/test/tests/data/validator/blognamevalidator_test.class.php	2007-02-10 09:05:34 UTC (rev 4703)
@@ -0,0 +1,67 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/validator/blognamevalidator.class.php" );
+
+	/**
+	 * \ingroup Test
+	 *
+	 * Test case for the BlogNameValidator class
+	 */
+	class BlogNameValidator_Test extends LifeTypeTestCase
+	{
+		function setUp()
+		{
+			// create a username validator
+			$this->b = new BlogNameValidator();
+		}
+		
+		/**
+		 * tests that an empty username does not validate
+		 */
+		function testEmptyBlogname()
+		{
+			$this->assertFalse( $this->b->validate( "" ), "An empty blogname did not generate an error!" );
+		}
+		
+		/**
+		 * tests that a forbidden username does not validate
+		 */
+		function testForbiddenBlognameRegexps()
+		{
+			// get the list of forbidden words, based on our configuration settings
+			lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
+			$config =& Config::getConfig();
+			
+			// blog names starting with 'a' and ending with 'b'
+			$forbiddenBlognames = $config->setValue( "forbidden_blognames", "^a.*" );
+			
+			$this->assertFalse( $this->b->validate( "a-this should not work" ), "A forbidden blogname should not be accepted as valid!" );
+			$this->assertTrue( $this->b->validate( "-this should work" ), "A valid blogname was not accepted as valid!" );
+		}
+		
+		/**
+		 * tests a valid username
+		 */
+		function testValidBlogname()
+		{
+			$this->assertTrue( $this->b->validate( "whatever" ), "A valid blogname was not accepted!" );
+		}
+		
+		/**
+		 * test a blog name that one domainized will return empty
+		 */
+		function testInvalidBlogName()
+		{
+			$this->assertFalse( $this->b->validate( "//::--", "The domainized() version of the blog name returned empty but the name was accepted as valid" ));
+		}
+		
+		/**
+		 * Test a blog name whose contents if pure HTML
+		 */
+		function testHTMLBlogNameOnly()
+		{
+			$this->assertFalse( $this->b->validate( "<h1></h1>", "A blog name containing HTML code only was accepted as valid" ));
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/locale/locale_en_UK.php
===================================================================
--- plog/branches/lifetype-1.2/locale/locale_en_UK.php	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/locale/locale_en_UK.php	2007-02-10 09:05:34 UTC (rev 4703)
@@ -1244,9 +1244,11 @@
 $messages['help_default_global_article_category_id'] = 'Identifier of the default global article category [ Default = empty ]';
 $messages['help_blog_does_not_exist_url'] = 'URL where users will be forwarded when they attempt to reach a blog that does not exist in this site, instead of being forwarded to the site\'s default blog [ Default = empty ]';
 
+$messages['error_invalid_blog_name'] = 'The blog name is not valid';
 $messages['bookmark_it_to_lifetype'] = 'Bookmark it to LifeType!';
 
 /* strings for /default/ templates */
 $messages['form_authenticated'] = 'Authenticated';
 
+$messages['help_forbidden_blognames'] = 'List of strings separated by a blank space that are not allowed to be used as blog names. It is possible to use regular expressions instead of plain strings. [ Default = (empty) ]';
 ?>

Modified: plog/branches/lifetype-1.2/locale/locale_es_ES.php
===================================================================
--- plog/branches/lifetype-1.2/locale/locale_es_ES.php	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/locale/locale_es_ES.php	2007-02-10 09:05:34 UTC (rev 4703)
@@ -1238,4 +1238,10 @@
 $messages['trackback_urls_help'] = 'LifeType puede encontrar las direcciones donde enviar retroenlaces automáticamente si el enlace de destino lo soporta. 
 Si los enlaces que forman parte del texto del artículo no incluyen esta característica, por favor añada cada una de las direcciones de retroenlaces "reales" (una por línea)';
 
+$messages['error_invalid_blog_name'] = 'El nombre de la bitácora no es válido';
+
+/* strings for /default/ templates */
+$messages['form_authenticated'] = 'Autentificado';
+
+$messages['help_forbidden_blognames'] = 'Lista de cadenas separadas por un espacio en blanco que no se pueden usar como nombres de bitácora. Es posible usar una expresión regular en lugar de una simple cadena. [ Valor por defecto = (vacío) ]';
 ?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/templates/admin/createblog.template
===================================================================
--- plog/branches/lifetype-1.2/templates/admin/createblog.template	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/templates/admin/createblog.template	2007-02-10 09:05:34 UTC (rev 4703)
@@ -9,7 +9,7 @@
        <span class="required">*</span>
        <div class="formHelp">{$locale->tr("blog_name_help")}</div>
        <input type="text" style="width:95%" name="blogName" id="blogName" value="{$blogName}"/>
-       {include file="$admintemplatepath/validate.template" field=blogName message=$locale->tr("error_empty_name")}
+       {include file="$admintemplatepath/validate.template" field=blogName message=$locale->tr("error_invalid_blog_name")}
      </div>
 	
     {if $blogDomainsEnabled}

Modified: plog/branches/lifetype-1.2/templates/admin/editblog.template
===================================================================
--- plog/branches/lifetype-1.2/templates/admin/editblog.template	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/templates/admin/editblog.template	2007-02-10 09:05:34 UTC (rev 4703)
@@ -41,7 +41,7 @@
       <span class="required">*</span>
       <div class="formHelp">{$locale->tr("blog_name_help")}</div>
       <input type="text" name="blogName" style="width:100%" id="blogName" value="{$blogName|escape:"html"}" />
-      {include file="$admintemplatepath/validate.template" field=blogName message=$locale->tr("error_empty_name")}
+      {include file="$admintemplatepath/validate.template" field=blogName message=$locale->tr("error_invalid_blog_name")}
     </div>
 
     <div class="field">

Modified: plog/branches/lifetype-1.2/templates/admin/globalsettings_summary.template
===================================================================
--- plog/branches/lifetype-1.2/templates/admin/globalsettings_summary.template	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/templates/admin/globalsettings_summary.template	2007-02-10 09:05:34 UTC (rev 4703)
@@ -30,6 +30,12 @@
     <div class="formHelp">{$locale->tr("help_forbidden_usernames")}</div>
     <input style="width:100%" type="text" id="config[forbidden_usernames]" name="config[forbidden_usernames]" value="{$forbidden_usernames}"/>
    </div>
+   <!-- forbidden_blognames -->
+   <div class="field">
+    <label for="config[forbidden_blognames]">forbidden_blognames</label>
+    <div class="formHelp">{$locale->tr("help_forbidden_blognames")}</div>
+    <input style="width:100%" type="text" id="config[forbidden_blognames]" name="config[forbidden_blognames]" value="{$forbidden_blognames}"/>
+   </div>
    <!-- force_one_blog_per_email_account -->
    <div class="field">
     <label for="config[force_one_blog_per_email_account]">force_one_blog_per_email_account</label>

Modified: plog/branches/lifetype-1.2/templates/summary/registerstep2.template
===================================================================
--- plog/branches/lifetype-1.2/templates/summary/registerstep2.template	2007-02-10 00:58:03 UTC (rev 4702)
+++ plog/branches/lifetype-1.2/templates/summary/registerstep2.template	2007-02-10 09:05:34 UTC (rev 4703)
@@ -20,7 +20,7 @@
      <label for="blogName">{$locale->tr("name")}</label>
      <div class="formHelp">{$locale->tr("register_blog_name_help")}</div>
      <input type="text" name="blogName" value="{$blogName}" id="blogName" size="40" />
-     {include file="summary/validate.template" field=blogName message=$locale->tr("error_empty_name")}
+     {include file="summary/validate.template" field=blogName message=$locale->tr("error_invalid_blog_name")}
    </div>
 
    {if $blogDomainsEnabled}



More information about the pLog-svn mailing list