Make WordPress Core

Ticket #23572: 23572.3.diff

File 23572.3.diff, 6.2 KB (added by wonderboymusic, 11 years ago)
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index cdcdd23..c28d24d 100644
    function wp_audio_shortcode( $attr ) { 
    874874        }
    875875
    876876        if ( ! $primary ) {
    877                 $audios = get_post_audio( $post_id );
     877                $audios = get_attached_audio( $post_id );
    878878                if ( empty( $audios ) )
    879879                        return;
    880880
    function wp_video_shortcode( $attr ) { 
    981981        }
    982982
    983983        if ( ! $primary ) {
    984                 $videos = get_post_video( $post_id );
     984                $videos = get_attached_video( $post_id );
    985985                if ( empty( $videos ) )
    986986                        return;
    987987
    function wp_enqueue_media( $args = array() ) { 
    17811781 * @param int $post_id  Post ID
    17821782 * @return array Found audio attachments
    17831783 */
    1784 function get_post_audio( $post_id = 0 ) {
     1784function get_attached_audio( $post_id = 0 ) {
    17851785        $post = empty( $post_id ) ? get_post() : get_post( $post_id );
    17861786        if ( empty( $post ) )
    17871787                return;
    function get_post_audio( $post_id = 0 ) { 
    18051805 * @param int $post_id  Post ID
    18061806 * @return array Found video attachments
    18071807 */
    1808 function get_post_video( $post_id = 0 ) {
     1808function get_attached_video( $post_id = 0 ) {
    18091809        $post = empty( $post_id ) ? get_post() : get_post( $post_id );
    18101810        if ( empty( $post ) )
    18111811                return;
    function get_post_video( $post_id = 0 ) { 
    18221822}
    18231823
    18241824/**
     1825 * Extract the srcs from the post's [{media type}] <source>s
     1826 *
     1827 * @since 3.6.0
     1828 *
     1829 * @param string $content A string which might contain media data.
     1830 * @param boolean $remove Whether to remove the found URL from the passed content.
     1831 * @return array A list of lists. Each item has a list of sources corresponding
     1832 *              to a [{media type}]'s primary src and specified fallbacks
     1833 */
     1834function get_content_media( $type, &$content, $remove = false ) {
     1835        $src = '';
     1836        $items = array();
     1837        $matches = array();
     1838
     1839        if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
     1840                foreach ( $matches as $shortcode ) {
     1841                        if ( $type === $shortcode[2] ) {
     1842                                $srcs = array();
     1843                                $count = 1;
     1844                                if ( $remove )
     1845                                        $content = str_replace( $shortcode[0], '', $content, $count );
     1846
     1847                                $item = do_shortcode_tag( $shortcode );
     1848                                preg_match_all( '#src=[\'"](.+?)[\'"]#is', $item, $src, PREG_SET_ORDER );
     1849                                if ( ! empty( $src ) ) {
     1850                                        foreach ( $src as $s )
     1851                                                $srcs[] = $s[1];
     1852
     1853                                        $items[] = array_values( array_unique( $srcs ) );
     1854                                }
     1855                        }
     1856                }
     1857        }
     1858        return $items;
     1859}
     1860
     1861/**
     1862 * Check the content blob for an <{media type}>, <object>, <embed>, or <iframe>, in that order
     1863 * If no HTML tag is found, check the first line of the post for a URL
     1864 *
     1865 * @since 3.6.0
     1866 *
     1867 * @param string $content A string which might contain media data.
     1868 * @param boolean $remove Whether to remove the found URL from the passed content.
     1869 * @return array A list of found HTML media embeds and possibly a URL by itself
     1870 */
     1871function get_embedded_media( $type, &$content, $remove = false ) {
     1872        $html = array();
     1873        $matches = '';
     1874
     1875        foreach ( array( $type, 'object', 'embed', 'iframe' ) as $tag ) {
     1876                if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
     1877                        $html[] = $matches[1];
     1878                        if ( $remove )
     1879                                $content = str_replace( $matches[0], '', $content );
     1880
     1881                        return $html;
     1882                }
     1883        }
     1884
     1885        $lines = explode( "\n", trim( $content ) );
     1886        $line = trim( array_shift( $lines  ) );
     1887
     1888        if ( 0 === stripos( $line, 'http' ) ) {
     1889                if ( $remove )
     1890                        $content = join( "\n", $lines );
     1891
     1892                $html[] = $line;
     1893        }
     1894        return $html;
     1895}
     1896
     1897/**
     1898 * Extract the srcs from the post's [audio] <source>s
     1899 *
     1900 * @since 3.6.0
     1901 *
     1902 * @param string $content A string which might contain audio data.
     1903 * @param boolean $remove Whether to remove the found URL from the passed content.
     1904 * @return array A list of lists. Each item has a list of sources corresponding
     1905 *              to a [audio]'s primary src and specified fallbacks
     1906 */
     1907function get_content_audio( &$content, $remove = false ) {
     1908        return get_content_media( 'audio', $content, $remove );
     1909}
     1910
     1911/**
     1912 * Check the content blob for an <audio>, <object>, <embed>, or <iframe>, in that order
     1913 * If no HTML tag is found, check the first line of the post for a URL
     1914 *
     1915 * @since 3.6.0
     1916 *
     1917 * @param string $content A string which might contain audio data.
     1918 * @param boolean $remove Whether to remove the found URL from the passed content.
     1919 * @return array A list of found HTML audio embeds and possibly a URL by itself
     1920 */
     1921function get_embedded_audio( &$content, $remove = false ) {
     1922        return get_embedded_media( 'audio', $content, $remove );
     1923}
     1924
     1925/**
     1926 * Extract the srcs from the post's [video] <source>s
     1927 *
     1928 * @since 3.6.0
     1929 *
     1930 * @param string $content A string which might contain video data.
     1931 * @param boolean $remove Whether to remove the found URL from the passed content.
     1932 * @return array A list of lists. Each item has a list of sources corresponding
     1933 *              to a [video]'s primary src and specified fallbacks
     1934 */
     1935function get_content_video( &$content, $remove = false ) {
     1936        return get_content_media( 'video', $content, $remove );
     1937}
     1938
     1939/**
     1940 * Check the content blob for a <video>, <object>, <embed>, or <iframe>, in that order
     1941 * If no HTML tag is found, check the first line of the post for a URL
     1942 *
     1943 * @since 3.6.0
     1944 *
     1945 * @param string $content A string which might contain video data.
     1946 * @param boolean $remove Whether to remove the found URL from the passed content.
     1947 * @return array A list of found HTML video embeds and possibly a URL by itself
     1948 */
     1949function get_embedded_video( &$content, $remove = false ) {
     1950        return get_embedded_media( 'video', $content, $remove );
     1951}
     1952
     1953/**
    18251954 * Audio embed handler callback.
    18261955 *
     1956 * @since 3.6.0
     1957 *
    18271958 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
    18281959 * @param array $attr Embed attributes.
    18291960 * @param string $url The original URL that was matched by the regex.
    wp_embed_register_handler( 'wp_audio_embed', '#https?://.+?\.(' . join( '|', wp_ 
    18411972/**
    18421973 * Video embed handler callback.
    18431974 *
     1975 * @since 3.6.0
     1976 *
    18441977 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
    18451978 * @param array $attr Embed attributes.
    18461979 * @param string $url The original URL that was matched by the regex.