Make WordPress Core

Ticket #22960: 22960.5.diff

File 22960.5.diff, 8.4 KB (added by wonderboymusic, 12 years ago)
  • wp-includes/functions.php

    diff --git wp-includes/functions.php wp-includes/functions.php
    index b55bca1..836ff7f 100644
    function get_tag_regex( $tag ) { 
    40394039                return;
    40404040
    40414041        return sprintf( '(<%1$s[^>]*(?:/?>$|>[\s\S]*?</%1$s>))', tag_escape( $tag ) );
    4042 }
    4043  No newline at end of file
     4042}
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index cdcdd23..75e9e1b 100644
    function wp_audio_shortcode( $attr ) { 
    874874        }
    875875
    876876        if ( ! $primary ) {
    877                 $audios = get_post_audio( $post_id );
     877                $audios = get_attached_audio( $post_id );
    878878                if ( empty( $audios ) )
    879879                        return;
    880880
    function wp_video_shortcode( $attr ) { 
    981981        }
    982982
    983983        if ( ! $primary ) {
    984                 $videos = get_post_video( $post_id );
     984                $videos = get_attached_video( $post_id );
    985985                if ( empty( $videos ) )
    986986                        return;
    987987
    function wp_enqueue_media( $args = array() ) { 
    17811781 * @param int $post_id  Post ID
    17821782 * @return array Found audio attachments
    17831783 */
    1784 function get_post_audio( $post_id = 0 ) {
     1784function get_attached_audio( $post_id = 0 ) {
    17851785        $post = empty( $post_id ) ? get_post() : get_post( $post_id );
    17861786        if ( empty( $post ) )
    17871787                return;
    function get_post_audio( $post_id = 0 ) { 
    18051805 * @param int $post_id  Post ID
    18061806 * @return array Found video attachments
    18071807 */
    1808 function get_post_video( $post_id = 0 ) {
     1808function get_attached_video( $post_id = 0 ) {
    18091809        $post = empty( $post_id ) ? get_post() : get_post( $post_id );
    18101810        if ( empty( $post ) )
    18111811                return;
    function get_post_video( $post_id = 0 ) { 
    18241824/**
    18251825 * Audio embed handler callback.
    18261826 *
     1827 * @since 3.6.0
     1828 *
    18271829 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
    18281830 * @param array $attr Embed attributes.
    18291831 * @param string $url The original URL that was matched by the regex.
    wp_embed_register_handler( 'wp_audio_embed', '#https?://.+?\.(' . join( '|', wp_ 
    18411843/**
    18421844 * Video embed handler callback.
    18431845 *
     1846 * @since 3.6.0
     1847 *
    18441848 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
    18451849 * @param array $attr Embed attributes.
    18461850 * @param string $url The original URL that was matched by the regex.
    function wp_video_embed( $matches, $attr, $url, $rawattr ) { 
    18601864        return apply_filters( 'wp_video_embed', $video, $attr, $url, $rawattr );
    18611865}
    18621866wp_embed_register_handler( 'wp_video_embed', '#https?://.+?\.(' . join( '|', wp_get_video_extensions() ) . ')#i', apply_filters( 'wp_video_embed_handler', 'wp_video_embed' ), 9999 );
     1867
     1868/**
     1869 * Retrieve images attached to the passed post
     1870 *
     1871 * @since 3.6.0
     1872 *
     1873 * @param int $post_id Optional. Post ID.
     1874 * @return array Found image attachments
     1875 */
     1876function get_attached_images( $post_id = 0 ) {
     1877        $post = empty( $post_id ) ? get_post() : get_post( $post_id );
     1878        if ( empty( $post ) )
     1879                return array();
     1880
     1881        $children = get_children( array(
     1882                'post_parent' => $post->ID,
     1883                'post_type' => 'attachment',
     1884                'post_mime_type' => 'image',
     1885                'posts_per_page' => -1,
     1886                'orderby' => 'menu_order',
     1887                'order' => 'ASC'
     1888        ) );
     1889
     1890        if ( ! empty( $children ) )
     1891                return $children;
     1892
     1893        return array();
     1894}
     1895
     1896/**
     1897 * Retrieve images attached to the passed post
     1898 *
     1899 * @since 3.6.0
     1900 *
     1901 * @param int $post_id Optional. Post ID.
     1902 * @return array Found image attachments
     1903 */
     1904function get_attached_image_srcs( $post_id = 0 ) {
     1905        $children = get_attached_images( $post_id );
     1906        if ( empty( $children ) )
     1907                return array();
     1908
     1909        $srcs = array();
     1910        foreach ( $children as $attachment )
     1911                $srcs[] = wp_get_attachment_url( $attachment->ID );
     1912
     1913        return $srcs;
     1914}
     1915
     1916/**
     1917 * Check the content blob for image srcs
     1918 *
     1919 * @since 3.6.0
     1920 *
     1921 * @param string $content A string which might contain image data.
     1922 * @param boolean $remove Whether to remove the found data from the passed content.
     1923 * @param int $limit Optional. The number of image srcs to return
     1924 * @return array The found image srcs
     1925 */
     1926function get_content_images( &$content, $remove = false, $limit = 0 ) {
     1927        $src = '';
     1928        $srcs = array();
     1929        $matches = array();
     1930
     1931        if ( preg_match_all( '#' . get_tag_regex( 'img' ) . '#i', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
     1932                foreach ( $matches as $tag ) {
     1933                        $count = 1;
     1934                        if ( $remove )
     1935                                $content = str_replace( $tag[0], '', $content, $count );
     1936
     1937                        preg_match( '#src=[\'"](.+?)[\'"]#is', $tag[1], $src );
     1938                        if ( ! empty( $src[1] ) ) {
     1939                                $srcs[] = $src[1];
     1940                                if ( $limit > 0 && count( $srcs ) >= $limit )
     1941                                        break;
     1942                        }
     1943                }
     1944        }
     1945
     1946        return array_values( array_unique( $srcs ) );
     1947}
     1948
     1949/**
     1950 * Check the content blob for image srcs and return the first
     1951 *
     1952 * @since 3.6.0
     1953 *
     1954 * @param string $content A string which might contain image data.
     1955 * @param boolean $remove Whether to remove the found data from the passed content.
     1956 * @return string The found data
     1957 */
     1958function get_content_image( &$content, $remove = false ) {
     1959        $srcs = get_content_images( $content, $remove, 1 );
     1960        if ( empty( $srcs ) )
     1961                return '';
     1962
     1963        return reset( $srcs );
     1964}
     1965
     1966/**
     1967 * Check the content blob for galleries and return their image srcs
     1968 *
     1969 * @since 3.6.0
     1970 *
     1971 * @param string $content A string which might contain image data.
     1972 * @param boolean $remove Optional. Whether to remove the found data from the passed content.
     1973 * @param int $limit Optional. The number of galleries to return
     1974 * @return array A list of galleries, which in turn are a list of their srcs in order
     1975 */
     1976function get_content_galleries( &$content, $remove = false, $limit = 0 ) {
     1977        $src = '';
     1978        $galleries = array();
     1979        $matches = array();
     1980
     1981        if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
     1982                foreach ( $matches as $shortcode ) {
     1983                        if ( 'gallery' === $shortcode[2] ) {
     1984                                $srcs = array();
     1985                                $count = 1;
     1986                                if ( $remove )
     1987                                        $content = str_replace( $shortcode[0], '', $content, $count );
     1988
     1989                                $data = shortcode_parse_atts( $shortcode[3] );
     1990                                $gallery = do_shortcode_tag( $shortcode );
     1991                                preg_match_all( '#src=[\'"](.+?)[\'"]#is', $gallery, $src, PREG_SET_ORDER );
     1992                                if ( ! empty( $src ) ) {
     1993                                        foreach ( $src as $s )
     1994                                                $srcs[] = $s[1];
     1995                                }
     1996
     1997                                $data['src'] = array_values( array_unique( $srcs ) );
     1998                                $galleries[] = $data;
     1999                                if ( $limit > 0 && count( $galleries ) >= $limit )
     2000                                        break;
     2001                        }
     2002                }
     2003        }
     2004
     2005        return $galleries;
     2006}
     2007
     2008/**
     2009 * Retrieve galleries from the passed post's content
     2010 *
     2011 * @since 3.6.0
     2012 *
     2013 * @param int $post_id Optional. Post ID.
     2014 * @return array A list of arrays, each containing gallery data and srcs parsed
     2015 *              from the expanded shortcode
     2016 */
     2017function get_post_galleries( $post_id = 0 ) {
     2018        $post = empty( $post_id ) ? clone get_post() : get_post( $post_id );
     2019        if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' )  )
     2020                return array();
     2021
     2022        return get_content_galleries( $post->post_content );
     2023}
     2024
     2025/**
     2026 * Retrieve the image srcs from galleries from a post's content, if present
     2027 *
     2028 * @since 3.6.0
     2029 *
     2030 * @param int $post_id Optional. Post ID.
     2031 * @return array A list of lists, each containing image srcs parsed
     2032 *              from an expanded shortcode
     2033 */
     2034function get_post_galleries_images( $post_id = 0 ) {
     2035        $post = empty( $post_id ) ? clone get_post() : get_post( $post_id );
     2036        if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' )  )
     2037                return array();
     2038
     2039        $data = get_content_galleries( $post->post_content );
     2040        return wp_list_pluck( $data, 'src' );
     2041}
     2042
     2043/**
     2044 * Check a specified post's content for gallery and, if present, return the first
     2045 *
     2046 * @since 3.6.0
     2047 *
     2048 * @param int $post_id Optional. Post ID.
     2049 * @return array Gallery data and srcs parsed from the expanded shortcode
     2050 */
     2051function get_post_gallery( $post_id = 0 ) {
     2052        $post = empty( $post_id ) ? clone get_post() : get_post( $post_id );
     2053        if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) )
     2054                return array();
     2055
     2056        $data = get_content_galleries( $post->post_content, false, 1 );
     2057        return reset( $data );
     2058}
     2059
     2060/**
     2061 * Check a post's content for galleries and return the image srcs for the first found gallery
     2062 *
     2063 * @since 3.6.0
     2064 *
     2065 * @param int $post_id Optional. Post ID.
     2066 * @return array A list of a gallery's image srcs in order
     2067 */
     2068function get_post_gallery_images( $post_id = 0 ) {
     2069        $gallery = get_post_gallery( $post_id );
     2070        if ( empty( $gallery['src'] ) )
     2071                return array();
     2072
     2073        return $gallery['src'];
     2074}
     2075 No newline at end of file