Make WordPress Core

Ticket #23282: 23282.7.diff

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