[pLog-svn] r2517 - in plog/trunk: class/action class/net class/template/templatesets class/view templates/misc templates/standard

oscar at devel.plogworld.net oscar at devel.plogworld.net
Fri Sep 23 21:47:24 GMT 2005


Author: oscar
Date: 2005-09-23 21:47:23 +0000 (Fri, 23 Sep 2005)
New Revision: 2517

Added:
   plog/trunk/templates/misc/pager.template
Modified:
   plog/trunk/class/action/blogaction.class.php
   plog/trunk/class/action/defaultaction.class.php
   plog/trunk/class/net/baserequestgenerator.class.php
   plog/trunk/class/net/rawrequestgenerator.class.php
   plog/trunk/class/template/templatesets/templatesetstorage.class.php
   plog/trunk/class/view/blogview.class.php
   plog/trunk/class/view/plugintemplatedview.class.php
   plog/trunk/templates/standard/footer.template
Log:
Added basic support for paging in the public side of a blog. Currently is always enabled by default and it only works with the 'standard' template set and with plain urls enabled. 

The presentation code for the pager is pure smarty code, like it was done for the admin interface in templates/admin/pager.template. The template used by the pager is stored under templates/misc/ . There are other alternatives to implement the pager, such as using a smarty method (instead of including the file:

{include file=".../pager.template" style="..."}

In my opinion the advantage of using smarty for the code is that users willing to create a new pager can include it in their own templates, while if we were using php code behind a smarty function, this would not be possible. If you have any other idea regarding the pager, please feel free so share it with us :-)

Modified: plog/trunk/class/action/blogaction.class.php
===================================================================
--- plog/trunk/class/action/blogaction.class.php	2005-09-22 06:06:22 UTC (rev 2516)
+++ plog/trunk/class/action/blogaction.class.php	2005-09-23 21:47:23 UTC (rev 2517)
@@ -283,7 +283,7 @@
 				// but first of all, validate it
 				$val = new IntegerValidator();
 				if( !$val->validate( $page ))
-					$page = 0;	
+					$page = 1;	
 
 				return $page;	    
 	    }		

Modified: plog/trunk/class/action/defaultaction.class.php
===================================================================
--- plog/trunk/class/action/defaultaction.class.php	2005-09-22 06:06:22 UTC (rev 2516)
+++ plog/trunk/class/action/defaultaction.class.php	2005-09-23 21:47:23 UTC (rev 2517)
@@ -30,7 +30,7 @@
             // value of the Date parameter from the request
             $this->_date = $this->_request->getValue( "Date", -1 );
 
-		$this->_categoryName = $this->_request->getValue( 'postCategoryName' );
+			$this->_categoryName = $this->_request->getValue( 'postCategoryName' );
             $this->_categoryId = $this->_request->getValue( 'postCategoryId' );
             if( $this->_categoryId == '' )
             	if( $this->_date == -1 )
@@ -113,7 +113,6 @@
             if( isset($category) )
                 $this->_view->setValue( "category", $category );			
 			
-
 			include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
             $users = new Users();
 
@@ -145,27 +144,6 @@
                 $this->_userId = $user->getId();
             }
 
-            // export the owner. The owner information should get from blogInfo directly
-            $this->_view->setValue( "owner", $this->_blogInfo->getOwnerInfo() );
-			
-            // amount of posts that we have to show, but keeping in mind that when browsing a
-            // category or specific date, we should show *all* of them
-            if( $this->_date > 0 || $this->_categoryId > 0 ) {
-                $this->_postAmount = -1;
-                // also, inform the template that we're showing them all!
-                $this->_view->setValue( 'showAll', true );
-            }
-            else {
-                $this->_postAmount = $blogSettings->getValue( 'show_posts_max' );
-                $this->_view->setValue( 'showAll', false );
-            }
-			
-            //
-            // :KLUDGE:
-            // the more things we add here to filter, the more complicated this function
-            // gets... look at this call and look at how many parameters it needs!! :(
-            //
-			
 			if( ($blogSettings->getValue( 'show_future_posts_in_calendar')) && ( $this->_date > -1 )) {
 				// if posts in the future are to be shown, we shouldn't set a maximum date
 				$todayTimestamp = 0;
@@ -176,6 +154,7 @@
        		}		
        		
        		// get the articles...
