Changeset 28342
- Timestamp:
- 05/07/2014 05:35:09 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r28194 r28342 1197 1197 } 1198 1198 1199 extract(shortcode_atts( array(1199 $atts = shortcode_atts( array( 1200 1200 'type' => 'audio', 1201 1201 'order' => 'ASC', … … 1209 1209 'images' => true, 1210 1210 'artists' => true 1211 ), $attr, 'playlist' ) );1212 1213 $id = intval( $ id);1214 if ( 'RAND' == $ order) {1215 $ orderby= 'none';1211 ), $attr, 'playlist' ); 1212 1213 $id = intval( $atts['id'] ); 1214 if ( 'RAND' == $atts['order'] ) { 1215 $atts['orderby'] = 'none'; 1216 1216 } 1217 1217 … … 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 … … 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 { … … 1261 1261 $theme_height = empty( $content_width ) ? $default_height : round( ( $default_height * $theme_width ) / $default_width ); 1262 1262 1263 $data = compact( 'type' ); 1264 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 } 1263 $data = array( 1264 'type' => $atts['type'], 1265 // don't pass strings to JSON, will be truthy in JS 1266 'tracklist' => filter_var( $atts['tracklist'], FILTER_VALIDATE_BOOLEAN ), 1267 'tracknumbers' => filter_var( $atts['tracknumbers'], FILTER_VALIDATE_BOOLEAN ), 1268 'images' => filter_var( $atts['images'], FILTER_VALIDATE_BOOLEAN ), 1269 'artists' => filter_var( $atts['artists'], FILTER_VALIDATE_BOOLEAN ), 1270 ); 1269 1271 1270 1272 $tracks = array(); … … 1290 1292 } 1291 1293 1292 if ( 'video' === $ type) {1294 if ( 'video' === $atts['type'] ) { 1293 1295 if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { 1294 1296 $width = $meta['width']; … … 1310 1312 } 1311 1313 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' );1314 if ( $atts['images'] ) { 1315 $thumb_id = get_post_thumbnail_id( $attachment->ID ); 1316 if ( ! empty( $thumb_id ) ) { 1317 list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'full' ); 1316 1318 $track['image'] = compact( 'src', 'width', 'height' ); 1317 list( $src, $width, $height ) = wp_get_attachment_image_src( $ id, 'thumbnail' );1319 list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' ); 1318 1320 $track['thumb'] = compact( 'src', 'width', 'height' ); 1319 1321 } else { … … 1330 1332 $data['tracks'] = $tracks; 1331 1333 1332 $safe_type = esc_attr( $ type);1333 $safe_style = esc_attr( $ style);1334 $safe_type = esc_attr( $atts['type'] ); 1335 $safe_style = esc_attr( $atts['style'] ); 1334 1336 1335 1337 ob_start(); … … 1344 1346 * @param string $style The 'theme' for the playlist. Core provides 'light' and 'dark'. 1345 1347 */ 1346 do_action( 'wp_playlist_scripts', $ type, $style);1348 do_action( 'wp_playlist_scripts', $atts['type'], $atts['style'] ); 1347 1349 } ?> 1348 1350 <div class="wp-playlist wp-<?php echo $safe_type ?>-playlist wp-playlist-<?php echo $safe_style ?>"> 1349 <?php if ( 'audio' === $ type): ?>1351 <?php if ( 'audio' === $atts['type'] ): ?> 1350 1352 <div class="wp-playlist-current-item"></div> 1351 1353 <?php endif ?> … … 1483 1485 * @param int $instances Unique numeric ID of this audio shortcode instance. 1484 1486 */ 1485 $html = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instances ); 1486 if ( '' !== $html ) 1487 return $html; 1487 $override = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instances ); 1488 if ( '' !== $override ) { 1489 return $override; 1490 } 1488 1491 1489 1492 $audio = null; … … 1496 1499 'preload' => 'none' 1497 1500 ); 1498 foreach ( $default_types as $type ) 1501 foreach ( $default_types as $type ) { 1499 1502 $defaults_atts[$type] = ''; 1503 } 1500 1504 1501 1505 $atts = shortcode_atts( $defaults_atts, $attr, 'audio' ); 1502 extract( $atts );1503 1506 1504 1507 $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 ) ); 1508 if ( ! empty( $atts['src'] ) ) { 1509 $type = wp_check_filetype( $atts['src'], wp_get_mime_types() ); 1510 if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) { 1511 return sprintf( '<a class="wp-embedded-audio" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) ); 1512 } 1509 1513 $primary = true; 1510 1514 array_unshift( $default_types, 'src' ); 1511 1515 } else { 1512 1516 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 ) 1517 if ( ! empty( $atts[ $ext ] ) ) { 1518 $type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() ); 1519 if ( strtolower( $type['ext'] ) === $ext ) { 1516 1520 $primary = true; 1521 } 1517 1522 } 1518 1523 } … … 1521 1526 if ( ! $primary ) { 1522 1527 $audios = get_attached_media( 'audio', $post_id ); 1523 if ( empty( $audios ) ) 1528 if ( empty( $audios ) ) { 1524 1529 return; 1530 } 1525 1531 1526 1532 $audio = reset( $audios ); 1527 $ src= wp_get_attachment_url( $audio->ID );1528 if ( empty( $ src ) )1533 $atts['src'] = wp_get_attachment_url( $audio->ID ); 1534 if ( empty( $atts['src'] ) ) { 1529 1535 return; 1536 } 1530 1537 1531 1538 array_unshift( $default_types, 'src' ); … … 1552 1559 * @param string $class CSS class or list of space-separated classes. 1553 1560 */ 1554 $ atts = array(1561 $html_atts = array( 1555 1562 'class' => apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ), 1556 1563 'id' => sprintf( 'audio-%d-%d', $post_id, $instances ), 1557 'loop' => $ loop,1558 'autoplay' => $a utoplay,1559 'preload' => $ preload,1564 'loop' => $atts['loop'], 1565 'autoplay' => $atts['autoplay'], 1566 'preload' => $atts['preload'], 1560 1567 'style' => 'width: 100%; visibility: hidden;', 1561 1568 ); … … 1563 1570 // These ones should just be omitted altogether if they are blank 1564 1571 foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) { 1565 if ( empty( $atts[$a] ) ) 1566 unset( $atts[$a] ); 1572 if ( empty( $html_atts[$a] ) ) { 1573 unset( $html_atts[$a] ); 1574 } 1567 1575 } 1568 1576 1569 1577 $attr_strings = array(); 1570 foreach ( $ atts as $k => $v ) {1578 foreach ( $html_atts as $k => $v ) { 1571 1579 $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; 1572 1580 } 1573 1581 1574 1582 $html = ''; 1575 if ( 'mediaelement' === $library && 1 === $instances ) 1583 if ( 'mediaelement' === $library && 1 === $instances ) { 1576 1584 $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n"; 1585 } 1577 1586 $html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) ); 1578 1587 … … 1580 1589 $source = '<source type="%s" src="%s" />'; 1581 1590 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 ); 1591 if ( ! empty( $atts[ $fallback ] ) ) { 1592 if ( empty( $fileurl ) ) { 1593 $fileurl = $atts[ $fallback ]; 1594 } 1595 $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); 1596 $url = add_query_arg( '_', $instances, $atts[ $fallback ] ); 1587 1597 $html .= sprintf( $source, $type['type'], esc_url( $url ) ); 1588 1598 } 1589 1599 } 1590 1600 1591 if ( 'mediaelement' === $library ) 1601 if ( 'mediaelement' === $library ) { 1592 1602 $html .= wp_mediaelement_fallback( $fileurl ); 1603 } 1593 1604 $html .= '</audio>'; 1594 1605 … … 1675 1686 * @param int $instances Unique numeric ID of this video shortcode instance. 1676 1687 */ 1677 $html = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instances ); 1678 if ( '' !== $html ) 1679 return $html; 1688 $override = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instances ); 1689 if ( '' !== $override ) { 1690 return $override; 1691 } 1680 1692 1681 1693 $video = null; … … 1692 1704 ); 1693 1705 1694 foreach ( $default_types as $type ) 1706 foreach ( $default_types as $type ) { 1695 1707 $defaults_atts[$type] = ''; 1708 } 1696 1709 1697 1710 $atts = shortcode_atts( $defaults_atts, $attr, 'video' ); 1698 extract( $atts );1699 1711 1700 1712 if ( is_admin() ) { 1701 1713 // 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'];1714 if ( $atts['width'] > $defaults_atts['width'] ) { 1715 $atts['height'] = round( ( $atts['height'] * $defaults_atts['width'] ) / $atts['width'] ); 1716 $atts['width'] = $defaults_atts['width']; 1705 1717 } 1706 1718 } else { 1707 1719 // 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;1720 if ( ! empty( $content_width ) && $atts['width'] > $content_width ) { 1721 $atts['height'] = round( ( $atts['height'] * $content_width ) / $atts['width'] ); 1722 $atts['width'] = $content_width; 1711 1723 } 1712 1724 } … … 1715 1727 1716 1728 $primary = false; 1717 if ( ! empty( $ src) ) {1718 if ( ! preg_match( $yt_pattern, $ src) ) {1719 $type = wp_check_filetype( $ src, wp_get_mime_types() );1729 if ( ! empty( $atts['src'] ) ) { 1730 if ( ! preg_match( $yt_pattern, $atts['src'] ) ) { 1731 $type = wp_check_filetype( $atts['src'], wp_get_mime_types() ); 1720 1732 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) );1733 return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) ); 1722 1734 } 1723 1735 } … … 1726 1738 } else { 1727 1739 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 ) 1740 if ( ! empty( $atts[ $ext ] ) ) { 1741 $type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() ); 1742 if ( strtolower( $type['ext'] ) === $ext ) { 1731 1743 $primary = true; 1744 } 1732 1745 } 1733 1746 } … … 1736 1749 if ( ! $primary ) { 1737 1750 $videos = get_attached_media( 'video', $post_id ); 1738 if ( empty( $videos ) ) 1751 if ( empty( $videos ) ) { 1739 1752 return; 1753 } 1740 1754 1741 1755 $video = reset( $videos ); 1742 $ src= wp_get_attachment_url( $video->ID );1743 if ( empty( $ src ) )1756 $atts['src'] = wp_get_attachment_url( $video->ID ); 1757 if ( empty( $atts['src'] ) ) { 1744 1758 return; 1759 } 1745 1760 1746 1761 array_unshift( $default_types, 'src' ); … … 1767 1782 * @param string $class CSS class or list of space-separated classes. 1768 1783 */ 1769 $ atts = array(1784 $html_atts = array( 1770 1785 'class' => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ), 1771 1786 '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,1787 'width' => absint( $atts['width'] ), 1788 'height' => absint( $atts['height'] ), 1789 'poster' => esc_url( $atts['poster'] ), 1790 'loop' => $atts['loop'], 1791 'autoplay' => $atts['autoplay'], 1792 'preload' => $atts['preload'], 1778 1793 ); 1779 1794 1780 1795 // These ones should just be omitted altogether if they are blank 1781 1796 foreach ( array( 'poster', 'loop', 'autoplay', 'preload' ) as $a ) { 1782 if ( empty( $atts[$a] ) ) 1783 unset( $atts[$a] ); 1797 if ( empty( $html_atts[$a] ) ) { 1798 unset( $html_atts[$a] ); 1799 } 1784 1800 } 1785 1801 1786 1802 $attr_strings = array(); 1787 foreach ( $ atts as $k => $v ) {1803 foreach ( $html_atts as $k => $v ) { 1788 1804 $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; 1789 1805 } 1790 1806 1791 1807 $html = ''; 1792 if ( 'mediaelement' === $library && 1 === $instances ) 1808 if ( 'mediaelement' === $library && 1 === $instances ) { 1793 1809 $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n"; 1810 } 1794 1811 $html .= sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) ); 1795 1812 … … 1797 1814 $source = '<source type="%s" src="%s" />'; 1798 1815 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) ) {1816 if ( ! empty( $atts[ $fallback ] ) ) { 1817 if ( empty( $fileurl ) ) { 1818 $fileurl = $atts[ $fallback ]; 1819 } 1820 if ( 'src' === $fallback && preg_match( $yt_pattern, $atts['src'] ) ) { 1804 1821 $type = array( 'type' => 'video/youtube' ); 1805 1822 } else { 1806 $type = wp_check_filetype( $ $fallback, wp_get_mime_types() );1823 $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); 1807 1824 } 1808 $url = add_query_arg( '_', $instances, $ $fallback);1825 $url = add_query_arg( '_', $instances, $atts[ $fallback ] ); 1809 1826 $html .= sprintf( $source, $type['type'], esc_url( $url ) ); 1810 1827 } … … 1812 1829 1813 1830 if ( ! empty( $content ) ) { 1814 if ( false !== strpos( $content, "\n" ) ) 1831 if ( false !== strpos( $content, "\n" ) ) { 1815 1832 $content = str_replace( array( "\r\n", "\n", "\t" ), '', $content ); 1816 1833 } 1817 1834 $html .= trim( $content ); 1818 1835 } 1819 1836 1820 if ( 'mediaelement' === $library ) 1837 if ( 'mediaelement' === $library ) { 1821 1838 $html .= wp_mediaelement_fallback( $fileurl ); 1839 } 1822 1840 $html .= '</video>'; 1823 1841 1824 $ html = sprintf( '<div style="width: %dpx; max-width: 100%%;" class="wp-video">%s</div>', $width, $html );1842 $output = sprintf( '<div style="width: %dpx; max-width: 100%%;" class="wp-video">%s</div>', $atts['width'], $html ); 1825 1843 1826 1844 /** … … 1829 1847 * @since 3.6.0 1830 1848 * 1831 * @param string $ htmlVideo shortcode HTML output.1849 * @param string $output Video shortcode HTML output. 1832 1850 * @param array $atts Array of video shortcode attributes. 1833 1851 * @param string $video Video file. … … 1835 1853 * @param string $library Media library used for the video shortcode. 1836 1854 */ 1837 return apply_filters( 'wp_video_shortcode', $ html, $atts, $video, $post_id, $library );1855 return apply_filters( 'wp_video_shortcode', $output, $atts, $video, $post_id, $library ); 1838 1856 } 1839 1857 add_shortcode( 'video', 'wp_video_shortcode' );
Note: See TracChangeset
for help on using the changeset viewer.