Make WordPress Core

Ticket #27881: media-27881.2.diff

File media-27881.2.diff, 14.9 KB (added by wonderboymusic, 9 years ago)
  • src/wp-includes/media.php

     
    11961196                        unset( $attr['orderby'] );
    11971197        }
    11981198
    1199         extract( shortcode_atts( array(
     1199        $atts = shortcode_atts( array(
    12001200                'type'          => 'audio',
    12011201                'order'         => 'ASC',
    12021202                'orderby'       => 'menu_order ID',
     
    12081208                'tracknumbers' => true,
    12091209                'images'        => true,
    12101210                'artists'       => true
    1211         ), $attr, 'playlist' ) );
     1211        ), $attr, 'playlist' );
    12121212
    1213         $id = intval( $id );
    1214         if ( 'RAND' == $order ) {
    1215                 $orderby = 'none';
     1213        $id = intval( $atts['id'] );
     1214        if ( 'RAND' == $atts['order'] ) {
     1215                $atts['orderby'] = 'none';
    12161216        }
    12171217
    12181218        $args = array(
    12191219                'post_status' => 'inherit',
    12201220                'post_type' => 'attachment',
    1221                 'post_mime_type' => $type,
    1222                 'order' => $order,
    1223                 'orderby' => $orderby
     1221                'post_mime_type' => $atts['$type'],
     1222                'order' => $atts['order'],
     1223                'orderby' => $atts['orderby']
    12241224        );
    12251225
    1226         if ( ! empty( $include ) ) {
    1227                 $args['include'] = $include;
     1226        if ( ! empty( $atts['include'] ) ) {
     1227                $args['include'] = $atts['include'];
    12281228                $_attachments = get_posts( $args );
    12291229
    12301230                $attachments = array();
     
    12311231                foreach ( $_attachments as $key => $val ) {
    12321232                        $attachments[$val->ID] = $_attachments[$key];
    12331233                }
    1234         } elseif ( ! empty( $exclude ) ) {
     1234        } elseif ( ! empty( $atts['exclude'] ) ) {
    12351235                $args['post_parent'] = $id;
    1236                 $args['exclude'] = $exclude;
     1236                $args['exclude'] = $atts['exclude'];
    12371237                $attachments = get_children( $args );
    12381238        } else {
    12391239                $args['post_parent'] = $id;
     
    12631263        $data = compact( 'type' );
    12641264
    12651265        // don't pass strings to JSON, will be truthy in JS
    1266         foreach ( array( 'tracklist', 'tracknumbers', 'images', 'artists' ) as $key ) {
    1267                 $data[$key] = filter_var( $$key, FILTER_VALIDATE_BOOLEAN );
    1268         }
     1266        $data['tracklist'] = filter_var( $atts['tracklist'], FILTER_VALIDATE_BOOLEAN );
     1267        $data['tracknumbers'] = filter_var( $atts['tracknumbers'], FILTER_VALIDATE_BOOLEAN );
     1268        $data['images'] = filter_var( $atts['images'], FILTER_VALIDATE_BOOLEAN );
     1269        $data['artists'] = filter_var( $atts['artists'], FILTER_VALIDATE_BOOLEAN );
    12691270
    12701271        $tracks = array();
    12711272        foreach ( $attachments as $attachment ) {
     
    12891290                                }
    12901291                        }
    12911292
    1292                         if ( 'video' === $type ) {
     1293                        if ( 'video' === $atts['type'] ) {
    12931294                                if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
    12941295                                        $width = $meta['width'];
    12951296                                        $height = $meta['height'];
     
    13091310                        }
    13101311                }
    13111312
    1312                 if ( $images ) {
    1313                         $id = get_post_thumbnail_id( $attachment->ID );
    1314                         if ( ! empty( $id ) ) {
    1315                                 list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'full' );
     1313                if ( $atts['images'] ) {
     1314                        $thumb_id = get_post_thumbnail_id( $attachment->ID );
     1315                        if ( ! empty( $thumb_id ) ) {
     1316                                list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'full' );
    13161317                                $track['image'] = compact( 'src', 'width', 'height' );
    1317                                 list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'thumbnail' );
     1318                                list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' );
    13181319                                $track['thumb'] = compact( 'src', 'width', 'height' );
    13191320                        } else {
    13201321                                $src = wp_mime_type_icon( $attachment->ID );
     
    13291330        }
    13301331        $data['tracks'] = $tracks;
    13311332
    1332         $safe_type = esc_attr( $type );
    1333         $safe_style = esc_attr( $style );
     1333        $safe_type = esc_attr( $atts['type'] );
     1334        $safe_style = esc_attr( $atts['style'] );
    13341335
    13351336        ob_start();
    13361337
     
    13431344                 * @param string $type  Type of playlist. Possible values are 'audio' or 'video'.
    13441345                 * @param string $style The 'theme' for the playlist. Core provides 'light' and 'dark'.
    13451346                 */
    1346                 do_action( 'wp_playlist_scripts', $type, $style );
     1347                do_action( 'wp_playlist_scripts', $atts['type'], $atts['style'] );
    13471348        } ?>
    13481349<div class="wp-playlist wp-<?php echo $safe_type ?>-playlist wp-playlist-<?php echo $safe_style ?>">
    1349         <?php if ( 'audio' === $type ): ?>
     1350        <?php if ( 'audio' === $atts['type'] ): ?>
    13501351        <div class="wp-playlist-current-item"></div>
    13511352        <?php endif ?>
    13521353        <<?php echo $safe_type ?> controls="controls" preload="none" width="<?php
     
    14821483         * @param string $content   Shortcode content.
    14831484         * @param int    $instances Unique numeric ID of this audio shortcode instance.
    14841485         */
    1485         $html = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instances );
    1486         if ( '' !== $html )
    1487                 return $html;
     1486        $override = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instances );
     1487        if ( '' !== $override ) {
     1488                return $override;
     1489        }
    14881490
    14891491        $audio = null;
    14901492
     
    14951497                'autoplay' => '',
    14961498                'preload'  => 'none'
    14971499        );
    1498         foreach ( $default_types as $type )
     1500        foreach ( $default_types as $type ) {
    14991501                $defaults_atts[$type] = '';
     1502        }
    15001503
    15011504        $atts = shortcode_atts( $defaults_atts, $attr, 'audio' );
    1502         extract( $atts );
    15031505
    15041506        $primary = false;
    1505         if ( ! empty( $src ) ) {
    1506                 $type = wp_check_filetype( $src, wp_get_mime_types() );
    1507                 if ( ! in_array( strtolower( $type['ext'] ), $default_types ) )
    1508                         return sprintf( '<a class="wp-embedded-audio" href="%s">%s</a>', esc_url( $src ), esc_html( $src ) );
     1507        if ( ! empty( $atts['src'] ) ) {
     1508                $type = wp_check_filetype( $atts['src'], wp_get_mime_types() );
     1509                if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) {
     1510                        return sprintf( '<a class="wp-embedded-audio" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) );
     1511                }
    15091512                $primary = true;
    15101513                array_unshift( $default_types, 'src' );
    15111514        } else {
    15121515                foreach ( $default_types as $ext ) {
    1513                         if ( ! empty( $$ext ) ) {
    1514                                 $type = wp_check_filetype( $$ext, wp_get_mime_types() );
    1515                                 if ( strtolower( $type['ext'] ) === $ext )
     1516                        if ( ! empty( $atts[ $ext ] ) ) {
     1517                                $type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() );
     1518                                if ( strtolower( $type['ext'] ) === $ext ) {
    15161519                                        $primary = true;
     1520                                }
    15171521                        }
    15181522                }
    15191523        }
     
    15201524
    15211525        if ( ! $primary ) {
    15221526                $audios = get_attached_media( 'audio', $post_id );
    1523                 if ( empty( $audios ) )
     1527                if ( empty( $audios ) ) {
    15241528                        return;
     1529                }
    15251530
    15261531                $audio = reset( $audios );
    1527                 $src = wp_get_attachment_url( $audio->ID );
    1528                 if ( empty( $src ) )
     1532                $atts['src'] = wp_get_attachment_url( $audio->ID );
     1533                if ( empty( $atts['src'] ) ) {
    15291534                        return;
     1535                }
    15301536
    15311537                array_unshift( $default_types, 'src' );
    15321538        }
     
    15511557         *
    15521558         * @param string $class CSS class or list of space-separated classes.
    15531559         */
    1554         $atts = array(
     1560        $html_atts = array(
    15551561                'class'    => apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ),
    15561562                'id'       => sprintf( 'audio-%d-%d', $post_id, $instances ),
    1557                 'loop'     => $loop,
    1558                 'autoplay' => $autoplay,
    1559                 'preload'  => $preload,
     1563                'loop'     => $atts['loop'],
     1564                'autoplay' => $atts['autoplay'],
     1565                'preload'  => $atts['preload'],
    15601566                'style'    => 'width: 100%; visibility: hidden;',
    15611567        );
    15621568
    15631569        // These ones should just be omitted altogether if they are blank
    15641570        foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) {
    1565                 if ( empty( $atts[$a] ) )
    1566                         unset( $atts[$a] );
     1571                if ( empty( $html_atts[$a] ) ) {
     1572                        unset( $html_atts[$a] );
     1573                }
    15671574        }
    15681575
    15691576        $attr_strings = array();
    1570         foreach ( $atts as $k => $v ) {
     1577        foreach ( $html_atts as $k => $v ) {
    15711578                $attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
    15721579        }
    15731580
    15741581        $html = '';
    1575         if ( 'mediaelement' === $library && 1 === $instances )
     1582        if ( 'mediaelement' === $library && 1 === $instances ) {
    15761583                $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
     1584        }
    15771585        $html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) );
    15781586
    15791587        $fileurl = '';
    15801588        $source = '<source type="%s" src="%s" />';
    15811589        foreach ( $default_types as $fallback ) {
    1582                 if ( ! empty( $$fallback ) ) {
    1583                         if ( empty( $fileurl ) )
    1584                                 $fileurl = $$fallback;
    1585                         $type = wp_check_filetype( $$fallback, wp_get_mime_types() );
    1586                         $url = add_query_arg( '_', $instances, $$fallback );
     1590                if ( ! empty( $atts[ $fallback ] ) ) {
     1591                        if ( empty( $fileurl ) ) {
     1592                                $fileurl = $atts[ $fallback ];
     1593                        }
     1594                        $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() );
     1595                        $url = add_query_arg( '_', $instances, $atts[ $fallback ] );
    15871596                        $html .= sprintf( $source, $type['type'], esc_url( $url ) );
    15881597                }
    15891598        }
    15901599
    1591         if ( 'mediaelement' === $library )
     1600        if ( 'mediaelement' === $library ) {
    15921601                $html .= wp_mediaelement_fallback( $fileurl );
     1602        }
    15931603        $html .= '</audio>';
    15941604
    15951605        /**
     
    16741684         * @param string $content   Video shortcode content.
    16751685         * @param int    $instances Unique numeric ID of this video shortcode instance.
    16761686         */
    1677         $html = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instances );
    1678         if ( '' !== $html )
    1679                 return $html;
     1687        $override = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instances );
     1688        if ( '' !== $override ) {
     1689                return $override;
     1690        }
    16801691
    16811692        $video = null;
    16821693
     
    16911702                'height'   => 360,
    16921703        );
    16931704
    1694         foreach ( $default_types as $type )
     1705        foreach ( $default_types as $type ) {
    16951706                $defaults_atts[$type] = '';
     1707        }
    16961708
    16971709        $atts = shortcode_atts( $defaults_atts, $attr, 'video' );
    1698         extract( $atts );
    16991710
    17001711        if ( is_admin() ) {
    17011712                // shrink the video so it isn't huge in the admin
    1702                 if ( $width > $defaults_atts['width'] ) {
    1703                         $height = round( ( $height * $defaults_atts['width'] ) / $width );
    1704                         $width = $defaults_atts['width'];
     1713                if ( $atts['width'] > $defaults_atts['width'] ) {
     1714                        $atts['height'] = round( ( $atts['height'] * $defaults_atts['width'] ) / $atts['width'] );
     1715                        $atts['width'] = $defaults_atts['width'];
    17051716                }
    17061717        } else {
    17071718                // if the video is bigger than the theme
    1708                 if ( ! empty( $content_width ) && $width > $content_width ) {
    1709                         $height = round( ( $height * $content_width ) / $width );
    1710                         $width = $content_width;
     1719                if ( ! empty( $content_width ) && $atts['width'] > $content_width ) {
     1720                        $atts['height'] = round( ( $atts['height'] * $content_width ) / $atts['width'] );
     1721                        $atts['width'] = $content_width;
    17111722                }
    17121723        }
    17131724
     
    17141725        $yt_pattern = '#^https?://(:?www\.)?(:?youtube\.com/watch|youtu\.be/)#';
    17151726
    17161727        $primary = false;
    1717         if ( ! empty( $src ) ) {
    1718                 if ( ! preg_match( $yt_pattern, $src ) ) {
    1719                         $type = wp_check_filetype( $src, wp_get_mime_types() );
     1728        if ( ! empty( $atts['src'] ) ) {
     1729                if ( ! preg_match( $yt_pattern, $atts['src'] ) ) {
     1730                        $type = wp_check_filetype( $atts['src'], wp_get_mime_types() );
    17201731                        if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) {
    1721                                 return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $src ), esc_html( $src ) );
     1732                                return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) );
    17221733                        }
    17231734                }
    17241735                $primary = true;
     
    17251736                array_unshift( $default_types, 'src' );
    17261737        } else {
    17271738                foreach ( $default_types as $ext ) {
    1728                         if ( ! empty( $$ext ) ) {
    1729                                 $type = wp_check_filetype( $$ext, wp_get_mime_types() );
    1730                                 if ( strtolower( $type['ext'] ) === $ext )
     1739                        if ( ! empty( $atts[ $ext ] ) ) {
     1740                                $type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() );
     1741                                if ( strtolower( $type['ext'] ) === $ext ) {
    17311742                                        $primary = true;
     1743                                }
    17321744                        }
    17331745                }
    17341746        }
     
    17351747
    17361748        if ( ! $primary ) {
    17371749                $videos = get_attached_media( 'video', $post_id );
    1738                 if ( empty( $videos ) )
     1750                if ( empty( $videos ) ) {
    17391751                        return;
     1752                }
    17401753
    17411754                $video = reset( $videos );
    1742                 $src = wp_get_attachment_url( $video->ID );
    1743                 if ( empty( $src ) )
     1755                $atts['src'] = wp_get_attachment_url( $video->ID );
     1756                if ( empty( $atts['src'] ) ) {
    17441757                        return;
     1758                }
    17451759
    17461760                array_unshift( $default_types, 'src' );
    17471761        }
     
    17661780         *
    17671781         * @param string $class CSS class or list of space-separated classes.
    17681782         */
    1769         $atts = array(
     1783        $html_atts = array(
    17701784                'class'    => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ),
    17711785                'id'       => sprintf( 'video-%d-%d', $post_id, $instances ),
    1772                 'width'    => absint( $width ),
    1773                 'height'   => absint( $height ),
    1774                 'poster'   => esc_url( $poster ),
    1775                 'loop'     => $loop,
    1776                 'autoplay' => $autoplay,
    1777                 'preload'  => $preload,
     1786                'width'    => absint( $atts['width'] ),
     1787                'height'   => absint( $atts['height'] ),
     1788                'poster'   => esc_url( $atts['poster'] ),
     1789                'loop'     => $atts['loop'],
     1790                'autoplay' => $atts['autoplay'],
     1791                'preload'  => $atts['preload'],
    17781792        );
    17791793
    17801794        // These ones should just be omitted altogether if they are blank
    17811795        foreach ( array( 'poster', 'loop', 'autoplay', 'preload' ) as $a ) {
    1782                 if ( empty( $atts[$a] ) )
    1783                         unset( $atts[$a] );
     1796                if ( empty( $html_atts[$a] ) ) {
     1797                        unset( $html_atts[$a] );
     1798                }
    17841799        }
    17851800
    17861801        $attr_strings = array();
    1787         foreach ( $atts as $k => $v ) {
     1802        foreach ( $html_atts as $k => $v ) {
    17881803                $attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
    17891804        }
    17901805
    17911806        $html = '';
    1792         if ( 'mediaelement' === $library && 1 === $instances )
     1807        if ( 'mediaelement' === $library && 1 === $instances ) {
    17931808                $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
     1809        }
    17941810        $html .= sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) );
    17951811
    17961812        $fileurl = '';
    17971813        $source = '<source type="%s" src="%s" />';
    17981814        foreach ( $default_types as $fallback ) {
    1799                 if ( ! empty( $$fallback ) ) {
    1800                         if ( empty( $fileurl ) )
    1801                                 $fileurl = $$fallback;
    1802 
    1803                         if ( 'src' === $fallback && preg_match( $yt_pattern, $src ) ) {
     1815                if ( ! empty( $atts[ $fallback ] ) ) {
     1816                        if ( empty( $fileurl ) ) {
     1817                                $fileurl = $atts[ $fallback ];
     1818                        }
     1819                        if ( 'src' === $fallback && preg_match( $yt_pattern, $atts['src'] ) ) {
    18041820                                $type = array( 'type' => 'video/youtube' );
    18051821                        } else {
    1806                                 $type = wp_check_filetype( $$fallback, wp_get_mime_types() );
     1822                                $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() );
    18071823                        }
    1808                         $url = add_query_arg( '_', $instances, $$fallback );
     1824                        $url = add_query_arg( '_', $instances, $atts[ $fallback ] );
    18091825                        $html .= sprintf( $source, $type['type'], esc_url( $url ) );
    18101826                }
    18111827        }
    18121828
    18131829        if ( ! empty( $content ) ) {
    1814                 if ( false !== strpos( $content, "\n" ) )
     1830                if ( false !== strpos( $content, "\n" ) ) {
    18151831                        $content = str_replace( array( "\r\n", "\n", "\t" ), '', $content );
    1816 
     1832                }
    18171833                $html .= trim( $content );
    18181834        }
    18191835
    1820         if ( 'mediaelement' === $library )
     1836        if ( 'mediaelement' === $library ) {
    18211837                $html .= wp_mediaelement_fallback( $fileurl );
     1838        }
    18221839        $html .= '</video>';
    18231840
    1824         $html = sprintf( '<div style="width: %dpx; max-width: 100%%;" class="wp-video">%s</div>', $width, $html );
     1841        $output = sprintf( '<div style="width: %dpx; max-width: 100%%;" class="wp-video">%s</div>', $atts['width'], $html );
    18251842
    18261843        /**
    18271844         * Filter the output of the video shortcode.
     
    18281845         *
    18291846         * @since 3.6.0
    18301847         *
    1831          * @param string $html    Video shortcode HTML output.
     1848         * @param string $output  Video shortcode HTML output.
    18321849         * @param array  $atts    Array of video shortcode attributes.
    18331850         * @param string $video   Video file.
    18341851         * @param int    $post_id Post ID.
    18351852         * @param string $library Media library used for the video shortcode.
    18361853         */
    1837         return apply_filters( 'wp_video_shortcode', $html, $atts, $video, $post_id, $library );
     1854        return apply_filters( 'wp_video_shortcode', $output, $atts, $video, $post_id, $library );
    18381855}
    18391856add_shortcode( 'video', 'wp_video_shortcode' );
    18401857