[pLog-svn] r2221 - in plog/branches/plog-1.0.2/class: action/admin dao net

oscar at devel.plogworld.net oscar at devel.plogworld.net
Tue Jun 14 20:13:38 GMT 2005


Author: oscar
Date: 2005-06-14 20:13:37 +0000 (Tue, 14 Jun 2005)
New Revision: 2221

Modified:
   plog/branches/plog-1.0.2/class/action/admin/adminupdateblogsettingsaction.class.php
   plog/branches/plog-1.0.2/class/action/admin/adminupdateeditblogaction.class.php
   plog/branches/plog-1.0.2/class/dao/bloginfo.class.php
   plog/branches/plog-1.0.2/class/dao/blogs.class.php
   plog/branches/plog-1.0.2/class/net/customrequestgenerator.class.php
Log:
this should fix issue 589... I don't like the fix too much, but it should work.


Modified: plog/branches/plog-1.0.2/class/action/admin/adminupdateblogsettingsaction.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/action/admin/adminupdateblogsettingsaction.class.php	2005-06-14 09:49:00 UTC (rev 2220)
+++ plog/branches/plog-1.0.2/class/action/admin/adminupdateblogsettingsaction.class.php	2005-06-14 20:13:37 UTC (rev 2221)
@@ -6,6 +6,7 @@
     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
 	include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminblogsettingsview.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
 	
 
     /**
@@ -72,11 +73,14 @@
             $this->_blogInfo->setBlog( Textfilter::filterAllHTML($this->_request->getValue( "blogName" )));
             $this->_blogInfo->setSettings( $blogSettings );
 			$this->_blogInfo->setProperties( $this->_request->getValue( "properties" ));
+			$this->_blogInfo->setMangledBlog( Textfilter::urlize( $this->_blogInfo->getBlog()));
 
 
             // and now update the settings in the database
             $blogs = new Blogs();
-			$this->notifyEvent( EVENT_PRE_BLOG_UPDATE, Array( "blog" => &$this->_blogInfo ));
+                        
+            // and now we can proceed...
+			$this->notifyEvent( EVENT_PRE_BLOG_UPDATE, Array( "blog" => &$this->_blogInfo ));						
             if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
             	$this->_view = new AdminBlogSettingsView( $this->_blogInfo );
                 $this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));

Modified: plog/branches/plog-1.0.2/class/action/admin/adminupdateeditblogaction.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/action/admin/adminupdateeditblogaction.class.php	2005-06-14 09:49:00 UTC (rev 2220)
+++ plog/branches/plog-1.0.2/class/action/admin/adminupdateeditblogaction.class.php	2005-06-14 20:13:37 UTC (rev 2221)
@@ -115,8 +115,9 @@
 			$blogInfo->setProperties( $this->_blogProperties );
             $blogInfo->setOwner( $this->_blogOwner );
 			$blogInfo->setStatus( $this->_blogStatus );
-
-            // and now update the settings in the database
+            $blogInfo->setMangledBlog( Textfilter::urlize( $blogInfo->getBlog()));
+       
+            
 			$this->notifyEvent( EVENT_PRE_BLOG_UPDATE, Array( "blog" => &$blogInfo ));
             if( !$blogs->updateBlog( $blogInfo->getId(), $blogInfo )) {
             	$this->_view = new AdminSiteBlogsListView( $this->_blogInfo );

Modified: plog/branches/plog-1.0.2/class/dao/bloginfo.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/dao/bloginfo.class.php	2005-06-14 09:49:00 UTC (rev 2220)
+++ plog/branches/plog-1.0.2/class/dao/bloginfo.class.php	2005-06-14 20:13:37 UTC (rev 2221)
@@ -35,6 +35,7 @@
         var $_usersInfo;
         var $_createTimestamp;
         var $_updateTimestamp;
+        var $_mangledBlog;
 
         // the TemplateSet representing the template set used by the blog
         var $_templateSet;
@@ -76,6 +77,8 @@
             $this->_totalPosts = null;
             $this->_createTimestamp = null;
             $this->_ownerInfo = null;
+            
+            $this->_mangledBlog = Textfilter::urlize( $this->getBlog());
         }
 
         /**
@@ -548,5 +551,19 @@
 	        $this->_locale = null;
 	        return( array_keys( get_object_vars( $this )));
         }
+        
+        function setMangledBlog( $mangledBlog )
+        {
+	        $this->_mangledBlog = $mangledBlog;
+        }
+        
+        function getMangledBlog()
+        {
+	        // fill in the field if it hasn't been filled yet
+	        if( $this->_mangledBlog === null )
+	        	$this->_mangledBlog = Textfilter::urlize( $this->getBlog());
+	        	
+	    	return( $this->_mangledBlog );   
+        }
     }
 ?>

Modified: plog/branches/plog-1.0.2/class/dao/blogs.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/dao/blogs.class.php	2005-06-14 09:49:00 UTC (rev 2220)
+++ plog/branches/plog-1.0.2/class/dao/blogs.class.php	2005-06-14 20:13:37 UTC (rev 2221)
@@ -88,6 +88,7 @@
 
             // load information about the blog owner
             $blogInfo->setStatus( $query_result["status"] );
+            $blogInfo->setMangledBlog( $query_result["mangled_blog"] );
 
             return $blogInfo;
         }
@@ -284,14 +285,21 @@
          * @param blogInfo A BlogInfo object containing all the information of the blog
          * @param return Returns true if everything ok or false otherwise
          */
