From efce6979b1eafa0250536355dc600f35f4c0e3f1 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 29 Nov 2005 01:43:32 +0000 Subject: [PATCH] Use the full page hierarchy when matching page URIs. Props David House. fixes #1964 git-svn-id: http://svn.automattic.com/wordpress/trunk@3229 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/classes.php | 26 +++++++++++++++++---- wp-includes/functions.php | 30 +++++++++++++++++++++++++ wp-includes/template-functions-post.php | 1 - 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/wp-includes/classes.php b/wp-includes/classes.php index dbb2521607..6264b15777 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -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; diff --git a/wp-includes/functions.php b/wp-includes/functions.php index e5fb89c9c4..73b1f9d19c 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -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; diff --git a/wp-includes/template-functions-post.php b/wp-includes/template-functions-post.php index 9b72900866..be4d97776e 100644 --- a/wp-includes/template-functions-post.php +++ b/wp-includes/template-functions-post.php @@ -283,7 +283,6 @@ function &get_page_children($page_id, $pages) { $page_list = array_merge($page_list, $children); } } - return $page_list; }