Chat post format code cleanup.
see #23625. props obenland. git-svn-id: http://core.svn.wordpress.org/trunk@23876 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9b90808fe9
commit
6d085d83d5
|
@ -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
|
* @since 3.6.0
|
||||||
*
|
*
|
||||||
|
@ -484,12 +484,10 @@ function get_content_chat( &$content, $remove = false ) {
|
||||||
if ( empty( $trimmed ) )
|
if ( empty( $trimmed ) )
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
$has_match = false;
|
|
||||||
$matched_parser = false;
|
$matched_parser = false;
|
||||||
foreach ( $_wp_chat_parsers as $parser ) {
|
foreach ( $_wp_chat_parsers as $parser ) {
|
||||||
@list( $newline_regex ) = $parser;
|
@list( $newline_regex, $delimiter_regex ) = $parser;
|
||||||
if ( preg_match( $newline_regex, $trimmed ) ) {
|
if ( preg_match( $newline_regex, $trimmed ) ) {
|
||||||
$has_match = true;
|
|
||||||
$matched_parser = $parser;
|
$matched_parser = $parser;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -498,15 +496,11 @@ function get_content_chat( &$content, $remove = false ) {
|
||||||
if ( false === $matched_parser )
|
if ( false === $matched_parser )
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
@list( $newline_regex, $delimiter_regex ) = $parser;
|
|
||||||
|
|
||||||
$last_index = 0;
|
$last_index = 0;
|
||||||
$stanzas = array();
|
$stanzas = $data = $stanza = array();
|
||||||
|
$author = $time = '';
|
||||||
$lines = explode( "\n", make_clickable( $trimmed ) );
|
$lines = explode( "\n", make_clickable( $trimmed ) );
|
||||||
|
|
||||||
$author = $time = '';
|
|
||||||
$data = array();
|
|
||||||
$stanza = array();
|
|
||||||
|
|
||||||
foreach ( $lines as $index => $line ) {
|
foreach ( $lines as $index => $line ) {
|
||||||
$line = trim( $line );
|
$line = trim( $line );
|
||||||
|
@ -514,17 +508,16 @@ function get_content_chat( &$content, $remove = false ) {
|
||||||
if ( empty( $line ) ) {
|
if ( empty( $line ) ) {
|
||||||
if ( ! empty( $author ) ) {
|
if ( ! empty( $author ) ) {
|
||||||
$stanza[] = array(
|
$stanza[] = array(
|
||||||
'time' => $time,
|
'time' => $time,
|
||||||
'author' => $author,
|
'author' => $author,
|
||||||
'message' => join( ' ', $data )
|
'message' => join( ' ', $data )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stanzas[] = $stanza;
|
$stanzas[] = $stanza;
|
||||||
$last_index = $index;
|
$last_index = $index;
|
||||||
$stanza = array();
|
$stanza = $data = array();
|
||||||
$author = $time = '';
|
$author = $time = '';
|
||||||
$data = array();
|
|
||||||
if ( ! empty( $lines[$index + 1] ) && ! preg_match( $delimiter_regex, $lines[$index + 1] ) )
|
if ( ! empty( $lines[$index + 1] ) && ! preg_match( $delimiter_regex, $lines[$index + 1] ) )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -539,8 +532,8 @@ function get_content_chat( &$content, $remove = false ) {
|
||||||
if ( $matched && ( ! empty( $matches[2] ) || ( $no_ws || $has_ws ) ) ) {
|
if ( $matched && ( ! empty( $matches[2] ) || ( $no_ws || $has_ws ) ) ) {
|
||||||
if ( ! empty( $author ) ) {
|
if ( ! empty( $author ) ) {
|
||||||
$stanza[] = array(
|
$stanza[] = array(
|
||||||
'time' => $time,
|
'time' => $time,
|
||||||
'author' => $author,
|
'author' => $author,
|
||||||
'message' => join( ' ', $data )
|
'message' => join( ' ', $data )
|
||||||
);
|
);
|
||||||
$data = array();
|
$data = array();
|
||||||
|
@ -556,8 +549,8 @@ function get_content_chat( &$content, $remove = false ) {
|
||||||
|
|
||||||
if ( ! empty( $author ) ) {
|
if ( ! empty( $author ) ) {
|
||||||
$stanza[] = array(
|
$stanza[] = array(
|
||||||
'time' => $time,
|
'time' => $time,
|
||||||
'author' => $author,
|
'author' => $author,
|
||||||
'message' => trim( join( ' ', $data ) )
|
'message' => trim( join( ' ', $data ) )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -602,29 +595,28 @@ function get_the_chat( $id = 0 ) {
|
||||||
* @print HTML
|
* @print HTML
|
||||||
*/
|
*/
|
||||||
function the_chat() {
|
function the_chat() {
|
||||||
$output = '<dl class="chat-transcript">';
|
$output = '<dl class="chat">';
|
||||||
|
|
||||||
$stanzas = get_the_chat();
|
$stanzas = get_the_chat();
|
||||||
|
|
||||||
foreach ( $stanzas as $stanza ) {
|
foreach ( $stanzas as $stanza ) {
|
||||||
foreach ( $stanza as $row ) {
|
foreach ( $stanza as $row ) {
|
||||||
$time = '';
|
$time = '';
|
||||||
if ( ! empty( $row['time'] ) )
|
if ( ! empty( $row['time'] ) )
|
||||||
$time = sprintf( '<time>%s</time>', esc_html( $row['time'] ) );
|
$time = sprintf( '<time class="chat-timestamp">%s</time>', esc_html( $row['time'] ) );
|
||||||
|
|
||||||
$output .= sprintf(
|
$output .= sprintf(
|
||||||
'<dt class="chat-author chat-author-%1$s vcard">%2$s <cite class="fn">%3$s</cite>: </dt>
|
'<dt class="chat-author chat-author-%1$s vcard">%2$s <cite class="fn">%3$s</cite>: </dt>
|
||||||
<dd class="chat-text">%4$s</dd>
|
<dd class="chat-text">%4$s</dd>
|
||||||
',
|
',
|
||||||
esc_attr( strtolower( $row['author'] ) ), // Slug.
|
esc_attr( sanitize_title_with_dashes( $row['author'] ) ), // Slug.
|
||||||
$time,
|
$time,
|
||||||
esc_html( $row['author'] ),
|
esc_html( $row['author'] ),
|
||||||
esc_html( $row['message'] )
|
$row['message']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$output .= '</dl><!-- .chat-transcript -->';
|
$output .= '</dl><!-- .chat -->';
|
||||||
|
|
||||||
echo $output;
|
echo $output;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3626,14 +3626,14 @@ function wp_old_slug_redirect() {
|
||||||
*
|
*
|
||||||
* @since 3.6.0
|
* @since 3.6.0
|
||||||
*
|
*
|
||||||
* @param string $content Content to split
|
* @param string $content Content to split.
|
||||||
* @return array Paged content
|
* @return array Paged content.
|
||||||
*/
|
*/
|
||||||
function paginate_content( $content ) {
|
function paginate_content( $content ) {
|
||||||
$content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
|
$content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
|
||||||
$content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
|
$content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
|
||||||
$content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
|
$content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
|
||||||
return explode( '<!--nextpage-->', $content);
|
return explode( '<!--nextpage-->', $content );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3642,9 +3642,10 @@ function paginate_content( $content ) {
|
||||||
* @since 3.6.0
|
* @since 3.6.0
|
||||||
*
|
*
|
||||||
* @param string $content
|
* @param string $content
|
||||||
|
* @param int $paged
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function get_paged_content( $content = null, $paged = null ) {
|
function get_paged_content( $content = '', $paged = 0 ) {
|
||||||
global $page;
|
global $page;
|
||||||
if ( empty( $page ) )
|
if ( empty( $page ) )
|
||||||
$page = 1;
|
$page = 1;
|
||||||
|
@ -3655,7 +3656,7 @@ function get_paged_content( $content = null, $paged = null ) {
|
||||||
if ( empty( $content ) ) {
|
if ( empty( $content ) ) {
|
||||||
$post = get_post();
|
$post = get_post();
|
||||||
if ( empty( $post ) )
|
if ( empty( $post ) )
|
||||||
return;
|
return '';
|
||||||
|
|
||||||
$content = $post->post_content;
|
$content = $post->post_content;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue