Ticket #27881: media-27881.2.diff
File media-27881.2.diff, 14.9 KB (added by , 9 years ago) |
---|
-
src/wp-includes/media.php
1196 1196 unset( $attr['orderby'] ); 1197 1197 } 1198 1198 1199 extract(shortcode_atts( array(1199 $atts = shortcode_atts( array( 1200 1200 'type' => 'audio', 1201 1201 'order' => 'ASC', 1202 1202 'orderby' => 'menu_order ID', … … 1208 1208 'tracknumbers' => true, 1209 1209 'images' => true, 1210 1210 'artists' => true 1211 ), $attr, 'playlist' ) );1211 ), $attr, 'playlist' ); 1212 1212 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'; 1216 1216 } 1217 1217 1218 1218 $args = array( 1219 1219 'post_status' => 'inherit', 1220 1220 'post_type' => 'attachment', 1221 'post_mime_type' => $ type,1222 'order' => $ order,1223 'orderby' => $ orderby1221 'post_mime_type' => $atts['$type'], 1222 'order' => $atts['order'], 1223 'orderby' => $atts['orderby'] 1224 1224 ); 1225 1225 1226 if ( ! empty( $ include) ) {1227 $args['include'] = $ include;1226 if ( ! empty( $atts['include'] ) ) { 1227 $args['include'] = $atts['include']; 1228 1228 $_attachments = get_posts( $args ); 1229 1229 1230 1230 $attachments = array(); … … 1231 1231 foreach ( $_attachments as $key => $val ) { 1232 1232 $attachments[$val->ID] = $_attachments[$key]; 1233 1233 } 1234 } elseif ( ! empty( $ exclude) ) {1234 } elseif ( ! empty( $atts['exclude'] ) ) { 1235 1235 $args['post_parent'] = $id; 1236 $args['exclude'] = $ exclude;1236 $args['exclude'] = $atts['exclude']; 1237 1237 $attachments = get_children( $args ); 1238 1238 } else { 1239 1239 $args['post_parent'] = $id; … … 1263 1263 $data = compact( 'type' ); 1264 1264 1265 1265 // 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 ); 1269 1270 1270 1271 $tracks = array(); 1271 1272 foreach ( $attachments as $attachment ) { … … 1289 1290 } 1290 1291 } 1291 1292 1292 if ( 'video' === $ type) {1293 if ( 'video' === $atts['type'] ) { 1293 1294 if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { 1294 1295 $width = $meta['width']; 1295 1296 $height = $meta['height']; … … 1309 1310 } 1310 1311 } 1311 1312 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' ); 1316 1317 $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' ); 1318 1319 $track['thumb'] = compact( 'src', 'width', 'height' ); 1319 1320 } else { 1320 1321 $src = wp_mime_type_icon( $attachment->ID ); … … 1329 1330 } 1330 1331 $data['tracks'] = $tracks; 1331 1332 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'] ); 1334 1335 1335 1336 ob_start(); 1336 1337 … … 1343 1344 * @param string $type Type of playlist. Possible values are 'audio' or 'video'. 1344 1345 * @param string $style The 'theme' for the playlist. Core provides 'light' and 'dark'. 1345 1346 */ 1346 do_action( 'wp_playlist_scripts', $ type, $style);1347 do_action( 'wp_playlist_scripts', $atts['type'], $atts['style'] ); 1347 1348 } ?> 1348 1349 <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'] ): ?> 1350 1351 <div class="wp-playlist-current-item"></div> 1351 1352 <?php endif ?> 1352 1353 <<?php echo $safe_type ?> controls="controls" preload="none" width="<?php … … 1482 1483 * @param string $content Shortcode content. 1483 1484 * @param int $instances Unique numeric ID of this audio shortcode instance. 1484 1485 */ 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 } 1488 1490 1489 1491 $audio = null; 1490 1492 … … 1495 1497 'autoplay' => '', 1496 1498 'preload' => 'none' 1497 1499 ); 1498 foreach ( $default_types as $type ) 1500 foreach ( $default_types as $type ) { 1499 1501 $defaults_atts[$type] = ''; 1502 } 1500 1503 1501 1504 $atts = shortcode_atts( $defaults_atts, $attr, 'audio' ); 1502 extract( $atts );1503 1505 1504 1506 $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 } 1509 1512 $primary = true; 1510 1513 array_unshift( $default_types, 'src' ); 1511 1514 } else { 1512 1515 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 ) { 1516 1519 $primary = true; 1520 } 1517 1521 } 1518 1522 } 1519 1523 } … … 1520 1524 1521 1525 if ( ! $primary ) { 1522 1526 $audios = get_attached_media( 'audio', $post_id ); 1523 if ( empty( $audios ) ) 1527 if ( empty( $audios ) ) { 1524 1528 return; 1529 } 1525 1530 1526 1531 $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'] ) ) { 1529 1534 return; 1535 } 1530 1536 1531 1537 array_unshift( $default_types, 'src' ); 1532 1538 } … … 1551 1557 * 1552 1558 * @param string $class CSS class or list of space-separated classes. 1553 1559 */ 1554 $ atts = array(1560 $html_atts = array( 1555 1561 'class' => apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ), 1556 1562 'id' => sprintf( 'audio-%d-%d', $post_id, $instances ), 1557 'loop' => $ loop,1558 'autoplay' => $a utoplay,1559 'preload' => $ preload,1563 'loop' => $atts['loop'], 1564 'autoplay' => $atts['autoplay'], 1565 'preload' => $atts['preload'], 1560 1566 'style' => 'width: 100%; visibility: hidden;', 1561 1567 ); 1562 1568 1563 1569 // These ones should just be omitted altogether if they are blank 1564 1570 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 } 1567 1574 } 1568 1575 1569 1576 $attr_strings = array(); 1570 foreach ( $ atts as $k => $v ) {1577 foreach ( $html_atts as $k => $v ) { 1571 1578 $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; 1572 1579 } 1573 1580 1574 1581 $html = ''; 1575 if ( 'mediaelement' === $library && 1 === $instances ) 1582 if ( 'mediaelement' === $library && 1 === $instances ) { 1576 1583 $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n"; 1584 } 1577 1585 $html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) ); 1578 1586 1579 1587 $fileurl = ''; 1580 1588 $source = '<source type="%s" src="%s" />'; 1581 1589 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 ] ); 1587 1596 $html .= sprintf( $source, $type['type'], esc_url( $url ) ); 1588 1597 } 1589 1598 } 1590 1599 1591 if ( 'mediaelement' === $library ) 1600 if ( 'mediaelement' === $library ) { 1592 1601 $html .= wp_mediaelement_fallback( $fileurl ); 1602 } 1593 1603 $html .= '</audio>'; 1594 1604 1595 1605 /** … … 1674 1684 * @param string $content Video shortcode content. 1675 1685 * @param int $instances Unique numeric ID of this video shortcode instance. 1676 1686 */ 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 } 1680 1691 1681 1692 $video = null; 1682 1693 … … 1691 1702 'height' => 360, 1692 1703 ); 1693 1704 1694 foreach ( $default_types as $type ) 1705 foreach ( $default_types as $type ) { 1695 1706 $defaults_atts[$type] = ''; 1707 } 1696 1708 1697 1709 $atts = shortcode_atts( $defaults_atts, $attr, 'video' ); 1698 extract( $atts );1699 1710 1700 1711 if ( is_admin() ) { 1701 1712 // 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']; 1705 1716 } 1706 1717 } else { 1707 1718 // 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; 1711 1722 } 1712 1723 } 1713 1724 … … 1714 1725 $yt_pattern = '#^https?://(:?www\.)?(:?youtube\.com/watch|youtu\.be/)#'; 1715 1726 1716 1727 $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() ); 1720 1731 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'] ) ); 1722 1733 } 1723 1734 } 1724 1735 $primary = true; … … 1725 1736 array_unshift( $default_types, 'src' ); 1726 1737 } else { 1727 1738 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 ) { 1731 1742 $primary = true; 1743 } 1732 1744 } 1733 1745 } 1734 1746 } … … 1735 1747 1736 1748 if ( ! $primary ) { 1737 1749 $videos = get_attached_media( 'video', $post_id ); 1738 if ( empty( $videos ) ) 1750 if ( empty( $videos ) ) { 1739 1751 return; 1752 } 1740 1753 1741 1754 $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'] ) ) { 1744 1757 return; 1758 } 1745 1759 1746 1760 array_unshift( $default_types, 'src' ); 1747 1761 } … … 1766 1780 * 1767 1781 * @param string $class CSS class or list of space-separated classes. 1768 1782 */ 1769 $ atts = array(1783 $html_atts = array( 1770 1784 'class' => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ), 1771 1785 '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' => $a utoplay,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'], 1778 1792 ); 1779 1793 1780 1794 // These ones should just be omitted altogether if they are blank 1781 1795 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 } 1784 1799 } 1785 1800 1786 1801 $attr_strings = array(); 1787 foreach ( $ atts as $k => $v ) {1802 foreach ( $html_atts as $k => $v ) { 1788 1803 $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; 1789 1804 } 1790 1805 1791 1806 $html = ''; 1792 if ( 'mediaelement' === $library && 1 === $instances ) 1807 if ( 'mediaelement' === $library && 1 === $instances ) { 1793 1808 $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n"; 1809 } 1794 1810 $html .= sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) ); 1795 1811 1796 1812 $fileurl = ''; 1797 1813 $source = '<source type="%s" src="%s" />'; 1798 1814 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'] ) ) { 1804 1820 $type = array( 'type' => 'video/youtube' ); 1805 1821 } else { 1806 $type = wp_check_filetype( $ $fallback, wp_get_mime_types() );1822 $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); 1807 1823 } 1808 $url = add_query_arg( '_', $instances, $ $fallback);1824 $url = add_query_arg( '_', $instances, $atts[ $fallback ] ); 1809 1825 $html .= sprintf( $source, $type['type'], esc_url( $url ) ); 1810 1826 } 1811 1827 } 1812 1828 1813 1829 if ( ! empty( $content ) ) { 1814 if ( false !== strpos( $content, "\n" ) ) 1830 if ( false !== strpos( $content, "\n" ) ) { 1815 1831 $content = str_replace( array( "\r\n", "\n", "\t" ), '', $content ); 1816 1832 } 1817 1833 $html .= trim( $content ); 1818 1834 } 1819 1835 1820 if ( 'mediaelement' === $library ) 1836 if ( 'mediaelement' === $library ) { 1821 1837 $html .= wp_mediaelement_fallback( $fileurl ); 1838 } 1822 1839 $html .= '</video>'; 1823 1840 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 ); 1825 1842 1826 1843 /** 1827 1844 * Filter the output of the video shortcode. … … 1828 1845 * 1829 1846 * @since 3.6.0 1830 1847 * 1831 * @param string $ htmlVideo shortcode HTML output.1848 * @param string $output Video shortcode HTML output. 1832 1849 * @param array $atts Array of video shortcode attributes. 1833 1850 * @param string $video Video file. 1834 1851 * @param int $post_id Post ID. 1835 1852 * @param string $library Media library used for the video shortcode. 1836 1853 */ 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 ); 1838 1855 } 1839 1856 add_shortcode( 'video', 'wp_video_shortcode' ); 1840 1857