[pLog-svn] r1324 - plog/trunk/class/net

oscar at devel.plogworld.net oscar at devel.plogworld.net
Sat Mar 5 22:18:00 GMT 2005


Author: oscar
Date: 2005-03-05 22:17:59 +0000 (Sat, 05 Mar 2005)
New Revision: 1324

Modified:
   plog/trunk/class/net/customurlhandler.class.php
Log:
now whenever 'custom urls' are enabled, the engine will also be capable to 'understand' 'search engine friendly' urls for backward compatibility so that users do not need to resort to mod_rewrite in order to keep the old urls working while switching to the new, nicer format.

Modified: plog/trunk/class/net/customurlhandler.class.php
===================================================================
--- plog/trunk/class/net/customurlhandler.class.php	2005-03-05 16:20:22 UTC (rev 1323)
+++ plog/trunk/class/net/customurlhandler.class.php	2005-03-05 22:17:59 UTC (rev 1324)
@@ -38,6 +38,21 @@
 									 "resource_download_link_format" => $config->getValue( "resource_download_link_format" ),
 									 "resource_preview_link_format" => $config->getValue( "resource_preview_link_format" ),
 									 "resource_medium_size_preview_link_format" => $config->getValue( "resource_medium_size_preview_link_format" ));
+			
+			// if the url did not match any of the current settings, then let's try to parse it as an old
+			// "search engine friendly" url
+			$this->_fallback = Array( "permalink_format" => "/post/{blogid}/{postid}",
+									 "category_link_format" => "/category/{$blogid}/{postid}",
+									 "blog_link_format" => "/blogid}",
+									 "archive_link_format" => "/archives/{blogid}/{year}/{month}/{day}",
+									 "user_posts_link_format" => "/user/{blogid}/{userid}",
+									 "post_trackbacks_link_format" => "/trackbacks/{blogid}/{postid}",
+									 "template_link_format" => "/static/{blogid}/{templatename}",
+									 "album_link_format" => "/album/{blogid}/{albumid}",
+									 "resource_link_format" => "/resource/{blogid}/{resourceid}",
+									 "resource_download_link_format" => "/get/{blogid}/{resourceid}",
+									 "resource_preview_link_format" => "",  // this one does not exist
+									 "resource_medium_size_preview_link_format" => "" ); // this one does not exist either
 		}
 		
 		function process( $requestUri )
@@ -46,7 +61,26 @@
 			$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()) {
+				$this->log->debug( "The url \"$requestUri\" was not a valid custom url, falling back to search engine url..." );
+				$m = new LinkFormatMatcher( $requestUri, $this->_fallback );
+				$this->_format = $m->identify();
+				$this->_params = $m->getParameters();
+				$this->_fillRequestParameters();
+			}
+			
+			return( true );
+		}
+		
+		/**
+		 * @private
+		 */
+		function _fillRequestParameters()
+		{
 			// ...and then based on this, fill in the parameters in the request
+			$matched = true;
 			if( $this->_format == "permalink_format" ) {
 				$this->_includeFile = $this->_indexName;
 				$this->_params["date"] = $this->_params["year"].$this->_params["month"].$this->_params["day"].$this->_params["hours"].$this->_params["minutes"];
@@ -167,7 +201,10 @@
 			}
 			else {
 				$this->_includeFile = $this->_indexName;
+				$matched = false;
 			}
+			
+			return( $matched );
 		}
 		
 		function getVars()




More information about the pLog-svn mailing list