-        function updateBlog( $blogId, $blogInfo )
+        function updateBlog( $blogId, &$blogInfo )
         {
+	        // check if there already is a blog wiht the same mangled name
+            if( $this->getBlogInfoByName( $blogInfo->getMangledBlog())) {
+	            // and if so, assign a new one...
+	        	$newMangledName = $blogInfo->getMangledBlog().$blogInfo->getId();	    
+	        	$blogInfo->setMangledBlog( $newMangledName );
+            }	        
+	        
             $query = "UPDATE ".$this->getPrefix()."blogs SET
                      blog = '".Db::qstr($blogInfo->getBlog()).
                      "', about = '".Db::qstr($blogInfo->getAbout()).
                      "', settings = '".serialize($blogInfo->getSettings()).
-                     "', owner_id = ".$blogInfo->getOwner().
-                     ", mangled_blog = '".TextFilter::urlize($blogInfo->getBlog()).
+                     "', owner_id = ".$blogInfo->getOwner().                     
+                     ", mangled_blog = '".$blogInfo->getMangledBlog().
                      "', status = '".Db::qstr($blogInfo->getStatus()).
                      "' WHERE id = '".Db::qstr($blogId)."';";
 
@@ -367,27 +375,35 @@
          {
             $blogSettings = $blog->getSettings();
             if( !$blogSettings )
-                $blogSettings = new BlogSettings();
+                $blogSettings = new BlogSettings();                
 
             $query = "INSERT INTO ".$this->getPrefix()."blogs (blog,owner_id,about,settings,mangled_blog,status)
                      VALUES ('".Db::qstr($blog->getBlog())."',".
                      $blog->getOwner().",'".
                      Db::qstr($blog->getAbout())."', '".
-                     Db::qstr(serialize($blogSettings))."', '".
-                     TextFilter::urlize($blog->getBlog())."', '".
+                     Db::qstr(serialize($blogSettings))."', '".                     
+                     $blog->getMangledBlog()."', '".
                      Db::qstr($blog->getStatus())."')";
 
             $result = $this->Execute( $query );
 
-            if( !$result ){
-                // FIXME: throw an exception?
+            if( !$result )
                 return false;
-            }
 
 
             $blogId = $this->_db->Insert_ID();
 
             $blog->setId( $blogId );
+            
+	        // check if there already is a blog wiht the same mangled name
+            if( $this->getBlogInfoByName( $blog->getMangledBlog())) {
+	            // and if so, assign a new one...	            
+	        	$newMangledName = $blog->getMangledBlog().$blog->getId();	    
+	        	$blog->setMangledBlog( $newMangledName );
+        		// if so, let's find a new one based on the blog id (just to make it unique)
+        		$query = "UPDATE ".$this->getPrefix()."blogs SET mangled_blog = '".Db::qstr($newMangledName)."' WHERE id = '".Db::qstr($blogId)."'";
+        		$result = $this->Execute( $query );
+        	}
 
             // create the row for the bayesian filter info
             $bayesianFilterInfo = new BayesianFilterInfos();

Modified: plog/branches/plog-1.0.2/class/net/customrequestgenerator.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/net/customrequestgenerator.class.php	2005-06-14 09:49:00 UTC (rev 2220)
+++ plog/branches/plog-1.0.2/class/net/customrequestgenerator.class.php	2005-06-14 20:13:37 UTC (rev 2221)
@@ -63,7 +63,7 @@
 			$day = $t->getDay();
 			if( $day < 10 ) $day = "0".$day;
             
-            $params = Array( '{blogname}' => TextFilter::urlize($this->_blogInfo->getBlog()),
+            $params = Array( '{blogname}' => $this->_blogInfo->getMangledBlog(),
                              '{blogid}' => $this->_blogInfo->getId(),
 							 '{blogowner}' => $ownerInfo->getUsername(),
                              '{year}' => $t->getYear(),
@@ -100,7 +100,7 @@
             
             $params = Array( "{year}" => $t->getYear(),
                              "{month}" => $t->getMonth(),
-                             "{blogname}" => TextFilter::urlize($this->_blogInfo->getBlog()),
+                             "{blogname}" => $this->_blogInfo->getMangledBlog(),
 							 "{blogowner}" => $ownerInfo->getUsername(),
                              "{blogid}" => $this->_blogInfo->getId());
 			if( strlen($date) == 6 ) $params["{day}"] = "";
@@ -172,7 +172,7 @@
                              "{catname}" => TextFilter::urlize($category->getName()),
                              "{blogid}" => $this->_blogInfo->getId(),
 							 "{blogowner}" => $ownerInfo->getUsername(),
-                             "{blogname}" => TextFilter::urlize($this->_blogInfo->getBlog()));
+                             "{blogname}" => $this->_blogInfo->getMangledBlog());
             $result = $this->_replaceTags( $categoryFormat, $params );
             
             $categoryLink = $this->getBaseUrl().$result;
@@ -195,8 +195,8 @@
 			$ownerInfo = $this->_blogInfo->getOwnerInfo();			
             
             $params = Array( "{blogid}" => $this->_blogInfo->getId(),
-                             "{blogname}" => TextFilter::urlize($this->_blogInfo->getBlog()),
-							 "{blogowner}" => $ownerInfo->getUsername(),							 
+                             "{blogname}" => $this->_blogInfo->getMangledBlog(),
+							 "{blogowner}" => $ownerInfo->getUsername(),
                              "{username}" => $user->getUsername(),
                              "{userid}" => $user->getId(),
 							 "{year}" => "",
@@ -223,7 +223,7 @@
 
             $blogLinkFormat = $this->_config->getValue( "blog_link_format" );
             $params = Array( "{blogid}" => $blogInfo->getId(),
-                             "{blogname}" => TextFilter::urlize($blogInfo->getBlog()),
+                             "{blogname}" => $blogInfo->getMangledBlog(),
 							 "{blogowner}" => $ownerInfo->getUsername());
             $result = $this->getBaseUrl().$this->_replaceTags( $blogLinkFormat, $params );
             
@@ -337,7 +337,7 @@
 			$ownerInfo = $this->_blogInfo->getOwnerInfo();			
 			
 			$params = Array( "{blogid}" => $this->_blogInfo->getId(),
-			                 "{blogname}" => Textfilter::urlize($this->_blogInfo->getBlog()),
+			                 "{blogname}" => $this->_blogInfo->getMangledBlog(),
 							 "{blogowner}" => $ownerInfo->getUsername(),							 
 							 "{albumid}" => "",
 							 "{albumname}" => "" );
@@ -387,7 +387,7 @@
 			$ownerInfo = $this->_blogInfo->getOwnerInfo();			
 			
 			$params = Array( "{blogid}" => $this->_blogInfo->getId(),
-			                 "{blogname}" => Textfilter::urlize($this->_blogInfo->getBlog()),
+			                 "{blogname}" => $this->_blogInfo->getMangledBlog(),
 							 "{blogowner}" => $ownerInfo->getUsername(),
 							 "{templatename}" => $template );
 			
@@ -465,15 +465,15 @@
             	$blogId = $ownerId;
             	$blogs =& new Blogs();
 				$blogInfo = $blogs->getBlogInfo($blogId);
-				$blogShortName = $blogInfo->getBlog();
+				$blogShortName = $blogInfo->getMangledBlog();
 				$ownerInfo = $blogInfo->getOwnerInfo();
 			} else {
-				$blogShortName = $this->_blogInfo->getBlog();
+				$blogShortName = $this->_blogInfo->getMangledBlog();
 				$ownerInfo = $this->_blogInfo->getOwnerInfo();
 			}
 		
 			$params = Array( "{blogid}" => $blogId,
-			                 "{blogname}" => Textfilter::urlize($blogShortName),
+			                 "{blogname}" => $blogShortName,
 							 "{blogowner}" => $ownerInfo->getUsername(),							 
 							 "{resourceid}" => $resource->getId(),
 							 "{resourcename}" => rawurlencode($resource->getFileName()),




More information about the pLog-svn mailing list