Make WordPress Core

Changeset 23978


Ignore:
Timestamp:
04/12/2013 10:22:41 PM (12 years ago)
Author:
markjaquith
Message:

Fix some Skype chat parsing issues.

props wonderboymusic. see #23625.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-formats.php

    r23935 r23978  
    454454}
    455455add_chat_detection_format( 'IM', '#^([^:]+):#', '#[:]#' );
    456 add_chat_detection_format( 'Skype', '#^(\[.+?\])\s([^:]+):#', '#[:]#' );
     456add_chat_detection_format( 'Skype', '#(\[.+?\])\s([^:]+):#', '#[:]#' );
    457457
    458458/**
     
    493493    global $_wp_chat_parsers;
    494494
    495     $trimmed = trim( $content );
     495    $trimmed = strip_tags( trim( $content ) );
    496496    if ( empty( $trimmed ) )
    497497        return 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(
     
    528532
    529533            $stanzas[] = $stanza;
    530             $last_index = $index;
     534
    531535            $stanza = $data = array();
    532536            $author = $time = '';
     
    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
     
    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;
Note: See TracChangeset for help on using the changeset viewer.