Make WordPress Core

Ticket #23282: 23282.6.diff

File 23282.6.diff, 17.6 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 bd4d5b9..b0f2c0c 100644
    function wp_ajax_send_attachment_to_editor() { 
    20302030                $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
    20312031                $title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
    20322032                $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt );
     2033        } elseif ( 'video' === substr( $post->post_mime_type, 0, 5 ) || 'audio' === substr( $post->post_mime_type, 0, 5 )  ) {
     2034                $html = stripslashes_deep( $_POST['html'] );
    20332035        }
    20342036
    20352037        $html = apply_filters( 'media_send_to_editor', $html, $id, $attachment );
    function wp_ajax_heartbeat() { 
    20862088                $screen_id = sanitize_key($_POST['screenid']);
    20872089        else
    20882090                $screen_id = 'site';
    2089        
     2091
    20902092        if ( ! empty($_POST['data']) ) {
    20912093                $data = wp_unslash( (array) $_POST['data'] );
    20922094                // todo: how much to sanitize and preset and what to leave to be accessed from $data or $_POST..?
  • wp-includes/functions.php

    diff --git wp-includes/functions.php wp-includes/functions.php
    index cbd7925..5ac68c7 100644
    function wp_is_stream( $path ) { 
    38833883 */
    38843884function wp_checkdate( $month, $day, $year, $source_date ) {
    38853885        return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
     3886}
     3887
     3888/**
     3889 * Return RegEx body to liberally match an opening HTML tag that:
     3890 * 1. Is self-closing or
     3891 * 2. Has no body but has a closing tag of the same name or
     3892 * 3. Contains a body and a closing tag of the same name
     3893 *
     3894 * Note: this RegEx does not balance inner tags and does not attempt to produce valid HTML
     3895 *
     3896 * @since 3.6.0
     3897 *
     3898 * @param string $tag An HTML tag name. Example: 'video'
     3899 * @return string
     3900 */
     3901function get_tag_regex( $tag ) {
     3902        if ( empty( $tag ) )
     3903                return;
     3904
     3905        return sprintf( '(<%1$s[^>]*(?:/?>$|>[\s\S]*?</%1$s>))', tag_escape( $tag ) );
    38863906}
     3907 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..1b5f844 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.mp3 = 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.mp4 = 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/asf':
     147                                        shortcode.wmv = props.linkUrl;
     148                                        break;
     149                                case 'video/x-flv':
     150                                        shortcode.flv = props.linkUrl;
     151                                        break;
     152                                }
     153                        }
     154
     155                        html = wp.shortcode.string({
     156                                tag:     'video',
     157                                attrs:   shortcode
     158                        });
     159
     160                        return html;
     161                },
     162
    98163                image: function( props, attachment ) {
    99164                        var img = {},
    100165                                options, classes, shortcode, html;
     
    575640                                                if ( props[ prop ] )
    576641                                                        options[ option ] = props[ prop ];
    577642                                        });
    578 
     643                                } else if ( 'video' === attachment.type ) {
     644                                        html = wp.media.string.video( props );
     645                                } else if ( 'audio' === attachment.type ) {
     646                                        html = wp.media.string.audio( props );
    579647                                } else {
    580648                                        html = wp.media.string.link( props );
    581649                                        options.post_title = props.title;
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index f1f3737..07b3fc1 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        $defaults = array(
     825                'mp3' => '',
     826                'ogg' => '',
     827                'wma' => ''
     828        );
     829        extract( shortcode_atts( $defaults, $attr ) );
     830
     831        $primary = false;
     832        foreach ( array_keys( $defaults ) as $ext ) {
     833                if ( ! empty( $$ext ) ) {
     834                        $type = wp_check_filetype( $$ext );
     835                        if ( $type['ext'] === $ext )
     836                                $primary = true;
     837                }
     838        }
     839
     840        if ( ! $primary ) {
     841                $audios = get_post_audio( $post->ID );
     842                if ( empty( $audios ) )
     843                        return;
     844
     845                $audio = reset( $audios );
     846                $src = wp_get_attachment_url( $audio->ID );
     847                if ( empty( $src ) )
     848                        return;
     849
     850                $type = wp_check_filetype( $src );
     851                if ( ! in_array( $type['ext'], array_keys( $defaults ) ) ) {
     852                        printf( '<a href="%1$s">%1$s</a>', $src );
     853                        return;
     854                }
     855                $defaults['src'] = '';
     856        }
     857
     858        wp_enqueue_style( 'wp-mediaelement' );
     859        wp_enqueue_script( 'wp-mediaelement' );
     860
     861        $atts = array(
     862                sprintf( 'class="%s"', apply_filters( 'audio_shortcode_class', 'wp-audio-shortcode' ) ),
     863                sprintf( 'id="audio-%d-%d"', $post->ID, $instances ),
     864        );
     865
     866        $html = sprintf( '<audio %s controls="controls" preload="none">', join( ' ', $atts ) );
     867
     868        $source = '<source type="%s" src="%s" />';
     869        foreach ( array_keys( $defaults ) as $fallback ) {
     870                if ( ! empty( $$fallback ) ) {
     871                        $type = wp_check_filetype( $$fallback );
     872                        $html .= sprintf( $source, $type['type'], $$fallback );
     873                }
     874        }
     875
     876        $html .= '</audio>';
     877
     878        return apply_filters( 'audio_shortcode', $html, $src, $audio, $post );
     879}
     880add_shortcode( 'audio', 'wp_audio_shortcode' );
     881
     882/**
     883 * The Video shortcode.
     884 *
     885 * This implements the functionality of the Video Shortcode for displaying
     886 * WordPress mp4s in a post.
     887 *
     888 * @since 3.6.0
     889 *
     890 * @param array $attr Attributes of the shortcode.
     891 * @return string HTML content to display video.
     892 */
     893function wp_video_shortcode( $attr ) {
     894        global $content_width;
     895        $post = get_post();
     896
     897        static $instances = 0;
     898        $instances++;
     899
     900        $video = null;
     901
     902        $default_types = array( 'mp4', 'webm', 'ogv', 'wmv', 'flv' );
     903
     904        extract( shortcode_atts( array(
     905                'width' => empty( $content_width ) ? 640 : $content_width,
     906                'height' => 360,
     907                'poster' => '',
     908        ), $attr ) );
     909
     910        $primary = false;
     911        foreach ( $default_types as $ext ) {
     912                if ( ! empty( $$ext ) ) {
     913                        $type = wp_check_filetype( $$ext );
     914                        if ( $type['ext'] === $ext )
     915                                $primary = true;
     916                }
     917        }
     918
     919        if ( ! $primary ) {
     920                $videos = get_post_video( $post->ID );
     921                if ( empty( $videos ) )
     922                        return;
     923
     924                $video = reset( $videos );
     925                $src = wp_get_attachment_url( $video->ID );
     926                if ( empty( $src ) )
     927                        return;
     928
     929                $type = wp_check_filetype( $src );
     930                if ( ! in_array( $type['ext'], $default_types ) ) {
     931                        printf( '<a href="%1$s">%1$s</a>', $src );
     932                        return;
     933                }
     934
     935                array_unshift( $default_types, 'src' );
     936        }
     937
     938        wp_enqueue_style( 'wp-mediaelement' );
     939        wp_enqueue_script( 'wp-mediaelement' );
     940
     941        $atts = array(
     942                sprintf( 'class="%s"', apply_filters( 'video_shortcode_class', 'wp-video-shortcode' ) ),
     943                sprintf( 'id="video-%d-%d"', $post->ID, $instances ),
     944                sprintf( 'width="%d"', $width ),
     945                sprintf( 'height="%d"', $height ),
     946        );
     947
     948        if ( ! empty( $poster ) )
     949                $atts[] = sprintf( 'poster="%s"', esc_url( $poster ) );
     950
     951        $html = sprintf( '<video %s controls="controls" preload="none">', join( ' ', $atts ) );
     952
     953        $source = '<source type="%s" src="%s" />';
     954        foreach ( $default_types as $fallback ) {
     955                if ( ! empty( $$fallback ) ) {
     956                        $type = wp_check_filetype( $$fallback );
     957                        $html .= sprintf( $source, $type['type'], $$fallback );
     958                }
     959        }
     960
     961        $html .= '</video>';
     962
     963        return apply_filters( 'video_shortcode', $html, $src, $video, $post );
     964}
     965add_shortcode( 'video', 'wp_video_shortcode' );
     966
     967/**
    806968 * Display previous image link that has the same post parent.
    807969 *
    808970 * @since 2.5.0
    function wp_enqueue_media( $args = array() ) { 
    15421704
    15431705        do_action( 'wp_enqueue_media' );
    15441706}
     1707
     1708/**
     1709 * Retrieve audio attached to the passed post
     1710 *
     1711 * @since 3.6.0
     1712 *
     1713 * @param int $post_id  Post ID
     1714 * @return array Found audio attachments
     1715 */
     1716function get_post_audio( $post_id = 0 ) {
     1717        $post = empty( $post_id ) ? get_post() : get_post( $post_id );
     1718        if ( empty( $post ) )
     1719                return;
     1720
     1721        $children = get_children( array(
     1722                'post_parent' => $post->ID,
     1723                'post_type' => 'attachment',
     1724                'post_mime_type' => 'audio',
     1725                'posts_per_page' => -1
     1726        ) );
     1727
     1728        if ( ! empty( $children ) )
     1729                return $children;
     1730}
     1731
     1732/**
     1733 * Check the content blob for an <audio>, <object>, <embed>, or <iframe>, in that order
     1734 * If no HTML tag is found, check the first line of the post for a URL
     1735 *
     1736 * @param string $content A string which might contain audio data.
     1737 * @param boolean $remove Whether to remove the found URL from the passed content.
     1738 * @return string The found data
     1739 */
     1740function get_content_audio( &$content, $remove = false ) {
     1741        $html = $matches = '';
     1742        foreach ( array( 'audio', 'object', 'embed', 'iframe' ) as $tag ) {
     1743                if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
     1744                        $html = $matches[1];
     1745                        if ( $remove )
     1746                                $content = str_replace( $matches[0], '', $content );
     1747
     1748                        return $html;
     1749                }
     1750        }
     1751
     1752        $lines = explode( "\n", trim( $content ) );
     1753        $line = trim( array_shift( $lines  ) );
     1754
     1755        if ( 0 === stripos( $line, 'http' ) ) {
     1756                if ( $remove )
     1757                        $content = join( "\n", $lines );
     1758
     1759                return $line;
     1760        }
     1761}
     1762
     1763/**
     1764 * Return the found audio data for the passed post
     1765 *
     1766 * @since 3.6.0
     1767 *
     1768 * @param int $id Optional. Post ID
     1769 */
     1770function get_the_audio( $id = 0 ) {
     1771        $post = empty( $id ) ? get_post() : get_post( $id );
     1772        if ( empty( $post ) )
     1773                return;
     1774
     1775        if ( shortcode_exists( 'audio' ) )
     1776                return do_shortcode( '[audio /]' );
     1777
     1778        $data = get_content_audio( $post->post_content );
     1779        if ( ! empty( $data ) )
     1780                return $data;
     1781
     1782        $audios = get_post_audio( $post->ID );
     1783        if ( empty( $audios ) )
     1784                return;
     1785
     1786        $audio = reset( $audios );
     1787        return wp_get_attachment_url( $audio->ID );
     1788}
     1789
     1790/**
     1791 * Output the found audio data for the current post
     1792 *
     1793 * @since 3.6.0
     1794 */
     1795function the_audio() {
     1796        echo apply_filters( 'the_audio', get_the_audio() );
     1797}
     1798
     1799/**
     1800 * Retrieve video attached to the passed post
     1801 *
     1802 * @since 3.6.0
     1803 *
     1804 * @param int $post_id  Post ID
     1805 * @return array Found video attachments
     1806 */
     1807function get_post_video( $post_id = 0 ) {
     1808        $post = empty( $post_id ) ? get_post() : get_post( $post_id );
     1809        if ( empty( $post ) )
     1810                return;
     1811
     1812        $children = get_children( array(
     1813                'post_parent' => $post->ID,
     1814                'post_type' => 'attachment',
     1815                'post_mime_type' => 'video',
     1816                'posts_per_page' => -1
     1817        ) );
     1818
     1819        if ( ! empty( $children ) )
     1820                return $children;
     1821}
     1822
     1823/**
     1824 * Check the content blob for a <video>, <object>, <embed>, or <iframe>, in that order
     1825 * If no HTML tag is found, check the first line of the post for a URL
     1826 *
     1827 * @param string $content A string which might contain video data.
     1828 * @param boolean $remove Whether to remove the found URL from the passed content.
     1829 * @return string The found data
     1830 */
     1831function get_content_video( &$content, $remove = false ) {
     1832        $html = $matches = '';
     1833        foreach ( array( 'video', 'object', 'embed', 'iframe' ) as $tag ) {
     1834                if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
     1835                        $html = $matches[1];
     1836                        if ( $remove )
     1837                                $content = str_replace( $matches[0], '', $content );
     1838
     1839                        return $html;
     1840                }
     1841        }
     1842
     1843        $lines = explode( "\n", trim( $content ) );
     1844        $line = trim( array_shift( $lines  ) );
     1845
     1846        if ( 0 === stripos( $line, 'http' ) ) {
     1847                if ( $remove )
     1848                        $content = join( "\n", $lines );
     1849
     1850                return $line;
     1851        }
     1852}
     1853
     1854/**
     1855 * Return the found video data for the passed post
     1856 *
     1857 * @since 3.6.0
     1858 *
     1859 * @param int $id Optional. Post ID
     1860 */
     1861function get_the_video( $id = 0 ) {
     1862        $post = empty( $id ) ? get_post() : get_post( $id );
     1863        if ( empty( $post ) )
     1864                return;
     1865
     1866        if ( shortcode_exists( 'video' ) )
     1867                return do_shortcode( '[video /]' );
     1868
     1869        $data = get_content_video( $post->post_content );
     1870        if ( ! empty( $data ) )
     1871                return $data;
     1872
     1873        $videos = get_post_video( $post->ID );
     1874        if ( empty( $videos ) )
     1875                return;
     1876
     1877        $video = reset( $videos );
     1878        return wp_get_attachment_url( $video->ID );
     1879}
     1880
     1881/**
     1882 * Output the found video data for the current post
     1883 *
     1884 * @since 3.6.0
     1885 */
     1886function the_video() {
     1887        echo apply_filters( 'the_video', get_the_video() );
     1888}
     1889 No newline at end of file
  • wp-includes/post-formats.php

    diff --git wp-includes/post-formats.php wp-includes/post-formats.php
    index 6d32aea..fa1f38b 100644
    function post_formats_compat( $content, $id = 0 ) { 
    386386                case 'video':
    387387                case 'audio':
    388388                        $shortcode_regex = '/' . get_shortcode_regex() . '/s';
    389                         $matches = preg_match( $shortcode_regex, $content );
     389                        preg_match( $shortcode_regex, $content, $matches );
     390
    390391                        if ( ! $matches || $format !== $matches[2] ) {
    391392                                if ( empty( $meta['media'] ) && ! empty( $compat[$format] ) ) {
    392393                                        $format_output .= $compat[$format];
    function post_formats_compat( $content, $id = 0 ) { 
    398399                                                // attempt to embed the URL
    399400                                                $format_output .= sprintf( '[embed]%s[/embed]', $meta['media'] );
    400401                                        }
     402                                } elseif ( empty( $meta['media'] ) ) {
     403                                        $data = '';
     404                                        // attempt to grab an embed code or URL from the content
     405                                        if ( 'audio' === $format ) {
     406                                                $data = get_content_audio( $content, true );
     407                                        } elseif ( 'video' === $format ) {
     408                                                $data = get_content_video( $content, true );
     409                                        }
     410
     411                                        if ( ! empty( $data ) ) {
     412                                                // attempt to embed the URL
     413                                                if ( 0 === stripos( $data, 'http' ) )
     414                                                        $format_output .= sprintf( '[embed]%s[/embed]', $data );
     415                                                else // data is probably an embed code
     416                                                        $format_output .= $data;
     417                                        } elseif ( 'audio' === $format ) {
     418                                                // get attached audio URL
     419                                                $audios = get_post_audio( $post->ID );
     420                                                if ( ! empty( $audios ) ) {
     421                                                        $audio = reset( $audios );
     422                                                        $url = wp_get_attachment_url( $audio->ID );
     423                                                        // core or plugin support for [audio]
     424                                                        if ( shortcode_exists( 'audio' ) ) {
     425                                                                $format_output .= sprintf( '[audio src="%s"/]', $url );
     426                                                        } else {
     427                                                                // no support detected, just add URL
     428                                                                $format_output .= sprintf( '<a href="%1$s">%1$s</a>', $url );
     429                                                        }
     430                                                }
     431                                        } elseif ( 'video' === $format ) {
     432                                                // get attached video URL
     433                                                $videos = get_post_video( $post->ID );
     434                                                if ( ! empty( $videos ) ) {
     435                                                        $video = reset( $videos );
     436                                                        $url = wp_get_attachment_url( $video->ID );
     437                                                        // core or plugin support for [video]
     438                                                        if ( shortcode_exists( 'video' ) ) {
     439                                                                $format_output .= sprintf( '[video src="%s"/]', $url );
     440                                                        } else {
     441                                                                // no support detected, just add URL link
     442                                                                $format_output .= sprintf( '<a href="%1$s">%1$s</a>', $url );
     443                                                        }
     444                                                }
     445                                        }
    401446                                }
    402447                        }
    403448                        break;
  • wp-includes/script-loader.php

    diff --git wp-includes/script-loader.php wp-includes/script-loader.php
    index cfb865e..2e5e527 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 ) )
  • wp-includes/shortcodes.php

    diff --git wp-includes/shortcodes.php wp-includes/shortcodes.php
    index 2dfc277..716dae4 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/**
    131145 * Search content for shortcodes and filter shortcodes through their hooks.
    132146 *
    133147 * If there are no shortcode tags defined, then the content will be returned