]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/link-template.php
Wordpress 3.6-scripts
[autoinstalls/wordpress.git] / wp-includes / link-template.php
index de76f45aae3b5d8d0f05f2eb573f52266d809190..f52f8ea2e4a659ebfd34bce15a004ce3c8f36446 100644 (file)
@@ -13,7 +13,7 @@
  * @uses apply_filters() Calls 'the_permalink' filter on the permalink string.
  */
 function the_permalink() {
-       echo apply_filters('the_permalink', get_permalink());
+       echo esc_url( apply_filters( 'the_permalink', get_permalink() ) );
 }
 
 /**
@@ -232,7 +232,7 @@ function post_permalink( $post_id = 0, $deprecated = '' ) {
  *
  * @since 1.5.0
  *
- * @param mixed $post Optional. Post ID or object.
+ * @param int|object $post Optional. Post ID or object.
  * @param bool $leavename Optional, defaults to false. Whether to keep page name.
  * @param bool $sample Optional, defaults to false. Is it a sample permalink.
  * @return string
@@ -256,7 +256,7 @@ function get_page_link( $post = false, $leavename = false, $sample = false ) {
  * @since 2.1.0
  * @access private
  *
- * @param mixed $post Optional. Post ID or object.
+ * @param int|object $post Optional. Post ID or object.
  * @param bool $leavename Optional. Leave name.
  * @param bool $sample Optional. Sample permalink.
  * @return string
@@ -291,7 +291,7 @@ function _get_page_link( $post = false, $leavename = false, $sample = false ) {
  *
  * @since 2.0.0
  *
- * @param mixed $post Optional. Post ID or object.
+ * @param int|object $post Optional. Post ID or object.
  * @param bool $leavename Optional. Leave name.
  * @return string
  */
