Make WordPress Core

Ticket #23593: 23593.diff

File 23593.diff, 4.9 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..c90d802 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 an <img>
     1574 * If no HTML tag is found, check the first line of the post for a URL
     1575 *
     1576 * @param string $content A string which might contain image data.
     1577 * @param boolean $remove Whether to remove the found data from the passed content.
     1578 * @return string The found data
     1579 */
     1580function get_content_image( &$content, $remove = false ) {
     1581        $matches = $match = $src = '';
     1582
     1583        if ( preg_match( '/' . get_shortcode_regex() . '/s', $content, $match ) && 'gallery' == $match[2] ) {
     1584                $count = 1;
     1585                if ( $remove )
     1586                        $content = str_replace( $match[0], '', $content, $count );
     1587
     1588                $gallery = do_shortcode_tag( $match );
     1589                preg_match( '#src=[\'"](.+?)[\'"]#is', $gallery, $src );
     1590                if ( ! empty( $src[1] ) )
     1591                        return $src[1];
     1592        }
     1593
     1594        if ( preg_match( '#' . get_tag_regex( 'img' ) . '#i', $content, $matches ) ) {
     1595                $count = 1;
     1596                if ( $remove )
     1597                        $content = str_replace( $matches[0], '', $content, $count );
     1598
     1599                preg_match( '#src=[\'"](.+?)[\'"]#is', $matches[1], $src );
     1600                if ( ! empty( $src[1] ) )
     1601                        return $src[1];
     1602        }
     1603
     1604        $lines = explode( "\n", trim( $content ) );
     1605        $line = trim( array_shift( $lines  ) );
     1606
     1607        if ( 0 === stripos( $line, 'http' ) ) {
     1608                if ( $remove )
     1609                        $content = join( "\n", $lines );
     1610
     1611                return $line;
     1612        }
     1613}
     1614
     1615/**
     1616 * Return the found image data for the passed post
     1617 *
     1618 * @since 3.6.0
     1619 *
     1620 * @param int $id Optional. Post ID
     1621 */
     1622function get_the_image( $id = 0 ) {
     1623        $post = empty( $id ) ? get_post() : get_post( $id );
     1624        if ( empty( $post ) )
     1625                return '';
     1626
     1627        $data = get_content_image( $post->post_content );
     1628        if ( ! empty( $data ) )
     1629                return $data;
     1630
     1631        $images = get_post_images( $post->ID );
     1632        if ( empty( $images ) )
     1633                return '';
     1634
     1635        $image = reset( $images );
     1636        return wp_get_attachment_url( $image->ID );
     1637}
     1638
     1639/**
     1640 * Output the found image data for the current post
     1641 *
     1642 * @since 3.6.0
     1643 */
     1644function the_image() {
     1645        echo apply_filters( 'the_image', get_the_image() );
     1646}
     1647 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..f971627 100644
    function post_formats_compat( $content, $id = 0 ) { 
    364364                                                );
    365365                                        }
    366366                                }
     367                        } else {
     368                                $data = get_content_image( $content, true );
     369                                $img_class = empty( $compat['image_class'] ) ? '' : sprintf( 'class="%s" ', esc_attr( $compat['image_class'] ) );
     370                                if ( ! empty( $data ) && 0 === stripos( $data, 'http' ) ) {
     371                                        if ( empty( $meta['url'] ) ) {
     372                                                $sformat = '<img %ssrc="%s"/>';
     373                                                $format_output .= sprintf( $sformat, $img_class, esc_url( $data ) );
     374                                        } else {
     375                                                $sformat = '<a href="%s"><img %ssrc="%s"/></a>';
     376                                                $format_output .= sprintf( $sformat, esc_url( $meta['url'] ), $img_class, esc_url( $data ) );
     377                                        }
     378                                } else {
     379                                        $images = get_post_images( $post->ID );
     380                                        if ( ! empty( $images ) ) {
     381                                                $image = reset( $images );
     382                                                $url = wp_get_attachment_url( $image->ID );
     383                                                $sformat = '<img %ssrc="%s"/>';
     384                                                $format_output .= sprintf( $sformat, $img_class, esc_url( $url ) );
     385                                        }
     386                                }
    367387                        }
    368388                        break;
    369389