| | 1996 | * Extract the srcs from the post's [audio] <source>s |
| | 1997 | * |
| | 1998 | * @since 3.6.0 |
| | 1999 | * |
| | 2000 | * @param string $content A string which might contain audio data. |
| | 2001 | * @param boolean $remove Whether to remove the found URL from the passed content. |
| | 2002 | * @return array A list of lists. Each item has a list of sources corresponding |
| | 2003 | * to a [audio]'s primary src and specified fallbacks |
| | 2004 | */ |
| | 2005 | function get_content_audio( &$content, $remove = false ) { |
| | 2006 | $src = ''; |
| | 2007 | $audios = array(); |
| | 2008 | $matches = array(); |
| | 2009 | |
| | 2010 | if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { |
| | 2011 | foreach ( $matches as $shortcode ) { |
| | 2012 | if ( 'audio' === $shortcode[2] ) { |
| | 2013 | $srcs = array(); |
| | 2014 | $count = 1; |
| | 2015 | if ( $remove ) |
| | 2016 | $content = str_replace( $shortcode[0], '', $content, $count ); |
| | 2017 | |
| | 2018 | $audio = do_shortcode_tag( $shortcode ); |
| | 2019 | preg_match_all( '#src=[\'"](.+?)[\'"]#is', $audio, $src, PREG_SET_ORDER ); |
| | 2020 | if ( ! empty( $src ) ) { |
| | 2021 | foreach ( $src as $s ) |
| | 2022 | $srcs[] = $s[1]; |
| | 2023 | |
| | 2024 | $audios[] = array_values( array_unique( $srcs ) ); |
| | 2025 | } |
| | 2026 | } |
| | 2027 | } |
| | 2028 | } |
| | 2029 | return $audios; |
| | 2030 | } |
| | 2031 | |
| | 2032 | /** |
| | 2033 | * Check the content blob for an <audio>, <object>, <embed>, or <iframe>, in that order |
| | 2034 | * If no HTML tag is found, check the first line of the post for a URL |
| | 2035 | * |
| | 2036 | * @since 3.6.0 |
| | 2037 | * |
| | 2038 | * @param string $content A string which might contain audio data. |
| | 2039 | * @param boolean $remove Whether to remove the found URL from the passed content. |
| | 2040 | * @return array A list of found HTML audio embeds and possibly a URL by itself |
| | 2041 | */ |
| | 2042 | function get_embedded_audio( &$content, $remove = false ) { |
| | 2043 | $html = array(); |
| | 2044 | $matches = ''; |
| | 2045 | |
| | 2046 | foreach ( array( 'audio', 'object', 'embed', 'iframe' ) as $tag ) { |
| | 2047 | if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) { |
| | 2048 | $html[] = $matches[1]; |
| | 2049 | if ( $remove ) |
| | 2050 | $content = str_replace( $matches[0], '', $content ); |
| | 2051 | |
| | 2052 | return $html; |
| | 2053 | } |
| | 2054 | } |
| | 2055 | |
| | 2056 | $lines = explode( "\n", trim( $content ) ); |
| | 2057 | $line = trim( array_shift( $lines ) ); |
| | 2058 | |
| | 2059 | if ( 0 === stripos( $line, 'http' ) ) { |
| | 2060 | if ( $remove ) |
| | 2061 | $content = join( "\n", $lines ); |
| | 2062 | |
| | 2063 | $html[] = $line; |
| | 2064 | } |
| | 2065 | return $html; |
| | 2066 | } |
| | 2067 | |
| | 2068 | /** |
| | 2069 | * Extract the srcs from the post's [video] <source>s |
| | 2070 | * |
| | 2071 | * @since 3.6.0 |
| | 2072 | * |
| | 2073 | * @param string $content A string which might contain video data. |
| | 2074 | * @param boolean $remove Whether to remove the found URL from the passed content. |
| | 2075 | * @return array A list of lists. Each item has a list of sources corresponding |
| | 2076 | * to a [video]'s primary src and specified fallbacks |
| | 2077 | */ |
| | 2078 | function get_content_video( &$content, $remove = false ) { |
| | 2079 | $src = ''; |
| | 2080 | $videos = array(); |
| | 2081 | $matches = array(); |
| | 2082 | |
| | 2083 | if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { |
| | 2084 | foreach ( $matches as $shortcode ) { |
| | 2085 | if ( 'video' === $shortcode[2] ) { |
| | 2086 | $srcs = array(); |
| | 2087 | $count = 1; |
| | 2088 | if ( $remove ) |
| | 2089 | $content = str_replace( $shortcode[0], '', $content, $count ); |
| | 2090 | |
| | 2091 | $video = do_shortcode_tag( $shortcode ); |
| | 2092 | preg_match_all( '#src=[\'"](.+?)[\'"]#is', $video, $src, PREG_SET_ORDER ); |
| | 2093 | if ( ! empty( $src ) ) { |
| | 2094 | foreach ( $src as $s ) |
| | 2095 | $srcs[] = $s[1]; |
| | 2096 | |
| | 2097 | $videos[] = array_values( array_unique( $srcs ) ); |
| | 2098 | } |
| | 2099 | } |
| | 2100 | } |
| | 2101 | } |
| | 2102 | return $videos; |
| | 2103 | } |
| | 2104 | |
| | 2105 | /** |
| | 2106 | * Check the content blob for a <video>, <object>, <embed>, or <iframe>, in that order |
| | 2107 | * If no HTML tag is found, check the first line of the post for a URL |
| | 2108 | * |
| | 2109 | * @since 3.6.0 |
| | 2110 | * |
| | 2111 | * @param string $content A string which might contain video data. |
| | 2112 | * @param boolean $remove Whether to remove the found URL from the passed content. |
| | 2113 | * @return array A list of found HTML video embeds and possibly a URL by itself |
| | 2114 | */ |
| | 2115 | function get_embedded_video( &$content, $remove = false ) { |
| | 2116 | $html = array(); |
| | 2117 | $matches = ''; |
| | 2118 | foreach ( array( 'video', 'object', 'embed', 'iframe' ) as $tag ) { |
| | 2119 | if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) { |
| | 2120 | $html[] = $matches[1]; |
| | 2121 | if ( $remove ) |
| | 2122 | $content = str_replace( $matches[0], '', $content ); |
| | 2123 | } |
| | 2124 | } |
| | 2125 | |
| | 2126 | $lines = explode( "\n", trim( $content ) ); |
| | 2127 | $line = trim( array_shift( $lines ) ); |
| | 2128 | |
| | 2129 | if ( 0 === stripos( $line, 'http' ) ) { |
| | 2130 | if ( $remove ) |
| | 2131 | $content = join( "\n", $lines ); |
| | 2132 | |
| | 2133 | $html[] = $line; |
| | 2134 | } |
| | 2135 | return $html; |
| | 2136 | } |
| | 2137 | |
| | 2138 | /** |