[pLog-svn] r6791 - in plugins/branches/lifetype-1.2: . clean clean/class clean/class/action clean/class/dao clean/class/view clean/locale clean/templates

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Fri Feb 13 12:31:23 EST 2009


Author: jondaley
Date: 2009-02-13 12:31:23 -0500 (Fri, 13 Feb 2009)
New Revision: 6791

Added:
   plugins/branches/lifetype-1.2/clean/
   plugins/branches/lifetype-1.2/clean/class/
   plugins/branches/lifetype-1.2/clean/class/action/
   plugins/branches/lifetype-1.2/clean/class/action/admincleanaction.class.php
   plugins/branches/lifetype-1.2/clean/class/action/admincleandeleteblogaction.class.php
   plugins/branches/lifetype-1.2/clean/class/dao/
   plugins/branches/lifetype-1.2/clean/class/dao/unusedblogs.class.php
   plugins/branches/lifetype-1.2/clean/class/view/
   plugins/branches/lifetype-1.2/clean/class/view/admincleandeleteblogaction.class.php
   plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php
   plugins/branches/lifetype-1.2/clean/locale/
   plugins/branches/lifetype-1.2/clean/locale/locale_en_UK.php
   plugins/branches/lifetype-1.2/clean/locale/locale_vn_VN.php
   plugins/branches/lifetype-1.2/clean/pluginclean.class.php
   plugins/branches/lifetype-1.2/clean/templates/
   plugins/branches/lifetype-1.2/clean/templates/cleanblogs.template
Log:
Mai Minh wrote a requested plugin.  This is the author's version, I'll be fixing it shortly

Added: plugins/branches/lifetype-1.2/clean/class/action/admincleanaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/action/admincleanaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/clean/class/action/admincleanaction.class.php	2009-02-13 17:31:23 UTC (rev 6791)
@@ -0,0 +1,24 @@
+<?php
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."plugins/clean/class/view/admincleanview.class.php" );	
+
+	/**
+	 * shows a form with the current configuration
+	 */
+	class AdminCleanAction extends AdminAction
+	{
+    	function AdminCleanAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+			$this->requireAdminPermission( "view_site_blogs" );
+        }
+        
+        function perform()
+        {
+	        $this->_view = new AdminCleanView( $this->_blogInfo );
+	        $this->setCommonData();	        
+            return true;
+        }
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/clean/class/action/admincleandeleteblogaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/action/admincleandeleteblogaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/clean/class/action/admincleandeleteblogaction.class.php	2009-02-13 17:31:23 UTC (rev 6791)
@@ -0,0 +1,104 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+    lt_include( PLOG_CLASS_PATH."plugins/clean/class/view/admincleanview.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+	 * it does not delete blogs from the system but simply set them to disabled
+	 */
+	class AdminCleanDeleteBlogAction extends AdminAction
+	{
+		var $_op;
+		var $_blogIds;
+
+    	function AdminCleanDeleteBlogAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+
+			// set up the data validation stuff
+        	$this->_op = $actionInfo->getActionParamValue();
+        	if( $this->_op == "cleanDeleteBlogs" )
+        		$this->registerFieldvalidator( "blogIds", new ArrayValidator( new IntegerValidator()));
+        	else
+        		$this->registerFieldValidator( "blogId", new IntegerValidator());
+        	$view = new AdminCleanView( $this->_blogInfo );
+        	$view->setErrorMessage( $this->_locale->tr("error_no_blogs_selected"));
+        	$this->setValidationErrorView( $view );
+
+			$this->requireAdminPermission( "update_site_blog" );
+        }
+
+        function perform()
+        {
+        	if( $this->_op == "cleanDeleteBlog" ) {
+        		$this->_blogIds = Array();
+        		$blogId = $this->_request->getValue( "blogId" );
+        		$this->_blogIds[] = $blogId;
+        	}
+        	else
+        		$this->_blogIds = $this->_request->getValue( "blogIds" );
+
+        	$this->_disableBlogs();
+        }
+        
+//        function disableBlog( $blogIn
+
+		/**
+		 * @private
+		 */
+        function _disableBlogs()
+        {
+        	// get the default blog id
+        	$config =& Config::getConfig();
+            $defaultBlogId = $config->getValue( "default_blog_id" );
+
+        	$errorMessage = "";
+        	$successMessage = "";
+        	$totalOk = 0;
+
+            $blogs = new Blogs();
+        	foreach( $this->_blogIds as $blogId ) {
+            	// get some info about the blog before deleting it
+                $blogInfo = $blogs->getBlogInfo( $blogId );
+				if( !$blogInfo ) {
+					$errorMessage .= $this->_locale->pr("error_deleting_blog2", $blogId)."<br/>";
+				}
+				else {
+					$this->notifyEvent( EVENT_PRE_BLOG_DELETE, Array( "blog" => &$blogInfo ));
+					// make sure we're not deleting the default one!
+					if( $defaultBlogId == $blogId ) {
+						$errorMessage .= $this->_locale->pr("error_blog_is_default_blog", $blogInfo->getBlog())."<br />";
+					}
+					else {
+					   // disable the blog
+					    $blogInfo->setStatus( BLOG_STATUS_DISABLED );
+						if( $blogs->updateBlog( $blogInfo )) {
+							$totalOk++;						
+							if( $totalOk < 2 )
+								$successMessage = $this->_locale->pr("blog_deleted_ok", $blogInfo->getBlog());
+							else
+								$successMessage = $this->_locale->pr( "blogs_deleted_ok", $totalOk );
+							
+							$this->notifyEvent( EVENT_POST_BLOG_DELETE, Array( "blog" => &$blogInfo ));
+						}
+						else
+							$errorMessage .= $this->_locale->pr("error_deleting_blog", $blogInfo->getBlog())."<br/>";
+					}
+				}
+			}
+
+            $this->_view = new AdminCleanView( $this->_blogInfo );
+            if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
+            if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage );
+            $this->setCommonData();
+
+            return true;
+        }
+    }
+?>

