[pLog-svn] r4072 - in plog/branches/lifetype-1.1.1/class: action/admin dao data test/tests/dao test/tests/data

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sun Oct 1 20:26:43 GMT 2006


Author: oscar
Date: 2006-10-01 20:26:43 +0000 (Sun, 01 Oct 2006)
New Revision: 4072

Modified:
   plog/branches/lifetype-1.1.1/class/action/admin/adminupdateblogsettingsaction.class.php
   plog/branches/lifetype-1.1.1/class/action/admin/adminupdateeditblogaction.class.php
   plog/branches/lifetype-1.1.1/class/dao/bloginfo.class.php
   plog/branches/lifetype-1.1.1/class/dao/blogs.class.php
   plog/branches/lifetype-1.1.1/class/data/textfilter.class.php
   plog/branches/lifetype-1.1.1/class/test/tests/dao/bloginfo_test.class.php
   plog/branches/lifetype-1.1.1/class/test/tests/dao/blogs_test.class.php
   plog/branches/lifetype-1.1.1/class/test/tests/data/textfilter_test.class.php
Log:
Fixes for mantis case http://bugs.lifetype.net/view.php?id=1076, where the changes made in 1.1 are not backwards compatible with older installations. The problem here is that althought the 'mangled' name of the blog used for custom urls is stored in the mangled_blog field, BlogInfo::setMangledBlogName() (called from Blogs::mapRow()) was calling once again Textfilter::domainize() and this, in the case of sites with blog names like 'my_blog_name' was mangling the name again to "my-blog-name". While it is very nice to generate domain names that follow the domain name specs, I guess we should be careful with backwards compatibility (this would generate a ton of broken links)

Now BlogInfo::setMangledBlogName() has an extra boolean parameter that tells whether to really mangle the name given or not. It is set to 'false' by default, so that Blogs::mapRow() simply uses whatever is stored in the database without further modifications.

Additionally, Textfilter::domainize() now also follows urlize_word_separator to determine which character to use as word separator in domain names. New installations will get '-' as default but old installation can easily revert to '_' so that all blog names are consistent (old ones and newly created ones)


Modified: plog/branches/lifetype-1.1.1/class/action/admin/adminupdateblogsettingsaction.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/action/admin/adminupdateblogsettingsaction.class.php	2006-10-01 19:41:36 UTC (rev 4071)
+++ plog/branches/lifetype-1.1.1/class/action/admin/adminupdateblogsettingsaction.class.php	2006-10-01 20:26:43 UTC (rev 4072)
@@ -93,7 +93,7 @@
             $this->_blogInfo->setTemplate( $this->_request->getValue( "blogTemplate" ));
 			$this->_blogInfo->setProperties( $this->_request->getValue( "properties" ));
 			$this->_blogInfo->setBlogCategoryId( $this->_request->getValue( "blogCategory" ));
-			$this->_blogInfo->setMangledBlogName( $this->_blogInfo->getBlog());
+			$this->_blogInfo->setMangledBlogName( $this->_blogInfo->getBlog(), true );
 			$this->_blogInfo->setShowInSummary( Textfilter::checkboxToBoolean( $this->_request->getValue( "blogShowInSummary" )));
 			
             // check to see whether we are going to save subdomain information			

Modified: plog/branches/lifetype-1.1.1/class/action/admin/adminupdateeditblogaction.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/action/admin/adminupdateeditblogaction.class.php	2006-10-01 19:41:36 UTC (rev 4071)
+++ plog/branches/lifetype-1.1.1/class/action/admin/adminupdateeditblogaction.class.php	2006-10-01 20:26:43 UTC (rev 4072)
@@ -113,7 +113,7 @@
 			$blogInfo->setProperties( $this->_blogProperties );
             $blogInfo->setOwner( $this->_blogOwner );
 			$blogInfo->setStatus( $this->_blogStatus );
