[pLog-svn] r2419 - in plog/branches/plog-1.1-daochanges: class/action class/action/admin class/dao class/dao/customfields class/gallery/dao class/gallery/resizers class/net/http class/net/http/session class/view/admin templates/admin

oscar at devel.plogworld.net oscar at devel.plogworld.net
Wed Aug 24 21:19:08 GMT 2005


Author: oscar
Date: 2005-08-24 21:19:08 +0000 (Wed, 24 Aug 2005)
New Revision: 2419

Added:
   plog/branches/plog-1.1-daochanges/class/gallery/resizers/gallerythumbnailgenerator.class.php
Modified:
   plog/branches/plog-1.1-daochanges/class/action/admin/adminaddpostaction.class.php
   plog/branches/plog-1.1-daochanges/class/action/admin/admindeletecommentaction.class.php
   plog/branches/plog-1.1-daochanges/class/action/admin/adminnewresourceaction.class.php
   plog/branches/plog-1.1-daochanges/class/action/commentaction.class.php
   plog/branches/plog-1.1-daochanges/class/action/resourceserveraction.class.php
   plog/branches/plog-1.1-daochanges/class/action/viewresourceaction.class.php
   plog/branches/plog-1.1-daochanges/class/dao/article.class.php
   plog/branches/plog-1.1-daochanges/class/dao/articlecategories.class.php
   plog/branches/plog-1.1-daochanges/class/dao/articlecomments.class.php
   plog/branches/plog-1.1-daochanges/class/dao/articles.class.php
   plog/branches/plog-1.1-daochanges/class/dao/bloginfo.class.php
   plog/branches/plog-1.1-daochanges/class/dao/commentscommon.class.php
   plog/branches/plog-1.1-daochanges/class/dao/customfields/customfield.class.php
   plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldcheckboxvalue.class.php
   plog/branches/plog-1.1-daochanges/class/dao/customfields/customfielddatevalue.class.php
   plog/branches/plog-1.1-daochanges/class/dao/customfields/customfields.class.php
   plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldsvalues.class.php
   plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldvalue.class.php
   plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldvaluefactory.class.php
   plog/branches/plog-1.1-daochanges/class/dao/trackbacks.class.php
   plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryalbum.class.php
   plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryalbums.class.php
   plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresource.class.php
   plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresourcequotas.class.php
   plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresources.class.php
   plog/branches/plog-1.1-daochanges/class/net/http/httpvars.class.php
   plog/branches/plog-1.1-daochanges/class/net/http/session/sessionmanager.class.php
   plog/branches/plog-1.1-daochanges/class/view/admin/admineditpostview.class.php
   plog/branches/plog-1.1-daochanges/class/view/admin/adminresourceslistview.class.php
   plog/branches/plog-1.1-daochanges/templates/admin/resources.template
Log:
all my latest changes from the last 3 weeks... Adding and removing items should work fine for all of the DAO classes except custom fields. Updating items hasn't been completely
implemented yet, specially the part that needs to update counters and so on. Sorting of items hasn't been implemented either, but that shouldn't be too difficult. 
This means that this branch should be working quite well now except for the issues above... I will probably merge this with the main 1.1 trunk unless somebody has something to say :-) I don't
think it makes too much sense to keep so many separate branches, and hopefully with only one branch we will all start working together towards getting this release ready before the end of the year (though to be sincere, this looks more like a 2006 release)


Modified: plog/branches/plog-1.1-daochanges/class/action/admin/adminaddpostaction.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/action/admin/adminaddpostaction.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/action/admin/adminaddpostaction.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -58,6 +58,7 @@
 			
 			$articles = new Articles();
 			$article->setFields( $this->_getArticleCustomFields());			
+			print_r($article->_customFields);
 			
 			// notifiy about this event
 			$this->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article ));				
@@ -100,8 +101,15 @@
             // the post to the database
 			$postText = Textfilter::xhtmlize($this->_postText).POST_EXTENDED_TEXT_MODIFIER.Textfilter::xhtmlize($this->_postExtendedText);
 			
-			$article  = new Article( $this->_postTopic, $postText, $this->_postCategories,
-									 $this->_userInfo->getId(), $this->_blogInfo->getId(), $this->_postStatus, 0, Array(), $this->_postSlug );
+			$article  = new Article( $this->_postTopic, 
+			                         $postText, 
+			                         $this->_postCategories,
+									 $this->_userInfo->getId(), 
+									 $this->_blogInfo->getId(), 
+									 $this->_postStatus, 
+									 0, 
+									 Array(), 
+									 $this->_postSlug );
 			// set also the date before it's too late
 			$article->setDateObject( $this->_postTimestamp );
 			$article->setCommentsEnabled( $this->_commentsEnabled );
@@ -183,4 +191,4 @@
             return true;
         }
     }
-?>
+?>
\ No newline at end of file

