Use the full page hierarchy when matching page URIs. Props David House. fixes #1964

git-svn-id: https://develop.svn.wordpress.org/trunk@3229 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2005-11-29 01:43:32 +00:00
parent a2e0b5f3cc
commit 5e34745dc9
3 changed files with 52 additions and 5 deletions

View File

@ -257,6 +257,7 @@ class WP_Query {
// First let's clear some variables
$whichcat = '';
$whichauthor = '';
$whichpage = '';
$result = '';
$where = '';
$limits = '';
@ -350,9 +351,25 @@ class WP_Query {
$q['name'] = sanitize_title($q['name']);
$where .= " AND post_name = '" . $q['name'] . "'";
} else if ('' != $q['pagename']) {
$q['pagename'] = sanitize_title(basename(str_replace('%2F', '/', urlencode($q['pagename']))));
$q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
$page_paths = '/' . trim($q['pagename'], '/');
$q['pagename'] = sanitize_title(basename($page_paths));
$q['name'] = $q['pagename'];
$where .= " AND post_name = '" . $q['pagename'] . "'";
$page_paths = explode('/', $page_paths);
foreach($page_paths as $pathdir)
$page_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
$all_page_ids = get_all_page_ids();
$reqpage = 0;
foreach ( $all_page_ids as $page_id ) {
$page = get_page($page_id);
if ( $page->fullpath == $page_path ) {
$reqpage = $page_id;
break;
}
}
$where .= " AND (ID = '$reqpage')";
} elseif ('' != $q['attachment']) {
$q['attachment'] = sanitize_title($q['attachment']);
$q['name'] = $q['attachment'];
@ -511,7 +528,7 @@ class WP_Query {
$q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'");
$whichauthor .= ' AND (post_author = '.intval($q['author']).')';
}
$where .= $search.$whichcat.$whichauthor;
if ((empty($q['order'])) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC'))) {
@ -1466,7 +1483,8 @@ class WP {
$request_match = $req_uri . '/' . $request;
}
if (preg_match("!^$match!", $request_match, $matches)) {
if (preg_match("!^$match!", $request_match, $matches) ||
preg_match("!^$match!", urldecode($request_match), $matches)) {
// Got a match.
$this->matched_rule = $match;

View File

@ -585,6 +585,20 @@ function &get_post(&$post, $output = OBJECT) {
}
}
function set_page_path($page) {
$page->fullpath = '/' . $page->post_name;
$path = $page->fullpath;
$curpage = $page;
while ($curpage->post_parent != 0) {
$curpage = get_page($curpage->post_parent);
$path = '/' . $curpage->post_name . $path;
}
$page->fullpath = $path;
return $page;
}
// Retrieves page data given a page ID or page object.
// Handles page caching.
function &get_page(&$page, $output = OBJECT) {
@ -612,6 +626,11 @@ function &get_page(&$page, $output = OBJECT) {
wp_cache_add($_page->ID, $_page, 'pages');
}
}
if (!isset($_page->fullpath)) {
$_page = set_page_path($_page);
wp_cache_replace($_page->cat_ID, $_page, 'pages');
}
if ( $output == OBJECT ) {
return $_page;
@ -720,6 +739,17 @@ function get_all_category_ids() {
return $cat_ids;
}
function get_all_page_ids() {
global $wpdb;
if ( ! $page_ids = wp_cache_get('all_page_ids', 'posts') ) {
$page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status='static'");
wp_cache_add('all_page_ids', $page_ids, 'pages');
}
return $page_ids;
}
function gzip_compression() {
if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') ) return false;
if ( !get_settings('gzipcompression') ) return false;

View File

@ -283,7 +283,6 @@ function &get_page_children($page_id, $pages) {
$page_list = array_merge($page_list, $children);
}
}
return $page_list;
}