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

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Fri Feb 13 13:59:30 EST 2009


Author: jondaley
Date: 2009-02-13 13:59:30 -0500 (Fri, 13 Feb 2009)
New Revision: 6793

Removed:
   plugins/branches/lifetype-1.2/clean/class/view/admincleandeleteblogaction.class.php
Modified:
   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/view/admincleanview.class.php
   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/cleanblogs.template
Log:
not the cleanest plugin.  Fixed some security issues, simplified the code, and added the english locale.

Modified: plugins/branches/lifetype-1.2/clean/class/action/admincleanaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/action/admincleanaction.class.php	2009-02-13 18:28:17 UTC (rev 6792)
+++ plugins/branches/lifetype-1.2/clean/class/action/admincleanaction.class.php	2009-02-13 18:59:30 UTC (rev 6793)
@@ -1,7 +1,8 @@
 <?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" );	
+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."class/data/validator/stringvalidator.class.php" );
+lt_include( PLOG_CLASS_PATH."plugins/clean/class/view/admincleanview.class.php" );	
 
 	/**
 	 * shows a form with the current configuration
@@ -12,11 +13,28 @@
         {
         	$this->AdminAction( $actionInfo, $request );
 			$this->requireAdminPermission( "view_site_blogs" );
+
+            $this->registerFieldValidator( "last_update", new IntegerValidator(), true);
+            $this->registerFieldValidator( "total_posts_less_then", new IntegerValidator(), true);
+			$this->registerFieldValidator( "searchTerms", new StringValidator(), true );
+
+            $view = new AdminCleanView( $this->_blogInfo );
+            $view->setErrorMessage( $this->_locale->tr("clean_error_invalid_filter_terms" ));
+            $this->setValidationErrorView( $view );
+            
         }
         
         function perform()
         {
-	        $this->_view = new AdminCleanView( $this->_blogInfo );
+            $last_update = $this->_request->getValue( "last_update" );
+            $total_posts_less_than = $this->_request->getValue( "total_posts_less_than" );
+            $search_terms = $this->_request->getValue( "searchTerms" );
+            
+	        $this->_view = new AdminCleanView( $this->_blogInfo,
+                                               Array( "last_update" => $last_update,
+                                                      "total_posts_less_than" => $total_posts_less_than,
+                                                      "search_terms" => $search_terms)
+                                               );
 	        $this->setCommonData();	        
             return true;
         }

Modified: plugins/branches/lifetype-1.2/clean/class/action/admincleandeleteblogaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/action/admincleandeleteblogaction.class.php	2009-02-13 18:28:17 UTC (rev 6792)
+++ plugins/branches/lifetype-1.2/clean/class/action/admincleandeleteblogaction.class.php	2009-02-13 18:59:30 UTC (rev 6793)
@@ -38,8 +38,7 @@
         {
         	if( $this->_op == "cleanDeleteBlog" ) {
         		$this->_blogIds = Array();
-        		$blogId = $this->_request->getValue( "blogId" );
-        		$this->_blogIds[] = $blogId;
+        		$this->_blogIds[] = $this->_request->getValue( "blogId" );
         	}
         	else
         		$this->_blogIds = $this->_request->getValue( "blogIds" );
@@ -47,8 +46,6 @@
         	$this->_disableBlogs();
         }
         
-//        function disableBlog( $blogIn
-
 		/**
 		 * @private
 		 */
@@ -68,31 +65,36 @@
                 $blogInfo = $blogs->getBlogInfo( $blogId );
 				if( !$blogInfo ) {
 					$errorMessage .= $this->_locale->pr("error_deleting_blog2", $blogId)."<br/>";
+                    continue;
 				}
-				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/>";
-					}
-				}
+                if( $defaultBlogId == $blogId ) {
+                    $errorMessage .= $this->_locale->pr("error_blog_is_default_blog",
+                                                        $blogInfo->getBlog())."<br />";
+                    continue;
+                }
+
+                $this->notifyEvent( EVENT_PRE_BLOG_DELETE, Array( "blog" => &$blogInfo ));
+
+                    // disable the blog
+                $blogInfo->setStatus( BLOG_STATUS_DISABLED );
+                if(!$blogs->updateBlog($blogInfo)){
+                    $errorMessage .= $this->_locale->pr("error_deleting_blog",
+                                                        $blogInfo->getBlog())."<br/>";
+                    continue;
+                }
+
+                $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 ));
 			}
 