Added: plugins/branches/lifetype-1.2/clean/class/dao/unusedblogs.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/dao/unusedblogs.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/clean/class/dao/unusedblogs.class.php	2009-02-13 17:31:23 UTC (rev 6791)
@@ -0,0 +1,396 @@
+<?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
+    {
+		var $_startTime;			
+    	function UnusedBlogs()
+    	{
+    		$this->Model();    	
+    		$this->table = $this->getPrefix()."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 status
+          * @param searchTerms
+          * @param page
+          * @param itemsPerPage
+          *
+          * @return Returns an array with all the blogs defined for this site. The array
+          * 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,
+                               $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 = "";
+			$totalPostLessThanCond = "num_posts < ".$total_posts_less_than;
+			$where = $lastUpdateCond." AND ".$totalPostLessThanCond;
+			
+			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;
+            }
+				
+			if( $where != "" )
+				$where = " WHERE $where";			
+
+            $query = "SELECT * FROM ".$this->table." $where ORDER BY id DESC";
+
+            $result = $this->Execute( $query, $page, $itemsPerPage );
+#echo $query;
+            if( !$result )
+                return false;
+
+            $blogs = Array();
+            while( $row = $result->FetchRow()) {
+				// map the row we just loaded
+                $blog = $this->mapRow( $row );
+                $blogs[$blog->getId()] = $blog;
+				
+				// and cache whatever we loaded for later use, just in case
+				$this->_cache->setData( $blog->getId(), CACHE_BLOGINFOS, $blog );
+				$this->_cache->setData( $blog->getMangledBlogName(), CACHE_BLOGIDBYNAME, $blog );				
+				$this->_cache->setData( $blog->getCustomDomain(), CACHE_BLOGIDBYDOMAIN, $blog );				
+            }
+            $result->Close();			
+
+            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();
+
+            $blogIds = Array();
+            while( $row = $result->FetchRow()) {
+                $blogIds[] = $row['id'];
+            }
+            $result->Close();			
+
+            return $blogIds;
+        }
+
+        /**
+         * returns the total number of blogs in the site
+         *
+         * @param status
+         * @param searchTerms
+         *
+         * @return The number of blogs
+         */
+        function getNumBlogs( $last_update = 30, $total_posts_less_than = 5, $blogCategoryId = ALL_BLOG_CATEGORIES, $searchTerms = "" )
+        {	
+			$where = "";
+            $this->_startTime = $this->getStartTime( $last_update );			
+            $lastUpdateCond = "last_update_date < ".$this->_startTime;
+			$totalPostLessThanCond = "num_posts < ".$total_posts_less_than;
+			$where = $lastUpdateCond." AND ".$totalPostLessThanCond;
+
+			if( $blogCategoryId != ALL_BLOG_CATEGORIES )
+				$where .= " AND blog_category_id = '".Db::qstr($blogCategoryId)."'";				
+										
+			if( $searchTerms != "" ) {				
+				$searchCond = $this->getSearchConditions( $searchTerms );
+                if( $where != "" )
+                    $where .= " AND";
+ 				$where .= " ".$searchCond;
+            }
+			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 ) 
+		{
+			lt_include( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
+
+            $time = new Timestamp();
+            $time->subtractSeconds( $duration * 24 * 60 * 60 );
+			$startTime = $time->getYear().$time->getMonth();
+			if( $time->getDay() < 10 )
+				$startTime .= "0";
+			$startTime .= $time->getDay();
+			$startTime .= "000000";
+			return $startTime;
+		}
+		
+    }
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/clean/class/view/admincleandeleteblogaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/view/admincleandeleteblogaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/clean/class/view/admincleandeleteblogaction.class.php	2009-02-13 17:31:23 UTC (rev 6791)
@@ -0,0 +1,104 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+    lt_include( PLOG_CLASS_PATH."plugins/clean/class/view/admincleanview.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+	 * it does not delete blogs from the system but simply set them to disabled
+	 */
+	class AdminCleanDeleteBlogAction extends AdminAction
+	{
+		var $_op;
+		var $_blogIds;
+
+    	function AdminCleanDeleteBlogAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+
+			// set up the data validation stuff
+        	$this->_op = $actionInfo->getActionParamValue();
+        	if( $this->_op == "deleteBlogs" )
+        		$this->registerFieldvalidator( "blogIds", new ArrayValidator( new IntegerValidator()));
+        	else
+        		$this->registerFieldValidator( "blogId", new IntegerValidator());
+        	$view = new AdminCleanView( $this->_blogInfo );
+        	$view->setErrorMessage( $this->_locale->tr("error_no_blogs_selected"));
+        	$this->setValidationErrorView( $view );
+
+			$this->requireAdminPermission( "update_site_blog" );
+        }
+
+        function perform()
+        {
+        	if( $this->_op == "deleteBlog" ) {
+        		$this->_blogIds = Array();
+        		$blogId = $this->_request->getValue( "blogId" );
+        		$this->_blogIds[] = $blogId;
+        	}
+        	else
+        		$this->_blogIds = $this->_request->getValue( "blogIds" );
+
+        	$this->_disableBlogs();
+        }
+        
+//        function disableBlog( $blogIn
+
+		/**
+		 * @private
+		 */
+        function _disableBlogs()
+        {
+        	// get the default blog id
+        	$config =& Config::getConfig();
+            $defaultBlogId = $config->getValue( "default_blog_id" );
+
+        	$errorMessage = "";
+        	$successMessage = "";
+        	$totalOk = 0;
+
+            $blogs = new Blogs();
+        	foreach( $this->_blogIds as $blogId ) {
+            	// get some info about the blog before deleting it
+                $blogInfo = $blogs->getBlogInfo( $blogId );
+				if( !$blogInfo ) {
+					$errorMessage .= $this->_locale->pr("error_deleting_blog2", $blogId)."<br/>";
+				}
+				else {
+					$this->notifyEvent( EVENT_PRE_BLOG_DELETE, Array( "blog" => &$blogInfo ));
+					// make sure we're not deleting the default one!
+					if( $defaultBlogId == $blogId ) {
+						$errorMessage .= $this->_locale->pr("error_blog_is_default_blog", $blogInfo->getBlog())."<br />";
+					}
+					else {
+					   // disable the blog
+					    $blogInfo->setStatus( BLOG_STATUS_DISABLED );
+						if( $blogs->updateBlog( $blogInfo )) {
+							$totalOk++;						
+							if( $totalOk < 2 )
+								$successMessage = $this->_locale->pr("blog_deleted_ok", $blogInfo->getBlog());
+							else
+								$successMessage = $this->_locale->pr( "blogs_deleted_ok", $totalOk );
+							
+							$this->notifyEvent( EVENT_POST_BLOG_DELETE, Array( "blog" => &$blogInfo ));
+						}
+						else
+							$errorMessage .= $this->_locale->pr("error_deleting_blog", $blogInfo->getBlog())."<br/>";
+					}
+				}
+			}
+
+            $this->_view = new AdminCleanView( $this->_blogInfo );
+            if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
+            if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage );
+            $this->setCommonData();
+
+            return true;
+        }
+    }
+?>

