tag within the content. If not, wraps the entire post * content with one. * * @since 0.9.0 * @access public * @param string $content The post content. * @return string $content */ function omega_quote_content( $content ) { if ( has_post_format( 'quote' ) ) { preg_match( '//', $content, $matches ); if ( empty( $matches ) ) $content = " {$content}"; } return $content; } /* === Chats === */ /** * Separates the post content into an array of arrays for further formatting of the chat content. * * @since 0.9.0 * @access public * @param string $content * @return array */ function omega_get_the_post_format_chat( $content ) { /* Allow the separator (separator for speaker/text) to be filtered. */ $separator = apply_filters( 'omega_post_format_chat_separator', ':' ); /* Split the content to get individual chat rows. */ $chat_rows = preg_split( "/(\r?\n)+|(
\s*)+/", $content ); /* Loop through each row and format the output. */ foreach ( $chat_rows as $chat_row ) { /* Set up a new, empty array of this stanza. */ $stanza = array(); /* If a speaker is found, create a new chat row with speaker and text. */ if ( preg_match( '/(? $chat_row ); } } $stanzas[] = $stanza; } return $stanzas; } /** * This function filters the post content when viewing a post with the "chat" post format. It formats * the content with structured HTML markup to make it easy for theme developers to style chat posts. * The advantage of this solution is that it allows for more than two speakers (like most solutions). * You can have 100s of speakers in your chat post, each with their own, unique classes for styling. * * @author David Chandra* @author Justin Tadlock * @copyright Copyright (c) 2012 * @link http://justintadlock.com/archives/2012/08/21/post-formats-chat * * @since 0.9.0 * @access public * @global array $_omega_post_chat_ids An array of IDs for the chat rows based on the author. * @param string $content The content of the post. * @return string $chat_output The formatted content of the post. */ function omega_chat_content( $content ) { /* If this isn't a chat, return. */ if ( !has_post_format( 'chat' ) || post_password_required() ) return $content; /* Open the chat transcript div and give it a unique ID based on the post ID. */ $chat_output = "\n\t\t\t" . ' '; /* Allow the separator (separator for speaker/text) to be filtered. */ $separator = apply_filters( 'omega_post_format_chat_separator', ':' ); /* Get the stanzas from the post content. */ $stanzas = omega_get_the_post_format_chat( $content ); /* Loop through the stanzas that were returned. */ foreach ( $stanzas as $stanza ) { /* Loop through each row of the stanza and format. */ foreach ( $stanza as $row ) { /* Get the chat author and message. */ $chat_author = !empty( $row['author'] ) ? $row['author'] : ''; $chat_text = $row['message']; /* Get the speaker/row ID. */ $speaker_id = omega_chat_row_id( $chat_author ); /* Format the time if there was one given. */ $time = empty( $row['time'] ) ? '' : ' '; /* Open the chat row. */ $chat_output .= "\n\t\t\t\t" . '\n"; /* Return the chat content. */ return $chat_output; } /** * This function returns an ID based on the provided chat author name. It keeps these IDs in a global * array and makes sure we have a unique set of IDs. The purpose of this function is to provide an "ID" * that will be used in an HTML class for individual chat rows so they can be styled. So, speaker "John" * will always have the same class each time he speaks. And, speaker "Mary" will have a different class * from "John" but will have the same class each time she speaks. * * @author David Chandra'; /* Add the chat row author. */ if ( !empty( $chat_author ) ) $chat_output .= "\n\t\t\t\t\t" . ''; /* Add the chat row text. */ $chat_output .= "\n\t\t\t\t\t" . ''; } } /* Close the chat transcript div. */ $chat_output .= "\n\t\t\t' . str_replace( array( "\r", "\n", "\t" ), '', apply_filters( 'omega_post_format_chat_text', $chat_text, $chat_author, $speaker_id ) ) . ''; /* Close the chat row. */ $chat_output .= "\n\t\t\t\t" . '* @author Justin Tadlock * @copyright Copyright (c) 2012 * @link http://justintadlock.com/archives/2012/08/21/post-formats-chat * * @since 0.9.0 * @access public * @global array $_omega_post_chat_ids An array of IDs for the chat rows based on the author. * @param string $chat_author Author of the current chat row. * @return int The ID for the chat row based on the author. */ function omega_chat_row_id( $chat_author ) { global $_omega_post_chat_ids; /* Let's sanitize the chat author to avoid craziness and differences like "John" and "john". */ $chat_author = strtolower( strip_tags( $chat_author ) ); /* Add the chat author to the array. */ $_omega_post_chat_ids[] = $chat_author; /* Make sure the array only holds unique values. */ $_omega_post_chat_ids = array_unique( $_omega_post_chat_ids ); /* Return the array key for the chat author and add "1" to avoid an ID of "0". */ return absint( array_search( $chat_author, $_omega_post_chat_ids ) ) + 1; } ?>