Changeset 24685
- Timestamp:
- 07/12/2013 08:34:07 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/media.php
r24684 r24685 1894 1894 1895 1895 /** 1896 * Check the content blob for images or image srcs1897 *1898 * @since 3.6.01899 *1900 * @param string $content A string which might contain image data.1901 * @param boolean $html Whether to return HTML or URLs in the array1902 * @return array The found images or srcs1903 */1904 function get_images_in_content( $content, $html = true ) {1905 $tags = array();1906 $captions = array();1907 1908 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) ) {1909 foreach ( $matches as $shortcode ) {1910 if ( 'caption' === $shortcode[2] ) {1911 $captions[] = $shortcode[0];1912 if ( $html )1913 $tags[] = do_shortcode_tag( $shortcode );1914 }1915 }1916 }1917 1918 foreach ( array( 'a', 'img' ) as $tag ) {1919 if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#i', $content, $matches, PREG_SET_ORDER ) ) {1920 foreach ( $matches as $node ) {1921 if ( ! strstr( $node[0], '<img ' ) )1922 continue;1923 1924 $count = 1;1925 $found = false;1926 1927 foreach ( $captions as $caption ) {1928 if ( strstr( $caption, $node[0] ) ) {1929 $found = true;1930 }1931 }1932 1933 if ( ! $found )1934 $tags[] = $node[0];1935 }1936 }1937 }1938 1939 if ( $html )1940 return $tags;1941 1942 $image_srcs = array();1943 1944 foreach ( $tags as $tag ) {1945 preg_match( '#src=([\'"])(.+?)\1#is', $tag, $src );1946 if ( ! empty( $src[2] ) )1947 $image_srcs[] = $src[2];1948 }1949 1950 $image_srcs = array_values( array_unique( $image_srcs ) );1951 return apply_filters( 'get_images_in_content', $image_srcs, $content );1952 }1953 1954 /**1955 * Check the content blob for images or srcs and return the first1956 *1957 * @since 3.6.01958 *1959 * @param string $content A string which might contain image data.1960 * @param boolean $html Whether to return HTML or URLs1961 * @return string The found data1962 */1963 function get_image_in_content( $content, $html = true ) {1964 $srcs = get_images_from_content( $content, $html );1965 return apply_filters( 'get_image_in_content', reset( $srcs ), $content );1966 }1967 1968 /**1969 1896 * Retrieve galleries from the passed post's content 1970 1897 *
Note: See TracChangeset
for help on using the changeset viewer.