summaryrefslogtreecommitdiffstats
path: root/wp-includes/link-template.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-10-12 16:21:15 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-10-12 16:21:15 +0000
commit3a4570b0fc8b3d6339bef71d17d7701554e0bbf7 (patch)
tree2a06e5261263c68d8afd95a6328879dc289cb909 /wp-includes/link-template.php
parentb83c34a7010faee0223f6037025c350da12e05e6 (diff)
downloadwordpress-mu-3a4570b0fc8b3d6339bef71d17d7701554e0bbf7.tar.gz
wordpress-mu-3a4570b0fc8b3d6339bef71d17d7701554e0bbf7.tar.xz
wordpress-mu-3a4570b0fc8b3d6339bef71d17d7701554e0bbf7.zip
Merge with WP 2.3 - testing use only!
Move pluggable functions out of wpmu-functions and into pluggable.php, fixes #439 git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1069 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/link-template.php')
-rw-r--r--wp-includes/link-template.php254
1 files changed, 139 insertions, 115 deletions
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index 2a05f93..6a0677b 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -6,11 +6,6 @@ function the_permalink() {
}
-function permalink_link() { // For backwards compatibility
- echo apply_filters('the_permalink', get_permalink());
-}
-
-
/**
* Conditionally adds a trailing slash if the permalink structure
* has a trailing slash, strips the trailing slash if not
@@ -64,6 +59,9 @@ function get_permalink($id = 0) {
);
$post = &get_post($id);
+
+ if ( empty($post->ID) ) return FALSE;
+
if ( $post->post_type == 'page' )
return get_page_link($post->ID);
elseif ($post->post_type == 'attachment')
@@ -71,16 +69,16 @@ function get_permalink($id = 0) {
$permalink = get_option('permalink_structure');
- if ( '' != $permalink && 'draft' != $post->post_status ) {
+ if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
$unixtime = strtotime($post->post_date);
$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 )
+ usort($cats, '_usort_terms_by_ID'); // order by ID
+ $category = $cats[0]->slug;
+ if ( $parent=$cats[0]->parent )
$category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
}
@@ -111,7 +109,7 @@ function get_permalink($id = 0) {
}
// get permalink from post ID
-function post_permalink($post_id = 0, $mode = '') { // $mode legacy
+function post_permalink($post_id = 0, $deprecated = '') {
return get_permalink($post_id);
}
@@ -169,7 +167,7 @@ function get_attachment_link($id = false) {
else
$parentlink = get_permalink( $object->post_parent );
if (strpos($parentlink, '?') === false)
- $link = trim($parentlink, '/') . '/' . $object->post_name . '/';
+ $link = trailingslashit($parentlink) . $object->post_name . '/';
}
if (! $link ) {
@@ -264,50 +262,95 @@ function get_post_comments_feed_link($post_id = '', $feed = 'rss2') {
$post_id = (int) $id;
if ( '' != get_option('permalink_structure') ) {
- $url = trailingslashit( get_permalink() ) . 'feed';
+ $url = trailingslashit( get_permalink($post_id) ) . 'feed';
if ( 'rss2' != $feed )
$url .= "/$feed";
$url = user_trailingslashit($url, 'single_feed');
} else {
- $url = get_option('home') . "/?feed=$feed&amp;p=$id";
+ $type = get_post_field('post_type', $post_id);
+ if ( 'page' == $type )
+ $url = get_option('home') . "/?feed=$feed&amp;page_id=$post_id";
+ else
+ $url = get_option('home') . "/?feed=$feed&amp;p=$post_id";
}
return apply_filters('post_comments_feed_link', $url);
}
-function edit_post_link($link = 'Edit This', $before = '', $after = '') {
- global $post;
+function get_edit_post_link( $id = 0 ) {
+ $post = &get_post( $id );
- if ( is_attachment() )
+ 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';
+ }
- if( $post->post_type == 'page' ) {
- if ( ! current_user_can('edit_page', $post->ID) )
+ 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 = '' ) {
+ global $post;
+
+ 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) )
+ if ( !current_user_can( 'edit_post', $post->ID ) )
return;
+
$file = 'post';
}
- $location = get_option('siteurl') . "/wp-admin/{$file}.php?action=edit&amp;post=$post->ID";
- echo $before . "<a href=\"$location\">$link</a>" . $after;
+ $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;
+}
+
+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;
+ }
+
+ $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 $post, $comment;
+function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
+ global $comment, $post;
- if( $post->post_type == 'page' ){
- if ( ! current_user_can('edit_page', $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) )
+ if ( !current_user_can( 'edit_post', $post->ID ) )
return;
}
- $location = get_option('siteurl') . "/wp-admin/comment.php?action=editcomment&amp;c=$comment->comment_ID";
- echo $before . "<a href='$location'>$link</a>" . $after;
+ $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;
}
// Navigation links
@@ -315,18 +358,18 @@ function edit_comment_link($link = 'Edit This', $before = '', $after = '') {
function get_previous_post($in_same_cat = false, $excluded_categories = '') {
global $post, $wpdb;
- if( !is_single() || is_attachment() )
+ if( empty($post) || !is_single() || is_attachment() )
return null;
$current_post_date = $post->post_date;
$join = '';
if ( $in_same_cat ) {
- $join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id ";
- $cat_array = get_the_category($post->ID);
- $join .= ' AND (category_id = ' . intval($cat_array[0]->cat_ID);
+ $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id ";
+ $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=tt_ids');
+ $join .= ' AND (tr.term_taxonomy_id = ' . intval($cat_array[0]);
for ( $i = 1; $i < (count($cat_array)); $i++ ) {
- $join .= ' OR category_id = ' . intval($cat_array[$i]->cat_ID);
+ $join .= ' OR tr.term_taxonomy_id = ' . intval($cat_array[$i]);
}
$join .= ')';
}
@@ -334,36 +377,32 @@ function get_previous_post($in_same_cat = false, $excluded_categories = '') {
$sql_exclude_cats = '';
if ( !empty($excluded_categories) ) {
$blah = explode(' and ', $excluded_categories);
- foreach ( $blah as $category ) {
- $category = intval($category);
- $sql_cat_ids = " OR pc.category_ID = '$category'";
- }
- $posts_in_ex_cats = $wpdb->get_col("SELECT p.ID FROM $wpdb->posts p LEFT JOIN $wpdb->post2cat pc ON pc.post_id=p.ID WHERE 1 = 0 $sql_cat_ids GROUP BY p.ID");
- $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
+ $posts_in_ex_cats = get_objects_in_term($blah, 'category');
+ $posts_in_ex_cats_sql = 'AND p.ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
}
$join = apply_filters( 'get_previous_post_join', $join, $in_same_cat, $excluded_categories );
- $where = apply_filters( 'get_previous_post_where', "WHERE post_date < '$current_post_date' AND post_type = 'post' AND post_status = 'publish' $posts_in_ex_cats_sql", $in_same_cat, $excluded_categories );
- $sort = apply_filters( 'get_previous_post_sort', 'ORDER BY post_date DESC LIMIT 1' );
+ $where = apply_filters( 'get_previous_post_where', "WHERE p.post_date < '$current_post_date' AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql", $in_same_cat, $excluded_categories );
+ $sort = apply_filters( 'get_previous_post_sort', 'ORDER BY p.post_date DESC LIMIT 1' );
- return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts $join $where $sort");
+ return @$wpdb->get_row("SELECT p.ID, p.post_title FROM $wpdb->posts AS p $join $where $sort");
}
function get_next_post($in_same_cat = false, $excluded_categories = '') {
global $post, $wpdb;
- if( !is_single() || is_attachment() )
+ if( empty($post) || !is_single() || is_attachment() )
return null;
$current_post_date = $post->post_date;
$join = '';
if ( $in_same_cat ) {
- $join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id ";
- $cat_array = get_the_category($post->ID);
- $join .= ' AND (category_id = ' . intval($cat_array[0]->cat_ID);
+ $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id ";
+ $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=tt_ids');
+ $join .= ' AND (tr.term_taxonomy_id = ' . intval($cat_array[0]);
for ( $i = 1; $i < (count($cat_array)); $i++ ) {
- $join .= ' OR category_id = ' . intval($cat_array[$i]->cat_ID);
+ $join .= ' OR tr.term_taxonomy_id = ' . intval($cat_array[$i]);
}
$join .= ')';
}
@@ -371,19 +410,15 @@ function get_next_post($in_same_cat = false, $excluded_categories = '') {
$sql_exclude_cats = '';
if ( !empty($excluded_categories) ) {
$blah = explode(' and ', $excluded_categories);
- foreach ( $blah as $category ) {
- $category = intval($category);
- $sql_cat_ids = " OR pc.category_ID = '$category'";
- }
- $posts_in_ex_cats = $wpdb->get_col("SELECT p.ID from $wpdb->posts p LEFT JOIN $wpdb->post2cat pc ON pc.post_id = p.ID WHERE 1 = 0 $sql_cat_ids GROUP BY p.ID");
- $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
+ $posts_in_ex_cats = get_objects_in_term($blah, 'category');
+ $posts_in_ex_cats_sql = 'AND p.ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
}
$join = apply_filters( 'get_next_post_join', $join, $in_same_cat, $excluded_categories );
- $where = apply_filters( 'get_next_post_where', "WHERE post_date > '$current_post_date' AND post_type = 'post' AND post_status = 'publish' $posts_in_ex_cats_sql AND ID != $post->ID", $in_same_cat, $excluded_categories );
- $sort = apply_filters( 'get_next_post_sort', 'ORDER BY post_date ASC LIMIT 1' );
+ $where = apply_filters( 'get_next_post_where', "WHERE p.post_date > '$current_post_date' AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql AND p.ID != $post->ID", $in_same_cat, $excluded_categories );
+ $sort = apply_filters( 'get_next_post_sort', 'ORDER BY p.post_date ASC LIMIT 1' );
- return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts $join $where $sort");
+ return @$wpdb->get_row("SELECT p.ID, p.post_title FROM $wpdb->posts AS p $join $where $sort");
}
@@ -397,7 +432,12 @@ function previous_post_link($format='&laquo; %link', $link='%title', $in_same_ca
if ( !$post )
return;
- $title = apply_filters('the_title', $post->post_title, $post);
+ $title = $post->post_title;
+
+ if ( empty($post->post_title) )
+ $title = __('Previous Post');
+
+ $title = apply_filters('the_title', $title, $post);
$string = '<a href="'.get_permalink($post->ID).'">';
$link = str_replace('%title', $title, $link);
$link = $pre . $string . $link . '</a>';
@@ -413,7 +453,12 @@ function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat =
if ( !$post )
return;
- $title = apply_filters('the_title', $post->post_title, $post);
+ $title = $post->post_title;
+
+ if ( empty($post->post_title) )
+ $title = __('Next Post');
+
+ $title = apply_filters('the_title', $title, $post);
$string = '<a href="'.get_permalink($post->ID).'">';
$link = str_replace('%title', $title, $link);
$link = $string . $link . '</a>';
@@ -425,74 +470,53 @@ function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat =
function get_pagenum_link($pagenum = 1) {
global $wp_rewrite;
- $qstr = $_SERVER['REQUEST_URI'];
+ $pagenum = (int) $pagenum;
- $page_querystring = "paged";
- $page_modstring = "page/";
- $page_modregex = "page/?";
- $permalink = 0;
+ $request = remove_query_arg( 'paged' );
$home_root = parse_url(get_option('home'));
$home_root = $home_root['path'];
- $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...
+ $home_root = preg_quote( trailingslashit( $home_root ), '|' );
+
+ $request = preg_replace('|^'. $home_root . '|', '', $request);
+ $request = preg_replace('|^/+|', '', $request);
+
+ if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
+ $base = trailingslashit( get_bloginfo( 'home' ) );
+
+ if ( $pagenum > 1 ) {
+ $result = add_query_arg( 'paged', $pagenum, $base . $request );
+ } else {
+ $result = $base . $request;
+ }
} else {
- // 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;
+ $qs_regex = '|\?.*?$|';
+ preg_match( $qs_regex, $request, $qs_match );
+
+ if ( $qs_match[0] ) {
+ $query_string = $qs_match[0];
+ $request = preg_replace( $qs_regex, '', $request );
} else {
- $qstr = $index . '?' . $page_querystring . '=' . $pagenum;
+ $query_string = '';
}
- }
- $qstr = preg_replace('|^/+|', '', $qstr);
- if ( $permalink )
- $qstr = user_trailingslashit($qstr, 'paged');
+ $request = preg_replace( '|page/(.+)/?$|', '', $request);
+ $request = preg_replace( '|^index\.php|', '', $request);
+ $request = ltrim($request, '/');
- // 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
- }
+ $base = trailingslashit( get_bloginfo( 'url' ) );
+
+ if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
+ $base .= 'index.php/';
- $qstr = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', trailingslashit( get_option('home') ) . $qstr );
+ if ( $pagenum > 1 ) {
+ $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
+ }
+
+ $result = $base . $request . $query_string;
+ }
- return $qstr;
+ return $result;
}
function get_next_posts_page_link($max_page = 0) {