+
             $this->_view = new AdminCleanView( $this->_blogInfo );
             if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
             if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage );

Deleted: plugins/branches/lifetype-1.2/clean/class/view/admincleandeleteblogaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/view/admincleandeleteblogaction.class.php	2009-02-13 18:28:17 UTC (rev 6792)
+++ plugins/branches/lifetype-1.2/clean/class/view/admincleandeleteblogaction.class.php	2009-02-13 18:59:30 UTC (rev 6793)
@@ -1,104 +0,0 @@
-<?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;
-        }
-    }
-?>

Modified: plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php	2009-02-13 18:28:17 UTC (rev 6792)
+++ plugins/branches/lifetype-1.2/clean/class/view/admincleanview.class.php	2009-02-13 18:59:30 UTC (rev 6793)
@@ -11,71 +11,55 @@
 	 */
 	class AdminCleanView extends AdminPluginTemplatedView
 	{
+        const LAST_UPDATE_DEFAULT = 30;
+        const TOTAL_POSTS_LESS_THAN_DEFAULT = 5;
+        const SEARCH_TERMS_DEFAULT = "";
+        
 		var $_page;
-		var $_last_update;
-		var $_total_posts_less_than;		
-		var $_searchTerms;
+		var $_last_update = self::LAST_UPDATE_DEFAULT;
+		var $_total_posts_less_than = self::TOTAL_POSTS_LESS_THAN_DEFAULT;
+		var $_search_terms = self::SEARCH_TERMS_DEFAULT;
 		var $_pagerUrl;
-		function AdminCleanView( $blogInfo )
+		function AdminCleanView( $blogInfo, $params = Array() )
 		{
-			$this->_pagerUrl = "?op=clean";
-			if( $this->_templateName == "" )
-				$this->_templateName = "cleanblogs";
-			$this->AdminPluginTemplatedView( $blogInfo, "clean", $this->_templateName );
-			
+			$this->AdminPluginTemplatedView( $blogInfo, "clean", "cleanblogs" );
+			$this->_pagerUrl = "?op=cleanUnusedBlogs";
 			$this->_page = $this->getCurrentPageFromRequest();
+
+            if(!empty($params["search_terms"]))
+                $this->_search_terms = $params["search_terms"];
+            if(!empty($params["last_update"]))
+                $this->_last_update = $params["last_update"];
+            if(!empty($params["total_posts_less_than"]))
+                $this->_total_posts_less_than = $params["total_posts_less_than"];
 		}
 		
-		/**
-		 * 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 );
+            $siteBlogs = $blogs->getAllBlogs( $this->_last_update,
+                                              $this->_total_posts_less_than,
+                                              ALL_BLOG_CATEGORIES,
+                                              $this->_search_terms,
+                                              $this->_page,
+                                              DEFAULT_ITEMS_PER_PAGE );
             if( !$siteBlogs ) {
             	$siteBlogs = Array();
             }
+
+#			print("search terms = ".$this->_search_terms);
+
+			$numBlogs = $blogs->getNumBlogs( $this->_last_update,
+                                             $this->_total_posts_less_than,
+                                             ALL_BLOG_CATEGORIES,
+                                             $this->_search_terms );
             
             // 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=",
+			$pager = new Pager( $this->_pagerUrl."&amp;searchTerms=".$this->_search_terms."&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 );
@@ -84,9 +68,9 @@
 			$this->setValue( "pager", $pager );
 			$this->setValue( "currentstatus", $this->_last_update );
 			$this->setValue( "blogstatus", BlogStatus::getStatusList( true ));
-			$this->setValue( "searchTerms", $this->_searchTerms );
+			$this->setValue( "searchTerms", $this->_search_terms );
 			$this->setValue( "total_posts_less_than", $this->_total_posts_less_than );
-		
+ 
 			// let the parent view do its job
 			parent::render();                        
 		}	

Modified: plugins/branches/lifetype-1.2/clean/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/locale/locale_en_UK.php	2009-02-13 18:28:17 UTC (rev 6792)
+++ plugins/branches/lifetype-1.2/clean/locale/locale_en_UK.php	2009-02-13 18:59:30 UTC (rev 6793)
@@ -1,12 +1,16 @@
 <?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["clean_unused_blogs"] = "Clean Unused Blogs";
+$messages["week"] = "1 week";
+$messages["month"] = "1 month";
+$messages["quarter"] = "3 months";
+$messages["year"] = "1 year";
+$messages["2year"] = "2 years";
+
+$messages["never_update"] = "Not updated in";
+$messages["last_update"] = "Last update";
 $messages["total_posts_less_than"] = "Total posts less than";
 
+$messages["clean_error_invalid_filter_terms"] = "Invalid filter terms (not updated, total posts less than, etc.) given.";
+
+
 ?>
\ No newline at end of file

Modified: plugins/branches/lifetype-1.2/clean/locale/locale_vn_VN.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/locale/locale_vn_VN.php	2009-02-13 18:28:17 UTC (rev 6792)
+++ plugins/branches/lifetype-1.2/clean/locale/locale_vn_VN.php	2009-02-13 18:59:30 UTC (rev 6793)
@@ -1,6 +1,6 @@
 <?php
-$messages["Clean"] = "Dọn dẹp blogs";
-$messages["clean"] = "Dọn dẹp blogs";
+$messages["clean_unused_blogs"] = "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";
@@ -9,4 +9,7 @@
 $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";
+
+$messages["clean_error_invalid_filter_terms"] = "Invalid filter terms (not updated, total posts less than, etc.) given.";
+
 ?>
\ No newline at end of file

Modified: plugins/branches/lifetype-1.2/clean/pluginclean.class.php
===================================================================
--- plugins/branches/lifetype-1.2/clean/pluginclean.class.php	2009-02-13 18:28:17 UTC (rev 6792)
+++ plugins/branches/lifetype-1.2/clean/pluginclean.class.php	2009-02-13 18:59:30 UTC (rev 6793)
@@ -1,8 +1,5 @@
 <?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
     {
@@ -13,27 +10,26 @@
             $this->id = "clean";
             $this->author = "Mai Minh";
             $this->desc = "This plugin cleans unused blogs.";
+            $this->version = "20090213";
   
             $this->locales = Array( "en_UK" , "zh_TW" );
             
-            if ($source == "admin") $this->init();
+            if ($source == "admin")
+                $this->init();
         }
 
 		function init()
 		{
-            $this->registerAdminAction( "clean", "AdminCleanAction" );
+            $this->registerAdminAction( "cleanUnusedBlogs", "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);
+            $this->addMenuEntry( "/menu/adminSettings/Miscellaneous", "clean_unused_blogs",
+                                 "?op=cleanUnusedBlogs",
+                                 "",
+                                 Array("update_site_blog", "view_site_blog"),
+                                 Array("update_site_blog", "view_site_blog"),
+                                 true);  // TODO: can this be false due to above permissions?
 		}
-
-		function register()
-		{
-		    $blogSettings = $this->blogInfo->getSettings();
-   		}
     }
 ?>

Modified: plugins/branches/lifetype-1.2/clean/templates/cleanblogs.template
===================================================================
--- plugins/branches/lifetype-1.2/clean/templates/cleanblogs.template	2009-02-13 18:28:17 UTC (rev 6792)
+++ plugins/branches/lifetype-1.2/clean/templates/cleanblogs.template	2009-02-13 18:59:30 UTC (rev 6793)
@@ -45,7 +45,7 @@
    
    <div class="list_nav_option">
     <br />
-    <input type="hidden" name="op" value="clean" />
+    <input type="hidden" name="op" value="cleanUnusedBlogs" />
     <input type="submit" name="Show" value="{$locale->tr("show")}" />
    </div>
   </fieldset> 
@@ -152,4 +152,4 @@
   </div> 
  </form>
 {include file="$admintemplatepath/footernavigation.template"}
-{include file="$admintemplatepath/footer.template"}
\ No newline at end of file
+{include file="$admintemplatepath/footer.template"}



More information about the pLog-svn mailing list