diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2007-02-15 13:19:12 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2007-02-15 13:19:12 +0000 |
commit | 8752f7651d737da0dbe86065e708347a58b40d61 (patch) | |
tree | ac80c1eb849760d123d729ffb33fb8a9dc1742db /wp-includes/link-template.php | |
parent | 982f28611561556403f1c1004ad41f3253205e0e (diff) | |
download | wordpress-mu-8752f7651d737da0dbe86065e708347a58b40d61.tar.gz wordpress-mu-8752f7651d737da0dbe86065e708347a58b40d61.tar.xz wordpress-mu-8752f7651d737da0dbe86065e708347a58b40d61.zip |
WP Merge to rev 4887
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@888 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/link-template.php')
-rw-r--r-- | wp-includes/link-template.php | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 20b9132..f576129 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -11,6 +11,23 @@ function permalink_link() { // For backwards compatibility } +/** + * Conditionally adds a trailing slash if the permalink structure + * has a trailing slash, strips the trailing slash if not + * @global object Uses $wp_rewrite + * @param $string string a URL with or without a trailing slash + * @return string + */ +function user_trailingslashit($string) { + global $wp_rewrite; + if ( $wp_rewrite->use_trailing_slashes ) + $string = trailingslashit($string); + else + $string = preg_replace('|/$|', '', $string); // untrailing slash + return $string; +} + + function permalink_anchor($mode = 'id') { global $post; switch ( strtolower($mode) ) { @@ -116,7 +133,8 @@ function _get_page_link( $id = false ) { if ( '' != $pagestruct && 'draft' != $post->post_status ) { $link = get_page_uri($id); $link = str_replace('%pagename%', $link, $pagestruct); - $link = get_option('home') . "/$link/"; + $link = get_option('home') . "/$link"; + $link = user_trailingslashit($link); } else { $link = get_option('home') . "/?page_id=$id"; } @@ -158,7 +176,7 @@ function get_year_link($year) { $yearlink = $wp_rewrite->get_year_permastruct(); if ( !empty($yearlink) ) { $yearlink = str_replace('%year%', $year, $yearlink); - return apply_filters('year_link', get_option('home') . trailingslashit($yearlink), $year); + return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink), $year); } else { return apply_filters('year_link', get_option('home') . '/?m=' . $year, $year); } @@ -174,7 +192,7 @@ function get_month_link($year, $month) { if ( !empty($monthlink) ) { $monthlink = str_replace('%year%', $year, $monthlink); $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); - return apply_filters('month_link', get_option('home') . trailingslashit($monthlink), $year, $month); + return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink), $year, $month); } else { return apply_filters('month_link', get_option('home') . '/?m=' . $year . zeroise($month, 2), $year, $month); } @@ -194,7 +212,7 @@ function get_day_link($year, $month, $day) { $daylink = str_replace('%year%', $year, $daylink); $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); - return apply_filters('day_link', get_option('home') . trailingslashit($daylink), $year, $month, $day); + return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink), $year, $month, $day); } else { return apply_filters('day_link', get_option('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day); } @@ -217,8 +235,8 @@ function get_feed_link($feed='rss2') { $feed = ''; $permalink = str_replace('%feed%', $feed, $permalink); - $permalink = preg_replace('#/+#', '/', "/$permalink/"); - $output = get_option('home') . $permalink; + $permalink = preg_replace('#/+#', '/', "/$permalink"); + $output = get_option('home') . user_trailingslashit($permalink); } else { if ( false !== strpos($feed, 'comments_') ) $feed = str_replace('comments_', 'comments-', $feed); @@ -435,12 +453,13 @@ function get_pagenum_link($pagenum = 1) { $qstr = preg_replace('|^/+|', '', $qstr); if ( $permalink ) - $qstr = trailingslashit($qstr); + $qstr = user_trailingslashit($qstr); $qstr = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', trailingslashit( get_option('home') ) . $qstr ); // showing /page/1/ or ?paged=1 is redundant if ( 1 === $pagenum ) { - $qstr = str_replace('page/1/', '', $qstr); // for mod_rewrite style + $qstr = str_replace(user_trailingslashit('index.php/page/1'), '', $qstr); // for PATHINFO style + $qstr = str_replace(user_trailingslashit('page/1'), '', $qstr); // for mod_rewrite style $qstr = remove_query_arg('paged', $qstr); // for query style } return $qstr; |