Added: plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php	2009-02-13 17:31:23 UTC (rev 6791)
@@ -0,0 +1,94 @@
+<?php
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
+	lt_include( PLOG_CLASS_PATH."plugins/clean/class/dao/unusedblogs.class.php" );
+		
+    /**
+     * \ingroup View
+     * @private
+     *
+	 * shows a list with all the blogs from the site
+	 */
+	class AdminCleanView extends AdminPluginTemplatedView
+	{
+		var $_page;
+		var $_last_update;
+		var $_total_posts_less_than;		
+		var $_searchTerms;
+		var $_pagerUrl;
+		function AdminCleanView( $blogInfo )
+		{
+			$this->_pagerUrl = "?op=clean";
+			if( $this->_templateName == "" )
+				$this->_templateName = "cleanblogs";
+			$this->AdminPluginTemplatedView( $blogInfo, "clean", $this->_templateName );
+			
+			$this->_page = $this->getCurrentPageFromRequest();
+		}
+		
+		/**
+		 * retrieves the current status from the request
+		 *
+		 * @private
+		 * @return nothing
+		 */
+		function getLastUpdateFromRequest()
+		{
+			$last_update = HttpVars::getRequestValue( "last_update" );
+			
+			// validate the value 
+			$val = new IntegerValidator();
+			if( !$val->validate( $last_update ))
+				$last_update = 30;
+				
+			return $last_update;
+		}
+		
+		function getTotalPostLessThanFromRequest()
+		{
+			$total_posts_less_than = HttpVars::getRequestValue( "total_posts_less_than" );
+			
+			// validate the value 
+			$val = new IntegerValidator();
+			if( !$val->validate( $total_posts_less_than ))
+				$total_posts_less_than = 5;
+				
+			return $total_posts_less_than;
+		}
+		
+		function render()
+		{			
+            // we need to get all the blogs
+			// get the data itself
+			$this->_last_update = $this->getLastUpdateFromRequest();
+			$this->_total_posts_less_than = $this->getTotalPostLessThanFromRequest();
+			$this->_searchTerms = HttpVars::getRequestValue( "searchTerms" );
+			$blogs = new UnusedBlogs();
+            $siteBlogs = $blogs->getAllBlogs( $this->_last_update, $this->_total_posts_less_than, ALL_BLOG_CATEGORIES, $this->_searchTerms, $this->_page, DEFAULT_ITEMS_PER_PAGE );
+#			print("search terms = ".$this->_searchTerms);
+			$numBlogs = $blogs->getNumBlogs( $this->_last_update, $this->_total_posts_less_than, ALL_BLOG_CATEGORIES, $this->_searchTerms );
+            if( !$siteBlogs ) {
+            	$siteBlogs = Array();
+            }
+            
+            // throw the right event
+			$this->notifyEvent( EVENT_BLOGS_LOADED, Array( "blogs" => &$siteBlogs ));            
+            
+			// calculate the links to the different pages
+			$pager = new Pager( $this->_pagerUrl."&amp;searchTerms=".$this->_searchTerms."&amp;last_update=".$this->_last_update."&amp;total_posts_less_than=".$this->_total_posts_less_than."&amp;page=",
+			                    $this->_page, 
+								$numBlogs, 
+								DEFAULT_ITEMS_PER_PAGE );
+
+			$this->setValue( "siteblogs", $siteBlogs );
+			$this->setValue( "pager", $pager );
+			$this->setValue( "currentstatus", $this->_last_update );
+			$this->setValue( "blogstatus", BlogStatus::getStatusList( true ));
+			$this->setValue( "searchTerms", $this->_searchTerms );
+			$this->setValue( "total_posts_less_than", $this->_total_posts_less_than );
+		
+			// let the parent view do its job
+			parent::render();                        
+		}	
+	}
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/clean/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/locale/locale_en_UK.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/clean/locale/locale_en_UK.php	2009-02-13 17:31:23 UTC (rev 6791)
@@ -0,0 +1,12 @@
+<?php
+$messages["forex"] = "Forex";
+$messages["Forex"] = "Forex";
+$messages["forex_plugin_enabled"] = "enabled";
+$messages["forex_plugin"] = "Forex";
+$messages["label_configuration"] = "Configuration";
+$messages["label_enable"] = "Enable";
+$messages["forex_settings_saved_ok"] = "Save Succeed!";
+$messages["error_updating_settings"] = "Update Fail!";
+$messages["total_posts_less_than"] = "Total posts less than";
+
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/clean/locale/locale_vn_VN.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/locale/locale_vn_VN.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/clean/locale/locale_vn_VN.php	2009-02-13 17:31:23 UTC (rev 6791)
@@ -0,0 +1,12 @@
+<?php
+$messages["Clean"] = "Dọn dẹp blogs";
+$messages["clean"] = "Dọn dẹp blogs";
+$messages["never_update"] = "Không cập nhật trong vòng";
+$messages["last_update"] = "Lần cập nhật cuối";
+$messages["week"] = "1 tuần";
+$messages["month"] = "1 tháng";
+$messages["quarter"] = "1 quý";
+$messages["year"] = "1 năm";
+$messages["2year"] = "2 năm";
+$messages["total_posts_less_than"] = "Tổng số bài viết ít hơn";
+?>
\ No newline at end of file

