Make WordPress Core

Ticket #8703: 8703.patch

File 8703.patch, 5.9 KB (added by Viper007Bond, 15 years ago)

Properly escape titles (namely HTML) and spaces are bad (replace them with tabs)

  • wp-includes/link-template.php

     
    940940        $title = apply_filters('the_title', $title, $post);
    941941
    942942        $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    943         $link .= $title;
     943        $link .= attribute_escape( $title );
    944944        $link .= "' href='" . get_permalink($post) . "' />\n";
    945945
    946         $adjacent = $previous ? 'previous' : 'next';
    947         return apply_filters( "{$adjacent}_post_rel_link", $link );
     946        $adjacent = $previous ? 'previous' : 'next';
     947        return apply_filters( "{$adjacent}_post_rel_link", $link );
    948948}
    949949
    950950/**
     
    10011001 * @return object
    10021002 */
    10031003function get_boundary_post($in_same_cat = false, $excluded_categories = '', $start = true) {
    1004         global $post, $wpdb;
     1004        global $post, $wpdb;
    10051005
    1006         if( empty($post) || !is_single() || is_attachment() )
    1007                 return null;
     1006        if ( empty($post) || !is_single() || is_attachment() )
     1007                return null;
    10081008
    10091009        $cat_array = array();
    10101010        $excluded_categories = array();
    1011         if ( !empty($in_same_cat) || !empty($excluded_categories) ) {
    1012                 if ( !empty($in_same_cat) ) {
    1013                         $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
    1014                 }
     1011        if ( !empty($in_same_cat) || !empty($excluded_categories) ) {
     1012                if ( !empty($in_same_cat) ) {
     1013                        $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
     1014                }
    10151015
    1016                 if ( !empty($excluded_categories) ) {
    1017                         $excluded_categories = array_map('intval', explode(',', $excluded_categories));
     1016                if ( !empty($excluded_categories) ) {
     1017                        $excluded_categories = array_map('intval', explode(',', $excluded_categories));
    10181018
    1019                         if ( !empty($cat_array) ) {
    1020                                 $excluded_categories = array_diff($excluded_categories, $cat_array);
    1021                         }
     1019                        if ( !empty($cat_array) )
     1020                                $excluded_categories = array_diff($excluded_categories, $cat_array);
    10221021
    1023                         $inverse_cats = array();
    1024                         foreach ( $excluded_categories as $excluded_category) {
    1025                                 $inverse_cats[] = $excluded_category * -1;
    1026                         }
    1027                         $excluded_categories = $inverse_cats;
    1028                 }
    1029         }
     1022                        $inverse_cats = array();
     1023                        foreach ( $excluded_categories as $excluded_category)
     1024                                $inverse_cats[] = $excluded_category * -1;
     1025                        $excluded_categories = $inverse_cats;
     1026                }
     1027        }
    10301028
    10311029        $categories = array_merge($cat_array, $excluded_categories);
    10321030
    1033         $order = $start ? 'ASC' : 'DESC';
     1031        $order = $start ? 'ASC' : 'DESC';
    10341032
    10351033        return get_posts("numberposts=1&order=$order&orderby=ID&category=$categories");
    10361034}
     
    10491047 * @return string
    10501048 */
    10511049function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) {
    1052         $posts = get_boundary_post($in_same_cat,$excluded_categories,$start);
     1050        $posts = get_boundary_post($in_same_cat,$excluded_categories,$start);
    10531051        // Even though we limited get_posts to return only 1 item it still returns an array of objects. 
    10541052        $post = $posts[0];     
    10551053
    1056         if ( empty($post) )
    1057                 return;
     1054        if ( empty($post) )
     1055                return;
    10581056
    1059         if ( empty($post->post_title) )
    1060                 $post->post_title = $start ? __('First Post') : __('Last Post');
     1057        if ( empty($post->post_title) )
     1058                $post->post_title = $start ? __('First Post') : __('Last Post');
    10611059
    1062         $date = mysql2date(get_option('date_format'), $post->post_date);
     1060        $date = mysql2date(get_option('date_format'), $post->post_date);
    10631061
    1064         $title = str_replace('%title', $post->post_title, $title);
    1065         $title = str_replace('%date', $date, $title);
    1066         $title = apply_filters('the_title', $title, $post);
     1062        $title = str_replace('%title', $post->post_title, $title);
     1063        $title = str_replace('%date', $date, $title);
     1064        $title = apply_filters('the_title', $title, $post);
    10671065
    1068         $link = $start ? "<link rel='start' title='" : "<link rel='end' title='";
    1069         $link .= $title;
    1070         $link .= "' href='" . get_permalink($post) . "' />\n";
     1066        $link = $start ? "<link rel='start' title='" : "<link rel='end' title='";
     1067        $link .= attribute_escape( $title );
     1068        $link .= "' href='" . get_permalink($post) . "' />\n";
    10711069
    1072         $boundary = $start ? 'start' : 'end';
    1073         return apply_filters( "{$boundary}_post_rel_link", $link );
     1070        $boundary = $start ? 'start' : 'end';
     1071        return apply_filters( "{$boundary}_post_rel_link", $link );
    10741072}
    10751073
    10761074/**
     
    10941092 * @return string
    10951093 */
    10961094function get_index_rel_link() {
    1097         $link = "<link rel='index' title='" . get_bloginfo('name') . "' href='" . get_bloginfo('siteurl') . "' />\n";
     1095        $link = "<link rel='index' title='" . attribute_escape( get_bloginfo('name') ) . "' href='" . get_bloginfo('siteurl') . "' />\n";
    10981096        return apply_filters( "index_rel_link", $link );
    10991097}
    11001098
     
    11221120        if ( empty($post) )
    11231121                return;
    11241122
    1125         $date = mysql2date(get_option('date_format'), $post->post_date);
     1123        $date = mysql2date(get_option('date_format'), $post->post_date);
    11261124
    1127         $title = str_replace('%title', $post->post_title, $title);
    1128         $title = str_replace('%date', $date, $title);
    1129         $title = apply_filters('the_title', $title, $post);
     1125        $title = str_replace('%title', $post->post_title, $title);
     1126        $title = str_replace('%date', $date, $title);
     1127        $title = apply_filters('the_title', $title, $post);
    11301128
    1131         $link = "<link rel='up' title='";
    1132         $link .= $title;
    1133         $link .= "' href='" . get_permalink($post) . "' />\n";
     1129        $link = "<link rel='up' title='";
     1130        $link .= attribute_escape( $title );
     1131        $link .= "' href='" . get_permalink($post) . "' />\n";
    11341132
    1135         return apply_filters( "parent_post_rel_link", $link );
     1133        return apply_filters( "parent_post_rel_link", $link );
    11361134}
    11371135
    11381136/**