-            $blogInfo->setMangledBlogName( Textfilter::urlize( $blogInfo->getBlog()));
+            $blogInfo->setMangledBlogName( $blogInfo->getBlog(), true );
 
             // check to see whether we are going to save subdomain information			
             if( Subdomains::getSubdomainsEnabled()) {

Modified: plog/branches/lifetype-1.1.1/class/dao/bloginfo.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/dao/bloginfo.class.php	2006-10-01 19:41:36 UTC (rev 4071)
+++ plog/branches/lifetype-1.1.1/class/dao/bloginfo.class.php	2006-10-01 20:26:43 UTC (rev 4072)
@@ -609,10 +609,13 @@
 		 *
 		 * @param mangledBlog the new mangled blog name
 		 */
-		function setMangledBlogName( $mangledBlog )
+		function setMangledBlogName( $mangledBlog, $modify = false )
 		{
-	        include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );			
-	        $this->_mangledBlog = Textfilter::domainize( $mangledBlog );
+			if( $modify ) {
+	        	include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+				$mangledBlog = Textfilter::domainize( $mangledBlog );
+			}
+			$this->_mangledBlog = $mangledBlog;
 		}
 		
 		/**
@@ -622,8 +625,8 @@
 		{
 	        // fill in the field if it hasn't been filled yet
 	        if( $this->_mangledBlog === null ) {
-	        	include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );		
-	        	$this->_mangledBlog = Textfilter::domainize( $this->getBlog());	
+	        	include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+				$this->setMangledBlogName( $this->getBlog(), true );
 			}
 	        	
 	    	return( $this->_mangledBlog );  

Modified: plog/branches/lifetype-1.1.1/class/dao/blogs.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/dao/blogs.class.php	2006-10-01 19:41:36 UTC (rev 4071)
+++ plog/branches/lifetype-1.1.1/class/dao/blogs.class.php	2006-10-01 20:26:43 UTC (rev 4072)
@@ -408,7 +408,7 @@
 			$blogInfo->setTotalTrackbacks( $row['num_trackbacks'] );
 			$blogInfo->setTotalComments( $row['num_comments'] );
 			// mangled blog
-			$blogInfo->setMangledBlogName( $row['mangled_blog'] );
+			$blogInfo->setMangledBlogName( $row['mangled_blog'], false );
 			$blogInfo->setCustomDomain( $row['custom_domain'] );
             // show in summary or not
 			$blogInfo->setShowInSummary( $row['show_in_summary'] );

Modified: plog/branches/lifetype-1.1.1/class/data/textfilter.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/data/textfilter.class.php	2006-10-01 19:41:36 UTC (rev 4071)
+++ plog/branches/lifetype-1.1.1/class/data/textfilter.class.php	2006-10-01 20:26:43 UTC (rev 4072)
@@ -437,6 +437,7 @@
          * or replaced will be thrown away.
          *
          * @param string The string that we wish to convert into something that can be used as a URL
+ 	     * @static
          */
         function domainize( $string )
         {
@@ -446,15 +447,19 @@
             // removing a set of reserved characters (rfc2396: ; / ? : @ & = + $ ,)
             $string = str_replace(array(';','/','?',':','@','&','=','+','$',','), '', $string);
 
+            include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+			$config =& Config::getConfig();
+            $sep = $config->getValue( "urlize_word_separator", URLIZE_WORD_SEPARATOR_DEFAULT );
+
             // replace some characters to similar ones
             // underscores aren't allowed in domain names according to rfc specs, and
             // cause trouble in some browsers, particularly with cookies.
-            $search  = array('_',' ', '.', 'ä','ö','ü','é','è','à','ç','à','è','ì','ò','ù','á','é','í','ó','ú','ë','ï' );
-            $replace = array('-','-', '-', 'a','o','u','e','e','a','c','a','e','i','o','u','a','e','i','o','u','e','i' );
+            $search  = array('-', '_',' ', '.', 'ä','ö','ü','é','è','à','ç','à','è','ì','ò','ù','á','é','í','ó','ú','ë','ï' );
+            $replace = array( $sep, $sep, $sep, $sep, 'a','o','u','e','e','a','c','a','e','i','o','u','a','e','i','o','u','e','i' );
             $string = str_replace($search, $replace, $string);
 
             // and everything that is still left that hasn't been replaced/encoded, throw it away
-            $string = preg_replace( '/[^a-z0-9-]/', '', $string );
+            $string = preg_replace( "/[^a-z0-9".$sep."]/", '', $string );
             $string = trim($string, "-.");
 
             return $string;            

Modified: plog/branches/lifetype-1.1.1/class/test/tests/dao/bloginfo_test.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/test/tests/dao/bloginfo_test.class.php	2006-10-01 19:41:36 UTC (rev 4071)
+++ plog/branches/lifetype-1.1.1/class/test/tests/dao/bloginfo_test.class.php	2006-10-01 20:26:43 UTC (rev 4072)
@@ -54,13 +54,16 @@
 		 */
 		function testSetMangledBlogName()
 		{
-			$blogName = "this_is_a_blog____  name";
-			
+			// when set to 'true', the second parameter modifies the blog name
+			$blogName = "this_is_a_blog____  name";			
         	$blog = new BlogInfo( "blah", 1, "blah blah", new BlogSettings());
-
-			$blog->setMangledBlogName( $blogName );
-			
+			$blog->setMangledBlogName( $blogName, true );			
 			$this->assertEquals( Textfilter::domainize( $blogName ), $blog->getMangledBlogName());
+			// and went set to 'false' (default value) it won't
+			$blogName = "this_is_a_blog____  name";			
+        	$blog2 = new BlogInfo( "blah", 1, "blah blah", new BlogSettings());
+			$blog2->setMangledBlogName( $blogName, false );
+			$this->assertEquals( "this_is_a_blog____  name", $blog2->getMangledBlogName());			
 		}
 	}
 ?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.1.1/class/test/tests/dao/blogs_test.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/test/tests/dao/blogs_test.class.php	2006-10-01 19:41:36 UTC (rev 4071)
