[pLog-svn] r2307 - in plog/trunk: class/action/admin class/dao class/plugin class/summary/action class/summary/dao class/summary/view class/view/admin templates/admin templates/summary

oscar at devel.plogworld.net oscar at devel.plogworld.net
Tue Jul 12 21:18:47 GMT 2005


Author: oscar
Date: 2005-07-12 21:18:47 +0000 (Tue, 12 Jul 2005)
New Revision: 2307

Added:
   plog/trunk/class/action/admin/adminaddblogcategoryaction.class.php
   plog/trunk/class/action/admin/adminblogcategoriesaction.class.php
   plog/trunk/class/action/admin/adminnewblogcategoryaction.class.php
   plog/trunk/class/dao/blogcategories.class.php
   plog/trunk/class/dao/blogcategory.class.php
   plog/trunk/class/view/admin/adminblogcategorieslistview.class.php
   plog/trunk/templates/admin/blogcategories.template
   plog/trunk/templates/admin/newblogcategory.template
Modified:
   plog/trunk/class/action/admin/adminupdateblogsettingsaction.class.php
   plog/trunk/class/dao/bloginfo.class.php
   plog/trunk/class/dao/blogs.class.php
   plog/trunk/class/plugin/eventlist.properties.php
   plog/trunk/class/summary/action/blogprofileaction.class.php
   plog/trunk/class/summary/dao/summarystats.class.php
   plog/trunk/class/summary/view/summarybloglistview.class.php
   plog/trunk/class/view/admin/adminblogsettingsview.class.php
   plog/trunk/templates/admin/blogsettings.template
   plog/trunk/templates/admin/menus.xml
   plog/trunk/templates/summary/blogslist.template
Log:
added support for blog categories, finally :))) Currently it is only possible to create new ones, I will add support for removing and editing them later on... As we discussed, there is only one blog category per blog. I've also modified the "blog settings" page to allow users to select one category, as well as the summary page that lists all the blogs (now it lists the category too) Now that I think of it, I forgot to modify the registration pages so that users are allowed to select one category at registration time... Perhaps later on!

Added: plog/trunk/class/action/admin/adminaddblogcategoryaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminaddblogcategoryaction.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/action/admin/adminaddblogcategoryaction.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -0,0 +1,79 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
+    include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );	
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminblogcategorieslistview.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+     * Action that adds a new article blog category
+     */
+    class AdminAddBlogCategoryAction extends SiteAdminAction 
+	{
+
+    	var $_categoryName;
+		var $_categoryDescription;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminAddBlogCategoryAction( $actionInfo, $request )
+        {
+        	$this->SiteAdminAction( $actionInfo, $request );
+			
+			// register two validators
+			$this->registerFieldValidator( "categoryName", new StringValidator());
+			$this->registerFieldValidator( "categoryDescription", new StringValidator());
+			// and the view we should show in case there is a validation error
+			$errorView = new AdminTemplatedView( $this->_blogInfo, "newblogcategory" );
+			$errorView->setErrorMessage( $this->_locale->tr("error_adding_blog_category" ));			
+			$this->setValidationErrorView( $errorView );
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+			// fetch the data, we already know it's valid and that we can trust it!
+        	$this->_categoryName     = $this->_request->getValue( "categoryName" );
+			$this->_categoryDescription = $this->_request->getValue( "categoryDescription" );
+		
+			// create the object...
+            $categories = new BlogCategories();
+            $category   = new BlogCategory( $this->_categoryName, $this->_categoryDescription );
+											   
+			// fire the pre event...
+			$this->notifyEvent( EVENT_PRE_BLOG_CATEGORY_ADD, Array( "category" => &$category ));
+
+            // once we have built the object, we can add it to the database!
+            if( $categories->addBlogCategory( $category )) {
+				$this->_view = new AdminBlogCategoriesListView( $this->_blogInfo );
+				$this->_view->setSuccess( true );
+				$this->_view->setSuccessMessage( $this->_locale->pr("blog_category_added_ok", $category->getName()));
+				
+				// fire the post event
+				$this->notifyEvent( EVENT_POST_BLOG_CATEGORY_ADD, Array( "category" => &$category ));
+				
+				// clear the cache if everything went fine
+				CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );														
+				
+				$this->setCommonData();
+            }
+            else {
+				// if there was an error, we should say so... as well as not changing the view since
+				// we're going back to the original view where we can add the category
+				$this->_view->setError( true );
+				$this->_view->setErrorMessage( $this->_locale->tr("error_adding_category" ));
+				$this->setCommonData( true );
+            }
+
+            // better to return true if everything fine
+            return true;
+        }
+    }
+?>
\ No newline at end of file