Modified: plog/branches/plog-1.1-daochanges/class/action/admin/admindeletecommentaction.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/action/admin/admindeletecommentaction.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/action/admin/admindeletecommentaction.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -88,7 +88,6 @@
 			// loop through the comments and remove them
             foreach( $this->_commentIds as $commentId ) {
             	// fetch the comment
-                //$comment = $comments->getPostComment( $this->_articleId, $commentId );
 				$comment = $comments->getComment( $commentId );
 				
 				if( !$comment ) {
@@ -101,11 +100,11 @@
 					// check if the comment really belongs to this blog...
 					$article = $comment->getArticle();
 					if( $article->getBlogId() != $this->_blogInfo->getId()) {
-						// if not, then we shouldn't be allowed to remove anything!
+						// if not, then we shouldn't be allowed to remove anything!						
 						$errorMessage .= $this->_locale->pr("error_deleting_comment", $comment->getTopic())."<br/>";
 					}
 					else {
-						if( !$comments->deletePostComment( $article->getId(), $commentId ))
+						if( !$comments->deleteComment( $commentId ))
 							$errorMessage .= $this->_locale->pr("error_deleting_comment", $comment->getTopic())."<br/>";
 						else {
 							$totalOk++;

Modified: plog/branches/plog-1.1-daochanges/class/action/admin/adminnewresourceaction.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/action/admin/adminnewresourceaction.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/action/admin/adminnewresourceaction.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -45,8 +45,9 @@
         function perform()
         {
             // check that we have at least one album where to put our pictures
-            $albums = new GalleryAlbums();			
-            if( $albums->getNumUserAlbums( $this->_blogInfo->getId()) == 0 ) {
+            $albums = new GalleryAlbums();
+            $blogAlbums = $albums->getNestedAlbumList( $this->_blogInfo->getId());            
+            if( count( $blogAlbums ) == 0 ) {
             	$this->_view = new AdminNewAlbumView( $this->_blogInfo );
                 $this->_view->setErrorMessage( $this->_locale->tr("error_must_create_album_first"));
                 $this->setCommonData();

Modified: plog/branches/plog-1.1-daochanges/class/action/commentaction.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/action/commentaction.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/action/commentaction.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -72,7 +72,7 @@
 			$postComments = $comments->getPostComments( $article->getId());
 			if( $this->_parentId > 0 ) {
 				// get a pre-set string for the subject field, for those users interested
-				$comment = $comments->getPostComment( $this->_parentId, $article->getId());
+				$comment = $comments->getComment( $this->_parentId );
 				// create the string
 				if( $comment ) {
 					$replyString = $this->_locale->tr("reply_string").$comment->getTopic();

Modified: plog/branches/plog-1.1-daochanges/class/action/resourceserveraction.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/action/resourceserveraction.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/action/resourceserveraction.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -7,7 +7,6 @@
 	include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
 	include_once( PLOG_CLASS_PATH."class/net/http/httpcache.class.php" );
     include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );	
-	include_once( PLOG_CLASS_PATH."class/net/url.class.php" );
     include_once( PLOG_CLASS_PATH."class/security/pipeline.class.php" );
     include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );	
 

Modified: plog/branches/plog-1.1-daochanges/class/action/viewresourceaction.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/action/viewresourceaction.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/action/viewresourceaction.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -55,7 +55,6 @@
         function perform()
         {
         	$galleryResources = new GalleryResources();
-			$galleryAlbums = new GalleryAlbums();
 			
 			// initialize the view
             $this->_view = new BlogView( $this->_blogInfo,
@@ -74,6 +73,8 @@
 			
 			// try to find the album to which this resource belongs
 			if( $this->_albumName ) {
+			    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );			
+				$galleryAlbums = new GalleryAlbums();				
 				$album = $galleryAlbums->getAlbumByName( $this->_albumName, $this->_blogInfo->getId(), false, true );
 				if( !$album ) {
 					$this->_view = new ErrorView( $this->_blogInfo );

Modified: plog/branches/plog-1.1-daochanges/class/dao/article.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/article.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/article.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -789,7 +789,7 @@
 		 *
 		 * @return An array of CustomFieldValue objects
 		 */
-		function getFields()
+		function getCustomFields()
 		{
 			if( is_null($this->_customFields) ) {
                 include_once( PLOG_CLASS_PATH.'class/dao/customfields/customfieldsvalues.class.php' );	
@@ -797,7 +797,7 @@
 				$customFields = new CustomFieldsValues();
 				$fields = $customFields->getArticleCustomFieldsValues( $this->getId(), $this->getBlog());
 				$this->setFields( $fields );
-			}						
+			}
 			
 			return $this->_customFields;
 		}
@@ -812,7 +812,7 @@
 		{
 			// if fields haven't been loaded yet, do so now
 			if( is_null($this->_fields) )
-				$this->getFields();
+				$this->getCustomFields();
 		
 			return $this->_fields["$fieldName"];
 		}
@@ -827,7 +827,7 @@
 		{
 			// if fields haven't been loaded yet, do so now
 			if( is_null($this->_fields) )
-				$this->getFields();		
+				$this->getCustomFields();		
 		
 			$fieldName = $fieldValue->getName();
 			$this->_fields["$fieldName"] = $fieldValue;

Modified: plog/branches/plog-1.1-daochanges/class/dao/articlecategories.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/articlecategories.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/articlecategories.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -117,6 +117,9 @@
 			                                     CACHE_ARTICLE_CATEGORIES_BYNAME => "getMangledName" ),
 			                              $page,
 			                              $itemsPerPage );
+			                              
+			if( !$categories )
+				return Array();
 			
 			/**
 			 * :TODO:

Modified: plog/branches/plog-1.1-daochanges/class/dao/articlecomments.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/articlecomments.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/articlecomments.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -46,14 +46,6 @@
         }
 
         /**
-         * Retrieves only one post from a given article
-         */
-        function getPostComment( $artid, $commentid )
-		{
-			return( CommentsCommon::getPostComment( $commentid, $artid, COMMENT_TYPE_COMMENT ));			
-		}
-
-        /**
          * Returns true if there already is a comment in the database with the same
          * article_id field, topic, text, replying to the same comment, username and so on
          * Useful in case we want to check if the user sent the same comment by mistake
@@ -68,32 +60,6 @@
 														 $userUrl, $clientIp, COMMENT_TYPE_COMMENT ));
         }
 
-		/**
-		 * Removes a comment from a post. It also updates all the other posts that
-         * have this one as the parent and makes them look as if they were 'top level'
-         * comments with no parent.
-         *
-         * @param artid The article identifier.
-         * @param commentid The comment identifier.
-		 */
-		function deletePostComment( $artid, $commentid )
-		{
-			return( CommentsCommon::deletePostComment( $artid, $commentid, COMMENT_TYPE_COMMENT ));
-		}
-		
-		/**
-		 * Removes a comment from a post. It also updates all the other posts that
-         * have this one as the parent and makes them look as if they were 'top level'
-         * comments with no parent.
-         *
-         * @param commentid The comment identifier.
-         * @param articleId The article identifier.		 
-		 */
-		function deleteComment( $commentid, $articleId = -1 )
-		{
-			return( $this->deletePostComment( $articleId, $commentid ));
-		}		
-
         /**
          * updates the status of a comment, regarding its spam status...
          *

Modified: plog/branches/plog-1.1-daochanges/class/dao/articles.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/articles.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/articles.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -335,8 +335,10 @@
 		                $maxDate = 0, 
 		                $searchTerms = "" )
 		{
-			if( $article->getStatus() != $status )
-				return false;
+			if( $status != POST_STATUS_ALL ) {
+				if( $article->getStatus() != $status )
+					return false;
+			}
 			if( $categoryId > 0 ) {
 				$found = false;
 				foreach( $article->getCategoryIds() as $catId ) {
@@ -351,6 +353,16 @@
 				if( $article->getUserId() != $userId )
 					return false;
 			}
+			if( $date > -1 ) {
+				$postDate = substr($article->getDate(),0,strlen($date));
+				if( $postDate != $date )
+					return false;
+			}
+			if( $maxDate > 0 ) {			
+				$postDate = substr($article->getDate(),0,strlen($maxDate));
+				if( $postDate > $maxDate )
+					return false;				
+			}
 			
 			return( true );
 		}
@@ -384,18 +396,19 @@
                                   $searchTerms = "", 
                                   $page        = -1 )
         {
-        	$articles = $this->getArticles( $blogId );
+        	$articles = $this->getArticles( $blogId );        	
         	
         	$result = Array();
-        	$add = false;
         	$total = 0;
         	foreach( $articles as $article ) {
-        		if( $this->check( $article )) {
+        		if( $this->check( $article, $date, $categoryId, $status, $userId, $maxDate, $searchTerms )) {
         			$result[] = $article;
         			$total++;
         		}
-        		if( $total >= $amount )
-        			break;
+        		if( $amount != -1 ) {
+	        		if( $total >= $amount )
+    	    			break;
+    	    	}
         	}
         	
         	return( $result );
@@ -637,6 +650,7 @@
 
             // and save the custom fields
             $customFields = new CustomFieldsValues();
+            $fields = $newArticle->getCustomFields();
             foreach( $fields as $field ) {
                 $customFields->addCustomFieldValue( $field->getFieldId(), 
                                                     $field->getValue(), 

Modified: plog/branches/plog-1.1-daochanges/class/dao/bloginfo.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/bloginfo.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/bloginfo.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -532,8 +532,8 @@
             // if there is no quota for this blog, then fetch it from the global
             // settings
             if( $quota == "" ) {
-                $config =& Config::getConfig();
-                $quota = $config->getValue( "resources_quota" );
+            	include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcequotas.class.php" );
+            	$quota = GalleryResourceQuotas::getGlobalResourceQuota();
             }
 
             return $quota;

Modified: plog/branches/plog-1.1-daochanges/class/dao/commentscommon.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/commentscommon.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/commentscommon.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -64,20 +64,25 @@
 				$this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE );
 				// update the article comments
 				$article = $comment->getArticle();
+				$blog = $article->getBlogInfo();
 				if( $comment->getType() == COMMENT_TYPE_COMMENT ) {
 					$article->setTotalComments( $article->getTotalComments() + 1 );
 					if( $comment->getStatus() == COMMENT_STATUS_ACTIVE ) {
 						$article->setNumComments( $article->getNumComments() +1 );
 					}
+					$blog->setTotalComments( $blog->getTotalComments() + 1 );
 				}
 				else {
 					$article->setTotalTrackbacks( $article->getTotalTrackbacks() + 1 );
 					if( $comment->getStatus() == COMMENT_STATUS_ACTIVE ) {
-						$article->setNumTrackbackss( $article->getNumTrackbacks() +1 );
-					}				
+						$article->setNumTrackbacks( $article->getNumTrackbacks() +1 );
+					}
+					$blog->setTotalTrackbacks( $blog->getTotalTrackbacks() + 1 );					
 				}
 				$articles = new Articles();
 				$articles->updateArticle( $article );
+				$blogs = new Blogs();
+				$blogs->updateBlog( $blog );
         	}
         	return( $result );
         }
@@ -156,28 +161,47 @@
 
 			// get the number of items and return it to the caller
 			return( $this->getNumItems( $table, $cond ));		
-        }		
-
+        }
+        
         /**
-         * Retrieves only one post from a given article
+         * returns the number of comments that a blog has
+         *
+         * @param blogId
+         * @param status
+         * @param type
+         * @return The number of comments, or 0 if error or no comments
          */
-        function getPostComment( $commentId, $articleId = -1, $type = COMMENT_TYPE_ANY )
-		{
-			$comment = $this->get( "id" , $commentid, CACHE_ARTICLE_COMMENTS );
-			if( !$comment )
-				return false;
-			if( $articleId > -1 ) {
-				if( $comment->getArticleId() != $articleId )
-					return false;
-			}
-			if( $type != COMMENT_TYPE_ANY ) {
-				if( $comment->getType() != $type ) {
-					return false;
-				}
-			}
-				
-			return( $comment );
-		}
+        function getNumBlogComments( $blogId, $status = COMMENT_STATUS_ALL, $type = COMMENT_TYPE_ANY )
+        {
+        	if( $status == COMMENT_STATUS_ALL && $type =! COMMENT_TYPE_ANY ) {
+        		// fast case, we can load the blog and query one of its intrinsic fields
+        		include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+        		$blogs = new Blogs();
+        		$blogInfo = $blogs->getBlogInfoById( $blogId );
+        		if( !$blogInfo )
+        			$numComments = 0;
+        		else {
+        			if( $type == COMMENT_TYPE_COMMENT )
+	        			$numComments = $blog->getTotalComments();
+	        		else
+	        			$numComments = $blog->getTotalTrackbacks();
+        		}
+        	}
+        	else {
+				// create the table name
+				$prefix = $this->getPrefix();
+				$table = "{$prefix}articles_comments";
+				// and the condition if any...
+				$cond = "blog_id = '".Db::qstr($blogId)."'";
+				if( $status != COMMENT_STATUS_ALL )
+					$cond .= " AND status = '".Db::qstr($status)."'";
+				if( $type != COMMENT_TYPE_ANY )
+					$query .= " AND type = '".Db::qstr($type)."'";				
+				$numComments = $this->getNumItems( $table, $cond );
+        	}
+        	
+        	return( $numComments );
+        }
 
 		/**
 		 * Removes a comment from a post. It also updates all the other posts that
@@ -186,11 +210,10 @@
          *
          * @param artid The article identifier.
          * @param commentid The comment identifier.
-		 * @param type
 		 */
-		function deletePostComment( $artid, $commentid, $type = COMMENT_TYPE_ANY )
+		function deleteComment( $commentid )
 		{
-			$comment = $this->getPostComment( $commentid, $artid, $type );
+			$comment = $this->getComment( $commentid );
 			if( $comment )  {
 				$this->delete( "id", $commentid );
 	            // update all the other posts
@@ -198,9 +221,38 @@
         	    $result = $this->Execute( $query );
         	    $this->_cache->removeData( $comment->getId(), CACHE_ARTICLE_COMMENTS );
         	    $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE );
+        	    
+        	    // update the blog and the article counters
+        	    include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+        	    include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+
+        	    $article = $comment->getArticle();
+        	    $blog = $article->getBlogInfo();
+        	    $type = $comment->getType();
+        	    if( $type == COMMENT_TYPE_COMMENT ) {
+	        	    $blog->setTotalComments( $blog->getTotalComments() - 1 );
+	        		$article->setTotalComments( $article->getTotalComments() - 1 );	        	    
+		        	if( $comment->getStatus() == COMMENT_STATUS_ACTIVE ) {
+		        		$article->setNumComments( $article->getNumComments() - 1 );		        		
+		        	}
+	        	}
+	        	else {
+	        	    $blog->setTotalTrackbacks( $blog->getTotalTrackbacks() - 1 );	        	
+	        		$article->setTotalTrackbacks( $article->getTotalTrackbacks() - 1 );
+		        	if( $comment->getStatus() == COMMENT_STATUS_ACTIVE ) {
+		        		$article->setNumTrackbacks( $article->getNumTrackbacks() - 1 );		        		
+		        	}
+	        	}
+        	    $blogs = new Blogs();
+	        	$blogs->updateBlog( $blog );
+        	    $articles = new Articles();
+        	    $articles->updateArticle( $article );        	    
 			}
-			else
+			else {
 				return false;
+			}
+				
+			return( true );
 		}		
 
         /**
@@ -258,7 +310,7 @@
 		 */
 		function getComment( $id, $type = COMMENT_TYPE_ANY )
 		{
-			$comment = $this->get( "id" , $commentid, CACHE_ARTICLE_COMMENTS );
+			$comment = $this->get( "id" , $id, CACHE_ARTICLE_COMMENTS );
 			if( !$comment )
 				return false;
 			if( $type != COMMENT_TYPE_ANY ) {

Modified: plog/branches/plog-1.1-daochanges/class/dao/customfields/customfield.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/customfields/customfield.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/customfields/customfield.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -29,6 +29,15 @@
 			$this->_searchable = $searchable;
 			$this->_hidden = $hidden;
 			$this->_defaultValue = "";
+			
+			$this->_fields = Array(
+				"field_name" => "getName",
+				"blog_id" => "getBlogId",
+				"field_description" => "getDescription",
+				"field_type" => "getType",
+				"hidden" => "getHidden",
+				"searchable" => "getSearchable"
+			);
 		}
 		
 		function getBlogId()
@@ -36,6 +45,11 @@
 			return $this->_blogId;
 		}
 		
+		function setBlogId( $blogId )
+		{
+			$this->_blogId = $blogId;
+		}		
+		
 		function getId()
 		{
 			return $this->_id;
@@ -109,6 +123,11 @@
 			$this->_hidden = $hidden;
 		}
 		
+		function setSearchable( $searchable )
+		{
+			$this->searchable = $searchable;
+		}
+		
 		function getDefaultValue()
 		{
 			return $this->_defaultValue;	

Modified: plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldcheckboxvalue.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldcheckboxvalue.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldcheckboxvalue.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -14,9 +14,9 @@
 		 *
 		 * @see CustomFieldValue
 		 */
-		function CustomFieldCheckboxValue( $fieldId, $fieldValue, $fieldName, $fieldType, $fieldDescription, $articleId, $blogId, $id = -1 )
+		function CustomFieldCheckboxValue( $fieldId, $fieldValue, $articleId, $blogId, $id = -1 )
 		{
-			$this->CustomFieldValue( $fieldId, $fieldValue, $fieldName, $fieldType, $fieldDescription, $articleId, $blogId, $id );
+			$this->CustomFieldValue( $fieldId, $fieldValue, $articleId, $blogId, $id );
 			
 			$this->setValue( $fieldValue );
 		}

Modified: plog/branches/plog-1.1-daochanges/class/dao/customfields/customfielddatevalue.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/customfields/customfielddatevalue.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/customfields/customfielddatevalue.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -16,9 +16,9 @@
 		 *
 		 * @see CustomFieldValue
 		 */
-		function CustomFieldDateValue( $fieldId, $fieldValue, $fieldName, $fieldType, $fieldDescription, $articleId, $blogId, $id = -1 )
+		function CustomFieldDateValue( $fieldId, $fieldValue, $articleId, $blogId, $id = -1 )
 		{
-			$this->CustomFieldValue( $fieldId, $fieldValue, $fieldName, $fieldType, $fieldDescription, $articleId, $blogId, $id );
+			$this->CustomFieldValue( $fieldId, $fieldValue, $articleId, $blogId, $id );
 			
 			$this->setValue( $fieldValue );
 		}

Modified: plog/branches/plog-1.1-daochanges/class/dao/customfields/customfields.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/customfields/customfields.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/customfields/customfields.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -15,6 +15,10 @@
 	define( "CUSTOM_FIELD_DATE", 4 );
 	define( "CUSTOM_FIELD_LIST", 5 );
 	define( "CUSTOM_FIELD_MULTILIST", 6 );
+	
+	define( "CACHE_CUSTOMFIELDS", "customfields" );
+	define( "CACHE_CUSTOMFIELDS_BLOG", "customfields_blog" );
+	define( "CACHE_CUSTOMFIELDS_BY_NAME", "customfields_name" );	
 
 	/**
      * Model for the custom fields
@@ -25,6 +29,7 @@
 		function CustomFields()
 		{
 			$this->Model();
+			$this->table = $this->getPrefix()."custom_fields_definition";
 		}
 		
 		/**
@@ -35,19 +40,7 @@
 		 */
 		function getCustomField( $id )
 		{
-			$query = "SELECT * FROM ".$this->getPrefix()."custom_fields_definition
-			          WHERE id = $id
-					  ORDER BY date ASC";
-					  
-			$result = $this->Execute( $query );
-			
-			if( !$result )
-				return false;
-				
-			if( $result->RowCount() == 0 )
-				return false;
-			else
-				return $this->_fillCustomFieldInformation( $result->FetchRow());
+			return( $this->get( "id", $id, CACHE_CUSTOMFIELDS ));
 		}
 
 		/**
@@ -59,17 +52,18 @@
 		 */		
 		function getCustomFieldByName( $blogId, $fieldName )
 		{
-			$query = "SELECT * FROM ".$this->getPrefix()."custom_fields_definition
-			          WHERE field_name = '".$fieldName."' AND blog_id = $blogId";
-					  
-			$result = $this->Execute( $query );
-			
-			if( !$result )
+			$blogFields = $this->getMany( "blog_id", 
+			                              $blogId, 
+			                              CACHE_CUSTOMFIELDS_BLOG,
+			                              Array( CACHE_CUSTOMFIELDS => "getId" ));
+			if( !$blogFields )
 				return false;
-			if( $result->RowCount() == 0 )
-				return false;
-				
-			return $this->_fillCustomFieldInformation( $result->FetchRow());					  
+			foreach( $blogFields as $field ) {
+				if( $field->getName() == $fieldName ) {
+					// we can return right away, no need to bother...
+					return( $field );
+				}
+			}
 		}
 		
 		/**
@@ -85,26 +79,29 @@
 		 */
 		function getBlogCustomFields( $blogId, $includeHidden = true, $page = -1, $itemsPerPage = 15 )
 		{
-
-			$query = "SELECT * FROM ".$this->getPrefix()."custom_fields_definition
-			          WHERE blog_id = $blogId";
-			if( !$includeHidden )
-				$query .= " AND hidden = 0 ";
-			$query .= " ORDER BY date ASC $limits";
-					  
-			$result = $this->Execute( $query, $page, $itemsPerPage );
-			
-			$fields = Array();			
-			
-			if( !$result )
-				return $fields;
-			
-			while( $row = $result->FetchRow()) {
-				$field = $this->_fillCustomFieldInformation( $row );
-				$fields[$field->getName()] = $field;
+			$blogFields = $this->getMany( "blog_id",
+			                              $blogId,
+			                              CACHE_CUSTOMFIELDS_BLOG,
+			                              Array( CACHE_CUSTOMFIELDS => "getId" ),
+			                              $page, 
+			                              $itemsPerPage );
+			                              
+			if( !$blogFields )
+				return( Array());
+			                          
+			// if we have to include the hidden fields, we can return the whole array as 
+			// those are already there
+			if( $includeHidden )
+				return( $blogFields );
+			                          
+			// if not, filter out the non-hidden
+			$result = Array();
+			foreach( $blogFields as $field ) {
+				if( !$field->isHidden())
+					$result[] = $field;
 			}
-		
-			return $fields;
+			
+			return( $result );
 		}
 
 		/**
@@ -115,30 +112,10 @@
 		 */
 		function getNumBlogCustomFields( $blogId, $includeHidden = true )
 		{
-			$prefix = $this->getPrefix();
-			$table  = "{$prefix}custom_fields_definition";
-			$cond = "blog_id = '".Db::qstr($blogId)."'";
-			if( !$includeHidden )
-				$cond .=  " AND hidden = 0";			
-			
-			return( $this->getNumItems( $table, $cond ));
+			return( count( $this->getBlogCustomFields( $blogId, $includeHidden )));
 		}
 		
 		/**
-		 * returns true if the given field already exists in the database
-		 *
-		 * @param fieldName
-		 * @param blogId
-		 * @return True if the field already exists or false otherwise
-		 */
-		function fieldExists( $fieldName, $blogId )
-		{
-			$field = $this->getCustomFieldByName( $blogId, $fieldName );
-			
-			return( $field != false );
-		}
-		
-		/**
 		 * adds a custom field to the database
 		 *
 		 * @param field A CustomField object
@@ -146,25 +123,17 @@
 		 */
 		function addCustomField( &$field )
 		{		
-			if( $this->fieldExists( $field->getName(), $field->getBlogId()))
+			// does the field already exist?
+			$existingField = $this->getCustomFieldByName( $field->getBlogId(), $field->getName());
+			if( $existingField ) // it already exists, we cannot add it!
 				return false;
-		
-			$query = "INSERT INTO ".$this->getPrefix()."custom_fields_definition
-			          (field_name, field_description, field_type, blog_id, searchable, hidden) VALUES(
-					  '".Db::qstr($field->getName())."','".Db::qstr($field->getDescription()).
-					  "', ".$field->getType().", ".$field->getBlogId().", ".$field->isSearchable().
-					  ", ".$field->isHidden().");";
-					  
-			$result = $this->Execute( $query );
-			
-			if( !$result ) 
-				return false;
 				
-			$fieldId = $this->_db->Insert_ID();
-			
-			$field->setId( $fieldId );
-			
-			return( $fieldId );
+			if( $result = $this->add( $field )) {
+				// clean the caches
+				$this->_cache->removeData( $field->getId(), CACHE_CUSTOMFIELDS );
+				$this->_cache->removeData( $field->getBlogId(), CACHE_CUSTOMFIELDS_BLOG );
+			}
+			return( $result );
 		}
 		
 		/**
@@ -179,14 +148,18 @@
 		 */
 		function removeCustomField( $id, $deleteValues = true )
 		{
-			$query = "DELETE FROM ".$this->getPrefix()."custom_fields_definition
-			          WHERE id = $id";
+			$field = $this->getCustomField( $id );
 			
-			$result = $this->Execute( $query );
+			if( !$field )
+				return false;
 			
-			if( !$result )
+			if( !$this->delete( "id", $id ));
 				return false;
 				
+			// clean the caches
+			$this->_cache->removeData( $field->getId(), CACHE_CUSTOMFIELDS );
+			$this->_cache->removeData( $field->getBlogId(), CACHE_CUSTOMFIELDS_BLOG );
+				
 			if( !$deleteValues )
 				return true;
 			
@@ -203,23 +176,18 @@
 		 */
 		function updateCustomField( $field )
 		{
-			$query = "UPDATE ".$this->getPrefix()."custom_fields_definition
-			          SET field_name = '".Db::qstr($field->getName())."',
-					  field_description = '".Db::qstr($field->getDescription())."',
-					  field_type = ".Db::qstr($field->getType()).",
-					  date = date,
-					  hidden = ".$field->isHidden()."
-					  WHERE id = ".$field->getId();
-
-			$result = $this->Execute( $query );
-			
-			return $result;
+			if( ($result = $this->update( $field ))) {
+				// clean the caches
+				$this->_cache->removeData( $field->getId(), CACHE_CUSTOMFIELDS );
+				$this->_cache->removeData( $field->getBlogId(), CACHE_CUSTOMFIELDS_BLOG );
+			}
+			return( $result );
 		}
 		
 		/**
 		 * @private
 		 */
-		function _fillCustomFieldInformation( $row )
+		function mapRow( $row )
 		{
 			$field = new CustomField( $row["field_name"],
 			                          $row["field_description"],

Modified: plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldsvalues.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldsvalues.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldsvalues.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -1,9 +1,11 @@
 <?php
 
     include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
-    include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/customfields/customfields.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/customfields/customfieldvaluefactory.class.php" );        
+    
+    define( "CACHE_CUSTOMFIELDVALUES", "customfieldvalues" );    
+    define( "CACHE_CUSTOMFIELDVALUES_ARTICLE", "customfieldvalues_article" );
 
     /**
      * Model for the values given to certain custom fields
@@ -16,30 +18,16 @@
         function CustomFieldsValues()
         {
             $this->Model();
+            $this->table = $this->getPrefix()."custom_fields_values";
         }
         
         /**
-         * gets the value associated to the custom field with the given id
-         *
-         * @param id The id of the custom field value
+         * @param id
          * @return A CustomFieldValue object
          */
         function getCustomFieldValue( $id )
         {
-            require_once( PLOG_CLASS_PATH . 'class/database/db.class.php' );
-
-            $query = Db::buildSelectQuery( CUSTOMFIELD_VALUES,
-                                           array(),
-                                           'id',
-                                           $id,
-                                           'date' );
-                      
-            $result = $this->Execute( $query );
-            
-            if( !$result )
-                return false;
-            else
-                return $this->_fillCustomFieldInformation( $result->FetchRow());
+        	return( $this->get( "id", $id, CACHE_CUSTOMFIELDVALUES ));
         }
         
         /**
@@ -53,23 +41,13 @@
          */
         function getArticleCustomFieldsValues( $articleId, $blogId, $includeHidden = true )
         {                   
-            //
-            // it's quite a big query and has a 'right outer join', but the whole point is that
-            // we want to obtain as many rows as fields we have available. If there is no value
-            // for this article for one of the fields, we still want to get a row with the name
-            // of the field, its type and so on, with 'null' values where there is no value.
-            //
             $prefix = $this->getPrefix();
             $query = "SELECT v.id AS id, d.id AS field_id, v.field_value AS field_value, 
                              d.field_name AS field_name, d.field_type AS field_type, 
                              d.field_description AS field_description 
                              FROM {$prefix}custom_fields_values v 
                              RIGHT OUTER JOIN {$prefix}custom_fields_definition d 
-                             ON v.article_id = $articleId AND v.field_id = d.id
-                             WHERE d.blog_id = '".Db::qstr($blogId)."'";
-            if( !$includeHidden )
-                $query .= " AND d.hidden = 0 ";
-            $query .= " ORDER BY date ASC";
+                             ON v.article_id = $articleId AND v.field_id = d.id";
                       
             $result = $this->Execute( $query );
             
@@ -80,78 +58,14 @@
                 return $fields;
             
             while( $row = $result->FetchRow()) {
-                $field = $this->_fillCustomFieldValueInformation( $row );
+                $field = $this->mapRow( $row );
                 $fields[$field->getName()] = $field;
             }
         
             return $fields;
         }
-        
+
         /**
-         * @private
-         * @see getArticleCustomFieldsValues
-         */
-        function getArticleCustomFieldsValuesByIds( $articleIds, $blogId, $includeHidden = true )
-        {                   
-            //
-            // it's quite a big query and has a 'right outer join', but the whole point is that
-            // we want to obtain as many rows as fields we have available. If there is no value
-            // for this article for one of the fields, we still want to get a row with the name
-            // of the field, its type and so on, with 'null' values where there is no value.
-            //
-            $prefix = $this->getPrefix();
-            $query = "SELECT v.article_id as article_id, v.id AS id, d.id AS field_id, v.field_value AS field_value, 
-                             d.field_name AS field_name, d.field_type AS field_type, 
-                             d.field_description AS field_description 
-                             FROM {$prefix}custom_fields_values v 
-                             RIGHT OUTER JOIN {$prefix}custom_fields_definition d 
-                             ON v.article_id IN (".$articleIds.") AND v.field_id = d.id
-                             WHERE d.blog_id = '".Db::qstr($blogId)."'";
-            if( !$includeHidden )
-                $query .= " AND d.hidden = 0 ";
-            $query .= " ORDER BY date ASC";
-                      
-            $result = $this->Execute( $query );
-            
-            //$fields = Array();
-                        
-            // return empty array if no fields
-            if( !$result )
-                return $fields;
-            
-            while ($row = $result->FetchRow()) {
-                $lastArticleId=$row["article_id"];
-                $field = $this->_fillCustomFieldValueInformation( $row );
-                $fields[$lastArticleId][$field->getName()] = $field;
-            }
-        
-            return $fields;
-        }
-                
-        
-        /**
-         * @param fieldId
-         * @param articleId
-         * @return A CustomFieldValue object
-         */
-        function getArticleCustomFieldValue( $fieldId, $articleId )
-        {
-            $query = "SELECT * FROM ".$this->getPrefix()."custom_fields_values
-                      WHERE field_id = $fieldId AND article_id = $articleId
-                      ORDER BY date ASC";
-                      
-            $result = $this->Execute( $query );
-                        
-            if( !$result )
-                return false;
-            
-            $row = $result->FetchRow();
-            $fieldValue = $this->_fillCustomFieldValueInformation( $row );
-        
-            return $fieldValue;
-        }
-        
-        /**
          * adds a custom field value to the given article
          *
          * @param fieldId
@@ -162,18 +76,20 @@
          */
         function addCustomFieldValue( $fieldId, $fieldValue, $articleId, $blogId )
         {
-            $filter = new Textfilter();
-            $query = "INSERT INTO ".$this->getPrefix()."custom_fields_values
-                      (field_id, field_value, normalized_value, blog_id, article_id)
-                      VALUES (
-                      $fieldId, '".Db::qstr($fieldValue)."','".
-                      $filter->normalizeText(Db::qstr($fieldValue))."',
-                      $blogId, $articleId
-                      )";
-                      
-            $result = $this->Execute( $query );
-            
-            return $result;
+        	// create a bogus object, we don't really need a full CustomFieldValue object
+        	// but it makes it easier for us if we'd like to use Model::add()
+        	$value = new CustomFieldValue( $fieldId, 
+        	                               $fieldValue,
+        	                               '',  // doesn't matter
+        	                               -1,  // doesn't matter
+        	                               '', // doesn't matter
+        	                               $articleId,
+        	                               $blogId );
+			if( $result = $this->add( $value )) {
+				$this->_cache->removeData( $articleId, CACHE_CUSTOMFIELDVALUES_ARTICLE );
+			}
+			
+			return( $result );
         }
         
         
@@ -185,12 +101,15 @@
          */
         function removeCustomFieldValue( $id )
         {
-            $query = "DELETE FROM ".$this->getPrefix()."custom_fields_values
-                      WHERE id = $id";
-                      
-            $result = $this->Execute( $query );
-            
-            return $result;
+        	$field = $this->getCustomFieldValue( $id );
+        	if( !$field )
+        		return false;
+        		
+        	if( $result = $this->delete( "id", $id )) {
+        		$this->_cache->removeData( $id, CACHE_CUSTOMFIELDVALUES );
+        		$this->_cache->removeData( $field->getArticleId(), CACHE_CUSTOMFIELDVALUES_ARTICLE );
+        	}
+        	return( $result );
         }
         
         /**
@@ -201,14 +120,14 @@
          */
         function removeCustomFieldValues( $fieldId )
         {
-            $query = "DELETE FROM ".$this->getPrefix()."custom_fields_values
-                      WHERE field_id = $fieldId";
-                      
-            $result = $this->Execute( $query );
-            
-            return $result;
-        }
+        	$result = $this->delete( "field_id", $fieldId );
 
+        	/**
+        	 * :TODO:
+        	 * clean the caches!!!!!!!
+        	 */        	
+        	return( $result );
+        }
         
         /**
          * Removes all the values associated to an article
@@ -218,23 +137,19 @@
          */
         function removeArticleCustomFields( $articleId )
         {
-            $query = "DELETE FROM ".$this->getPrefix()."custom_fields_values
-                      WHERE article_id = $articleId"; 
-                      
-            $result = $this->Execute( $query );
-            
-            return $result;
+        	$result = $this->delete( "article_id", $articleId );
+        	
+        	/**
+        	 * :TODO:
+        	 * clean the caches!!!!!!!
+        	 */        	
+        	return( $result );
         }
         
-        function updateCustomFieldValue( $fieldValue )
-        {
-        
-        }
-        
         /**
          * @private
          */
-        function _fillCustomFieldValueInformation( $row )
+        function mapRow( $row )
         {
             return CustomFieldValueFactory::getCustomFieldValueObject( $row );
         }

Modified: plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldvalue.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldvalue.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldvalue.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -1,13 +1,13 @@
 <?php
 
-	include_once( PLOG_CLASS_PATH."class/dao/customfields/customfield.class.php" );
+	include_once( PLOG_CLASS_PATH."class/database/dbobject.class.php" );
 
 	/**
      * Defines a value assigned to a custom field
 	 *
 	 * \ingroup DAO
      */
-	class CustomFieldValue extends CustomField
+	class CustomFieldValue extends DbObject
 	{
 		var $_fieldId;
 		var $_fieldValue;
@@ -16,18 +16,39 @@
 		var $_articleId;
 		var $_field;
 	
-		function CustomFieldValue( $fieldId, $fieldValue, $fieldName, $fieldType, $fieldDescription, $articleId, $blogId, $id = -1 )
+		function CustomFieldValue( $fieldId, $fieldValue, $articleId, $blogId, $id = -1 )
 		{
-			// call the parent constructor
-			$this->CustomField( $fieldName, $fieldDescription, $fieldType, $blogId, false );
+			// constructor
+			$this->DbObject();			
 			// and save some other values
 			$this->_fieldId = $fieldId;
 			if( $fieldValue == null ) $fieldValue = "";
 			$this->_fieldValue = $fieldValue;
 			$this->_articleId = $articleId;
 			$this->_id = $id;
+			$this->_customField = null;
+			
+			$this->_fields = Array(
+			   "field_id" => "getFieldId",
+			   "field_value" => "getValue",
+			   "normalized_value" => "getNormalizedValue",
+			   "blog_id" => "getBlogId",
+			   "article_id" => "getArticleId"
+			);
 		}
 		
+		/**
+		 * @private
+		 */
+		function _loadFieldDefinition()
+		{
+			if( $this->_customField == null ) {
+				include_once( PLOG_CLASS_PATH."class/dao/customfields/customfields.class.php" );
+				$customFields = new CustomFields();
+				$this->_customField = $customFields->getCustomField( $this->_fieldId );
+			}
+		}
+		
 		function getBlogId()
 		{
 			return $this->_blogId;
@@ -38,6 +59,11 @@
 			return $this->_id;
 		}
 		
+		function setId( $id )
+		{
+			$this->_id = $id;
+		}
+		
 		function getFieldId()
 		{
 			return $this->_fieldId;
@@ -57,5 +83,35 @@
 		{
 			$this->_fieldValue = $value;
 		}
+		
+		function getNormalizedValue()
+		{
+			include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+            $filter = new Textfilter();
+            return( $filter->normalizeText($this->getValue()));
+		}
+		
+		function getType()
+		{
+			$this->_loadFieldDefition();
+			return( $this->_customField->getType());
+		}
+		
+		function getDescription()
+		{
+			$this->_loadFieldDefinition();
+			return( $this->_customField->getDescription());
+		}
+		
+		function getName()
+		{
+			$this->_loadFieldDefinition();
+			return( $this->_customField->getName());			
+		}
+		
+		function getFieldDefinition()
+		{
+			return( $this->_customField );
+		}
 	}
 ?>
\ No newline at end of file

Modified: plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldvaluefactory.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldvaluefactory.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/customfields/customfieldvaluefactory.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -55,9 +55,6 @@
 			$constructor = CustomFieldValueFactory::_findConstructorClass( (int)$row["field_type"] );
 			$value = new $constructor( $row["field_id"],
 			                           $row["field_value"],
-									   $row["field_name"],
-									   $row["field_type"],
-									   $row["field_description"],
 									   $row["article_id"],
 					   			       $row["blog_id"],
  									   $row["id"] );

Modified: plog/branches/plog-1.1-daochanges/class/dao/trackbacks.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/dao/trackbacks.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/dao/trackbacks.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -135,28 +135,15 @@
         }
 
 		/**
-		 * gets a single trackback from the db
-         * only used by the admin panel, no caching enabled
-		 *
-		 * @param trackbackId
-		 * @param postId
-		 * @return A Tracback object
-		 */
-		function getArticleTrackback( $trackbackId, $articleId = -1 )
-		{	
-			return( CommentsCommon::getPostComment( $trackbackId, $articleId, COMMENT_TYPE_TRACKBACK ));
-		}
-		
-		/**
 		 * removes a trackback from the database
 		 *
 		 * @param trackbackId
 		 * @param articleId
 		 * @return True if successful or false otherwise
 		 */
-		function deletePostTrackback( $trackbackId, $articleId )
+		function deleteTrackback( $trackbackId )
 		{
-			return( CommentsCommon::deletePostComment( $articleId, $trackbackId, COMMENT_TYPE_TRACKBACK ));
+			return( CommentsCommon::deleteComment( $trackbackId, COMMENT_TYPE_TRACKBACK ));
 
             // clear the cache
             $this->_cache->removeData( $articleId, CACHE_TRACKBACKS );
@@ -180,4 +167,4 @@
 														 COMMENT_TYPE_TRACKBACK ));
         }		
     }
-?>
+?>
\ No newline at end of file

Modified: plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryalbum.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryalbum.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryalbum.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -53,10 +53,12 @@
             $this->_parentId = $parentId;
             $this->_date = $date;
             $this->_id = $id;
-            $this->_numResources = -1;
-            $this->_numChildren  = -1;
+            $this->_numResources = 0;
+            $this->_numChildren  = 0;
             $this->_showAlbum = $showAlbum;
             $this->_properties = $properties;
+            $this->_children = null;
+            $this->_resources = null;
             
             $this->_pk = "id";
             $this->_fields = Array(
@@ -68,7 +70,9 @@
                 "date" => "getDate",
                 "properties" => "getProperties",
                 "show_album" => "getShowAlbum",
-                "mangled_name" => "getMangledName"
+                "mangled_name" => "getMangledName",
+                "num_resources" => "getNumResources",
+                "num_children" => "getNumChildren"
             );
         }
         
@@ -142,6 +146,23 @@
         {
         	return $this->_parentId;
         }
+        
+		/**
+		 * Returns the parent album, or null if there is no parent album
+		 *
+		 * @return A GalleryAlbum object or null if there is no parent
+		 */
+        function getParent()
+        {
+        	if( $this->_parent == null ) {
+        		include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
+        		$albums = new GalleryAlbums();
+        		$this->_parent = $albums->getAlbum( $this->getParentId(), $this->getOwnerId());
+        	}
+        	
+        	return( $this->_parent );
+        }
+        
 
 		/**
 		 * Sets the parent id of the album. It is important that it is a valid 
@@ -201,22 +222,6 @@
         }
 
 		/**
-		 * Returns how many child albums this album has.
-		 *
-		 * @return An integer, or '0' if the album has no children.
-		 */
-        function getNumChildren()
-        {
-			// breaking the rules here again...
-			if( $this->_numChildren == -1 ) {
-				$albums = new GalleryAlbums();
-				$this->_numChildren = $albums->getNumChildren( $this->getId());
-			}
-			
-			return $this->_numChildren;
-        }
-
-		/**
 		 * Returns an array of GalleryAlbum objects representing all the child
 		 * albums that this album has. 
 		 *
@@ -224,6 +229,11 @@
 		 */
         function getChildren()
         {
+        	if( $this->_children == null ) {
+        		$albums = new GalleryAlbums();
+        		$this->_children = $albums->getChildAlbums( $this->getId(), $this->getOwnerId());
+        	}
+        	
 			return $this->_children;
         }
 
@@ -250,6 +260,16 @@
         {
         	return $this->_numResources;
         }
+        
+		/**
+		 * Returns the number of children that this album has.
+		 *
+		 * @return An integer value, or '0' if it has none.
+		 */
+        function getNumChildren()
+        {
+        	return $this->_numChildren;
+        }        
 
 		/**
 		 * Sets number of children of this album.
@@ -284,7 +304,6 @@
 		 */
         function getResources()
         {
-        	//return $this->_resources;
 			if( $this->_resources == null ) {
 				$res = new GalleryResources();
 				$this->_resources = $res->getUserResources( $this->getOwnerId(), $this->getId());
@@ -360,4 +379,4 @@
         	return( Textfilter::urlize( $this->getName()));        	
         }
     }
-?>
+?>
\ No newline at end of file

Modified: plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryalbums.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryalbums.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryalbums.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -3,6 +3,9 @@
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
     include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbum.class.php" );
     include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );    
+    
+    define( "CACHE_USERALBUMS_NESTED", "useralbums_nested" );
+	define( "CACHE_USERALBUMS", "useralbums" );    
 
     /**
 	 * \ingroup Gallery
@@ -69,7 +72,7 @@
 				$result = $albums;
 				
 			return( $result );
-        }
+        }       
 
 		/**
 		 * Returns a specific album from the database.
@@ -152,7 +155,7 @@
         			$result[] = $album;
         	}
         	
-        	return( $album );
+        	return( $result );
         }
 		
         /**
@@ -166,28 +169,21 @@
         {        	
         	if(( $result = $this->add( $album ))) {
     	        $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS );
+    	        $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS_NESTED );    	        
+    	        if( $album->getParentId() > 0 ) {
+	    	        // update the counters of the parent if there's any
+    	        	$parent = $album->getParent();
+    	        	if( $parent ) {
+	    	        	$parent->setNumChildren( $parent->getNumChildren() + 1 );
+    		        	$this->updateAlbum( $parent );
+    		        }
+    	        }
     	    }
             
             return $result;
         }
 
         /**
-         * @private
-         */
-        function getNumChildren( $albumId )
-        {
-        	$query = "SELECT COUNT(*) AS num_children FROM ".$this->getPrefix()."gallery_albums
-                      WHERE parent_id = $albumId";
-            $result = $this->Execute( $query );
-            if( !$result )
-            	return 0;
-
-            $row = $result->FetchRow();
-
-            return $row["num_children"];
-        }
-
-        /**
          * updates an album in the db
          *
          * @param album A GalleryAlbum object that already exists in the db.
@@ -232,27 +228,20 @@
             		
             $this->delete( "id", $albumId );
             $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS );
-            $this->delete( "parent_id", $album->getId());
+            $this->_cache->removeData( $album->getOwnerId(), CACHE_USERALBUMS_NESTED );            
+            //$this->delete( "parent_id", $album->getId());
             
+            // update the counters
+            $parent = $album->getParent();
+            if( $parent ) {
+	            $parent->setNumChildren( $parent->getNumChildren() - 1 );
+	            $this->updateAlbum( $parent );
+	        }
+            
             return( true );
         }
 		
 		/**
-		 * returns how many albums this user has
-		 *
-		 * @param userId The number of albums that this user has
-		 * @return The number of albums, or 0 if none or error
-		 */
-		function getNumUserAlbums( $userId )
-		{
-			$prefix = $this->getPrefix();
-			$table = "{$prefix}gallery_albums";
-			$cond = "owner_id = '".Db::qstr($userId)."'";
-				
-			return( $this->getNumItems( $table, $cond ));
-		}
-		
-		/**
 		 * returns all the albums of the blog in an array. The key of the array is the
 		 * parent id of all the albums in the position, and each position is either an
 		 * array with all the albums that share the same parent id or empty if none
@@ -263,41 +252,18 @@
 		 */
 		function getUserAlbumsGroupedByParentId( $userId, $albumId = 0 )
 		{
-            $albums = $this->_cache->getData( $userId, CACHE_USERALBUMS );
-
-            if ( !$albums ) {
-                $prefix = $this->getPrefix();
-                $query = "SELECT * FROM {$prefix}gallery_albums 
-                          WHERE owner_id = '".Db::qstr($userId)."'
-                          ORDER BY name ASC";
-
-                $result = $this->Execute( $query );
-                
-                if( !$result )
-                    return Array();
-                    
-                $albums = Array();
-                $ids = Array();
-                $ids[] = 0;
-                while( $row = $result->FetchRow()) {
-                    $album = new GalleryAlbum( $row["owner_id"],
-                                            $row["name"],
-                                            $row["description"],
-                                            $row["flags"],
-                                            $row["parent_id"],
-                                            $row["date"],
-                                            unserialize($row["properties"]),
-                                            $row["show_album"],
-                                            $row["id"] );
+            $userAlbums = $this->getUserAlbums( $userId );                        
+            $albums = Array();
+ 
+            if( $userAlbums ) {
+                foreach( $userAlbums as $album ) {
                     $key = $album->getParentId();
                     if( $albums["$key"] == "" )
                         $albums["$key"] = Array();
-                    $albums["$key"][] = $album;
-                    
+                    $albums["$key"][] = $album;                 
                     $ids[] = $album->getId();
                 }
-                $this->_cache->setData( $userId, CACHE_USERALBUMS, $albums );
-            }
+            }           
 			
 			return $albums;
 		}
@@ -310,8 +276,14 @@
 		 */
 		function getNestedAlbumList( $userId )
 		{
-			$albums = $this->getUserAlbumsGroupedByParentId( $userId );
-			$nestedAlbums = $this->_getNestedAlbumList( $albums );
+			$nestedAlbums = $this->_cache->getData( $userId, CACHE_USERALBUMS_NESTED );
+			if( !$nestedAlbums ) {
+				// cache the data for later use... this is quite a costly operation so 
+				// it's probably worth caching it!
+				$albums = $this->getUserAlbumsGroupedByParentId( $userId );
+				$nestedAlbums = $this->_getNestedAlbumList( $albums );
+				$this->_cache->setData( $userId, CACHE_USERALBUMS_NESTED, $nestedAlbums );
+			}
 			
 			return $nestedAlbums;
 		}
@@ -325,7 +297,7 @@
 		{
 			$level++;
 			if( $albums["$start"] == "" )
-				return Array();
+				return Array();				
 				
 			foreach( $albums["$start"] as $album ) {
 				// do the replacing
@@ -352,15 +324,10 @@
                                        unserialize($row["properties"]),
                                        $row["show_album"],
                                        $row["id"] );
-
-			$id = $row["id"];
-			$ownerId = $row["owner_id"];
-			/*if( !isset($this->_childAlbums[$id])) {
-				$this->_childAlbums[$id] = $this->getChildAlbums( $id, $ownerId );
-			}*/
-            $album->setChildren( $this->_childAlbums[$id] );
             $album->setNumResources( $row['num_resources'] );
+            $album->setNumChildren( $row['num_children'] );
+            
             return $album;
 		}
     }
-?>
+?>
\ No newline at end of file

Modified: plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresource.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresource.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresource.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -73,6 +73,7 @@
             $this->_date = $date;
 			$this->_thumbnailFormat = $thumbnailFormat;
             $this->_id = $id;
+            $this->_album = null;
             
             $this->_fields = Array(
                 "owner_id" => "getOwnerId",
@@ -83,6 +84,7 @@
                 "resource_type" => "getResourceType",
                 "file_path" => "getFilePath",
                 "file_name" => "getFileName",
+                "file_size" => "getFileSize", 
                 "thumbnail_format" => "getThumbnailFormat",
                 "normalized_description" => "getNormalizedDescription",
                 "properties" => "getProperties",
@@ -251,6 +253,12 @@
 		 */		
 		function getAlbum()
 		{
+			if( $this->_album == null ) {
+				include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
+				$albums = new GalleryAlbums();
+				$this->_album = $albums->getAlbum( $this->getAlbumId());
+			}
+			
 			return $this->_album;
 		}
 

Modified: plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresourcequotas.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresourcequotas.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresourcequotas.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -1,9 +1,6 @@
 <?php
 
 	include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
-	include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
-	include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );	
 	
 	define( "GLOBAL_QUOTA_DEFAULT", 5000000 );
 
@@ -23,6 +20,7 @@
 		 */
 		function getGlobalResourceQuota()
 		{
+			include_once( PLOG_CLASS_PATH."class/config/config.class.php" );		
 			$config =& Config::getConfig();
 			$quota = $config->getValue( "resources_quota", GLOBAL_QUOTA_DEFAULT );
 			
@@ -33,26 +31,33 @@
 		 * Returns the quota usage of a user
 		 *
 		 * @param userId The user whose quota usage we would like to know
-		 * @param albumId The album identifier, optional
 		 * @return The number of bytes used
 		 * @static
 		 */
-		function getBlogResourceQuotaUsage( $userId, $albumId = -1 )
+		function getBlogResourceQuotaUsage( $userId )
 		{
-			// get the user resources
-			$resources = new GalleryResources();
-			$blogResources = $resources->getUserResources( $userId, $albumId );
+			//
+			// :HACK:
+			// this is done so that we can keep this method static while still easily
+			// executing an sql query!
+			//
+			$model = new Model();
+			$prefix = $model->getPrefix();
+		
+			// we can use one query to calculate this...
+			$query = "SELECT SUM(file_size) AS total_size FROM {$prefix}gallery_resources
+			          WHERE owner_id = '".Db::qstr( $userId )."'";
+			$result = $model->Execute( $query );
 			
-			if( !$blogResources )
+			if( !$result ) 
 				return 0;
-			
-			// and now go one by one calculating the sizes
-			$total = 0;
-			foreach( $blogResources as $resource ) {
-				$total += $resource->getFileSize();
-			}
-			
-			return $total;
+			$row = $result->FetchRow();
+			if( isset( $row["total_size"] ))
+				$quota = $row["total_size"];
+			else
+				$quota = 0;
+				
+			return( $quota );
 		}
 		
 		/**
@@ -67,7 +72,13 @@
 		function isBlogOverResourceQuota( $blogId, $fileSize )
 		{
 			// current allocated quota
-			$blogQuota = GalleryResourceQuotas::getBlogResourceQuota( $blogId );
+			include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+			$blogs = new Blogs();
+			$blog = $blogs->getBlogInfo( $blogId );
+			if( !$blog )
+				return false;
+				
+			$blogQuota = $blog->getResourcesQuota();
 			
 			// but if the quota is 0, then for sure we won't be over the quota :)
 			if( $blogQuota == 0 )
@@ -80,26 +91,6 @@
 				return true;
 			else
 				return false;
-		}
-	
-		/**
-		 * returns the current quota allocated for a blog
-		 *
-		 * @param blogId
-		 * @return
-		 * @static
-		 */
-		function getBlogResourceQuota( $blogId )
-		{
-			$blogs = new Blogs();
-			$blogInfo = $blogs->getBlogInfo( $blogId );
-			$blogSettings = $blogInfo->getSettings();
-			
-			$blogQuota = $blogSettings->getValue( "resources_quota" );
-			if( $blogQuota == "" )
-				$blogQuota = GalleryResourceQuotas::getGlobalResourceQuota();
-				
-			return $blogQuota;
-		}
+		}	
 	}
 ?>
\ No newline at end of file

Modified: plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresources.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresources.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/gallery/dao/galleryresources.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -15,9 +15,10 @@
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
     include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresource.class.php" );
     include_once( PLOG_CLASS_PATH."class/gallery/galleryconstants.php" );
-    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
-	include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
-	include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+	
+	define( "CACHE_RESOURCES", "galleryresources" );
+	define( "CACHE_RESOURCES_BY_NAME", "galleryresources_name" );	
+	define( "CACHE_RESOURCES_USER", "galleryresources_user" );	
 
     /**
 	 * \ingroup Gallery
@@ -68,10 +69,7 @@
 
     	function GalleryResources()
         {
-        	$this->Model();
-
-            $this->albums = new GalleryAlbums();			
-            
+        	$this->Model();            
             $this->table = $this->getPrefix()."gallery_resources";
         }
 
@@ -89,11 +87,9 @@
 
             if( !$resource )            
             	return false;
-            if( $ownerId > -1 && $resource->getOwnerId() != $ownerId )
+            if( !$this->check( $resource, $ownerId, $albumId ))
             	return false;
-            if( $albumId > -1 && $resource->getAlbumId() != $albumId )
-            	return false;
-			
+
 			return $resource;
         }
 		
@@ -106,7 +102,7 @@
 		 * if there was no next resource
          */		 
 		function getNextResource( $resource )
-		{
+		{		
 			$prefix = $this->getPrefix();
 			$albumId = $resource->getAlbumId();
 			$date = $resource->getDate();
@@ -128,7 +124,8 @@
 			$row = $result->FetchRow();
 			$resource = $this->mapRow( $row );
 			
-			$this->_cache->setData( $resource->getId(), CACHE_RESOURCES, $resource );			
+			$this->_cache->setData( $resource->getId(), CACHE_RESOURCES, $resource );
+			$this->_cache->setData( $resource->getFileName(), CACHE_RESOURCES_BY_NAME, $resource );			
 			
 			return $resource;
 		}
@@ -165,6 +162,7 @@
 			$resource = $this->mapRow( $row );
 			
 			$this->_cache->setData( $resource->getId(), CACHE_RESOURCES, $resource );
+			$this->_cache->setData( $resource->getFileName(), CACHE_RESOURCES_BY_NAME, $resource );			
 			
 			return $resource;		
 		}
@@ -180,62 +178,52 @@
          * the resources that match the given conditions, or empty
          * if none could be found.
          */
-        function getUserResources( $ownerId, $albumId = GALLERY_NO_ALBUM, $resourceType = GALLEY_RESOURCE_ANY, $page = DEFAULT_PAGING_ENABLED, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+        function getUserResources( $ownerId, 
+                                   $albumId = GALLERY_NO_ALBUM, 
+                                   $resourceType = GALLERY_RESOURCE_ANY, 
+                                   $page = DEFAULT_PAGING_ENABLED, 
+                                   $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
         {
-        	$query = "SELECT id, owner_id, album_id, description,
-        	                 date, flags, resource_type, file_path, file_name,
-        	                 metadata, thumbnail_format 
-        	          FROM ".$this->getPrefix()."gallery_resources
-                      WHERE owner_id = '".Db::qstr($ownerId)."'";
-            if( $albumId > GALLERY_NO_ALBUM )
-            	$query .= " AND album_id = '".Db::qstr($albumId)."'";
-			if( $resourceType > GALLEY_RESOURCE_ANY )
-				$query .= " AND resource_type = '".Db::qstr($resourceType)."'";
+        	$resources = $this->getMany( "owner_id", 
+        								 $ownerId, 
+        	                             CACHE_RESOURCES_USER,
+        	                             null,
+        	                             $page,
+        	                             $itemsPerPage );
+            if( !$resources )
+            	return Array();            	
+            	
+           	$result = Array();
+           	foreach( $resources as $resource ) {
+				if( $this->check( $resource, $ownerId, $albumId, $resourceType ))
+					$result[] = $resource;
+           	}
 
-
-			$query .= " ORDER BY album_id, date ASC";
-
-            $result = $this->Execute( $query, $page, $itemsPerPage );
-
-            if( !$result )
-            	return Array();
-
-            $resources = Array();
-            while( $row = $result->FetchRow()) {
-				$res = new GalleryResource( $row["owner_id"],
-											$row["album_id"],
-											$row["description"],
-											$row["flags"],
-											$row["resource_type"],
-											$row["file_path"],
-											$row["file_name"],
-											unserialize($row["metadata"]),
-											$row["date"],
-											$row["thumbnail_format"],
-											$row["id"] );
-
-				// we should also try to get some information about
-				// to which album this resource belongs
-				if( $albumId != GALLERY_NO_ALBUM ) {
-					// since we're loading all the resources of the same album, it makes no sense
-					// to load the same album every time... so let's load the album only on the first
-					// try and then use the "cached" version
-					if( $album == null ) {
-						$album = $this->albums->getAlbum( $row["album_id"], $row["owner_id"], false );
-					}
-					$res->setAlbum( $album );
-				}
-				else {
-					$resAlbum = $this->albums->getAlbum( $row["album_id"], $row["owner_id"], false );
-					$res->setAlbum( $resAlbum );
-				}
-				
-				array_push( $resources, $res );
-				$this->_cache->setData( $res->getId(), CACHE_RESOURCES, $res );
-            }
-
-            return $resources;
+            return $result;
         }
+        
+        /**
+         * @private
+         */
+        function check( $resource, 
+                        $ownerId = -1, 
+                        $albumId = GALLERY_NO_ALBUM, 
+                        $resourceType = GALLERY_RESOURCE_ANY )
+        {
+        	if( $ownerId != -1 ) {
+        		if( $resource->getOwnerId() != $ownerId )
+        			return false;
+        	}
+        	if( $albumId != GALLERY_NO_ALBUM ) {
+           		if( $resource->getAlbumId() != $albumId )
+           			return false;
+           	}
+           	if( $resourceType != GALLERY_RESOURCE_ANY ) {
+           		if( $resource->getResourceType() != $resourceType )
+           			return false;
+           	}
+           	return( true );
+        }
 		
 		/**
 		 * returns the number of items given certain conditions
@@ -250,15 +238,7 @@
 		 */
 		function getNumUserResources( $ownerId, $albumId = GALLERY_NO_ALBUM, $resourceType = GALLEY_RESOURCE_ANY )
 		{
-			$prefix = $this->getPrefix();
-			$table  = "{$prefix}gallery_resources";
-            if( $albumId > GALLERY_NO_ALBUM )
-            	$cond .= "album_id = '".Db::qstr($albumId)."'";
-			if( $resourceType > GALLEY_RESOURCE_ANY )
-				$cond .= " AND resource_type = '".Db::qstr($resourceType)."'";
-				
-			// return the number of items
-			return( $this->getNumItems( $table, $cond ));
+			return( count( $this->getUserResources( $ownerId, $albumId, $resourceType )));
 		}
 
 		/**
@@ -298,8 +278,10 @@
 											$filePath, $fileName, $metadata )
 		{
 			// prepare the metadata to be stored in the db
+			$fileSize = $metadata["filesize"];
 			$serMetadata = Db::qstr( serialize($metadata));
 			// get the correct thumbnail format
+			include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
 			$config =& Config::getConfig();
 			$thumbnailFormat = $config->getValue( "thumbnail_format" );
 			// prepare some other stuff
@@ -310,10 +292,11 @@
 			// finally put the query together and execute it
 			$query = "INSERT INTO ".$this->getPrefix()."gallery_resources(
 						  owner_id, album_id, description, flags, resource_type,
-						  file_path, file_name, metadata, thumbnail_format, normalized_description) VALUES (
+						  file_path, file_name, file_size, metadata, thumbnail_format, normalized_description) 
+						  VALUES (
 						  $ownerId, $albumId, '".Db::qstr($description)."', $flags, $resourceType,
-						  '$filePath', '$fileName', '$serMetadata', '$thumbnailFormat',
-				  '".Db::qstr($normalizedDescription)."');";	
+						  '$filePath', '$fileName', '$fileSize', '$serMetadata', '$thumbnailFormat',
+				  '".Db::qstr($normalizedDescription)."');";
 						  
 			$result = $this->Execute( $query );
 
@@ -338,78 +321,21 @@
 				$this->Execute( $query );
 
 			}
+			
+			include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );			
+			$albums = new GalleryAlbums();
+			$album = $albums->getAlbum( $albumId );
+			$album->setNumResources( $album->getNumResources() + 1 );
+			$albums->updateAlbum( $album );			
+			
+			// clear our own caches
+            $this->_cache->removeData( $resourceId, CACHE_RESOURCES );
+			$this->_cache->removeData( $ownerId, CACHE_RESOURCES_USER );
+			$this->_cache->removeData( $fileName, CACHE_RESOURCES_BY_NAME );			
 		
 			return $resourceId;	
 		}
 
-		/**
-		 * generates the thumbnail of a file that we have just added.
-		 *
-		 * @param resFile the resource file from which we're trying to generate the
-		 * thubmail.
-		 * @param fileName The name and path of the new thumbnail we're going to create
-		 */
-		function generateResourceThumbnail( $resFile, $resourceId, $ownerId )
-		{
-			// get some configuration settings regarding the size of the
-			// thumbnails, and also the default format for thumbnails
-			$config =& Config::getConfig();
-			$previewHeight = $config->getValue( "thumbnail_height", GALLERY_DEFAULT_THUMBNAIL_HEIGHT );
-			$previewWidth  = $config->getValue( "thumbnail_width", GALLERY_DEFAULT_THUMBNAIL_WIDTH );
-			$previewKeepAspectRatio = $config->getValue( "thumbnails_keep_aspect_ratio" );
-			
-			// get the file extension
-			$fileParts = explode( ".", $resFile );
-			$fileExt = strtolower($fileParts[count($fileParts)-1]);
-			$fileName = $ownerId."-".$resourceId.".".$fileExt;
-			
-			// and start the resizing process
-			include_once( PLOG_CLASS_PATH."class/gallery/resizers/galleryresizer.class.php" );			
-			$resizer = new GalleryResizer( $resFile );
-			include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );			
-			GalleryResourceStorage::checkPreviewsStorageFolder( $ownerId );
-			$outFile = GalleryResourceStorage::getPreviewsFolder( $ownerId ).$fileName;
-			
-			// and finally, we can generate the preview!
-			$result = $resizer->generate( $outFile, $previewHeight, $previewWidth, $previewKeepAspectRatio );
-			
-			return $result;
-		}
-		
-		/**
-		 * generates the medium-sized thumbnail of a file that we have just added
-		 *
-		 * @param resFile the resource file from which we're trying to generate the
-		 * thubmail.
-		 * @param fileName The name and path of the new thumbnail we're going to create
-		 */
-		function generateResourceMediumSizeThumbnail( $resFile, $resourceId, $ownerId )
-		{
-			// get some configuration settings regarding the size of the
-			// thumbnails, and also the default format for thumbnails
-			$config =& Config::getConfig();
-			$previewHeight = $config->getValue( "medium_size_thumbnail_height", GALLERY_DEFAULT_MEDIUM_SIZE_THUMBNAIL_HEIGHT );
-			$previewWidth  = $config->getValue( "medium_size_thumbnail_width", GALLERY_DEFAULT_MEDIUM_SIZE_THUMBNAIL_WIDTH );
-			$previewKeepAspectRatio = $config->getValue( "thumbnails_keep_aspect_ratio" );
-			
-			// get the file extension
-			$fileParts = explode( ".", $resFile );
-			$fileExt = strtolower($fileParts[count($fileParts)-1]);
-			$fileName = $ownerId."-".$resourceId.".".$fileExt;
-			
-			// and start the resizing process
-		    include_once( PLOG_CLASS_PATH."class/gallery/resizers/galleryresizer.class.php" );			
-			$resizer = new GalleryResizer( $resFile );
-		    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );			
-			GalleryResourceStorage::checkMediumSizePreviewsStorageFolder( $ownerId );
-			$outFile = GalleryResourceStorage::getMediumSizePreviewsFolder( $ownerId ).$fileName;
-			
-			// and finally, we can generate the preview!
-			$result = $resizer->generate( $outFile, $previewWidth, $previewHeight, $previewKeepAspectRatio );
-			
-			return $result;
-		}		
-
         /**
          * adds a resource to the database. This method requires a FileUpload parameter and it
 		 * will take care of processing the upload file and so on. If the file is already in disk and we'd
@@ -490,8 +416,9 @@
 			
             // and finally, we can generate the thumbnail only if the file is an image, of course :)
             if( $resourceType == GALLERY_RESOURCE_IMAGE ) {
-                $this->generateResourceThumbnail( $resFile, $resourceId, $ownerId );
-				$this->generateResourceMediumSizeThumbnail( $resFile, $resourceId, $ownerId );
+            	include_once( PLOG_CLASS_PATH."class/gallery/resizers/gallerythumbnailgenerator.class.php" );            
+                GalleryThumbnailGenerator::generateResourceThumbnail( $resFile, $resourceId, $ownerId );
+				GalleryThumbnailGenerator::generateResourceMediumSizeThumbnail( $resFile, $resourceId, $ownerId );
             }
 			
             // return the id of the resource we just added
@@ -570,7 +497,8 @@
     
             // and finally, we can generate the thumbnail only if the file is an image, of course :)
             if( $resourceType == GALLERY_RESOURCE_IMAGE ) {
-                $this->generateResourceThumbnail( $resFile, $resourceId, $ownerId );
+            	include_once( PLOG_CLASS_PATH."class/gallery/resizers/gallerythumbnailgenerator.class.php" );
+                GalleryThumbnailGenerator::generateResourceThumbnail( $resFile, $resourceId, $ownerId );
             }
             
             // return the id of the resource we just added
@@ -587,26 +515,14 @@
          */
         function getResourceFile( $ownerId, $fileName, $albumId = -1 )
         {
-        	$query = "SELECT id, owner_id, album_id, description,
-        	          date, flags, resource_type, file_path, file_name,
-        	          metadata, thumbnail_format 
-        	          FROM ".$this->getPrefix()."gallery_resources
-                      WHERE owner_id = $ownerId AND
-                      file_name = '$fileName'";
-					  
-			if( $albumId > 0 )
-				$query .= " AND album_id = $albumId";
-
-            $result = $this->Execute( $query );
-            if( !$result )
-            	return false;
-
-            if( $result->RecordCount() == 0 )
-            	return false;
-
-            $row = $result->FetchRow();
-
-            return $this->mapRow( $row );
+        	$resource = $this->get( "file_name", $fileName, CACHE_RESOURCES_BY_NAME );
+        	if( $resource->getOwnerId() != $ownerId )
+        		return false;
+        	if( $albumId != -1 )
+        		if( $resource->getAlbumId() != $albumId )
+        			return false;
+        			
+            return( $resource );
         }
 
         /**
@@ -618,7 +534,14 @@
          */
         function updateResource( $resource ) 
         {
-        	return( $this->update( $resource ));
+        	if( $result = $this->update( $resource )) {
+        		// if update ok, reset the caches
+				$this->_cache->removeData( $resource->getId(), CACHE_RESOURCES );
+				$this->_cache->removeData( $resource->getOwnerId(), CACHE_RESOURCES_USER );
+				$this->_cache->removeData( $resource->getOwnerId()."_".$resource->getFileName(), CACHE_RESOURCES_BY_NAME );
+        	}
+        	
+        	return( $result );
         }
 
         /**
@@ -634,11 +557,19 @@
             $resource = $this->getResource( $resourceId, $ownerId );
             if( $resource ) {
             	$this->delete( "id", $resourceId );
-	            $this->_cache->removeData( $resourceId, CACHE_RESOURCES );            	
-	            // otherwise, proceed and remove the file from disk
-			    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );            
+	            $this->_cache->removeData( $resource->getId(), CACHE_RESOURCES );
+				$this->_cache->removeData( $resource->getOwnerId(), CACHE_RESOURCES_USER );
+				$this->_cache->removeData( $resource->getFileName(), CACHE_RESOURCES_BY_NAME );
+				// update the counters
+				include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
+				$albums = new GalleryAlbums();
+				$album = $resource->getAlbum();
+				$album->setNumResources( $album->getNumResources() - 1 );
+				$albums->updateAlbum( $album );		
+	            // proceed and remove the file from disk
+			    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );
         	    $storage = new GalleryResourceStorage();
-            	return $storage->remove( $resource );	            
+            	return $storage->remove( $resource );            	
             }
             else {
             	return false;
@@ -665,29 +596,6 @@
             	return true;
         }
 		
-		/**
-		 * Returns the total number of resources of the given blog
-		 *
-		 * @param userId
-		 * @param albumId
-		 * @return The number of total resources
-		 */
-		function getNumResources( $userId, $albumId = -1 )
-		{
-			$query = "SELECT COUNT(*) AS total FROM ".$this->getPrefix()."gallery_resources
-			          WHERE owner_id = $userId";
-			if( $albumId > 0 )
-				$query .= " AND album_id = $albumId";
-				
-			$result = $this->Execute( $query );
-			
-			if( !$result )
-				return 0;
-				
-			$row = $result->FetchRow();
-			return $row["total"];
-		}
-		
         /**
          * @private
          */
@@ -704,12 +612,6 @@
                                         $row["date"],
 										$row["thumbnail_format"],
                                         $row["id"] );
-
-             // we should also try to get some information about
-             // to which album this resource belongs             
-             $album = $this->albums->getAlbum( $row["album_id"], $row["owner_id"], false );
-             $res->setAlbum( $album );
-
              return $res;
         }
     }

Added: plog/branches/plog-1.1-daochanges/class/gallery/resizers/gallerythumbnailgenerator.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/gallery/resizers/gallerythumbnailgenerator.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/gallery/resizers/gallerythumbnailgenerator.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -0,0 +1,80 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+	
+	class GalleryThumbnailGenerator extends Object
+	{
+	
+		/**
+		 * generates the thumbnail of a file that we have just added.
+		 *
+		 * @param resFile the resource file from which we're trying to generate the
+		 * thubmail.
+		 * @param fileName The name and path of the new thumbnail we're going to create
+		 * @static
+		 */
+		function generateResourceThumbnail( $resFile, $resourceId, $ownerId )
+		{
+			// get some configuration settings regarding the size of the
+			// thumbnails, and also the default format for thumbnails
+			include_once( PLOG_CLASS_PATH."class/config/config.class.php" );			
+			$config =& Config::getConfig();
+			$previewHeight = $config->getValue( "thumbnail_height", GALLERY_DEFAULT_THUMBNAIL_HEIGHT );
+			$previewWidth  = $config->getValue( "thumbnail_width", GALLERY_DEFAULT_THUMBNAIL_WIDTH );
+			$previewKeepAspectRatio = $config->getValue( "thumbnails_keep_aspect_ratio" );
+			
+			// get the file extension
+			$fileParts = explode( ".", $resFile );
+			$fileExt = strtolower($fileParts[count($fileParts)-1]);
+			$fileName = $ownerId."-".$resourceId.".".$fileExt;
+			
+			// and start the resizing process
+			include_once( PLOG_CLASS_PATH."class/gallery/resizers/galleryresizer.class.php" );			
+			$resizer = new GalleryResizer( $resFile );
+			include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );			
+			GalleryResourceStorage::checkPreviewsStorageFolder( $ownerId );
+			$outFile = GalleryResourceStorage::getPreviewsFolder( $ownerId ).$fileName;
+			
+			// and finally, we can generate the preview!
+			$result = $resizer->generate( $outFile, $previewHeight, $previewWidth, $previewKeepAspectRatio );
+			
+			return $result;
+		}
+		
+		/**
+		 * generates the medium-sized thumbnail of a file that we have just added
+		 *
+		 * @param resFile the resource file from which we're trying to generate the
+		 * thubmail.
+		 * @param fileName The name and path of the new thumbnail we're going to create
+		 * @static
+		 */
+		function generateResourceMediumSizeThumbnail( $resFile, $resourceId, $ownerId )
+		{
+			// get some configuration settings regarding the size of the
+			// thumbnails, and also the default format for thumbnails
+			include_once( PLOG_CLASS_PATH."class/config/config.class.php" );			
+			$config =& Config::getConfig();
+			$previewHeight = $config->getValue( "medium_size_thumbnail_height", GALLERY_DEFAULT_MEDIUM_SIZE_THUMBNAIL_HEIGHT );
+			$previewWidth  = $config->getValue( "medium_size_thumbnail_width", GALLERY_DEFAULT_MEDIUM_SIZE_THUMBNAIL_WIDTH );
+			$previewKeepAspectRatio = $config->getValue( "thumbnails_keep_aspect_ratio" );
+			
+			// get the file extension
+			$fileParts = explode( ".", $resFile );
+			$fileExt = strtolower($fileParts[count($fileParts)-1]);
+			$fileName = $ownerId."-".$resourceId.".".$fileExt;
+			
+			// and start the resizing process
+		    include_once( PLOG_CLASS_PATH."class/gallery/resizers/galleryresizer.class.php" );			
+			$resizer = new GalleryResizer( $resFile );
+		    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );			
+			GalleryResourceStorage::checkMediumSizePreviewsStorageFolder( $ownerId );
+			$outFile = GalleryResourceStorage::getMediumSizePreviewsFolder( $ownerId ).$fileName;
+			
+			// and finally, we can generate the preview!
+			$result = $resizer->generate( $outFile, $previewWidth, $previewHeight, $previewKeepAspectRatio );
+			
+			return $result;
+		}		
+	}
+?>
\ No newline at end of file

Modified: plog/branches/plog-1.1-daochanges/class/net/http/httpvars.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/net/http/httpvars.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/net/http/httpvars.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -272,10 +272,16 @@
             } else {
                 $protocol = 'https://';
             }
