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 | |
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 | } |
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 ); |
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; |