Make WordPress Core

Ticket #23965: 23965.7.diff

File 23965.7.diff, 6.0 KB (added by wonderboymusic, 12 years ago)
  • wp-includes/functions.php

    diff --git wp-includes/functions.php wp-includes/functions.php
    index 0afa50b..c10709c 100644
    function wp_auth_check( $response, $data ) { 
    39853985function get_tag_regex( $tag ) {
    39863986        if ( empty( $tag ) )
    39873987                return;
    3988 
    3989         return sprintf( '(<%1$s[^>]*(?:/?>$|>[\s\S]*?</%1$s>))', tag_escape( $tag ) );
     3988        return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
    39903989}
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index bd52867..51a466d 100644
    function get_embedded_media( $type, &$content, $remove = false, $limit = 0 ) { 
    19661966
    19671967        foreach ( array( $type, 'object', 'embed', 'iframe' ) as $tag ) {
    19681968                if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
    1969                         $html[] = $matches[1];
     1969                        $html[] = $matches[0];
    19701970                        if ( $remove )
    19711971                                $content = str_replace( $matches[0], '', $content );
    19721972
    function get_content_images( &$content, $html = true, $remove = false, $limit = 
    22092209        $tags = array();
    22102210        $captions = array();
    22112211
    2212         if ( $remove && preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
     2212        if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
    22132213                foreach ( $matches as $shortcode ) {
    2214                         if ( 'caption' === $shortcode[2] )
     2214                        if ( 'caption' === $shortcode[2] ) {
    22152215                                $captions[] = $shortcode[0];
     2216                                if ( $html )
     2217                                        $tags[] = do_shortcode( $shortcode[0] );
     2218                        }
     2219
     2220                        if ( $limit > 0 && count( $tags ) >= $limit )
     2221                                break;
    22162222                }
    22172223        }
    22182224
    2219         if ( preg_match_all( '#<img[^>]+/?>#i', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
    2220                 foreach ( $matches as $tag ) {
    2221                         $count = 1;
    2222                         if ( $remove ) {
     2225        foreach ( array( 'a', 'img' ) as $tag ) {
     2226                if ( preg_match_all( '#' . get_tag_regex( $tag ) .  '#i', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
     2227                        foreach ( $matches as $node ) {
     2228                                if ( ! strstr( $node[0], '<img ' ) )
     2229                                        continue;
     2230
     2231                                $count = 1;
     2232                                $found = false;
     2233
    22232234                                foreach ( $captions as $caption ) {
    2224                                         if ( strstr( $caption, $tag[0] ) ) {
    2225                                                 $content = str_replace( $caption, '', $content, $count );
     2235                                        if ( strstr( $caption, $node[0] ) ) {
     2236                                                $found = true;
     2237                                                if ( $remove )
     2238                                                        $content = str_replace( $caption, '', $content, $count );
    22262239                                        }
    22272240                                }
    22282241
    2229                                 $content = str_replace( $tag[0], '', $content, $count );
    2230                         }
     2242                                if ( $remove )
     2243                                        $content = str_replace( $node[0], '', $content, $count );
    22312244
    2232                         $tags[] = $tag[0];
     2245                                if ( ! $found )
     2246                                        $tags[] = $node[0];
    22332247
    2234                         if ( $limit > 0 && count( $tags ) >= $limit )
    2235                                 break;
     2248                                if ( $limit > 0 && count( $tags ) >= $limit )
     2249                                        break 2;
     2250                        }
    22362251                }
    22372252        }
    22382253
    function get_the_post_format_image( $attached_size = 'full', &$post = null ) { 
    24002415        if ( isset( $post->format_content ) )
    24012416                return $post->format_content;
    24022417
     2418        $matched = false;
    24032419        $meta = get_post_format_meta( $post->ID );
    24042420
    24052421        $link_fmt = '%s';
    function get_the_post_format_image( $attached_size = 'full', &$post = null ) { 
    24262442                $sizes = get_intermediate_image_sizes();
    24272443                $sizes[] = 'full'; // Add original image source.
    24282444
    2429                 $urls = array();
     2445                $urls = array( get_attachment_link( $media->ID ) );
    24302446                foreach ( $sizes as $size ) {
    24312447                        $image = wp_get_attachment_image_src( $media->ID, $size );
    24322448                        if ( $image )
    function get_the_post_format_image( $attached_size = 'full', &$post = null ) { 
    24442460                        foreach ( $matches as $shortcode ) {
    24452461                                if ( 'caption' === $shortcode[2] ) {
    24462462                                        foreach ( $urls as $url ) {
    2447                                                 if ( strstr( $shortcode[0], $url ) )
     2463                                                if ( strstr( $shortcode[0], $url ) ) {
     2464                                                        if ( ! $matched )
     2465                                                                $matched = do_shortcode( $shortcode[0] );
    24482466                                                        $content = str_replace( $shortcode[0], '', $content, $count );
     2467                                                }
    24492468                                        }
    24502469                                }
    24512470                        }
    function get_the_post_format_image( $attached_size = 'full', &$post = null ) { 
    24552474                        if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
    24562475                                foreach ( $matches as $match ) {
    24572476                                        foreach ( $urls as $url ) {
    2458                                                 if ( strstr( $match[0], $url ) )
     2477                                                if ( strstr( $match[0], $url ) ) {
     2478                                                        if ( ! $matched )
     2479                                                                $matched = $match[0];
    24592480                                                        $content = str_replace( $match[0], '', $content, $count );
     2481                                                }
    24602482                                        }
    24612483                                }
    24622484                        }
    24632485                }
    24642486
    24652487                $post->split_content = $content;
    2466                 $image = wp_get_attachment_image( $media->ID, $attached_size );
    2467                 $post->format_content = sprintf( $link_fmt, $image );
     2488                if ( ! $matched ) {
     2489                        $image = wp_get_attachment_image( $media->ID, $attached_size );
     2490                        $post->format_content = sprintf( $link_fmt, $image );
     2491                } else {
     2492                        $post->format_content = $matched;
     2493                        if ( ! empty( $meta['url'] ) && false === stripos( $matched, '<a ' ) )
     2494                                $post->format_content = sprintf( $link_fmt, $matched );
     2495                }
    24682496                return $post->format_content;
    24692497        }
    24702498
  • wp-includes/post-formats.php

    diff --git wp-includes/post-formats.php wp-includes/post-formats.php
    index 127d1ef..4301bed 100644
    function post_formats_compat( $content, $id = 0 ) { 
    380380                                $image = is_numeric( $meta['image'] ) ? wp_get_attachment_url( $meta['image'] ) : $meta['image'];
    381381
    382382                                if ( ! empty( $image ) && ! stristr( $content, $image ) ) {
    383                                         $image_html = sprintf(
    384                                                 '<img %ssrc="%s" alt="" />',
    385                                                 empty( $compat['image_class'] ) ? '' : sprintf( 'class="%s" ', esc_attr( $compat['image_class'] ) ),
    386                                                 $image
    387                                         );
    388                                         if ( empty( $meta['url'] ) ) {
     383                                        if ( false === strpos( $image, '<a ' ) ) {
     384                                                $image_html = sprintf(
     385                                                        '<img %ssrc="%s" alt="" />',
     386                                                        empty( $compat['image_class'] ) ? '' : sprintf( 'class="%s" ', esc_attr( $compat['image_class'] ) ),
     387                                                        $image
     388                                                );
     389                                        } else {
     390                                                $image_html = $image;
     391                                        }
     392
     393                                        if ( empty( $meta['url'] ) || false !== strpos( $image, '<a ' ) ) {
    389394                                                $format_output .= $image_html;
    390395                                        } else {
    391396                                                $format_output .= sprintf(