From 026d8847b4c068d5cfc52b1308446e754f966c3f Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Fri, 22 Mar 2013 05:55:08 +0000 Subject: [PATCH] Add functions to parse audio or video data out of arbitrary content or a post props wonderboymusic. see #23572 git-svn-id: http://core.svn.wordpress.org/trunk@23774 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 129 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/wp-includes/media.php b/wp-includes/media.php index 070ac2ae02..0e18bea944 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1821,6 +1821,135 @@ function get_attached_video( $post_id = 0 ) { return $children; } +/** + * Extract the srcs from the post's [{media type}] s + * + * @since 3.6.0 + * + * @param string $content A string which might contain media data. + * @param boolean $remove Whether to remove the found URL from the passed content. + * @return array A list of lists. Each item has a list of sources corresponding + * to a [{media type}]'s primary src and specified fallbacks + */ +function get_content_media( $type, &$content, $remove = false ) { + $src = ''; + $items = array(); + $matches = array(); + + if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { + foreach ( $matches as $shortcode ) { + if ( $type === $shortcode[2] ) { + $srcs = array(); + $count = 1; + if ( $remove ) + $content = str_replace( $shortcode[0], '', $content, $count ); + + $item = do_shortcode_tag( $shortcode ); + preg_match_all( '#src=[\'"](.+?)[\'"]#is', $item, $src, PREG_SET_ORDER ); + if ( ! empty( $src ) ) { + foreach ( $src as $s ) + $srcs[] = $s[1]; + + $items[] = array_values( array_unique( $srcs ) ); + } + } + } + } + return $items; +} + +/** + * Check the content blob for an <{media type}>, , , or