Make WordPress Core

Changeset 3229


Ignore:
Timestamp:
11/29/2005 01:43:32 AM (18 years ago)
Author:
ryan
Message:

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

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/classes.php

    r3226 r3229  
    258258        $whichcat = '';
    259259        $whichauthor = '';
     260        $whichpage = '';
    260261        $result = '';
    261262        $where = '';
     
    351352            $where .= " AND post_name = '" . $q['name'] . "'";
    352353        } else if ('' != $q['pagename']) {
    353             $q['pagename'] = sanitize_title(basename(str_replace('%2F', '/', urlencode($q['pagename']))));
     354            $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
     355            $page_paths = '/' . trim($q['pagename'], '/');
     356            $q['pagename'] = sanitize_title(basename($page_paths));
    354357            $q['name'] = $q['pagename'];
    355             $where .= " AND post_name = '" . $q['pagename'] . "'";
     358            $page_paths = explode('/', $page_paths);
     359            foreach($page_paths as $pathdir)
     360                $page_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
     361               
     362            $all_page_ids = get_all_page_ids();
     363            $reqpage = 0;           
     364            foreach ( $all_page_ids as $page_id ) {
     365                $page = get_page($page_id);
     366                if ( $page->fullpath == $page_path ) {
     367                    $reqpage = $page_id;
     368                    break;
     369                }
     370            }
     371           
     372            $where .= " AND (ID = '$reqpage')";
    356373        } elseif ('' != $q['attachment']) {
    357374            $q['attachment'] = sanitize_title($q['attachment']);
     
    512529            $whichauthor .= ' AND (post_author = '.intval($q['author']).')';
    513530        }
    514 
     531       
    515532        $where .= $search.$whichcat.$whichauthor;
    516533
     
    14671484                }
    14681485
    1469                 if (preg_match("!^$match!", $request_match, $matches)) {
     1486                if (preg_match("!^$match!", $request_match, $matches) ||
     1487                    preg_match("!^$match!", urldecode($request_match), $matches)) {
    14701488                    // Got a match.
    14711489                    $this->matched_rule = $match;
  • trunk/wp-includes/functions.php

    r3220 r3229  
    586586}
    587587
     588function set_page_path($page) {
     589    $page->fullpath = '/' . $page->post_name;
     590    $path = $page->fullpath;
     591    $curpage = $page;
     592    while ($curpage->post_parent != 0) {
     593        $curpage = get_page($curpage->post_parent);
     594        $path = '/' . $curpage->post_name . $path;
     595    }
     596   
     597    $page->fullpath = $path;
     598
     599    return $page;
     600}
     601
    588602// Retrieves page data given a page ID or page object.
    589603// Handles page caching.
     
    613627        }
    614628    }
     629   
     630    if (!isset($_page->fullpath)) {
     631        $_page = set_page_path($_page);
     632        wp_cache_replace($_page->cat_ID, $_page, 'pages');
     633    }
    615634
    616635    if ( $output == OBJECT ) {
     
    719738   
    720739    return $cat_ids;
     740}
     741
     742function get_all_page_ids() {
     743    global $wpdb;
     744   
     745    if ( ! $page_ids = wp_cache_get('all_page_ids', 'posts') ) {
     746        $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status='static'");
     747        wp_cache_add('all_page_ids', $page_ids, 'pages');
     748    }
     749   
     750    return $page_ids;
    721751}
    722752
  • trunk/wp-includes/template-functions-post.php

    r3217 r3229  
    284284        }
    285285    }
    286 
    287286    return $page_list;
    288287}
Note: See TracChangeset for help on using the changeset viewer.