From 5bde51754dabcb8b28b05f69f4100af6f7310349 Mon Sep 17 00:00:00 2001 From: rboren Date: Tue, 25 Jan 2005 00:23:57 +0000 Subject: [PATCH] Generate feed and trackback rules for pages. Bug 742. git-svn-id: http://svn.automattic.com/wordpress/trunk@2146 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/classes.php | 22 +++++++++++++++++----- wp-trackback.php | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/wp-includes/classes.php b/wp-includes/classes.php index f9122f821c..56d8b53ea9 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -282,7 +282,7 @@ class WP_Query { $q['name'] = sanitize_title($q['name']); $where .= " AND post_name = '" . $q['name'] . "'"; } else if ('' != $q['pagename']) { - $q['pagename'] = sanitize_title($q['pagename']); + $q['pagename'] = sanitize_title(basename($q['pagename'])); $q['name'] = $q['pagename']; $where .= " AND post_name = '" . $q['pagename'] . "'"; } @@ -821,10 +821,12 @@ class WP_Rewrite { $uris = get_settings('page_uris'); $rewrite_rules = array(); + $page_structure = '/%pagename%'; if( is_array( $uris ) ) { foreach ($uris as $uri => $pagename) { - $rewrite_rules += array($uri . '/?$' => "index.php?pagename=" . urldecode($pagename)); + $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename='); + $rewrite_rules += $this->generate_rewrite_rules($page_structure); } } @@ -929,9 +931,18 @@ class WP_Rewrite { } function add_rewrite_tag($tag, $pattern, $query) { - $this->rewritecode[] = $tag; - $this->rewritereplace[] = $pattern; - $this->queryreplace[] = $query; + // If the tag already exists, replace the existing pattern and query for + // that tag, otherwise add the new tag, pattern, and query to the end of + // the arrays. + $position = array_search($tag, $this->rewritecode); + if (FALSE !== $position && NULL !== $position) { + $this->rewritereplace[$position] = $pattern; + $this->queryreplace[$position] = $query; + } else { + $this->rewritecode[] = $tag; + $this->rewritereplace[] = $pattern; + $this->queryreplace[] = $query; + } } function generate_rewrite_rules($permalink_structure, $page = true, $feed = true, $forcomments = false, $walk_dirs = true) { @@ -1004,6 +1015,7 @@ class WP_Rewrite { if ($num_toks) { $post = 0; if (strstr($struct, '%postname%') || strstr($struct, '%post_id%') + || strstr($struct, '%pagename%') || (strstr($struct, '%year%') && strstr($struct, '%monthnum%') && strstr($struct, '%day%') && strstr($struct, '%hour%') && strstr($struct, '%minute') && strstr($struct, '%second%'))) { $post = 1; $trackbackmatch = $match . $trackbackregex; diff --git a/wp-trackback.php b/wp-trackback.php index 38af11d753..9791594d7f 100644 --- a/wp-trackback.php +++ b/wp-trackback.php @@ -48,7 +48,7 @@ if ( function_exists('mb_convert_encoding') ) { // For international trackbacks $blog_name = mb_convert_encoding($blog_name, get_settings('blog_charset'), $charset); } -if ( is_single() ) +if ( is_single() || is_page() ) $tb_id = $posts[0]->ID; if ( !$tb_id )