Make WordPress Core

Ticket #13701: 13701.diff

File 13701.diff, 5.7 KB (added by wonderboymusic, 12 years ago)
  • wp-includes/rewrite.php

    diff --git wp-includes/rewrite.php wp-includes/rewrite.php
    index e2dbc80..d8cf9c7 100644
    class WP_Rewrite { 
    735735        var $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    736736
    737737        /**
     738         * Default date endianness
     739         *
     740         * @since 3.7.0
     741         * @access private
     742         * @var string
     743         */
     744        var $default_date_endian = '%year%/%monthnum%/%day%';
     745        /**
    738746         * Whether permalinks are being used.
    739747         *
    740748         * This can be either rewrite module or permalink in the HTTP query string.
    class WP_Rewrite { 
    874882        }
    875883
    876884        /**
     885         * Retrieve the date endian from the permalink structure
     886         *
     887         * @since 3.7.0
     888         * @access public
     889         *
     890         * @return array
     891         */
     892        function get_date_endian() {
     893                // The date permalink must have year, month, and day separated by slashes.
     894                $alternative_endians = array( '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%' );
     895
     896                $date_endian = '';
     897
     898                foreach ( $alternative_endians as $endian ) {
     899                        if ( false !== strpos( $this->permalink_structure, $endian ) ) {
     900                                $date_endian = $endian;
     901                                break;
     902                        }
     903                }
     904
     905                if ( empty( $date_endian ) )
     906                        $date_endian = $this->default_date_endian;
     907
     908                return $date_endian;
     909        }
     910
     911        /**
    877912         * Retrieve date permalink structure, with year, month, and day.
    878913         *
    879914         * The permalink structure for the date, if not set already depends on the
    class WP_Rewrite { 
    902937                        return false;
    903938                }
    904939
    905                 // The date permalink must have year, month, and day separated by slashes.
    906                 $endians = array('%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%');
    907 
    908                 $this->date_structure = '';
    909                 $date_endian = '';
    910 
    911                 foreach ( $endians as $endian ) {
    912                         if ( false !== strpos($this->permalink_structure, $endian) ) {
    913                                 $date_endian= $endian;
    914                                 break;
    915                         }
    916                 }
    917 
    918                 if ( empty($date_endian) )
    919                         $date_endian = '%year%/%monthnum%/%day%';
    920 
    921940                // Do not allow the date tags and %post_id% to overlap in the permalink
    922941                // structure. If they do, move the date tags to $front/date/.
    923942                $front = $this->front;
    class WP_Rewrite { 
    931950                        $tok_index++;
    932951                }
    933952
    934                 $this->date_structure = $front . $date_endian;
     953                $this->date_structure = $front . $this->get_date_endian();
    935954
    936955                return $this->date_structure;
    937956        }
    class WP_Rewrite { 
    12621281                $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
    12631282                //build an array of the tags (note that said array ends up being in $tokens[0])
    12641283                preg_match_all('/%.+?%/', $permalink_structure, $tokens);
    1265 
    12661284                $num_tokens = count($tokens[0]);
    12671285
    12681286                $index = $this->index; //probably 'index.php'
    12691287                $feedindex = $index;
    12701288                $trackbackindex = $index;
    1271                 //build a list from the rewritecode and queryreplace arrays, that will look something like
    1272                 //tagname=$matches[i] where i is the current $i
    1273                 for ( $i = 0; $i < $num_tokens; ++$i ) {
    1274                         if ( 0 < $i )
    1275                                 $queries[$i] = $queries[$i - 1] . '&';
    1276                         else
    1277                                 $queries[$i] = '';
    12781289
    1279                         $query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1);
    1280                         $queries[$i] .= $query_token;
    1281                 }
     1290                if ( EP_DATE === $ep_mask && $this->default_date_endian !== $this->get_date_endian() ) {
     1291                        $reformatted = array( '%year%', array( '%monthnum%', '%year%' ) );
     1292                        switch ( $this->get_date_endian() ) {
     1293                                case '%day%/%monthnum%/%year%':
     1294                                        $reformatted[] = array( '%day%', '%monthnum%', '%year%' );
     1295                                        break;
     1296                                case '%monthnum%/%day%/%year%':
     1297                                        $reformatted[] = array( '%monthnum%', '%day%', '%year%' );
     1298                                        break;
     1299                        }
     1300
     1301                        foreach ( $reformatted as $tokens ) {
     1302                                if ( ! is_array( $tokens ) )
     1303                                        $tokens = array( $tokens );
     1304
     1305                                $query_parts = array();
     1306                                foreach ( $tokens as $i => $token )
     1307                                        $query_parts[] = str_replace( $this->rewritecode, $this->queryreplace, $token ) . $this->preg_index( $i + 1 );
    12821308
     1309                                $queries[] = join( '&', $query_parts );
     1310                        }
     1311                } else {
     1312                        //build a list from the rewritecode and queryreplace arrays, that will look something like
     1313                        //tagname=$matches[i] where i is the current $i
     1314                        for ( $i = 0; $i < $num_tokens; ++$i ) {
     1315                                if ( 0 < $i )
     1316                                        $queries[$i] = $queries[$i - 1] . '&';
     1317                                else
     1318                                        $queries[$i] = '';
     1319
     1320                                $query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1);
     1321                                $queries[$i] .= $query_token;
     1322                        }
     1323                }
    12831324                //get the structure, minus any cruft (stuff that isn't tags) at the front
    12841325                $structure = $permalink_structure;
    12851326                if ( $front != '/' )
    class WP_Rewrite { 
    12921333                $dirs = $walk_dirs ? explode('/', $structure) : array( $structure );
    12931334                $num_dirs = count($dirs);
    12941335
     1336                if ( EP_DATE === $ep_mask && $this->default_date_endian !== $this->get_date_endian() ) {
     1337                        $dirs = array( '%year%', '%monthnum%/%year%' );
     1338                        switch ( $this->get_date_endian() ) {
     1339                                case '%day%/%monthnum%/%year%':
     1340                                        $dirs[] = '%day%/%monthnum%/%year%';
     1341                                        break;
     1342                                case '%monthnum%/%day%/%year%':
     1343                                        $dirs[] = '%monthnum%/%day%/%year%';
     1344                                        break;
     1345                        }
     1346                }
    12951347                //strip slashes from the front of $front
    12961348                $front = preg_replace('|^/+|', '', $front);
    12971349
    class WP_Rewrite { 
    12991351                $post_rewrite = array();
    13001352                $struct = $front;
    13011353                for ( $j = 0; $j < $num_dirs; ++$j ) {
    1302                         //get the struct for this dir, and trim slashes off the front
    1303                         $struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above
     1354                        if ( EP_DATE === $ep_mask && $this->default_date_endian !== $this->get_date_endian() ) {
     1355                                $struct = $front . $dirs[$j];
     1356                        } else {
     1357                                //get the struct for this dir, and trim slashes off the front
     1358                                $struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above
     1359                        }
     1360
    13041361                        $struct = ltrim($struct, '/');
    13051362
    13061363                        //replace tags with regexes