*/ ?> '; /* 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 ) { /* If a speaker is found, create a new chat row with speaker and text. */ if ( strpos( $chat_row, $separator ) ) { /* Split the chat row into author/text. */ $chat_row_split = explode( $separator, trim( $chat_row ), 2 ); /* Get the chat author and strip tags. */ $chat_author = strip_tags( trim( $chat_row_split[0] ) ); /* Get the chat text. */ $chat_text = trim( $chat_row_split[1] ); /* Get the chat row ID (based on chat author) to give a specific class to each row for styling. */ $speaker_id = blogbox_chat_row_id( $chat_author ); /* Open the chat row. */ $chat_output .= "\n\t\t\t\t" . '
'; /* Add the chat row author. */ $chat_output .= "\n\t\t\t\t\t" . '
' . apply_filters( 'my_post_format_chat_author', $chat_author, $speaker_id ) . '' . $separator . '
'; /* Add the chat row text. */ $chat_output .= "\n\t\t\t\t\t" . '
' . str_replace( array( "\r", "\n", "\t" ), '', apply_filters( 'my_post_format_chat_text', $chat_text, $chat_author, $speaker_id ) ) . '
'; /* Close the chat row. */ $chat_output .= "\n\t\t\t\t" . '
'; } /** * If no author is found, assume this is a separate paragraph of text that belongs to the * previous speaker and label it as such, but let's still create a new row. */ else { /* Make sure we have text. */ if ( !empty( $chat_row ) ) { /* Open the chat row. */ $chat_output .= "\n\t\t\t\t" . '
'; /* Don't add a chat row author. The label for the previous row should suffice. */ /* Add the chat row text. */ $chat_output .= "\n\t\t\t\t\t" . '
' . str_replace( array( "\r", "\n", "\t" ), '', apply_filters( 'my_post_format_chat_text', $chat_row, $chat_author, $speaker_id ) ) . '
'; /* Close the chat row. */ $chat_output .= "\n\t\t\t
"; } } } /* Close the chat transcript div. */ $chat_output .= "\n\t\t\t\n"; /* Return the chat content and apply filters for developers. */ return apply_filters( 'blogbox_format_chat_content', $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 * @link http://www.turtlepod.org * @author Justin Tadlock * @link http://justintadlock.com * @copyright Copyright (c) 2012 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @link http://justintadlock.com/archives/2012/08/21/post-formats-chat * * @global array $_post_format_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. */ if( !function_exists( 'blogbox_chat_row_id' ) ) { function blogbox_chat_row_id( $chat_author ) { global $_post_format_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. */ $_post_format_chat_ids[] = $chat_author; /* Make sure the array only holds unique values. */ $_post_format_chat_ids = array_unique( $_post_format_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, $_post_format_chat_ids ) ) + 1; } } /** * This function was taken from http://codex.wordpress.org/Using_Gravatars * It checks the gravatar site for a valid gravatar for the email supplied and * returns a boolean true or false */ if (!function_exists ('blogbox_validate_gravatar')){ function blogbox_validate_gravatar($email) { // Craft a potential url and test its headers $hash = md5(strtolower(trim($email))); $uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404'; $headers = @get_headers($uri); if (!preg_match("|200|", $headers[0])) { $has_valid_avatar = FALSE; } else { $has_valid_avatar = TRUE; } return $has_valid_avatar; } } /** * This function is called by the post format functions and supplies the meta * for the top section of the post. */ if (!function_exists ('blogbox_post_metatop')){ function blogbox_post_metatop() { global $blogbox_options; $exclude_timestamp = $blogbox_options['bB_exclude_timestamp']; $exclude_author = $blogbox_options['bB_exclude_author']; //return if no meta if( true == $exclude_timestamp && true == $exclude_author ) { return; } echo '
'; if( true != $exclude_timestamp ) { ?>     '; } } /** * This function is called by all the post formats to add the meta bottom strip */ if (!function_exists ('blogbox_post_metabottom')){ function blogbox_post_metabottom($bB_post_format) { global $blogbox_options; $exclude_category = $blogbox_options['bB_exclude_category']; $exclude_tags = $blogbox_options['bB_exclude_tags']; echo ''; } }