[pLog-svn] r6642 - plog/branches/lifetype-1.2/class/summary/action

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Sat Jun 21 16:47:25 EDT 2008


Author: jondaley
Date: 2008-06-21 16:47:25 -0400 (Sat, 21 Jun 2008)
New Revision: 6642

Modified:
   plog/branches/lifetype-1.2/class/summary/action/summaryrssaction.class.php
Log:
moved all validation to the beginning, making things clearer, as well as sharing some code

Modified: plog/branches/lifetype-1.2/class/summary/action/summaryrssaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/summary/action/summaryrssaction.class.php	2008-06-21 20:46:52 UTC (rev 6641)
+++ plog/branches/lifetype-1.2/class/summary/action/summaryrssaction.class.php	2008-06-21 20:47:25 UTC (rev 6642)
@@ -7,6 +7,7 @@
 	lt_include( PLOG_CLASS_PATH."class/summary/view/summaryrssview.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/net/rawrequestgenerator.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
 	
 	define( "SUMMARY_RSS_TYPE_DEFAULT", "default" );
 	define( "SUMMARY_RSS_TYPE_MOST_COMMENTED", "mostcommented" );
@@ -24,7 +25,11 @@
       */
      class SummaryRssAction extends SummaryAction
      {
-
+         var _mode;
+         var _profile;
+         var _globalArticleCategoryId;
+         var _blogCategoryId;
+         
         function SummaryRssAction( $actionInfo, $request )
         {
             $this->SummaryAction( $actionInfo, $request );
@@ -45,8 +50,39 @@
 				// in case the parameter looks weird, let's use a default one...
 				$this->_mode = SUMMARY_RSS_TYPE_DEFAULT;
 			}
-			
+
 			$this->_profile = $this->_request->getValue( "profile" );
+            $profileValidator = new StringValidator();
+            $profileValidator->addRule( new RegexpRule( "^([a-zA-Z0-9]*)$" ));
+            if(!$profileValidator->validate($this->_profile)){
+                $this->_profile = "";
+            }
+
+            $val = new IntegerValidator();
+
+            $this->_globalArticleCategoryId = $this->_request->getValue("globalArticleCategoryId");
+            if(!$val->validate( $this->_globalArticleCategoryId)){
+                $this->_globalArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES;
+            }
+            else{
+                    // id is an integer, now lets see it is a valid category id
+                lt_include( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" );
+                $categories = new GlobalArticleCategories();
+                if(!$categories->getGlobalArticleCategory( $this->_globalArticleCategoryId ))
+                    $this->_globalArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES;
+            }
+            
+            
+            $this->_blogCategoryId = $this->_request->getValue("blogCategoryId");
+            if(!$val->validate($this->_blogCategoryId)){
+                $this->_blogCategoryId = ALL_BLOG_CATEGORIES;
+            }
+            else{
+                lt_include( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
+                $categories = new BlogCategories();
+                if(!$categories->getBlogCategory( $this->_blogCategoryId ))
+                    $this->_blogCategoryId = ALL_BLOG_CATEGORIES;
+            }
 			
 			return true;
 		}
@@ -59,17 +95,12 @@
             if( $this->_mode == SUMMARY_RSS_TYPE_MOST_COMMENTED ||
                 $this->_mode == SUMMARY_RSS_TYPE_MOST_READ ||
                 $this->_mode == SUMMARY_RSS_TYPE_DEFAULT ||
-                $this->_mode == SUMMARY_RSS_TYPE_POSTS_LIST ) {	                
+                $this->_mode == SUMMARY_RSS_TYPE_POSTS_LIST )
+            {
 	                
-            	// get the globalArticleCategoryId from request
-				$globalArticleCategoryId = $this->_request->getValue( "globalArticleCategoryId" );
-				$val = new IntegerValidator();
-				if( !$val->validate( $globalArticleCategoryId ))
-					$globalArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES;
-				    			
 	            // RSS feeds for posts stuff
 	            $this->_view = new SummaryRssView( $this->_profile, Array( "summary" => "rss", 
-			                                       "globalArticleCategoryId" => $globalArticleCategoryId,
+			                                       "globalArticleCategoryId" => $this->_globalArticleCategoryId,
 			                                       "mode" => $this->_mode,
 												   "profile" => $this->_profile ));
 				if( $this->_view->isCached()) {
@@ -87,32 +118,18 @@
 					$postslist = $stats->getMostReadArticles();			
 				}
 				elseif( $this->_mode == SUMMARY_RSS_TYPE_POSTS_LIST ) {
-     				lt_include( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" );
             		lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
             		
             		// get the summary_items_per_page from config
             		$config =& Config::getConfig();
             		$summaryItemsPerPage = $config->getValue( "summary_items_per_page", SUMMARY_DEFAULT_ITEMS_PER_PAGE );
 					
-					$categories = new GlobalArticleCategories();
-					$currentGlobalArticleCategory = $categories->getGlobalArticleCategory( $globalArticleCategoryId );
-					
-					if( empty($currentGlobalArticleCategory) )
-						$globalArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES;
-						
-					$postslist = $stats->getPostsByGlobalCategory( $globalArticleCategoryId,
+					$postslist = $stats->getPostsByGlobalCategory( $this->_globalArticleCategoryId,
         										 					 $page = 1, 
         										 					 $summaryItemsPerPage );
 				}				
 				else {
-					lt_include( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" );
-					$categories = new GlobalArticleCategories();
-					$currentGlobalArticleCategory = $categories->getGlobalArticleCategory( $globalArticleCategoryId );
-					
-					if( empty($currentGlobalArticleCategory) )
-						$globalArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES;
-					
-					$postslist = $stats->getRecentArticles( $globalArticleCategoryId );
+					$postslist = $stats->getRecentArticles( $this->_globalArticleCategoryId );
 				}
 	
 	            if( !$postslist ) {
@@ -125,15 +142,9 @@
 			        $this->_mode == SUMMARY_RSS_TYPE_NEWEST_BLOGS ||
 			        $this->_mode == SUMMARY_RSS_TYPE_BLOGS_LIST ) {
 				
-            	// get the globalArticleCategoryId from request
-				$blogCategoryId = $this->_request->getValue( "blogCategoryId" );
-				$val = new IntegerValidator();
-				if( !$val->validate( $blogCategoryId ))
-					$blogCategoryId = ALL_BLOG_CATEGORIES;
-
 				// RSS feeds for blogs, need different template sets...
 	            $this->_view = new SummaryRssView( "blogs_".$this->_profile, Array( "summary" => "rss",
-	            								   "blogCategoryId" => $blogCategoryId, 
+	            								   "blogCategoryId" => $this->_blogCategoryId, 
 			                                       "mode" => $this->_mode,
 												   "profile" => $this->_profile ));
 				if( $this->_view->isCached()) {
@@ -149,21 +160,14 @@
 					$blogslist = $stats->getMostActiveBlogs();	
 				}
 				elseif( $this->_mode == SUMMARY_RSS_TYPE_BLOGS_LIST ) {
-     				lt_include( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
             		lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
             		
             		// get the summary_items_per_page from config
             		$config =& Config::getConfig();
             		$summaryItemsPerPage = $config->getValue( "summary_items_per_page", SUMMARY_DEFAULT_ITEMS_PER_PAGE );
-					
-					$categories = new BlogCategories();
-					$currentBlogCategory = $categories->getBlogCategory( $blogCategoryId );
-					
-					if( empty($currentBlogCategory) )
-						$blogCategoryId = ALL_BLOG_CATEGORIES;
-						
-					$blogslist = $blogs->getAllBlogs( BLOG_STATUS_ACTIVE, 
-													  $blogCategoryId, 
+
+                    $blogslist = $blogs->getAllBlogs( BLOG_STATUS_ACTIVE, 
+													  $this->_blogCategoryId, 
 													  "", 
 													  1, 
 													  $summaryItemsPerPage );



More information about the pLog-svn mailing list