X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/a6f44f0edcda2471c5a33e4156c1c9488c7f3210..fa11948979fd6a4ea5705dc613b239699a459db3:/wp-includes/media.php diff --git a/wp-includes/media.php b/wp-includes/media.php index 6111f363..14972380 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -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. @@ -640,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, 'caption')); + ), $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'); @@ -704,7 +734,8 @@ function gallery_shortcode($attr) { 'columns' => 3, 'size' => 'thumbnail', 'include' => '', - 'exclude' => '' + 'exclude' => '', + 'link' => '' ), $attr, 'gallery')); $id = intval($id); @@ -778,9 +809,9 @@ function gallery_shortcode($attr) { $i = 0; foreach ( $attachments as $id => $attachment ) { - if ( ! empty( $attr['link'] ) && 'file' === $attr['link'] ) + if ( ! empty( $link ) && 'file' === $link ) $image_output = wp_get_attachment_link( $id, $size, false, false ); - elseif ( ! empty( $attr['link'] ) && 'none' === $attr['link'] ) + elseif ( ! empty( $link ) && 'none' === $link ) $image_output = wp_get_attachment_image( $id, $size, false ); else $image_output = wp_get_attachment_link( $id, $size, true, false ); @@ -844,15 +875,30 @@ function wp_get_audio_extensions() { * * @since 3.6.0 * - * @param array $attr Attributes of the shortcode. + * @param array $attr Attributes of the shortcode. + * @param string $content Optional. Shortcode content. * @return string HTML content to display audio. */ -function wp_audio_shortcode( $attr ) { +function wp_audio_shortcode( $attr, $content = '' ) { $post_id = get_post() ? get_the_ID() : 0; static $instances = 0; $instances++; + /** + * Override the default audio shortcode. + * + * @since 3.7.0 + * + * @param null Empty variable to be replaced with shortcode markup. + * @param array $attr Attributes of the shortcode. + * @param string $content Shortcode content. + * @param int $instances Unique numeric ID of this audio shortcode instance. + */ + $html = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instances ); + if ( '' !== $html ) + return $html; + $audio = null; $default_types = wp_get_audio_extensions(); @@ -871,7 +917,7 @@ function wp_audio_shortcode( $attr ) { $primary = false; if ( ! empty( $src ) ) { $type = wp_check_filetype( $src, wp_get_mime_types() ); - if ( ! in_array( $type['ext'], $default_types ) ) + if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) return sprintf( '%s', esc_url( $src ), esc_html( $src ) ); $primary = true; array_unshift( $default_types, 'src' ); @@ -879,7 +925,7 @@ function wp_audio_shortcode( $attr ) { foreach ( $default_types as $ext ) { if ( ! empty( $$ext ) ) { $type = wp_check_filetype( $$ext, wp_get_mime_types() ); - if ( $type['ext'] === $ext ) + if ( strtolower( $type['ext'] ) === $ext ) $primary = true; } } @@ -946,7 +992,7 @@ function wp_audio_shortcode( $attr ) { return apply_filters( 'wp_audio_shortcode', $html, $atts, $audio, $post_id, $library ); } -add_shortcode( 'audio', apply_filters( 'wp_audio_shortcode_handler', 'wp_audio_shortcode' ) ); +add_shortcode( 'audio', 'wp_audio_shortcode' ); /** * Return a filtered list of WP-supported video formats @@ -966,16 +1012,31 @@ function wp_get_video_extensions() { * * @since 3.6.0 * - * @param array $attr Attributes of the shortcode. + * @param array $attr Attributes of the shortcode. + * @param string $content Optional. Shortcode content. * @return string HTML content to display video. */ -function wp_video_shortcode( $attr ) { +function wp_video_shortcode( $attr, $content = '' ) { global $content_width; $post_id = get_post() ? get_the_ID() : 0; static $instances = 0; $instances++; + /** + * Override the default video shortcode. + * + * @since 3.7.0 + * + * @param null Empty variable to be replaced with shortcode markup. + * @param array $attr Attributes of the shortcode. + * @param string $content Shortcode content. + * @param int $instances Unique numeric ID of this video shortcode instance. + */ + $html = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instances ); + if ( '' !== $html ) + return $html; + $video = null; $default_types = wp_get_video_extensions(); @@ -1010,7 +1071,7 @@ function wp_video_shortcode( $attr ) { $primary = false; if ( ! empty( $src ) ) { $type = wp_check_filetype( $src, wp_get_mime_types() ); - if ( ! in_array( $type['ext'], $default_types ) ) + if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) return sprintf( '%s', esc_url( $src ), esc_html( $src ) ); $primary = true; array_unshift( $default_types, 'src' ); @@ -1018,7 +1079,7 @@ function wp_video_shortcode( $attr ) { foreach ( $default_types as $ext ) { if ( ! empty( $$ext ) ) { $type = wp_check_filetype( $$ext, wp_get_mime_types() ); - if ( $type['ext'] === $ext ) + if ( strtolower( $type['ext'] ) === $ext ) $primary = true; } } @@ -1090,7 +1151,7 @@ function wp_video_shortcode( $attr ) { $html = sprintf( '
%s
', $width, $html ); return apply_filters( 'wp_video_shortcode', $html, $atts, $video, $post_id, $library ); } -add_shortcode( 'video', apply_filters( 'wp_video_shortcode_handler', 'wp_video_shortcode' ) ); +add_shortcode( 'video', 'wp_video_shortcode' ); /** * Display previous image link that has the same post parent. @@ -1683,6 +1744,7 @@ function wp_prepare_attachment_for_js( $attachment ) { if ( $meta && 'image' === $type ) { $sizes = array(); + /** This filter is documented in wp-admin/includes/media.php */ $possible_sizes = apply_filters( 'image_size_names_choose', array( 'thumbnail' => __('Thumbnail'), 'medium' => __('Medium'),