<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13689] trunk/wp-includes/rewrite.php: Whitespace additions to WP_Rewrite.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13689">13689</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-03-13 07:29:10 +0000 (Sat, 13 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Whitespace additions to WP_Rewrite. A few coding standards too.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesrewritephp">trunk/wp-includes/rewrite.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesrewritephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/rewrite.php (13688 => 13689)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/rewrite.php        2010-03-13 06:59:07 UTC (rev 13688)
+++ trunk/wp-includes/rewrite.php        2010-03-13 07:29:10 UTC (rev 13689)
</span><span class="lines">@@ -34,9 +34,8 @@
</span><span class="cx">  */
</span><span class="cx"> function add_rewrite_tag($tagname, $regex) {
</span><span class="cx">         //validation
</span><del>-        if (strlen($tagname) &lt; 3 || $tagname{0} != '%' || $tagname{strlen($tagname)-1} != '%') {
</del><ins>+        if ( strlen($tagname) &lt; 3 || $tagname{0} != '%' || $tagname{strlen($tagname)-1} != '%' )
</ins><span class="cx">                 return;
</span><del>-        }
</del><span class="cx"> 
</span><span class="cx">         $qv = trim($tagname, '%');
</span><span class="cx"> 
</span><span class="lines">@@ -71,9 +70,8 @@
</span><span class="cx">  */
</span><span class="cx"> function add_feed($feedname, $function) {
</span><span class="cx">         global $wp_rewrite;
</span><del>-        if (!in_array($feedname, $wp_rewrite-&gt;feeds)) { //override the file if it is
</del><ins>+        if ( ! in_array($feedname, $wp_rewrite-&gt;feeds) ) //override the file if it is
</ins><span class="cx">                 $wp_rewrite-&gt;feeds[] = $feedname;
</span><del>-        }
</del><span class="cx">         $hook = 'do_feed_' . $feedname;
</span><span class="cx">         // Remove default function hook
</span><span class="cx">         remove_action($hook, $hook, 10, 1);
</span><span class="lines">@@ -95,7 +93,15 @@
</span><span class="cx">         $wp_rewrite-&gt;flush_rules( $hard );
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+//pseudo-places
</ins><span class="cx"> /**
</span><ins>+ * Endpoint Mask for default, which is nothing.
+ *
+ * @since 2.1.0
+ */
+define('EP_NONE', 0);
+
+/**
</ins><span class="cx">  * Endpoint Mask for Permalink.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.1.0
</span><span class="lines">@@ -186,15 +192,7 @@
</span><span class="cx">  */
</span><span class="cx"> define('EP_PAGES', 4096);
</span><span class="cx"> 
</span><del>-//pseudo-places
</del><span class="cx"> /**
</span><del>- * Endpoint Mask for default, which is nothing.
- *
- * @since 2.1.0
- */
-define('EP_NONE', 0);
-
-/**
</del><span class="cx">  * Endpoint Mask for everything.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.1.0
</span><span class="lines">@@ -259,7 +257,7 @@
</span><span class="cx">         // First, check to see if there is a 'p=N' or 'page_id=N' to match against
</span><span class="cx">         if ( preg_match('#[?&amp;](p|page_id|attachment_id)=(\d+)#', $url, $values) )        {
</span><span class="cx">                 $id = absint($values[2]);
</span><del>-                if ($id)
</del><ins>+                if ( $id )
</ins><span class="cx">                         return $id;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -314,12 +312,11 @@
</span><span class="cx"> 
</span><span class="cx">         // Look for matches.
</span><span class="cx">         $request_match = $request;
</span><del>-        foreach ($rewrite as $match =&gt; $query) {
</del><ins>+        foreach ( (array)$rewrite as $match =&gt; $query) {
</ins><span class="cx">                 // If the requesting file is the anchor of the match, prepend it
</span><span class="cx">                 // to the path info.
</span><del>-                if ( (! empty($url)) &amp;&amp; (strpos($match, $url) === 0) &amp;&amp; ($url != $request)) {
</del><ins>+                if ( !empty($url) &amp;&amp; ($url != $request) &amp;&amp; (strpos($match, $url) === 0) )
</ins><span class="cx">                         $request_match = $url . '/' . $request;
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 if ( preg_match(&quot;!^$match!&quot;, $request_match, $matches) ) {
</span><span class="cx">                         // Got a match.
</span><span class="lines">@@ -328,6 +325,7 @@
</span><span class="cx"> 
</span><span class="cx">                         // Substitute the substring matches into the query.
</span><span class="cx">                         $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
</span><ins>+
</ins><span class="cx">                         // Filter out non-public query vars
</span><span class="cx">                         global $wp;
</span><span class="cx">                         parse_str($query, $query_vars);
</span><span class="lines">@@ -336,6 +334,7 @@
</span><span class="cx">                                 if ( in_array($key, $wp-&gt;public_query_vars) )
</span><span class="cx">                                         $query[$key] = $value;
</span><span class="cx">                         }
</span><ins>+
</ins><span class="cx">                         // Do the query
</span><span class="cx">                         $query = new WP_Query($query);
</span><span class="cx">                         if ( $query-&gt;is_single || $query-&gt;is_page )
</span><span class="lines">@@ -724,10 +723,7 @@
</span><span class="cx">          * @return bool True, if permalinks are enabled.
</span><span class="cx">          */
</span><span class="cx">         function using_permalinks() {
</span><del>-                if (empty($this-&gt;permalink_structure))
-                        return false;
-                else
-                        return true;
</del><ins>+                return ! empty($this-&gt;permalink_structure);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -741,14 +737,12 @@
</span><span class="cx">          * @return bool
</span><span class="cx">          */
</span><span class="cx">         function using_index_permalinks() {
</span><del>-                if (empty($this-&gt;permalink_structure)) {
</del><ins>+                if ( empty($this-&gt;permalink_structure) )
</ins><span class="cx">                         return false;
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 // If the index is not in the permalink, we're using mod_rewrite.
</span><del>-                if (preg_match('#^/*' . $this-&gt;index . '#', $this-&gt;permalink_structure)) {
</del><ins>+                if ( preg_match('#^/*' . $this-&gt;index . '#', $this-&gt;permalink_structure) )
</ins><span class="cx">                         return true;
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="lines">@@ -764,7 +758,7 @@
</span><span class="cx">          * @return bool
</span><span class="cx">          */
</span><span class="cx">         function using_mod_rewrite_permalinks() {
</span><del>-                if ( $this-&gt;using_permalinks() &amp;&amp; ! $this-&gt;using_index_permalinks())
</del><ins>+                if ( $this-&gt;using_permalinks() &amp;&amp; ! $this-&gt;using_index_permalinks() )
</ins><span class="cx">                         return true;
</span><span class="cx">                 else
</span><span class="cx">                         return false;
</span><span class="lines">@@ -825,11 +819,11 @@
</span><span class="cx">                 $page_uris = array();
</span><span class="cx">                 $page_attachment_uris = array();
</span><span class="cx"> 
</span><del>-                foreach ($posts as $id =&gt; $post) {
</del><ins>+                foreach ( $posts as $id =&gt; $post ) {
</ins><span class="cx">                         // URL =&gt; page name
</span><span class="cx">                         $uri = get_page_uri($id);
</span><span class="cx">                         $attachments = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT ID, post_name, post_parent FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND post_parent = %d&quot;, $id ));
</span><del>-                        if ( $attachments ) {
</del><ins>+                        if ( !empty($attachments) ) {
</ins><span class="cx">                                 foreach ( $attachments as $attachment ) {
</span><span class="cx">                                         $attach_uri = get_page_uri($attachment-&gt;ID);
</span><span class="cx">                                         $page_attachment_uris[$attach_uri] = $attachment-&gt;ID;
</span><span class="lines">@@ -869,14 +863,14 @@
</span><span class="cx">                 $uris = $page_uris[0];
</span><span class="cx">                 $attachment_uris = $page_uris[1];
</span><span class="cx"> 
</span><del>-                if( is_array( $attachment_uris ) ) {
-                        foreach ($attachment_uris as $uri =&gt; $pagename) {
</del><ins>+                if ( is_array( $attachment_uris ) ) {
+                        foreach ( $attachment_uris as $uri =&gt; $pagename ) {
</ins><span class="cx">                                 $this-&gt;add_rewrite_tag('%pagename%', &quot;($uri)&quot;, 'attachment=');
</span><span class="cx">                                 $rewrite_rules = array_merge($rewrite_rules, $this-&gt;generate_rewrite_rules($page_structure, EP_PAGES));
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><del>-                if( is_array( $uris ) ) {
-                        foreach ($uris as $uri =&gt; $pagename) {
</del><ins>+                if ( is_array( $uris ) ) {
+                        foreach ( $uris as $uri =&gt; $pagename ) {
</ins><span class="cx">                                 $this-&gt;add_rewrite_tag('%pagename%', &quot;($uri)&quot;, 'pagename=');
</span><span class="cx">                                 $rewrite_rules = array_merge($rewrite_rules, $this-&gt;generate_rewrite_rules($page_structure, EP_PAGES));
</span><span class="cx">                         }
</span><span class="lines">@@ -906,11 +900,10 @@
</span><span class="cx">          * @return bool|string False on no permalink structure. Date permalink structure.
</span><span class="cx">          */
</span><span class="cx">         function get_date_permastruct() {
</span><del>-                if (isset($this-&gt;date_structure)) {
</del><ins>+                if ( isset($this-&gt;date_structure) )
</ins><span class="cx">                         return $this-&gt;date_structure;
</span><del>-                }
</del><span class="cx"> 
</span><del>-                if (empty($this-&gt;permalink_structure)) {
</del><ins>+                if ( empty($this-&gt;permalink_structure) ) {
</ins><span class="cx">                         $this-&gt;date_structure = '';
</span><span class="cx">                         return false;
</span><span class="cx">                 }
</span><span class="lines">@@ -921,8 +914,8 @@
</span><span class="cx">                 $this-&gt;date_structure = '';
</span><span class="cx">                 $date_endian = '';
</span><span class="cx"> 
</span><del>-                foreach ($endians as $endian) {
-                        if (false !== strpos($this-&gt;permalink_structure, $endian)) {
</del><ins>+                foreach ( $endians as $endian ) {
+                        if ( false !== strpos($this-&gt;permalink_structure, $endian) ) {
</ins><span class="cx">                                 $date_endian= $endian;
</span><span class="cx">                                 break;
</span><span class="cx">                         }
</span><span class="lines">@@ -937,7 +930,7 @@
</span><span class="cx">                 preg_match_all('/%.+?%/', $this-&gt;permalink_structure, $tokens);
</span><span class="cx">                 $tok_index = 1;
</span><span class="cx">                 foreach ( (array) $tokens[0] as $token) {
</span><del>-                        if ( ($token == '%post_id%') &amp;&amp; ($tok_index &lt;= 3) ) {
</del><ins>+                        if ( '%post_id%' == $token &amp;&amp; ($tok_index &lt;= 3) ) {
</ins><span class="cx">                                 $front = $front . 'date/';
</span><span class="cx">                                 break;
</span><span class="cx">                         }
</span><span class="lines">@@ -963,9 +956,8 @@
</span><span class="cx">         function get_year_permastruct() {
</span><span class="cx">                 $structure = $this-&gt;get_date_permastruct($this-&gt;permalink_structure);
</span><span class="cx"> 
</span><del>-                if (empty($structure)) {
</del><ins>+                if ( empty($structure) )
</ins><span class="cx">                         return false;
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 $structure = str_replace('%monthnum%', '', $structure);
</span><span class="cx">                 $structure = str_replace('%day%', '', $structure);
</span><span class="lines">@@ -989,9 +981,8 @@
</span><span class="cx">         function get_month_permastruct() {
</span><span class="cx">                 $structure = $this-&gt;get_date_permastruct($this-&gt;permalink_structure);
</span><span class="cx"> 
</span><del>-                if (empty($structure)) {
</del><ins>+                if ( empty($structure) )
</ins><span class="cx">                         return false;
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 $structure = str_replace('%day%', '', $structure);
</span><span class="cx"> 
</span><span class="lines">@@ -1028,16 +1019,15 @@
</span><span class="cx">          * @return bool|string False on failure. Category permalink structure.
</span><span class="cx">          */
</span><span class="cx">         function get_category_permastruct() {
</span><del>-                if (isset($this-&gt;category_structure)) {
</del><ins>+                if ( isset($this-&gt;category_structure) )
</ins><span class="cx">                         return $this-&gt;category_structure;
</span><del>-                }
</del><span class="cx"> 
</span><del>-                if (empty($this-&gt;permalink_structure)) {
</del><ins>+                if ( empty($this-&gt;permalink_structure) ) {
</ins><span class="cx">                         $this-&gt;category_structure = '';
</span><span class="cx">                         return false;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                if (empty($this-&gt;category_base))
</del><ins>+                if ( empty($this-&gt;category_base) )
</ins><span class="cx">                         $this-&gt;category_structure = trailingslashit( $this-&gt;front . 'category' );
</span><span class="cx">                 else
</span><span class="cx">                         $this-&gt;category_structure = trailingslashit( '/' . $this-&gt;root . $this-&gt;category_base );
</span><span class="lines">@@ -1061,16 +1051,15 @@
</span><span class="cx">          * @return bool|string False on failure. Tag permalink structure.
</span><span class="cx">          */
</span><span class="cx">         function get_tag_permastruct() {
</span><del>-                if (isset($this-&gt;tag_structure)) {
</del><ins>+                if ( isset($this-&gt;tag_structure) )
</ins><span class="cx">                         return $this-&gt;tag_structure;
</span><del>-                }
</del><span class="cx"> 
</span><del>-                if (empty($this-&gt;permalink_structure)) {
</del><ins>+                if ( empty($this-&gt;permalink_structure) ) {
</ins><span class="cx">                         $this-&gt;tag_structure = '';
</span><span class="cx">                         return false;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                if (empty($this-&gt;tag_base))
</del><ins>+                if ( empty($this-&gt;tag_base) )
</ins><span class="cx">                         $this-&gt;tag_structure = trailingslashit( $this-&gt;front . 'tag' );
</span><span class="cx">                 else
</span><span class="cx">                         $this-&gt;tag_structure = trailingslashit( '/' . $this-&gt;root . $this-&gt;tag_base );
</span><span class="lines">@@ -1092,8 +1081,10 @@
</span><span class="cx">         function get_extra_permastruct($name) {
</span><span class="cx">                 if ( empty($this-&gt;permalink_structure) )
</span><span class="cx">                         return false;
</span><ins>+
</ins><span class="cx">                 if ( isset($this-&gt;extra_permastructs[$name]) )
</span><span class="cx">                         return $this-&gt;extra_permastructs[$name];
</span><ins>+
</ins><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -1110,11 +1101,10 @@
</span><span class="cx">          * @return string|bool False if not found. Permalink structure string.
</span><span class="cx">          */
</span><span class="cx">         function get_author_permastruct() {
</span><del>-                if (isset($this-&gt;author_structure)) {
</del><ins>+                if ( isset($this-&gt;author_structure) )
</ins><span class="cx">                         return $this-&gt;author_structure;
</span><del>-                }
</del><span class="cx"> 
</span><del>-                if (empty($this-&gt;permalink_structure)) {
</del><ins>+                if ( empty($this-&gt;permalink_structure) ) {
</ins><span class="cx">                         $this-&gt;author_structure = '';
</span><span class="cx">                         return false;
</span><span class="cx">                 }
</span><span class="lines">@@ -1137,11 +1127,10 @@
</span><span class="cx">          * @return string|bool False if not found. Permalink structure string.
</span><span class="cx">          */
</span><span class="cx">         function get_search_permastruct() {
</span><del>-                if (isset($this-&gt;search_structure)) {
</del><ins>+                if ( isset($this-&gt;search_structure) )
</ins><span class="cx">                         return $this-&gt;search_structure;
</span><del>-                }
</del><span class="cx"> 
</span><del>-                if (empty($this-&gt;permalink_structure)) {
</del><ins>+                if ( empty($this-&gt;permalink_structure) ) {
</ins><span class="cx">                         $this-&gt;search_structure = '';
</span><span class="cx">                         return false;
</span><span class="cx">                 }
</span><span class="lines">@@ -1164,9 +1153,8 @@
</span><span class="cx">          * @return string|bool False if not found. Permalink structure string.
</span><span class="cx">          */
</span><span class="cx">         function get_page_permastruct() {
</span><del>-                if (isset($this-&gt;page_structure)) {
</del><ins>+                if ( isset($this-&gt;page_structure) )
</ins><span class="cx">                         return $this-&gt;page_structure;
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 if (empty($this-&gt;permalink_structure)) {
</span><span class="cx">                         $this-&gt;page_structure = '';
</span><span class="lines">@@ -1191,11 +1179,10 @@
</span><span class="cx">          * @return string|bool False if not found. Permalink structure string.
</span><span class="cx">          */
</span><span class="cx">         function get_feed_permastruct() {
</span><del>-                if (isset($this-&gt;feed_structure)) {
</del><ins>+                if ( isset($this-&gt;feed_structure) )
</ins><span class="cx">                         return $this-&gt;feed_structure;
</span><del>-                }
</del><span class="cx"> 
</span><del>-                if (empty($this-&gt;permalink_structure)) {
</del><ins>+                if ( empty($this-&gt;permalink_structure) ) {
</ins><span class="cx">                         $this-&gt;feed_structure = '';
</span><span class="cx">                         return false;
</span><span class="cx">                 }
</span><span class="lines">@@ -1218,9 +1205,8 @@
</span><span class="cx">          * @return string|bool False if not found. Permalink structure string.
</span><span class="cx">          */
</span><span class="cx">         function get_comment_feed_permastruct() {
</span><del>-                if (isset($this-&gt;comment_feed_structure)) {
</del><ins>+                if ( isset($this-&gt;comment_feed_structure) )
</ins><span class="cx">                         return $this-&gt;comment_feed_structure;
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 if (empty($this-&gt;permalink_structure)) {
</span><span class="cx">                         $this-&gt;comment_feed_structure = '';
</span><span class="lines">@@ -1283,10 +1269,10 @@
</span><span class="cx">         function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) {
</span><span class="cx">                 //build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
</span><span class="cx">                 $feedregex2 = '';
</span><del>-                foreach ( (array) $this-&gt;feeds as $feed_name) {
</del><ins>+                foreach ( (array) $this-&gt;feeds as $feed_name)
</ins><span class="cx">                         $feedregex2 .= $feed_name . '|';
</span><del>-                }
</del><span class="cx">                 $feedregex2 = '(' . trim($feedregex2, '|') .  ')/?$';
</span><ins>+
</ins><span class="cx">                 //$feedregex is identical but with /feed/ added on as well, so URLs like &lt;permalink&gt;/feed/atom
</span><span class="cx">                 //and &lt;permalink&gt;/atom are both possible
</span><span class="cx">                 $feedregex = $this-&gt;feed_base  . '/' . $feedregex2;
</span><span class="lines">@@ -1297,7 +1283,7 @@
</span><span class="cx">                 $commentregex = 'comment-page-([0-9]{1,})/?$';
</span><span class="cx"> 
</span><span class="cx">                 //build up an array of endpoint regexes to append =&gt; queries to append
</span><del>-                if ($endpoints) {
</del><ins>+                if ( $endpoints ) {
</ins><span class="cx">                         $ep_query_append = array ();
</span><span class="cx">                         foreach ( (array) $this-&gt;endpoints as $endpoint) {
</span><span class="cx">                                 //match everything after the endpoint name, but allow for nothing to appear there
</span><span class="lines">@@ -1320,12 +1306,11 @@
</span><span class="cx">                 $trackbackindex = $index;
</span><span class="cx">                 //build a list from the rewritecode and queryreplace arrays, that will look something like
</span><span class="cx">                 //tagname=$matches[i] where i is the current $i
</span><del>-                for ($i = 0; $i &lt; $num_tokens; ++$i) {
-                        if (0 &lt; $i) {
</del><ins>+                for ( $i = 0; $i &lt; $num_tokens; ++$i ) {
+                        if ( 0 &lt; $i )
</ins><span class="cx">                                 $queries[$i] = $queries[$i - 1] . '&amp;';
</span><del>-                        } else {
</del><ins>+                        else
</ins><span class="cx">                                 $queries[$i] = '';
</span><del>-                        }
</del><span class="cx"> 
</span><span class="cx">                         $query_token = str_replace($this-&gt;rewritecode, $this-&gt;queryreplace, $tokens[0][$i]) . $this-&gt;preg_index($i+1);
</span><span class="cx">                         $queries[$i] .= $query_token;
</span><span class="lines">@@ -1333,18 +1318,14 @@
</span><span class="cx"> 
</span><span class="cx">                 //get the structure, minus any cruft (stuff that isn't tags) at the front
</span><span class="cx">                 $structure = $permalink_structure;
</span><del>-                if ($front != '/') {
</del><ins>+                if ( $front != '/' )
</ins><span class="cx">                         $structure = str_replace($front, '', $structure);
</span><del>-                }
</del><ins>+
</ins><span class="cx">                 //create a list of dirs to walk over, making rewrite rules for each level
</span><span class="cx">                 //so for example, a $structure of /%year%/%month%/%postname% would create
</span><span class="cx">                 //rewrite rules for /%year%/, /%year%/%month%/ and /%year%/%month%/%postname%
</span><span class="cx">                 $structure = trim($structure, '/');
</span><del>-                if ($walk_dirs) {
-                        $dirs = explode('/', $structure);
-                } else {
-                        $dirs[] = $structure;
-                }
</del><ins>+                $dirs = $walk_dirs ? explode('/', $structure) : array( $structure );
</ins><span class="cx">                 $num_dirs = count($dirs);
</span><span class="cx"> 
</span><span class="cx">                 //strip slashes from the front of $front
</span><span class="lines">@@ -1353,22 +1334,31 @@
</span><span class="cx">                 //the main workhorse loop
</span><span class="cx">                 $post_rewrite = array();
</span><span class="cx">                 $struct = $front;
</span><del>-                for ($j = 0; $j &lt; $num_dirs; ++$j) {
</del><ins>+                for ( $j = 0; $j &lt; $num_dirs; ++$j ) {
</ins><span class="cx">                         //get the struct for this dir, and trim slashes off the front
</span><span class="cx">                         $struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above
</span><span class="cx">                         $struct = ltrim($struct, '/');
</span><ins>+
</ins><span class="cx">                         //replace tags with regexes
</span><span class="cx">                         $match = str_replace($this-&gt;rewritecode, $this-&gt;rewritereplace, $struct);
</span><ins>+
</ins><span class="cx">                         //make a list of tags, and store how many there are in $num_toks
</span><span class="cx">                         $num_toks = preg_match_all('/%.+?%/', $struct, $toks);
</span><ins>+
</ins><span class="cx">                         //get the 'tagname=$matches[i]'
</span><span class="cx">                         $query = ( isset($queries) &amp;&amp; is_array($queries) ) ? $queries[$num_toks - 1] : '';
</span><span class="cx"> 
</span><span class="cx">                         //set up $ep_mask_specific which is used to match more specific URL types
</span><del>-                        switch ($dirs[$j]) {
-                                case '%year%': $ep_mask_specific = EP_YEAR; break;
-                                case '%monthnum%': $ep_mask_specific = EP_MONTH; break;
-                                case '%day%': $ep_mask_specific = EP_DAY; break;
</del><ins>+                        switch ( $dirs[$j] ) {
+                                case '%year%':
+                                        $ep_mask_specific = EP_YEAR;
+                                        break;
+                                case '%monthnum%':
+                                        $ep_mask_specific = EP_MONTH;
+                                        break;
+                                case '%day%':
+                                        $ep_mask_specific = EP_DAY;
+                                        break;
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         //create query for /page/xx
</span><span class="lines">@@ -1394,16 +1384,16 @@
</span><span class="cx">                         $feedquery2 = $feedindex . '?' . $query . '&amp;feed=' . $this-&gt;preg_index($num_toks + 1);
</span><span class="cx"> 
</span><span class="cx">                         //if asked to, turn the feed queries into comment feed ones
</span><del>-                        if ($forcomments) {
</del><ins>+                        if ( $forcomments ) {
</ins><span class="cx">                                 $feedquery .= '&amp;withcomments=1';
</span><span class="cx">                                 $feedquery2 .= '&amp;withcomments=1';
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         //start creating the array of rewrites for this dir
</span><span class="cx">                         $rewrite = array();
</span><del>-                        if ($feed) //...adding on /feed/ regexes =&gt; queries
</del><ins>+                        if ( $feed ) //...adding on /feed/ regexes =&gt; queries
</ins><span class="cx">                                 $rewrite = array($feedmatch =&gt; $feedquery, $feedmatch2 =&gt; $feedquery2);
</span><del>-                        if ($paged) //...and /page/xx ones
</del><ins>+                        if ( $paged ) //...and /page/xx ones
</ins><span class="cx">                                 $rewrite = array_merge($rewrite, array($pagematch =&gt; $pagequery));
</span><span class="cx"> 
</span><span class="cx">                         //only on pages with comments add ../comment-page-xx/
</span><span class="lines">@@ -1413,17 +1403,16 @@
</span><span class="cx">                                 $rewrite = array_merge($rewrite, array($rootcommentmatch =&gt; $rootcommentquery));
</span><span class="cx"> 
</span><span class="cx">                         //do endpoints
</span><del>-                        if ($endpoints) {
</del><ins>+                        if ( $endpoints ) {
</ins><span class="cx">                                 foreach ( (array) $ep_query_append as $regex =&gt; $ep) {
</span><span class="cx">                                         //add the endpoints on if the mask fits
</span><del>-                                        if ($ep[0] &amp; $ep_mask || $ep[0] &amp; $ep_mask_specific) {
</del><ins>+                                        if ( $ep[0] &amp; $ep_mask || $ep[0] &amp; $ep_mask_specific )
</ins><span class="cx">                                                 $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this-&gt;preg_index($num_toks + 2);
</span><del>-                                        }
</del><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         //if we've got some tags in this dir
</span><del>-                        if ($num_toks) {
</del><ins>+                        if ( $num_toks ) {
</ins><span class="cx">                                 $post = false;
</span><span class="cx">                                 $page = false;
</span><span class="cx"> 
</span><span class="lines">@@ -1431,11 +1420,13 @@
</span><span class="cx">                                 //individual post. Do this by checking it contains at least one of 1) post name,
</span><span class="cx">                                 //2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
</span><span class="cx">                                 //minute all present). Set these flags now as we need them for the endpoints.
</span><del>-                                if (strpos($struct, '%postname%') !== false || strpos($struct, '%post_id%') !== false
</del><ins>+                                if ( strpos($struct, '%postname%') !== false
+                                                || strpos($struct, '%post_id%') !== false
</ins><span class="cx">                                                 || strpos($struct, '%pagename%') !== false
</span><del>-                                                || (strpos($struct, '%year%') !== false &amp;&amp; strpos($struct, '%monthnum%') !== false &amp;&amp; strpos($struct, '%day%') !== false &amp;&amp; strpos($struct, '%hour%') !== false &amp;&amp; strpos($struct, '%minute%') !== false &amp;&amp; strpos($struct, '%second%') !== false)) {
</del><ins>+                                                || (strpos($struct, '%year%') !== false &amp;&amp; strpos($struct, '%monthnum%') !== false &amp;&amp; strpos($struct, '%day%') !== false &amp;&amp; strpos($struct, '%hour%') !== false &amp;&amp; strpos($struct, '%minute%') !== false &amp;&amp; strpos($struct, '%second%') !== false)
+                                                ) {
</ins><span class="cx">                                         $post = true;
</span><del>-                                        if (strpos($struct, '%pagename%') !== false)
</del><ins>+                                        if ( strpos($struct, '%pagename%') !== false )
</ins><span class="cx">                                                 $page = true;
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="lines">@@ -1445,20 +1436,20 @@
</span><span class="cx">                                                 if ( strpos($struct, &quot;%$ptype%&quot;) !== false ) {
</span><span class="cx">                                                         $post = true;
</span><span class="cx">                                                         $page = false;
</span><ins>+                                                        break;
</ins><span class="cx">                                                 }
</span><span class="cx">                                         }
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="cx">                                 //if we're creating rules for a permalink, do all the endpoints like attachments etc
</span><del>-                                if ($post) {
-                                        $post = true;
</del><ins>+                                if ( $post ) {
</ins><span class="cx">                                         //create query and regex for trackback
</span><span class="cx">                                         $trackbackmatch = $match . $trackbackregex;
</span><span class="cx">                                         $trackbackquery = $trackbackindex . '?' . $query . '&amp;tb=1';
</span><span class="cx">                                         //trim slashes from the end of the regex for this dir
</span><span class="cx">                                         $match = rtrim($match, '/');
</span><span class="cx">                                         //get rid of brackets
</span><del>-                                        $submatchbase = str_replace(array('(',')'),'',$match);
</del><ins>+                                        $submatchbase = str_replace( array('(', ')'), '', $match);
</ins><span class="cx"> 
</span><span class="cx">                                         //add a rule for at attachments, which take the form of &lt;permalink&gt;/some-text
</span><span class="cx">                                         $sub1 = $submatchbase . '/([^/]+)/';
</span><span class="lines">@@ -1484,12 +1475,14 @@
</span><span class="cx">                                         $subcommentquery = $subquery . '&amp;cpage=' . $this-&gt;preg_index(2);
</span><span class="cx"> 
</span><span class="cx">                                         //do endpoints for attachments
</span><del>-                                        if ( !empty($endpoints) ) { foreach ( (array) $ep_query_append as $regex =&gt; $ep ) {
-                                                if ($ep[0] &amp; EP_ATTACHMENT) {
-                                                        $rewrite[$sub1 . $regex] = $subquery . $ep[1] . $this-&gt;preg_index(2);
-                                                        $rewrite[$sub2 . $regex] = $subquery . $ep[1] . $this-&gt;preg_index(2);
</del><ins>+                                        if ( !empty($endpoints) ) {
+                                                foreach ( (array) $ep_query_append as $regex =&gt; $ep ) {
+                                                        if ( $ep[0] &amp; EP_ATTACHMENT ) {
+                                                                $rewrite[$sub1 . $regex] = $subquery . $ep[1] . $this-&gt;preg_index(2);
+                                                                $rewrite[$sub2 . $regex] = $subquery . $ep[1] . $this-&gt;preg_index(2);
+                                                        }
</ins><span class="cx">                                                 }
</span><del>-                                        } }
</del><ins>+                                        }
</ins><span class="cx"> 
</span><span class="cx">                                         //now we've finished with endpoints, finish off the $sub1 and $sub2 matches
</span><span class="cx">                                         $sub1 .= '?$';
</span><span class="lines">@@ -1510,7 +1503,7 @@
</span><span class="cx">                                 $rewrite = array_merge($rewrite, array($match =&gt; $query));
</span><span class="cx"> 
</span><span class="cx">                                 //if we're matching a permalink, add those extras (attachments etc) on
</span><del>-                                if ($post) {
</del><ins>+                                if ( $post ) {
</ins><span class="cx">                                         //add trackback
</span><span class="cx">                                         $rewrite = array_merge(array($trackbackmatch =&gt; $trackbackquery), $rewrite);
</span><span class="cx"> 
</span><span class="lines">@@ -1566,19 +1559,18 @@
</span><span class="cx">         function rewrite_rules() {
</span><span class="cx">                 $rewrite = array();
</span><span class="cx"> 
</span><del>-                if (empty($this-&gt;permalink_structure)) {
</del><ins>+                if ( empty($this-&gt;permalink_structure) )
</ins><span class="cx">                         return $rewrite;
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 // robots.txt
</span><span class="cx">                 $robots_rewrite = array('robots\.txt$' =&gt; $this-&gt;index . '?robots=1');
</span><span class="cx"> 
</span><span class="cx">                 //Default Feed rules - These are require to allow for the direct access files to work with permalink structure starting with %category%
</span><del>-                $default_feeds = array(        '.*wp-atom.php$'        =&gt;        $this-&gt;index .'?feed=atom',
-                                                                '.*wp-rdf.php$'        =&gt;        $this-&gt;index .'?feed=rdf',
-                                                                '.*wp-rss.php$'        =&gt;        $this-&gt;index .'?feed=rss',
-                                                                '.*wp-rss2.php$'        =&gt;        $this-&gt;index .'?feed=rss2',
-                                                                '.*wp-feed.php$'        =&gt;        $this-&gt;index .'?feed=feed',
</del><ins>+                $default_feeds = array(        '.*wp-atom.php$'        =&gt;        $this-&gt;index . '?feed=atom',
+                                                                '.*wp-rdf.php$'                =&gt;        $this-&gt;index . '?feed=rdf',
+                                                                '.*wp-rss.php$'                =&gt;        $this-&gt;index . '?feed=rss',
+                                                                '.*wp-rss2.php$'        =&gt;        $this-&gt;index . '?feed=rss2',
+                                                                '.*wp-feed.php$'        =&gt;        $this-&gt;index . '?feed=feed',
</ins><span class="cx">                                                                 '.*wp-commentsrss2.php$'        =&gt;        $this-&gt;index . '?feed=rss2&amp;withcomments=1');
</span><span class="cx"> 
</span><span class="cx">                 // Post
</span><span class="lines">@@ -1674,21 +1666,18 @@
</span><span class="cx">          * @return string
</span><span class="cx">          */
</span><span class="cx">         function mod_rewrite_rules() {
</span><del>-                if ( ! $this-&gt;using_permalinks()) {
</del><ins>+                if ( ! $this-&gt;using_permalinks() )
</ins><span class="cx">                         return '';
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 $site_root = parse_url(get_option('siteurl'));
</span><del>-                if ( isset( $site_root['path'] ) ) {
</del><ins>+                if ( isset( $site_root['path'] ) )
</ins><span class="cx">                         $site_root = trailingslashit($site_root['path']);
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 $home_root = parse_url(home_url());
</span><del>-                if ( isset( $home_root['path'] ) ) {
</del><ins>+                if ( isset( $home_root['path'] ) )
</ins><span class="cx">                         $home_root = trailingslashit($home_root['path']);
</span><del>-                } else {
</del><ins>+                else
</ins><span class="cx">                         $home_root = '/';
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 $rules = &quot;&lt;IfModule mod_rewrite.c&gt;\n&quot;;
</span><span class="cx">                 $rules .= &quot;RewriteEngine On\n&quot;;
</span><span class="lines">@@ -1702,14 +1691,14 @@
</span><span class="cx"> 
</span><span class="cx">                         // If the match is unanchored and greedy, prepend rewrite conditions
</span><span class="cx">                         // to avoid infinite redirects and eclipsing of real files.
</span><del>-                        if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
</del><ins>+                        //if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
</ins><span class="cx">                                 //nada.
</span><del>-                        }
</del><ins>+                        //}
</ins><span class="cx"> 
</span><span class="cx">                         $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . &quot; [QSA,L]\n&quot;;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                if ($this-&gt;use_verbose_rules) {
</del><ins>+                if ( $this-&gt;use_verbose_rules ) {
</ins><span class="cx">                         $this-&gt;matches = '';
</span><span class="cx">                         $rewrite = $this-&gt;rewrite_rules();
</span><span class="cx">                         $num_rules = count($rewrite);
</span><span class="lines">@@ -1723,15 +1712,14 @@
</span><span class="cx"> 
</span><span class="cx">                                 // If the match is unanchored and greedy, prepend rewrite conditions
</span><span class="cx">                                 // to avoid infinite redirects and eclipsing of real files.
</span><del>-                                if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
</del><ins>+                                //if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
</ins><span class="cx">                                         //nada.
</span><del>-                                }
</del><ins>+                                //}
</ins><span class="cx"> 
</span><del>-                                if (strpos($query, $this-&gt;index) !== false) {
</del><ins>+                                if ( strpos($query, $this-&gt;index) !== false )
</ins><span class="cx">                                         $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . &quot; [QSA,L]\n&quot;;
</span><del>-                                } else {
</del><ins>+                                else
</ins><span class="cx">                                         $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . &quot; [QSA,L]\n&quot;;
</span><del>-                                }
</del><span class="cx">                         }
</span><span class="cx">                 } else {
</span><span class="cx">                         $rules .= &quot;RewriteCond %{REQUEST_FILENAME} !-f\n&quot; .
</span><span class="lines">@@ -1760,9 +1748,8 @@
</span><span class="cx">          */
</span><span class="cx">         function iis7_url_rewrite_rules($add_parent_tags = false, $indent = &quot;  &quot;, $end_of_line = &quot;\n&quot;) {
</span><span class="cx"> 
</span><del>-                if ( ! $this-&gt;using_permalinks()) {
</del><ins>+                if ( ! $this-&gt;using_permalinks() )
</ins><span class="cx">                         return '';
</span><del>-                }
</del><span class="cx"> 
</span><span class="cx">                 if ( !is_multisite() ) {
</span><span class="cx">                         $rules = '';
</span><span class="lines">@@ -1793,7 +1780,7 @@
</span><span class="cx">                 } else {
</span><span class="cx">                         $siteurl = get_option( 'siteurl' );
</span><span class="cx">                         $siteurl_len = strlen( $siteurl );
</span><del>-                        if ( defined( 'WP_CONTENT_URL' ) &amp;&amp; substr( WP_CONTENT_URL, 0, $siteurl_len ) == $siteurl &amp;&amp; strlen( WP_CONTENT_URL ) &gt; $siteurl_len ) 
</del><ins>+                        if ( substr( WP_CONTENT_URL, 0, $siteurl_len ) == $siteurl &amp;&amp; strlen( WP_CONTENT_URL ) &gt; $siteurl_len ) 
</ins><span class="cx">                                 $content_path = substr( WP_CONTENT_URL, $siteurl_len + 1 );
</span><span class="cx">                         else
</span><span class="cx">                                 $content_path = 'wp-content'; 
</span><span class="lines">@@ -1863,7 +1850,7 @@
</span><span class="cx">                 //get everything up to the first ?
</span><span class="cx">                 $index = (strpos($redirect, '?') == false ? strlen($redirect) : strpos($redirect, '?'));
</span><span class="cx">                 $front = substr($redirect, 0, $index);
</span><del>-                if ($front != $this-&gt;index) { //it doesn't redirect to WP's index.php
</del><ins>+                if ( $front != $this-&gt;index ) { //it doesn't redirect to WP's index.php
</ins><span class="cx">                         $this-&gt;add_external_rule($regex, $redirect);
</span><span class="cx">                 } else {
</span><span class="cx">                         if ( 'bottom' == $after)
</span><span class="lines">@@ -1960,9 +1947,8 @@
</span><span class="cx">                 $this-&gt;permalink_structure = get_option('permalink_structure');
</span><span class="cx">                 $this-&gt;front = substr($this-&gt;permalink_structure, 0, strpos($this-&gt;permalink_structure, '%'));
</span><span class="cx">                 $this-&gt;root = '';
</span><del>-                if ($this-&gt;using_index_permalinks()) {
</del><ins>+                if ( $this-&gt;using_index_permalinks() )
</ins><span class="cx">                         $this-&gt;root = $this-&gt;index . '/';
</span><del>-                }
</del><span class="cx">                 $this-&gt;category_base = get_option( 'category_base' );
</span><span class="cx">                 $this-&gt;tag_base = get_option( 'tag_base' );
</span><span class="cx">                 unset($this-&gt;category_structure);
</span><span class="lines">@@ -1997,7 +1983,7 @@
</span><span class="cx">          * @param string $permalink_structure Permalink structure.
</span><span class="cx">          */
</span><span class="cx">         function set_permalink_structure($permalink_structure) {
</span><del>-                if ($permalink_structure != $this-&gt;permalink_structure) {
</del><ins>+                if ( $permalink_structure != $this-&gt;permalink_structure ) {
</ins><span class="cx">                         update_option('permalink_structure', $permalink_structure);
</span><span class="cx">                         $this-&gt;init();
</span><span class="cx">                         do_action('permalink_structure_changed', $this-&gt;permalink_structure, $permalink_structure);
</span><span class="lines">@@ -2017,7 +2003,7 @@
</span><span class="cx">          * @param string $category_base Category permalink structure base.
</span><span class="cx">          */
</span><span class="cx">         function set_category_base($category_base) {
</span><del>-                if ($category_base != $this-&gt;category_base) {
</del><ins>+                if ( $category_base != $this-&gt;category_base ) {
</ins><span class="cx">                         update_option('category_base', $category_base);
</span><span class="cx">                         $this-&gt;init();
</span><span class="cx">                 }
</span></span></pre>
</div>
</div>

</body>
</html>