<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[23819] trunk/wp-includes: Give themers tangible, user-friendly template functions to take full advantage of structured post formats.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/23819">23819</a></dd>
<dt>Author</dt> <dd>markjaquith</dd>
<dt>Date</dt> <dd>2013-03-27 18:34:59 +0000 (Wed, 27 Mar 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Give themers tangible, user-friendly template functions to take full advantage of structured post formats.
* the_audio()
* the_video()
* the_image()
* get_the_media()
Also introduces:
* get_the_extra_content()
* the_extra_content()
Those two functions are like their non-extra versions, except that they
will have any post-format bits extracted. e.g. It's an image post, for
which the_image() will extract an <img /> tag. the_extra_content() will
output the content *without* that image.
props wonderboymusic. Herculean effort. fixes <a href="http://core.trac.wordpress.org/ticket/23572">#23572</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
<li><a href="#trunkwpincludespostformatsphp">trunk/wp-includes/post-formats.php</a></li>
<li><a href="#trunkwpincludesposttemplatephp">trunk/wp-includes/post-template.php</a></li>
<li><a href="#trunkwpincludesqueryphp">trunk/wp-includes/query.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (23818 => 23819)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2013-03-27 18:11:56 UTC (rev 23818)
+++ trunk/wp-includes/media.php        2013-03-27 18:34:59 UTC (rev 23819)
</span><span class="lines">@@ -887,7 +887,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         $library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' );
</span><del>-        if ( 'mediaelement' === $library ) {
</del><ins>+        if ( 'mediaelement' === $library && did_action( 'init' ) ) {
</ins><span class="cx">                 wp_enqueue_style( 'wp-mediaelement' );
</span><span class="cx">                 wp_enqueue_script( 'wp-mediaelement' );
</span><span class="cx">         }
</span><span class="lines">@@ -994,7 +994,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         $library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' );
</span><del>-        if ( 'mediaelement' === $library ) {
</del><ins>+        if ( 'mediaelement' === $library && did_action( 'init' ) ) {
</ins><span class="cx">                 wp_enqueue_style( 'wp-mediaelement' );
</span><span class="cx">                 wp_enqueue_script( 'wp-mediaelement' );
</span><span class="cx">         }
</span><span class="lines">@@ -1828,40 +1828,50 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Extract the srcs from the post's [{media type}] <source>s
</del><ins>+ * Extract and parse {media type} shortcodes or srcs from the passed content
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><ins>+ * @param string $type Type of media: audio or video
</ins><span class="cx"> * @param string $content A string which might contain media data.
</span><ins>+ * @param boolean $html Whether to return HTML or URLs
</ins><span class="cx"> * @param boolean $remove Whether to remove the found URL from the passed content.
</span><del>- * @return array A list of lists. Each item has a list of sources corresponding
- *                to a [{media type}]'s primary src and specified fallbacks
</del><ins>+ * @return array A list of parsed shortcodes or extracted srcs
</ins><span class="cx"> */
</span><del>-function get_content_media( $type, &$content, $remove = false ) {
-        $src = '';
</del><ins>+function get_content_media( $type, &$content, $html = true, $remove = false ) {
</ins><span class="cx">         $items = array();
</span><span class="cx">         $matches = array();
</span><span class="cx">
</span><span class="cx">         if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
</span><span class="cx">                 foreach ( $matches as $shortcode ) {
</span><span class="cx">                         if ( $type === $shortcode[2] ) {
</span><del>-                                $srcs = array();
</del><span class="cx">                                 $count = 1;
</span><span class="cx">                                 if ( $remove )
</span><del>-                                        $content = str_replace( $shortcode[0], '', $content, $count );
</del><ins>+                                        $content =& str_replace( $shortcode[0], '', $content, $count );
</ins><span class="cx">
</span><del>-                                $item = do_shortcode_tag( $shortcode );
-                                preg_match_all( '#src=[\'"](.+?)[\'"]#is', $item, $src, PREG_SET_ORDER );
-                                if ( ! empty( $src ) ) {
-                                        foreach ( $src as $s )
-                                                $srcs[] = $s[1];
-
-                                        $items[] = array_values( array_unique( $srcs ) );
-                                }
</del><ins>+                                $items[] = do_shortcode_tag( $shortcode );
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">         }
</span><del>-        return $items;
</del><ins>+
+        if ( $html )
+                return $items;
+
+        $src = '';
+        $data = array();
+
+        foreach ( $items as $item ) {
+                preg_match_all( '#src=[\'"](.+?)[\'"]#is', $item, $src, PREG_SET_ORDER );
+                if ( ! empty( $src ) ) {
+                        $srcs = array();
+                        foreach ( $src as $s )
+                                $srcs[] = $s[1];
+
+                        $data[] = array_values( array_unique( $srcs ) );
+                }
+        }
+
+        return $data;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -1870,11 +1880,13 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><ins>+ * @param string $type Type of media: audio or video
</ins><span class="cx"> * @param string $content A string which might contain media data.
</span><span class="cx"> * @param boolean $remove Whether to remove the found URL from the passed content.
</span><ins>+ * @param int $limit Optional. The number of galleries to return
</ins><span class="cx"> * @return array A list of found HTML media embeds and possibly a URL by itself
</span><span class="cx"> */
</span><del>-function get_embedded_media( $type, &$content, $remove = false ) {
</del><ins>+function get_embedded_media( $type, &$content, $remove = false, $limit = 0 ) {
</ins><span class="cx">         $html = array();
</span><span class="cx">         $matches = '';
</span><span class="cx">
</span><span class="lines">@@ -1884,13 +1896,16 @@
</span><span class="cx">                         if ( $remove )
</span><span class="cx">                                 $content = str_replace( $matches[0], '', $content );
</span><span class="cx">
</span><del>-                        return $html;
</del><ins>+                        if ( $limit > 0 && count( $html ) >= $limit )
+                                break;
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        if ( ! empty( $html ) && count( $html ) >= $limit )
+                return $html;
+
</ins><span class="cx">         $lines = explode( "\n", trim( $content ) );
</span><span class="cx">         $line = trim( array_shift( $lines ) );
</span><del>-
</del><span class="cx">         if ( 0 === stripos( $line, 'http' ) ) {
</span><span class="cx">                 if ( $remove )
</span><span class="cx">                         $content = join( "\n", $lines );
</span><span class="lines">@@ -1901,17 +1916,18 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Extract the srcs from the post's [audio] <source>s
</del><ins>+ * Extract the HTML or <source> srcs from the content's [audio]
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $content A string which might contain audio data.
</span><ins>+ * @param boolean $html Whether to return HTML or URLs
</ins><span class="cx"> * @param boolean $remove Whether to remove the found URL from the passed content.
</span><del>- * @return array A list of lists. Each item has a list of sources corresponding
- *                to a [audio]'s primary src and specified fallbacks
</del><ins>+ * @return array A list of lists. Each item has a list of HTML or srcs corresponding
+ *                to an [audio]'s HTML or primary src and specified fallbacks
</ins><span class="cx"> */
</span><del>-function get_content_audio( &$content, $remove = false ) {
-        return get_content_media( 'audio', $content, $remove );
</del><ins>+function get_content_audio( &$content, $html = true, $remove = false ) {
+        return get_content_media( 'audio', $content, $html, $remove );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -1929,17 +1945,18 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Extract the srcs from the post's [video] <source>s
</del><ins>+ * Extract the HTML or <source> srcs from the content's [video]
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $content A string which might contain video data.
</span><ins>+ * @param boolean $html Whether to return HTML or URLs
</ins><span class="cx"> * @param boolean $remove Whether to remove the found URL from the passed content.
</span><del>- * @return array A list of lists. Each item has a list of sources corresponding
- *                to a [video]'s primary src and specified fallbacks
</del><ins>+ * @return array A list of lists. Each item has a list of HTML or srcs corresponding
+ *                to a [video]'s HTML or primary src and specified fallbacks
</ins><span class="cx"> */
</span><del>-function get_content_video( &$content, $remove = false ) {
-        return get_content_media( 'video', $content, $remove );
</del><ins>+function get_content_video( &$content, $html = true, $remove = false ) {
+        return get_content_media( 'video', $content, $html, $remove );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -2001,6 +2018,117 @@
</span><span class="cx"> wp_embed_register_handler( 'wp_video_embed', '#https?://.+?\.(' . join( '|', wp_get_video_extensions() ) . ')#i', apply_filters( 'wp_video_embed_handler', 'wp_video_embed' ), 9999 );
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Return suitable HTML code for output based on the content related to the global $post
+ * If found, remove the content from the @global $post's post_content field
+ *
+ * @since 3.6.0
+ *
+ * @param string $type Required. 'audio' or 'video'
+ * @param WP_Post $post Optional. Used instead of global $post when passed.
+ * @return string
+ */
+function get_the_media( $type, &$post = null ) {
+        global $wp_embed;
+
+        if ( empty( $post ) )
+                $post =& get_post();
+
+        if ( empty( $post ) )
+                return '';
+
+        if ( isset( $post->format_content ) )
+                return $post->format_content;
+
+        $count = 1;
+
+        if ( has_post_format( $type ) ) {
+                $meta = get_post_format_meta( $post->ID );
+                if ( ! empty( $meta['media'] ) ) {
+                        if ( is_numeric( $meta['media'] ) ) {
+                                $url = wp_get_attachment_url( $meta['media'] );
+                                $shortcode = sprintf( '[%s src="%s"]', $type, $url );
+                        } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $meta['media'] ) ) {
+                                $shortcode = $meta['media'];
+                        } elseif ( preg_match( '#<[^>]+>#', $meta['media'] ) ) {
+                                $post->format_content = $meta['media'];
+                                return $post->format_content;
+                        } elseif ( 0 === strpos( $meta['media'], 'http' ) ) {
+                                $post->split_content = str_replace( $meta['media'], '', $post->post_content, $count );
+                                if ( strstr( $meta['media'], home_url() ) ) {
+                                        $shortcode = sprintf( '[%s src="%s"]', $type, $meta['media'] );
+                                } else {
+                                        $post->format_content = $wp_embed->autoembed( $meta['media'] );
+                                        return $post->format_content;
+                                }
+                        }
+
+                        if ( ! empty( $shortcode ) ) {
+                                $post->format_content = do_shortcode( $shortcode );
+                                return $post->format_content;
+                        }
+                }
+        }
+
+        $medias = call_user_func( 'get_attached_' . $type );
+        if ( ! empty( $medias ) ) {
+                $media = reset( $medias );
+                $url = wp_get_attachment_url( $media->ID );
+                $shortcode = sprintf( '[%s src="%s"]', $type, $url );
+                $post->format_content = do_shortcode( $shortcode );
+                return $post->format_content;
+        }
+
+        // these functions expected a reference, not a value
+        $_content = $post->post_content;
+        $content =& $_content;
+
+        $htmls = get_content_media( $type, $content, true, true );
+        if ( ! empty( $htmls ) ) {
+                $html = reset( $htmls );
+                $post->split_content = $content;
+                $post->format_content = $html;
+                return $post->format_content;
+        }
+
+        $embeds = get_embedded_media( $type, $content, true, 1 );
+        if ( ! empty( $embeds ) ) {
+                $embed = reset( $embeds );
+                $post->split_content = $content;
+                if ( 0 === strpos( $embed, 'http' ) ) {
+                        if ( strstr( $embed, home_url() ) ) {
+                                $post->format_content = do_shortcode( sprintf( '[%s src="%s"]', $type, $embed ) );
+                        } else {
+                                $post->format_content = $wp_embed->autoembed( $embed );
+                        }
+                } else {
+                        $post->format_content = $embed;
+                }
+                return $post->format_content;
+        }
+
+        return '';
+}
+
+/**
+ * Output the first video in the current (@global) post's content
+ *
+ * @since 3.6.0
+ *
+ */
+function the_video() {
+        echo get_the_media( 'video' );
+}
+/**
+ * Output the first audio in the current (@global) post's content
+ *
+ * @since 3.6.0
+ *
+ */
+function the_audio() {
+        echo get_the_media( 'audio' );
+}
+
+/**
</ins><span class="cx"> * Retrieve images attached to the passed post
</span><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="lines">@@ -2033,22 +2161,22 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Check the content blob for image srcs
</del><ins>+ * Check the content blob for images or image srcs
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $content A string which might contain image data.
</span><ins>+ * @param boolean $html Whether to return HTML or URLs
</ins><span class="cx"> * @param boolean $remove Whether to remove the found data from the passed content.
</span><span class="cx"> * @param int $limit Optional. The number of image srcs to return
</span><del>- * @return array The found image srcs
</del><ins>+ * @return array The found images or srcs
</ins><span class="cx"> */
</span><del>-function get_content_images( &$content, $remove = false, $limit = 0 ) {
-        $src = '';
-        $srcs = array();
</del><ins>+function get_content_images( &$content, $html = true, $remove = false, $limit = 0 ) {
</ins><span class="cx">         $matches = array();
</span><ins>+        $tags = array();
+        $captions = array();
</ins><span class="cx">
</span><span class="cx">         if ( $remove && preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
</span><del>-                $captions = array();
</del><span class="cx">                 foreach ( $matches as $shortcode ) {
</span><span class="cx">                         if ( 'caption' === $shortcode[2] )
</span><span class="cx">                                 $captions[] = $shortcode[0];
</span><span class="lines">@@ -2068,29 +2196,43 @@
</span><span class="cx">                                 $content = str_replace( $tag[0], '', $content, $count );
</span><span class="cx">                         }
</span><span class="cx">
</span><del>-                        preg_match( '#src=[\'"](.+?)[\'"]#is', $tag[0], $src );
-                        if ( ! empty( $src[1] ) ) {
-                                $srcs[] = $src[1];
-                                if ( $limit > 0 && count( $srcs ) >= $limit )
-                                        break;
-                        }
</del><ins>+                        $tags[] = $tag[0];
+
+                        if ( $limit > 0 && count( $tags ) >= $limit )
+                                break;
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        if ( $html )
+                return $tags;
+
+        $src = '';
+        $srcs = array();
+
+        foreach ( $tags as $tag ) {
+                preg_match( '#src=[\'"](.+?)[\'"]#is', $tag, $src );
+                if ( ! empty( $src[1] ) ) {
+                        $srcs[] = $src[1];
+                        if ( $limit > 0 && count( $srcs ) >= $limit )
+                                break;
+                }
+        }
+
</ins><span class="cx">         return array_values( array_unique( $srcs ) );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Check the content blob for image srcs and return the first
</del><ins>+ * Check the content blob for images or srcs and return the first
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $content A string which might contain image data.
</span><ins>+ * @param boolean $html Whether to return HTML or URLs
</ins><span class="cx"> * @param boolean $remove Whether to remove the found data from the passed content.
</span><span class="cx"> * @return string The found data
</span><span class="cx"> */
</span><del>-function get_content_image( &$content, $remove = false ) {
-        $srcs = get_content_images( $content, $remove, 1 );
</del><ins>+function get_content_image( &$content, $html = true, $remove = false ) {
+        $srcs = get_content_images( $content, $html, $remove, 1 );
</ins><span class="cx">         if ( empty( $srcs ) )
</span><span class="cx">                 return '';
</span><span class="cx">
</span><span class="lines">@@ -2205,4 +2347,85 @@
</span><span class="cx">                 return array();
</span><span class="cx">
</span><span class="cx">         return $gallery['src'];
</span><ins>+}
+
+/**
+ * Return the first image in the current (@global) post's content
+ *
+ * @since 3.6.0
+ *
+ * @param string $attached_size If an attached image is found, the size to display it.
+ * @param WP_Post $post Optional. Used instead of global $post when passed.
+ */
+function get_the_image( $attached_size = 'full', &$post = null ) {
+        if ( empty( $post ) )
+                $post = get_post();
+
+        if ( empty( $post ) )
+                return '';
+
+        if ( isset( $post->format_content ) )
+                return $post->format_content;
+
+        $medias = get_attached_images();
+        if ( ! empty( $medias ) ) {
+                $media = reset( $medias );
+                $sizes = get_intermediate_image_sizes();
+
+                $urls = array();
+                foreach ( $sizes as $size ) {
+                        $urls[] = reset( wp_get_attachment_image_src( $media->ID, $size ) );
+                        $urls[] = get_attachment_link( $media->ID );
+                }
+
+                $count = 1;
+                $matches = array();
+                $content =& $post->post_content;
+
+                if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
+                        foreach ( $matches as $shortcode ) {
+                                if ( 'caption' === $shortcode[2] ) {
+                                        foreach ( $urls as $url ) {
+                                                if ( strstr( $shortcode[0], $url ) )
+                                                        $content = str_replace( $shortcode[0], '', $content, $count );
+                                        }
+                                }
+                        }
+                }
+
+                foreach ( array( 'a', 'img' ) as $tag ) {
+                        if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
+                                foreach ( $matches as $match ) {
+                                        foreach ( $urls as $url ) {
+                                                if ( strstr( $match[0], $url ) )
+                                                        $content = str_replace( $match[0], '', $content, $count );
+                                        }
+                                }
+                        }
+                }
+
+                $post->split_content = $content;
+                $post->format_content = wp_get_attachment_image( $media->ID, $attached_size );
+                return $post->format_content;
+        }
+
+        $content =& $post->post_content;
+        $htmls = get_content_images( $content, true, true, 1 );
+        if ( ! empty( $htmls ) ) {
+                $html = reset( $htmls );
+                $post->split_content = $content;
+                $post->format_content = $html;
+                return $post->format_content;
+        }
+}
+
+/**
+ * Output the first image in the current (@global) post's content
+ *
+ * @since 3.6.0
+ *
+ * @param string $attached_size If an attached image is found, the size to display it.
+ */
+function the_image( $attached_size = 'full' ) {
+        echo get_the_image( $attached_size );
</ins><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludespostformatsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-formats.php (23818 => 23819)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-formats.php        2013-03-27 18:11:56 UTC (rev 23818)
+++ trunk/wp-includes/post-formats.php        2013-03-27 18:34:59 UTC (rev 23819)
</span><span class="lines">@@ -678,3 +678,89 @@
</span><span class="cx"> function the_url() {
</span><span class="cx">         echo esc_url( get_the_url() );
</span><span class="cx"> }
</span><ins>+
+/**
+ * Retrieve the post content, minus the extracted post format content
+ *
+ * @since 3.6.0
+ *
+ * @internal there is a lot of code that could be abstracted from get_the_content()
+ *
+ * @param string $more_link_text Optional. Content for when there is more text.
+ * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
+ * @return string
+ */
+function get_the_extra_content( $more_link_text = null, $strip_teaser = false ) {
+        global $more, $page, $format_pages, $multipage, $preview;
+
+        $post = get_post();
+
+        if ( null === $more_link_text )
+                $more_link_text = __( '(more...)' );
+
+        $output = '';
+        $has_teaser = false;
+        $matches = array();
+
+        // If post password required and it doesn't match the cookie.
+        if ( post_password_required() )
+                return get_the_password_form();
+
+        if ( $page > count( $format_pages ) ) // if the requested page doesn't exist
+                $page = count( $format_pages ); // give them the highest numbered page that DOES exist
+
+        $content = $format_pages[$page-1];
+        if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
+                $content = explode( $matches[0], $content, 2 );
+                if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
+                        $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
+
+                $has_teaser = true;
+        } else {
+                $content = array( $content );
+        }
+
+        if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )
+                $strip_teaser = true;
+
+        $teaser = $content[0];
+
+        if ( $more && $strip_teaser && $has_teaser )
+                $teaser = '';
+
+        $output .= $teaser;
+
+        if ( count( $content ) > 1 ) {
+                if ( $more ) {
+                        $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
+                } else {
+                        if ( ! empty( $more_link_text ) )
+                                $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
+
+                        $output = force_balance_tags( $output );
+                }
+        }
+
+        if ( $preview ) // preview fix for javascript bug with foreign languages
+                $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
+
+        return $output;
+}
+
+/**
+ * Display the post content minus the parsed post format data.
+ *
+ * @since 3.6.0
+ *
+ * @param string $more_link_text Optional. Content for when there is more text.
+ * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
+ */
+function the_extra_content( $more_link_text = null, $strip_teaser = false ) {
+        $extra = get_the_extra_content( $more_link_text, $strip_teaser );
+
+        remove_filter( 'the_content', 'post_formats_compat', 7 );
+        $content = apply_filters( 'the_content', $extra );
+        add_filter( 'the_content', 'post_formats_compat', 7 );
+
+        echo str_replace( ']]>', ']]&gt;', $content );
+}
</ins></span></pre></div>
<a id="trunkwpincludesposttemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-template.php (23818 => 23819)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-template.php        2013-03-27 18:11:56 UTC (rev 23818)
+++ trunk/wp-includes/post-template.php        2013-03-27 18:34:59 UTC (rev 23819)
</span><span class="lines">@@ -159,13 +159,11 @@
</span><span class="cx"> * @since 0.71
</span><span class="cx"> *
</span><span class="cx"> * @param string $more_link_text Optional. Content for when there is more text.
</span><del>- * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
</del><ins>+ * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
</ins><span class="cx"> */
</span><del>-function the_content($more_link_text = null, $stripteaser = false) {
-        $content = get_the_content($more_link_text, $stripteaser);
-        $content = apply_filters('the_content', $content);
-        $content = str_replace(']]>', ']]&gt;', $content);
-        echo $content;
</del><ins>+function the_content( $more_link_text = null, $strip_teaser = false ) {
+        $content = apply_filters( 'the_content', get_the_content( $more_link_text, $strip_teaser ) );
+        echo str_replace( ']]>', ']]&gt;', $content );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -177,7 +175,7 @@
</span><span class="cx"> * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>-function get_the_content( $more_link_text = null, $stripteaser = false ) {
</del><ins>+function get_the_content( $more_link_text = null, $strip_teaser = false ) {
</ins><span class="cx">         global $more, $page, $pages, $multipage, $preview;
</span><span class="cx">
</span><span class="cx">         $post = get_post();
</span><span class="lines">@@ -186,43 +184,49 @@
</span><span class="cx">                 $more_link_text = __( '(more...)' );
</span><span class="cx">
</span><span class="cx">         $output = '';
</span><del>-        $hasTeaser = false;
</del><ins>+        $has_teaser = false;
+        $matches = array();
</ins><span class="cx">
</span><span class="cx">         // If post password required and it doesn't match the cookie.
</span><span class="cx">         if ( post_password_required() )
</span><span class="cx">                 return get_the_password_form();
</span><span class="cx">
</span><del>-        if ( $page > count($pages) ) // if the requested page doesn't exist
-                $page = count($pages); // give them the highest numbered page that DOES exist
</del><ins>+        if ( $page > count( $pages ) ) // if the requested page doesn't exist
+                $page = count( $pages ); // give them the highest numbered page that DOES exist
</ins><span class="cx">
</span><del>-        $content = $pages[$page-1];
-        if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
-                $content = explode($matches[0], $content, 2);
-                if ( !empty($matches[1]) && !empty($more_link_text) )
-                        $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
</del><ins>+        $content = $pages[$page - 1];
+        if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
+                $content = explode( $matches[0], $content, 2 );
+                if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
+                        $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
</ins><span class="cx">
</span><del>-                $hasTeaser = true;
</del><ins>+                $has_teaser = true;
</ins><span class="cx">         } else {
</span><del>-                $content = array($content);
</del><ins>+                $content = array( $content );
</ins><span class="cx">         }
</span><del>-        if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
-                $stripteaser = true;
</del><ins>+
+        if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )
+                $strip_teaser = true;
+
</ins><span class="cx">         $teaser = $content[0];
</span><del>-        if ( $more && $stripteaser && $hasTeaser )
</del><ins>+
+        if ( $more && $strip_teaser && $has_teaser )
</ins><span class="cx">                 $teaser = '';
</span><ins>+
</ins><span class="cx">         $output .= $teaser;
</span><del>-        if ( count($content) > 1 ) {
</del><ins>+
+        if ( count( $content ) > 1 ) {
</ins><span class="cx">                 if ( $more ) {
</span><span class="cx">                         $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
</span><span class="cx">                 } else {
</span><del>-                        if ( ! empty($more_link_text) )
</del><ins>+                        if ( ! empty( $more_link_text ) )
</ins><span class="cx">                                 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
</span><del>-                        $output = force_balance_tags($output);
</del><ins>+                        $output = force_balance_tags( $output );
</ins><span class="cx">                 }
</span><ins>+        }
</ins><span class="cx">
</span><del>-        }
</del><span class="cx">         if ( $preview ) // preview fix for javascript bug with foreign languages
</span><del>-                $output =        preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output);
</del><ins>+                $output =        preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
</ins><span class="cx">
</span><span class="cx">         return $output;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpincludesqueryphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/query.php (23818 => 23819)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/query.php        2013-03-27 18:11:56 UTC (rev 23818)
+++ trunk/wp-includes/query.php        2013-03-27 18:34:59 UTC (rev 23819)
</span><span class="lines">@@ -3677,7 +3677,7 @@
</span><span class="cx"> * @return bool True when finished.
</span><span class="cx"> */
</span><span class="cx"> function setup_postdata($post) {
</span><del>-        global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
</del><ins>+        global $id, $authordata, $currentday, $currentmonth, $page, $pages, $format_pages, $multipage, $more, $numpages;
</ins><span class="cx">
</span><span class="cx">         $id = (int) $post->ID;
</span><span class="cx">
</span><span class="lines">@@ -3691,18 +3691,38 @@
</span><span class="cx">                 $page = 1;
</span><span class="cx">         if ( is_single() || is_page() || is_feed() )
</span><span class="cx">                 $more = 1;
</span><del>-        $content = $post->post_content;
</del><ins>+        $split_content = $content = $post->post_content;
+        $format = get_post_format( $post );
+        if ( $format && in_array( $format, array( 'image', 'audio', 'video' ) ) ) {
+                switch ( $format ) {
+                case 'image':
+                        get_the_image( 'full', $post );
+                        if ( isset( $post->split_content ) )
+                                $split_content = $post->split_content;
+                        break;
+                case 'audio':
+                        get_the_media( 'audio', $post );
+                        if ( isset( $post->split_content ) )
+                                $split_content = $post->split_content;
+                        break;
+                case 'video':
+                        get_the_media( 'video', $post );
+                        if ( isset( $post->split_content ) )
+                                $split_content = $post->split_content;
+                        break;
+                }
+        }
+
</ins><span class="cx">         if ( strpos( $content, '<!--nextpage-->' ) ) {
</span><span class="cx">                 if ( $page > 1 )
</span><span class="cx">                         $more = 1;
</span><span class="cx">                 $multipage = 1;
</span><del>-                $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
-                $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
-                $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
-                $pages = explode('<!--nextpage-->', $content);
-                $numpages = count($pages);
</del><ins>+                $pages = paginate_content( $content );
+                $format_pages = paginate_content( $split_content );
+                $numpages = count( $pages );
</ins><span class="cx">         } else {
</span><span class="cx">                 $pages = array( $post->post_content );
</span><ins>+                $format_pages = array( $split_content );
</ins><span class="cx">                 $multipage = 0;
</span><span class="cx">         }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>