-            $host      = $serverVars["HTTP_HOST"];
+            //$host      = $serverVars["HTTP_HOST"];
+            $host = $serverVars["SERVER_NAME"];
             $scriptUrl = $serverVars["PHP_SELF"];
-
-            return $protocol . $host . $scriptUrl;
+            $port = $serverVars["SERVER_PORT"];
+            if( $port == 80 || $post == 443 )
+				$baseUrl = $protocol . $host . $scriptUrl;
+			else
+				$baseUrl = $protocol . $host . ":" . $port . $scriptUrl;
+				
+            return( $baseUrl );
         }
     }
 ?>

Modified: plog/branches/plog-1.1-daochanges/class/net/http/session/sessionmanager.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/net/http/session/sessionmanager.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/net/http/session/sessionmanager.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -195,4 +195,4 @@
 		    return true;
 		}
 	}
-?>
+?>
\ No newline at end of file

Modified: plog/branches/plog-1.1-daochanges/class/view/admin/admineditpostview.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/view/admin/admineditpostview.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/view/admin/admineditpostview.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -64,7 +64,8 @@
 	            
 	            // we need to play a bit with the values of the fields, as the editpost.template page is
 	            // expecting them in a bit different way than if we just do an $article->getFields()
-	            $customFieldValues = $this->_article->getFields();
+	            $customFieldValues = $this->_article->getCustomFields();
+	            print_r($customFieldValues);
 	            $customField = Array();
 	            foreach( $customFieldValues as $fieldValue )
 	            	$customField[$fieldValue->getFieldId()] = $fieldValue->getValue();

