Make WordPress Core

Ticket #23282: 23282.12.diff

File 23282.12.diff, 18.5 KB (added by wonderboymusic, 12 years ago)
  • wp-admin/includes/ajax-actions.php

    diff --git wp-admin/includes/ajax-actions.php wp-admin/includes/ajax-actions.php
    index 8581c9e..93a897f 100644
    function wp_ajax_send_attachment_to_editor() { 
    20242024                $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
    20252025                $title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
    20262026                $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt );
     2027        } elseif ( 'video' === substr( $post->post_mime_type, 0, 5 ) || 'audio' === substr( $post->post_mime_type, 0, 5 )  ) {
     2028                $html = stripslashes_deep( $_POST['html'] );
    20272029        }
    20282030
    20292031        $html = apply_filters( 'media_send_to_editor', $html, $id, $attachment );
  • wp-includes/functions.php

    diff --git wp-includes/functions.php wp-includes/functions.php
    index b29b941..78dedb6 100644
    $("#wp-auth-check-form iframe").load(function(){ 
    40204020</script>
    40214021</div>' ) );
    40224022}
     4023
     4024/**
     4025 * Return RegEx body to liberally match an opening HTML tag that:
     4026 * 1. Is self-closing or
     4027 * 2. Has no body but has a closing tag of the same name or
     4028 * 3. Contains a body and a closing tag of the same name
     4029 *
     4030 * Note: this RegEx does not balance inner tags and does not attempt to produce valid HTML
     4031 *
     4032 * @since 3.6.0
     4033 *
     4034 * @param string $tag An HTML tag name. Example: 'video'
     4035 * @return string
     4036 */
     4037function get_tag_regex( $tag ) {
     4038        if ( empty( $tag ) )
     4039                return;
     4040
     4041        return sprintf( '(<%1$s[^>]*(?:/?>$|>[\s\S]*?</%1$s>))', tag_escape( $tag ) );
     4042}
     4043 No newline at end of file
  • wp-includes/js/media-editor.js

    diff --git wp-includes/js/media-editor.js wp-includes/js/media-editor.js
    index 15eff8d..7dbbb79 100644
     
    6666                                        src:       size.url,
    6767                                        captionId: 'attachment_' + attachment.id
    6868                                });
    69 
     69                        } else if ( 'video' === attachment.type || 'audio' === attachment.type ) {
     70                                _.extend( props, _.pick( attachment, 'title', 'type', 'icon', 'mime' ) );
    7071                        // Format properties for non-images.
    7172                        } else {
    7273                                props.title = props.title || attachment.filename;
     
    9596                        return wp.html.string( options );
    9697                },
    9798
     99                audio: function( props, attachment ) {
     100                        var shortcode, html;
     101
     102                        props = wp.media.string.props( props, attachment );
     103
     104                        shortcode = {};
     105
     106                        if ( props.mime ) {
     107                                switch ( props.mime ) {
     108                                case 'audio/mpeg':
     109                                        if ( props.linkUrl.indexOf( 'mp3' ) )
     110                                                shortcode.mp3 = props.linkUrl;
     111                                        else if ( props.linkUrl.indexOf( 'm4a' ) )
     112                                                shortcode.m4a = props.linkUrl;
     113                                        break;
     114                                case 'audio/mp3':
     115                                        shortcode.mp3 = props.linkUrl;
     116                                        break;
     117                                case 'audio/m4a':
     118                                        shortcode.m4a = props.linkUrl;
     119                                        break;
     120                                case 'audio/wav':
     121                                        shortcode.wav = props.linkUrl;
     122                                        break;
     123                                case 'audio/ogg':
     124                                        shortcode.ogg = props.linkUrl;
     125                                        break;
     126                                case 'audio/x-ms-wma':
     127                                case 'audio/wma':
     128                                        shortcode.wma = props.linkUrl;
     129                                        break;
     130                                }
     131                        }
     132
     133                        html = wp.shortcode.string({
     134                                tag:     'audio',
     135                                attrs:   shortcode
     136                        });
     137
     138                        return html;
     139                },
     140
     141                video: function( props, attachment ) {
     142                        var shortcode, html;
     143
     144                        props = wp.media.string.props( props, attachment );
     145
     146                        shortcode = {};
     147
     148                        if ( props.mime ) {
     149                                switch ( props.mime ) {
     150                                case 'video/mp4':
     151                                        shortcode.mp4 = props.linkUrl;
     152                                        break;
     153                                case 'video/m4v':
     154                                        shortcode.m4v = props.linkUrl;
     155                                        break;
     156                                case 'video/webm':
     157                                        shortcode.webm = props.linkUrl;
     158                                        break;
     159                                case 'video/ogg':
     160                                        shortcode.ogv = props.linkUrl;
     161                                        break;
     162                                case 'video/x-ms-wmv':
     163                                case 'video/wmv':
     164                                case 'video/asf':
     165                                        shortcode.wmv = props.linkUrl;
     166                                        break;
     167                                case 'video/flv':
     168                                case 'video/x-flv':
     169                                        shortcode.flv = props.linkUrl;
     170                                        break;
     171                                }
     172                        }
     173
     174                        html = wp.shortcode.string({
     175                                tag:     'video',
     176                                attrs:   shortcode
     177                        });
     178
     179                        return html;
     180                },
     181
    98182                image: function( props, attachment ) {
    99183                        var img = {},
    100184                                options, classes, shortcode, html;
     
    575659                                                if ( props[ prop ] )
    576660                                                        options[ option ] = props[ prop ];
    577661                                        });
    578 
     662                                } else if ( 'video' === attachment.type ) {
     663                                        html = wp.media.string.video( props );
     664                                } else if ( 'audio' === attachment.type ) {
     665                                        html = wp.media.string.audio( props );
    579666                                } else {
    580667                                        html = wp.media.string.link( props );
    581668                                        options.post_title = props.title;
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index c543389..5b65f3d 100644
    function gallery_shortcode($attr) { 
    803803}
    804804
    805805/**
     806 * Provide a No-JS Flash fallback as a last resort for audio / video
     807 *
     808 * @since 3.6.0
     809 *
     810 * @param string $url
     811 * @return string Fallback HTML
     812 */
     813function wp_mediaelement_fallback( $url ) {
     814        return apply_filters( 'wp_mediaelement_fallback', sprintf( '<a href="%1$s">%1$s</a>', esc_url( $url ) ), $url );
     815}
     816
     817/**
     818 * Return a filtered list of WP-supported audio formats
     819 *
     820 * @since 3.6.0
     821 * @return array
     822 */
     823function wp_get_audio_extensions() {
     824        return apply_filters( 'wp_audio_extensions', array( 'mp3', 'ogg', 'wma', 'm4a', 'wav' ) );
     825}
     826
     827/**
     828 * The Audio shortcode.
     829 *
     830 * This implements the functionality of the Audio Shortcode for displaying
     831 * WordPress mp3s in a post.
     832 *
     833 * @since 3.6.0
     834 *
     835 * @param array $attr Attributes of the shortcode.
     836 * @return string HTML content to display audio.
     837 */
     838function wp_audio_shortcode( $attr ) {
     839        $post_id = get_post() ? get_the_ID() : 0;
     840
     841        static $instances = 0;
     842        $instances++;
     843
     844        $audio = null;
     845
     846        $default_types = wp_get_audio_extensions();
     847        $defaults_atts = array( 'src' => '' );
     848        foreach ( $default_types as $type  )
     849                $defaults_atts[$type] = '';
     850
     851        $atts = shortcode_atts( $defaults_atts, $attr );
     852        extract( $atts );
     853
     854        $primary = false;
     855        if ( ! empty( $src ) ) {
     856                $type = wp_check_filetype( $src );
     857                if ( ! in_array( $type['ext'], $default_types ) ) {
     858                        printf( '<a class="wp-post-format-link-audio" href="%1$s">%1$s</a>', $src );
     859                        return;
     860                }
     861                $primary = true;
     862                array_unshift( $default_types, 'src' );
     863        } else {
     864                foreach ( $default_types as $ext ) {
     865                        if ( ! empty( $$ext ) ) {
     866                                $type = wp_check_filetype( $$ext );
     867                                if ( $type['ext'] === $ext )
     868                                        $primary = true;
     869                        }
     870                }
     871        }
     872
     873        if ( ! $primary ) {
     874                $audios = get_post_audio( $post_id );
     875                if ( empty( $audios ) )
     876                        return;
     877
     878                $audio = reset( $audios );
     879                $src = wp_get_attachment_url( $audio->ID );
     880                if ( empty( $src ) )
     881                        return;
     882
     883                array_unshift( $default_types, 'src' );
     884        }
     885
     886        $library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' );
     887        if ( 'mediaelement' === $library ) {
     888                wp_enqueue_style( 'wp-mediaelement' );
     889                wp_enqueue_script( 'wp-mediaelement' );
     890        }
     891
     892        $atts = array(
     893                sprintf( 'class="%s"', apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ) ),
     894                sprintf( 'id="audio-%d-%d"', $post_id, $instances ),
     895        );
     896
     897        $html = sprintf( '<audio %s controls="controls" preload="none">', join( ' ', $atts ) );
     898
     899        $fileurl = '';
     900        $source = '<source type="%s" src="%s" />';
     901        foreach ( $default_types as $fallback ) {
     902                if ( ! empty( $$fallback ) ) {
     903                        if ( empty( $fileurl ) )
     904                                $fileurl = $$fallback;
     905                        $type = wp_check_filetype( $$fallback );
     906                        $html .= sprintf( $source, $type['type'], $$fallback );
     907                }
     908        }
     909
     910        if ( 'mediaelement' === $library )
     911                $html .= wp_mediaelement_fallback( $fileurl );
     912        $html .= '</audio>';
     913
     914        return apply_filters( 'wp_audio_shortcode', $html, $atts, $audio, $post_id );
     915}
     916add_shortcode( 'audio', apply_filters( 'wp_audio_shortcode_handler', 'wp_audio_shortcode' ) );
     917
     918/**
     919 * Return a filtered list of WP-supported video formats
     920 *
     921 * @since 3.6.0
     922 * @return array
     923 */
     924function wp_get_video_extensions() {
     925        return apply_filters( 'wp_video_extensions', array( 'mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv' ) );
     926}
     927
     928/**
     929 * The Video shortcode.
     930 *
     931 * This implements the functionality of the Video Shortcode for displaying
     932 * WordPress mp4s in a post.
     933 *
     934 * @since 3.6.0
     935 *
     936 * @param array $attr Attributes of the shortcode.
     937 * @return string HTML content to display video.
     938 */
     939function wp_video_shortcode( $attr ) {
     940        global $content_width;
     941        $post_id = get_post() ? get_the_ID() : 0;
     942
     943        static $instances = 0;
     944        $instances++;
     945
     946        $video = null;
     947
     948        $default_types = wp_get_video_extensions();
     949        $defaults_atts = array(
     950                'src' => '',
     951                'poster' => '',
     952                'height' => 360,
     953                'width' => empty( $content_width ) ? 640 : $content_width,
     954        );
     955        foreach ( $default_types as $type  )
     956                $defaults_atts[$type] = '';
     957
     958        $atts = shortcode_atts( $defaults_atts, $attr );
     959        extract( $atts );
     960
     961        $primary = false;
     962        if ( ! empty( $src ) ) {
     963                $type = wp_check_filetype( $src );
     964                if ( ! in_array( $type['ext'], $default_types ) ) {
     965                        printf( '<a class="wp-post-format-link-video" href="%1$s">%1$s</a>', $src );
     966                        return;
     967                }
     968                $primary = true;
     969                array_unshift( $default_types, 'src' );
     970        } else {
     971                foreach ( $default_types as $ext ) {
     972                        if ( ! empty( $$ext ) ) {
     973                                $type = wp_check_filetype( $$ext );
     974                                if ( $type['ext'] === $ext )
     975                                        $primary = true;
     976                        }
     977                }
     978        }
     979
     980        if ( ! $primary ) {
     981                $videos = get_post_video( $post_id );
     982                if ( empty( $videos ) )
     983                        return;
     984
     985                $video = reset( $videos );
     986                $src = wp_get_attachment_url( $video->ID );
     987                if ( empty( $src ) )
     988                        return;
     989
     990                array_unshift( $default_types, 'src' );
     991        }
     992
     993        $library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' );
     994        if ( 'mediaelement' === $library ) {
     995                wp_enqueue_style( 'wp-mediaelement' );
     996                wp_enqueue_script( 'wp-mediaelement' );
     997        }
     998
     999        $atts = array(
     1000                sprintf( 'class="%s"', apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ) ),
     1001                sprintf( 'id="video-%d-%d"', $post_id, $instances ),
     1002                sprintf( 'width="%d"', $width ),
     1003                sprintf( 'height="%d"', $height ),
     1004        );
     1005
     1006        if ( ! empty( $poster ) )
     1007                $atts[] = sprintf( 'poster="%s"', esc_url( $poster ) );
     1008
     1009        $html = sprintf( '<video %s controls="controls" preload="none">', join( ' ', $atts ) );
     1010
     1011        $fileurl = '';
     1012        $source = '<source type="%s" src="%s" />';
     1013        foreach ( $default_types as $fallback ) {
     1014                if ( ! empty( $$fallback ) ) {
     1015                        if ( empty( $fileurl ) )
     1016                                $fileurl = $$fallback;
     1017                        $type = wp_check_filetype( $$fallback );
     1018                        // m4v sometimes shows up as video/mpeg which collides with mp4
     1019                        if ( 'm4v' === $type['ext'] )
     1020                                $type['type'] = 'video/m4v';
     1021                        $html .= sprintf( $source, $type['type'], $$fallback );
     1022                }
     1023        }
     1024        if ( 'mediaelement' === $library )
     1025                $html .= wp_mediaelement_fallback( $fileurl, $width, $height );
     1026        $html .= '</video>';
     1027
     1028        return apply_filters( 'wp_video_shortcode', $html, $atts, $video, $post_id );
     1029}
     1030add_shortcode( 'video', apply_filters( 'wp_video_shortcode_handler', 'wp_video_shortcode' ) );
     1031
     1032/**
    8061033 * Display previous image link that has the same post parent.
    8071034 *
    8081035 * @since 2.5.0
    function wp_enqueue_media( $args = array() ) { 
    15421769
    15431770        do_action( 'wp_enqueue_media' );
    15441771}
     1772
     1773/**
     1774 * Retrieve audio attached to the passed post
     1775 *
     1776 * @since 3.6.0
     1777 *
     1778 * @param int $post_id  Post ID
     1779 * @return array Found audio attachments
     1780 */
     1781function get_post_audio( $post_id = 0 ) {
     1782        $post = empty( $post_id ) ? get_post() : get_post( $post_id );
     1783        if ( empty( $post ) )
     1784                return;
     1785
     1786        $children = get_children( array(
     1787                'post_parent' => $post->ID,
     1788                'post_type' => 'attachment',
     1789                'post_mime_type' => 'audio',
     1790                'posts_per_page' => -1
     1791        ) );
     1792
     1793        if ( ! empty( $children ) )
     1794                return $children;
     1795}
     1796
     1797/**
     1798 * Retrieve video attached to the passed post
     1799 *
     1800 * @since 3.6.0
     1801 *
     1802 * @param int $post_id  Post ID
     1803 * @return array Found video attachments
     1804 */
     1805function get_post_video( $post_id = 0 ) {
     1806        $post = empty( $post_id ) ? get_post() : get_post( $post_id );
     1807        if ( empty( $post ) )
     1808                return;
     1809
     1810        $children = get_children( array(
     1811                'post_parent' => $post->ID,
     1812                'post_type' => 'attachment',
     1813                'post_mime_type' => 'video',
     1814                'posts_per_page' => -1
     1815        ) );
     1816
     1817        if ( ! empty( $children ) )
     1818                return $children;
     1819}
     1820
     1821/**
     1822 * Audio embed handler callback.
     1823 *
     1824 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
     1825 * @param array $attr Embed attributes.
     1826 * @param string $url The original URL that was matched by the regex.
     1827 * @param array $rawattr The original unmodified attributes.
     1828 * @return string The embed HTML.
     1829 */
     1830function wp_audio_embed( $matches, $attr, $url, $rawattr ) {
     1831        $audio = $url;
     1832        if ( shortcode_exists( 'audio' ) )
     1833                $audio = do_shortcode( '[audio src="' . $url . '" /]' );
     1834        return apply_filters( 'wp_audio_embed', $audio, $attr, $url, $rawattr );
     1835}
     1836wp_embed_register_handler( 'wp_audio_embed', '#https?://.+?\.(' . join( '|', wp_get_audio_extensions() ) . ')#i', apply_filters( 'wp_audio_embed_handler', 'wp_audio_embed' ), 9999 );
     1837
     1838/**
     1839 * Video embed handler callback.
     1840 *
     1841 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
     1842 * @param array $attr Embed attributes.
     1843 * @param string $url The original URL that was matched by the regex.
     1844 * @param array $rawattr The original unmodified attributes.
     1845 * @return string The embed HTML.
     1846 */
     1847function wp_video_embed( $matches, $attr, $url, $rawattr ) {
     1848        $dimensions = '';
     1849        $video = $url;
     1850        if ( shortcode_exists( 'video' ) ) {
     1851                if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) {
     1852                        $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] );
     1853                        $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] );
     1854                }
     1855                $video = do_shortcode( '[video ' . $dimensions . 'src="' . $url . '" /]' );
     1856        }
     1857        return apply_filters( 'wp_video_embed', $video, $attr, $url, $rawattr );
     1858}
     1859wp_embed_register_handler( 'wp_video_embed', '#https?://.+?\.(' . join( '|', wp_get_video_extensions() ) . ')#i', apply_filters( 'wp_video_embed_handler', 'wp_video_embed' ), 9999 );
  • wp-includes/post-formats.php

    diff --git wp-includes/post-formats.php wp-includes/post-formats.php
    index 828447b..7dfc171 100644
    function post_formats_compat( $content, $id = 0 ) { 
    308308        $show_content = true;
    309309        $format_output = '';
    310310        $meta = get_post_format_meta( $post->ID );
     311        // passed by ref in preg_match()
     312        $matches = array();
    311313
    312314        switch ( $format ) {
    313315                case 'link':
    function post_formats_compat( $content, $id = 0 ) { 
    365367                        break;
    366368
    367369                case 'gallery':
    368                         preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches );
    369                         if ( ! empty( $matches ) && isset( $matches[2] ) ) {
    370                                 foreach ( (array) $matches[2] as $match ) {
    371                                         if ( 'gallery' === $match )
    372                                                 break 2; // foreach + case
    373                                 }
    374                         }
    375 
    376                         if ( ! empty( $meta['gallery'] ) ) {
     370                        if ( ! has_shortcode( $post->post_content, $format ) && ! empty( $meta['gallery'] ) )
    377371                                $format_output .= $meta['gallery'];
    378                         }
    379372                        break;
    380373
    381374                case 'video':
    382375                case 'audio':
    383                         $shortcode_regex = '/' . get_shortcode_regex() . '/s';
    384                         $matches = preg_match( $shortcode_regex, $content );
    385                         if ( ! $matches || $format !== $matches[2] ) {
    386                                 if ( ! empty( $meta['media'] ) ) {
    387                                         // the metadata is a shortcode or an embed code
    388                                         if ( preg_match( $shortcode_regex, $meta['media'] ) || preg_match( '#<[^>]+>#', $meta['media'] ) ) {
    389                                                 $format_output .= $meta['media'];
    390                                         } elseif ( ! stristr( $content, $meta['media'] ) ) {
    391                                                 // attempt to embed the URL
    392                                                 $format_output .= sprintf( '[embed]%s[/embed]', $meta['media'] );
    393                                         }
     376                        if ( ! has_shortcode( $post->post_content, $format ) && ! empty( $meta['media'] ) ) {
     377                                // the metadata is a shortcode or an embed code
     378                                if ( preg_match( '/' . get_shortcode_regex() . '/s', $meta['media'] ) || preg_match( '#<[^>]+>#', $meta['media'] ) ) {
     379                                        $format_output .= $meta['media'];
     380                                } elseif ( ! stristr( $content, $meta['media'] ) ) {
     381                                        // attempt to embed the URL
     382                                        $format_output .= sprintf( '[embed]%s[/embed]', $meta['media'] );
    394383                                }
    395                         }
     384                        }
    396385                        break;
    397386                default:
    398387                        return $content;
  • wp-includes/script-loader.php

    diff --git wp-includes/script-loader.php wp-includes/script-loader.php
    index 84b76d3..bf3e4fb 100644
    function wp_default_scripts( &$scripts ) { 
    277277
    278278        $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), '0.9.8', 1 );
    279279
     280        $scripts->add( 'mediaelement', "/wp-includes/js/mediaelement/mediaelement-and-player$suffix.js", array('jquery'), '2.10.1', 1 );
     281        $scripts->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement.js", array('mediaelement'), false, 1 );
     282
    280283        $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), false, 1 );
    281284        did_action( 'init' ) && $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
    282285                'empty' => __('Strength indicator'),
    function wp_default_styles( &$styles ) { 
    543546        $styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons' ) );
    544547        $styles->add( 'buttons', "/wp-includes/css/buttons$suffix.css" );
    545548
     549        $styles->add( 'mediaelement', "/wp-includes/js/mediaelement/mediaelementplayer$suffix.css" );
     550        $styles->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement.css", array( 'mediaelement' ) );
     551
    546552        foreach ( $rtl_styles as $rtl_style ) {
    547553                $styles->add_data( $rtl_style, 'rtl', true );
    548554                if ( $suffix && ! in_array( $rtl_style, $no_suffix ) )
  • wp-includes/shortcodes.php

    diff --git wp-includes/shortcodes.php wp-includes/shortcodes.php
    index bdc3f9b..b7a0b1b 100644
    function remove_all_shortcodes() { 
    128128}
    129129
    130130/**
     131 * Whether a registered shortcode exists named $tag
     132 *
     133 * @since 3.6.0
     134 *
     135 * @global array $shortcode_tags
     136 * @param string $tag
     137 * @return boolean
     138 */
     139function shortcode_exists( $tag ) {
     140        global $shortcode_tags;
     141        return array_key_exists( $tag, $shortcode_tags );
     142}
     143
     144/**
     145 * Whether the passed content contains the specified shortcode
     146 *
     147 * @since 3.6.0
     148 *
     149 * @global array $shortcode_tags
     150 * @param string $tag
     151 * @return boolean
     152 */
     153function has_shortcode( $content, $tag ) {
     154        if ( shortcode_exists( $tag ) ) {
     155                $matches = array();
     156                preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
     157                if ( empty( $matches ) )
     158                        return false;
     159
     160                foreach ( $matches as $shortcode ) {
     161                        if ( $tag === $shortcode[2] )
     162                                return true;
     163                }
     164        }
     165        return false;
     166}
     167
     168/**
    131169 * Search content for shortcodes and filter shortcodes through their hooks.
    132170 *
    133171 * If there are no shortcode tags defined, then the content will be returned