434 | | $home_root = trailingslashit($home_root); |
435 | | $qstr = preg_replace('|^'. $home_root . '|', '', $qstr); |
436 | | $qstr = preg_replace('|^/+|', '', $qstr); |
| 439 | $home_root = preg_quote(trailingslashit($home_root), '|'); |
| 440 | $request = preg_replace('|^'. $home_root . '|', '', $request); |
| 441 | $request = preg_replace('|^/+|', '', $request); |
438 | | $index = $_SERVER['PHP_SELF']; |
439 | | $index = preg_replace('|^'. $home_root . '|', '', $index); |
440 | | $index = preg_replace('|^/+|', '', $index); |
441 | | |
442 | | // if we already have a QUERY style page string |
443 | | if ( stristr( $qstr, $page_querystring ) ) { |
444 | | $replacement = "$page_querystring=$pagenum"; |
445 | | $qstr = preg_replace("/".$page_querystring."[^\d]+\d+/", $replacement, $qstr); |
446 | | // if we already have a mod_rewrite style page string |
447 | | } elseif ( preg_match( '|'.$page_modregex.'\d+|', $qstr ) ) { |
448 | | $permalink = 1; |
449 | | $qstr = preg_replace('|'.$page_modregex.'\d+|',"$page_modstring$pagenum",$qstr); |
450 | | |
451 | | // if we don't have a page string at all ... |
452 | | // lets see what sort of URL we have... |
| 443 | if ( !$wp_rewrite->using_permalinks() ) { |
| 444 | $base = trailingslashit($get_option('home')); |
| 445 | if ( $pagenum > 1 ) |
| 446 | $result = $base . add_query_arg('paged', $pagenum, $request); |
| 447 | else |
| 448 | $result = $base . $request; |
454 | | // we need to know the way queries are being written |
455 | | // if there's a querystring_start (a "?" usually), it's definitely not mod_rewritten |
456 | | if ( stristr( $qstr, '?' ) ) { |
457 | | // so append the query string (using &, since we already have ?) |
458 | | $qstr .= '&' . $page_querystring . '=' . $pagenum; |
459 | | // otherwise, it could be rewritten, OR just the default index ... |
460 | | } elseif( '' != get_option('permalink_structure') && ! is_admin() ) { |
461 | | $permalink = 1; |
462 | | $index = $wp_rewrite->index; |
463 | | // If it's not a path info permalink structure, trim the index. |
464 | | if ( !$wp_rewrite->using_index_permalinks() ) { |
465 | | $qstr = preg_replace("#/*" . $index . "/*#", '/', $qstr); |
466 | | } else { |
467 | | // If using path info style permalinks, make sure the index is in |
468 | | // the URL. |
469 | | if ( strpos($qstr, $index) === false ) |
470 | | $qstr = '/' . $index . $qstr; |
471 | | } |
472 | | |
473 | | $qstr = trailingslashit($qstr) . $page_modstring . $pagenum; |
| 450 | $qs_regex = '|\?.*?$|'; |
| 451 | preg_match($qs_regex, $request, $qs_match); |
| 452 | if ( $qs_match[0] ) { |
| 453 | $query_string = $qs_match[0]; |
| 454 | $request = preg_replace($qs_regex, '', $request); |
479 | | $qstr = preg_replace('|^/+|', '', $qstr); |
480 | | if ( $permalink ) |
481 | | $qstr = user_trailingslashit($qstr, 'paged'); |
482 | | $qstr = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', trailingslashit( get_option('home') ) . $qstr ); |
| 459 | // clean /index.php [...] /page/N/ or variants |
| 460 | $request = preg_replace('|^/?index\.php/?|', '', $request); |
| 461 | $request = preg_replace('|/?page/[0-9]*?/?$|', '', $request); |
484 | | // showing /page/1/ or ?paged=1 is redundant |
485 | | if ( 1 === $pagenum ) { |
486 | | $qstr = str_replace(user_trailingslashit('index.php/page/1', 'paged'), '', $qstr); // for PATHINFO style |
487 | | $qstr = str_replace(user_trailingslashit('page/1', 'paged'), '', $qstr); // for mod_rewrite style |
488 | | $qstr = remove_query_arg('paged', $qstr); // for query style |
| 463 | $base = get_option('home') . '/'; |
| 464 | if ( $wp_rewrite->using_index_permalinks() && $pagenum > 1 ) |
| 465 | $base .= 'index.php/'; |
| 466 | $request = ( $pagenum > 1 ) ? $request . user_trailingslashit('page/' . $pagenum, 'paged') : $request; |
| 467 | $result = $base . $request . $query_string; |
| 468 | |