Modified: plog/branches/plog-1.1-daochanges/class/view/admin/adminresourceslistview.class.php
===================================================================
--- plog/branches/plog-1.1-daochanges/class/view/admin/adminresourceslistview.class.php	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/class/view/admin/adminresourceslistview.class.php	2005-08-24 21:19:08 UTC (rev 2419)
@@ -49,23 +49,30 @@
 			// get the page from the request
 			$this->_page = $this->getCurrentPageFromRequest();
 
-	        	// and the current album
-        		$galleryAlbums = new GalleryAlbums();
+	        // and the current album
+        	$galleryAlbums = new GalleryAlbums();
 			$galleryResources = new GalleryResources();
 
 			if( $this->_albumId > ROOT_ALBUM_ID && $this->_page > 0 ) {
-        	    		$album = $galleryAlbums->getAlbum( $this->_albumId, $this->_blogInfo->getId());
+        	    $album = $galleryAlbums->getAlbum( $this->_albumId, $this->_blogInfo->getId());
 				if( !$album || $album == "") {
 					$this->_albumId = ROOT_ALBUM_ID;
 				}
 				else {
-					//$resources = $album->getResources();
-					$resources = $galleryResources->getUserResources( $this->_blogInfo->getId(), $this->_albumId, $this->_resourceType, $this->_page, DEFAULT_ITEMS_PER_PAGE );
-					$numResources = $galleryResources->getNumUserResources( $this->_blogInfo->getId(), $this->_albumId, $this->_resourceType );
+					// resources for this page
+					$resources = $galleryResources->getUserResources( $this->_blogInfo->getId(),
+					                                                  $this->_albumId,
+					                                                  $this->_resourceType,
+					                                                  $this->_page,
+					                                                  DEFAULT_ITEMS_PER_PAGE );
+					// total number of resources, used by the pager
+					$numResources = $galleryResources->getNumUserResources( $this->_blogInfo->getId(),
+					                                                        $this->_albumId,
+					                                                        $this->_resourceType );
 				}
 			}
 			else {
-				$albums = $galleryAlbums->getChildAlbums( $this->_albumId, $this->_blogInfo->getId());
+				$albums = $galleryAlbums->getChildAlbums( $this->_albumId, $this->_blogInfo->getId());			
 				$resources = Array();
 			}
 			
