From 6d085d83d5054e63c8b18e2de90461c7a63f566e Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Fri, 29 Mar 2013 21:06:37 +0000 Subject: [PATCH] Chat post format code cleanup. see #23625. props obenland. git-svn-id: http://core.svn.wordpress.org/trunk@23876 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-formats.php | 40 +++++++++++++++--------------------- wp-includes/query.php | 15 +++++++------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/wp-includes/post-formats.php b/wp-includes/post-formats.php index 9487ad0350..c59c2861e5 100644 --- a/wp-includes/post-formats.php +++ b/wp-includes/post-formats.php @@ -417,7 +417,7 @@ function post_formats_compat( $content, $id = 0 ) { } /** - * Add chat detection support to the `get_content_chat()` chat parser + * Add chat detection support to the `get_content_chat()` chat parser. * * @since 3.6.0 * @@ -484,12 +484,10 @@ function get_content_chat( &$content, $remove = false ) { if ( empty( $trimmed ) ) return array(); - $has_match = false; $matched_parser = false; foreach ( $_wp_chat_parsers as $parser ) { - @list( $newline_regex ) = $parser; + @list( $newline_regex, $delimiter_regex ) = $parser; if ( preg_match( $newline_regex, $trimmed ) ) { - $has_match = true; $matched_parser = $parser; break; } @@ -498,15 +496,11 @@ function get_content_chat( &$content, $remove = false ) { if ( false === $matched_parser ) return array(); - @list( $newline_regex, $delimiter_regex ) = $parser; - $last_index = 0; - $stanzas = array(); + $stanzas = $data = $stanza = array(); + $author = $time = ''; $lines = explode( "\n", make_clickable( $trimmed ) ); - $author = $time = ''; - $data = array(); - $stanza = array(); foreach ( $lines as $index => $line ) { $line = trim( $line ); @@ -514,17 +508,16 @@ function get_content_chat( &$content, $remove = false ) { if ( empty( $line ) ) { if ( ! empty( $author ) ) { $stanza[] = array( - 'time' => $time, - 'author' => $author, + 'time' => $time, + 'author' => $author, 'message' => join( ' ', $data ) ); } $stanzas[] = $stanza; $last_index = $index; - $stanza = array(); + $stanza = $data = array(); $author = $time = ''; - $data = array(); if ( ! empty( $lines[$index + 1] ) && ! preg_match( $delimiter_regex, $lines[$index + 1] ) ) break; } @@ -539,8 +532,8 @@ function get_content_chat( &$content, $remove = false ) { if ( $matched && ( ! empty( $matches[2] ) || ( $no_ws || $has_ws ) ) ) { if ( ! empty( $author ) ) { $stanza[] = array( - 'time' => $time, - 'author' => $author, + 'time' => $time, + 'author' => $author, 'message' => join( ' ', $data ) ); $data = array(); @@ -556,8 +549,8 @@ function get_content_chat( &$content, $remove = false ) { if ( ! empty( $author ) ) { $stanza[] = array( - 'time' => $time, - 'author' => $author, + 'time' => $time, + 'author' => $author, 'message' => trim( join( ' ', $data ) ) ); } @@ -602,29 +595,28 @@ function get_the_chat( $id = 0 ) { * @print HTML */ function the_chat() { - $output = '
'; - + $output = '
'; $stanzas = get_the_chat(); foreach ( $stanzas as $stanza ) { foreach ( $stanza as $row ) { $time = ''; if ( ! empty( $row['time'] ) ) - $time = sprintf( '', esc_html( $row['time'] ) ); + $time = sprintf( '', esc_html( $row['time'] ) ); $output .= sprintf( '
%2$s %3$s:
%4$s
', - esc_attr( strtolower( $row['author'] ) ), // Slug. + esc_attr( sanitize_title_with_dashes( $row['author'] ) ), // Slug. $time, esc_html( $row['author'] ), - esc_html( $row['message'] ) + $row['message'] ); } } - $output .= '
'; + $output .= '
'; echo $output; } diff --git a/wp-includes/query.php b/wp-includes/query.php index 478beb9293..03303879ed 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -3626,14 +3626,14 @@ function wp_old_slug_redirect() { * * @since 3.6.0 * - * @param string $content Content to split - * @return array Paged content + * @param string $content Content to split. + * @return array Paged content. */ function paginate_content( $content ) { $content = str_replace( "\n\n", '', $content ); - $content = str_replace( "\n", '', $content ); - $content = str_replace( "\n", '', $content ); - return explode( '', $content); + $content = str_replace( "\n", '', $content ); + $content = str_replace( "\n", '', $content ); + return explode( '', $content ); } /** @@ -3642,9 +3642,10 @@ function paginate_content( $content ) { * @since 3.6.0 * * @param string $content + * @param int $paged * @return string */ -function get_paged_content( $content = null, $paged = null ) { +function get_paged_content( $content = '', $paged = 0 ) { global $page; if ( empty( $page ) ) $page = 1; @@ -3655,7 +3656,7 @@ function get_paged_content( $content = null, $paged = null ) { if ( empty( $content ) ) { $post = get_post(); if ( empty( $post ) ) - return; + return ''; $content = $post->post_content; }