Rewrite rule generation cleanup, including re-indent.
git-svn-id: http://svn.automattic.com/wordpress/trunk@1870 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
acbad8e480
commit
81bb103348
|
@ -1420,7 +1420,7 @@ function get_day_permastruct($permalink_structure = '') {
|
||||||
return get_date_permastruct($permalink_structure);
|
return get_date_permastruct($permalink_structure);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generate_rewrite_rules($permalink_structure = '', $matches = '') {
|
function generate_rewrite_rules($permalink_structure = '', $matches = '', $forcomments = false) {
|
||||||
$rewritecode =
|
$rewritecode =
|
||||||
array(
|
array(
|
||||||
'%year%',
|
'%year%',
|
||||||
|
@ -1469,7 +1469,9 @@ function generate_rewrite_rules($permalink_structure = '', $matches = '') {
|
||||||
's='
|
's='
|
||||||
);
|
);
|
||||||
|
|
||||||
$feedregex = '(feed|rdf|rss|rss2|atom)/?$';
|
$feedregex2 = '(feed|rdf|rss|rss2|atom)/?$';
|
||||||
|
$feedregex = 'feed/' . $feedregex2;
|
||||||
|
|
||||||
$trackbackregex = 'trackback/?$';
|
$trackbackregex = 'trackback/?$';
|
||||||
$pageregex = 'page/?([0-9]{1,})/?$';
|
$pageregex = 'page/?([0-9]{1,})/?$';
|
||||||
|
|
||||||
|
@ -1504,6 +1506,7 @@ function generate_rewrite_rules($permalink_structure = '', $matches = '') {
|
||||||
$struct = $front;
|
$struct = $front;
|
||||||
for ($j = 0; $j < $num_dirs; ++$j) {
|
for ($j = 0; $j < $num_dirs; ++$j) {
|
||||||
$struct .= $dirs[$j] . '/';
|
$struct .= $dirs[$j] . '/';
|
||||||
|
$struct = ltrim($struct, '/');
|
||||||
$match = str_replace($rewritecode, $rewritereplace, $struct);
|
$match = str_replace($rewritecode, $rewritereplace, $struct);
|
||||||
$num_toks = preg_match_all('/%.+?%/', $struct, $toks);
|
$num_toks = preg_match_all('/%.+?%/', $struct, $toks);
|
||||||
$query = $queries[$num_toks - 1];
|
$query = $queries[$num_toks - 1];
|
||||||
|
@ -1514,6 +1517,17 @@ function generate_rewrite_rules($permalink_structure = '', $matches = '') {
|
||||||
$feedmatch = $match . $feedregex;
|
$feedmatch = $match . $feedregex;
|
||||||
$feedquery = $feedindex . '?' . $query . '&feed=' . preg_index($num_toks + 1, $matches);
|
$feedquery = $feedindex . '?' . $query . '&feed=' . preg_index($num_toks + 1, $matches);
|
||||||
|
|
||||||
|
$feedmatch2 = $match . $feedregex2;
|
||||||
|
$feedquery2 = $feedindex . '?' . $query . '&feed=' . preg_index($num_toks + 1, $matches);
|
||||||
|
|
||||||
|
if ($forcomments) {
|
||||||
|
$feedquery .= '&withcomments=1';
|
||||||
|
$feedquery2 .= '&withcomments=1';
|
||||||
|
}
|
||||||
|
|
||||||
|
$rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2, $pagematch => $pagequery);
|
||||||
|
|
||||||
|
if ($num_toks) {
|
||||||
$post = 0;
|
$post = 0;
|
||||||
if (strstr($struct, '%postname%') || strstr($struct, '%post_id%')
|
if (strstr($struct, '%postname%') || strstr($struct, '%post_id%')
|
||||||
|| (strstr($struct, '%year%') && strstr($struct, '%monthnum%') && strstr($struct, '%day%') && strstr($struct, '%hour%') && strstr($struct, '%minute') && strstr($struct, '%second%'))) {
|
|| (strstr($struct, '%year%') && strstr($struct, '%monthnum%') && strstr($struct, '%day%') && strstr($struct, '%hour%') && strstr($struct, '%minute') && strstr($struct, '%second%'))) {
|
||||||
|
@ -1527,13 +1541,16 @@ function generate_rewrite_rules($permalink_structure = '', $matches = '') {
|
||||||
$query = $index . '?' . $query;
|
$query = $index . '?' . $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_rewrite = array($feedmatch => $feedquery, $pagematch => $pagequery, $match => $query) + $post_rewrite;
|
$rewrite = $rewrite + array($match => $query);
|
||||||
|
|
||||||
if ($post) {
|
if ($post) {
|
||||||
$post_rewrite = array($trackbackmatch => $trackbackquery) + $post_rewrite;
|
$rewrite = array($trackbackmatch => $trackbackquery) + $rewrite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$post_rewrite = $rewrite + $post_rewrite;
|
||||||
|
}
|
||||||
|
|
||||||
return $post_rewrite;
|
return $post_rewrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1554,10 +1571,6 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_rewrite = generate_rewrite_rules($permalink_structure, $matches);
|
|
||||||
|
|
||||||
$feedregex = '(feed|rdf|rss|rss2|atom)/?$';
|
|
||||||
$pageregex = 'page/?([0-9]{1,})/?$';
|
|
||||||
$front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
|
$front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
|
||||||
$index = 'index.php';
|
$index = 'index.php';
|
||||||
$prefix = '';
|
$prefix = '';
|
||||||
|
@ -1565,26 +1578,17 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
|
||||||
$prefix = $index . '/';
|
$prefix = $index . '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate date rules.
|
// Post
|
||||||
|
$post_rewrite = generate_rewrite_rules($permalink_structure, $matches);
|
||||||
|
|
||||||
|
// Date
|
||||||
$date_rewrite = generate_rewrite_rules(get_date_permastruct($permalink_structure), $matches);
|
$date_rewrite = generate_rewrite_rules(get_date_permastruct($permalink_structure), $matches);
|
||||||
|
|
||||||
// Site feed
|
// Root
|
||||||
$sitefeedmatch = $prefix . 'feed/?([_0-9a-z-]+)?/?$';
|
$root_rewrite = generate_rewrite_rules($prefix . '/', $matches);
|
||||||
$sitefeedquery = 'index.php?feed=_' . preg_index(1, $matches);
|
|
||||||
|
|
||||||
// Site comment feed
|
// Comments
|
||||||
$sitecommentfeedmatch = $prefix . 'comments/feed/?([_0-9a-z-]+)?/?$';
|
$comments_rewrite = generate_rewrite_rules($prefix . 'comments', $matches, true);
|
||||||
$sitecommentfeedquery = 'index.php?feed=_' . preg_index(1, $matches) . '&withcomments=1';
|
|
||||||
|
|
||||||
// Site page
|
|
||||||
$sitepagematch = $prefix . $pageregex;
|
|
||||||
$sitepagequery = 'index.php?paged=' . preg_index(1, $matches);
|
|
||||||
|
|
||||||
$site_rewrite = array(
|
|
||||||
$sitefeedmatch => $sitefeedquery,
|
|
||||||
$sitecommentfeedmatch => $sitecommentfeedquery,
|
|
||||||
$sitepagematch => $sitepagequery,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
$search_structure = $prefix . "search/%search%";
|
$search_structure = $prefix . "search/%search%";
|
||||||
|
@ -1603,17 +1607,15 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
|
||||||
$author_structure = $front . 'author/%author%';
|
$author_structure = $front . 'author/%author%';
|
||||||
$author_rewrite = generate_rewrite_rules($author_structure, $matches);
|
$author_rewrite = generate_rewrite_rules($author_structure, $matches);
|
||||||
|
|
||||||
// Site static pages
|
|
||||||
$page_structure = $prefix . 'site/%pagename%';
|
|
||||||
$page_rewrite = generate_rewrite_rules($page_structure, $matches);
|
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
$pages_rewrite = page_rewrite_rules();
|
$page_rewrite = page_rewrite_rules();
|
||||||
|
|
||||||
|
// Deprecated style static pages
|
||||||
|
$page_structure = $prefix . 'site/%pagename%';
|
||||||
|
$old_page_rewrite = generate_rewrite_rules($page_structure, $matches);
|
||||||
|
|
||||||
// Put them together.
|
// Put them together.
|
||||||
$rewrite = $pages_rewrite + $site_rewrite + $page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite;
|
$rewrite = $page_rewrite + $root_rewrite + $comments_rewrite + $old_page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite + $post_rewrite;
|
||||||
|
|
||||||
$rewrite = $rewrite + $post_rewrite;
|
|
||||||
|
|
||||||
$rewrite = apply_filters('rewrite_rules_array', $rewrite);
|
$rewrite = apply_filters('rewrite_rules_array', $rewrite);
|
||||||
return $rewrite;
|
return $rewrite;
|
||||||
|
|
Loading…
Reference in New Issue