Make WordPress Core

Ticket #3930: 3930.diff

File 3930.diff, 4.0 KB (added by rob1n, 18 years ago)
  • wp-includes/link-template.php

     
    464464
    465465function get_pagenum_link($pagenum = 1) {
    466466        global $wp_rewrite;
    467 
    468         $qstr = $_SERVER['REQUEST_URI'];
    469 
    470         $page_querystring = "paged";
    471         $page_modstring = "page/";
    472         $page_modregex = "page/?";
    473         $permalink = 0;
    474 
     467       
     468        $pagenum = (int) $pagenum;
     469       
     470        $request = remove_query_arg( 'paged' );
     471       
    475472        $home_root = parse_url(get_option('home'));
    476473        $home_root = $home_root['path'];
    477         $home_root = trailingslashit($home_root);
    478         $qstr = preg_replace('|^'. $home_root . '|', '', $qstr);
    479         $qstr = preg_replace('|^/+|', '', $qstr);
    480 
     474        $home_root = preg_quote( trailingslashit( $home_root ), '|' );
     475       
     476        $request = preg_replace('|^'. $home_root . '|', '', $qstr);
     477        $request = preg_replace('|^/+|', '', $qstr);
     478       
    481479        $index = $_SERVER['PHP_SELF'];
    482480        $index = preg_replace('|^'. $home_root . '|', '', $index);
    483481        $index = preg_replace('|^/+|', '', $index);
    484 
    485         // if we already have a QUERY style page string
    486         if ( stripos( $qstr, $page_querystring ) !== false ) {
    487                 $replacement = "$page_querystring=$pagenum";
    488                 $qstr = preg_replace("/".$page_querystring."[^\d]+\d+/", $replacement, $qstr);
    489                 // if we already have a mod_rewrite style page string
    490         } elseif ( preg_match( '|'.$page_modregex.'\d+|', $qstr ) ) {
    491                 $permalink = 1;
    492                 $qstr = preg_replace('|'.$page_modregex.'\d+|',"$page_modstring$pagenum",$qstr);
    493 
    494                 // if we don't have a page string at all ...
    495                 // lets see what sort of URL we have...
     482       
     483        if ( !$wp_rewrite->using_permalinks() ) {
     484                $base = trailingslashit( get_bloginfo( 'home' ) );
     485               
     486                if ( $pagenum > 1 ) {
     487                        $result = add_query_arg( 'paged', $pagenum, $request );
     488                } else {
     489                        $result = $base . $request;
     490                }
    496491        } else {
    497                 // we need to know the way queries are being written
    498                 // if there's a querystring_start (a "?" usually), it's definitely not mod_rewritten
    499                 if ( stripos( $qstr, '?' ) !== false ) {
    500                         // so append the query string (using &, since we already have ?)
    501                         $qstr .=        '&' . $page_querystring . '=' . $pagenum;
    502                         // otherwise, it could be rewritten, OR just the default index ...
    503                 } elseif( '' != get_option('permalink_structure') && ! is_admin() ) {
    504                         $permalink = 1;
    505                         $index = $wp_rewrite->index;
    506                         // If it's not a path info permalink structure, trim the index.
    507                         if ( !$wp_rewrite->using_index_permalinks() ) {
    508                                 $qstr = preg_replace("#/*" . $index . "/*#", '/', $qstr);
    509                         } else {
    510                                 // If using path info style permalinks, make sure the index is in
    511                                 // the URL.
    512                                 if ( strpos($qstr, $index) === false )
    513                                         $qstr = '/' . $index . $qstr;
    514                         }
    515 
    516                         $qstr = trailingslashit($qstr) . $page_modstring . $pagenum;
     492                $qs_regex = '|\?.*?$|';
     493                preg_match( $qs_regex, $request, $qs_match );
     494               
     495                if ( $qs_match[0] ) {
     496                        $query_string = $qs_match[0];
     497                        $request = preg_replace( $qs_regex, '', $request );
    517498                } else {
    518                         $qstr = $index . '?' . $page_querystring . '=' . $pagenum;
     499                        $query_string = '';
    519500                }
     501               
     502                $base = get_bloginfo( 'home' ) . '/';
     503               
     504                if ( $wp_rewrite->using_index_permalinks() && $pagenum > 1 ) {
     505                        $base .= 'index.php/';
     506                }
     507               
     508                $request = ( $pagenum > 1 ) ? $request . user_trailingslashit( 'page/' . $pagenum, 'paged' ) : $request;
     509                $result = $base . $request . $query_string;
    520510        }
    521 
    522         $qstr = preg_replace('|^/+|', '', $qstr);
    523         if ( $permalink )
    524                 $qstr = user_trailingslashit($qstr, 'paged');
    525         $qstr = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', trailingslashit( get_option('home') ) . $qstr );
    526 
    527         // showing /page/1/ or ?paged=1 is redundant
    528         if ( 1 === $pagenum ) {
    529                 $qstr = str_replace(user_trailingslashit('index.php/page/1', 'paged'), '', $qstr); // for PATHINFO style
    530                 $qstr = str_replace(user_trailingslashit('page/1', 'paged'), '', $qstr); // for mod_rewrite style
    531                 $qstr = remove_query_arg('paged', $qstr); // for query style
    532         }
    533         return $qstr;
     511       
     512        return $result;
    534513}
    535514
    536515function get_next_posts_page_link($max_page = 0) {