+            $this->_postAmount = $blogSettings->getValue( 'show_posts_max' );			
 			$blogArticles = $this->articles->getBlogArticles( 
 			                        $blogId, 
 			                        $this->_date,
@@ -188,12 +167,12 @@
 							        $this->_page );							        
 			// and the total number based on the conditions given
 			$numArticles = $this->articles->getNumBlogArticles( 
-			                        $blogId, 
+			                        $blogId,
 			                        $this->_date,
-							        $this->_postAmount, 
+							        -1,
 							        $this->_categoryId,
-							        POST_STATUS_PUBLISHED, 
-							        $this->_userId, 
+							        POST_STATUS_PUBLISHED,
+							        $this->_userId,
 							        $todayTimestamp );
 
             // if we couldn't fetch the articles, send an error and quit
@@ -203,13 +182,6 @@
                 $this->_view->setValue( 'message', 'error_fetching_articles' );
             }
             else {
-	            // otherwise, continue
-                // the view will take care of cutting the post if we have the "show more"
-                // feature enabled or not... we could do it here but I think that belongs
-                // to the view since it is presentation stuff... It could also be handled
-                // by the template but then it'd make the template a little bit more
-                // complicated...
-				
 				// ---
 				// before finishing, let's see if there's any plugin that would like to do 
 				// anything with the post that we just loaded
@@ -232,12 +204,15 @@
     	        $this->_view->setValue( 'posts', $articles );
     	        
     	        // build the pager and pass it to the view
-    	        
-    	        $pager = new Pager( "page=".$this->_page,    // url to the next page
+    	        $url = $this->_blogInfo->getBlogRequestGenerator();
+				$basePageUrl = $url->getCurrentUrl( $category,
+				                                    $user,
+				                                    $this->_date );
+				
+    	        $pager = new Pager( $basePageUrl,            // url to the next page
     	                            $this->_page,            // current page
     	                            $numArticles,            // total number of articles
-    	                            $this->_postAmount );
-    	        
+    	                            $this->_postAmount );    	        
     	        $this->_view->setValue( 'pager', $pager );
             }           
 

Modified: plog/trunk/class/net/baserequestgenerator.class.php
===================================================================
--- plog/trunk/class/net/baserequestgenerator.class.php	2005-09-22 06:06:22 UTC (rev 2516)
+++ plog/trunk/class/net/baserequestgenerator.class.php	2005-09-23 21:47:23 UTC (rev 2517)
@@ -635,6 +635,21 @@
 				$url .= "$filePath/$file";
 
 			return $url;
-		}		
+		}
+		
+		/**
+		 * given the parameters, recalculates the current URL. This method also has support
+		 * for paged urls
+		 *
+		 * @param category
+		 * @param userInfo
+		 * @param date
+		 * @param page
+		 * @return the current url with its page
+		 */
+		function getCurrentUrl( $category = null, $userInfo = null, $date = null, $page = null )
+		{
+			throw( new Exception( "This function must be implemented by child classes." ));
+		}
     }
 ?>
\ No newline at end of file

Modified: plog/trunk/class/net/rawrequestgenerator.class.php
===================================================================
--- plog/trunk/class/net/rawrequestgenerator.class.php	2005-09-22 06:06:22 UTC (rev 2516)
+++ plog/trunk/class/net/rawrequestgenerator.class.php	2005-09-23 21:47:23 UTC (rev 2517)
@@ -485,5 +485,33 @@
 
             return $request;
         }
+		
+		/**
+		 * given the parameters, recalculates the current URL. This method also has support
+		 * for paged urls
+		 *
+		 * @param category
+		 * @param userInfo
+		 * @param date
+		 * @param page
+		 * @return the current url with its page
+		 */
+		function getCurrentUrl( $category = null, $userInfo = null, $date = -1 )
+		{
+			$url = $this->getIndexUrl()."?op=Default&";
+			if( $category )
+				$params .= "postCategoryId=".$category->getId()."&";
+			if( $userInfo )
+				$params .= "userId=".$userInfo->getId()."&";
+			if( $date != -1 )
+				$params .= "date=".$date."&";
+				
+			if( $params )
+				$url .= $params;
+				
+			$url .= "page=";
+				
+			return( $url );
+		}		
     }
 ?>

Modified: plog/trunk/class/template/templatesets/templatesetstorage.class.php
===================================================================
--- plog/trunk/class/template/templatesets/templatesetstorage.class.php	2005-09-22 06:06:22 UTC (rev 2516)
+++ plog/trunk/class/template/templatesets/templatesetstorage.class.php	2005-09-23 21:47:23 UTC (rev 2517)
@@ -428,5 +428,17 @@
 
 			return $url;
 		}
