[pLog-svn] r1472 - plog/trunk/class/dao

francesc at devel.plogworld.net francesc at devel.plogworld.net
Mon Mar 14 22:48:14 GMT 2005


Author: francesc
Date: 2005-03-14 22:48:14 +0000 (Mon, 14 Mar 2005)
New Revision: 1472

Modified:
   plog/trunk/class/dao/bloginfo.class.php
   plog/trunk/class/dao/blogs.class.php
Log:
Added getTotalComments & getTotalTrackbacks to be used by dashboard

Modified: plog/trunk/class/dao/bloginfo.class.php
===================================================================
--- plog/trunk/class/dao/bloginfo.class.php	2005-03-14 16:32:50 UTC (rev 1471)
+++ plog/trunk/class/dao/bloginfo.class.php	2005-03-14 22:48:14 UTC (rev 1472)
@@ -3,58 +3,60 @@
     /**
      * @package dao
      */
-	 
-	include_once( PLOG_CLASS_PATH."class/database/dbobject.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/blogsettings.class.php" );
-	include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );
-	include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
 
-	/**
-	 * This is the representation of a blog. It contains all the information we need to know,
+    include_once( PLOG_CLASS_PATH."class/database/dbobject.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/blogsettings.class.php" );
+    include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );
+    include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+
+    /**
+     * This is the representation of a blog. It contains all the information we need to know,
      * such as the name of the blog, the owner, description, etc.
-	 */
-	class BlogInfo extends DbObject 
-	{
+     */
+    class BlogInfo extends DbObject
+    {
 
-		var $_blog;
-		var $_owner; // owner id
-		var $_about;
-		var $_settings;
-		var $_id;
+        var $_blog;
+        var $_owner; // owner id
+        var $_about;
+        var $_settings;
+        var $_id;
 
         // More optional information for each blog. Only used when we load this data
         var $_createDate;
         var $_updateDate;
         var $_totalPosts;
+        var $_totalComments;
+        var $_totalTrackbacks;
         var $_viewedTotal;
         var $_ownerInfo;
-        var $_usersInfo;        
-        var $_createTimestamp;        
+        var $_usersInfo;
+        var $_createTimestamp;
         var $_updateTimestamp;
-		
-		// the TemplateSet representing the template set used by the blog
-		var $_templateSet;
-		
-		// the Locale object
-		var $_locale;
-		
-		// the status
-		var $_status;
 
-		function BlogInfo( $blog, $owner, $about, $settings, $id = -1 )
-		{
-			$this->setBlog( $blog );
-			$this->_owner = $owner;
-			$this->_about = $about;
-			$this->_settings = $settings;
-			if( $this->_settings == "" )
-				$this->_settings = new BlogSettings();
-			
-			$this->_id = $id;
+        // the TemplateSet representing the template set used by the blog
+        var $_templateSet;
 
+        // the Locale object
+        var $_locale;
+
+        // the status
+        var $_status;
+
+        function BlogInfo( $blog, $owner, $about, $settings, $id = -1 )
+        {
+            $this->setBlog( $blog );
+            $this->_owner = $owner;
+            $this->_about = $about;
+            $this->_settings = $settings;
+            if( $this->_settings == "" )
+                $this->_settings = new BlogSettings();
+
+            $this->_id = $id;
+
             $this->_createDate = "";
             $this->_updateDate = "";
             $this->_totalPosts = 0;
@@ -62,30 +64,30 @@
             $this->_usersInfo = array();
             $this->_createTimestamp = "";
             $this->_updateTimestamp = "";
-			
-			// no template set loaded
-			$this->_templateSet = null;
-			
-			// default status is active
-			$this->_status = BLOG_STATUS_ACTIVE;
-			
-			// values that are loaded on demand
-			$this->_updateTimestamp = null;
-			$this->_viewedTotal = null;
-			$this->_totalPosts = null;
-			$this->_createTimestamp = null;
-            $this->_ownerInfo = null;			
-		}
 
+            // no template set loaded
+            $this->_templateSet = null;
+
+            // default status is active
+            $this->_status = BLOG_STATUS_ACTIVE;
+
+            // values that are loaded on demand
+            $this->_updateTimestamp = null;
+            $this->_viewedTotal = null;
+            $this->_totalPosts = null;
+            $this->_createTimestamp = null;
+            $this->_ownerInfo = null;
+        }
+
         /**
          * Returns the short name of the blog.
          *
          * @return A string with the short name of the blog.
          */
-		function getBlog()
-		{
-			return $this->_blog;
-		}
+        function getBlog()
+        {
+            return $this->_blog;
+        }
 
 
         /**
@@ -93,10 +95,10 @@
          *
          * @return An integer value representing the identifier of the user who owns this blog.
          */
-		function getOwner()
-		{
-			return $this->_owner;
-		}
+        function getOwner()
+        {
+            return $this->_owner;
+        }
 
         /**
          * Returns a longer and descriptive text about this blog. It can also be empty since it is
@@ -104,410 +106,434 @@
          *
          * @return A string containing the more descriptive text about the journal.
          */
-		function getAbout()
-		{
-			return $this->_about;
-		}
+        function getAbout()
+        {
+            return $this->_about;
+        }
 
         /**
          * Returns a BlogSettings object with information about the settings of the journal.
          * @private
          */
-		function getSettings()
-		{
-			return $this->_settings;
-		}
-		
-		/**
-		 * returns a key from the blog settings
-		 */
-		function getValue( $value )
-		{
-			if( !$this->_settings )
-				return "";
-				
-			return $this->_settings->getValue( $value );
-		}
-		
-		/**
-		 * returns a key from the blog settings
-		 */
-		function setValue( $key, $value )
-		{
-			if( !$this->_settings )
-				return true;
-				
-			$this->_settings->setValue( $key, $value );
-			
-			return true;
-		}
-		
-		/**
-		 * implemented from DbObject. Merges a list of properties with the current settings
-		 *
-		 * @param properties
-		 */
-		function addProperties( $properties )
-		{
-			return $this->setProperties( $properties );
-		}
-		
-		/**
-		 * adds an array of pairs (key,value) to the blog settings
-		 */
-		function setProperties( $properties )
-		{
-			// nothing to do if we don't get an array as parameters
-			if( !is_array($properties))
-				return true;
-				
-			foreach( $properties as $key => $value ) {
-				$this->setValue( $key, $value );
-			}
-			
-			return true;
-		}
+        function getSettings()
+        {
+            return $this->_settings;
+        }
 
+        /**
+         * returns a key from the blog settings
+         */
+        function getValue( $value )
+        {
+            if( !$this->_settings )
+                return "";
+
+            return $this->_settings->getValue( $value );
+        }
+
+        /**
+         * returns a key from the blog settings
+         */
+        function setValue( $key, $value )
+        {
+            if( !$this->_settings )
+                return true;
+
+            $this->_settings->setValue( $key, $value );
+
+            return true;
+        }
+
+        /**
+         * implemented from DbObject. Merges a list of properties with the current settings
+         *
+         * @param properties
+         */
+        function addProperties( $properties )
+        {
+            return $this->setProperties( $properties );
+        }
+
+        /**
+         * adds an array of pairs (key,value) to the blog settings
+         */
+        function setProperties( $properties )
+        {
+            // nothing to do if we don't get an array as parameters
+            if( !is_array($properties))
+                return true;
+
+            foreach( $properties as $key => $value ) {
+                $this->setValue( $key, $value );
+            }
+
+            return true;
+        }
+
          /**
          */
-		function getCreateDateObject( )
-		{
-			// if it hasn't been loaded yet...
-			if( $this->_createTimestamp == null ) {
-				$blogs = new Blogs();
-				$this->setCreateDate( $blogs->getBlogCreateDate( $this->getId()));
-			}
-			
-			return $this->_createTimestamp;
-		}
+        function getCreateDateObject( )
+        {
+            // if it hasn't been loaded yet...
+            if( $this->_createTimestamp == null ) {
+                $blogs = new Blogs();
+                $this->setCreateDate( $blogs->getBlogCreateDate( $this->getId()));
+            }
 
+            return $this->_createTimestamp;
+        }
+
         /**
          */
-		function getUpdateDateObject( )
-		{
-			if( $this->_updateTimestamp == null ) {
-				$blogs = new Blogs();
-				$this->setUpdateDate( $blogs->getBlogUpdateDate( $this->getId()));
-			}
-			
-			return $this->_updateTimestamp;
-		}
+        function getUpdateDateObject( )
+        {
+            if( $this->_updateTimestamp == null ) {
+                $blogs = new Blogs();
+                $this->setUpdateDate( $blogs->getBlogUpdateDate( $this->getId()));
+            }
 
+            return $this->_updateTimestamp;
+        }
+
         /**
          */
-		function getTotalPosts( )
-		{
-			if( $this->_totalPosts == null ) {
-				$blogs = new Blogs();
-				$this->_totalPosts = $blogs->getBlogTotalPosts( $this->getId());
-			}
-			
-			return $this->_totalPosts;
-		}
+        function getTotalPosts( )
+        {
+            if( $this->_totalPosts == null ) {
+                $blogs = new Blogs();
+                $this->_totalPosts = $blogs->getBlogTotalPosts( $this->getId());
+            }
 
+            return $this->_totalPosts;
+        }
+
         /**
          */
-		function getViewedTotal( )
-		{
-			if( $this->_viewedTotal == null ) {
-				$blogs = new Blogs();
-				$this->_viewedTotal = $blogs->getBlogViewedTotal( $this->getId());
-			}
-		
-			return $this->_viewedTotal;
-		}
+        function getTotalComments( )
+        {
+            if( $this->_totalComments == null ) {
+                $blogs = new Blogs();
+                $this->_totalComments = $blogs->getBlogTotalComments( $this->getId());
+            }
 
+            return $this->_totalComments;
+        }
+
         /**
-		 * Gets information about the owner of this blog
-		 * @return return a UserInfo object which contains much more info about the owner of the blog
          */
-		function getOwnerInfo()
-		{
-			if( $this->_ownerInfo == null ) {
-				$users = new Users();
-				$ownerInfo = $users->getUserInfoFromId( $this->_owner );
-				$this->setOwnerInfo( $ownerInfo );			
-			}
-		
-			return $this->_ownerInfo;
-		}
+        function getTotalTrackbacks( )
+        {
+            if( $this->_totalTrackbacks == null ) {
+                $blogs = new Blogs();
+                $this->_totalTrackbacks = $blogs->getBlogTotalTrackbacks( $this->getId());
+            }
 
+            return $this->_totalTrackbacks;
+        }
+
         /**
+         */
+        function getViewedTotal( )
+        {
+            if( $this->_viewedTotal == null ) {
+                $blogs = new Blogs();
+                $this->_viewedTotal = $blogs->getBlogViewedTotal( $this->getId());
+            }
+
+            return $this->_viewedTotal;
+        }
+
+        /**
+         * Gets information about the owner of this blog
+         * @return return a UserInfo object which contains much more info about the owner of the blog
+         */
+        function getOwnerInfo()
+        {
+            if( $this->_ownerInfo == null ) {
+                $users = new Users();
+                $ownerInfo = $users->getUserInfoFromId( $this->_owner );
+                $this->setOwnerInfo( $ownerInfo );
+            }
+
+            return $this->_ownerInfo;
+        }
+
+        /**
          * @private
          */
-		function getUsersInfo( )
-		{
-			if( $this->_usersInfo == null ) {
-				$userpermissions = new UserPermissions();			
-				$blogUsers = $userpermissions->getBlogUsers( $this->getId());
-                $this->setUsersInfo( $blogUsers );			
-			}
-			
-			return $this->_usersInfo;
-		}
+        function getUsersInfo( )
+        {
+            if( $this->_usersInfo == null ) {
+                $userpermissions = new UserPermissions();
+                $blogUsers = $userpermissions->getBlogUsers( $this->getId());
+                $this->setUsersInfo( $blogUsers );
+            }
 
+            return $this->_usersInfo;
+        }
+
         /**
          * Returns the identifier of this blog.
          *
          * @return An integer value with the identifier of this blog.
          */
-		function getId()
-		{
-			return $this->_id;
-		}
+        function getId()
+        {
+            return $this->_id;
+        }
 
         /**
          * @private
          */
-		function setBlog( $blog )
-		{
-			$tf = new Textfilter();
-			$this->_blog = $tf->filterAllHTML($blog);
-		}
+        function setBlog( $blog )
+        {
+            $tf = new Textfilter();
+            $this->_blog = $tf->filterAllHTML($blog);
+        }
 
         /**
          * @param owner id
          * @private
          */
-		function setOwner( $owner )
-		{
-			$this->_owner = $owner;
-		}
+        function setOwner( $owner )
+        {
+            $this->_owner = $owner;
+        }
 
         /**
          * @private
          */
-		function setAbout( $about )
-		{
-			$this->_about = $about;
-		}
+        function setAbout( $about )
+        {
+            $this->_about = $about;
+        }
 
         /**
          * @private
          */
-		function setSettings( $settings )
-		{
-			$this->_settings = $settings;
-		}
+        function setSettings( $settings )
+        {
+            $this->_settings = $settings;
+        }
 
         /**
          * @private
          */
-		function setCreateDate( $newCreateDate )
-		{
-			$this->_createDate = $newCreateDate;
+        function setCreateDate( $newCreateDate )
+        {
+            $this->_createDate = $newCreateDate;
 
-			$this->_createTimestamp = new Timestamp( $newCreateDate );
-		}
+            $this->_createTimestamp = new Timestamp( $newCreateDate );
+        }
 
         /**
          * @private
          */
-		function setUpdateDate( $newUpdateDate )
-		{
-			$this->_updateDate = $newUpdateDate;
+        function setUpdateDate( $newUpdateDate )
+        {
+            $this->_updateDate = $newUpdateDate;
 
-			$this->_updateTimestamp = new Timestamp( $newUpdateDate );
-		}
+            $this->_updateTimestamp = new Timestamp( $newUpdateDate );
+        }
 
         /**
          * @private
          */
-		function setTotalPosts( $newTotalPosts )
-		{
-			$this->_totalPosts = $newTotalPosts;
-		}
+        function setTotalPosts( $newTotalPosts )
+        {
+            $this->_totalPosts = $newTotalPosts;
+        }
 
         /**
          * @private
          */
-		function setViewedTotal( $newViewedTotal )
-		{
-			$this->_viewedTotal = $newViewedTotal;
-		}
+        function setViewedTotal( $newViewedTotal )
+        {
+            $this->_viewedTotal = $newViewedTotal;
+        }
 
         /**
          * @private
          */
-		function setOwnerInfo( $newOwnerInfo )
-		{
-			$this->_ownerInfo = $newOwnerInfo;
-		}
+        function setOwnerInfo( $newOwnerInfo )
+        {
+            $this->_ownerInfo = $newOwnerInfo;
+        }
 
         /**
          * @private
          */
-		function setUsersInfo( $newUsersInfo )
-		{
-			$this->_usersInfo = $newUsersInfo;
-		}
+        function setUsersInfo( $newUsersInfo )
+        {
+            $this->_usersInfo = $newUsersInfo;
+        }
 
         /**
          * @private
          */
-		function setId( $id )
-		{
-			$this->_id = $id;
-		}
+        function setId( $id )
+        {
+            $this->_id = $id;
+        }
 
-		/**
-		 * returns the name of the template used by this blog
-		 *
-		 * @param the name of the template set used by this blog
-		 */
-		function getTemplate()
-		{
-			return $this->_settings->getValue( "template");
-		}
-		
-		/**
-		 * sets the template name
-		 *
-		 * @param template The name of the template that we'd like to use
-		 * @return always true
-		 */
-		function setTemplate( $template )
-		{
-			// save the template in the settings
-			$this->_settings->setValue( "template", $template );
-			// and reset the TemplateSet object so that it gets reloaded next time
-			// somebody uses BlogInfo::getTemplateSet
-			$this->_templateSet = null;	
-			
-			return true;
-		}
-		
-		/**
-		 * this method is some kind of a shortcut for a very common operation: obtaining the
-		 * correct RequestGenerator object so that we can generate urls based on the information
-		 * from this blog. This is very handy for example in the summary page where we have to 
-		 * generate lots of different urls for lots of different blogs.
-		 *
-		 * @return A RequestGenerator object
-		 */
-		function getBlogRequestGenerator()
-		{
-			return RequestGenerator::getRequestGenerator( $this );
-		}
-		
-		/**
-		 * returns a TemplateSet object with the information about the template used
-		 * by the blog
-		 *
-		 * @return a TemplateSet object
-		 */
-		function getTemplateSet()
-		{
-			// since including these files is quite a costly operation, let's do it only
-			// whenever we have to instead of always and always always... :)
-			if( $this->_templateSet == null ) {
-				include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
-				$ts = new TemplateSets();
-				$this->_templateSet = $ts->getTemplateSet( $this->getTemplate(), $this->getId());
-				if( $this->_templateSet == null ) {
-					// what if the admin removes the current template set used by this blog???
-					$this->_templateSet = $ts->getDefaultTemplateSet();
-				}
-			}
-			
-			return $this->_templateSet;
-		}
-		
-		/**
-		 * changes the template set used by the blog
-		 *
-		 * @param templateSet A TemplateSet object
-		 * @return always true
-		 */
-		function setTemplateSet( $templateSet )
-		{
-			$this->setTemplate( $templateSet->getName());
-			
-			return true;
-		}
-		
-		/**
-		 * returns the right locale object for the blog
-		 *
-		 * @param a Locale object
-		 */
-		function &getLocale()
-		{
-			if( $this->_locale == null ) {
-				include_once( PLOG_CLASS_PATH."class/locale/locales.class.php" );	
-				$this->_locale =& Locales::getLocale( $this->_settings->getValue( "locale" ), "en_UK" );
-			}
-			
-			return $this->_locale;
-		}
-		
-		/**
-		 * sets the new locale for the blog
-		 *
-		 * @param a valid Locale object
-		 * @return Always true
-		 */
-		function setLocale( $locale )
-		{
-			$this->_locale = $locale;
-			$this->_settings->setValue( "locale", $locale->getLocaleCode());
-			
-			return true;	
-		}
-		
-		/**
-		 * returns the status of the blog
-		 *
-		 * @return the current status of the blog
-		 */
-		function getStatus()
-		{
-			return $this->_status;
-		}
-		
-		/**
-		 * sets the current status of the blog
-		 *
-		 * @param status
-		 * @return always true
-		 */
-		function setStatus( $status )
-		{
-			$this->_status = $status;
-			
-			return true;	
-		}
-		
-		/**
-		 * returns the quota for this blog, or the value of the global quota
-		 * for blogs in case this blog has no quota assigned
-		 *
-		 * @return the resources quota
-		 */
-		function getResourcesQuota()
-		{
-			$quota = $this->_settings->getValue( "resources_quota" );
-			
-			// 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" );
-			}
-			
-			return $quota;
-		}
+        /**
+         * returns the name of the template used by this blog
+         *
+         * @param the name of the template set used by this blog
+         */
+        function getTemplate()
+        {
+            return $this->_settings->getValue( "template");
+        }
 
-		/**
-		 * sets the quota
-		 *
-		 * @param quota
-		 */
-		function setResourcesQuota( $quota )
-		{
-			$this->_settings->setValue( "resources_quota", $quota );
+        /**
+         * sets the template name
+         *
+         * @param template The name of the template that we'd like to use
+         * @return always true
+         */
+        function setTemplate( $template )
+        {
+            // save the template in the settings
+            $this->_settings->setValue( "template", $template );
+            // and reset the TemplateSet object so that it gets reloaded next time
+            // somebody uses BlogInfo::getTemplateSet
+            $this->_templateSet = null;
 
-			return true;
-		}
-	}
+            return true;
+        }
+
+        /**
+         * this method is some kind of a shortcut for a very common operation: obtaining the
+         * correct RequestGenerator object so that we can generate urls based on the information
+         * from this blog. This is very handy for example in the summary page where we have to
+         * generate lots of different urls for lots of different blogs.
+         *
+         * @return A RequestGenerator object
+         */
+        function getBlogRequestGenerator()
+        {
+            return RequestGenerator::getRequestGenerator( $this );
+        }
+
+        /**
+         * returns a TemplateSet object with the information about the template used
+         * by the blog
+         *
+         * @return a TemplateSet object
+         */
+        function getTemplateSet()
+        {
+            // since including these files is quite a costly operation, let's do it only
+            // whenever we have to instead of always and always always... :)
+            if( $this->_templateSet == null ) {
+                include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
+                $ts = new TemplateSets();
+                $this->_templateSet = $ts->getTemplateSet( $this->getTemplate(), $this->getId());
+                if( $this->_templateSet == null ) {
+                    // what if the admin removes the current template set used by this blog???
+                    $this->_templateSet = $ts->getDefaultTemplateSet();
+                }
+            }
+
+            return $this->_templateSet;
+        }
+
+        /**
+         * changes the template set used by the blog
+         *
+         * @param templateSet A TemplateSet object
+         * @return always true
+         */
+        function setTemplateSet( $templateSet )
+        {
+            $this->setTemplate( $templateSet->getName());
+
+            return true;
+        }
+
+        /**
+         * returns the right locale object for the blog
+         *
+         * @param a Locale object
+         */
+        function &getLocale()
+        {
+            if( $this->_locale == null ) {
+                include_once( PLOG_CLASS_PATH."class/locale/locales.class.php" );
+                $this->_locale =& Locales::getLocale( $this->_settings->getValue( "locale" ), "en_UK" );
+            }
+
+            return $this->_locale;
+        }
+
+        /**
+         * sets the new locale for the blog
+         *
+         * @param a valid Locale object
+         * @return Always true
+         */
+        function setLocale( $locale )
+        {
+            $this->_locale = $locale;
+            $this->_settings->setValue( "locale", $locale->getLocaleCode());
+
+            return true;
+        }
+
+        /**
+         * returns the status of the blog
+         *
+         * @return the current status of the blog
+         */
+        function getStatus()
+        {
+            return $this->_status;
+        }
+
+        /**
+         * sets the current status of the blog
+         *
+         * @param status
+         * @return always true
+         */
+        function setStatus( $status )
+        {
+            $this->_status = $status;
+
+            return true;
+        }
+
+        /**
+         * returns the quota for this blog, or the value of the global quota
+         * for blogs in case this blog has no quota assigned
+         *
+         * @return the resources quota
+         */
+        function getResourcesQuota()
+        {
+            $quota = $this->_settings->getValue( "resources_quota" );
+
+            // 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" );
+            }
+
+            return $quota;
+        }
+
+        /**
+         * sets the quota
+         *
+         * @param quota
+         */
+        function setResourcesQuota( $quota )
+        {
+            $this->_settings->setValue( "resources_quota", $quota );
+
+            return true;
+        }
+    }
 ?>

