Make WordPress Core

Changeset 23819


Ignore:
Timestamp:
03/27/2013 06:34:59 PM (11 years ago)
Author:
markjaquith
Message:

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 #23572

Location:
trunk/wp-includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/media.php

    r23776 r23819  
    888888
    889889    $library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' );
    890     if ( 'mediaelement' === $library ) {
     890    if ( 'mediaelement' === $library && did_action( 'init' ) ) {
    891891        wp_enqueue_style( 'wp-mediaelement' );
    892892        wp_enqueue_script( 'wp-mediaelement' );
     
    995995
    996996    $library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' );
    997     if ( 'mediaelement' === $library ) {
     997    if ( 'mediaelement' === $library && did_action( 'init' ) ) {
    998998        wp_enqueue_style( 'wp-mediaelement' );
    999999        wp_enqueue_script( 'wp-mediaelement' );
     
    18291829
    18301830/**
    1831  * Extract the srcs from the post's [{media type}] <source>s
    1832  *
    1833  * @since 3.6.0
    1834  *
     1831 * Extract and parse {media type} shortcodes or srcs from the passed content
     1832 *
     1833 * @since 3.6.0
     1834 *
     1835 * @param string $type Type of media: audio or video
    18351836 * @param string $content A string which might contain media data.
     1837 * @param boolean $html Whether to return HTML or URLs
    18361838 * @param boolean $remove Whether to remove the found URL from the passed content.
    1837  * @return array A list of lists. Each item has a list of sources corresponding
    1838  *      to a [{media type}]'s primary src and specified fallbacks
    1839  */
    1840 function get_content_media( $type, &$content, $remove = false ) {
    1841     $src = '';
     1839 * @return array A list of parsed shortcodes or extracted srcs
     1840 */
     1841function get_content_media( $type, &$content, $html = true, $remove = false ) {
    18421842    $items = array();
    18431843    $matches = array();
     
    18461846        foreach ( $matches as $shortcode ) {
    18471847            if ( $type === $shortcode[2] ) {
    1848                 $srcs = array();
    18491848                $count = 1;
    18501849                if ( $remove )
    1851                     $content = str_replace( $shortcode[0], '', $content, $count );
    1852 
    1853                 $item = do_shortcode_tag( $shortcode );
    1854                 preg_match_all( '#src=[\'"](.+?)[\'"]#is', $item, $src, PREG_SET_ORDER );
    1855                 if ( ! empty( $src ) ) {
    1856                     foreach ( $src as $s )
    1857                         $srcs[] = $s[1];
    1858 
    1859                     $items[] = array_values( array_unique( $srcs ) );
    1860                 }
     1850                    $content =& str_replace( $shortcode[0], '', $content, $count );
     1851
     1852                $items[] = do_shortcode_tag( $shortcode );
    18611853            }
    18621854        }
    18631855    }
    1864     return $items;
     1856
     1857    if ( $html )
     1858        return $items;
     1859
     1860    $src = '';
     1861    $data = array();
     1862
     1863    foreach ( $items as $item ) {
     1864        preg_match_all( '#src=[\'"](.+?)[\'"]#is', $item, $src, PREG_SET_ORDER );
     1865        if ( ! empty( $src ) ) {
     1866            $srcs = array();
     1867            foreach ( $src as $s )
     1868                $srcs[] = $s[1];
     1869
     1870            $data[] = array_values( array_unique( $srcs ) );
     1871        }
     1872    }
     1873
     1874    return $data;
    18651875}
    18661876
     
    18711881 * @since 3.6.0
    18721882 *
     1883 * @param string $type Type of media: audio or video
    18731884 * @param string $content A string which might contain media data.
    18741885 * @param boolean $remove Whether to remove the found URL from the passed content.
     1886 * @param int $limit Optional. The number of galleries to return
    18751887 * @return array A list of found HTML media embeds and possibly a URL by itself
    18761888 */
    1877 function get_embedded_media( $type, &$content, $remove = false ) {
     1889function get_embedded_media( $type, &$content, $remove = false, $limit = 0 ) {
    18781890    $html = array();
    18791891    $matches = '';
     
    18851897                $content = str_replace( $matches[0], '', $content );
    18861898
    1887             return $html;
    1888         }
    1889     }
     1899            if ( $limit > 0 && count( $html ) >= $limit )
     1900                break;
     1901        }
     1902    }
     1903
     1904    if ( ! empty( $html ) && count( $html ) >= $limit )
     1905        return $html;
    18901906
    18911907    $lines = explode( "\n", trim( $content ) );
    18921908    $line = trim( array_shift( $lines  ) );
    1893 
    18941909    if ( 0 === stripos( $line, 'http' ) ) {
    18951910        if ( $remove )
     
    19021917
    19031918/**
    1904  * Extract the srcs from the post's [audio] <source>s
     1919 * Extract the HTML or <source> srcs from the content's [audio]
    19051920 *
    19061921 * @since 3.6.0
    19071922 *
    19081923 * @param string $content A string which might contain audio data.
     1924 * @param boolean $html Whether to return HTML or URLs
    19091925 * @param boolean $remove Whether to remove the found URL from the passed content.
    1910  * @return array A list of lists. Each item has a list of sources corresponding
    1911  *      to a [audio]'s primary src and specified fallbacks
    1912  */
    1913 function get_content_audio( &$content, $remove = false ) {
    1914     return get_content_media( 'audio', $content, $remove );
     1926 * @return array A list of lists. Each item has a list of HTML or srcs corresponding
     1927 *      to an [audio]'s HTML or primary src and specified fallbacks
     1928 */
     1929function get_content_audio( &$content, $html = true, $remove = false ) {
     1930    return get_content_media( 'audio', $content, $html, $remove );
    19151931}
    19161932
     
    19301946
    19311947/**
    1932  * Extract the srcs from the post's [video] <source>s
     1948 * Extract the HTML or <source> srcs from the content's [video]
    19331949 *
    19341950 * @since 3.6.0
    19351951 *
    19361952 * @param string $content A string which might contain video data.
     1953 * @param boolean $html Whether to return HTML or URLs
    19371954 * @param boolean $remove Whether to remove the found URL from the passed content.
    1938  * @return array A list of lists. Each item has a list of sources corresponding
    1939  *      to a [video]'s primary src and specified fallbacks
    1940  */
    1941 function get_content_video( &$content, $remove = false ) {
    1942     return get_content_media( 'video', $content, $remove );
     1955 * @return array A list of lists. Each item has a list of HTML or srcs corresponding
     1956 *      to a [video]'s HTML or primary src and specified fallbacks
     1957 */
     1958function get_content_video( &$content, $html = true, $remove = false ) {
     1959    return get_content_media( 'video', $content, $html, $remove );
    19431960}
    19441961
     
    20022019
    20032020/**
     2021 * Return suitable HTML code for output based on the content related to the global $post
     2022 * If found, remove the content from the @global $post's post_content field
     2023 *
     2024 * @since 3.6.0
     2025 *
     2026 * @param string $type Required. 'audio' or 'video'
     2027 * @param WP_Post $post Optional. Used instead of global $post when passed.
     2028 * @return string
     2029 */
     2030function get_the_media( $type, &$post = null ) {
     2031    global $wp_embed;
     2032
     2033    if ( empty( $post ) )
     2034        $post =& get_post();
     2035
     2036    if ( empty( $post ) )
     2037        return '';
     2038
     2039    if ( isset( $post->format_content ) )
     2040        return $post->format_content;
     2041
     2042    $count = 1;
     2043
     2044    if ( has_post_format( $type ) ) {
     2045        $meta = get_post_format_meta( $post->ID );
     2046        if ( ! empty( $meta['media'] ) ) {
     2047            if ( is_numeric( $meta['media'] ) ) {
     2048                $url = wp_get_attachment_url( $meta['media'] );
     2049                $shortcode = sprintf( '[%s src="%s"]', $type, $url );
     2050            } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $meta['media'] ) ) {
     2051                $shortcode = $meta['media'];
     2052            } elseif ( preg_match( '#<[^>]+>#', $meta['media'] ) ) {
     2053                $post->format_content = $meta['media'];
     2054                return $post->format_content;
     2055            } elseif ( 0 === strpos( $meta['media'], 'http' ) ) {
     2056                $post->split_content = str_replace( $meta['media'], '', $post->post_content, $count );
     2057                if ( strstr( $meta['media'], home_url() ) ) {
     2058                    $shortcode = sprintf( '[%s src="%s"]', $type, $meta['media'] );
     2059                } else {
     2060                    $post->format_content = $wp_embed->autoembed( $meta['media'] );
     2061                    return $post->format_content;
     2062                }
     2063            }
     2064
     2065            if ( ! empty( $shortcode ) ) {
     2066                $post->format_content = do_shortcode( $shortcode );
     2067                return $post->format_content;
     2068            }
     2069        }
     2070    }
     2071
     2072    $medias = call_user_func( 'get_attached_' . $type );
     2073    if ( ! empty( $medias ) ) {
     2074        $media = reset( $medias );
     2075        $url = wp_get_attachment_url( $media->ID );
     2076        $shortcode = sprintf( '[%s src="%s"]', $type, $url );
     2077        $post->format_content = do_shortcode( $shortcode );
     2078        return $post->format_content;
     2079    }
     2080
     2081    // these functions expected a reference, not a value
     2082    $_content = $post->post_content;
     2083    $content =& $_content;
     2084
     2085    $htmls = get_content_media( $type, $content, true, true );
     2086    if ( ! empty( $htmls ) ) {
     2087        $html = reset( $htmls );
     2088        $post->split_content = $content;
     2089        $post->format_content = $html;
     2090        return $post->format_content;
     2091    }
     2092
     2093    $embeds = get_embedded_media( $type, $content, true, 1 );
     2094    if ( ! empty( $embeds ) ) {
     2095        $embed = reset( $embeds );
     2096        $post->split_content = $content;
     2097        if ( 0 === strpos( $embed, 'http' ) ) {
     2098            if ( strstr( $embed, home_url() ) ) {
     2099                $post->format_content = do_shortcode( sprintf( '[%s src="%s"]', $type, $embed ) );
     2100            } else {
     2101                $post->format_content = $wp_embed->autoembed( $embed );
     2102            }
     2103        } else {
     2104            $post->format_content = $embed;
     2105        }
     2106        return $post->format_content;
     2107    }
     2108
     2109    return '';
     2110}
     2111
     2112/**
     2113 * Output the first video in the current (@global) post's content
     2114 *
     2115 * @since 3.6.0
     2116 *
     2117 */
     2118function the_video() {
     2119    echo get_the_media( 'video' );
     2120}
     2121/**
     2122 * Output the first audio  in the current (@global) post's content
     2123 *
     2124 * @since 3.6.0
     2125 *
     2126 */
     2127function the_audio() {
     2128    echo get_the_media( 'audio' );
     2129}
     2130
     2131/**
    20042132 * Retrieve images attached to the passed post
    20052133 *
     
    20342162
    20352163/**
    2036  * Check the content blob for image srcs
     2164 * Check the content blob for images or image srcs
    20372165 *
    20382166 * @since 3.6.0
    20392167 *
    20402168 * @param string $content A string which might contain image data.
     2169 * @param boolean $html Whether to return HTML or URLs
    20412170 * @param boolean $remove Whether to remove the found data from the passed content.
    20422171 * @param int $limit Optional. The number of image srcs to return
    2043  * @return array The found image srcs
    2044  */
    2045 function get_content_images( &$content, $remove = false, $limit = 0 ) {
    2046     $src = '';
    2047     $srcs = array();
     2172 * @return array The found images or srcs
     2173 */
     2174function get_content_images( &$content, $html = true, $remove = false, $limit = 0 ) {
    20482175    $matches = array();
     2176    $tags = array();
     2177    $captions = array();
    20492178
    20502179    if ( $remove && preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
    2051         $captions = array();
    20522180        foreach ( $matches as $shortcode ) {
    20532181            if ( 'caption' === $shortcode[2] )
     
    20692197            }
    20702198
    2071             preg_match( '#src=[\'"](.+?)[\'"]#is', $tag[0], $src );
    2072             if ( ! empty( $src[1] ) ) {
    2073                 $srcs[] = $src[1];
    2074                 if ( $limit > 0 && count( $srcs ) >= $limit )
    2075                     break;
    2076             }
     2199            $tags[] = $tag[0];
     2200
     2201            if ( $limit > 0 && count( $tags ) >= $limit )
     2202                break;
     2203        }
     2204    }
     2205
     2206    if ( $html )
     2207        return $tags;
     2208
     2209    $src = '';
     2210    $srcs = array();
     2211
     2212    foreach ( $tags as $tag ) {
     2213        preg_match( '#src=[\'"](.+?)[\'"]#is', $tag, $src );
     2214        if ( ! empty( $src[1] ) ) {
     2215            $srcs[] = $src[1];
     2216            if ( $limit > 0 && count( $srcs ) >= $limit )
     2217                break;
    20772218        }
    20782219    }
     
    20822223
    20832224/**
    2084  * Check the content blob for image srcs and return the first
     2225 * Check the content blob for images or srcs and return the first
    20852226 *
    20862227 * @since 3.6.0
    20872228 *
    20882229 * @param string $content A string which might contain image data.
     2230 * @param boolean $html Whether to return HTML or URLs
    20892231 * @param boolean $remove Whether to remove the found data from the passed content.
    20902232 * @return string The found data
    20912233 */
    2092 function get_content_image( &$content, $remove = false ) {
    2093     $srcs = get_content_images( $content, $remove, 1 );
     2234function get_content_image( &$content, $html = true, $remove = false ) {
     2235    $srcs = get_content_images( $content, $html, $remove, 1 );
    20942236    if ( empty( $srcs ) )
    20952237        return '';
     
    22072349    return $gallery['src'];
    22082350}
     2351
     2352/**
     2353 * Return the first image in the current (@global) post's content
     2354 *
     2355 * @since 3.6.0
     2356 *
     2357 * @param string $attached_size If an attached image is found, the size to display it.
     2358 * @param WP_Post $post Optional. Used instead of global $post when passed.
     2359 */
     2360function get_the_image( $attached_size = 'full', &$post = null ) {
     2361    if ( empty( $post ) )
     2362        $post = get_post();
     2363
     2364    if ( empty( $post ) )
     2365        return '';
     2366
     2367    if ( isset( $post->format_content ) )
     2368        return $post->format_content;
     2369
     2370    $medias = get_attached_images();
     2371    if ( ! empty( $medias ) ) {
     2372        $media = reset( $medias );
     2373        $sizes = get_intermediate_image_sizes();
     2374
     2375        $urls = array();
     2376        foreach ( $sizes as $size ) {
     2377            $urls[] = reset( wp_get_attachment_image_src( $media->ID, $size ) );
     2378            $urls[] = get_attachment_link( $media->ID );
     2379        }
     2380
     2381        $count = 1;
     2382        $matches = array();
     2383        $content =& $post->post_content;
     2384
     2385        if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
     2386            foreach ( $matches as $shortcode ) {
     2387                if ( 'caption' === $shortcode[2] ) {
     2388                    foreach ( $urls as $url ) {
     2389                        if ( strstr( $shortcode[0], $url ) )
     2390                            $content = str_replace( $shortcode[0], '', $content, $count );
     2391                    }
     2392                }
     2393            }
     2394        }
     2395
     2396        foreach ( array( 'a', 'img' ) as $tag ) {
     2397            if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
     2398                foreach ( $matches as $match ) {
     2399                    foreach ( $urls as $url ) {
     2400                        if ( strstr( $match[0], $url ) )
     2401                            $content = str_replace( $match[0], '', $content, $count );
     2402                    }
     2403                }
     2404            }
     2405        }
     2406
     2407        $post->split_content = $content;
     2408        $post->format_content = wp_get_attachment_image( $media->ID, $attached_size );
     2409        return $post->format_content;
     2410    }
     2411
     2412    $content =& $post->post_content;
     2413    $htmls = get_content_images( $content, true, true, 1 );
     2414    if ( ! empty( $htmls ) ) {
     2415        $html = reset( $htmls );
     2416        $post->split_content = $content;
     2417        $post->format_content = $html;
     2418        return $post->format_content;
     2419    }
     2420}
     2421
     2422/**
     2423 * Output the first image in the current (@global) post's content
     2424 *
     2425 * @since 3.6.0
     2426 *
     2427 * @param string $attached_size If an attached image is found, the size to display it.
     2428 */
     2429function the_image( $attached_size = 'full' ) {
     2430    echo get_the_image( $attached_size );
     2431}
  • trunk/wp-includes/post-formats.php

    r23804 r23819  
    679679    echo esc_url( get_the_url() );
    680680}
     681
     682/**
     683 * Retrieve the post content, minus the extracted post format content
     684 *
     685 * @since 3.6.0
     686 *
     687 * @internal there is a lot of code that could be abstracted from get_the_content()
     688 *
     689 * @param string $more_link_text Optional. Content for when there is more text.
     690 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
     691 * @return string
     692 */
     693function get_the_extra_content( $more_link_text = null, $strip_teaser = false ) {
     694    global $more, $page, $format_pages, $multipage, $preview;
     695
     696    $post = get_post();
     697
     698    if ( null === $more_link_text )
     699        $more_link_text = __( '(more...)' );
     700
     701    $output = '';
     702    $has_teaser = false;
     703    $matches = array();
     704
     705    // If post password required and it doesn't match the cookie.
     706    if ( post_password_required() )
     707        return get_the_password_form();
     708
     709    if ( $page > count( $format_pages ) ) // if the requested page doesn't exist
     710        $page = count( $format_pages ); // give them the highest numbered page that DOES exist
     711
     712    $content = $format_pages[$page-1];
     713    if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
     714        $content = explode( $matches[0], $content, 2 );
     715        if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
     716            $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
     717
     718        $has_teaser = true;
     719    } else {
     720        $content = array( $content );
     721    }
     722
     723    if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )
     724        $strip_teaser = true;
     725
     726    $teaser = $content[0];
     727
     728    if ( $more && $strip_teaser && $has_teaser )
     729        $teaser = '';
     730
     731    $output .= $teaser;
     732
     733    if ( count( $content ) > 1 ) {
     734        if ( $more ) {
     735            $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
     736        } else {
     737            if ( ! empty( $more_link_text ) )
     738                $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
     739
     740            $output = force_balance_tags( $output );
     741        }
     742    }
     743
     744    if ( $preview ) // preview fix for javascript bug with foreign languages
     745        $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
     746
     747    return $output;
     748}
     749
     750/**
     751 * Display the post content minus the parsed post format data.
     752 *
     753 * @since 3.6.0
     754 *
     755 * @param string $more_link_text Optional. Content for when there is more text.
     756 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
     757 */
     758function the_extra_content( $more_link_text = null, $strip_teaser = false ) {
     759    $extra = get_the_extra_content( $more_link_text, $strip_teaser );
     760
     761    remove_filter( 'the_content', 'post_formats_compat', 7 );
     762    $content = apply_filters( 'the_content', $extra );
     763    add_filter( 'the_content', 'post_formats_compat', 7 );
     764
     765    echo str_replace( ']]>', ']]&gt;', $content );
     766}
  • trunk/wp-includes/post-template.php

    r23769 r23819  
    160160 *
    161161 * @param string $more_link_text Optional. Content for when there is more text.
    162  * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
    163  */
    164 function the_content($more_link_text = null, $stripteaser = false) {
    165     $content = get_the_content($more_link_text, $stripteaser);
    166     $content = apply_filters('the_content', $content);
    167     $content = str_replace(']]>', ']]&gt;', $content);
    168     echo $content;
     162 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
     163 */
     164function the_content( $more_link_text = null, $strip_teaser = false ) {
     165    $content = apply_filters( 'the_content', get_the_content( $more_link_text, $strip_teaser ) );
     166    echo str_replace( ']]>', ']]&gt;', $content );
    169167}
    170168
     
    178176 * @return string
    179177 */
    180 function get_the_content( $more_link_text = null, $stripteaser = false ) {
     178function get_the_content( $more_link_text = null, $strip_teaser = false ) {
    181179    global $more, $page, $pages, $multipage, $preview;
    182180
     
    187185
    188186    $output = '';
    189     $hasTeaser = false;
     187    $has_teaser = false;
     188    $matches = array();
    190189
    191190    // If post password required and it doesn't match the cookie.
     
    193192        return get_the_password_form();
    194193
    195     if ( $page > count($pages) ) // if the requested page doesn't exist
    196         $page = count($pages); // give them the highest numbered page that DOES exist
    197 
    198     $content = $pages[$page-1];
    199     if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
    200         $content = explode($matches[0], $content, 2);
    201         if ( !empty($matches[1]) && !empty($more_link_text) )
    202             $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
    203 
    204         $hasTeaser = true;
     194    if ( $page > count( $pages ) ) // if the requested page doesn't exist
     195        $page = count( $pages ); // give them the highest numbered page that DOES exist
     196
     197    $content = $pages[$page - 1];
     198    if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
     199        $content = explode( $matches[0], $content, 2 );
     200        if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
     201            $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
     202
     203        $has_teaser = true;
    205204    } else {
    206         $content = array($content);
    207     }
    208     if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
    209         $stripteaser = true;
     205        $content = array( $content );
     206    }
     207
     208    if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )
     209        $strip_teaser = true;
     210
    210211    $teaser = $content[0];
    211     if ( $more && $stripteaser && $hasTeaser )
     212
     213    if ( $more && $strip_teaser && $has_teaser )
    212214        $teaser = '';
     215
    213216    $output .= $teaser;
    214     if ( count($content) > 1 ) {
     217
     218    if ( count( $content ) > 1 ) {
    215219        if ( $more ) {
    216220            $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
    217221        } else {
    218             if ( ! empty($more_link_text) )
     222            if ( ! empty( $more_link_text ) )
    219223                $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
    220             $output = force_balance_tags($output);
     224            $output = force_balance_tags( $output );
    221225        }
    222 
    223     }
     226    }
     227
    224228    if ( $preview ) // preview fix for javascript bug with foreign languages
    225         $output =   preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output);
     229        $output =   preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
    226230
    227231    return $output;
  • trunk/wp-includes/query.php

    r23804 r23819  
    36783678 */
    36793679function setup_postdata($post) {
    3680     global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
     3680    global $id, $authordata, $currentday, $currentmonth, $page, $pages, $format_pages, $multipage, $more, $numpages;
    36813681
    36823682    $id = (int) $post->ID;
     
    36923692    if ( is_single() || is_page() || is_feed() )
    36933693        $more = 1;
    3694     $content = $post->post_content;
     3694    $split_content = $content = $post->post_content;
     3695    $format = get_post_format( $post );
     3696    if ( $format && in_array( $format, array( 'image', 'audio', 'video' ) ) ) {
     3697        switch ( $format ) {
     3698        case 'image':
     3699            get_the_image( 'full', $post );
     3700            if ( isset( $post->split_content ) )
     3701                $split_content = $post->split_content;
     3702            break;
     3703        case 'audio':
     3704            get_the_media( 'audio', $post );
     3705            if ( isset( $post->split_content ) )
     3706                $split_content = $post->split_content;
     3707            break;
     3708        case 'video':
     3709            get_the_media( 'video', $post );
     3710            if ( isset( $post->split_content ) )
     3711                $split_content = $post->split_content;
     3712            break;
     3713        }
     3714    }
     3715
    36953716    if ( strpos( $content, '<!--nextpage-->' ) ) {
    36963717        if ( $page > 1 )
    36973718            $more = 1;
    36983719        $multipage = 1;
    3699         $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
    3700         $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
    3701         $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
    3702         $pages = explode('<!--nextpage-->', $content);
    3703         $numpages = count($pages);
     3720        $pages = paginate_content( $content );
     3721        $format_pages = paginate_content( $split_content );
     3722        $numpages = count( $pages );
    37043723    } else {
    37053724        $pages = array( $post->post_content );
     3725        $format_pages = array( $split_content );
    37063726        $multipage = 0;
    37073727    }
Note: See TracChangeset for help on using the changeset viewer.