From fe5b462eea78cadc57537659be685960356465cd Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Sun, 2 Jun 2013 16:26:10 +0000 Subject: [PATCH] Remove a bunch of Post Format template functions. * get_post_format_meta() * add_chat_detection_format() * get_content_chat() * get_the_post_format_chat() * the_post_format_chat() * get_content_quote() * get_the_post_format_quote() * the_post_format_quote() * get_the_post_format_url() * the_post_format_url() * get_the_remaining_content() * the_remaining_content() see #24452 git-svn-id: http://core.svn.wordpress.org/trunk@24399 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-formats.php | 494 ----------------------------------- 1 file changed, 494 deletions(-) diff --git a/wp-includes/post-formats.php b/wp-includes/post-formats.php index 5e1a3cfbad..d33cf32ca6 100644 --- a/wp-includes/post-formats.php +++ b/wp-includes/post-formats.php @@ -72,57 +72,6 @@ function set_post_format( $post, $format ) { return wp_set_post_terms( $post->ID, $format, 'post_format' ); } -/** - * Retrieve post format metadata for a post - * - * @since 3.6.0 - * - * @param int $post_id (optional) The post ID. - * @return array The array of post format metadata. - */ -function get_post_format_meta( $post_id = 0 ) { - $meta = get_post_meta( $post_id ); - $keys = array( 'quote', 'quote_source_name', 'quote_source_url', 'link_url', 'gallery', 'audio_embed', 'video_embed', 'url', 'image' ); - - if ( empty( $meta ) ) - return array_fill_keys( $keys, '' ); - - $upgrade = array( - '_wp_format_quote_source' => 'quote_source_name', - '_wp_format_audio' => 'audio_embed', - '_wp_format_video' => 'video_embed' - ); - - $format = get_post_format( $post_id ); - if ( ! empty( $format ) ) { - switch ( $format ) { - case 'link': - $upgrade['_wp_format_url'] = 'link_url'; - break; - case 'quote': - $upgrade['_wp_format_url'] = 'quote_source_url'; - break; - } - } - - $upgrade_keys = array_keys( $upgrade ); - foreach ( $meta as $key => $values ) { - if ( ! in_array( $key, $upgrade_keys ) ) - continue; - update_post_meta( $post_id, '_format_' . $upgrade[$key], reset( $values ) ); - delete_post_meta( $post_id, $key ); - } - - $values = array(); - - foreach ( $keys as $key ) { - $value = get_post_meta( $post_id, '_format_' . $key, true ); - $values[$key] = empty( $value ) ? '' : $value; - } - - return apply_filters( 'post_format_meta', $values ); -} - /** * Returns an array of post format slugs to their translated and pretty display versions * @@ -285,308 +234,6 @@ function _post_format_wp_get_object_terms( $terms ) { } add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' ); -/** - * Add chat detection support to the `get_content_chat()` chat parser. - * - * @since 3.6.0 - * - * @global array $_wp_chat_parsers - * - * @param string $name Unique identifier for chat format. Example: IRC - * @param string $newline_regex RegEx to match the start of a new line, typically when a new "username:" appears - * The parser will handle up to 3 matched expressions - * $matches[0] = the string before the user's message starts - * $matches[1] = the time of the message, if present - * $matches[2] = the author/username - * OR - * $matches[0] = the string before the user's message starts - * $matches[1] = the author/username - * @param string $delimiter_regex RegEx to determine where to split the username syntax from the chat message - */ -function add_chat_detection_format( $name, $newline_regex, $delimiter_regex ) { - global $_wp_chat_parsers; - - if ( empty( $_wp_chat_parsers ) ) - $_wp_chat_parsers = array(); - - $_wp_chat_parsers = array( $name => array( $newline_regex, $delimiter_regex ) ) + $_wp_chat_parsers; -} -add_chat_detection_format( 'IM', '#^([^:]+):#', '#[:]#' ); -add_chat_detection_format( 'Skype', '#(\[.+?\])\s([^:]+):#', '#[:]#' ); - -/** - * Deliberately interpret passed content as a chat transcript that is optionally - * followed by commentary - * - * If the content does not contain username syntax, assume that it does not contain - * chat logs and return - * - * Example: - * - * One stanza of chat: - * Scott: Hey, let's chat! - * Helen: No. - * - * $stanzas = array( - * array( - * array( - * 'time' => '', - * 'author' => 'Scott', - * 'messsage' => "Hey, let's chat!" - * ), - * array( - * 'time' => '', - * 'author' => 'Helen', - * 'message' => 'No.' - * ) - * ) - * ) - * - * @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. - * @return array A chat log as structured data - */ -function get_content_chat( &$content, $remove = false ) { - global $_wp_chat_parsers; - - $trimmed = strip_tags( trim( $content ) ); - if ( empty( $trimmed ) ) - return array(); - - $matched_parser = false; - foreach ( $_wp_chat_parsers as $parser ) { - @list( $newline_regex, $delimiter_regex ) = $parser; - if ( preg_match( $newline_regex, $trimmed ) ) { - $matched_parser = $parser; - break; - } - } - - if ( false === $matched_parser ) - return array(); - - $last_index = 0; - $stanzas = $data = $stanza = array(); - $author = $time = ''; - $lines = explode( "\n", make_clickable( $trimmed ) ); - $found = false; - $found_index = 0; - - foreach ( $lines as $index => $line ) { - if ( ! $found ) - $found_index = $index; - - $line = trim( $line ); - - if ( empty( $line ) && $found ) { - if ( ! empty( $author ) ) { - $stanza[] = array( - 'time' => $time, - 'author' => $author, - 'message' => join( ' ', $data ) - ); - } - - $stanzas[] = $stanza; - - $stanza = $data = array(); - $author = $time = ''; - if ( ! empty( $lines[$index + 1] ) && ! preg_match( $delimiter_regex, $lines[$index + 1] ) ) - break; - else - continue; - } - - $matched = preg_match( $newline_regex, $line, $matches ); - if ( ! $matched ) - continue; - - $found = true; - $last_index = $index; - $author_match = empty( $matches[2] ) ? $matches[1] : $matches[2]; - // assume username syntax if no whitespace is present - $no_ws = $matched && ! preg_match( '#[\r\n\t ]#', $author_match ); - // allow script-like stanzas - $has_ws = $matched && preg_match( '#[\r\n\t ]#', $author_match ) && empty( $lines[$index + 1] ) && empty( $lines[$index - 1] ); - if ( $matched && ( ! empty( $matches[2] ) || ( $no_ws || $has_ws ) ) ) { - if ( ! empty( $author ) ) { - $stanza[] = array( - 'time' => $time, - 'author' => $author, - 'message' => join( ' ', $data ) - ); - $data = array(); - } - - $time = empty( $matches[2] ) ? '' : $matches[1]; - $author = $author_match; - $data[] = trim( str_replace( $matches[0], '', $line ) ); - } elseif ( preg_match( '#\S#', $line ) ) { - $data[] = $line; - } - } - - if ( ! empty( $author ) ) { - $stanza[] = array( - 'time' => $time, - 'author' => $author, - 'message' => trim( join( ' ', $data ) ) - ); - } - - if ( ! empty( $stanza ) ) - $stanzas[] = $stanza; - - if ( $remove ) { - if ( 0 === $found_index ) { - $removed = array_slice( $lines, $last_index ); - } else { - $before = array_slice( $lines, 0, $found_index ); - $after = array_slice( $lines, $last_index + 1 ); - $removed = array_filter( array_merge( $before, $after ) ); - } - $content = trim( join( "\n", $removed ) ); - } - - return $stanzas; -} - -/** - * Retrieve structured chat data from the current or passed post - * - * @since 3.6.0 - * - * @param int $post_id (optional) The post ID. - * @return array The chat content. - */ -function get_the_post_format_chat( $post_id = 0 ) { - if ( ! $post = get_post( $post_id ) ) - return array(); - - $data = get_content_chat( get_paged_content( $post->post_content ) ); - if ( empty( $data ) ) - return array(); - - return $data; -} - -/** - * Output HTML for a given chat's structured data. Themes can use this as a - * template tag in place of the_content() for Chat post format templates. - * - * @since 3.6.0 - * - * @uses get_the_post_format_chat() - * - * @print HTML - */ -function the_post_format_chat() { - $output = '
'; - $stanzas = get_the_post_format_chat(); - - foreach ( $stanzas as $stanza ) { - foreach ( $stanza as $row ) { - $time = ''; - if ( ! empty( $row['time'] ) ) - $time = sprintf( '', esc_html( $row['time'] ) ); - - $output .= sprintf( - '
%2$s %3$s:
-
%4$s
- ', - esc_attr( sanitize_title_with_dashes( $row['author'] ) ), // Slug. - $time, - esc_html( $row['author'] ), - $row['message'] - ); - } - } - - $output .= '
'; - - echo $output; -} - -/** - * Get the first
from the $content string passed by reference. - * - * If $content does not have a blockquote, assume the whole string - * is the quote. - * - * @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. - * @return string The quote content. - */ -function get_content_quote( &$content, $remove = false, $replace = '' ) { - if ( empty( $content ) ) - return ''; - - if ( ! preg_match( '/]*>(.+?)<\/blockquote>/is', $content, $matches ) ) { - $quote = $content; - if ( $remove || ! empty( $replace ) ) - $content = $replace; - return $quote; - } - - if ( $remove || ! empty( $replace ) ) - $content = preg_replace( '/]*>(.+?)<\/blockquote>/is', addcslashes( $replace, '\\$' ), $content, 1 ); - - return $matches[1]; -} - -/** - * Get a quote from the post content and set split_content for future use. - * - * @since 3.6.0 - * - * @uses get_content_quote() - * @uses apply_filters() Calls 'quote_source_format' filter to allow changing the typographical mark added to the quote source (em-dash prefix, by default) - * - * @param object $post (optional) A reference to the post object, falls back to get_post(). - * @return string The quote html. - */ -function get_the_post_format_quote( &$post = null ) { - if ( empty( $post ) ) - $post = get_post(); - - if ( empty( $post ) ) - return ''; - - $content = $post->post_content; - $quote = get_content_quote( $content, true ); - $post->split_content = $content; - - if ( ! empty( $quote ) ) - $quote = sprintf( '
%s
', wpautop( $quote ) ); - - $meta = get_post_format_meta( $post->ID ); - - if ( ! empty( $meta['quote_source_name'] ) ) { - $source = ( empty( $meta['quote_source_url'] ) ) ? $meta['quote_source_name'] : sprintf( '%s', esc_url( $meta['quote_source_url'] ), $meta['quote_source_name'] ); - $source = sprintf( apply_filters( 'quote_source_format', __( '— %s' ) ), $source ); - $quote .= sprintf( '
%s
', $source ); - } - - if ( ! empty( $quote ) ) - $quote = sprintf( '
%s
', $quote ); - - return $quote; -} - -/** - * Outputs the post format quote. - * - * @since 3.6.0 - */ -function the_post_format_quote() { - echo get_the_post_format_quote(); -} - /** * 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. @@ -627,147 +274,6 @@ function get_content_url( &$content, $remove = false ) { return ''; } -/** - * Attempt to retrieve a URL from a post's content - * - * @since 3.6.0 - * - * @param int $post_id (optional) The post ID. - * @return string A URL, if found. - */ -function get_the_post_format_url( $post_id = 0 ) { - if ( ! $post = get_post( $post_id ) ) - return ''; - - $format = get_post_format( $post->ID ); - if ( in_array( $format, array( 'image', 'link', 'quote' ) ) ) { - $meta = get_post_format_meta( $post->ID ); - $meta_link = ''; - - switch ( $format ) { - case 'link': - if ( ! empty( $meta['link_url'] ) ) - $meta_link = $meta['link_url']; - break; - case 'image': - if ( ! empty( $meta['url'] ) ) - $meta_link = $meta['url']; - break; - case 'quote': - if ( ! empty( $meta['quote_source_url'] ) ) - $meta_link = $meta['quote_source_url']; - break; - } - - if ( ! empty( $meta_link ) ) - return apply_filters( 'get_the_post_format_url', esc_url_raw( $meta_link ), $post ); - } - - if ( ! empty( $post->post_content ) ) - return apply_filters( 'get_the_post_format_url', get_content_url( $post->post_content ), $post ); -} - -/** - * Attempt to output a URL from a post's content - * - * @since 3.6.0 - *. - */ -function the_post_format_url() { - echo esc_url( get_the_post_format_url() ); -} - -/** - * Retrieve the post content, minus the extracted post format content - * - * @since 3.6.0 - * - * @internal there is a lot of code that could be abstracted from get_the_content() - * - * @param string $more_link_text Optional. Content for when there is more text. - * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. - * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise. - * @return string The content minus the extracted post format content. - */ -function get_the_remaining_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) { - global $more, $page, $preview; - - $post = get_post( $id ); - - extract( wp_parse_post_content( $post, true ) ); - - if ( null === $more_link_text ) - $more_link_text = __( '(more…)' ); - - $output = ''; - $has_teaser = false; - - // If post password required and it doesn't match the cookie. - if ( post_password_required( $post ) ) - return get_the_password_form( $post ); - - if ( $page > count( $pages ) ) // if the requested page doesn't exist - $page = count( $pages ); // give them the highest numbered page that DOES exist - - $content = $pages[$page-1]; - if ( preg_match( '//', $content, $matches ) ) { - $content = explode( $matches[0], $content, 2 ); - if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) - $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); - - $has_teaser = true; - } else { - $content = array( $content ); - } - - if ( false !== strpos( $post->post_content, '' ) && ( ! $multipage || $page == 1 ) ) - $strip_teaser = true; - - $teaser = $content[0]; - - if ( $more && $strip_teaser && $has_teaser ) - $teaser = ''; - - $output .= $teaser; - - if ( count( $content ) > 1 ) { - if ( $more ) { - $output .= '' . $content[1]; - } else { - if ( ! empty( $more_link_text ) ) - $output .= apply_filters( 'the_content_more_link', ' ID}\" class=\"more-link\">$more_link_text", $more_link_text ); - - $output = force_balance_tags( $output ); - } - } - - if ( $preview ) // preview fix for javascript bug with foreign languages - $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); - - return $output; -} - -/** - * Display the post content minus the parsed post format data. - * - * @since 3.6.0 - * - * @param string $more_link_text Optional. Content for when there is more text. - * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. - * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise. - */ -function the_remaining_content( $more_link_text = null, $strip_teaser = false, $id = 0 ) { - $post = get_post( $id ); - - $extra = get_the_remaining_content( $more_link_text, $strip_teaser, $post->ID ); - - remove_filter( 'the_content', 'post_formats_compat', 7 ); - $content = apply_filters( 'the_content', $extra, $post->ID ); - add_filter( 'the_content', 'post_formats_compat', 7, 2 ); - - echo str_replace( ']]>', ']]>', $content ); -} - /** * Don't display post titles for asides and status posts on the front end. *