diff --git wp-includes/rewrite.php wp-includes/rewrite.php
index e2dbc80..d8cf9c7 100644
|
|
class WP_Rewrite { |
735 | 735 | var $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
736 | 736 | |
737 | 737 | /** |
| 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 | /** |
738 | 746 | * Whether permalinks are being used. |
739 | 747 | * |
740 | 748 | * This can be either rewrite module or permalink in the HTTP query string. |
… |
… |
class WP_Rewrite { |
874 | 882 | } |
875 | 883 | |
876 | 884 | /** |
| 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 | /** |
877 | 912 | * Retrieve date permalink structure, with year, month, and day. |
878 | 913 | * |
879 | 914 | * The permalink structure for the date, if not set already depends on the |
… |
… |
class WP_Rewrite { |
902 | 937 | return false; |
903 | 938 | } |
904 | 939 | |
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 | | |
921 | 940 | // Do not allow the date tags and %post_id% to overlap in the permalink |
922 | 941 | // structure. If they do, move the date tags to $front/date/. |
923 | 942 | $front = $this->front; |
… |
… |
class WP_Rewrite { |
931 | 950 | $tok_index++; |
932 | 951 | } |
933 | 952 | |
934 | | $this->date_structure = $front . $date_endian; |
| 953 | $this->date_structure = $front . $this->get_date_endian(); |
935 | 954 | |
936 | 955 | return $this->date_structure; |
937 | 956 | } |
… |
… |
class WP_Rewrite { |
1262 | 1281 | $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); |
1263 | 1282 | //build an array of the tags (note that said array ends up being in $tokens[0]) |
1264 | 1283 | preg_match_all('/%.+?%/', $permalink_structure, $tokens); |
1265 | | |
1266 | 1284 | $num_tokens = count($tokens[0]); |
1267 | 1285 | |
1268 | 1286 | $index = $this->index; //probably 'index.php' |
1269 | 1287 | $feedindex = $index; |
1270 | 1288 | $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] = ''; |
1278 | 1289 | |
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 ); |
1282 | 1308 | |
| 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 | } |
1283 | 1324 | //get the structure, minus any cruft (stuff that isn't tags) at the front |
1284 | 1325 | $structure = $permalink_structure; |
1285 | 1326 | if ( $front != '/' ) |
… |
… |
class WP_Rewrite { |
1292 | 1333 | $dirs = $walk_dirs ? explode('/', $structure) : array( $structure ); |
1293 | 1334 | $num_dirs = count($dirs); |
1294 | 1335 | |
| 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 | } |
1295 | 1347 | //strip slashes from the front of $front |
1296 | 1348 | $front = preg_replace('|^/+|', '', $front); |
1297 | 1349 | |
… |
… |
class WP_Rewrite { |
1299 | 1351 | $post_rewrite = array(); |
1300 | 1352 | $struct = $front; |
1301 | 1353 | 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 | |
1304 | 1361 | $struct = ltrim($struct, '/'); |
1305 | 1362 | |
1306 | 1363 | //replace tags with regexes |