Make WordPress Core

Ticket #23282: 23282.4.diff

File 23282.4.diff, 8.7 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 cd4ba08..60cf65e 100644
    function wp_ajax_send_attachment_to_editor() { 
    20252025                $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
    20262026                $title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
    20272027                $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt );
     2028        } elseif ( 'video' === substr( $post->post_mime_type, 0, 5 ) || 'audio' === substr( $post->post_mime_type, 0, 5 )  ) {
     2029                $html = stripslashes_deep( $_POST['html'] );
    20282030        }
    20292031
    20302032        $html = apply_filters( 'media_send_to_editor', $html, $id, $attachment );
    function wp_ajax_heartbeat() { 
    20812083                $screen_id = sanitize_key($_POST['screenid']);
    20822084        else
    20832085                $screen_id = 'site';
    2084        
     2086
    20852087        if ( ! empty($_POST['data']) ) {
    20862088                $data = (array) $_POST['data'];
    20872089                // todo: how much to sanitize and preset and what to leave to be accessed from $data or $_POST..?
  • wp-includes/js/media-editor.js

    diff --git wp-includes/js/media-editor.js wp-includes/js/media-editor.js
    index 15eff8d..456a968 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                                        shortcode.src = props.linkUrl;
     110                                        break;
     111                                case 'audio/ogg':
     112                                        shortcode.ogg = props.linkUrl;
     113                                        break;
     114                                case 'audio/wma':
     115                                        shortcode.wma = props.linkUrl;
     116                                        break;
     117                                }
     118                        }
     119
     120                        html = wp.shortcode.string({
     121                                tag:     'audio',
     122                                attrs:   shortcode
     123                        });
     124
     125                        return html;
     126                },
     127
     128                video: function( props, attachment ) {
     129                        var shortcode, html;
     130
     131                        props = wp.media.string.props( props, attachment );
     132
     133                        shortcode = {};
     134
     135                        if ( props.mime ) {
     136                                switch ( props.mime ) {
     137                                case 'video/mp4':
     138                                        shortcode.src = props.linkUrl;
     139                                        break;
     140                                case 'video/webm':
     141                                        shortcode.webm = props.linkUrl;
     142                                        break;
     143                                case 'video/ogg':
     144                                        shortcode.ogv = props.linkUrl;
     145                                        break;
     146                                case 'video/quicktime':
     147                                        shortcode.mov = props.linkUrl;
     148                                        break;
     149                                case 'video/asf':
     150                                        shortcode.wmv = props.linkUrl;
     151                                        break;
     152                                case 'video/x-flv':
     153                                        shortcode.flv = props.linkUrl;
     154                                        break;
     155                                }
     156                        }
     157
     158                        html = wp.shortcode.string({
     159                                tag:     'video',
     160                                attrs:   shortcode
     161                        });
     162
     163                        return html;
     164                },
     165
    98166                image: function( props, attachment ) {
    99167                        var img = {},
    100168                                options, classes, shortcode, html;
     
    575643                                                if ( props[ prop ] )
    576644                                                        options[ option ] = props[ prop ];
    577645                                        });
    578 
     646                                } else if ( 'video' === attachment.type ) {
     647                                        html = wp.media.string.video( props );
     648                                } else if ( 'audio' === attachment.type ) {
     649                                        html = wp.media.string.audio( props );
    579650                                } else {
    580651                                        html = wp.media.string.link( props );
    581652                                        options.post_title = props.title;
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index 682ffbb..371c9ca 100644
    function gallery_shortcode($attr) { 
    803803}
    804804
    805805/**
     806 * The Audio shortcode.
     807 *
     808 * This implements the functionality of the Audio Shortcode for displaying
     809 * WordPress mp3s in a post.
     810 *
     811 * @since 3.6.0
     812 *
     813 * @param array $attr Attributes of the shortcode.
     814 * @return string HTML content to display audio.
     815 */
     816function wp_audio_shortcode( $attr ) {
     817        $post = get_post();
     818
     819        static $instances = 0;
     820        $instances++;
     821
     822        $audio = null;
     823
     824        extract( shortcode_atts( array(
     825                'src' => '',
     826                'ogg' => '',
     827                'wma' => ''
     828        ), $attr ) );
     829
     830        if ( empty( $src ) ) {
     831                $children = get_children( array(
     832                        'post_parent' => $post->ID,
     833                        'post_type' => 'attachment',
     834                        'post_mime_type' => 'audio',
     835                        'posts_per_page' => 1
     836                ) );
     837
     838                if ( empty( $children ) )
     839                        return;
     840
     841                $audio = reset( $children );
     842                $src = wp_get_attachment_url( $audio->ID );
     843                if ( empty( $src ) )
     844                        return;
     845        }
     846
     847        wp_enqueue_style( 'wp-mediaelement' );
     848        wp_enqueue_script( 'wp-mediaelement' );
     849
     850        $atts = array(
     851                sprintf( 'class="%s"', apply_filters( 'audio_shortcode_class', 'wp-audio-shortcode' ) ),
     852                sprintf( 'id="audio-%d-%d"', $post->ID, $instances ),
     853        );
     854
     855        $source = '<source type="%s" src="%s" />';
     856
     857        $html = sprintf( '<audio %s controls="controls" preload="none">', join( ' ', $atts ) );
     858
     859        foreach ( array( 'src', 'ogg', 'wma' ) as $fallback ) {
     860                if ( ! empty( $$fallback ) ) {
     861                        $type = wp_check_filetype( $$fallback );
     862                        $html .= sprintf( $source, $type['type'], $$fallback );
     863                }
     864        }
     865
     866        $html .= '</audio>';
     867
     868        return apply_filters( 'audio_shortcode', $html, $src, $audio, $post );
     869}
     870add_shortcode( 'audio', 'wp_audio_shortcode' );
     871
     872/**
     873 * The Video shortcode.
     874 *
     875 * This implements the functionality of the Video Shortcode for displaying
     876 * WordPress mp4s in a post.
     877 *
     878 * @since 3.6.0
     879 *
     880 * @param array $attr Attributes of the shortcode.
     881 * @return string HTML content to display video.
     882 */
     883function wp_video_shortcode( $attr ) {
     884        global $content_width;
     885        $post = get_post();
     886
     887        static $instances = 0;
     888        $instances++;
     889
     890        $video = null;
     891
     892        extract( shortcode_atts( array(
     893                'src' => '',
     894                'width' => empty( $content_width ) ? 640 : $content_width,
     895                'height' => 360,
     896                'poster' => '',
     897                'webm' => '',
     898                'ogv' => '',
     899                'mov' => '',
     900                'wmv' => '',
     901                'flv' => '',
     902        ), $attr ) );
     903
     904        if ( empty( $src ) ) {
     905                $children = get_children( array(
     906                        'post_parent' => $post->ID,
     907                        'post_type' => 'attachment',
     908                        'post_mime_type' => 'video',
     909                        'posts_per_page' => 1
     910                ) );
     911
     912                if ( empty( $children ) )
     913                        return;
     914
     915                $video = reset( $children );
     916                $src = wp_get_attachment_url( $video->ID );
     917                if ( empty( $src ) )
     918                        return;
     919        }
     920
     921        wp_enqueue_style( 'wp-mediaelement' );
     922        wp_enqueue_script( 'wp-mediaelement' );
     923
     924        $atts = array(
     925                sprintf( 'class="%s"', apply_filters( 'video_shortcode_class', 'wp-video-shortcode' ) ),
     926                sprintf( 'id="video-%d-%d"', $post->ID, $instances ),
     927                sprintf( 'width="%d"', $width ),
     928                sprintf( 'height="%d"', $height ),
     929        );
     930
     931        if ( ! empty( $poster ) )
     932                $atts[] = sprintf( 'poster="%s"', esc_url( $poster ) );
     933
     934        $source = '<source type="%s" src="%s" />';
     935
     936        $html = sprintf( '<video %s controls="controls" preload="none">', join( ' ', $atts ) );
     937
     938        foreach ( array( 'src', 'webm', 'ogv', 'mov', 'wmv', 'flv' ) as $fallback ) {
     939                if ( ! empty( $$fallback ) ) {
     940                        $type = wp_check_filetype( $$fallback );
     941                        $html .= sprintf( $source, $type['type'], $$fallback );
     942                }
     943        }
     944
     945        $html .= '</video>';
     946
     947        return apply_filters( 'video_shortcode', $html, $src, $video, $post );
     948}
     949add_shortcode( 'video', 'wp_video_shortcode' );
     950
     951/**
    806952 * Display previous image link that has the same post parent.
    807953 *
    808954 * @since 2.5.0
  • wp-includes/script-loader.php

    diff --git wp-includes/script-loader.php wp-includes/script-loader.php
    index d5bc4db..db67152 100644
    function wp_default_scripts( &$scripts ) { 
    274274
    275275        $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), '0.9.8', 1 );
    276276
     277        $scripts->add( 'mediaelement', "/wp-includes/js/mediaelement/mediaelement-and-player$suffix.js", array('jquery'), '2.10.1', 1 );
     278        $scripts->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement.js", array('mediaelement'), false, 1 );
     279
    277280        $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), false, 1 );
    278281        did_action( 'init' ) && $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
    279282                'empty' => __('Strength indicator'),
    function wp_default_styles( &$styles ) { 
    538541        $styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons' ) );
    539542        $styles->add( 'buttons', "/wp-includes/css/buttons$suffix.css" );
    540543
     544        $styles->add( 'mediaelement', "/wp-includes/js/mediaelement/mediaelementplayer$suffix.css" );
     545        $styles->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement.css", array( 'mediaelement' ) );
     546
    541547        foreach ( $rtl_styles as $rtl_style ) {
    542548                $styles->add_data( $rtl_style, 'rtl', true );
    543549                if ( $suffix && ! in_array( $rtl_style, $no_suffix ) )