Make WordPress Core

Ticket #22960: 22960.diff

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

    diff --git wp-includes/functions.php wp-includes/functions.php
    index cbd7925..a88c843 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/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index f1f3737..932a33c 100644
    function wp_enqueue_media( $args = array() ) { 
    15421542
    15431543        do_action( 'wp_enqueue_media' );
    15441544}
     1545
     1546/**
     1547 * Retrieve images attached to the passed post
     1548 *
     1549 * @since 3.6.0
     1550 *
     1551 * @param int $post_id  Post ID
     1552 * @return array Found image attachments
     1553 */
     1554function get_post_images( $post_id = 0 ) {
     1555        $post = empty( $post_id ) ? get_post() : get_post( $post_id );
     1556        if ( empty( $post ) )
     1557                return;
     1558
     1559        $children = get_children( array(
     1560                'post_parent' => $post->ID,
     1561                'post_type' => 'attachment',
     1562                'post_mime_type' => 'image',
     1563                'posts_per_page' => -1,
     1564                'orderby' => 'menu_order',
     1565                'order' => 'ASC'
     1566        ) );
     1567
     1568        if ( ! empty( $children ) )
     1569                return $children;
     1570}
     1571
     1572/**
     1573 * Check the content blob for images
     1574 *
     1575 * @param string $content A string which might contain image data.
     1576 * @param boolean $remove Whether to remove the found data from the passed content.
     1577 * @return string The found data
     1578 */
     1579function get_content_images( &$content, $remove = false ) {
     1580        $src = '';
     1581        $srcs = array();
     1582        $matches = array();
     1583        $match = array();
     1584
     1585        if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $match, PREG_SET_ORDER ) && ! empty( $match ) ) {
     1586                foreach ( $match as $i => $shortcode ) {
     1587                        if ( 'gallery' === $shortcode[2] ) {
     1588                                $count = 1;
     1589                                if ( $remove )
     1590                                        $content = str_replace( $shortcode[0], '', $content, $count );
     1591
     1592                                $gallery = do_shortcode_tag( $shortcode );
     1593                                preg_match_all( '#src=[\'"](.+?)[\'"]#is', $gallery, $src, PREG_SET_ORDER );
     1594                                if ( ! empty( $src ) ) {
     1595                                        foreach ( $src as $s )
     1596                                                $srcs[] = $s[1];
     1597                                }
     1598                        }
     1599                }
     1600        }
     1601
     1602        if ( preg_match_all( '#' . get_tag_regex( 'img' ) . '#i', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
     1603                foreach ( $matches as $tag ) {
     1604                        $count = 1;
     1605                        if ( $remove )
     1606                                $content = str_replace( $tag[0], '', $content, $count );
     1607
     1608                        preg_match( '#src=[\'"](.+?)[\'"]#is', $tag[1], $src );
     1609                        if ( ! empty( $src[1] ) )
     1610                                $srcs[] = $src[1];
     1611                }
     1612        }
     1613
     1614        return array_values( array_unique( $srcs ) );
     1615}
     1616
     1617/**
     1618 * Return the found gallery / image data for the passed post
     1619 *
     1620 * @since 3.6.0
     1621 *
     1622 * @param int $id Optional. Post ID
     1623 */
     1624function get_the_images( $id = 0 ) {
     1625        $post = empty( $id ) ? get_post() : get_post( $id );
     1626        if ( empty( $post ) )
     1627                return '';
     1628
     1629        $srcs = array();
     1630
     1631        $data = get_content_images( $post->post_content );
     1632        if ( ! empty( $data ) )
     1633                $srcs = array_merge( $srcs, $data );
     1634
     1635        $images = get_post_images( $post->ID );
     1636        if ( empty( $images ) )
     1637                return $srcs;
     1638
     1639        foreach ( $images as $image )
     1640                $srcs[] = wp_get_attachment_url( $image->ID );
     1641
     1642        return array_values( array_unique( $srcs ) );
     1643}
     1644 No newline at end of file