@@ -79,19 +86,19 @@
 
 			// fetch some statistics and continue
 			$quotaUsage = GalleryResourceQuotas::getBlogResourceQuotaUsage( $this->_blogInfo->getId());
-			$totalResources = $galleryResources->getNumResources( $this->_blogInfo->getId());
-			$currentQuota = GalleryResourceQuotas::getBlogResourceQuota( $this->_blogInfo->getId());
+			$totalResources = $galleryResources->getNumUserResources( $this->_blogInfo->getId());
 			$this->setValue( "quotausage", $quotaUsage );
 			$this->setValue( "totalresources", $totalResources );
-			$this->setValue( "quota", $currentQuota );
 
 			// and now export info about the albums and so on but only 
 			// if we're browsing the first page only (albums do not appear anymore after the first page)
             $this->setValue( "album", $album );
-			if( $this->_albumId > ROOT_ALBUM_ID && $this->_page < 2 )
+			if( $this->_albumId > ROOT_ALBUM_ID && $this->_page < 2 ) {
 				$this->setValue( "albums", $album->getChildren());
-			else
+			}
+			else {
 				$this->setValue( "albums", $albums );
+			}
 	        
 			// event about the resources
 			$this->notifyEvent( EVENT_RESOURCES_LOADED, Array ( "resources" => &$resources ));

Modified: plog/branches/plog-1.1-daochanges/templates/admin/resources.template
===================================================================
--- plog/branches/plog-1.1-daochanges/templates/admin/resources.template	2005-08-24 21:15:19 UTC (rev 2418)
+++ plog/branches/plog-1.1-daochanges/templates/admin/resources.template	2005-08-24 21:19:08 UTC (rev 2419)
@@ -104,6 +104,7 @@
 </table>
 </div>
 <div id="list_action_bar">
+  {assign var=quota value=$blog->getResourcesQuota()}
   {include file="$admintemplatepath/adminpager.template" style=list}
   {$locale->tr("num_resources")}: <strong>{$totalresources}</strong>, {$locale->tr("total_size")}: <strong>{$quotausage|round}</strong>
   {if $quota > 0 }, {$locale->tr("quota")}: <strong>{$quota|round}</strong>{/if}




More information about the pLog-svn mailing list