Added: plog/trunk/class/action/admin/adminblogcategoriesaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminblogcategoriesaction.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/action/admin/adminblogcategoriesaction.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -0,0 +1,20 @@
+<?php
+	
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminblogcategorieslistview.class.php" );
+	
+	class AdminBlogCategoriesAction extends SiteAdminAction
+	{
+	
+		function AdminBlogCategoriesAction( $actionInfo, $request )
+		{
+			$this->SiteAdminAction( $actionInfo, $request );
+		}
+		
+		function perform()
+		{
+			$this->_view = new AdminBlogCategoriesListView( $this->_blogInfo );
+			$this->setCommonData();
+		}
+	}
+?>
\ No newline at end of file

Added: plog/trunk/class/action/admin/adminnewblogcategoryaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminnewblogcategoryaction.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/action/admin/adminnewblogcategoryaction.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -0,0 +1,35 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+    include_once( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+     * Action that adds a new blog category
+     */
+    class AdminNewBlogCategoryAction extends SiteAdminAction
+    {
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminNewBlogCategoryAction( $actionInfo, $request )
+        {
+        	$this->SiteAdminAction( $actionInfo, $request );
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+        	// initialize the view
+        	$this->_view = new AdminTemplatedView( $this->_blogInfo, "newblogcategory" );
+            $this->setCommonData();
+            return true;
+        }
+    }
+?>
\ No newline at end of file

Modified: plog/trunk/class/action/admin/adminupdateblogsettingsaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminupdateblogsettingsaction.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/action/admin/adminupdateblogsettingsaction.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -30,6 +30,7 @@
 			$this->registerFieldValidator( "blogName",  new StringValidator());
 			$this->registerFieldValidator( "blogLocale", new StringValidator());
 			$this->registerFieldValidator( "blogTemplate", new StringValidator());
+			$this->registerFieldValidator( "blogCategory", new IntegerValidator());
 			$this->registerField( "blogAbout" );			
 			$this->registerField( "blogShowMoreEnabled" );
 			$this->registerField( "blogEnableHtmlarea" );
@@ -74,8 +75,8 @@
             $this->_blogInfo->setBlog( $this->_request->getValue( "blogName" ));
             $this->_blogInfo->setSettings( $blogSettings );
 			$this->_blogInfo->setProperties( $this->_request->getValue( "properties" ));
+			$this->_blogInfo->setBlogCategoryId( $this->_request->getValue( "blogCategory" ));
 
-
             // and now update the settings in the database
             $blogs = new Blogs();
 			$this->notifyEvent( EVENT_PRE_BLOG_UPDATE, Array( "blog" => &$this->_blogInfo ));

Added: plog/trunk/class/dao/blogcategories.class.php
===================================================================
--- plog/trunk/class/dao/blogcategories.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/dao/blogcategories.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -0,0 +1,154 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/blogcategory.class.php" );
+	
+	class BlogCategories extends Model
+	{
+	
+		function BlogCategories()
+		{
+			$this->Model();
+		}
+		
+		/**
+		 * loads the given blog category
+		 *
+		 * @param id
+		 * @return false if there was an error loading or a BlogCategory object if it was found
+		 */
+		function getBlogCategory( $id )
+		{
+			$prefix = $this->getPrefix();
+			$query = "SELECT * FROM {$prefix}blog_categories WHERE id = '".Db::qstr( $id )."'";			
+			
+			$result = $this->Execute( $query );
+			
+			if( !$result )
+				return false;
+				
+			$row = $result->FetchRow();
+			
+			return( $this->_mapRow( $row ));
+		}
+		
+		/**
+		 * adds a new blog category
+		 *
+		 * @param category A BlogCategory object
+		 * @return true if successful or false otherwise. Upon success, $category->getId() will
+		 * return the new id assigned to the object in the db.
+		 */
+		function addBlogCategory( &$category )
+		{
+			$prefix = $this->getPrefix();
+			$query = "INSERT INTO {$prefix}blog_categories (name, description, properties)
+			          VALUES ('".Db::qstr($category->getName())."','".Db::qstr($category->getDescription())."','".
+					  Db::qstr(serialize($category->getProperties()))."')";
+					  
+			$result = $this->Execute( $query );
+			
+			if( !$result )
+				return false;
+				
+			// get and set the id for the last insertion
+			$id = $this->_db->Insert_ID();
+			$category->setId( $id );
+			
+			return( true );
+		}
+		
+		/**
+		 * deletes a blog category. Warning: the upper layers must have already made sure that there
+		 * are no blogs that point to this blog categories *before* removing it, or else we could have
+		 * problems with data integrity.		 
+		 *
+		 * @param id
+		 * @return True if successful, false otherwise
+		 */
+		function deleteBlogCategory( $id )
+		{
+			$prefix = $this->getPrefix();
+			$query = "DELETE FROM {$prefix}blog_categories WHERE id = '".Db::qstr( $id )."'";
+			
+			return( $this->Execute( $query ));
+		}
+		
+		/**
+		 * update a given blog category
+		 *
+		 * @param category A BlogCategory object
+		 * @return True if successful or false otherwise
+		 */
+		function updateBlogCategory( $category )
+		{
+			$prefix = $this->getPrefix();
+			$query = "UPDATE {$prefix}blog_categories SET
+			          name = '".Db::qstr( $category->getName())."',
+					  description = '".Db::qstr( $category->getDescription())."',
+					  properties = '".Db::qstr( $category->getProperties())."'
+					  WHERE id = '".Db::qstr( $category->getId())."'";
+					  
+			return( $this->Execute( $query ));
+		}
+		
+		/**
+		 * returns the total amount of blog categories in the database
+		 *
+		 * @return an integer
+		 */
+		function getNumBlogCategories()
+		{
+			$query = "SELECT COUNT(*) AS total FROM ".$this->getPrefix()."blog_categories";
+			
+			$result = $this->Execute( $query );
+			
+			if( !$result )
+				return 0;
+				
+			$row = $result->FetchRow();
+			if( $row["total"] == "" )
+				return( 0 );
+			else
+				return( $row["total"] );
+		}
+		
+		/**
+		 * returns all blog categories
+		 *
+		 * @param page
+		 * @param itemsPerPage
+		 * @return An array of BlogCategory objects or false in case of error
+		 */
+		function getBlogCategories( $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+		{
+			$prefix = $this->getPrefix();
+			$query = "SELECT * FROM {$prefix}blog_categories";
+			
+			// execute the paged query if necessary
+			$result = $this->Execute( $query, $page, $itemsPerPage );
+			
+			if( !$result )
+				return( false );
+				
+			// if everything ok, loop through the results
+			$categories = Array();
+			while( $row = $result->FetchRow()) {
+				array_push( $categories, $this->_mapRow( $row ));
+			}
+			
+			return( $categories );
+		}
+		
+		/**
+		 * @private
+		 */
+		function _mapRow( $row )
+		{
+			return( new BlogCategory( $row["name"],
+			                          $row["description"],
+									  unserialize($row["properties"]),
+									  $row["id"] ));									  
+		}
+	}
+?>
\ No newline at end of file

Added: plog/trunk/class/dao/blogcategory.class.php
===================================================================
--- plog/trunk/class/dao/blogcategory.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/dao/blogcategory.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -0,0 +1,113 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/database/dbobject.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/blogstatus.class.php" );
+
+    /**
+	 * \ingroup DAO
+	 *
+     * Represents a global blog category
+     */
+	class BlogCategory extends DbObject 
+	{
+	
+		var $_id;
+		var $_name;
+		var $_description;
+		var $_properties;
+
+		function BlogCategory( $name, $description = "", $properties = Array(), $id = -1 )
+		{
+			$this->DbObject();
+		
+			$this->_id = $id;
+			$this->_name = $name;
+			$this->_description = $description;
+			$this->_properties = $properties;
+		}
+
+        /**
+         * @private
+         */
+		function setId( $newId )
+		{
+			$this->_id = $newId;
+		}
+
+        /**
+         * @private
+         */
+		function setName( $newName )
+		{
+			$this->_name = $newName;
+		}
+				
+		/**
+		 * sets the description
+		 *
+		 * @param description
+		 */
+		function setDescription( $desc )
+		{
+			$this->_description = $desc;
+		}
+
+        /**
+         * Returns the identifier assigned to this category.
+         *
+         * @return An integer value with the category number.
+         */
+		function getId()
+		{
+			return $this->_id;
+		}
+
+        /**
+         * Returns the name assigned to the category.
+         *
+         * @return A string value with the name assigned to the category.
+         */
+		function getName()
+		{
+			return $this->_name;
+		}
+
+        /**
+         * Returns how many articles have been categorized under this category.
+         *
+		 * @param status A valid post status
+         * @return An integer value
+         */
+        function getNumBlogs( $status = BLOG_STATUS_ACTIVE )
+        {
+        }
+		
+		/**
+		 * returns a list with all the blogs that have been categorized under this category
+		 *
+		 * @return An Array of BlogInfo objects
+		 */
+		function getBlogs( $status = BLOG_STATUS_ACTIVE )
+		{		
+		}
+		
+		/**
+		 * returns the description
+		 *
+		 * @return The description
+		 */
+		function getDescription()
+		{
+			return $this->_description;
+		}
+		
+		/**
+		 * @private
+		 * For future use
+		 */
+		function getProperties()
+		{
+			return( $this->_properties );
+		}	
+	}
+?>

Modified: plog/trunk/class/dao/bloginfo.class.php
===================================================================
--- plog/trunk/class/dao/bloginfo.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/dao/bloginfo.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -39,6 +39,10 @@
 
         // the status
         var $_status;
+		
+		// the blog category
+		var $_categoryId;
+		var $_category;
 
         function BlogInfo( $blog, $owner, $about, $settings, $id = -1 )
         {
@@ -71,6 +75,10 @@
             $this->_totalPosts = null;
             $this->_createTimestamp = null;
             $this->_ownerInfo = null;
+			
+			// information about the blog category id
+			$this->_category = null;
+			$this->_categoryId = 0;
         }
 
         /**
@@ -354,6 +362,7 @@
          */
         function setCreateDate( $newCreateDate )
         {
+        	include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
             $this->_createDate = $newCreateDate;
 
             $this->_createTimestamp = new Timestamp( $newCreateDate );
@@ -364,7 +373,8 @@
          */
         function setUpdateDate( $newUpdateDate )
         {
-            $this->_updateDate = $newUpdateDate;
+        	include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );        
+            $this->_updateDate = $newUpdateDate;           
 
             $this->_updateTimestamp = new Timestamp( $newUpdateDate );
         }
@@ -570,5 +580,49 @@
 
             return true;
         }
+		
+		/**
+		 * returns the blog category id. You shouldn't probably use this method, 
+		 * BlogInfo::getBlogCategory() will return the real BlogCategory object for you.
+		 *
+		 * @return the blog category id
+		 */
+		function getBlogCategoryId()
+		{
+			return( $this->_categoryId );
+		}
+		
+		/**
+		 * sets the blog category id
+		 *
+		 * @param the new id
+		 */
+		function setBlogCategoryId( $categoryId )
+		{
+			if( $categoryId != $this->_categoryId )
+				$this->_category = null;
+		
+			$this->_categoryId = $categoryId;			
+		}
+		
+		/**
+		 * loads the blog category
+		 *
+		 * @return A BlogCategory object
+		 */
+		function getBlogCategory()
+		{
+			// check if the category has already been loaded and if not, load it and save a reference
+			// to it in the object
+			if( $this->_category == null && $this->_categoryId > 0 ) {
+				include_once( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
+				
+				$blogCategories = new BlogCategories();
+				
+				$this->_category = $blogCategories->getBlogCategory( $this->_categoryId );				
+			}
+			
+			return( $this->_category );
+		}
     }
-?>
+?>
\ No newline at end of file

Modified: plog/trunk/class/dao/blogs.class.php
===================================================================
--- plog/trunk/class/dao/blogs.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/dao/blogs.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -1,9 +1,6 @@
 <?php
 
-    require_once( PLOG_CLASS_PATH . 'class/dao/model.class.php' );
-    require_once( PLOG_CLASS_PATH . 'class/config/config.class.php' );
-    require_once( PLOG_CLASS_PATH . 'class/dao/users.class.php' );
-    require_once( PLOG_CLASS_PATH . 'class/file/file.class.php' );
+    require_once( PLOG_CLASS_PATH . 'class/dao/model.class.php' );    
     require_once( PLOG_CLASS_PATH . 'class/dao/blogstatus.class.php' );
 
     /**
@@ -274,6 +271,7 @@
             $keyValuePairs['owner_id']     = $blogInfo->getOwnerId();
             $keyValuePairs['mangled_blog'] = $blogName;
             $keyValuePairs['status']       = $blogInfo->getStatus();
+			$keyValuePairs['blog_category_id'] = $blogInfo->getBlogCategoryId();
 
             $query = Db::buildUpdateQuery( BLOGS_TABLENAME,
                                            $keyValuePairs,
@@ -319,6 +317,7 @@
          {
             // source classes
             include_once( PLOG_CLASS_PATH."class/net/xmlrpcclient.class.php" );
+            require_once( PLOG_CLASS_PATH . 'class/config/config.class.php' );            
 
             // if this feature is not enabled, we quit
             $config =& Config::getConfig();
@@ -369,15 +368,16 @@
             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,blog_category_id)
                      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->getStatus())."','".
+					 Db::qstr($blog->getBlogCategoryId())."');";
 
-            $result = $this->Execute( $query );
+            $result = $this->Execute( $query );            
 
             if( !$result ){
                 // FIXME: throw an exception?
@@ -429,7 +429,7 @@
                                            array(),
                                            $whereConditions,
                                            null,
-                                           'blog' );
+                                           'blog' );                                           
 
             $result = $this->Execute( $query, $page, $itemsPerPage );
 
@@ -633,10 +633,12 @@
                                       unserialize($query_result["settings"]),
                                       $query_result["id"] );
 
-            // load information about the blog owner
+            // load information about the blog status
             $blogInfo->setStatus( $query_result["status"] );
+			// load information abotu the blog category id
+			$blogInfo->setBlogCategoryId( $query_result["blog_category_id"] );
 
             return $blogInfo;
         }
     }
-?>
+?>
\ No newline at end of file

Modified: plog/trunk/class/plugin/eventlist.properties.php
===================================================================
--- plog/trunk/class/plugin/eventlist.properties.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/plugin/eventlist.properties.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -156,4 +156,12 @@
 	define( "EVENT_POST_MARK_SPAM_TRACKBACK", 25 ); 
 	define( "EVENT_PRE_MARK_NO_SPAM_TRACKBACK", 26 ); 
 	define( "EVENT_POST_MARK_NO_SPAM_TRACKBACK", 27 ); 	
-?>
+	// events related to new blog categories
+	define( "EVENT_PRE_ADD_BLOG_CATEGORY", 112 );
+	define( "EVENT_POST_ADD_BLOG_CATEGORY", 113 );
+	define( "EVENT_PRE_UPDATE_BLOG_CATEGORY", 114 );
+	define( "EVENT_POST_UPDATE_BLOG_CATEGORY", 115 );
+	define( "EVENT_PRE_DELETE_BLOG_CATEGORY", 116 );
+	define( "EVENT_POST_UPDATE_BLOG_CATEGORY", 117 );
+	define( "EVENT_BLOG_CATEGORIES_LOADED", 118 );
+?>
\ No newline at end of file

Modified: plog/trunk/class/summary/action/blogprofileaction.class.php
===================================================================
--- plog/trunk/class/summary/action/blogprofileaction.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/summary/action/blogprofileaction.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -1,9 +1,7 @@
 <?php
 
 	include_once( PLOG_CLASS_PATH."class/summary/action/summaryaction.class.php" );
-    include_once( PLOG_CLASS_PATH."class/summary/dao/summarystats.class.php" );
     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 
-	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );	
 	
 	/**
 	 * by default, how many posts show as recent from this blog
@@ -44,6 +42,10 @@
 				return true;
 			}
 			
+			include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+			include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+			include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+			
 			// load some information about the user
 			$blogs = new Blogs();
 			$blogInfo = $blogs->getBlogInfo( $this->_blogId, true );
@@ -57,7 +59,7 @@
 			
 			// fetch the blog latest posts
 			$posts = Array();
-			$articles = new Articles();
+			$articles = new Articles();			
 			$t = new Timestamp();
 			$posts = $articles->getBlogArticles( $blogInfo->getId(),
 			                                     -1,

Modified: plog/trunk/class/summary/dao/summarystats.class.php
===================================================================
--- plog/trunk/class/summary/dao/summarystats.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/summary/dao/summarystats.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -4,8 +4,6 @@
     include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/articlecommentstatus.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/articlestatus.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
-    include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 	
 	/**
 	 * maximum number of items that will be shown per page in the summary
@@ -24,25 +22,11 @@
      */
     class SummaryStats extends Model
     {
-        
-        var $_now;
-        var $_sevenDaysAgo;
 
         function SummaryStats()
         {
             // initialize ADOdb
             $this->Model();
-            
-            // common object for all methods so that we can reuse caches
-            $this->articles = new Articles();
-            $this->blogs = new Blogs();            
-            
-            // calculate the date limits
-            $t = new Timestamp();
-            $this->_now = $t->getTimestamp(); 
-            // 7 days ago
-            $t->subtractSeconds( 7 * 24 * 60 * 60 );
-            $this->_sevenDaysAgo = $t->getTimestamp();
         }
 
         /**
@@ -67,8 +51,15 @@
        				         AND c.status = ".COMMENT_STATUS_NONSPAM."
        				         AND b.id = a.blog_id
        				         AND b.status = ".BLOG_STATUS_ACTIVE."
-       				         AND a.date <= ".$this->_now;
+       				         AND a.date <= NOW()";
 
+			// ignore certain topics and/or certain texts
+			/*if( $ignoreTopic != "" )
+				$query .= " AND t.topic NOT LIKE '%".Db::qstr( $ignoreTopic )."%' ";
+
+			if( $ignoreText != "" )
+				$query .= " AND t.text NOT LIKE '%".Db::qstr( $ignoreTopic )."%' ";*/
+
 			$query .= " GROUP BY c.article_id ORDER BY total_comments DESC ";
 
             if( $maxPosts > 0 )
@@ -82,8 +73,9 @@
             }
 
             $posts = Array();
+            $articles = new Articles();
             while( $row = $result->FetchRow()) {
-            	array_push( $posts, $this->articles->_fillArticleInformation($row));
+            	array_push( $posts, $articles->_fillArticleInformation($row));
             }
 
             return $posts;
@@ -100,8 +92,8 @@
          */
         function getMostReadArticles( $maxPosts = 0, $ignoreTopic = "", $ignoreText = "" )
         {
+             include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 
-
              $prefix = $this->getPrefix();
              $query = " SELECT 
                  a.id as id, 
@@ -114,7 +106,7 @@
                  a.slug as slug
                  FROM {$prefix}articles a
                  WHERE status = ".POST_STATUS_PUBLISHED."
-                 AND a.date <= ".$this->_now." AND a.date > ".$this->_sevenDaysAgo;
+                 AND TO_DAYS(NOW()) - TO_DAYS(date) < 7  ";
 
 			$query .= " ORDER BY a.num_reads DESC ";
 
@@ -127,8 +119,9 @@
             	return Array();
 
             $posts = Array();
+            $articles = new Articles();
             while( $row = $result->FetchRow()) {
-				$post = $this->articles->_fillArticleInformation($row);
+				$post = $articles->_fillArticleInformation($row);
             	array_push( $posts, $post );
             }
 
@@ -157,8 +150,9 @@
             }
 
             $blogs = Array();
+            $blogdao = new Blogs();
             while( $row = $result->FetchRow()) {
-            	$blog = $this->blogs->_fillBlogInformation( $row );
+            	$blog = $blogdao->_fillBlogInformation( $row );
                 $blogs[$blog->getId()] = $blog;
             }
 
@@ -179,8 +173,7 @@
                        FROM {$prefix}articles AS a
                        INNER JOIN {$prefix}blogs AS b 
                            ON b.id=a.blog_id AND b.status=".BLOG_STATUS_ACTIVE.
-                       " WHERE a.date >= ".$this->_sevenDaysAgo." AND a.date <= ".$this->_now." 
-                       GROUP BY a.blog_id ORDER BY rank DESC ";
+                       " GROUP BY a.blog_id ORDER BY rank DESC ";
 
             if( $maxBlogs > 0 )
                 $query .= " LIMIT 0,".$maxBlogs;
@@ -192,8 +185,9 @@
             }
 
             $blogs = Array();
+            $blogdao = new Blogs();
             while( $row = $result->FetchRow()) {
-                $blog = $this->blogs->_fillBlogInformation( $row );
+                $blog = $blogdao->_fillBlogInformation( $row );
                 $blogs[$blog->getId()] = $blog;
             }
 
@@ -257,17 +251,18 @@
             $date   = $t->getTimestamp();
 			$prefix = $this->getPrefix();
 
-			$query = "SELECT a.id as id, a.id,a.date,
+			$query = "SELECT a.id as id, a.id,t.topic,t.text,a.date,
                              a.user_id,a.blog_id, a.status, a.properties,
                              a.num_reads, a.slug
 					  FROM {$prefix}articles a, 
 					       {$prefix}blogs b
-					  WHERE a.date >= ".$this->_sevenDaysAgo." AND a.date <= ".$this->_now."
+					  WHERE TO_DAYS(NOW()) - TO_DAYS(a.date) < 7 
 					        AND a.blog_id = b.id
 					        AND b.status = ".BLOG_STATUS_ACTIVE."
-					        AND a.status = ".POST_STATUS_PUBLISHED;
+					        AND a.status = ".POST_STATUS_PUBLISHED."
+					        AND a.date < NOW()";
 
-			$query .= " ORDER BY a.date DESC LIMIT 0, $maxPosts";
+			$query .= " GROUP BY a.id ORDER BY a.date DESC LIMIT 0, $maxPosts";
 
             $result = $this->Execute( $query );
 
@@ -277,12 +272,12 @@
             $blogs = Array();
             $posts = Array();
             $i     = 0;
-
+            $articles = new Articles();
             while( ($row = $result->FetchRow()) && ($i < $maxPosts) ) {
                 if (!in_array($row["blog_id"], $blogs))
                 {
                     $blogs[] = $row["blog_id"];
-                    array_push( $posts, $this->articles->_fillArticleInformation($row) );
+                    array_push( $posts, $articles->_fillArticleInformation($row) );
                     $i++;
                 }
             }
@@ -321,13 +316,13 @@
 
                 if (empty($maxPosts))
                 {
-                    array_push( $posts, $this->articles->_fillArticleInformation($row));
+                    array_push( $posts, $articles->_fillArticleInformation($row));
                     $count++;
                 }
                 else if($count <= $maxPosts && empty($ids[$row["blog_id"]]))
                 {
                     $ids[$row["blog_id"]] = true;
-                    array_push( $posts, $this->articles->_fillArticleInformation($row));
+                    array_push( $posts, $articles->_fillArticleInformation($row));
                     $count++;
                 }
             }