+		
+		/**
+		 * returns the path to the 'templates/misc/' folder
+		 *
+		 * @return path
+		 * @static
+		 */
+		function getMiscTemplateFolder()
+		{
+			$templatePath = TemplateSetStorage::getBaseTemplateFolder()."/misc";
+			return $templatePath;		
+		}
 	}
-?>
+?>
\ No newline at end of file

Modified: plog/trunk/class/view/blogview.class.php
===================================================================
--- plog/trunk/class/view/blogview.class.php	2005-09-22 06:06:22 UTC (rev 2516)
+++ plog/trunk/class/view/blogview.class.php	2005-09-23 21:47:23 UTC (rev 2517)
@@ -230,6 +230,7 @@
 			$this->setValue( 'blog', $this->_blogInfo );			
 			$this->setValue( 'blogsettings', $this->_blogInfo->getSettings());
 			$this->setValue( 'rss', new RssParser());
+			$this->setValue( 'misctemplatepath', TemplateSetStorage::getMiscTemplateFolder());
 			
 			// ask the parent to do something, if needed
 			parent::render();

Modified: plog/trunk/class/view/plugintemplatedview.class.php
===================================================================
--- plog/trunk/class/view/plugintemplatedview.class.php	2005-09-22 06:06:22 UTC (rev 2516)
+++ plog/trunk/class/view/plugintemplatedview.class.php	2005-09-23 21:47:23 UTC (rev 2517)
@@ -72,6 +72,7 @@
 				$blogTemplate = $storage->getTemplateFolder( $templateSet );
 			
 			$this->_template->assign( "blogtemplate", $blogTemplate );
+			$this->_template->assign( "misctemplatepath", $storage->getMiscTemplateFolder());
 
 			parent::render();
         }

Added: plog/trunk/templates/misc/pager.template
===================================================================
--- plog/trunk/templates/misc/pager.template	2005-09-22 06:06:22 UTC (rev 2516)
+++ plog/trunk/templates/misc/pager.template	2005-09-23 21:47:23 UTC (rev 2517)
@@ -0,0 +1,27 @@
+{if $pager}
+	{if $style=="backonly"}
+		{if !$pager->isFirstPage() && !$pager->isEmpty()}
+		   <a class="pagerLink" href="{$pager->getPrevPageLink()}">&laquo;Prev</a>&nbsp;</a>
+		{/if}	
+	{elseif $style=="forwardonly"}
+		{if !$pager->isLastPage() && !$pager->isEmpty()}
+			<a class="pagerLink" href="{$pager->getNextPageLink()}">Next&raquo;</a>&nbsp;</a>
+		{/if}
+	{elseif $style=="links"}	
+		{if !$pager->isFirstPage() && !$pager->isEmpty()}
+		   <a class="pagerLink" href="{$pager->getPrevPageLink()}">&laquo;Prev</a>&nbsp;</a>
+		{/if}	
+		{foreach from=$pager->getPageLinks() item=pageLink key=pageId}
+		  {if $pageId == $pager->getCurrentPage()}
+			<span class="pagerCurrent">&nbsp;{$pageId}&nbsp;</span>
+		  {else}
+			<a class="pagerLink" href="{$pageLink}">&nbsp;{$pageId}&nbsp;</a>&nbsp;
+		  {/if}  
+		{/foreach}
+		{if !$pager->isLastPage() && !$pager->isEmpty()}
+			<a class="pagerLink" href="{$pager->getNextPageLink()}">Next&raquo;</a>&nbsp;</a>
+		{/if}
+	{else}
+		<h1>unrecognized pager style {$style}!!</h1>
+	{/if}
+{/if}
\ No newline at end of file

Modified: plog/trunk/templates/standard/footer.template
===================================================================
--- plog/trunk/templates/standard/footer.template	2005-09-22 06:06:22 UTC (rev 2516)
+++ plog/trunk/templates/standard/footer.template	2005-09-23 21:47:23 UTC (rev 2517)
@@ -68,8 +68,12 @@
 
 <div class="clearer">&nbsp;</div> 
 
+<div class="pager">
+ {include file="$misctemplatepath/pager.template" style="links"}
 </div>
 
+</div>
+
 <div id="Bottommenu"><a href="http://www.w3.org/WAI/">Accessible</a> and Valid <a href="http://validator.w3.org/check/referer">XHTML 1.0 Strict</a> and <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a></div>
 
 




More information about the pLog-svn mailing list