Multiple improvements to image post format insertion and display.
* get_tag_regex() altered based on Unit Tests. * Changes to post-formats.js to provide size and link context during image selection. * Captions are now output in the_post_format_image() when present. * The meta value for url is respected for the image post format when the HTML in the image meta doesn't include a link props wonderboymusic. fixes #23965, #23964. see #24147, #24046. git-svn-id: http://core.svn.wordpress.org/trunk@24066 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e7b2915ecd
commit
0a49442e35
|
@ -93,21 +93,17 @@ window.wp = window.wp || {};
|
|||
|
||||
lastMimeType = mime;
|
||||
|
||||
// Create the media frame.
|
||||
mediaFrame = wp.media.frames.formatMedia = wp.media( {
|
||||
// Set the title of the modal.
|
||||
title: $el.data('choose'),
|
||||
|
||||
// Tell the modal to show only items matching the current mime type.
|
||||
library: {
|
||||
type: mime
|
||||
},
|
||||
|
||||
// Customize the submit button.
|
||||
button: {
|
||||
// Set the text of the button.
|
||||
text: $el.data('update')
|
||||
}
|
||||
},
|
||||
states: [
|
||||
new wp.media.controller.Library({
|
||||
library: wp.media.query( { type: mime } ),
|
||||
title: $el.data('choose'),
|
||||
displaySettings: 'image' === mime
|
||||
})
|
||||
]
|
||||
} );
|
||||
|
||||
mediaPreview = function(attachment) {
|
||||
|
@ -155,7 +151,11 @@ window.wp = window.wp || {};
|
|||
// show one preview at a time
|
||||
mediaPreview(attachment);
|
||||
} else {
|
||||
html = wp.media.string.image({}, attachment);
|
||||
html = wp.media.string.image({
|
||||
align : getUserSetting('align'),
|
||||
size : getUserSetting('imgsize'),
|
||||
link : getUserSetting('urlbutton')
|
||||
}, attachment);
|
||||
// set the hidden input's value
|
||||
$field.val(html);
|
||||
$('#image-preview').remove();
|
||||
|
|
|
@ -3985,6 +3985,5 @@ function wp_auth_check( $response, $data ) {
|
|||
function get_tag_regex( $tag ) {
|
||||
if ( empty( $tag ) )
|
||||
return;
|
||||
|
||||
return sprintf( '(<%1$s[^>]*(?:/?>$|>[\s\S]*?</%1$s>))', tag_escape( $tag ) );
|
||||
return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
|
||||
}
|
||||
|
|
|
@ -1966,7 +1966,7 @@ function get_embedded_media( $type, &$content, $remove = false, $limit = 0 ) {
|
|||
|
||||
foreach ( array( $type, 'object', 'embed', 'iframe' ) as $tag ) {
|
||||
if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
|
||||
$html[] = $matches[1];
|
||||
$html[] = $matches[0];
|
||||
if ( $remove )
|
||||
$content = str_replace( $matches[0], '', $content );
|
||||
|
||||
|
@ -2209,30 +2209,45 @@ function get_content_images( &$content, $html = true, $remove = false, $limit =
|
|||
$tags = array();
|
||||
$captions = array();
|
||||
|
||||
if ( $remove && preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
|
||||
if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
|
||||
foreach ( $matches as $shortcode ) {
|
||||
if ( 'caption' === $shortcode[2] )
|
||||
if ( 'caption' === $shortcode[2] ) {
|
||||
$captions[] = $shortcode[0];
|
||||
if ( $html )
|
||||
$tags[] = do_shortcode( $shortcode[0] );
|
||||
}
|
||||
|
||||
if ( $limit > 0 && count( $tags ) >= $limit )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( preg_match_all( '#<img[^>]+/?>#i', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
|
||||
foreach ( $matches as $tag ) {
|
||||
foreach ( array( 'a', 'img' ) as $tag ) {
|
||||
if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#i', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
|
||||
foreach ( $matches as $node ) {
|
||||
if ( ! strstr( $node[0], '<img ' ) )
|
||||
continue;
|
||||
|
||||
$count = 1;
|
||||
if ( $remove ) {
|
||||
$found = false;
|
||||
|
||||
foreach ( $captions as $caption ) {
|
||||
if ( strstr( $caption, $tag[0] ) ) {
|
||||
if ( strstr( $caption, $node[0] ) ) {
|
||||
$found = true;
|
||||
if ( $remove )
|
||||
$content = str_replace( $caption, '', $content, $count );
|
||||
}
|
||||
}
|
||||
|
||||
$content = str_replace( $tag[0], '', $content, $count );
|
||||
}
|
||||
if ( $remove )
|
||||
$content = str_replace( $node[0], '', $content, $count );
|
||||
|
||||
$tags[] = $tag[0];
|
||||
if ( ! $found )
|
||||
$tags[] = $node[0];
|
||||
|
||||
if ( $limit > 0 && count( $tags ) >= $limit )
|
||||
break;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2400,6 +2415,7 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
|
|||
if ( isset( $post->format_content ) )
|
||||
return $post->format_content;
|
||||
|
||||
$matched = false;
|
||||
$meta = get_post_format_meta( $post->ID );
|
||||
|
||||
$link_fmt = '%s';
|
||||
|
@ -2407,16 +2423,33 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
|
|||
$link_fmt = '<a href="' . esc_url( $meta['url'] ) . '">%s</a>';
|
||||
|
||||
if ( ! empty( $meta['image'] ) ) {
|
||||
if ( is_numeric( $meta['image'] ) )
|
||||
if ( is_numeric( $meta['image'] ) ) {
|
||||
$image = wp_get_attachment_image( absint( $meta['image'] ), $attached_size );
|
||||
elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $meta['image'] ) )
|
||||
// wrap image in <a>
|
||||
if ( ! empty( $meta['url'] ) )
|
||||
$image = sprint( $link_fmt, $image );
|
||||
} elseif ( has_shortcode( $meta['image'], 'gallery' ) ) {
|
||||
// wrap <img> in <a>
|
||||
if ( ! empty( $meta['url'] ) && false === strpos( $meta['image'], '<a ' ) ) {
|
||||
$meta['image'] = preg_replace(
|
||||
'#(<img[^>]+>)#',
|
||||
sprintf( '<a href="%s">$1</a>', esc_url( $meta['url'] ) ),
|
||||
$meta['image']
|
||||
);
|
||||
}
|
||||
$image = do_shortcode( $meta['image'] );
|
||||
elseif ( ! preg_match( '#<[^>]+>#', $meta['image'] ) )
|
||||
} elseif ( ! preg_match( '#<[^>]+>#', $meta['image'] ) ) {
|
||||
// not HTML, assume URL
|
||||
$image = sprintf( '<img src="%s" alt="" />', esc_url( $meta['image'] ) );
|
||||
else
|
||||
} else {
|
||||
// assume HTML
|
||||
$image = $meta['image'];
|
||||
}
|
||||
|
||||
if ( false === strpos( $image, '<a ' ) )
|
||||
$post->format_content = sprintf( $link_fmt, $image );
|
||||
else
|
||||
$post->format_content = $image;
|
||||
return $post->format_content;
|
||||
}
|
||||
|
||||
|
@ -2444,27 +2477,39 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
|
|||
foreach ( $matches as $shortcode ) {
|
||||
if ( 'caption' === $shortcode[2] ) {
|
||||
foreach ( $urls as $url ) {
|
||||
if ( strstr( $shortcode[0], $url ) )
|
||||
if ( strstr( $shortcode[0], $url ) ) {
|
||||
if ( ! $matched )
|
||||
$matched = do_shortcode( $shortcode[0] );
|
||||
$content = str_replace( $shortcode[0], '', $content, $count );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( array( 'a', 'img' ) as $tag ) {
|
||||
if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
|
||||
foreach ( $matches as $match ) {
|
||||
foreach ( $urls as $url ) {
|
||||
if ( strstr( $match[0], $url ) )
|
||||
if ( strstr( $match[0], $url ) ) {
|
||||
if ( ! $matched )
|
||||
$matched = $match[0];
|
||||
$content = str_replace( $match[0], '', $content, $count );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$post->split_content = $content;
|
||||
if ( ! $matched ) {
|
||||
$image = wp_get_attachment_image( $media->ID, $attached_size );
|
||||
$post->format_content = sprintf( $link_fmt, $image );
|
||||
} else {
|
||||
$post->format_content = $matched;
|
||||
if ( ! empty( $meta['url'] ) && false === stripos( $matched, '<a ' ) )
|
||||
$post->format_content = sprintf( $link_fmt, $matched );
|
||||
}
|
||||
return $post->format_content;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue