Index: wp-includes/post-formats.php =================================================================== --- wp-includes/post-formats.php (revision 24177) +++ wp-includes/post-formats.php (working copy) @@ -353,11 +353,11 @@ if ( ! preg_match( '#' . $esc_url . '[^/&\?]?#', $content ) ) { $url = $meta['link_url']; } else { - $url = get_content_url( $content, true ); + $url = get_content_url( $content, array( 'remove' => true ) ); } } else { $content_before = $content; - $url = get_content_url( $content, true ); + $url = get_content_url( $content, array( 'remove' => true ) ); if ( $content_before == $content ) $url = ''; } @@ -418,8 +418,12 @@ $quote = get_the_post_format_quote( $post ); // Replace the existing quote in-place. - if ( ! empty( $quote ) ) - get_content_quote( $content, true, $quote ); + if ( ! empty( $quote ) ) { + get_content_quote( $content, array( + 'remove' => true, + 'replace' => $quote, + ) ); + } break; case 'video': @@ -523,15 +527,24 @@ * ) * ) * + * $args contents: + * - remove - Whether to remove the found data from the passed content. + * * @since 3.6.0 * * @param string $content A string which might contain chat data, passed by reference. - * @param boolean $remove Whether to remove the found data from the passed content. + * @param array $args (optional) arguments. * @return array A chat log as structured data */ -function get_content_chat( &$content, $remove = false ) { +function get_content_chat( &$content, $args = array() ) { global $_wp_chat_parsers; + $defaults = array( + 'remove' => false, + ); + + $args = wp_parse_args( $args, $defaults ); + $trimmed = strip_tags( trim( $content ) ); if ( empty( $trimmed ) ) return array(); @@ -620,7 +633,7 @@ if ( ! empty( $stanza ) ) $stanzas[] = $stanza; - if ( $remove ) { + if ( $args['remove'] ) { if ( 0 === $found_index ) { $removed = array_slice( $lines, $last_index ); } else { @@ -639,15 +652,18 @@ * * @since 3.6.0 * - * @param int $id (optional) The post ID. + * @uses get_content_chat() + * + * @param int $post_id (optional) The post ID. * @return array The chat content. */ -function get_the_post_format_chat( $id = 0 ) { - $post = empty( $id ) ? clone get_post() : get_post( $id ); +function get_the_post_format_chat( $post_id = 0 ) { + $post = empty( $post_id ) ? clone get_post() : get_post( $post_id ); if ( empty( $post ) ) return array(); - $data = get_content_chat( get_paged_content( $post->post_content ) ); + $content = get_paged_content( $post->post_content ); + $data = get_content_chat( $content ); if ( empty( $data ) ) return array(); @@ -697,26 +713,36 @@ * If $content does not have a blockquote, assume the whole string * is the quote. * + * $args contents: + * - remove - Whether to remove the quote from the content. + * - replace - Content to replace the quote content with. + * * @since 3.6.0 * * @param string $content A string which might contain chat data, passed by reference. - * @param bool $remove (optional) Whether to remove the quote from the content. - * @param string $replace (optional) Content to replace the quote content with. + * @param array $args An optional array of arguments. * @return string The quote content. */ -function get_content_quote( &$content, $remove = false, $replace = '' ) { +function get_content_quote( &$content, $args = array() ) { + $defaults = array( + 'remove' => false, + 'replace' => '', + ); + + $args = wp_parse_args( $args, $defaults ); + if ( empty( $content ) ) return ''; if ( ! preg_match( '/
]*>(.+?)<\/blockquote>/is', $content, $matches ) ) { $quote = $content; - if ( $remove || ! empty( $replace ) ) - $content = $replace; + if ( $args['remove'] || ! empty( $args['replace'] ) ) + $content = $args['replace']; return $quote; } - if ( $remove || ! empty( $replace ) ) - $content = preg_replace( '/]*>(.+?)<\/blockquote>/is', addcslashes( $replace, '\\$' ), $content, 1 ); + if ( $args['remove'] || ! empty( $args['replace'] ) ) + $content = preg_replace( '/]*>(.+?)<\/blockquote>/is', addcslashes( $args['replace'], '\\$' ), $content, 1 ); return $matches[1]; } @@ -740,7 +766,10 @@ return ''; $content = $post->post_content; - $quote = get_content_quote( $content, true ); + $quote = get_content_quote( $content, array( + 'remove' => true, + ) ); + $post->split_content = $content; if ( ! empty( $quote ) ) @@ -773,20 +802,29 @@ * Extract a URL from passed content, if possible * Checks for a URL on the first line of the content or the first encountered href attribute. * + * $args contents: + * - remove - Whether to remove the found URL from the passed content. + * * @since 3.6.0 * * @param string $content A string which might contain a URL, passed by reference. - * @param boolean $remove Whether to remove the found URL from the passed content. + * @param array $args An optional array of arguments. * @return string The found URL. */ -function get_content_url( &$content, $remove = false ) { +function get_content_url( &$content, $args = array() ) { + $defaults = array( + 'remove' => false, + ); + + $args = wp_parse_args( $args, $defaults ); + if ( empty( $content ) ) return ''; // the content is a URL $trimmed = trim( $content ); if ( 0 === stripos( $trimmed, 'http' ) && ! preg_match( '#\s#', $trimmed ) ) { - if ( $remove ) + if ( $args['content'] ) $content = ''; return $trimmed; @@ -800,7 +838,7 @@ // the content is a URL followed by content if ( 0 === stripos( $line, 'http' ) ) { - if ( $remove ) + if ( $args['remove'] ) $content = trim( join( "\n", $lines ) ); return esc_url_raw( $line ); Index: wp-includes/media.php =================================================================== --- wp-includes/media.php (revision 24177) +++ wp-includes/media.php (working copy) @@ -1897,33 +1897,48 @@ /** * Extract and parse {media type} shortcodes or srcs from the passed content * + * $args contents: + * - type - Type of media: audio or video. + * - return - Whether to return HTML or URLs. + * - remove - Whether to remove the found URL from the passed content. + * - limit - The number of medias to return. + * * @since 3.6.0 * - * @param string $type Type of media: audio or video * @param string $content A string which might contain media data. - * @param boolean $html Whether to return HTML or URLs - * @param boolean $remove Whether to remove the found URL from the passed content. - * @param int $limit Optional. The number of medias to return + * @param array $args An array of arguments. * @return array A list of parsed shortcodes or extracted srcs */ -function get_content_media( $type, &$content, $html = true, $remove = false, $limit = 0 ) { +function get_content_media( &$content, $args ) { + $defaults = array( + 'type' => null, + 'html' => true, + 'remove' => false, + 'limit' => 0, + ); + + $args = wp_parse_args( $args, $defaults ); + + if ( empty( $args['type'] ) ) + return; + $items = array(); if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) { foreach ( $matches as $shortcode ) { - if ( $type === $shortcode[2] ) { + if ( $args['type'] === $shortcode[2] ) { $count = 1; - if ( $remove ) - $content =& str_replace( $shortcode[0], '', $content, $count ); + if ( $args['remove'] ) + $content = str_replace( $shortcode[0], '', $content, $count ); $items[] = do_shortcode_tag( $shortcode ); - if ( $limit > 0 && count( $items ) >= $limit ) + if ( $args['limit'] > 0 && count( $items ) >= $args['limit'] ) break; } } } - if ( $html ) + if ( $args['html'] ) return $items; $data = array(); @@ -1946,35 +1961,49 @@ * Check the content blob for an <{media type}>,