Ticket #24202: 24202.2.diff
| File 24202.2.diff, 25.8 KB (added by , 13 years ago) |
|---|
-
wp-includes/media.php
1897 1897 /** 1898 1898 * Extract and parse {media type} shortcodes or srcs from the passed content 1899 1899 * 1900 * Default arguments: 1901 * string 'type' Type of media: audio or video. 1902 * string 'content' A string that might contain media data. 1903 * boolean 'return_html' Whether to return HTML or URLs. 1904 * boolean 'remove_from_content' Whether to remove the found URL from the passed content. 1905 * int 'media_count' The number of medias to return. 1906 * 1900 1907 * @since 3.6.0 1901 1908 * 1902 * @param string $type Type of media: audio or video 1903 * @param string $content A string which might contain media data. 1904 * @param boolean $html Whether to return HTML or URLs 1905 * @param boolean $remove Whether to remove the found URL from the passed content. 1906 * @param int $limit Optional. The number of medias to return 1909 * @param array $args An array of arguments. 1907 1910 * @return array A list of parsed shortcodes or extracted srcs 1908 1911 */ 1909 function get_content_media( $type, &$content, $html = true, $remove = false, $limit = 0 ) { 1912 function get_content_media( $args = array() ) { 1913 $defaults = array( 1914 'type' => null, 1915 'content' => &$content, 1916 'return_html' => true, 1917 'remove_from_content' => false, 1918 'media_count' => 0 1919 ); 1920 1921 $args = wp_parse_args( $args, $defaults ); 1922 1923 if ( null == $args['type'] ) 1924 return; 1925 1910 1926 $items = array(); 1911 1927 1912 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $ content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {1928 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $args['content'], $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 1913 1929 foreach ( $matches as $shortcode ) { 1914 if ( $ type=== $shortcode[2] ) {1930 if ( $args['type'] === $shortcode[2] ) { 1915 1931 $count = 1; 1916 if ( $ remove)1917 $ content =& str_replace( $shortcode[0], '', $content, $count );1932 if ( $args['remove_from_content'] ) 1933 $args['content'] =& str_replace( $shortcode[0], '', $args['content'], $count ); 1918 1934 1919 1935 $items[] = do_shortcode_tag( $shortcode ); 1920 if ( $ limit > 0 && count( $items ) >= $limit)1936 if ( $args['media_count'] > 0 && count( $items ) >= $args['media_count'] ) 1921 1937 break; 1922 1938 } 1923 1939 } 1924 1940 } 1925 1941 1926 if ( $ html)1942 if ( $args['return_html'] ) 1927 1943 return $items; 1928 1944 1929 1945 $data = array(); … … 1946 1962 * Check the content blob for an <{media type}>, <object>, <embed>, or <iframe>, in that order 1947 1963 * If no HTML tag is found, check the first line of the post for a URL 1948 1964 * 1965 * Default arguments: 1966 * string 'type' Type of media: audio or video. 1967 * string 'content' A string that might contain media data. 1968 * boolean 'remove_from_content' Whether to remove the found URL from the passed content. 1969 * int 'media_count' The number of medias to return. 1970 * 1949 1971 * @since 3.6.0 1950 1972 * 1951 * @param string $type Type of media: audio or video 1952 * @param string $content A string which might contain media data. 1953 * @param boolean $remove Whether to remove the found URL from the passed content. 1954 * @param int $limit Optional. The number of galleries to return 1973 * @param array $args (optional) An array of arguments. 1955 1974 * @return array A list of found HTML media embeds and possibly a URL by itself 1956 1975 */ 1957 function get_embedded_media( $type, &$content, $remove = false, $limit = 0 ) { 1976 function get_embedded_media( $args = array() ) { 1977 $defaults = array( 1978 'type' => null, 1979 'content' => &$content, 1980 'remove_from_content' => false, 1981 'media_count' => 0 1982 ); 1983 1984 $args = wp_parse_args( $args, $defaults ); 1985 1986 if ( null == $args['type'] ) 1987 return; 1988 1958 1989 $html = array(); 1959 1990 1960 foreach ( array( $ type, 'object', 'embed', 'iframe' ) as $tag ) {1961 if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $ content, $matches ) ) {1991 foreach ( array( $args['type'], 'object', 'embed', 'iframe' ) as $tag ) { 1992 if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $args['content'], $matches ) ) { 1962 1993 $html[] = $matches[0]; 1963 if ( $ remove)1964 $ content = str_replace( $matches[0], '', $content);1994 if ( $args['remove_from_content'] ) 1995 $args['content'] = str_replace( $matches[0], '', $args['content'] ); 1965 1996 1966 if ( $ limit > 0 && count( $html ) >= $limit)1997 if ( $args['media_count'] > 0 && count( $html ) >= $args['media_count'] ) 1967 1998 break; 1968 1999 } 1969 2000 } 1970 2001 1971 if ( ! empty( $html ) && count( $html ) >= $ limit)2002 if ( ! empty( $html ) && count( $html ) >= $args['media_count'] ) 1972 2003 return $html; 1973 2004 1974 $lines = explode( "\n", trim( $ content) );2005 $lines = explode( "\n", trim( $args['content'] ) ); 1975 2006 $line = trim( array_shift( $lines ) ); 1976 2007 if ( 0 === stripos( $line, 'http' ) ) { 1977 if ( $ remove)1978 $ content= join( "\n", $lines );2008 if ( $args['remove_from_content'] ) 2009 $args['content'] = join( "\n", $lines ); 1979 2010 1980 2011 $html[] = $line; 1981 2012 } … … 1987 2018 * 1988 2019 * @since 3.6.0 1989 2020 * 1990 * @ param string $content A string which might contain audio data.1991 * @param boolean $html Whether to return HTML or URLs1992 * @param boolean $remove Whether to remove the found URL from the passed content.2021 * @uses get_content_media() 2022 * 2023 * @param array $args (optional) An array of arguments. 1993 2024 * @return array A list of lists. Each item has a list of HTML or srcs corresponding 1994 2025 * to an [audio]'s HTML or primary src and specified fallbacks 1995 2026 */ 1996 function get_content_audio( &$content, $html = true, $remove = false) {1997 return get_content_media( 'audio', $content, $html, $remove);2027 function get_content_audio( $args = array() ) { 2028 return get_content_media( array_merge( $args, array( 'type' => 'audio' ) ) ); 1998 2029 } 1999 2030 2000 2031 /** … … 2003 2034 * 2004 2035 * @since 3.6.0 2005 2036 * 2006 * @param string $content A string which might contain audio data. 2007 * @param boolean $remove Whether to remove the found URL from the passed content. 2037 * @uses get_embedded_media() 2038 * 2039 * @param array $args (optional) An array of arguments. 2008 2040 * @return array A list of found HTML audio embeds and possibly a URL by itself 2009 2041 */ 2010 function get_embedded_audio( &$content, $remove = false) {2011 return get_embedded_media( 'audio', $content, $remove);2042 function get_embedded_audio( $args = array() ) { 2043 return get_embedded_media( array_merge( $args, array( 'type' => 'audio' ) ) ); 2012 2044 } 2013 2045 2014 2046 /** … … 2016 2048 * 2017 2049 * @since 3.6.0 2018 2050 * 2019 * @ param string $content A string which might contain video data.2020 * @param boolean $html Whether to return HTML or URLs2021 * @param boolean $remove Whether to remove the found URL from the passed content.2051 * @uses get_content_media() 2052 * 2053 * @param array $args (optional) An array of arguments. 2022 2054 * @return array A list of lists. Each item has a list of HTML or srcs corresponding 2023 2055 * to a [video]'s HTML or primary src and specified fallbacks 2024 2056 */ 2025 function get_content_video( &$content, $html = true, $remove = false) {2026 return get_content_media( 'video', $content, $html, $remove);2057 function get_content_video( $args = array() ) { 2058 return get_content_media( array_merge( $args, array( 'type' => 'video' ) ) ); 2027 2059 } 2028 2060 2029 2061 /** … … 2032 2064 * 2033 2065 * @since 3.6.0 2034 2066 * 2035 * @param string $content A string which might contain video data. 2036 * @param boolean $remove Whether to remove the found URL from the passed content. 2067 * @uses get_embedded_media() 2068 * 2069 * @param array $args (optional) An array of arguments. 2037 2070 * @return array A list of found HTML video embeds and possibly a URL by itself 2038 2071 */ 2039 function get_embedded_video( &$content, $remove = false) {2040 return get_embedded_media( 'video', $content, $remove);2072 function get_embedded_video( $args = array() ) { 2073 return get_embedded_media( array_merge( $args, array( 'type' => 'video' ) ) ); 2041 2074 } 2042 2075 2043 2076 /** … … 2046 2079 * 2047 2080 * @since 3.6.0 2048 2081 * 2082 * @uses get_content_media() 2083 * @uses get_embedded_media() 2084 * 2049 2085 * @param string $type Required. 'audio' or 'video' 2050 2086 * @param WP_Post $post Optional. Used instead of global $post when passed. 2051 2087 * @param int $limit Optional. The number of medias to remove if content is scanned. … … 2102 2138 // these functions expect a reference, so we should make a copy of post content to avoid changing it 2103 2139 $content = $post->post_content; 2104 2140 2105 $htmls = get_content_media( $type, $content, true, true, $limit ); 2141 $htmls = get_content_media( array( 2142 'type' => $type, 2143 'content' => $content, 2144 'return_html' => true, 2145 'remove_from_content' => true, 2146 'media_count' => $limit 2147 ) ); 2148 2106 2149 if ( ! empty( $htmls ) ) { 2107 2150 $html = reset( $htmls ); 2108 2151 $post->split_content = $content; … … 2110 2153 return $post->format_content[ $cache_key ]; 2111 2154 } 2112 2155 2113 $embeds = get_embedded_media( $type, $content, true, 1 ); 2156 $embeds = get_embedded_media( array( 2157 'type' => $type, 2158 'content' => $content, 2159 'remove_from_content' => true, 2160 'media_count' => 1 2161 ) ); 2162 2114 2163 if ( ! empty( $embeds ) ) { 2115 2164 $embed = reset( $embeds ); 2116 2165 $post->split_content = $content; … … 2194 2243 /** 2195 2244 * Check the content blob for images or image srcs 2196 2245 * 2246 * Default arguments: 2247 * string 'content' A string that might contain media data. 2248 * boolean 'return_html' Whether to return HTML or URLs. 2249 * boolean 'remove_from_content' Whether to remove the found URL from the passed content. 2250 * int 'media_count' The number of medias to return. 2251 * 2197 2252 * @since 3.6.0 2198 2253 * 2199 * @param string $content A string which might contain image data. 2200 * @param boolean $html Whether to return HTML or URLs 2201 * @param boolean $remove Whether to remove the found data from the passed content. 2202 * @param int $limit Optional. The number of image srcs to return 2254 * @param array $args (optional) An array of arguments. 2203 2255 * @return array The found images or srcs 2204 2256 */ 2205 function get_content_images( &$content, $html = true, $remove = false, $limit = 0 ) { 2257 function get_content_images( $args = array() ) { 2258 $defaults = array( 2259 'content' => &$content, 2260 'return_html' => true, 2261 'remove_from_content' => false, 2262 'media_count' => 0 2263 ); 2264 2265 $args = wp_parse_args( $args, $defaults ); 2266 2206 2267 $tags = array(); 2207 2268 $captions = array(); 2208 2269 2209 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $ content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {2270 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $args['content'], $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 2210 2271 foreach ( $matches as $shortcode ) { 2211 2272 if ( 'caption' === $shortcode[2] ) { 2212 2273 $captions[] = $shortcode[0]; 2213 if ( $ html)2274 if ( $args['return_html'] ) 2214 2275 $tags[] = do_shortcode( $shortcode[0] ); 2215 2276 } 2216 2277 2217 if ( $ limit > 0 && count( $tags ) >= $limit)2278 if ( $args['media_count'] > 0 && count( $tags ) >= $args['media_count'] ) 2218 2279 break; 2219 2280 } 2220 2281 } 2221 2282 2222 2283 foreach ( array( 'a', 'img' ) as $tag ) { 2223 if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#i', $ content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {2284 if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#i', $args['content'], $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 2224 2285 foreach ( $matches as $node ) { 2225 2286 if ( ! strstr( $node[0], '<img ' ) ) 2226 2287 continue; … … 2231 2292 foreach ( $captions as $caption ) { 2232 2293 if ( strstr( $caption, $node[0] ) ) { 2233 2294 $found = true; 2234 if ( $ remove)2235 $ content = str_replace( $caption, '', $content, $count );2295 if ( $args['remove_from_content'] ) 2296 $args['content'] = str_replace( $caption, '', $args['content'], $count ); 2236 2297 } 2237 2298 } 2238 2299 2239 if ( $ remove)2240 $content = str_replace( $node[0], '', $ content, $count );2300 if ( $args['remove_from_content'] ) 2301 $content = str_replace( $node[0], '', $args['content'], $count ); 2241 2302 2242 2303 if ( ! $found ) 2243 2304 $tags[] = $node[0]; 2244 2305 2245 if ( $ limit > 0 && count( $tags ) >= $limit)2306 if ( $args['media_count'] > 0 && count( $tags ) >= $args['media_count'] ) 2246 2307 break 2; 2247 2308 } 2248 2309 } 2249 2310 } 2250 2311 2251 if ( $ html)2312 if ( $args['return_html'] ) 2252 2313 return $tags; 2253 2314 2254 2315 $srcs = array(); … … 2257 2318 preg_match( '#src=[\'"](.+?)[\'"]#is', $tag, $src ); 2258 2319 if ( ! empty( $src[1] ) ) { 2259 2320 $srcs[] = $src[1]; 2260 if ( $ limit > 0 && count( $srcs ) >= $limit)2321 if ( $args['media_count'] > 0 && count( $srcs ) >= $args['media_count'] ) 2261 2322 break; 2262 2323 } 2263 2324 } 2264 2325 2265 return apply_filters( 'content_images', array_values( array_unique( $srcs ) ), $ content);2326 return apply_filters( 'content_images', array_values( array_unique( $srcs ) ), $args['content'] ); 2266 2327 } 2267 2328 2268 2329 /** 2269 2330 * Check the content blob for images or srcs and return the first 2270 2331 * 2332 * Default arguments: 2333 * string 'content' A string that might contain media data. 2334 * boolean 'return_html' Whether to return HTML or URLs. 2335 * boolean 'remove_from_content' Whether to remove the found URL from the passed content. 2336 * 2271 2337 * @since 3.6.0 2272 2338 * 2273 * @ param string $content A string which might contain image data.2274 * @param boolean $html Whether to return HTML or URLs2275 * @param boolean $remove Whether to remove the found data from the passed content.2339 * @uses get_content_images() 2340 * 2341 * @param array $args (optional) An array of arguments. 2276 2342 * @return string The found data 2277 2343 */ 2278 function get_content_image( &$content, $html = true, $remove = false ) { 2279 $srcs = get_content_images( $content, $html, $remove, 1 ); 2344 function get_content_image( $args = array() ) { 2345 $defaults = array( 2346 'content' => &$content, 2347 'return_html' => true, 2348 'remove_from_content' => false 2349 ); 2350 2351 $args = wp_parse_args( $args, $defaults ); 2352 2353 $srcs = get_content_images( array_merge( $args, array( 'media_count' => 1 ) ) ); 2280 2354 if ( empty( $srcs ) ) 2281 2355 return ''; 2282 2356 2283 return apply_filters( 'content_image', reset( $srcs ), $ content);2357 return apply_filters( 'content_image', reset( $srcs ), $args['content'] ); 2284 2358 } 2285 2359 2286 2360 /** 2287 2361 * Check the content blob for galleries and return their image srcs 2288 2362 * 2363 * Default arguments: 2364 * string 'content' A string that might contain media data. 2365 * boolean 'return_html' Whether to return HTML or URLs. 2366 * boolean 'remove_from_content' Whether to remove the found URL from the passed content. 2367 * int 'media_count' The number of medias to return. 2368 * 2289 2369 * @since 3.6.0 2290 2370 * 2291 * @param string $content A string which might contain image data. 2292 * @param boolean $html Whether to return HTML or data 2293 * @param boolean $remove Optional. Whether to remove the found data from the passed content. 2294 * @param int $limit Optional. The number of galleries to return 2371 * @param array $args (optional) An array of arguments. 2295 2372 * @return array A list of galleries, which in turn are a list of their srcs in order 2296 2373 */ 2297 function get_content_galleries( &$content, $html = true, $remove = false, $limit = 0 ) { 2374 function get_content_galleries( $args = array() ) { 2375 $defaults = array( 2376 'content' => &$content, 2377 'return_html' => true, 2378 'remove_from_content' => false, 2379 'media_count' => 0 2380 ); 2381 2382 $args = wp_parse_args( $args, $defaults ); 2383 2298 2384 $galleries = array(); 2299 2385 2300 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $ content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {2386 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $args['content'], $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { 2301 2387 foreach ( $matches as $shortcode ) { 2302 2388 if ( 'gallery' === $shortcode[2] ) { 2303 2389 $srcs = array(); 2304 2390 $count = 1; 2305 if ( $ remove)2306 $ content = str_replace( $shortcode[0], '', $content, $count );2391 if ( $args['remove_from_content'] ) 2392 $args['content'] = str_replace( $shortcode[0], '', $args['content'], $count ); 2307 2393 2308 2394 $data = shortcode_parse_atts( $shortcode[3] ); 2309 2395 $gallery = do_shortcode_tag( $shortcode ); 2310 if ( $ html) {2396 if ( $args['return_html'] ) { 2311 2397 $galleries[] = $gallery; 2312 2398 } else { 2313 2399 preg_match_all( '#src=[\'"](.+?)[\'"]#is', $gallery, $src, PREG_SET_ORDER ); … … 2320 2406 $galleries[] = $data; 2321 2407 } 2322 2408 2323 if ( $ limit > 0 && count( $galleries ) >= $limit)2409 if ( $args['media_count'] > 0 && count( $galleries ) >= $args['media_count'] ) 2324 2410 break; 2325 2411 } 2326 2412 } 2327 2413 } 2328 2414 2329 return apply_filters( 'content_galleries', $galleries, $ content);2415 return apply_filters( 'content_galleries', $galleries, $args['content'] ); 2330 2416 } 2331 2417 2332 2418 /** 2333 2419 * Retrieve galleries from the passed post's content 2334 2420 * 2421 * Default arguments: 2422 * int 'id' The post id. 2423 * boolean 'return_html' Whether to return HTML or data. 2424 * 2335 2425 * @since 3.6.0 2336 2426 * 2337 * @param int $post_id Optional. Post ID. 2338 * @param boolean $html Whether to return HTML or data 2427 * @uses get_content_galleries() 2428 * 2429 * @param array $args (optional) An array of arguments. 2339 2430 * @return array A list of arrays, each containing gallery data and srcs parsed 2340 2431 * from the expanded shortcode 2341 2432 */ 2342 function get_post_galleries( $post_id = 0, $html = true ) { 2343 $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); 2433 function get_post_galleries( $args = array() ) { 2434 $defaults = array( 2435 'id' => 0, 2436 'return_html' => true 2437 ); 2438 2439 $args = wp_parse_args( $args, $defaults ); 2440 2441 $post = 0 == $args['id'] ? clone get_post() : get_post( $args['id'] ); 2344 2442 if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) 2345 2443 return array(); 2346 2444 2347 return get_content_galleries( $post->post_content, $html ); 2445 $galleries = get_content_galleries( array( 2446 'content' => $post->post_content, 2447 'return_html' => $args['return_html'] 2448 ) ); 2449 2450 return $galleries; 2348 2451 } 2349 2452 2350 2453 /** … … 2352 2455 * 2353 2456 * @since 3.6.0 2354 2457 * 2355 * @param int $post_id Optional. Post ID. 2458 * @uses get_content_galleries() 2459 * 2460 * @param int $post_id (optional) The post id. 2356 2461 * @return array A list of lists, each containing image srcs parsed 2357 2462 * from an expanded shortcode 2358 2463 */ … … 2361 2466 if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) 2362 2467 return array(); 2363 2468 2364 $data = get_content_galleries( $post->post_content, false ); 2469 $data = get_content_galleries( array( 2470 'content' => $post->post_content, 2471 'return_html' => false 2472 ) ); 2473 2365 2474 return wp_list_pluck( $data, 'src' ); 2366 2475 } 2367 2476 2368 2477 /** 2369 2478 * Check a specified post's content for gallery and, if present, return the first 2370 2479 * 2480 * Default arguments: 2481 * int 'id' The post id. 2482 * boolean 'return_html' Whether to return HTML or URLs. 2483 * 2371 2484 * @since 3.6.0 2372 2485 * 2373 * @param int $post_id Optional. Post ID. 2374 * @param boolean $html Whether to return HTML or data 2486 * @uses get_content_galleries() 2487 * 2488 * @param array $args (optional) An array of arguments. 2375 2489 * @return array Gallery data and srcs parsed from the expanded shortcode 2376 2490 */ 2377 function get_post_gallery( $post_id = 0, $html = true ) { 2378 $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); 2491 function get_post_gallery( $args = array() ) { 2492 $defaults = array( 2493 'id' => 0, 2494 'return_html' => true 2495 ); 2496 2497 $args = wp_parse_args( $args, $defaults ); 2498 2499 $post = 0 == $args['id'] ? clone get_post() : get_post( $args['id'] ); 2379 2500 if ( empty( $post ) || ! has_shortcode( $post->post_content, 'gallery' ) ) 2380 2501 return array(); 2381 2502 2382 $data = get_content_galleries( $post->post_content, $html, false, 1 ); 2503 $data = get_content_galleries( array( 2504 'content' => $post->post_content, 2505 'return_html' => $args['return_html'], 2506 'remove_from_content' => false, 2507 'media_count' => 1 2508 ) ); 2509 2383 2510 return reset( $data ); 2384 2511 } 2385 2512 … … 2401 2528 * @return array A list of a gallery's image srcs in order 2402 2529 */ 2403 2530 function get_post_gallery_images( $post_id = 0 ) { 2404 $gallery = get_post_gallery( $post_id, false ); 2531 $gallery = get_post_gallery( array( 2532 'id' => $post_id, 2533 'return_html' => false 2534 ) ); 2535 2405 2536 if ( empty( $gallery['src'] ) ) 2406 2537 return array(); 2407 2538 … … 2413 2544 * 2414 2545 * @since 3.6.0 2415 2546 * 2547 * @uses get_content_images() 2548 * 2416 2549 * @param string $attached_size If an attached image is found, the size to display it. 2417 2550 * @param WP_Post $post Optional. Used instead of global $post when passed. 2418 2551 */ … … 2529 2662 } 2530 2663 2531 2664 $content = $post->post_content; 2532 $htmls = get_content_images( $content, true, true, 1 ); 2665 $htmls = get_content_images( array( 2666 'content' => $content, 2667 'return_html' => true, 2668 'remove_from_content' => true, 2669 'media_count' => 1 2670 ) ); 2671 2533 2672 if ( ! empty( $htmls ) ) { 2534 2673 $html = reset( $htmls ); 2535 2674 $post->split_content = $content; -
wp-includes/post-formats.php
353 353 if ( ! preg_match( '#' . $esc_url . '[^/&\?]?#', $content ) ) { 354 354 $url = $meta['link_url']; 355 355 } else { 356 $url = get_content_url( $content, true);356 $url = get_content_url( array( 'content' => $content, 'remove_from_content' => true ) ); 357 357 } 358 358 } else { 359 359 $content_before = $content; 360 $url = get_content_url( $content, true);360 $url = get_content_url( array( 'content' => $content, 'remove_from_content' => true ) ); 361 361 if ( $content_before == $content ) 362 362 $url = ''; 363 363 } … … 529 529 * @param boolean $remove Whether to remove the found data from the passed content. 530 530 * @return array A chat log as structured data 531 531 */ 532 function get_content_chat( &$content, $remove = false) {532 function get_content_chat( $args = array() ) { 533 533 global $_wp_chat_parsers; 534 534 535 $trimmed = strip_tags( trim( $content ) ); 535 $defaults = array( 536 'content' => &$content, 537 'remove_from_content' => false 538 ); 539 540 $args = wp_parse_args( $args, $defaults ); 541 542 $trimmed = strip_tags( trim( $args['content'] ) ); 536 543 if ( empty( $trimmed ) ) 537 544 return array(); 538 545 … … 620 627 if ( ! empty( $stanza ) ) 621 628 $stanzas[] = $stanza; 622 629 623 if ( $ remove) {630 if ( $args['remove_from_content'] ) { 624 631 if ( 0 === $found_index ) { 625 632 $removed = array_slice( $lines, $last_index ); 626 633 } else { … … 628 635 $after = array_slice( $lines, $last_index + 1 ); 629 636 $removed = array_filter( array_merge( $before, $after ) ); 630 637 } 631 $ content= trim( join( "\n", $removed ) );638 $args['content'] = trim( join( "\n", $removed ) ); 632 639 } 633 640 634 641 return $stanzas; … … 639 646 * 640 647 * @since 3.6.0 641 648 * 642 * @param int $id (optional) The post ID. 649 * @uses get_content_chat() 650 * 651 * @param int $post_id (optional) The post ID. 643 652 * @return array The chat content. 644 653 */ 645 function get_the_post_format_chat( $ id = 0 ) {646 $post = empty( $ id ) ? clone get_post() : get_post( $id );654 function get_the_post_format_chat( $post_id = 0 ) { 655 $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); 647 656 if ( empty( $post ) ) 648 657 return array(); 649 658 650 $data = get_content_chat( get_paged_content( $post->post_content) );659 $data = get_content_chat( array( 'content' => get_paged_content( $post->post_content ) ) ); 651 660 if ( empty( $data ) ) 652 661 return array(); 653 662 … … 704 713 * @param string $replace (optional) Content to replace the quote content with. 705 714 * @return string The quote content. 706 715 */ 707 function get_content_quote( &$content, $remove = false, $replace = '' ) { 708 if ( empty( $content ) ) 716 function get_content_quote( $args = array() ) { 717 $defaults = array( 718 'content' => &$content, 719 'remove_from_content' => false, 720 'replace_with' => '' 721 ); 722 723 $args = wp_parse_args( $args, $defaults ); 724 725 if ( empty( $args['content'] ) ) 709 726 return ''; 710 727 711 if ( ! preg_match( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', $ content, $matches ) ) {712 $quote = $ content;713 if ( $ remove || ! empty( $replace) )714 $ content = $replace;728 if ( ! preg_match( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', $args['content'], $matches ) ) { 729 $quote = $args['content']; 730 if ( $args['remove_from_content'] || ! empty( $args['replace_with'] ) ) 731 $args['content'] = $args['replace_with']; 715 732 return $quote; 716 733 } 717 734 718 if ( $ remove || ! empty( $replace) )719 $ content = preg_replace( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', addcslashes( $replace, '\\$' ), $content, 1 );735 if ( $args['remove_from_content'] || ! empty( $args['replace_with'] ) ) 736 $args['content'] = preg_replace( '/<blockquote[^>]*>(.+?)<\/blockquote>/is', addcslashes( $args['replace_with'], '\\$' ), $args['content'], 1 ); 720 737 721 738 return $matches[1]; 722 739 } … … 739 756 return ''; 740 757 741 758 $content = $post->post_content; 742 $quote = get_content_quote( $content, true ); 759 $quote = get_content_quote( array( 760 'content' => $content, 761 'remove_from_content' => true 762 ) ); 763 743 764 $post->split_content = $content; 744 765 745 766 if ( ! empty( $quote ) ) … … 778 799 * @return string The found URL. 779 800 */ 780 801 function get_content_url( &$content, $remove = false ) { 781 if ( empty( $content ) ) 802 $defaults = array( 803 'content' => &$content, 804 'remove_from_content' => false 805 ); 806 807 $args = wp_parse_args( $args, $defaults ); 808 809 if ( empty( $args['content'] ) ) 782 810 return ''; 783 811 784 812 // the content is a URL 785 $trimmed = trim( $ content);813 $trimmed = trim( $args['content'] ); 786 814 if ( 0 === stripos( $trimmed, 'http' ) && ! preg_match( '#\s#', $trimmed ) ) { 787 if ( $ remove)788 $ content= '';815 if ( $args['remove_from_content'] ) 816 $args['content'] = ''; 789 817 790 818 return $trimmed; 791 819 // the content is HTML so we grab the first href 792 } elseif ( preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', $ content, $matches ) ) {820 } elseif ( preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', $args['content'], $matches ) ) { 793 821 return esc_url_raw( $matches[1] ); 794 822 } 795 823 … … 798 826 799 827 // the content is a URL followed by content 800 828 if ( 0 === stripos( $line, 'http' ) ) { 801 if ( $ remove)802 $ content= trim( join( "\n", $lines ) );829 if ( $args['remove_from_content'] ) 830 $args['content'] = trim( join( "\n", $lines ) ); 803 831 804 832 return esc_url_raw( $line ); 805 833 } … … 845 873 } 846 874 847 875 if ( ! empty( $post->post_content ) ) 848 return apply_filters( 'get_the_post_format_url', get_content_url( $post->post_content), $post );876 return apply_filters( 'get_the_post_format_url', get_content_url( array( 'content' => $post->post_content ) ), $post ); 849 877 } 850 878 851 879 /**