Ticket #12779: 12779.diff
File 12779.diff, 12.0 KB (added by , 15 years ago) |
---|
-
rewrite.php
54 54 * @param string $struct Permalink structure. 55 55 * @param bool $with_front Prepend front base to permalink structure. 56 56 */ 57 function add_permastruct( $name, $struct, $with_front = true, $ep_mask = EP_NONE) {57 function add_permastruct( $name, $struct, $with_front = true, $ep_mask = 'none' ) { 58 58 global $wp_rewrite; 59 59 return $wp_rewrite->add_permastruct( $name, $struct, $with_front, $ep_mask ); 60 60 } … … 93 93 $wp_rewrite->flush_rules( $hard ); 94 94 } 95 95 96 //pseudo-places 96 // pseudo-places -- these are deprecated 97 97 98 /** 98 99 * Endpoint Mask for default, which is nothing. 99 100 * 100 101 * @since 2.1.0 102 * @deprecated 3.0.0 101 103 */ 102 104 define('EP_NONE', 0); 103 105 … … 105 107 * Endpoint Mask for Permalink. 106 108 * 107 109 * @since 2.1.0 110 * @deprecated 3.0.0 108 111 */ 109 112 define('EP_PERMALINK', 1); 110 113 … … 112 115 * Endpoint Mask for Attachment. 113 116 * 114 117 * @since 2.1.0 118 * @deprecated 3.0.0 115 119 */ 116 120 define('EP_ATTACHMENT', 2); 117 121 … … 119 123 * Endpoint Mask for date. 120 124 * 121 125 * @since 2.1.0 126 * @deprecated 3.0.0 122 127 */ 123 128 define('EP_DATE', 4); 124 129 … … 126 131 * Endpoint Mask for year 127 132 * 128 133 * @since 2.1.0 134 * @deprecated 3.0.0 129 135 */ 130 136 define('EP_YEAR', 8); 131 137 … … 133 139 * Endpoint Mask for month. 134 140 * 135 141 * @since 2.1.0 142 * @deprecated 3.0.0 136 143 */ 137 144 define('EP_MONTH', 16); 138 145 … … 140 147 * Endpoint Mask for day. 141 148 * 142 149 * @since 2.1.0 150 * @deprecated 3.0.0 143 151 */ 144 152 define('EP_DAY', 32); 145 153 … … 147 155 * Endpoint Mask for root. 148 156 * 149 157 * @since 2.1.0 158 * @deprecated 3.0.0 150 159 */ 151 160 define('EP_ROOT', 64); 152 161 … … 154 163 * Endpoint Mask for comments. 155 164 * 156 165 * @since 2.1.0 166 * @deprecated 3.0.0 157 167 */ 158 168 define('EP_COMMENTS', 128); 159 169 … … 161 171 * Endpoint Mask for searches. 162 172 * 163 173 * @since 2.1.0 174 * @deprecated 3.0.0 164 175 */ 165 176 define('EP_SEARCH', 256); 166 177 … … 168 179 * Endpoint Mask for categories. 169 180 * 170 181 * @since 2.1.0 182 * @deprecated 3.0.0 171 183 */ 172 184 define('EP_CATEGORIES', 512); 173 185 … … 175 187 * Endpoint Mask for tags. 176 188 * 177 189 * @since 2.3.0 190 * @deprecated 3.0.0 178 191 */ 179 192 define('EP_TAGS', 1024); 180 193 … … 182 195 * Endpoint Mask for authors. 183 196 * 184 197 * @since 2.1.0 198 * @deprecated 3.0.0 185 199 */ 186 200 define('EP_AUTHORS', 2048); 187 201 … … 189 203 * Endpoint Mask for pages. 190 204 * 191 205 * @since 2.1.0 206 * @deprecated 3.0.0 192 207 */ 193 208 define('EP_PAGES', 4096); 194 209 … … 196 211 * Endpoint Mask for everything. 197 212 * 198 213 * @since 2.1.0 214 * @deprecated 3.0.0 199 215 */ 200 216 define('EP_ALL', 8191); 201 217 … … 712 728 */ 713 729 var $feeds = array ( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); 714 730 731 // prolly will need one of these 732 715 733 /** 734 * @since 3.0.0 735 * @access private 736 * @var array 737 */ 738 var $_endpoints = array( 'none', 'permalink', 'attachment', 'date', 'year', 'month', 'day', 739 'root', 'comments', 'search', 'categories', 'tags', 'authors', 'pages' ); 740 741 /** 742 * @since 3.0.0 743 * @access private 744 * @var array 745 */ 746 var $_bitmasks = array( 'EP_NONE' => 'none', 'EP_PERMALINK' => 'permalink', 'EP_attachment' => 'attachment', 747 'EP_DATE' => 'date', 'EP_YEAR' => 'year', 'EP_MONTH' => 'month', 'EP_DAY' => 'day', 'EP_ROOT' => 'root', 748 'EP_COMMENTS' => 'comments', 'EP_SEARCH' => 'search', 'EP_CATEGORIES' => 'categories', 'EP_TAGS' => 'tags', 749 'EP_AUTHORS' => 'authors', 'EP_PAGES' => 'pages' ); 750 751 /** 716 752 * Whether permalinks are being used. 717 753 * 718 754 * This can be either rewrite module or permalink in the HTTP query string. … … 855 891 856 892 if ( ! $this->use_verbose_page_rules ) { 857 893 $this->add_rewrite_tag('%pagename%', "(.+?)", 'pagename='); 858 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));894 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, 'pages')); 859 895 return $rewrite_rules; 860 896 } 861 897 … … 866 902 if ( is_array( $attachment_uris ) ) { 867 903 foreach ( $attachment_uris as $uri => $pagename ) { 868 904 $this->add_rewrite_tag('%pagename%', "($uri)", 'attachment='); 869 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));905 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, 'pages')); 870 906 } 871 907 } 872 908 if ( is_array( $uris ) ) { 873 909 foreach ( $uris as $uri => $pagename ) { 874 910 $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename='); 875 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));911 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, 'pages')); 876 912 } 877 913 } 878 914 … … 1258 1294 * @access public 1259 1295 * 1260 1296 * @param string $permalink_structure The permalink structure. 1261 * @param int $ep_mask Optional, default is EP_NONE. Endpoint constant, see EP_* constants.1297 * @param int $ep_mask Optional, default is false, for none. Endpoint, see WP_Rewrite::add_endpoint(). 1262 1298 * @param bool $paged Optional, default is true. Whether permalink request is paged. 1263 1299 * @param bool $feed Optional, default is true. Whether for feed. 1264 1300 * @param bool $forcomments Optional, default is false. Whether for comments. … … 1266 1302 * @param bool $endpoints Optional, default is true. Whether endpoints are enabled. 1267 1303 * @return array Rewrite rule list. 1268 1304 */ 1269 function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) { 1305 function generate_rewrite_rules($permalink_structure, $ep_mask = 'none', $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) { 1306 $this->_bitmasks_to_array( $ep_mask ); 1307 1270 1308 //build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/? 1271 1309 $feedregex2 = ''; 1272 1310 foreach ( (array) $this->feeds as $feed_name) … … 1351 1389 //set up $ep_mask_specific which is used to match more specific URL types 1352 1390 switch ( $dirs[$j] ) { 1353 1391 case '%year%': 1354 $ep_mask_specific = EP_YEAR;1392 $ep_mask_specific = 'year'; 1355 1393 break; 1356 1394 case '%monthnum%': 1357 $ep_mask_specific = EP_MONTH;1395 $ep_mask_specific = 'month'; 1358 1396 break; 1359 1397 case '%day%': 1360 $ep_mask_specific = EP_DAY;1398 $ep_mask_specific = 'day'; 1361 1399 break; 1362 1400 default: 1363 $ep_mask_specific = EP_NONE;1401 $ep_mask_specific = 'none'; 1364 1402 } 1365 1403 1366 1404 //create query for /page/xx … … 1399 1437 $rewrite = array_merge($rewrite, array($pagematch => $pagequery)); 1400 1438 1401 1439 //only on pages with comments add ../comment-page-xx/ 1402 if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask || EP_NONE & $ep_mask)1440 if ( array_intersect( $ep_mask, array ( 'pages', 'permalink', 'none' ) ) ) 1403 1441 $rewrite = array_merge($rewrite, array($commentmatch => $commentquery)); 1404 else if ( EP_ROOT & $ep_mask&& get_option('page_on_front') )1442 else if ( in_array( $ep_mask, 'root' ) && get_option('page_on_front') ) 1405 1443 $rewrite = array_merge($rewrite, array($rootcommentmatch => $rootcommentquery)); 1406 1444 1407 1445 //do endpoints 1408 1446 if ( $endpoints ) { 1409 1447 foreach ( (array) $ep_query_append as $regex => $ep) { 1410 1448 //add the endpoints on if the mask fits 1411 if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific)1449 if ( array_intersect( $ep[0], array( $ep_mask, $ep_mask_specific ) ) ) 1412 1450 $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2); 1413 1451 } 1414 1452 } … … 1480 1518 //do endpoints for attachments 1481 1519 if ( !empty($endpoints) ) { 1482 1520 foreach ( (array) $ep_query_append as $regex => $ep ) { 1483 if ( $ep[0] & EP_ATTACHMENT) {1521 if ( in_array( 'attachment', $ep[0] ) ) { 1484 1522 $rewrite[$sub1 . $regex] = $subquery . $ep[1] . $this->preg_index(2); 1485 1523 $rewrite[$sub2 . $regex] = $subquery . $ep[1] . $this->preg_index(2); 1486 1524 } … … 1538 1576 * @return array 1539 1577 */ 1540 1578 function generate_rewrite_rule($permalink_structure, $walk_dirs = false) { 1541 return $this->generate_rewrite_rules($permalink_structure, EP_NONE, false, false, false, $walk_dirs);1579 return $this->generate_rewrite_rules($permalink_structure, false, false, false, false, $walk_dirs); 1542 1580 } 1543 1581 1544 1582 /** … … 1577 1615 '.*wp-commentsrss2.php$' => $this->index . '?feed=rss2&withcomments=1'); 1578 1616 1579 1617 // Post 1580 $post_rewrite = $this->generate_rewrite_rules($this->permalink_structure, EP_PERMALINK);1618 $post_rewrite = $this->generate_rewrite_rules($this->permalink_structure, 'permalink'); 1581 1619 $post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite); 1582 1620 1583 1621 // Date 1584 $date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE);1622 $date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), 'date'); 1585 1623 $date_rewrite = apply_filters('date_rewrite_rules', $date_rewrite); 1586 1624 1587 1625 // Root 1588 $root_rewrite = $this->generate_rewrite_rules($this->root . '/', EP_ROOT);1626 $root_rewrite = $this->generate_rewrite_rules($this->root . '/', 'root'); 1589 1627 $root_rewrite = apply_filters('root_rewrite_rules', $root_rewrite); 1590 1628 1591 1629 // Comments 1592 $comments_rewrite = $this->generate_rewrite_rules($this->root . $this->comments_base, EP_COMMENTS, true, true, true, false);1630 $comments_rewrite = $this->generate_rewrite_rules($this->root . $this->comments_base, 'comments', true, true, true, false); 1593 1631 $comments_rewrite = apply_filters('comments_rewrite_rules', $comments_rewrite); 1594 1632 1595 1633 // Search 1596 1634 $search_structure = $this->get_search_permastruct(); 1597 $search_rewrite = $this->generate_rewrite_rules($search_structure, EP_SEARCH);1635 $search_rewrite = $this->generate_rewrite_rules($search_structure, 'search'); 1598 1636 $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite); 1599 1637 1600 1638 // Categories 1601 $category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES);1639 $category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), 'categories'); 1602 1640 $category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite); 1603 1641 1604 1642 // Tags 1605 $tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), EP_TAGS);1643 $tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), 'tags'); 1606 1644 $tag_rewrite = apply_filters('tag_rewrite_rules', $tag_rewrite); 1607 1645 1608 1646 // Authors 1609 $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);1647 $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), 'authors'); 1610 1648 $author_rewrite = apply_filters('author_rewrite_rules', $author_rewrite); 1611 1649 1612 1650 // Pages … … 1618 1656 if ( is_array($permastruct) ) 1619 1657 $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct[0], $permastruct[1])); 1620 1658 else 1621 $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct, EP_NONE));1659 $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct, false)); 1622 1660 } 1623 1661 1624 1662 // Put them together. … … 1895 1933 * @param array $places URL types that endpoint can be used. 1896 1934 */ 1897 1935 function add_endpoint($name, $places) { 1936 $this->_bitmasks_to_array( $places ); 1937 1898 1938 global $wp; 1899 1939 $this->endpoints[] = array ( $places, $name ); 1900 1940 $wp->add_query_var($name); 1901 1941 } 1902 1942 1943 function _bitmasks_to_array( &$places ) { 1944 if ( is_int( $places ) ) { 1945 $_places = array(); 1946 foreach ( $this->_bitmasks as $bit => $new ) { 1947 if ( constant( $bit ) & $places ) 1948 $_places[] = $new; 1949 } 1950 $places = $_places; 1951 } elseif ( ! is_array( $places ) ) { 1952 $places = array( 'none' ); 1953 } 1954 } 1955 1903 1956 /** 1904 1957 * Add permalink structure. 1905 1958 * … … 1913 1966 * @param string $struct Permalink structure. 1914 1967 * @param bool $with_front Prepend front base to permalink structure. 1915 1968 */ 1916 function add_permastruct($name, $struct, $with_front = true, $ep_mask = EP_NONE) { 1969 function add_permastruct($name, $struct, $with_front = true, $ep_mask = 'none' ) { 1970 $this->_bitmasks_to_array( $ep_mask ); 1917 1971 if ( $with_front ) 1918 1972 $struct = $this->front . $struct; 1919 1973 $this->extra_permastructs[$name] = array($struct, $ep_mask);