Added: plugins/branches/lifetype-1.2/clean/pluginclean.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/pluginclean.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/clean/pluginclean.class.php	2009-02-13 17:31:23 UTC (rev 6791)
@@ -0,0 +1,39 @@
+<?php
+# Clean unused blogs
+# By: Mai Minh
+    lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/Date.class.php" );
+
+    class PluginClean extends PluginBase
+    {
+        function PluginClean($source = "")
+        {
+			$this->PluginBase($source);
+			
+            $this->id = "clean";
+            $this->author = "Mai Minh";
+            $this->desc = "This plugin cleans unused blogs.";
+  
+            $this->locales = Array( "en_UK" , "zh_TW" );
+            
+            if ($source == "admin") $this->init();
+        }
+
+		function init()
+		{
+            $this->registerAdminAction( "clean", "AdminCleanAction" );
+			$this->registerAdminAction( "cleanDeleteBlog", "AdminCleanDeleteBlogAction" );
+			$this->registerAdminAction( "cleanDeleteBlogs", "AdminCleanDeleteBlogAction" );			
+			
+			$menu =& Menu::getMenu();
+			if( !$menu->entryExists( "/menu/adminSettings/Miscellaneous" ))						
+				$this->addMenuEntry( "/menu/adminSettings", "Miscellaneous", "", "", true, false );			
+            $this->addMenuEntry( "/menu/adminSettings/Miscellaneous", "Clean", "?op=clean", "clean", false, true);
+		}
+
+		function register()
+		{
+		    $blogSettings = $this->blogInfo->getSettings();
+   		}
+    }
+?>

