Changeset 4495 for trunk/wp-includes/rewrite.php
- Timestamp:
- 11/19/2006 07:56:05 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/rewrite.php (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/rewrite.php
r4279 r4495 17 17 return; 18 18 } 19 19 20 20 $qv = trim($tagname, '%'); 21 21 22 22 global $wp_rewrite, $wp; 23 23 $wp->add_query_var($qv); … … 25 25 } 26 26 27 //Add a new feed type like /atom1/ 27 //Add a new feed type like /atom1/ 28 28 function add_feed($feedname, $function) { 29 29 global $wp_rewrite; … … 170 170 var $endpoints; 171 171 var $use_verbose_rules = false; 172 var $rewritecode = 172 var $rewritecode = 173 173 array( 174 174 '%year%', … … 186 186 ); 187 187 188 var $rewritereplace = 188 var $rewritereplace = 189 189 array( 190 190 '([0-9]{4})', … … 202 202 ); 203 203 204 var $queryreplace = 204 var $queryreplace = 205 205 array ( 206 206 'year=', … … 219 219 220 220 var $feeds = array ( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); 221 221 222 222 function using_permalinks() { 223 223 if (empty($this->permalink_structure)) … … 236 236 return true; 237 237 } 238 238 239 239 return false; 240 240 } … … 252 252 253 253 if (! empty($this->matches)) { 254 $match_prefix = '$' . $this->matches . '['; 254 $match_prefix = '$' . $this->matches . '['; 255 255 $match_suffix = ']'; 256 } 257 258 return "$match_prefix$number$match_suffix"; 256 } 257 258 return "$match_prefix$number$match_suffix"; 259 259 } 260 260 … … 302 302 break; 303 303 } 304 } 304 } 305 305 306 306 if ( empty($date_endian) ) … … 308 308 309 309 // Do not allow the date tags and %post_id% to overlap in the permalink 310 // structure. If they do, move the date tags to $front/date/. 310 // structure. If they do, move the date tags to $front/date/. 311 311 $front = $this->front; 312 312 preg_match_all('/%.+?%/', $this->permalink_structure, $tokens); … … 483 483 $trackbackregex = 'trackback/?$'; 484 484 $pageregex = 'page/?([0-9]{1,})/?$'; 485 485 486 486 //build up an array of endpoint regexes to append => queries to append 487 487 if ($endpoints) { 488 488 $ep_query_append = array (); 489 foreach ($this->endpoints as $endpoint) { 489 foreach ($this->endpoints as $endpoint) { 490 490 //match everything after the endpoint name, but allow for nothing to appear there 491 491 $epmatch = $endpoint[1] . '(/(.*))?/?$'; … … 512 512 $queries[$i] = $queries[$i - 1] . '&'; 513 513 } 514 514 515 515 $query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1); 516 516 $queries[$i] .= $query_token; … … 549 549 //get the 'tagname=$matches[i]' 550 550 $query = $queries[$num_toks - 1]; 551 551 552 552 //set up $ep_mask_specific which is used to match more specific URL types 553 553 switch ($dirs[$j]) { … … 581 581 if ($paged) //...and /page/xx ones 582 582 $rewrite = array_merge($rewrite, array($pagematch => $pagequery)); 583 583 584 584 //if we've got some tags in this dir 585 585 if ($num_toks) { 586 586 $post = false; 587 587 $page = false; 588 589 //check to see if this dir is permalink-level: i.e. the structure specifies an 588 589 //check to see if this dir is permalink-level: i.e. the structure specifies an 590 590 //individual post. Do this by checking it contains at least one of 1) post name, 591 //2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and 591 //2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and 592 592 //minute all present). Set these flags now as we need them for the endpoints. 593 593 if (strstr($struct, '%postname%') || strstr($struct, '%post_id%') … … 598 598 $page = true; 599 599 } 600 600 601 601 //do endpoints 602 602 if ($endpoints) { … … 608 608 } 609 609 } 610 610 611 611 //if we're creating rules for a permalink, do all the endpoints like attachments etc 612 612 if ($post) { … … 619 619 //get rid of brackets 620 620 $submatchbase = str_replace(array('(',')'),'',$match); 621 621 622 622 //add a rule for at attachments, which take the form of <permalink>/some-text 623 623 $sub1 = $submatchbase . '/([^/]+)/'; … … 627 627 //add an ? as we don't have to match that last slash, and finally a $ so we 628 628 //match to the end of the URL 629 629 630 630 //add another rule to match attachments in the explicit form: 631 631 //<permalink>/attachment/some-text … … 634 634 $sub2feed = $sub2 . $feedregex; //feeds, <permalink>/attachment/feed/(atom|...) 635 635 $sub2feed2 = $sub2 . $feedregex2; //and feeds again on to this <permalink>/attachment/(feed|atom...) 636 636 637 637 //create queries for these extra tag-ons we've just dealt with 638 638 $subquery = $index . '?attachment=' . $this->preg_index(1); 639 639 $subtbquery = $subquery . '&tb=1'; 640 640 $subfeedquery = $subquery . '&feed=' . $this->preg_index(2); 641 641 642 642 //do endpoints for attachments 643 643 if ($endpoint) { foreach ($ep_query_append as $regex => $ep) { … … 647 647 } 648 648 } } 649 649 650 650 //now we've finished with endpoints, finish off the $sub1 and $sub2 matches 651 651 $sub1 .= '?$'; 652 652 $sub2 .= '?$'; 653 653 654 654 //allow URLs like <permalink>/2 for <permalink>/page/2 655 655 $match = $match . '(/[0-9]+)?/?$'; … … 660 660 $query = $index . '?' . $query; 661 661 } 662 662 663 663 //create the final array for this dir by joining the $rewrite array (which currently 664 664 //only contains rules/queries for trackback, pages etc) to the main regex/query for … … 670 670 //add trackback 671 671 $rewrite = array_merge(array($trackbackmatch => $trackbackquery), $rewrite); 672 672 673 673 //add regexes/queries for attachments, attachment trackbacks and so on 674 674 if ( ! $page ) //require <permalink>/attachment/stuff form for pages because of confusion with subpages … … 764 764 $home_root = parse_url(get_option('home')); 765 765 $home_root = trailingslashit($home_root['path']); 766 766 767 767 $rules = "<IfModule mod_rewrite.c>\n"; 768 768 $rules .= "RewriteEngine On\n"; 769 769 $rules .= "RewriteBase $home_root\n"; 770 770 771 771 //add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all) 772 772 foreach ($this->non_wp_rules as $match => $query) { … … 820 820 return $rules; 821 821 } 822 822 823 823 //Add a straight rewrite rule 824 824 function add_rule($regex, $redirect) { … … 832 832 } 833 833 } 834 834 835 835 //add a rule that doesn't redirect to index.php 836 836 function add_external_rule($regex, $redirect) { 837 837 $this->non_wp_rules[$regex] = $redirect; 838 838 } 839 839 840 840 //add an endpoint, like /trackback/, to be inserted after certain URL types (specified in $places) 841 841 function add_endpoint($name, $places) {
Note: See TracChangeset
for help on using the changeset viewer.