[pLog-svn] r6794 - in plugins/branches/lifetype-1.2/clean/class: dao view

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Fri Feb 13 14:19:47 EST 2009


Author: jondaley
Date: 2009-02-13 14:19:47 -0500 (Fri, 13 Feb 2009)
New Revision: 6794

Modified:
   plugins/branches/lifetype-1.2/clean/class/dao/unusedblogs.class.php
   plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php
Log:
more simplification.  unusedblogs was copied from blogs.class rather than inherited, and it wasn't cleaned out of function it didn't need, so it looked confusing, and pretty hard to keep up-to-date

Modified: plugins/branches/lifetype-1.2/clean/class/dao/unusedblogs.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/dao/unusedblogs.class.php	2009-02-13 18:59:30 UTC (rev 6793)
+++ plugins/branches/lifetype-1.2/clean/class/dao/unusedblogs.class.php	2009-02-13 19:19:47 UTC (rev 6794)
@@ -1,200 +1,21 @@
 <?php
-    lt_include( PLOG_CLASS_PATH."class/dao/model.class.php" );    
-    lt_include( PLOG_CLASS_PATH."class/dao/blogstatus.class.php" );
-	lt_include( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );
-    
-#    define( "ALL_BLOG_CATEGORIES", 0 );   
-    
-    /**
-     * \ingroup DAO
-     * DAO class for BlogInfo objects, which represent a blog.
-     */
-    class UnusedBlogs extends Model
+    lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );    
+
+    class UnusedBlogs extends Blogs
     {
-		var $_startTime;			
     	function UnusedBlogs()
     	{
-    		$this->Model();    	
-    		$this->table = $this->getPrefix()."blogs";
+    		$this->Blogs();
     	}
 
-        /**
-         * Returns information about a blog.
-         *
-         * @param blogId Identifier of the blog we want to get information
-         * @param extendedInfo
-         * @return Returns a BlogInfo object containing information about the blog
-         */
-        function getBlogInfo( $blogId )
-        {
-            lt_include( PLOG_CLASS_PATH . 'class/dao/bloginfo.class.php' );
-            return( $this->get( "id", $blogId,
-                                CACHE_BLOGINFOS,
-                                Array( CACHE_BLOGIDBYNAME => "getMangledBlogName",
-                                       CACHE_BLOGIDBYDOMAIN => "getCustomDomain")));
-        }
-
-        /**
-         * Returns information about a blog.
-         *
-         * @param blogName Identifier of the blog we want to get information
-         * @return Returns a BlogInfo object containing information about the blog
-         */
-        function getBlogInfoByName( $blogName, $extendedInfo = false )
-        {
-            lt_include( PLOG_CLASS_PATH . 'class/dao/bloginfo.class.php' );        
-        	return( $this->get( "mangled_blog", $blogName,
-                                CACHE_BLOGIDBYNAME,
-                                Array( CACHE_BLOGINFOS => "getId" )));
-        }
-
-        function getBlogInfoByDomain($blogDomain, $extendedInfo = false){
-            lt_include(PLOG_CLASS_PATH . 'class/dao/bloginfo.class.php');
-        	return( $this->get( "custom_domain", $blogDomain,
-                                CACHE_BLOGIDBYDOMAIN,
-                                Array( CACHE_BLOGINFOS => "getId" )));
-        }
-		
-		/**
-		 * @see Model::getSearchConditions
-		 */
-		function getSearchConditions( $searchTerms )
-		{
-			return( "blog LIKE '%".Db::qstr( $searchTerms )."%'" );
-		}
-
-		/**
-		 * Updates blog category counters
-		 *
-		 * @private
-		 */
-		function updateBlogCategoriesLink( $blogInfo, $oldBlogInfo = null )
-		{
-			lt_include( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
-			$blogCategories = new BlogCategories();
-			$blogCategory = $blogInfo->getBlogCategory();
-			
-			if( $blogCategory ) {
-				$blogCategory->setNumActiveBlogs($this->getNumItems( $this->getPrefix().'blogs', 'blog_category_id = '.$blogCategory->getId().' AND status = '.BLOG_STATUS_ACTIVE ));
-				$blogCategory->setNumBlogs($this->getNumItems( $this->getPrefix().'blogs', 'blog_category_id = '.$blogCategory->getId()));
-				$blogCategories->updateBlogCategory( $blogCategory );
-			}
-			
-			if( $oldBlogInfo ) {
-				$oldBlogCategory = $oldBlogInfo->getBlogCategory();
-				if ($oldBlogCategory)
-				{
-					$oldBlogCategory->setNumActiveBlogs($this->getNumItems( $this->getPrefix().'blogs', 'blog_category_id = '.$oldBlogCategory->getId().' AND status = '.BLOG_STATUS_ACTIVE ));
-					$oldBlogCategory->setNumBlogs($this->getNumItems( $this->getPrefix().'blogs', 'blog_category_id = '.$oldBlogCategory->getId()));
-					$blogCategories->updateBlogCategory( $oldBlogCategory );
-				}		
-			}
-			
-			return( true );
-		}
-		
-        /**
-         * Updates the configuration of a blog
-         *
-         * @param blogId Blog identifier
-         * @param blogInfo A BlogInfo object containing all the information of the blog
-         * @param return Returns true if everything's ok or false otherwise
-         */
-        function updateBlog( &$blog )
-        {
-			// load the previous version of this blog
-			$prevVersion = $this->getBlogInfo( $blog->getId());
-			
-			// check that the mangled_blog field is unique
-            $mangledBlog = $blog->getMangledBlogName();
-            $i = 1;
-            // check if there already is a blog with the same mangled name
-			$done = false;
-            while(( $tmpBlog = $this->getBlogInfoByName( $mangledBlog )) && !$done)
-            {
-				if( $tmpBlog->getId() != $blog->getId()) {
-	                $i++;
-	                $mangledBlog = substr($mangledBlog, 0,
-	                               ($i > 2) ? strlen($mangledBlog)-strlen($i-1) : strlen($mangledBlog)).$i;
-				}
-				else {
-					$done = true;
-				}
-            }
-            $blog->setMangledBlogName($mangledBlog);				
-			
-			if( ($result = $this->update( $blog ))) {
-				// reset the caches
-				$this->_cache->removeData( $blog->getCustomDomain(), CACHE_BLOGIDBYDOMAIN );
-				$this->_cache->removeData( $blog->getMangledBlogName(), CACHE_BLOGIDBYNAME );
-				$this->_cache->removeData( $blog->getId(), CACHE_BLOGINFOS );
-									
-				// update blog categories
-				$this->updateBlogCategoriesLink( $blog, $prevVersion );
-				
-				// some settings in the BlogSettings object might affect other database items, such
-				// as the sorting order of categories and link cateegories. Hence, we should reset
-				// those caches too
-				$this->_cache->removeData( $blog->getId(), CACHE_ARTICLE_CATEGORIES_BLOG );
-				$this->_cache->removeData( $blog->getId(), CACHE_MYLINKCATEGORIES_ALL );
-			}
-
-            // always return true,
-            // $result is only false if nothing was changed, but that really isn't an error?
-            return true;
-        }
-
          /**
-          * Adds a new blog to the database.
-          *
-          * @param blog A BlogInfo object with the necessary information
-          * @see BlogInfo
-          * @return False if unsuccessful or true otherwise. It will also set the database id of the
-          * parameter passed by reference in case it is successful.
-          */
-         function addBlog( &$blog )
-         {
-            // source classes
-            lt_include( PLOG_CLASS_PATH."class/dao/bayesianfilterinfos.class.php" );
-            lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
-
-            $blogSettings = $blog->getSettings();
-            if( !$blogSettings )
-                $blogSettings = new BlogSettings();
-
-			// check that the mangled_blog field is unique
-            $mangledBlog = $blog->getMangledBlogName();
-            $i = 1;
-            // check if there already is a blog with the same mangled name
-            while($this->getBlogInfoByName( $mangledBlog ))
-            {
-                $i++;
-                $mangledBlog = substr($mangledBlog, 0,
-                               ($i > 2) ? strlen($mangledBlog)-strlen($i-1) : strlen($mangledBlog)).$i;
-            }
-            $blog->setMangledBlogName($mangledBlog);
-
-			$blogId = $this->add( $blog );
-			
-			// update blog categories
-			$this->updateBlogCategoriesLink( $blog );
-
-            // create the row for the bayesian filter info
-            $bayesianFilterInfo = new BayesianFilterInfos();
-            $bayesianFilterInfo->insert( $blogId );
-            
-            $this->_cache->setData( $blogId, CACHE_BLOGINFOS, $blog );
-//            $this->_cache->setData( $blog->getMangledBlogName(), CACHE_BLOGIDBYNAME );
-
-            // and return the blog identifier
-            return $blogId;
-         }
-
-         /**
           * Returns all the blogs defined for the site in an array, sorted by its
           * blog identifier.
           *
+          * @param last_update
+          * @param total_posts_less_than
           * @param status
+          * @param blogCategoryId
           * @param searchTerms
           * @param page
           * @param itemsPerPage
@@ -203,42 +24,40 @@
           * is sorted by the blog identifier, so that $blogs[$blogId] will give us the information
           * of the blog with $blogId as its identifier.
           */
-         function getAllBlogs( $last_update = 30,
-							   $total_posts_less_than = 5,
+         function getAllBlogs( $last_update,
+							   $total_posts_less_than,
+                               $status = BLOG_STATUS_ALL,
                                $blogCategoryId = ALL_BLOG_CATEGORIES,
                                $searchTerms = "", 
                                $page = -1, 
                                $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
         {
-			$where = "";
-            $this->_startTime = $this->getStartTime( $last_update );			
-			$lastUpdateCond = "";
-            $lastUpdateCond = "last_update_date < ".$this->_startTime;
-			$totalPostLessThanCond = "";
+            $lastUpdateCond = "last_update_date < ".$this->_getStartTime( $last_update );
 			$totalPostLessThanCond = "num_posts < ".$total_posts_less_than;
 			$where = $lastUpdateCond." AND ".$totalPostLessThanCond;
 			
+            if( $status != BLOG_STATUS_ALL )
+                $where .= "status = '".Db::qstr($status)."'";
+
 			if( $blogCategoryId != ALL_BLOG_CATEGORIES ) {
 				if( $where != "" ) 
 					$where .= " AND ";
 				$where .= " blog_category_id = '".Db::qstr($blogCategoryId)."'";
 			}
 
-			$searchCond = "";
 			if( $searchTerms != "" ){
-				$searchCond = $this->getSearchConditions( $searchTerms );
                 if( $where != "" )
                     $where .= " AND ";
-				$where .= $searchCond;
+				$where .= $this->getSearchConditions( $searchTerms );
             }
 				
 			if( $where != "" )
 				$where = " WHERE $where";			
 
-            $query = "SELECT * FROM ".$this->table." $where ORDER BY id DESC";
+            $query = "SELECT * FROM ".$this->getPrefix()."blogs $where ORDER BY id DESC";
 
             $result = $this->Execute( $query, $page, $itemsPerPage );
-#echo $query;
+
             if( !$result )
                 return false;
 
@@ -259,43 +78,26 @@
         }    
 
         /**
-         * returns only an array with all the blog ids
-         *
-         * @return an array with blog ids
-         */
-        function getAllBlogIds()
-        {
-            $query = "SELECT id FROM ".$this->getPrefix()."blogs";
-
-            $result = $this->Execute( $query );
-            if( !$result )
-                return Array();
-
-            $blogIds = Array();
-            while( $row = $result->FetchRow()) {
-                $blogIds[] = $row['id'];
-            }
-            $result->Close();			
-
-            return $blogIds;
-        }
-
-        /**
          * returns the total number of blogs in the site
          *
+         * @param last_update
+         * @param total_posts_less_than
          * @param status
+         * @param blogCategoryId
          * @param searchTerms
          *
          * @return The number of blogs
          */
-        function getNumBlogs( $last_update = 30, $total_posts_less_than = 5, $blogCategoryId = ALL_BLOG_CATEGORIES, $searchTerms = "" )
+        function getNumBlogs( $last_update = 30, $total_posts_less_than = 5, $status = BLOG_STATUS_ALL,
+                              $blogCategoryId = ALL_BLOG_CATEGORIES, $searchTerms = "" )
         {	
-			$where = "";
-            $this->_startTime = $this->getStartTime( $last_update );			
-            $lastUpdateCond = "last_update_date < ".$this->_startTime;
+            $lastUpdateCond = "last_update_date < ".$this->_getStartTime( $last_update );
 			$totalPostLessThanCond = "num_posts < ".$total_posts_less_than;
 			$where = $lastUpdateCond." AND ".$totalPostLessThanCond;
 
+             if( $status != BLOG_STATUS_ALL )
+                 $where .= "status = '".Db::qstr($status)."'";
+
 			if( $blogCategoryId != ALL_BLOG_CATEGORIES )
 				$where .= " AND blog_category_id = '".Db::qstr($blogCategoryId)."'";				
 										
@@ -308,77 +110,10 @@
 			return( $this->getNumItems( $this->getPrefix()."blogs", $where ));
         }
 
-        /**
-         * Removes a blog from the database. It also removes all its posts, its posts categories
-         * its links, its links categories, its trackbacks and its comments
-         *
-         * @param blogId the id of the blog we'd like to delete
-         * @return boolean success of the operation
-         */
-        function deleteBlog( $blogId )
-        {
-			// update blog categories
-			$blog = $this->getBlogInfo( $blogId );
-			$this->updateBlogCategoriesLink( $blog );	
-
-            // source class
-            lt_include( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
-	
-			// delete the blog template sets
-			$templateSets = new TemplateSets();
-			$tsStorage = new TemplateSetStorage();
-			$blogTemplates = $templateSets->getBlogTemplates( $blogId );
-			foreach( $blogTemplates as $template ) {
-				$tsStorage->removeBlogTemplate( $template, $blogId );
-			}
-			// when done, remove the parent "blog_X" folder
-			File::deleteDir( TemplateSetStorage::getBlogBaseTemplateFolder( $blogId ));
-
-            // and finally, remove the cache and delete the blog
-			$this->_cache->removeData( $blog->getCustomDomain(), CACHE_BLOGIDBYDOMAIN );
-			$this->_cache->removeData( $blog->getMangledBlogName(), CACHE_BLOGIDBYNAME );
-			$this->_cache->removeData( $blog->getId(), CACHE_BLOGINFOS );
-            return( $this->delete( "id", $blogId ));
-        }
-
-		/**
-         * @private
-         */
-        function mapRow( $row )
-        {
-            // source class
-            lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
-
-            // create new BlogInfo
-            $blogInfo = new BlogInfo( stripslashes($row["blog"]),
-                                      $row["owner_id"],
-                                      stripslashes($row["about"]),
-                                      unserialize($row["settings"]),
-                                      $row["id"] );
-
-            // load information about the blog status
-            $blogInfo->setStatus( $row["status"] );
-			// load information abotu the blog category id
-			$blogInfo->setBlogCategoryId( $row["blog_category_id"] );
-			// counters
-			$blogInfo->setTotalPosts( $row['num_posts'] );
-			$blogInfo->setTotalTrackbacks( $row['num_trackbacks'] );
-			$blogInfo->setTotalComments( $row['num_comments'] );
-			// mangled blog
-			$blogInfo->setMangledBlogName( $row['mangled_blog'], false );
-			$blogInfo->setCustomDomain( $row['custom_domain'] );
-            // show in summary or not
-			$blogInfo->setShowInSummary( $row['show_in_summary'] );
-			// create date and update date
-			$blogInfo->setCreateDate( $row['create_date'] );
-			$blogInfo->setUpdateDate( $row['last_update_date'] );
-
-            return $blogInfo;
-        }
 		/** 
 		 * @private
 		 */
-		function getStartTime( $duration ) 
+		function _getStartTime( $duration ) 
 		{
 			lt_include( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
 

Modified: plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php	2009-02-13 18:59:30 UTC (rev 6793)
+++ plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php	2009-02-13 19:19:47 UTC (rev 6794)
@@ -40,6 +40,7 @@
 			$blogs = new UnusedBlogs();
             $siteBlogs = $blogs->getAllBlogs( $this->_last_update,
                                               $this->_total_posts_less_than,
+                                              BLOG_STATUS_ALL,
                                               ALL_BLOG_CATEGORIES,
                                               $this->_search_terms,
                                               $this->_page,
@@ -48,10 +49,9 @@
             	$siteBlogs = Array();
             }
 
-#			print("search terms = ".$this->_search_terms);
-
 			$numBlogs = $blogs->getNumBlogs( $this->_last_update,
                                              $this->_total_posts_less_than,
+                                             BLOG_STATUS_ALL,
                                              ALL_BLOG_CATEGORIES,
                                              $this->_search_terms );
             



More information about the pLog-svn mailing list