@@ -301,9 +301,9 @@ function get_attachment_link( $post = null, $leavename = false ) {
        $link = false;
 
        $post = get_post( $post );
+       $parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
 
-       if ( $wp_rewrite->using_permalinks() && ( $post->post_parent > 0 ) && ( $post->post_parent != $post->ID ) ) {
-               $parent = get_post($post->post_parent);
+       if ( $wp_rewrite->using_permalinks() && $parent ) {
                if ( 'page' == $parent->post_type )
                        $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front
                else
@@ -867,9 +867,10 @@ function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
 
        if ( ! $link = get_post_type_archive_link( $post_type ) )
                return false;
+
        $post_type_obj = get_post_type_object( $post_type );
-       if ( $post_type_obj->rewrite['feeds'] && get_option( 'permalink_structure' ) ) {
-               $link = trailingslashit($link);
+       if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) {
+               $link = trailingslashit( $link );
                $link .= 'feed/';
                if ( $feed != $default_feed )
                        $link .= "$feed/";
@@ -896,7 +897,9 @@ function get_edit_post_link( $id = 0, $context = 'display' ) {
        if ( ! $post = get_post( $id ) )
                return;
 
-       if ( 'display' == $context )
+       if ( 'revision' === $post->post_type )
+               $action = '';
+       elseif ( 'display' == $context )
                $action = '&action=edit';
        else
                $action = '&action=edit';
@@ -905,7 +908,7 @@ function get_edit_post_link( $id = 0, $context = 'display' ) {
        if ( !$post_type_object )
                return;
 
-       if ( !current_user_can( $post_type_object->cap->edit_post, $post->ID ) )
+       if ( !current_user_can( 'edit_post', $post->ID ) )
                return;
 
        return apply_filters( 'get_edit_post_link', admin_url( sprintf($post_type_object->_edit_link . $action, $post->ID) ), $post->ID, $context );
@@ -959,7 +962,7 @@ function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false
        if ( !$post_type_object )
                return;
 
-       if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) )
+       if ( !current_user_can( 'delete_post', $post->ID ) )
                return;
 
        $action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash';
@@ -1174,7 +1177,7 @@ function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $pr
        $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories );
        $sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
 
-       $query = "SELECT p.id FROM $wpdb->posts AS p $join $where $sort";
+       $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
        $query_key = 'adjacent_post_' . md5($query);
        $result = wp_cache_get($query_key, 'counts');
        if ( false !== $result ) {
@@ -1217,16 +1220,15 @@ function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $ex
        if ( empty($post) )
                return;
 
-       if ( empty($post->post_title) )
+       $post_title = the_title_attribute( array( 'echo' => false, 'post' => $post ) );
+
+       if ( empty( $post_title ) )
                $post_title = $previous ? __('Previous Post') : __('Next Post');
-       else
-               $post_title = $post->post_title;
 
        $date = mysql2date(get_option('date_format'), $post->post_date);
 
        $title = str_replace('%title', $post_title, $title);
        $title = str_replace('%date', $date, $title);
-       $title = apply_filters('the_title', $title, $post->ID);
 
        $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
        $link .= esc_attr( $title );
@@ -1449,13 +1451,13 @@ function get_pagenum_link($pagenum = 1, $escape = true ) {
                }
 
                $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);
-               $request = preg_replace( '|^index\.php|i', '', $request);
+               $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request);
                $request = ltrim($request, '/');
 
                $base = trailingslashit( get_bloginfo( 'url' ) );
 
                if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
-                       $base .= 'index.php/';
+                       $base .= $wp_rewrite->index . '/';
 
                if ( $pagenum > 1 ) {
                        $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' );
@@ -1919,7 +1921,7 @@ function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
 
        $url = set_url_scheme( $url, $scheme );
 
-       if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
+       if ( $path && is_string( $path ) )
                $url .= '/' . ltrim( $path, '/' );
 
        return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );
@@ -1971,7 +1973,7 @@ function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
 
        $url = set_url_scheme( $url, $scheme );
 
-       if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
+       if ( $path && is_string( $path ) )
                $url .= '/' . ltrim( $path, '/' );
 
        return apply_filters( 'site_url', $url, $path, $scheme, $blog_id );
@@ -2005,7 +2007,7 @@ function admin_url( $path = '', $scheme = 'admin' ) {
 function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
        $url = get_site_url($blog_id, 'wp-admin/', $scheme);
 
-       if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
+       if ( $path && is_string( $path ) )
                $url .= ltrim( $path, '/' );
 
        return apply_filters( 'admin_url', $url, $path, $blog_id );
@@ -2018,12 +2020,13 @@ function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
  * @since 2.6.0
  *
  * @param string $path Optional. Path relative to the includes url.
+ * @param string $scheme Optional. Scheme to give the includes url context.
  * @return string Includes url link with optional path appended.
 */
-function includes_url($path = '') {
-       $url = site_url() . '/' . WPINC . '/';
+function includes_url( $path = '', $scheme = null ) {
+       $url = site_url( '/' . WPINC . '/', $scheme );
 
-       if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
+       if ( $path && is_string( $path ) )
                $url .= ltrim($path, '/');
 
        return apply_filters('includes_url', $url, $path);
@@ -2041,7 +2044,7 @@ function includes_url($path = '') {
 function content_url($path = '') {
        $url = set_url_scheme( WP_CONTENT_URL );
 
-       if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
+       if ( $path && is_string( $path ) )
                $url .= '/' . ltrim($path, '/');
 
        return apply_filters('content_url', $url, $path);
@@ -2080,7 +2083,7 @@ function plugins_url($path = '', $plugin = '') {
                        $url .= '/' . ltrim($folder, '/');
        }
 
-       if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
+       if ( $path && is_string( $path ) )
                $url .= '/' . ltrim($path, '/');
 
        return apply_filters('plugins_url', $url, $path, $plugin);
@@ -2111,7 +2114,7 @@ function network_site_url( $path = '', $scheme = null ) {
        else
                $url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme );
 
-       if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
+       if ( $path && is_string( $path ) )
                $url .= ltrim( $path, '/' );
 
        return apply_filters( 'network_site_url', $url, $path, $scheme );
@@ -2147,7 +2150,7 @@ function network_home_url( $path = '', $scheme = null ) {
        else
                $url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme );
 
-       if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
+       if ( $path && is_string( $path ) )
                $url .= ltrim( $path, '/' );
 
        return apply_filters( 'network_home_url', $url, $path, $orig_scheme);
@@ -2169,7 +2172,7 @@ function network_admin_url( $path = '', $scheme = 'admin' ) {
 
        $url = network_site_url('wp-admin/network/', $scheme);
 
-       if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
+       if ( $path && is_string( $path ) )
                $url .= ltrim($path, '/');
 
        return apply_filters('network_admin_url', $url, $path);
@@ -2188,7 +2191,7 @@ function network_admin_url( $path = '', $scheme = 'admin' ) {
 function user_admin_url( $path = '', $scheme = 'admin' ) {
        $url = network_site_url('wp-admin/user/', $scheme);
 
-       if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
+       if ( $path && is_string( $path ) )
                $url .= ltrim($path, '/');
 
        return apply_filters('user_admin_url', $url, $path);