X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/00dbffaf1593b0ac719d98f00839221a9ca52133..fa11948979fd6a4ea5705dc613b239699a459db3:/wp-includes/media.php diff --git a/wp-includes/media.php b/wp-includes/media.php index d664e073..14972380 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -138,16 +138,16 @@ function image_downsize($id, $size = 'medium') { if ( !wp_attachment_is_image($id) ) return false; + // plugins can use this to provide resize services + if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) + return $out; + $img_url = wp_get_attachment_url($id); $meta = wp_get_attachment_metadata($id); $width = $height = 0; $is_intermediate = false; $img_url_basename = wp_basename($img_url); - // plugins can use this to provide resize services - if ( $out = apply_filters('image_downsize', false, $id, $size) ) - return $out; - // try for a new style intermediate size if ( $intermediate = image_get_intermediate_size($id, $size) ) { $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url); @@ -164,7 +164,7 @@ function image_downsize($id, $size = 'medium') { $is_intermediate = true; } } - if ( !$width && !$height && isset($meta['width'], $meta['height']) ) { + if ( !$width && !$height && isset( $meta['width'], $meta['height'] ) ) { // any other type: use the real image $width = $meta['width']; $height = $meta['height']; @@ -284,8 +284,9 @@ function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, // The larger ratio fits, and is likely to be a more "snug" fit. $ratio = $larger_ratio; - $w = intval( $current_width * $ratio ); - $h = intval( $current_height * $ratio ); + // Very small dimensions may result in 0, 1 should be the minimum. + $w = max ( 1, intval( $current_width * $ratio ) ); + $h = max ( 1, intval( $current_height * $ratio ) ); // Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short // We also have issues with recursive calls resulting in an ever-changing result. Constraining to the result of a constraint should yield the original result. @@ -539,6 +540,7 @@ function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = * @param int $attachment_id Image attachment ID. * @param string $size Optional, default is 'thumbnail'. * @param bool $icon Optional, default is false. Whether it is an icon. + * @param mixed $attr Optional, attributes for the image markup. * @return string HTML img element or empty string on failure. */ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') { @@ -639,20 +641,49 @@ function img_caption_shortcode($attr, $content = null) { if ( $output != '' ) return $output; - extract(shortcode_atts(array( - 'id' => '', - 'align' => 'alignnone', - 'width' => '', + $atts = shortcode_atts( array( + 'id' => '', + 'align' => 'alignnone', + 'width' => '', 'caption' => '' - ), $attr)); + ), $attr, 'caption' ); - if ( 1 > (int) $width || empty($caption) ) + $atts['width'] = (int) $atts['width']; + if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) return $content; - if ( $id ) $id = 'id="' . esc_attr($id) . '" '; - - return '
' - . do_shortcode( $content ) . '

' . $caption . '

'; + if ( ! empty( $atts['id'] ) ) + $atts['id'] = 'id="' . esc_attr( $atts['id'] ) . '" '; + + $caption_width = 10 + $atts['width']; + + /** + * Filter the width of an image's caption. + * + * By default, the caption is 10 pixels greater than the width of the image, + * to prevent post content from running up against a floated image. + * + * @since 3.7.0 + * + * @param int $caption_width Width in pixels. To remove this inline style, return zero. + * @param array $atts { + * The attributes of the caption shortcode. + * + * @type string 'id' The ID of the div element for the caption. + * @type string 'align' The class name that aligns the caption. Default 'alignnone'. + * @type int 'width' The width of the image being captioned. + * @type string 'caption' The image's caption. + * } + * @param string $content The image element, possibly wrapped in a hyperlink. + */ + $caption_width = apply_filters( 'img_caption_shortcode_width', $caption_width, $atts, $content ); + + $style = ''; + if ( $caption_width ) + $style = 'style="width: ' . (int) $caption_width . 'px" '; + + return '
' + . do_shortcode( $content ) . '

' . $atts['caption'] . '

'; } add_shortcode('gallery', 'gallery_shortcode'); @@ -696,15 +727,16 @@ function gallery_shortcode($attr) { extract(shortcode_atts(array( 'order' => 'ASC', 'orderby' => 'menu_order ID', - 'id' => $post->ID, + 'id' => $post ? $post->ID : 0, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', - 'exclude' => '' - ), $attr)); + 'exclude' => '', + 'link' => '' + ), $attr, 'gallery')); $id = intval($id); if ( 'RAND' == $order ) @@ -769,20 +801,31 @@ function gallery_shortcode($attr) { #{$selector} .gallery-caption { margin-left: 0; } - - "; + /* see gallery_shortcode() in wp-includes/media.php */ + "; $size_class = sanitize_html_class( $size ); $gallery_div = "