Modified: plog/trunk/class/dao/blogs.class.php
===================================================================
--- plog/trunk/class/dao/blogs.class.php	2005-03-14 16:32:50 UTC (rev 1471)
+++ plog/trunk/class/dao/blogs.class.php	2005-03-14 22:48:14 UTC (rev 1472)
@@ -9,71 +9,71 @@
     include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
     include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
     include_once( PLOG_CLASS_PATH."class/net/xmlrpcclient.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/mylinks.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/bayesianfilterinfos.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
-	include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
-	include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/blogstatus.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/mylinks.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/bayesianfilterinfos.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
+    include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+    include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/blogstatus.class.php" );
 
     /**
      * Model for the Blogs
      */
-	class Blogs extends Model
-	{
+    class Blogs extends Model
+    {
 
-		/**
-		 * Returns information about a blog.
+        /**
+         * Returns information about a blog.
          *
          * @param blogId Identifier of the blog we want to get information
-		 * @param extendedInfo
+         * @param extendedInfo
          * @return Returns a BlogInfo object containing information about the blog
-		 */
-		function getBlogInfo( $blogId, $extendedInfo = false )
-		{
-			$query = "SELECT * FROM ".$this->getPrefix()."blogs WHERE id = '".Db::qstr($blogId)."'";
+         */
+        function getBlogInfo( $blogId, $extendedInfo = false )
+        {
+            $query = "SELECT * FROM ".$this->getPrefix()."blogs WHERE id = '".Db::qstr($blogId)."'";
 
-			return $this->_getBlogInfoFromQuery( $query, $extendedInfo );
-		}
+            return $this->_getBlogInfoFromQuery( $query, $extendedInfo );
+        }
 
-		/**
-		 * Returns information about a blog.
+        /**
+         * 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 )
-		{
-			$query = "SELECT * FROM ".$this->getPrefix()."blogs WHERE mangled_blog = '".Db::qstr($blogName)."';";
+         */
+        function getBlogInfoByName( $blogName, $extendedInfo = false )
+        {
+            $query = "SELECT * FROM ".$this->getPrefix()."blogs WHERE mangled_blog = '".Db::qstr($blogName)."';";
 
-			//$this->_db->debug=true;
+            //$this->_db->debug=true;
 
-			return $this->_getBlogInfoFromQuery( $query, $extendedInfo );
-		}
+            return $this->_getBlogInfoFromQuery( $query, $extendedInfo );
+        }
 
-		/**
-		 * @private
-		 */
-		function _getBlogInfoFromQuery( $query, $extendedInfo = false )
-		{
-			$result = $this->Execute( $query );
+        /**
+         * @private
+         */
+        function _getBlogInfoFromQuery( $query, $extendedInfo = false )
+        {
+            $result = $this->Execute( $query );
 
-			if( !$result )
-				return false;
+            if( !$result )
+                return false;
 
             if( $result->RecordCount() == 0 )
-            	return false;
+                return false;
 
-			$row = $result->FetchRow( $result );
-			$blogInfo = $this->_fillBlogInformation( $row, $extendedInfo );
+            $row = $result->FetchRow( $result );
+            $blogInfo = $this->_fillBlogInformation( $row, $extendedInfo );
             $blogSettings = $this->getBlogSettingsFromField( $row["settings"] );
             $blogInfo->setSettings( $blogSettings );
 
-			return $blogInfo;
-		}
+            return $blogInfo;
+        }
 
         /**
          * Private function.
@@ -82,18 +82,18 @@
          */
         function _fillBlogInformation( $query_result, $extended = false )
         {
-        	$blogInfo = new BlogInfo( stripslashes($query_result["blog"]),
+            $blogInfo = new BlogInfo( stripslashes($query_result["blog"]),
                                       $query_result["owner_id"],
                                       stripslashes($query_result["about"]),
                                       unserialize($query_result["settings"]),
                                       $query_result["id"] );
 
-			// load information about the blog owner
-			$blogInfo->setStatus( $query_result["status"] );
+            // load information about the blog owner
+            $blogInfo->setStatus( $query_result["status"] );
 
             return $blogInfo;
         }
-		
+
         /**
          * Retrieves the first article date timestamp
          *
@@ -102,7 +102,7 @@
          */
         function getBlogCreateDate( $blogId )
         {
-			$query  = "SELECT date FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId. " ORDER BY date ASC LIMIT 0,1" ;
+            $query  = "SELECT date FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId. " ORDER BY date ASC LIMIT 0,1" ;
 
             $result = $this->_db->Execute( $query );
 
@@ -116,7 +116,7 @@
 
             return $row["date"];
         }
-		
+
         /**
          * Retrieves the last article date timestamp
          *
@@ -125,7 +125,7 @@
          */
         function getBlogUpdateDate( $blogId )
         {
-			$query  = "SELECT date FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId. " ORDER BY date DESC LIMIT 0,1" ;
+            $query  = "SELECT date FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId. " ORDER BY date DESC LIMIT 0,1" ;
             $result = $this->_db->Execute( $query );
 
             if (!$result)
@@ -138,7 +138,7 @@
 
             return $row["date"];
         }
-		
+
         /**
          * Retrieves the total number of reads of all articles in that blog
          *
@@ -147,7 +147,7 @@
          */
         function getBlogViewedTotal( $blogId )
         {
-			$query  = "SELECT SUM(num_reads) as total FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId;
+            $query  = "SELECT SUM(num_reads) as total FROM ".$this->getPrefix()."articles WHERE blog_id = ".$blogId;
 
             $result = $this->_db->Execute( $query );
 
@@ -161,7 +161,7 @@
 
             return $row["total"];
         }
-		
+
         /**
          * Retrieves the total number of posts in a blog
          *
@@ -170,7 +170,7 @@
          */
         function getBlogTotalPosts( $blogId )
         {
-			$query  = "SELECT COUNT(*) as total FROM ".$this->getPrefix()."articles WHERE blog_id = $blogId AND status = ".POST_STATUS_PUBLISHED;
+            $query  = "SELECT COUNT(*) as total FROM ".$this->getPrefix()."articles WHERE blog_id = $blogId AND status = ".POST_STATUS_PUBLISHED;
             $result = $this->_db->Execute( $query );
 
             if (!$result)
@@ -182,9 +182,53 @@
                 return false;
 
             return intval($row["total"]);
-        }														
+        }
 
         /**
+         * Retrieves the total number of comments in a blog
+         *
+         * @param blogId The identifier of the blog from which we'd like to fetch the settings
+         * @return Returns an integer with the number of comments
+         */
+        function getBlogTotalComments( $blogId )
+        {
+            $query  = "SELECT COUNT(*) as total FROM ".$this->getPrefix()."articles_comments AS c, ".$this->getPrefix()."articles AS a WHERE ((a.blog_id = $blogId) AND (a.id = c.article_id)) AND c.status = ".COMMENT_STATUS_NONSPAM;
+            $result = $this->_db->Execute( $query );
+
+            if (!$result)
+                return false;
+
+            $row = $result->FetchRow();
+
+            if (!isset($row["total"]))
+                return false;
+
+            return intval($row["total"]);
+        }
+
+        /**
+         * Retrieves the total number of trackbacks in a blog
+         *
+         * @param blogId The identifier of the blog from which we'd like to fetch the settings
+         * @return Returns an integer with the number of trackbacks
+         */
+        function getBlogTotalTrackbacks( $blogId )
+        {
+            $query  = "SELECT COUNT(*) as total FROM ".$this->getPrefix()."trackbacks AS t, ".$this->getPrefix()."articles AS a WHERE ((a.blog_id = $blogId) AND (a.id = t.article_id))";
+            $result = $this->_db->Execute( $query );
+
+            if (!$result)
+                return false;
+
+            $row = $result->FetchRow();
+
+            if (!isset($row["total"]))
+                return false;
+
+            return intval($row["total"]);
+        }
+
+        /**
          * Retrieves the blog settings
          *
          * @param settingsField The contents of the blog_settings field from the database
@@ -192,16 +236,16 @@
          */
         function getBlogSettingsFromField( $settingsField )
         {
-        	if( $settingsField == "" || $settingsField == null ) {
-            	$settings = new BlogSettings();
+            if( $settingsField == "" || $settingsField == null ) {
+                $settings = new BlogSettings();
             }
             else {
-				$settings = unserialize( $settingsField );
+                $settings = unserialize( $settingsField );
                 if( !is_object($settings)) {
-                	// if the BlogSettings object is not valid, return a valid one
+                    // if the BlogSettings object is not valid, return a valid one
                     // with some of the default settings, so that at least
                     // the blog will keep working!
-                	$settings = new BlogSettings();
+                    $settings = new BlogSettings();
                 }
             }
 
@@ -216,7 +260,7 @@
          */
         function getBlogSettings( $blogId )
         {
-			$query = "SELECT settings FROM ".$this->getPrefix()."blogs WHERE id = ".$blogId;
+            $query = "SELECT settings FROM ".$this->getPrefix()."blogs WHERE id = ".$blogId;
 
             $result = $this->Execute( $query );
 
@@ -234,14 +278,14 @@
          */
         function updateBlog( $blogId, $blogInfo )
         {
-        	$query = "UPDATE ".$this->getPrefix()."blogs SET
-        	         blog = '".Db::qstr($blogInfo->getBlog()).
-        	         "', about = '".Db::qstr($blogInfo->getAbout()).
-        	         "', settings = '".serialize($blogInfo->getSettings()).
-        	         "', owner_id = ".$blogInfo->getOwner().
-        	         ", mangled_blog = '".TextFilter::urlize($blogInfo->getBlog()).
-        	         "', status = '".Db::qstr($blogInfo->getStatus()).
-        	         "' WHERE id = '".Db::qstr($blogId)."';";
+            $query = "UPDATE ".$this->getPrefix()."blogs SET
+                     blog = '".Db::qstr($blogInfo->getBlog()).
+                     "', about = '".Db::qstr($blogInfo->getAbout()).
+                     "', settings = '".serialize($blogInfo->getSettings()).
+                     "', owner_id = ".$blogInfo->getOwner().
+                     ", mangled_blog = '".TextFilter::urlize($blogInfo->getBlog()).
+                     "', status = '".Db::qstr($blogInfo->getStatus()).
+                     "' WHERE id = '".Db::qstr($blogId)."';";
 
             $result = $this->Execute( $query );
 
@@ -257,7 +301,7 @@
          */
          function updateBlogSettings( $blogId, $blogSettings )
          {
-         	$query = "UPDATE ".$this->getPrefix()."blogs SET settings = '".serialize($blogSettings)."' WHERE id = ".$blogId;
+            $query = "UPDATE ".$this->getPrefix()."blogs SET settings = '".serialize($blogSettings)."' WHERE id = ".$blogId;
 
             $result = $this->Execute( $query );
 
@@ -272,28 +316,28 @@
           */
          function updateNotify( $blogInfo )
          {
-         	// if this feature is not enabled, we quit
-			$config =& Config::getConfig();
+            // if this feature is not enabled, we quit
+            $config =& Config::getConfig();
             if( !$config->getValue( "xmlrpc_ping_enabled" ))
-            	return;
+                return;
 
-         	// get the array which contains the hosts
+            // get the array which contains the hosts
             $hosts = $config->getValue( "xmlrpc_ping_hosts" );
 
             // if it is not an array, quit
             if( !is_array($hosts))
-            	return;
+                return;
 
             // if no hosts, we can quit too
             if( empty($hosts))
-            	return;
+                return;
 
             // otherwise, we continue
             $xmlrpcPingResult = Array();
             $rg =& RequestGenerator::getRequestGenerator( $blogInfo );
             $blogLink = $rg->blogLink();
             foreach( $hosts as $host ) {
-            	$client = new XmlRpcClient( $host );
+                $client = new XmlRpcClient( $host );
                 $result = $client->ping( $blogInfo->getBlog(), $blogLink);
                 //print("result = ".$result. "is Error = ".$client->isError()." message: ".$client->getErrorMessage()."<br/>");
                 //$xmlrpcPingResult[$result["host"]
@@ -307,23 +351,23 @@
           * 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.
+          * @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 )
          {
-			$blogSettings = $blog->getSettings();
-			if( !$blogSettings )
-				$blogSettings = new BlogSettings();
+            $blogSettings = $blog->getSettings();
+            if( !$blogSettings )
+                $blogSettings = new BlogSettings();
 
-         	$query = "INSERT INTO ".$this->getPrefix()."blogs (blog,owner_id,about,settings,mangled_blog,status)
+            $query = "INSERT INTO ".$this->getPrefix()."blogs (blog,owner_id,about,settings,mangled_blog,status)
                      VALUES ('".Db::qstr($blog->getBlog())."',".
                      $blog->getOwner().",'".
-					 Db::qstr($blog->getAbout())."', '".
-					 Db::qstr(serialize($blogSettings))."', '".
-					 TextFilter::urlize($blog->getBlog())."', '".
-					 Db::qstr($blog->getStatus())."')";
+                     Db::qstr($blog->getAbout())."', '".
+                     Db::qstr(serialize($blogSettings))."', '".
+                     TextFilter::urlize($blog->getBlog())."', '".
+                     Db::qstr($blog->getStatus())."')";
 
                      $this->log->debug($query);
 
@@ -333,20 +377,20 @@
             if( !$result ){
                 $this->log->error("add blog to db failed:".$this->DbError());
                 // FIXME: throw an exception?
-            	return false;
+                return false;
             }
 
 
             $blogId = $this->_db->Insert_ID();
-			
-			$blog->setId( $blogId );
 
-			// create the row for the bayesian filter info
-			$bayesianFilterInfo = new BayesianFilterInfos();
-			$bayesianFilterInfo->insert( $blogId );
+            $blog->setId( $blogId );
 
-			// and return the blog identifier
-			return $blogId;
+            // create the row for the bayesian filter info
+            $bayesianFilterInfo = new BayesianFilterInfos();
+            $bayesianFilterInfo->insert( $blogId );
+
+            // and return the blog identifier
+            return $blogId;
          }
 
          /**
@@ -362,58 +406,58 @@
           */
          function getAllBlogs( $status = BLOG_STATUS_ALL, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
          {
-			if( $status != BLOG_STATUS_ALL )
-				$where = "WHERE status = '".Db::qstr($status)."'";
+            if( $status != BLOG_STATUS_ALL )
+                $where = "WHERE status = '".Db::qstr($status)."'";
 
-         	$query = "SELECT * FROM ".$this->getPrefix()."blogs $where ORDER BY blog $limits";
+            $query = "SELECT * FROM ".$this->getPrefix()."blogs $where ORDER BY blog $limits";
 
             $result = $this->Execute( $query, $page, $itemsPerPage );
 
             if( !$result )
-            	return false;
+                return false;
 
             $blogs = Array();
             while( $row = $result->FetchRow()) {
-            	$blog = $this->_fillBlogInformation( $row, true );
+                $blog = $this->_fillBlogInformation( $row, true );
                 $blogs[$blog->getId()] = $blog;
             }
 
             return $blogs;
         }
-		
-		/**
-		 * 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();
-				
-			// return all the rows straight from adodb
-			return( $result->GetRows());
-		}
 
-		/**
-		 * returns the total number of blogs in the site
-		 *
-		 * @return The number of blogs
-		 */
-		function getNumBlogs( $status = BLOG_STATUS_ALL )
-		{
-			$prefix = $this->getPrefix();
-			$table = "{$prefix}blogs";
-			if( $status != BLOG_STATUS_ALL )
-				$cond = "status = '".Db::qstr($status)."'";		
-				
-			return( $this->getNumItems( $table, $cond ));
-		}
+        /**
+         * 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();
+
+            // return all the rows straight from adodb
+            return( $result->GetRows());
+        }
+
         /**
+         * returns the total number of blogs in the site
+         *
+         * @return The number of blogs
+         */
+        function getNumBlogs( $status = BLOG_STATUS_ALL )
+        {
+            $prefix = $this->getPrefix();
+            $table = "{$prefix}blogs";
+            if( $status != BLOG_STATUS_ALL )
+                $cond = "status = '".Db::qstr($status)."'";
+
+            return( $this->getNumItems( $table, $cond ));
+        }
+
+        /**
          * 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
          *
@@ -421,7 +465,7 @@
          */
         function deleteBlog( $blogId )
         {
-        	// first of all, delete the posts
+            // first of all, delete the posts
             $articles = new Articles();
             $articles->deleteBlogPosts( $blogId );
 
@@ -440,33 +484,33 @@
             $perms->revokeBlogPermissions( $blogId );
 
             // and finally, delete the blog
-        	$query = "DELETE FROM ".$this->getPrefix()."blogs WHERE id = $blogId";
+            $query = "DELETE FROM ".$this->getPrefix()."blogs WHERE id = $blogId";
 
             $result = $this->Execute( $query );
 
             return $result;
         }
 
-		 /**
-		  * disables a blog
-		  *
-		  * @param blogId
-		  */
-		 function disableBlog( $blogId )
-		 {
-				$query = "UPDATE ".$this->getPrefix()."blogs
-						  SET status = '".BLOG_STATUS_DISABLED."'
-						  WHERE id = '".Db::qstr($blogId)."'";
+         /**
+          * disables a blog
+          *
+          * @param blogId
+          */
+         function disableBlog( $blogId )
+         {
+                $query = "UPDATE ".$this->getPrefix()."blogs
+                          SET status = '".BLOG_STATUS_DISABLED."'
+                          WHERE id = '".Db::qstr($blogId)."'";
 
-				$result = $this->Execute( $query );
+                $result = $this->Execute( $query );
 
-				if( !$result )
-					return false;
+                if( !$result )
+                    return false;
 
-				if( $this->_db->Affected_Rows() == 0 )
-					return false;
+                if( $this->_db->Affected_Rows() == 0 )
+                    return false;
 
-				return true;
-		 }
+                return true;
+         }
      }
 ?>




More information about the pLog-svn mailing list