+++ plog/branches/lifetype-1.1.1/class/test/tests/dao/blogs_test.class.php	2006-10-01 20:26:43 UTC (rev 4072)
@@ -68,13 +68,13 @@
 			// update the name and the mangled blog name, in the same way it is done in
 			// class/action/admin/adminupdateblogsettingsaction.class.php
 			$blog1->setBlog( $randomName );
-			$blog1->setMangledBlogName( $randomName );
+			$blog1->setMangledBlogName( $randomName, true );
 			$blogs->updateBlog( $blog1 );
-			$blog2->setMangledBlogName( $randomName );			
+			$blog2->setMangledBlogName( $randomName, true );
 			$blog2->setBlog( $randomName );
-			$blog2->setMangledBlogName( $randomName );			
+			$blog2->setMangledBlogName( $randomName, true );
 			$blogs->updateBlog( $blog2 );
-			$blog3->setMangledBlogName( $randomName );			
+			$blog3->setMangledBlogName( $randomName, true );
 			$blog3->setBlog( $randomName );	
 			$blogs->updateBlog( $blog3 );
 			

Modified: plog/branches/lifetype-1.1.1/class/test/tests/data/textfilter_test.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/test/tests/data/textfilter_test.class.php	2006-10-01 19:41:36 UTC (rev 4071)
+++ plog/branches/lifetype-1.1.1/class/test/tests/data/textfilter_test.class.php	2006-10-01 20:26:43 UTC (rev 4072)
@@ -49,19 +49,24 @@
 		 */
 		function testDomainize()
 		{
+			// load the value of the default separator
+			$config =& Config::getConfig();
+            $sep = $config->getValue( "urlize_word_separator", URLIZE_WORD_SEPARATOR_DEFAULT );			
+			
 			// set of input values and their expected output
 			$tests = Array(
-				"test blog" => "test-blog",
-				"test-blog" => "test-blog",
-				"test-blog" => "test-blog",
-				"test.blog" => "test-blog",
+				"test blog" => "test{$sep}blog",
+				"test-blog" => "test{$sep}blog",
+				"test_blog" => "test{$sep}blog",
+				"test.blog" => "test{$sep}blog",
 				"??test//blog" => "testblog",
-				"==================test blog" => "test-blog"
+				"==================test blog" => "test{$sep}blog",
+				"this.has.dots_and-hyphens----and   spaces		    " => "this{$sep}has{$sep}dots{$sep}and{$sep}hyphens{$sep}{$sep}{$sep}{$sep}and{$sep}spaces{$sep}"
 			);
 			
 			foreach( $tests as $input => $output ) {
 				$result = $this->tf->domainize( $input );
-				$this->assertEquals( $output, $result );
+				$this->assertEquals( $output, $result, "input was: $input" );
 			}
 		}
 	}



More information about the pLog-svn mailing list