[pLog-svn] r6788 - plog/branches/lifetype-1.2/class/net

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Mon Feb 2 20:52:41 EST 2009


Author: jondaley
Date: 2009-02-02 20:52:41 -0500 (Mon, 02 Feb 2009)
New Revision: 6788

Modified:
   plog/branches/lifetype-1.2/class/net/customrequestgenerator.class.php
Log:
allow fancier custom URLs.  I'll write up some documentation at some point, but I've had a couple requests for this, and I'm now using it on my own blog.  This is actually quite handy for migrating people from 'search engine friendly' URLs to custom URLs, since now they both can be accepted, but the new URL is published.  The second preg_replace() call replaces all str_replace() calls, and the first preg_replace is the new feature

Modified: plog/branches/lifetype-1.2/class/net/customrequestgenerator.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/net/customrequestgenerator.class.php	2009-02-03 01:45:06 UTC (rev 6787)
+++ plog/branches/lifetype-1.2/class/net/customrequestgenerator.class.php	2009-02-03 01:52:41 UTC (rev 6788)
@@ -438,12 +438,11 @@
          */
         function _replaceTags( $format, $tags )
         {
-            $result = $format;
-            $result = str_replace( "$", "", $format );
-			$result = str_replace( "(", "", $result );
-			$result = str_replace( ")", "", $result );
-			$result = str_replace( "?", "", $result );
-			$result = str_replace( "\\", "", $result );
+                // allow such things as archive_link_format:
+                // /archives/(?:{year}/{month}/{day}/)?{postname}$
+                // /(?:post|archives)/(?:{year}/{month}/{day}/)?{postname}$
+            $result = preg_replace("/\(\?:([^\)\|]*)([^\)]*)\)/", "$1", $format);
+            $result = preg_replace("/[$()?\\\\]/", "", $result);
             foreach( $tags as $key => $value ) {
                 $result = str_replace( $key, $value, $result );
             }



More information about the pLog-svn mailing list