WordPress.org

Make WordPress Core

Changeset 1570


Ignore:
Timestamp:
08/27/2004 08:59:38 PM (17 years ago)
Author:
rboren
Message:

404 permalink handler.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-blog-header.php

    r1558 r1570  
    99require_once( dirname(__FILE__) . '/wp-includes/wp-l10n.php');
    1010
    11 // Process PATH_INFO, if set.
    12 $path_info = array();
    13 if ( !empty( $_SERVER['PATH_INFO'] ) ) {
     11$query_vars = array();
     12
     13// Process PATH_INFO and 404.
     14if ((isset($_GET['error']) && $_GET['error'] == '404') ||
     15    (! empty( $_SERVER['PATH_INFO']))) {
     16
    1417    // Fetch the rewrite rules.
    1518    $rewrite = rewrite_rules('matches');
    1619
    17     $pathinfo = $_SERVER['PATH_INFO'];
    18     // Trim leading '/'.
    19     $pathinfo = preg_replace('!^/!', '', $pathinfo);
    20 
    2120    if (! empty($rewrite)) {
    22         // Get the name of the file requesting path info.
    23         $req_uri = $_SERVER['REQUEST_URI'];
     21        $pathinfo = $_SERVER['PATH_INFO'];
     22    $req_uri = $_SERVER['REQUEST_URI'];     
     23    $home_path = parse_url(get_settings('home'));
     24    $home_path = $home_path['path'];
     25
     26    // Trim path info from the end and the leading home path from the
     27    // front.  For path info requests, this leaves us with the requesting
     28    // filename, if any.  For 404 requests, this leaves us with the
     29    // requested permalink.
    2430        $req_uri = str_replace($pathinfo, '', $req_uri);
    25         $req_uri = preg_replace("!/+$!", '', $req_uri);
    26         $req_uri = explode('/', $req_uri);
    27         $req_uri = $req_uri[count($req_uri)-1];
     31    $req_uri = str_replace($home_path, '', $req_uri);
     32    $req_uri = trim($req_uri, '/');
     33    $pathinfo = trim($pathinfo, '/');
     34
     35    // The requested permalink is in $pathinfo for path info requests and
     36    //  $req_uri for other requests.
     37    if (! empty($pathinfo)) {
     38      $request = $pathinfo;
     39    } else {
     40      $request = $req_uri;
     41    }
    2842
    2943        // Look for matches.
    30         $pathinfomatch = $pathinfo;
     44    $request_match = $request;
    3145        foreach ($rewrite as $match => $query) {
    32             // If the request URI is the anchor of the match, prepend it
     46            // If the requesting file is the anchor of the match, prepend it
    3347            // to the path info.
    34             if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0)) {
    35                 $pathinfomatch = $req_uri . '/' . $pathinfo;
    36             }
    37 
    38             if (preg_match("!^$match!", $pathinfomatch, $matches)) {
     48        if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0)) {
     49          $request_match = $req_uri . '/' . $request;
     50        }
     51
     52            if (preg_match("!^$match!", $request_match, $matches)) {
    3953                // Got a match.
    4054                // Trim the query of everything up to the '?'.
     
    4559
    4660                // Parse the query.
    47                 parse_str($query, $path_info);
     61                parse_str($query, $query_vars);
     62
     63        // If we're processing a 404 request, clear the error var
     64        // since we found something.
     65        if (isset($_GET['error'])) {
     66            unset($_GET['error']);
     67        }
     68
    4869                break;
    4970            }
    5071        }
    51     }   
    52 }
    53 
    54 $wpvarstoreset = array('m','p','posts','w', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename');
     72    }
     73}
     74
     75$wpvarstoreset = array('m','p','posts','w', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'error');
    5576
    5677for ($i=0; $i<count($wpvarstoreset); $i += 1) {
     
    5879    if (!isset($$wpvar)) {
    5980        if (empty($_POST[$wpvar])) {
    60             if (empty($_GET[$wpvar]) && empty($path_info[$wpvar])) {
     81            if (empty($_GET[$wpvar]) && empty($query_vars[$wpvar])) {
    6182                $$wpvar = '';
    6283            } elseif (!empty($_GET[$wpvar])) {
    6384                $$wpvar = $_GET[$wpvar];
    6485            } else {
    65                 $$wpvar = $path_info[$wpvar];
     86                $$wpvar = $query_vars[$wpvar];
    6687            }
    6788        } else {
     
    200221  include(ABSPATH . 'wp-content/search.php');
    201222  exit;
     223} else if (is_404() && (! isset($wp_did_404)) &&
     224       file_exists(ABSPATH . 'wp-content/404.php')) {
     225  $wp_did_404 = true;
     226  include(ABSPATH . 'wp-content/404.php');
     227  exit;
    202228} else if (is_feed() && $pagenow != 'wp-feed.php') {
    203229  include(dirname(__FILE__) . '/wp-feed.php');
  • trunk/wp-includes/classes.php

    r1558 r1570  
    2323    var $is_feed = false;
    2424    var $is_home = false;
     25    var $is_404 = false;
    2526
    2627    function init () {
     
    3839        $this->is_feed = false;
    3940        $this->is_home = false;
     41        $this->is_404 = false;
    4042
    4143        unset($this->posts);
     
    161163        }
    162164
     165        if ('' != $qv['error'] || '404' == $qv['pagename']) {
     166            $this->is_404 = true;
     167        }
     168
    163169        if ( ($this->is_date || $this->is_author || $this->is_category)
    164170             && (! ($this->is_single || $this->is_page)) ) {
     
    166172        }
    167173
    168         if ( ! ($this->is_archive || $this->is_single || $this->is_page || $this->is_search || $this->is_feed)) {
     174        if ( ! ($this->is_archive || $this->is_single || $this->is_page || $this->is_search || $this->is_feed || $this->is_404)) {
    169175            $this->is_home = true;
    170176        }
  • trunk/wp-includes/functions.php

    r1558 r1570  
    16631663}
    16641664
     1665function is_404 () {
     1666    global $wp_query;
     1667
     1668    return $wp_query->is_404;
     1669}
     1670
    16651671function get_query_var($var) {
    16661672  global $wp_query;
Note: See TracChangeset for help on using the changeset viewer.