Ticket #24202: 24202.8.diff
File 24202.8.diff, 16.2 KB (added by , 11 years ago) |
---|
-
wp-includes/media.php
857 857 858 858 $default_types = wp_get_audio_extensions(); 859 859 $defaults_atts = array( 'src' => '' ); 860 foreach ( $default_types as $type 860 foreach ( $default_types as $type ) 861 861 $defaults_atts[$type] = ''; 862 862 863 863 $atts = shortcode_atts( $defaults_atts, $attr, 'audio' ); … … 963 963 'width' => empty( $content_width ) ? 640 : $content_width, 964 964 ); 965 965 966 foreach ( $default_types as $type 966 foreach ( $default_types as $type ) 967 967 $defaults_atts[$type] = ''; 968 968 969 969 $atts = shortcode_atts( $defaults_atts, $attr, 'video' ); … … 1444 1444 $args['path'] = $path; 1445 1445 1446 1446 if ( ! isset( $args['mime_type'] ) ) { 1447 $file_info 1447 $file_info = wp_check_filetype( $args['path'] ); 1448 1448 1449 1449 // If $file_info['type'] is false, then we let the editor attempt to 1450 1450 // figure out the file type, rather than forcing a failure based on extension. … … 1473 1473 * @since 3.5.0 1474 1474 * @access public 1475 1475 * 1476 * @param string|array $args Array of requirements. 1476 * @param string|array $args Array of requirements. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } 1477 1477 * @return boolean true if an eligible editor is found; false otherwise 1478 1478 */ 1479 1479 function wp_image_editor_supports( $args = array() ) { … … 1842 1842 * @since 3.6.0 1843 1843 * 1844 1844 * @param string $type (Mime) type of media desired 1845 * @param int $post_id Post ID1845 * @param mixed $post Post ID or object 1846 1846 * @return array Found attachments 1847 1847 */ 1848 function get_attached_media( $type, $post _id= 0 ) {1849 if ( ! $post = get_post( $post _id) )1850 return ;1848 function get_attached_media( $type, $post = 0 ) { 1849 if ( ! $post = get_post( $post ) ) 1850 return array(); 1851 1851 1852 1852 $args = array( 1853 1853 'post_parent' => $post->ID, … … 1866 1866 } 1867 1867 1868 1868 /** 1869 * Extract and parse {media type} shortcodes or srcs from the passed content1869 * Check the content blob for an <audio>, <video> <object>, <embed>, or <iframe> 1870 1870 * 1871 1871 * @since 3.6.0 1872 1872 * 1873 * @param string $type Type of media: audio or video1874 1873 * @param string $content A string which might contain media data. 1875 * @param boolean $html Whether to return HTML or URLs 1876 * @param int $limit Optional. The number of medias to return 1877 * @return array A list of parsed shortcodes or extracted srcs 1874 * @param array $types array of media types: 'audio', 'video', 'object', 'embed', or 'iframe' 1875 * @return array A list of found HTML media embeds 1878 1876 */ 1879 function get_content_media( $type, $content, $html = true, $limit = 0 ) { 1880 $items = array(); 1877 function get_media_embedded_in_content( $content, $types = null ) { 1878 $html = array(); 1879 $allowed_media_types = array( 'audio', 'video', 'object', 'embed', 'iframe' ); 1881 1880 1882 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 1883 foreach ( $matches as $shortcode ) { 1884 if ( $type === $shortcode[2] ) { 1885 $count = 1; 1886 1887 $items[] = do_shortcode_tag( $shortcode ); 1888 if ( $limit > 0 && count( $items ) >= $limit ) 1889 break; 1890 } 1891 } 1881 if ( ! empty( $types ) ) { 1882 if ( ! is_array( $types ) ) 1883 $types = array( $types ); 1884 $allowed_media_types = array_intersect( $allowed_media_types, $types ); 1892 1885 } 1893 1886 1894 if ( $html ) 1895 return $items; 1896 1897 $data = array(); 1898 1899 foreach ( $items as $item ) { 1900 preg_match_all( '#src=([\'"])(.+?)\1#is', $item, $src, PREG_SET_ORDER ); 1901 if ( ! empty( $src ) ) { 1902 $srcs = array(); 1903 foreach ( $src as $s ) 1904 $srcs[] = $s[2]; 1905 1906 $data[] = array_values( array_unique( $srcs ) ); 1907 } 1908 } 1909 1910 return $data; 1911 } 1912 1913 /** 1914 * Check the content blob for an <{media type}>, <object>, <embed>, or <iframe>, in that order 1915 * If no HTML tag is found, check the first line of the post for a URL 1916 * 1917 * @since 3.6.0 1918 * 1919 * @param string $type Type of media: audio or video 1920 * @param string $content A string which might contain media data. 1921 * @param int $limit Optional. The number of galleries to return 1922 * @return array A list of found HTML media embeds and possibly a URL by itself 1923 */ 1924 function get_embedded_media( $type, $content, $limit = 0 ) { 1925 $html = array(); 1926 1927 foreach ( array( $type, 'object', 'embed', 'iframe' ) as $tag ) { 1887 foreach ( $allowed_media_types as $tag ) { 1928 1888 if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) { 1929 1889 $html[] = $matches[0]; 1930 1931 if ( $limit > 0 && count( $html ) >= $limit )1932 break;1933 1890 } 1934 1891 } 1935 1892 1936 if ( ! empty( $html ) && count( $html ) >= $limit )1937 return $html;1938 1939 $lines = explode( "\n", trim( $content ) );1940 $line = trim( array_shift( $lines ) );1941 if ( 0 === stripos( $line, 'http' ) ) {1942 $html[] = $line;1943 }1944 1893 return $html; 1945 1894 } 1946 1895 1947 1896 /** 1948 * Extract the HTML or <source> srcs from the content's [audio]1949 *1950 * @since 3.6.01951 *1952 * @param string $content A string which might contain audio data.1953 * @param boolean $html Whether to return HTML or URLs1954 * @return array A list of lists. Each item has a list of HTML or srcs corresponding1955 * to an [audio]'s HTML or primary src and specified fallbacks1956 */1957 function get_content_audio( $content, $html = true ) {1958 return get_content_media( 'audio', $content, $html );1959 }1960 1961 /**1962 * Check the content blob for an <audio>, <object>, <embed>, or <iframe>, in that order1963 * If no HTML tag is found, check the first line of the post for a URL1964 *1965 * @since 3.6.01966 *1967 * @param string $content A string which might contain audio data.1968 * @return array A list of found HTML audio embeds and possibly a URL by itself1969 */1970 function get_embedded_audio( $content ) {1971 return get_embedded_media( 'audio', $content );1972 }1973 1974 /**1975 * Extract the HTML or <source> srcs from the content's [video]1976 *1977 * @since 3.6.01978 *1979 * @param string $content A string which might contain video data.1980 * @param boolean $html Whether to return HTML or URLs1981 * @return array A list of lists. Each item has a list of HTML or srcs corresponding1982 * to a [video]'s HTML or primary src and specified fallbacks1983 */1984 function get_content_video( $content, $html = true ) {1985 return get_content_media( 'video', $content, $html );1986 }1987 1988 /**1989 * Check the content blob for a <video>, <object>, <embed>, or <iframe>, in that order1990 * If no HTML tag is found, check the first line of the post for a URL1991 *1992 * @since 3.6.01993 *1994 * @param string $content A string which might contain video data.1995 * @return array A list of found HTML video embeds and possibly a URL by itself1996 */1997 function get_embedded_video( $content ) {1998 return get_embedded_media( 'video', $content );1999 }2000 2001 /**2002 * Retrieve images attached to the passed post2003 *2004 * @since 3.6.02005 *2006 * @param int $post_id Optional. Post ID.2007 * @return array Found image attachments2008 */2009 function get_attached_image_srcs( $post_id = 0 ) {2010 $children = get_attached_media( 'image', $post_id );2011 if ( empty( $children ) )2012 return array();2013 2014 $srcs = array();2015 foreach ( $children as $attachment )2016 $srcs[] = wp_get_attachment_url( $attachment->ID );2017 2018 return $srcs;2019 }2020 2021 /**2022 1897 * Check the content blob for images or image srcs 2023 1898 * 2024 1899 * @since 3.6.0 2025 1900 * 2026 1901 * @param string $content A string which might contain image data. 2027 1902 * @param boolean $html Whether to return HTML or URLs in the array 2028 * @param int $limit Optional. The number of image srcs to return2029 1903 * @return array The found images or srcs 2030 1904 */ 2031 function get_ content_images( $content, $html = true, $limit = 0) {1905 function get_images_in_content( $content, $html = true ) { 2032 1906 $tags = array(); 2033 1907 $captions = array(); 2034 1908 2035 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches )) {1909 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) ) { 2036 1910 foreach ( $matches as $shortcode ) { 2037 1911 if ( 'caption' === $shortcode[2] ) { 2038 1912 $captions[] = $shortcode[0]; 2039 1913 if ( $html ) 2040 1914 $tags[] = do_shortcode_tag( $shortcode ); 2041 1915 } 2042 2043 if ( $limit > 0 && count( $tags ) >= $limit )2044 break;2045 1916 } 2046 1917 } 2047 1918 2048 1919 foreach ( array( 'a', 'img' ) as $tag ) { 2049 if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#i', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches) ) {1920 if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#i', $content, $matches, PREG_SET_ORDER ) ) { 2050 1921 foreach ( $matches as $node ) { 2051 1922 if ( ! strstr( $node[0], '<img ' ) ) 2052 1923 continue; … … 2062 1933 2063 1934 if ( ! $found ) 2064 1935 $tags[] = $node[0]; 2065 2066 if ( $limit > 0 && count( $tags ) >= $limit )2067 break 2;2068 1936 } 2069 1937 } 2070 1938 } … … 2072 1940 if ( $html ) 2073 1941 return $tags; 2074 1942 2075 $ srcs = array();1943 $image_srcs = array(); 2076 1944 2077 1945 foreach ( $tags as $tag ) { 2078 1946 preg_match( '#src=([\'"])(.+?)\1#is', $tag, $src ); 2079 if ( ! empty( $src[2] ) ) { 2080 $srcs[] = $src[2]; 2081 if ( $limit > 0 && count( $srcs ) >= $limit ) 2082 break; 2083 } 1947 if ( ! empty( $src[2] ) ) 1948 $image_srcs[] = $src[2]; 2084 1949 } 2085 1950 2086 return apply_filters( 'content_images', array_values( array_unique( $srcs ) ), $content ); 1951 $image_srcs = array_values( array_unique( $image_srcs ) ); 1952 return apply_filters( 'get_images_in_content', $image_srcs, $content ); 2087 1953 } 2088 1954 2089 1955 /** … … 2095 1961 * @param boolean $html Whether to return HTML or URLs 2096 1962 * @return string The found data 2097 1963 */ 2098 function get_content_image( $content, $html = true ) { 2099 $srcs = get_content_images( $content, $html, 1 ); 2100 if ( empty( $srcs ) ) 2101 return ''; 2102 2103 return apply_filters( 'content_image', reset( $srcs ), $content ); 1964 function get_image_in_content( $content, $html = true ) { 1965 $srcs = get_images_from_content( $content, $html ); 1966 return apply_filters( 'get_image_in_content', reset( $srcs ), $content ); 2104 1967 } 2105 1968 2106 1969 /** 2107 * Check the content blob for galleries and return their image srcs1970 * Retrieve galleries from the passed post's content 2108 1971 * 2109 1972 * @since 3.6.0 2110 1973 * 2111 * @param string $content A string which might contain image data.1974 * @param mixed $post Optional. Post ID or object. 2112 1975 * @param boolean $html Whether to return HTML or data in the array 2113 * @ param int $limit Optional. The number of galleries to return2114 * @return array A list of galleries, which in turn are a list of their srcs in order1976 * @return array A list of arrays, each containing gallery data and srcs parsed 1977 * from the expanded shortcode 2115 1978 */ 2116 function get_content_galleries( $content, $html = true, $limit = 0 ) { 1979 function get_post_galleries( $post, $html = true ) { 1980 if ( ! $post = get_post( $post ) ) 1981 return array(); 1982 1983 if ( ! has_shortcode( $post->post_content, 'gallery' ) ) 1984 return array(); 1985 2117 1986 $galleries = array(); 2118 2119 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 1987 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) { 2120 1988 foreach ( $matches as $shortcode ) { 2121 1989 if ( 'gallery' === $shortcode[2] ) { 2122 1990 $srcs = array(); 2123 1991 $count = 1; 2124 1992 2125 $data = shortcode_parse_atts( $shortcode[3] );2126 1993 $gallery = do_shortcode_tag( $shortcode ); 2127 1994 if ( $html ) { 2128 1995 $galleries[] = $gallery; … … 2133 2000 $srcs[] = $s[2]; 2134 2001 } 2135 2002 2003 $data = shortcode_parse_atts( $shortcode[3] ); 2136 2004 $data['src'] = array_values( array_unique( $srcs ) ); 2137 2005 $galleries[] = $data; 2138 2006 } 2139 2140 if ( $limit > 0 && count( $galleries ) >= $limit )2141 break;2142 2007 } 2143 2008 } 2144 2009 } 2145 2010 2146 return apply_filters( ' content_galleries', $galleries, $content );2011 return apply_filters( 'get_post_galleries', $galleries, $post ); 2147 2012 } 2148 2013 2149 2014 /** 2150 * Retrieve galleries from the passed post's content2015 * Check a specified post's content for gallery and, if present, return the first 2151 2016 * 2152 2017 * @since 3.6.0 2153 2018 * 2154 * @param int $post_id Optional. Post ID. 2155 * @param boolean $html Whether to return HTML or data in the array 2156 * @return array A list of arrays, each containing gallery data and srcs parsed 2157 * from the expanded shortcode 2019 * @param mixed $post Optional. Post ID or object. 2020 * @param boolean $html Whether to return HTML or data 2021 * @return string|array Gallery data and srcs parsed from the expanded shortcode 2158 2022 */ 2159 function get_post_galler ies( $post_id= 0, $html = true ) {2160 if ( ! $post = get_post( $post_id ) )2161 return array();2023 function get_post_gallery( $post = 0, $html = true ) { 2024 $galleries = get_post_galleries( $post, $html ); 2025 $gallery = reset( $galleries ); 2162 2026 2163 if ( ! has_shortcode( $post->post_content, 'gallery' ) ) 2164 return array(); 2165 2166 return get_content_galleries( $post->post_content, $html ); 2027 return apply_filters( 'get_post_gallery', $gallery, $post, $galleries ); 2167 2028 } 2168 2029 2169 2030 /** … … 2171 2032 * 2172 2033 * @since 3.6.0 2173 2034 * 2174 * @param int $post_id Optional. Post ID.2035 * @param mixed $post Optional. Post ID or object. 2175 2036 * @return array A list of lists, each containing image srcs parsed 2176 2037 * from an expanded shortcode 2177 2038 */ 2178 function get_post_galleries_images( $post_id = 0 ) { 2179 if ( ! $post = get_post( $post_id ) ) 2180 return array(); 2181 2182 if ( ! has_shortcode( $post->post_content, 'gallery' ) ) 2183 return array(); 2184 2185 $data = get_content_galleries( $post->post_content, false ); 2186 return wp_list_pluck( $data, 'src' ); 2039 function get_post_galleries_images( $post = 0 ) { 2040 $galleries = get_post_galleries( $post, false ); 2041 return wp_list_pluck( $galleries, 'src' ); 2187 2042 } 2188 2043 2189 2044 /** 2190 * Check a specified post's content for gallery and, if present, return the first2191 *2192 * @since 3.6.02193 *2194 * @param int $post_id Optional. Post ID.2195 * @param boolean $html Whether to return HTML or data2196 * @return string|array Gallery data and srcs parsed from the expanded shortcode2197 */2198 function get_post_gallery( $post_id = 0, $html = true ) {2199 if ( ! $post = get_post( $post_id ) )2200 return $html ? '' : array();2201 2202 if ( ! has_shortcode( $post->post_content, 'gallery' ) )2203 return $html ? '' : array();2204 2205 $data = get_content_galleries( $post->post_content, $html, false, 1 );2206 return reset( $data );2207 }2208 2209 /**2210 2045 * Check a post's content for galleries and return the image srcs for the first found gallery 2211 2046 * 2212 2047 * @since 3.6.0 2213 2048 * 2214 * @param int $post_id Optional. Post ID.2049 * @param mixed $post Optional. Post ID or object. 2215 2050 * @return array A list of a gallery's image srcs in order 2216 2051 */ 2217 function get_post_gallery_images( $post_id = 0 ) { 2218 $gallery = get_post_gallery( $post_id, false ); 2219 if ( empty( $gallery['src'] ) ) 2220 return array(); 2221 2222 return $gallery['src']; 2052 function get_post_gallery_images( $post = 0 ) { 2053 $galleries = get_post_gallery( $post, false ); 2054 return empty( $gallery['src'] ) ? array() : $gallery['src']; 2223 2055 } -
wp-includes/post-formats.php
243 243 * @param string $content A string which might contain a URL. 244 244 * @return string The found URL. 245 245 */ 246 function get_ content_url( $content ) {246 function get_url_in_content( $content ) { 247 247 if ( empty( $content ) ) 248 248 return ''; 249 249 250 // the content is a URL 250 // the content is a URL in its entirety 251 251 $trimmed = trim( $content ); 252 252 if ( 0 === stripos( $trimmed, 'http' ) && ! preg_match( '#\s#', $trimmed ) ) { 253 return $trimmed;253 return esc_url_raw( $trimmed ); 254 254 255 255 // the content is HTML so we grab the first href 256 256 } elseif ( preg_match( '/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches ) ) { … … 264 264 if ( 0 === stripos( $line, 'http' ) ) 265 265 return esc_url_raw( $line ); 266 266 267 return '';267 return false; 268 268 } 269 269 270 270 /** -
wp-content/themes/twentythirteen/functions.php
484 484 /** 485 485 * Returns the URL from the post. 486 486 * 487 * @uses get_ content_url() to get the URL in the post meta (if it exists) or487 * @uses get_url_in_content() to get the URL in the post meta (if it exists) or 488 488 * the first link found in the post content. 489 489 * 490 490 * Falls back to the post permalink if no URL is found in the post. … … 495 495 */ 496 496 function twentythirteen_get_link_url() { 497 497 $content = get_the_content(); 498 $has_url = get_ content_url( $content );498 $has_url = get_url_in_content( $content ); 499 499 500 500 return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); 501 501 }