Added: plugins/branches/lifetype-1.2/clean/templates/cleanblogs.template
===================================================================
--- plugins/branches/lifetype-1.2/clean/templates/cleanblogs.template	                        (rev 0)
+++ plugins/branches/lifetype-1.2/clean/templates/cleanblogs.template	2009-02-13 17:31:23 UTC (rev 6791)
@@ -0,0 +1,155 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=Clean title=$locale->tr("Clean")}
+<script type="text/javascript" src="js/ui/plogui.js"></script>
+<script type="text/javascript">
+	var errorStatusMsg = '{$locale->tr("error_select_status")}';
+	var showMassiveChangeOption = '{$locale->tr("show_massive_change_option")}';
+	var hideMassiveChangeOption = '{$locale->tr("hide_massive_change_option")}';
+</script>
+        <div id="list_nav_bar">
+            <div id="list_nav_select">
+            
+<form id="viewBlogs" action="admin.php" method="post">
+ <fieldset>
+  <legend>{$locale->tr("show_by")}</legend>
+   <div class="list_nav_option">
+    <label for="last_update">{$locale->tr("never_update")}</label>
+	<br />
+    <select name="last_update" id="last_update">
+      <option value="7" {if $currentstatus == 7} selected="selected"{/if}>{$locale->tr("week")}</option>
+      <option value="30" {if $currentstatus == 30} selected="selected"{/if}>{$locale->tr("month")}</option>
+      <option value="90" {if $currentstatus == 90} selected="selected"{/if}>{$locale->tr("quarter")}</option>	  	  
+      <option value="365" {if $currentstatus == 365} selected="selected"{/if}>{$locale->tr("year")}</option>	  	  	  
+      <option value="730" {if $currentstatus == 730} selected="selected"{/if}>{$locale->tr("2year")}</option>	  	  	  	  
+    </select>
+   </div>
+
+   <div class="list_nav_option">
+    <label for="total_posts_less_than">{$locale->tr("total_posts_less_than")}</label>
+	<br />
+    <select name="total_posts_less_than" id="total_posts_less_than">
+      <option value="1" {if $total_posts_less_than == 1} selected="selected"{/if}>1</option>
+      <option value="5" {if $total_posts_less_than == 5} selected="selected"{/if}>5</option>
+      <option value="10" {if $total_posts_less_than == 10} selected="selected"{/if}>10</option>
+      <option value="20" {if $total_posts_less_than == 20} selected="selected"{/if}>20</option>
+      <option value="50" {if $total_posts_less_than == 50} selected="selected"{/if}>50</option>
+      <option value="100" {if $total_posts_less_than == 100} selected="selected"{/if}>100</option>
+    </select>
+   </div>
+   
+   <div class="list_nav_option">
+   <label for="search">{$locale->tr("search_terms")}</label>
+   <br />
+   <input type="text" name="searchTerms" value="{$searchTerms}" size="15" id="search" />
+   </div>   
+   
+   <div class="list_nav_option">
+    <br />
+    <input type="hidden" name="op" value="clean" />
+    <input type="submit" name="Show" value="{$locale->tr("show")}" />
+   </div>
+  </fieldset> 
+ </form> 
+ </div>
+ <br style="clear:both" />
+ </div> 
+ 
+ <form id="editBlogs" method="post" action="admin.php">
+{check_perms adminperm=update_site_blog}	
+     <div class="optionIcon">
+		<a id="optionIconLink" href="#bulkEdit" title="{$locale->tr("show_massive_change_option")}" onclick="switchMassiveOption()">{$locale->tr("show_massive_change_option")}</a>
+	</div>
+{/check_perms}	
+  <div id="list"> 
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}
+   <table id="list" class="info" summary="{$locale->tr("editSiteBlogs")}">
+    <thead>
+     <tr>
+      <th><input class="checkbox" type="checkbox" name="all" id="all" value="1" onclick="toggleAllChecks('editBlogs');" /></th>
+      <th style="width:35%;">{$locale->tr("blog")}</th>
+      <th style="width:25%">{$locale->tr("owner")}</th>
+      <th style="width:15%;">{$locale->tr("status")}</th>
+	  <th style="width:10%;">{$locale->tr("last_update")}</th> 
+      <th style="width:25%;">{$locale->tr("actions")}</th>
+     </tr>
+    </thead>
+    <tbody>
+     {foreach from=$siteblogs item=siteblog}
+      <tr>
+       <td><input class="checkbox" type="checkbox" name="blogIds[{counter}]" value="{$siteblog->getId()}"/></td>
+       <td class="col_highlighted">
+        {check_perms adminperm=update_site_blog}<a href="?op=editBlog&amp;blogId={$siteblog->getId()}">{/check_perms}{$siteblog->getBlog()}{check_perms adminperm=update_site_blog}</a>{/check_perms}
+       </td>
+       <td>
+	    {assign var=ownerInfo value=$siteblog->getOwnerInfo()}
+	    <a href="?op=editSiteUser&amp;userId={$ownerInfo->getId()}">{$ownerInfo->getUsername()}</a>
+	   </td>
+       <td>
+        {foreach from=$blogstatus key=name item=status}
+          {if $siteblog->getStatus() == $status}
+          {if $status == 2}<span style="color:red">{$locale->tr($name)}</span>
+		  {else}{$locale->tr($name)}{/if}
+		  {/if}
+        {/foreach}        
+       </td>       
+	   <td>
+		{$siteblog->getUpdateDate()}
+	   </td>
+       <td>
+        <div class="list_action_button">
+	     {check_perms adminperm=update_site_blog}
+         <a href="?op=cleanDeleteBlog&amp;blogId={$siteblog->getId()}" title="{$locale->tr("delete")}">
+	       <img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete")}" />
+	     </a>
+         <a href="?op=editBlog&amp;blogId={$siteblog->getId()}" title="{$locale->tr("edit")}">
+	       <img src="imgs/admin/icon_edit-16.png" alt="{$locale->tr("edit")}" />
+	     </a>
+		 {assign var=blogUrl value=$siteblog->getBlogRequestGenerator()}
+       	 {assign var=blogname value=$siteblog->getBlog()}
+		 <a href="{$blogUrl->blogLink()}" title="{$locale->pr("goto_blog_page",$blogname)}">
+		   <img src="imgs/admin/icon_goto-16.png" alt="{$locale->pr("goto_blog_page",$blogname)}" />
+		 </a>
+		 {if $siteblog->getStatus() == 3}
+         <a href="?op=resendConfirmation&amp;blogId={$siteblog->getId()}" title="{$locale->tr("resend_confirmation_blog")}">
+	       <img src="imgs/admin/icon_mail-16.png" alt="{$locale->tr("resend_confirmation_blog")}" />
+	     </a>
+		 {/if}
+		 {/check_perms}
+		 {check_perms adminperm=edit_blog_admin_mode}
+		 <a href="?op=adminBlogSelect&amp;blogId={$siteblog->getId()}&amp;action=controlCenter" title="{$locale->tr("administrate_user_blog")}">
+		   <img src="imgs/admin/icon_lock_open-16.png" alt="{$locale->tr("administrate_user_blog")}" />
+		 </a>
+		 {/check_perms}
+        </div>
+      </tr>
+     {/foreach}
+    </tbody> 
+   </table>
+  </div>
+ <a name="bulkEdit"></a>
+  <div id="list_action_bar">
+	{adminpager style="list"}
+	{check_perms adminperm=update_site_blog}
+    <input type="hidden" name="op" value="cleanDeleteBlogs"/>
+    <input type="submit" name="{$locale->tr("delete")}" value="{$locale->tr("delete")}"/>  
+    {/check_perms}
+	{check_perms adminperm=update_site_blog}
+    <div id="massiveChangeOption" style="display: none">
+        <fieldset>	
+        <legend>{$locale->tr("massive_change_option")}</legend>            
+            <label for="blogStatus">{$locale->tr("status")}</label>
+            <select name="blogStatus" id="blogStatus">
+              <option value="-1">-{$locale->tr("select")}-</option>
+		    	{foreach from=$blogstatus key=name item=status}
+		      		{if $status != -1}<option value="{$status}">{$locale->tr($name)}</option>{/if}
+		    	{/foreach}	
+            </select>
+            <input type="button" name="changeBlogStatus" value="{$locale->tr("change_status")}" class="submit" onClick="javascript:submitBlogsList('changeBlogStatus');" /> 
+        </fieldset>
+	</div>
+	{/check_perms}
+  </div> 
+ </form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file



More information about the pLog-svn mailing list