[pLog-svn] r2521 - in plog/trunk: class/net locale templates/admin

oscar at devel.plogworld.net oscar at devel.plogworld.net
Sat Sep 24 14:57:38 GMT 2005


Author: oscar
Date: 2005-09-24 14:57:37 +0000 (Sat, 24 Sep 2005)
New Revision: 2521

Modified:
   plog/trunk/class/net/customrequestgenerator.class.php
   plog/trunk/class/net/customurlhandler.class.php
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/templates/admin/globalsettings_url.template
Log:
Added support for paging when custom urls are enabled. Basically, There is a new configurable parameter under global settings->urls called page_suffix_format that allows users to define how the suffix that is appended to normal urls that support pages is defined (defaults to "/page/{page}")

When custom urls are parsed, we first get the value of the page, remove it from the url itself and then continue parsing it as we did before (and therefore, previously working code did not need any changes) The value of the page parameter is then put back into the request like all the other parameters extracted from the url.

It seems to work well, let me know if there's any problem with it... (if you test it :))

Modified: plog/trunk/class/net/customrequestgenerator.class.php
===================================================================
--- plog/trunk/class/net/customrequestgenerator.class.php	2005-09-24 14:53:27 UTC (rev 2520)
+++ plog/trunk/class/net/customrequestgenerator.class.php	2005-09-24 14:57:37 UTC (rev 2521)
@@ -516,5 +516,37 @@
             
             return $result;
         }
+
+		/**
+		 * 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 )
+		{
+			if( $category ) {
+				$url = $this->categoryLink( $category );
+			}
+			elseif( $userInfo ) {
+				$url = $this->postUserLink( $userInfo );
+			}
+			elseif( $date > -1 ) {
+				$url = $this->getArchiveLink( $date );
+			}
+			else {
+				// if none of the above, we should at least get a link to the blog!
+				$url = $this->blogLink();
+			}		
+			
+			$pageFormat = $this->_config->getValue( "page_suffix_format" );
+			$pageFormat = str_replace( "{page}", "", $pageFormat );
+			
+			return( $url.$pageFormat );
+		}
     }
 ?>
\ No newline at end of file

Modified: plog/trunk/class/net/customurlhandler.class.php
===================================================================
--- plog/trunk/class/net/customurlhandler.class.php	2005-09-24 14:53:27 UTC (rev 2520)
+++ plog/trunk/class/net/customurlhandler.class.php	2005-09-24 14:57:37 UTC (rev 2521)
@@ -74,6 +74,42 @@
 									 "resource_medium_size_preview_link_format" => "" ); // this one does not exist either
 		}
 		
+		/**
+		 * @private
+		 */
+		function getPageParameterValue( $requestUri )		
+		{
+			$config =& Config::getConfig();
+			$pageSuffix = $config->getValue( "page_suffix_format" );
+			$pageSuffixRegexp = str_replace( "{page}", "([0-9]*)", $pageSuffix );
+			$pageSuffixRegexp = "/".str_replace( "/", "\/", $pageSuffixRegexp )."/";
+			//print($pageSuffixRegexp."<br/>");			
+			if( preg_match( $pageSuffixRegexp, $requestUri, $matches ))
+				$page = $matches[1];
+			else
+				$page = "";
+				
+			//print("page = $page<br/>");
+			
+			return( $page );
+		}
+		
+		/**
+		 * @private
+		 * Given a request uri/url, remove the suffix which is used for the paging if any		 
+		 */
+		function removePageSuffix( $requestUri )
+		{
+			$config =& Config::getConfig();
+			$pageSuffix = $config->getValue( "page_suffix_format" );
+			$pageSuffixRegexp = str_replace( "{page}", "[0-9]*", $pageSuffix );
+			$pageSuffixRegexp = "/".str_replace( "/", "\/", $pageSuffixRegexp )."/";
+			$requestUri = preg_replace( $pageSuffixRegexp, "", $requestUri );
+			//print($pageSuffixRegexp." - ".$requestUri);
+			
+			return( $requestUri );		
+		}
+		
 		function process( $requestUri )
 		{
 			// decode the string, since it seems that php will not do it for us in this case...
@@ -84,12 +120,20 @@
 	            // if so, remove everything including the question mark
 	            $requestUri = substr( $requestUri, 0, $pos );
             }
-                  
+			
+			// once we're done with everything else, let's get the value page parameter and save it			
+			$page = $this->getPageParameterValue( $requestUri );
+			
+			// and now we can remove remove the page suffix so that it doesn't interfere with the 
+			// url parser
+			$requestUri = $this->removePageSuffix( $requestUri );                  						
+			
 			// guess which format we're using...
 			$m = new LinkFormatMatcher( $requestUri, $this->_formats );
 			$this->_format = $m->identify();
 			$this->_params = $m->getParameters();
 			
+			
 			// if it didn't work out the first time, let's try with an additional url format
 			if( !$this->_fillRequestParameters()) {
 				$m = new LinkFormatMatcher( $requestUri, $this->_fallback );
@@ -98,6 +142,9 @@
 				$this->_fillRequestParameters();
 			}
 			
+			// put the parameter back as a parameter
+			$this->_params["page"] = $page;
+						
 			return( true );
 		}
 		
@@ -311,6 +358,11 @@
 				$matched = false;
 			}
 			
+			// this must be put in the _vars array so that client classes, when checking
+			// for the parameters that were identified in the request, can also include
+			// the page parameter
+			$this->_vars["page"] = "page";
+			
 			return( $matched );
 		}
 		

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2005-09-24 14:53:27 UTC (rev 2520)
+++ plog/trunk/locale/locale_en_UK.php	2005-09-24 14:57:37 UTC (rev 2521)
@@ -958,4 +958,6 @@
 $messages['error_incorrect_global_category_id'] = 'Invalid global article category';
 $messages['global_category_deleted_ok'] = 'Article category "%s" deleted successfully';
 $messages['error_deleting_global_category2'] = 'There was an error removing article category with id = %s';
+
+$messages['help_page_suffix_format'] = 'Suffix that will be appended to URLs that support paging';
 ?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/globalsettings_url.template
===================================================================
--- plog/trunk/templates/admin/globalsettings_url.template	2005-09-24 14:53:27 UTC (rev 2520)
+++ plog/trunk/templates/admin/globalsettings_url.template	2005-09-24 14:57:37 UTC (rev 2521)
@@ -82,4 +82,10 @@
     <div class="formHelp">{$locale->tr("help_resource_download_link_format")}</div>	
     <input style="width:100%" type="text" id="config[resource_download_link_format]" name="config[resource_download_link_format]" value="{$resource_download_link_format}"/>
    </div>
+   <!-- page_suffix_format -->
+   <div class="field">
+    <label for="config[page_suffix_format]">page_suffix_format</label>
+    <div class="formHelp">{$locale->tr("help_page_suffix_format")}</div>	
+    <input style="width:100%" type="text" id="config[page_suffix_format]" name="config[page_suffix_format]" value="{$page_suffix_format}"/>
+   </div>   
 </div>
\ No newline at end of file




More information about the pLog-svn mailing list