Make WordPress Core

Ticket #23625: 23625.15.diff

File 23625.15.diff, 2.7 KB (added by wonderboymusic, 12 years ago)
  • wp-includes/post-formats.php

    diff --git wp-includes/post-formats.php wp-includes/post-formats.php
    index a6e1049..977d960 100644
    function add_chat_detection_format( $name, $newline_regex, $delimiter_regex ) { 
    453453        $_wp_chat_parsers = array( $name => array( $newline_regex, $delimiter_regex ) ) + $_wp_chat_parsers;
    454454}
    455455add_chat_detection_format( 'IM', '#^([^:]+):#', '#[:]#' );
    456 add_chat_detection_format( 'Skype', '#^(\[.+?\])\s([^:]+):#', '#[:]#' );
     456add_chat_detection_format( 'Skype', '#(\[.+?\])\s([^:]+):#', '#[:]#' );
    457457
    458458/**
    459459 * Deliberately interpret passed content as a chat transcript that is optionally
    add_chat_detection_format( 'Skype', '#^(\[.+?\])\s([^:]+):#', '#[:]#' ); 
    492492function get_content_chat( &$content, $remove = false ) {
    493493        global $_wp_chat_parsers;
    494494
    495         $trimmed = trim( $content );
     495        $trimmed = strip_tags( trim( $content ) );
    496496        if ( empty( $trimmed ) )
    497497                return array();
    498498
    function get_content_chat( &$content, $remove = false ) { 
    512512        $stanzas = $data = $stanza = array();
    513513        $author = $time = '';
    514514        $lines = explode( "\n", make_clickable( $trimmed ) );
    515 
     515        $found = false;
     516        $found_index = 0;
    516517
    517518        foreach ( $lines as $index => $line ) {
     519                if ( ! $found )
     520                        $found_index = $index;
     521
    518522                $line = trim( $line );
    519523
    520                 if ( empty( $line ) ) {
     524                if ( empty( $line ) && $found ) {
    521525                        if ( ! empty( $author ) ) {
    522526                                $stanza[] = array(
    523527                                        'time'    => $time,
    function get_content_chat( &$content, $remove = false ) { 
    527531                        }
    528532
    529533                        $stanzas[] = $stanza;
    530                         $last_index = $index;
     534
    531535                        $stanza = $data = array();
    532536                        $author = $time = '';
    533537                        if ( ! empty( $lines[$index + 1] ) && ! preg_match( $delimiter_regex, $lines[$index + 1] ) )
    function get_content_chat( &$content, $remove = false ) { 
    538542
    539543                $matches = array();
    540544                $matched = preg_match( $newline_regex, $line, $matches );
     545                if ( ! $matched )
     546                        continue;
     547
     548                $found = true;
     549                $last_index = $index;
    541550                $author_match = empty( $matches[2] ) ? $matches[1] : $matches[2];
    542551                // assume username syntax if no whitespace is present
    543552                $no_ws = $matched && ! preg_match( '#[\r\n\t ]#', $author_match );
    function get_content_chat( &$content, $remove = false ) { 
    572581        if ( ! empty( $stanza ) )
    573582                $stanzas[] = $stanza;
    574583
    575         if ( $remove )
    576                 $content = trim( join( "\n", array_slice( $lines, $last_index ) ) );
     584        if ( $remove ) {
     585                if ( 0 === $found_index ) {
     586                        $removed = array_slice( $lines, $last_index );
     587                } else {
     588                        $before = array_slice( $lines, 0, $found_index );
     589                        $after = array_slice( $lines, $last_index + 1 );
     590                        $removed = array_filter( array_merge( $before, $after ) );
     591                }
     592                $content = trim( join( "\n", $removed ) );
     593        }
    577594
    578595        return $stanzas;
    579596}