Modified: plog/trunk/class/summary/view/summarybloglistview.class.php
===================================================================
--- plog/trunk/class/summary/view/summarybloglistview.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/summary/view/summarybloglistview.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -36,9 +36,9 @@
 			}
 
 			// get the data itself
-			$blogs = new Blogs();
+			$blogs = new Blogs();						
             $siteBlogs = $blogs->getAllBlogs( BLOG_STATUS_ACTIVE, "", $this->_page, $this->_numBlogsPerPage );
-			$numBlogs = $blogs->getNumBlogs( BLOG_STATUS_ACTIVE );
+			$numBlogs = $blogs->getNumBlogs( BLOG_STATUS_ACTIVE );			
 			
             if( !$siteBlogs ) {
                 // if there was an error, show the error view

Added: plog/trunk/class/view/admin/adminblogcategorieslistview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminblogcategorieslistview.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/view/admin/adminblogcategorieslistview.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -0,0 +1,60 @@
+<?php
+
+?><?php
+
+	include_once( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
+	
+    /**
+     * \ingroup View
+     * @private
+     *
+     * Action that shows a form to add a link for the blogroll feature
+     */
+    class AdminBlogCategoriesListView extends AdminTemplatedView 
+	{
+		var $_page;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminBlogCategoriesListView( $blogInfo )
+        {
+        	$this->AdminTemplatedView( $blogInfo, "blogcategories" );			
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function render()
+        {
+			// prepare a few parameters
+            $categories = new BlogCategories();
+			
+			// get the page too
+			$this->_page = $this->getCurrentPageFromRequest();
+			
+			// retrieve the categories in an paged fashion
+			$totalCategories = $categories->getNumBlogCategories();
+            $blogCategories = $categories->getBlogCategories( $this->_page, DEFAULT_ITEMS_PER_PAGE );
+			if( !$blogCategories ) {
+				$blogCategories = Array();
+			}
+			
+			// throw the even in case somebody's waiting for it!
+			$this->notifyEvent( EVENT_BLOG_CATEGORIES_LOADED, Array( "categories" => &$blogCategories ));
+            $this->setValue( "categories", $blogCategories );
+			
+			// the pager that will be used
+			$pager = new Pager( "?op=editBlogCategories&amp;page=",
+			                    $this->_page,
+								$totalCategories,
+								DEFAULT_ITEMS_PER_PAGE );
+			$this->setValue( "pager", $pager );
+			
+			parent::render();
+        }
+    }
+?>
\ No newline at end of file

Modified: plog/trunk/class/view/admin/adminblogsettingsview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminblogsettingsview.class.php	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/class/view/admin/adminblogsettingsview.class.php	2005-07-12 21:18:47 UTC (rev 2307)
@@ -3,6 +3,7 @@
 	include_once( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
 	include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
 	include_once( PLOG_CLASS_PATH."class/locale/locales.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
 	
     /**
      * \ingroup View
@@ -34,6 +35,7 @@
 			$this->setValue( "blogShowFuturePosts", $blogSettings->getValue( "show_future_posts_in_calendar" ));
 			$this->setValue( "blogEnableAutosaveDrafts", $blogSettings->getValue( "new_drafts_autosave_enabled" ));
 			$this->setValue( "blogCommentsOrder", $blogSettings->getValue( "comments_order" ));
+			$this->setValue( "blogCategory", $this->_blogInfo->getBlogCategoryId());
 		}
 		
 		function render()
@@ -48,6 +50,10 @@
 			// waaaay nicer than just showing the locale code
             $this->setValue( "locales", Locales::getLocales());
 			
+			// set the blog categories
+			$categories = new BlogCategories();
+			$this->setValue( "categories", $categories->getBlogCategories());			
+			
 			parent::render();
 		}
 	}

Added: plog/trunk/templates/admin/blogcategories.template
===================================================================
--- plog/trunk/templates/admin/blogcategories.template	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/templates/admin/blogcategories.template	2005-07-12 21:18:47 UTC (rev 2307)
@@ -0,0 +1,50 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=editBlogCategories title=$locale->tr("editBlogCategories")}
+
+        <div id="list_nav_bar">
+            <div id="list_nav_select">
+            
+ <form id="deleteBlogCategories" action="admin.php" method="post"
+ <div id="list">
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}
+ <table class="info">
+  <thead>
+   <tr>
+    <th style="width:10px;"><input class="checkbox" type="checkbox" class="check" name="all" id="all" value="1" onclick="toggleAllChecks('deleteCategories');" /></th>
+    <th style="width:375px;">{$locale->tr("category")}</th>
+    <th style="width:100px;">{$locale->tr("blogs")}</th>
+    <th style="width:95px;">{$locale->tr("actions")}</th>
+   </tr>
+  </thead>
+  <tbody> 
+  {foreach from=$categories item=category}
+  <tr class="{cycle values="odd, even"}">
+   <td>
+      <input class="checkbox" type="checkbox" name="categoryIds[{counter}]" id="checks_{$category->getId()}" value="{$category->getId()}" />
+   </td>  
+   <td class="col_highlighted">
+    <a href="admin.php?op=editBlogCategory&amp;categoryId={$category->getId()}">{$category->getName()}</a>
+   </td>
+   <td>
+    {$category->getNumBlogs()}
+   </td>	
+   <td>
+     <div class="list_action_button">
+       <a href="?op=editBlogCategory&amp;categoryId={$category->getId()}"><img src="imgs/admin/icon_edit-16.png" alt="{$locale->tr("edit")}" /></a>
+       <a href="?op=deleteBlogCategory&amp;categoryId={$category->getId()}"><img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete")}" /></a>
+     </div>
+   </td>
+  </tr>
+  {/foreach}
+ </tbody> 
+ </table>
+ </div>
+ <div id="list_action_bar">
+  {include file="$admintemplatepath/adminpager.template" style=list}
+  <input type="hidden" name="op" value="deleteBlogCategories"/>
+  <input type="submit" name="Delete selected" value="{$locale->tr("delete")}"/>
+ </div>
+ </form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file

Modified: plog/trunk/templates/admin/blogsettings.template
===================================================================
--- plog/trunk/templates/admin/blogsettings.template	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/templates/admin/blogsettings.template	2005-07-12 21:18:47 UTC (rev 2307)
@@ -41,6 +41,22 @@
       </select>
       {include file="$admintemplatepath/validate.template" field=blogLocale message=$locale->tr("error_invalid_locale")}
     </div>
+	
+    <div class="field">
+     <label for="blogLocale">{$locale->tr("blog_category")}</label>
+     <span class="required">*</span>
+     <div class="formHelp">{$locale->tr("blog_category_help")}</div>
+     <select name="blogCategory" id="blogCategory">
+	  <option value="0">{$locale->tr("none")}</option>
+      {foreach from=$categories item=category}
+       <option value="{$category->getId()}" {if $category->getId()==$blogCategory} selected="selected" {/if}>
+	    {$category->getName()}
+	   </option>
+      {/foreach}
+      </select>
+      {include file="$admintemplatepath/validate.template" field=blogCategory message=$locale->tr("error_invalid_blog_category")}
+    </div>
+	
 
     <div class="field">
      <label for="blogMaxMainPageItems">{$locale->tr("max_main_page_items")}</label>

Modified: plog/trunk/templates/admin/menus.xml
===================================================================
--- plog/trunk/templates/admin/menus.xml	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/templates/admin/menus.xml	2005-07-12 21:18:47 UTC (rev 2307)
@@ -5,6 +5,8 @@
 	       <editPosts url="?op=editPosts"/>
 	       <editArticleCategories url="?op=editArticleCategories" />
 	       <newArticleCategory url="?op=newArticleCategory" />
+	       <editComments url="?op=editComments" />
+	       <editTrackbacks url="?op=editTrackbacks" />		   
  		</managePosts>
  		<manageLinks ignoreBreadCrumbs="1">
 			 <newLink url="?op=newLink" /> 		
@@ -48,6 +50,8 @@
 		<Blogs ignoreBreadCrumbs="1">
 			<createBlog url="?op=createBlog" siteAdmin="1" />
 			<editSiteBlogs url="?op=editSiteBlogs" siteAdmin="1" />		
+			<newBlogCategory url="?op=newBlogCategory" siteAdmin="1" />
+			<editBlogCategories url="?op=editBlogCategories" siteAdmin="1" />			
 		</Blogs>
 		<Locales ignoreBreadCrumbs="1">
 			<newLocale url="?op=newLocale" siteAdmin="1" />

Added: plog/trunk/templates/admin/newblogcategory.template
===================================================================
--- plog/trunk/templates/admin/newblogcategory.template	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/templates/admin/newblogcategory.template	2005-07-12 21:18:47 UTC (rev 2307)
@@ -0,0 +1,32 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=newBlogCategory title=$locale->tr("newBlogCategory")}
+
+ <form name="addBlogCategory" method="post" action="admin.php">
+  <fieldset class="inputField">
+   <legend>{$locale->tr("newBlogCategory")}</legend>
+   {include file="$admintemplatepath/formvalidate.template" message=$locale->tr("error_adding_blog_category")}   
+   
+   <div class="field">
+    <label for="categoryName">{$locale->tr("name")}</label>
+    <span class="required">*</span>
+    <div class="formHelp">{$locale->tr("category_name_help")}</div>
+    <input type="text" value="{$categoryName}" id="categoryName" name="categoryName" />
+    {include file="$admintemplatepath/validate.template" field=categoryName message=$locale->tr("error_empty_name")}
+   </div>
+   
+   <div class="field">
+    <label for="categoryDescription">{$locale->tr("description")}</label>
+    <span class="required">*</span>
+    <div class="formHelp">{$locale->tr("category_description_help")}</div>	
+    <textarea name="categoryDescription" cols="60" id="categoryDescription" rows="5">{$categoryDescription}</textarea>
+    {include file="$admintemplatepath/validate.template" field=categoryDescription message=$locale->tr("error_empty_description")}  
+   </div>
+   
+  </fieldset>
+  <div class="buttons">
+   <input type="hidden" name="op" value="addBlogCategory" />
+   <input type="reset" name="Reset" value="{$locale->tr("reset")}" />
+   <input type="submit" name="Add" value="{$locale->tr("add")}" />
+  </div> 
+ </form>
+{include file="$admintemplatepath/footer.template"}

Modified: plog/trunk/templates/summary/blogslist.template
===================================================================
--- plog/trunk/templates/summary/blogslist.template	2005-07-12 21:15:12 UTC (rev 2306)
+++ plog/trunk/templates/summary/blogslist.template	2005-07-12 21:18:47 UTC (rev 2307)
@@ -4,12 +4,14 @@
         {assign var="updateDate" value=$blog->getUpdateDateObject()}
         {assign var="owner" value=$blog->getOwnerInfo()}
 		{assign var="url" value=$blog->getBlogRequestGenerator()}
+		{assign var=category value=$blog->getBlogCategory()}
 
         <h3>
 		 <a href="{$url->blogLink()}">{$blog->getBlog()|strip_tags}</a>
 		 <a href="?op=BlogProfile&amp;blogId={$blog->getId()}"> ? </a>
 		</h3>
         <div class="subtitle">
+		    {if $category}{$locale->tr("category")}: {$category->getName()}{/if}<br/>
             {$locale->tr("updated")} {$locale->formatDate($updateDate,"%e %B %Y")}
         </div>
         <p>




More information about the pLog-svn mailing list