Ticket #23572: 23572-html.8.diff
File 23572-html.8.diff, 19.4 KB (added by , 11 years ago) |
---|
-
wp-includes/media.php
function wp_audio_shortcode( $attr ) { 887 887 } 888 888 889 889 $library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ); 890 if ( 'mediaelement' === $library ) {890 if ( 'mediaelement' === $library && did_action( 'init' ) ) { 891 891 wp_enqueue_style( 'wp-mediaelement' ); 892 892 wp_enqueue_script( 'wp-mediaelement' ); 893 893 } … … function wp_video_shortcode( $attr ) { 994 994 } 995 995 996 996 $library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' ); 997 if ( 'mediaelement' === $library ) {997 if ( 'mediaelement' === $library && did_action( 'init' ) ) { 998 998 wp_enqueue_style( 'wp-mediaelement' ); 999 999 wp_enqueue_script( 'wp-mediaelement' ); 1000 1000 } … … function get_attached_video( $post_id = 0 ) { 1828 1828 } 1829 1829 1830 1830 /** 1831 * Extract the srcs from the post's [{media type}] <source>s1831 * Extract and parse {media type} shortcodes or srcs from the passed content 1832 1832 * 1833 1833 * @since 3.6.0 1834 1834 * 1835 * @param string $type Type of media: audio or video 1835 1836 * @param string $content A string which might contain media data. 1837 * @param boolean $html Whether to return HTML or URLs 1836 1838 * @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 * @return array A list of parsed shortcodes or extracted srcs 1839 1840 */ 1840 function get_content_media( $type, &$content, $remove = false ) { 1841 $src = ''; 1841 function get_content_media( $type, &$content, $html = true, $remove = false ) { 1842 1842 $items = array(); 1843 1843 $matches = array(); 1844 1844 1845 1845 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 1846 1846 foreach ( $matches as $shortcode ) { 1847 1847 if ( $type === $shortcode[2] ) { 1848 $srcs = array();1849 1848 $count = 1; 1850 1849 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]; 1850 $content =& str_replace( $shortcode[0], '', $content, $count ); 1858 1851 1859 $items[] = array_values( array_unique( $srcs ) ); 1860 } 1852 $items[] = do_shortcode_tag( $shortcode ); 1861 1853 } 1862 1854 } 1863 1855 } 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; 1865 1875 } 1866 1876 1867 1877 /** … … function get_content_media( $type, &$content, $remove = false ) { 1870 1880 * 1871 1881 * @since 3.6.0 1872 1882 * 1883 * @param string $type Type of media: audio or video 1873 1884 * @param string $content A string which might contain media data. 1874 1885 * @param boolean $remove Whether to remove the found URL from the passed content. 1886 * @param int $limit Optional. The number of galleries to return 1875 1887 * @return array A list of found HTML media embeds and possibly a URL by itself 1876 1888 */ 1877 function get_embedded_media( $type, &$content, $remove = false ) {1889 function get_embedded_media( $type, &$content, $remove = false, $limit = 0 ) { 1878 1890 $html = array(); 1879 1891 $matches = ''; 1880 1892 … … function get_embedded_media( $type, &$content, $remove = false ) { 1884 1896 if ( $remove ) 1885 1897 $content = str_replace( $matches[0], '', $content ); 1886 1898 1887 return $html; 1899 if ( $limit > 0 && count( $html ) >= $limit ) 1900 break; 1888 1901 } 1889 1902 } 1890 1903 1904 if ( ! empty( $html ) && count( $html ) >= $limit ) 1905 return $html; 1906 1891 1907 $lines = explode( "\n", trim( $content ) ); 1892 1908 $line = trim( array_shift( $lines ) ); 1893 1909 … … function get_embedded_media( $type, &$content, $remove = false ) { 1901 1917 } 1902 1918 1903 1919 /** 1904 * Extract the srcs from the post's [audio] <source>s1920 * Extract the HTML or <source> srcs from the content's [audio] 1905 1921 * 1906 1922 * @since 3.6.0 1907 1923 * 1908 1924 * @param string $content A string which might contain audio data. 1925 * @param boolean $html Whether to return HTML or URLs 1909 1926 * @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 corresponding1911 * to a [audio]'sprimary src and specified fallbacks1927 * @return array A list of lists. Each item has a list of HTML or srcs corresponding 1928 * to an [audio]'s HTML or primary src and specified fallbacks 1912 1929 */ 1913 function get_content_audio( &$content, $ remove = false ) {1914 return get_content_media( 'audio', $content, $ remove );1930 function get_content_audio( &$content, $html = true, $remove = false ) { 1931 return get_content_media( 'audio', $content, $html, $remove ); 1915 1932 } 1916 1933 1917 1934 /** … … function get_embedded_audio( &$content, $remove = false ) { 1929 1946 } 1930 1947 1931 1948 /** 1932 * Extract the srcs from the post's [video] <source>s1949 * Extract the HTML or <source> srcs from the content's [video] 1933 1950 * 1934 1951 * @since 3.6.0 1935 1952 * 1936 1953 * @param string $content A string which might contain video data. 1954 * @param boolean $html Whether to return HTML or URLs 1937 1955 * @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 corresponding1939 * to a [video]'s primary src and specified fallbacks1956 * @return array A list of lists. Each item has a list of HTML or srcs corresponding 1957 * to a [video]'s HTML or primary src and specified fallbacks 1940 1958 */ 1941 function get_content_video( &$content, $ remove = false ) {1942 return get_content_media( 'video', $content, $ remove );1959 function get_content_video( &$content, $html = true, $remove = false ) { 1960 return get_content_media( 'video', $content, $html, $remove ); 1943 1961 } 1944 1962 1945 1963 /** … … function wp_video_embed( $matches, $attr, $url, $rawattr ) { 2001 2019 wp_embed_register_handler( 'wp_video_embed', '#https?://.+?\.(' . join( '|', wp_get_video_extensions() ) . ')#i', apply_filters( 'wp_video_embed_handler', 'wp_video_embed' ), 9999 ); 2002 2020 2003 2021 /** 2022 * Return suitable HTML code for output based on the content related to the global $post 2023 * If found, remove the content from the @global $post's post_content field 2024 * 2025 * @since 3.6.0 2026 * 2027 * @param string $type Required. 'audio' or 'video' 2028 * @param WP_Post $post Optional. Used instead of global $post when passed. 2029 * @return string 2030 */ 2031 function get_the_media( $type, &$post = null ) { 2032 if ( empty( $post ) ) 2033 $post = get_post(); 2034 2035 if ( empty( $post ) ) 2036 return ''; 2037 2038 if ( isset( $post->format_content ) ) 2039 return $post->format_content; 2040 2041 $count = 1; 2042 2043 if ( has_post_format( $type ) ) { 2044 $meta = get_post_format_meta( $post->ID ); 2045 if ( ! empty( $meta['media'] ) ) { 2046 if ( is_numeric( $meta['media'] ) ) { 2047 $url = wp_get_attachment_url( $meta['media'] ); 2048 $shortcode = sprintf( '[%s src="%s"]', $type, $url ); 2049 } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $meta['media'] ) ) { 2050 $shortcode = $meta['media']; 2051 } elseif ( preg_match( '#<[^>]+>#', $meta['media'] ) ) { 2052 $post->format_content = $meta['media']; 2053 return $post->format_content; 2054 } elseif ( 0 === strpos( $meta['media'], 'http' ) ) { 2055 $post->split_content = str_replace( $meta['media'], '', $post->post_content, $count ); 2056 $shortcode = sprintf( '[%s src="%s"]', $type, $meta['media'] ); 2057 } 2058 2059 if ( ! empty( $shortcode ) ) { 2060 $post->format_content = do_shortcode( $shortcode ); 2061 return $post->format_content; 2062 } 2063 } 2064 } 2065 2066 $medias = call_user_func( 'get_attached_' . $type ); 2067 if ( ! empty( $medias ) ) { 2068 $media = reset( $medias ); 2069 $url = wp_get_attachment_url( $media->ID ); 2070 $shortcode = sprintf( '[%s src="%s"]', $type, $url ); 2071 $post->format_content = do_shortcode( $shortcode ); 2072 return $post->format_content; 2073 } 2074 2075 // these functions expected a reference, not a value 2076 $content =& $post->post_content; 2077 2078 $htmls = get_content_media( $type, $content, true, true ); 2079 if ( ! empty( $htmls ) ) { 2080 $html = reset( $htmls ); 2081 $post->split_content = $content; 2082 $post->format_content = $html; 2083 return $post->format_content; 2084 } 2085 2086 $embeds = get_embedded_media( $type, $content, true, 1 ); 2087 if ( ! empty( $embeds ) ) { 2088 $embed = reset( $embeds ); 2089 $post->split_content = $content; 2090 if ( 0 === strpos( $embed, 'http' ) ) { 2091 $shortcode = sprintf( '[%s src="%s"]', $type, $embed ); 2092 $post->format_content = do_shortcode( $shortcode ); 2093 return $post->format_content; 2094 } else { 2095 $post->format_content = $embed; 2096 return $post->format_content; 2097 } 2098 } 2099 2100 return ''; 2101 } 2102 2103 /** 2104 * Output the first video in the current (@global) post's content 2105 * 2106 * @since 3.6.0 2107 * 2108 */ 2109 function the_video() { 2110 echo get_the_media( 'video' ); 2111 } 2112 /** 2113 * Output the first audio in the current (@global) post's content 2114 * 2115 * @since 3.6.0 2116 * 2117 */ 2118 function the_audio() { 2119 echo get_the_media( 'audio' ); 2120 } 2121 2122 /** 2004 2123 * Retrieve images attached to the passed post 2005 2124 * 2006 2125 * @since 3.6.0 … … function get_attached_image_srcs( $post_id = 0 ) { 2033 2152 } 2034 2153 2035 2154 /** 2036 * Check the content blob for image srcs2155 * Check the content blob for images or image srcs 2037 2156 * 2038 2157 * @since 3.6.0 2039 2158 * 2040 2159 * @param string $content A string which might contain image data. 2160 * @param boolean $html Whether to return HTML or URLs 2041 2161 * @param boolean $remove Whether to remove the found data from the passed content. 2042 2162 * @param int $limit Optional. The number of image srcs to return 2043 * @return array The found image srcs2163 * @return array The found images or srcs 2044 2164 */ 2045 function get_content_images( &$content, $remove = false, $limit = 0 ) { 2046 $src = ''; 2047 $srcs = array(); 2165 function get_content_images( &$content, $html = true, $remove = false, $limit = 0 ) { 2048 2166 $matches = array(); 2167 $tags = array(); 2168 $captions = array(); 2049 2169 2050 2170 if ( $remove && preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 2051 $captions = array();2052 2171 foreach ( $matches as $shortcode ) { 2053 2172 if ( 'caption' === $shortcode[2] ) 2054 2173 $captions[] = $shortcode[0]; … … function get_content_images( &$content, $remove = false, $limit = 0 ) { 2068 2187 $content = str_replace( $tag[0], '', $content, $count ); 2069 2188 } 2070 2189 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 } 2190 $tags[] = $tag[0]; 2191 2192 if ( $limit > 0 && count( $tags ) >= $limit ) 2193 break; 2194 } 2195 } 2196 2197 if ( $html ) 2198 return $tags; 2199 2200 $src = ''; 2201 $srcs = array(); 2202 2203 foreach ( $tags as $tag ) { 2204 preg_match( '#src=[\'"](.+?)[\'"]#is', $tag, $src ); 2205 if ( ! empty( $src[1] ) ) { 2206 $srcs[] = $src[1]; 2207 if ( $limit > 0 && count( $srcs ) >= $limit ) 2208 break; 2077 2209 } 2078 2210 } 2079 2211 … … function get_content_images( &$content, $remove = false, $limit = 0 ) { 2081 2213 } 2082 2214 2083 2215 /** 2084 * Check the content blob for image srcs and return the first2216 * Check the content blob for images or srcs and return the first 2085 2217 * 2086 2218 * @since 3.6.0 2087 2219 * 2088 2220 * @param string $content A string which might contain image data. 2221 * @param boolean $html Whether to return HTML or URLs 2089 2222 * @param boolean $remove Whether to remove the found data from the passed content. 2090 2223 * @return string The found data 2091 2224 */ 2092 function get_content_image( &$content, $ remove = false ) {2093 $srcs = get_content_images( $content, $ remove, 1 );2225 function get_content_image( &$content, $html = true, $remove = false ) { 2226 $srcs = get_content_images( $content, $html, $remove, 1 ); 2094 2227 if ( empty( $srcs ) ) 2095 2228 return ''; 2096 2229 … … function get_post_gallery_images( $post_id = 0 ) { 2205 2338 return array(); 2206 2339 2207 2340 return $gallery['src']; 2341 } 2342 2343 /** 2344 * Return the first image in the current (@global) post's content 2345 * 2346 * @since 3.6.0 2347 * 2348 * @param string $attached_size If an attached image is found, the size to display it. 2349 * @param WP_Post $post Optional. Used instead of global $post when passed. 2350 */ 2351 function get_the_image( $attached_size = 'full', &$post = null ) { 2352 if ( empty( $post ) ) 2353 $post = get_post(); 2354 2355 if ( empty( $post ) ) 2356 return ''; 2357 2358 if ( isset( $post->format_content ) ) 2359 return $post->format_content; 2360 2361 $medias = get_attached_images(); 2362 if ( ! empty( $medias ) ) { 2363 $media = reset( $medias ); 2364 $sizes = get_intermediate_image_sizes(); 2365 2366 $urls = array(); 2367 foreach ( $sizes as $size ) { 2368 $urls[] = reset( wp_get_attachment_image_src( $media->ID, $size ) ); 2369 $urls[] = get_attachment_link( $media->ID ); 2370 } 2371 2372 $count = 1; 2373 $matches = array(); 2374 $content =& $post->post_content; 2375 2376 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 2377 foreach ( $matches as $shortcode ) { 2378 if ( 'caption' === $shortcode[2] ) { 2379 foreach ( $urls as $url ) { 2380 if ( strstr( $shortcode[0], $url ) ) 2381 $content = str_replace( $shortcode[0], '', $content, $count ); 2382 } 2383 } 2384 } 2385 } 2386 2387 foreach ( array( 'a', 'img' ) as $tag ) { 2388 if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 2389 foreach ( $matches as $match ) { 2390 foreach ( $urls as $url ) { 2391 if ( strstr( $match[0], $url ) ) 2392 $content = str_replace( $match[0], '', $content, $count ); 2393 } 2394 } 2395 } 2396 } 2397 2398 $post->split_content = $content; 2399 $post->format_content = wp_get_attachment_image( $media->ID, $attached_size ); 2400 return $post->format_content; 2401 } 2402 2403 $content =& $post->post_content; 2404 $htmls = get_content_images( $content, true, true, 1 ); 2405 if ( ! empty( $htmls ) ) { 2406 $html = reset( $htmls ); 2407 $post->split_content = $content; 2408 $post->format_content = $html; 2409 return $post->format_content; 2410 } 2411 } 2412 2413 /** 2414 * Output the first image in the current (@global) post's content 2415 * 2416 * @since 3.6.0 2417 * 2418 * @param string $attached_size If an attached image is found, the size to display it. 2419 */ 2420 function the_image( $attached_size = 'full' ) { 2421 echo get_the_image( $attached_size ); 2208 2422 } 2423 No newline at end of file -
wp-includes/post-formats.php
function get_the_url( $id = 0 ) { 678 678 function the_url() { 679 679 echo esc_url( get_the_url() ); 680 680 } 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 $stripteaser Optional. Strip teaser content before the more text. Default is false. 691 * @return string 692 */ 693 function get_the_extra_content( $more_link_text = null, $stripteaser = false ) { 694 global $more, $page, $pages, $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 $hasTeaser = false; 703 704 // If post password required and it doesn't match the cookie. 705 if ( post_password_required() ) 706 return get_the_password_form(); 707 708 if ( $page > count( $format_pages ) ) // if the requested page doesn't exist 709 $page = count( $format_pages ); // give them the highest numbered page that DOES exist 710 711 $content = $format_pages[$page-1]; 712 if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { 713 $content = explode( $matches[0], $content, 2 ); 714 if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) 715 $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); 716 717 $hasTeaser = true; 718 } else { 719 $content = array( $content ); 720 } 721 722 if ( ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) ) 723 $stripteaser = true; 724 725 $teaser = $content[0]; 726 727 if ( $more && $stripteaser && $hasTeaser ) 728 $teaser = ''; 729 730 $output .= $teaser; 731 732 if ( count( $content ) > 1 ) { 733 if ( $more ) { 734 $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; 735 } else { 736 if ( ! empty( $more_link_text ) ) 737 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); 738 739 $output = force_balance_tags( $output ); 740 } 741 } 742 743 if ( $preview ) // preview fix for javascript bug with foreign languages 744 $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); 745 746 return $output; 747 } 748 749 /** 750 * Display the post content minus the parsed post format data. 751 * 752 * @since 3.6.0 753 * 754 * @param string $more_link_text Optional. Content for when there is more text. 755 * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false. 756 */ 757 function the_extra_content( $more_link_text = null, $stripteaser = false ) { 758 $content = get_the_extra_content( $more_link_text, $stripteaser ); 759 remove_filter( 'the_content', 'post_formats_compat', 7 ); 760 $content = apply_filters( 'the_content', $content ); 761 add_filter( 'the_content', 'post_formats_compat', 7 ); 762 $content = str_replace( ']]>', ']]>', $content ); 763 echo $content; 764 } 765 No newline at end of file -
wp-includes/query.php
function wp_old_slug_redirect() { 3621 3621 exit; 3622 3622 endif; 3623 3623 } 3624 3624 3625 /** 3625 3626 * Split the passed content by <!--nextpage--> 3626 3627 * … … function get_paged_content( $content = null, $paged = null ) { 3677 3678 * @return bool True when finished. 3678 3679 */ 3679 3680 function setup_postdata($post) { 3680 global $id, $authordata, $currentday, $currentmonth, $page, $pages, $ multipage, $more, $numpages;3681 global $id, $authordata, $currentday, $currentmonth, $page, $pages, $format_pages, $multipage, $more, $numpages; 3681 3682 3682 3683 $id = (int) $post->ID; 3683 3684 … … function setup_postdata($post) { 3691 3692 $page = 1; 3692 3693 if ( is_single() || is_page() || is_feed() ) 3693 3694 $more = 1; 3694 $content = $post->post_content; 3695 $split_content = $content = $post->post_content; 3696 $format = get_post_format( $post ); 3697 if ( $format && in_array( $format, array( 'image', 'audio', 'video' ) ) ) { 3698 switch ( $format ) { 3699 case 'image': 3700 get_the_image( 'full', $post ); 3701 if ( isset( $post->split_content ) ) 3702 $split_content = $post->split_content; 3703 break; 3704 case 'audio': 3705 get_the_media( 'audio', $post ); 3706 if ( isset( $post->split_content ) ) 3707 $split_content = $post->split_content; 3708 break; 3709 case 'video': 3710 get_the_media( 'video', $post ); 3711 if ( isset( $post->split_content ) ) 3712 $split_content = $post->split_content; 3713 break; 3714 } 3715 } 3716 3695 3717 if ( strpos( $content, '<!--nextpage-->' ) ) { 3696 3718 if ( $page > 1 ) 3697 3719 $more = 1; 3698 3720 $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); 3721 $pages = paginate_content( $content ); 3722 $format_pages = paginate_content( $split_content ); 3723 $numpages = count( $pages ); 3704 3724 } else { 3705 3725 $pages = array( $post->post_content ); 3726 $format_pages = array( $split_content ); 3706 3727 $multipage = 0; 3707 3728 } 3708 3729