summaryrefslogtreecommitdiffstats
path: root/wp-includes/link-template.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-06-21 16:41:02 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-06-21 16:41:02 +0000
commita5fe68e002632c190ffbd85167671ed4d4961135 (patch)
treeae57f94603111507c50cb3c212a03bedf8f7dc5a /wp-includes/link-template.php
parent4e38776b5b68c61a4593a84340f4654200f7568e (diff)
downloadwordpress-mu-a5fe68e002632c190ffbd85167671ed4d4961135.tar.gz
wordpress-mu-a5fe68e002632c190ffbd85167671ed4d4961135.tar.xz
wordpress-mu-a5fe68e002632c190ffbd85167671ed4d4961135.zip
WP Merge to WP 2.2.1
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1005 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/link-template.php')
-rw-r--r--wp-includes/link-template.php181
1 files changed, 81 insertions, 100 deletions
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index 99b8ae0..2a05f93 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -77,6 +77,8 @@ function get_permalink($id = 0) {
$category = '';
if (strpos($permalink, '%category%') !== false) {
$cats = get_the_category($post->ID);
+ if ( $cats )
+ usort($cats, '_get_the_category_usort_by_ID'); // order by ID
$category = $cats[0]->category_nicename;
if ( $parent=$cats[0]->category_parent )
$category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
@@ -109,7 +111,7 @@ function get_permalink($id = 0) {
}
// get permalink from post ID
-function post_permalink($post_id = 0, $deprecated = '') {
+function post_permalink($post_id = 0, $mode = '') { // $mode legacy
return get_permalink($post_id);
}
@@ -273,80 +275,39 @@ function get_post_comments_feed_link($post_id = '', $feed = 'rss2') {
return apply_filters('post_comments_feed_link', $url);
}
-function get_edit_post_link( $id = 0 ) {
- $post = &get_post( $id );
-
- if ( $post->post_type == 'attachment' ) {
- return;
- } elseif ( $post->post_type == 'page' ) {
- if ( !current_user_can( 'edit_page', $post->ID ) )
- return;
-
- $file = 'page';
- } else {
- if ( !current_user_can( 'edit_post', $post->ID ) )
- return;
-
- $file = 'post';
- }
-
- return apply_filters( 'get_edit_post_link', get_bloginfo( 'wpurl' ) . '/wp-admin/' . $file . '.php?action=edit&amp;post=' . $post->ID, $post->ID );
-}
-
-function edit_post_link( $link = 'Edit This', $before = '', $after = '' ) {
+function edit_post_link($link = 'Edit This', $before = '', $after = '') {
global $post;
- if ( $post->post_type == 'attachment' ) {
+ if ( is_attachment() )
return;
- } elseif ( $post->post_type == 'page' ) {
- if ( !current_user_can( 'edit_page', $post->ID ) )
+
+ if( $post->post_type == 'page' ) {
+ if ( ! current_user_can('edit_page', $post->ID) )
return;
-
$file = 'page';
} else {
- if ( !current_user_can( 'edit_post', $post->ID ) )
+ if ( ! current_user_can('edit_post', $post->ID) )
return;
-
$file = 'post';
}
- $link = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . __( 'Edit post' ) . '">' . $link . '</a>';
- echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
+ $location = get_option('siteurl') . "/wp-admin/{$file}.php?action=edit&amp;post=$post->ID";
+ echo $before . "<a href=\"$location\">$link</a>" . $after;
}
-function get_edit_comment_link( $comment_id = 0 ) {
- $comment = &get_comment( $comment_id );
- $post = &get_post( $comment->comment_post_ID );
-
- if ( $post->post_type == 'attachment' ) {
- return;
- } elseif ( $post->post_type == 'page' ) {
- if ( !current_user_can( 'edit_page', $post->ID ) )
- return;
- } else {
- if ( !current_user_can( 'edit_post', $post->ID ) )
- return;
- }
+function edit_comment_link($link = 'Edit This', $before = '', $after = '') {
+ global $post, $comment;
- $location = get_bloginfo( 'wpurl' ) . '/wp-admin/comment.php?action=editcomment&amp;c=' . $comment->comment_ID;
- return apply_filters( 'get_edit_comment_link', $location );
-}
-
-function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
- global $comment, $post;
-
- if ( $post->post_type == 'attachment' ) {
- return;
- } elseif ( $post->post_type == 'page' ) {
- if ( !current_user_can( 'edit_page', $post->ID ) )
+ if( $post->post_type == 'page' ){
+ if ( ! current_user_can('edit_page', $post->ID) )
return;
} else {
- if ( !current_user_can( 'edit_post', $post->ID ) )
+ if ( ! current_user_can('edit_post', $post->ID) )
return;
}
- $link = '<a href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
- echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
+ $location = get_option('siteurl') . "/wp-admin/comment.php?action=editcomment&amp;c=$comment->comment_ID";
+ echo $before . "<a href='$location'>$link</a>" . $after;
}
// Navigation links
@@ -463,55 +424,75 @@ function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat =
function get_pagenum_link($pagenum = 1) {
global $wp_rewrite;
-
- $pagenum = (int) $pagenum;
-
- $request = remove_query_arg( 'paged' );
-
+
+ $qstr = $_SERVER['REQUEST_URI'];
+
+ $page_querystring = "paged";
+ $page_modstring = "page/";
+ $page_modregex = "page/?";
+ $permalink = 0;
+
$home_root = parse_url(get_option('home'));
$home_root = $home_root['path'];
- $home_root = preg_quote( trailingslashit( $home_root ), '|' );
-
- $request = preg_replace('|^'. $home_root . '|', '', $request);
- $request = preg_replace('|^/+|', '', $request);
-
- if ( !$wp_rewrite->using_permalinks() ) {
- $base = trailingslashit( get_bloginfo( 'home' ) );
-
- if ( $pagenum > 1 ) {
- $result = add_query_arg( 'paged', $pagenum, $base . $request );
- } else {
- $result = $base . $request;
- }
+ $home_root = trailingslashit($home_root);
+ $qstr = preg_replace('|^'. $home_root . '|', '', $qstr);
+ $qstr = preg_replace('|^/+|', '', $qstr);
+
+ $index = $_SERVER['PHP_SELF'];
+ $index = preg_replace('|^'. $home_root . '|', '', $index);
+ $index = preg_replace('|^/+|', '', $index);
+
+ // if we already have a QUERY style page string
+ if ( stripos( $qstr, $page_querystring ) !== false ) {
+ $replacement = "$page_querystring=$pagenum";
+ $qstr = preg_replace("/".$page_querystring."[^\d]+\d+/", $replacement, $qstr);
+ // if we already have a mod_rewrite style page string
+ } elseif ( preg_match( '|'.$page_modregex.'\d+|', $qstr ) ) {
+ $permalink = 1;
+ $qstr = preg_replace('|'.$page_modregex.'\d+|',"$page_modstring$pagenum",$qstr);
+
+ // if we don't have a page string at all ...
+ // lets see what sort of URL we have...
} else {
- $request = preg_replace( '|/?page/(.+)/?$|', '', $request);
-
- $qs_regex = '|\?.*?$|';
- preg_match( $qs_regex, $request, $qs_match );
-
- if ( $qs_match[0] ) {
- $query_string = $qs_match[0];
- $request = preg_replace( $qs_regex, '', $request );
+ // we need to know the way queries are being written
+ // if there's a querystring_start (a "?" usually), it's definitely not mod_rewritten
+ if ( stripos( $qstr, '?' ) !== false ) {
+ // so append the query string (using &, since we already have ?)
+ $qstr .= '&amp;' . $page_querystring . '=' . $pagenum;
+ // otherwise, it could be rewritten, OR just the default index ...
+ } elseif( '' != get_option('permalink_structure') && ! is_admin() ) {
+ $permalink = 1;
+ $index = $wp_rewrite->index;
+ // If it's not a path info permalink structure, trim the index.
+ if ( !$wp_rewrite->using_index_permalinks() ) {
+ $qstr = preg_replace("#/*" . $index . "/*#", '/', $qstr);
+ } else {
+ // If using path info style permalinks, make sure the index is in
+ // the URL.
+ if ( strpos($qstr, $index) === false )
+ $qstr = '/' . $index . $qstr;
+ }
+
+ $qstr = trailingslashit($qstr) . $page_modstring . $pagenum;
} else {
- $query_string = '';
+ $qstr = $index . '?' . $page_querystring . '=' . $pagenum;
}
-
- $base = trailingslashit( get_bloginfo( 'url' ) );
-
- if ( $wp_rewrite->using_index_permalinks() && $pagenum > 1 ) {
- $base .= 'index.php/';
- }
-
- if ( $pagenum > 1 ) {
- $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
- } else {
- $request = user_trailingslashit( $request );
- }
-
- $result = $base . $request . $query_string;
}
-
- return $result;
+
+ $qstr = preg_replace('|^/+|', '', $qstr);
+ if ( $permalink )
+ $qstr = user_trailingslashit($qstr, 'paged');
+
+ // showing /page/1/ or ?paged=1 is redundant
+ if ( 1 === $pagenum ) {
+ $qstr = str_replace(user_trailingslashit('index.php/page/1', 'paged'), '', $qstr); // for PATHINFO style
+ $qstr = str_replace(user_trailingslashit('page/1', 'paged'), '', $qstr); // for mod_rewrite style
+ $qstr = remove_query_arg('paged', $qstr); // for query style
+ }
+
+ $qstr = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', trailingslashit( get_option('home') ) . $qstr );
+
+ return $qstr;
}
function get_next_posts_page_link($max_page = 0) {