Ticket #31214: 31214.2.diff
File 31214.2.diff, 1.7 KB (added by , 10 years ago) |
---|
-
src/wp-includes/class-oembed.php
563 563 return $html; 564 564 } 565 565 566 $ pre = array();567 $ tokens= array();568 if ( class_exists( 'DOMDocument' ) ) {569 $token = '__PRE__';570 $replace = array();571 $count = 1;566 $count = 1; 567 $found = array(); 568 $token = '__PRE__'; 569 $search = array( "\t", "\n", "\r", ' ' ); 570 $replace = array( '__TAB__', '__NL__', '__CR__', '__SPACE__' ); 571 $tokenized = str_replace( $search, $replace, $html ); 572 572 573 $dom = new DOMDocument(); 574 $dom->loadHTML( $html ); 575 $tags = $dom->getElementsByTagName( 'pre' ); 576 foreach ( $tags as $i => $tag ) { 577 $tag_html = $dom->saveHTML( $tag ); 578 $tag_token = $token . $i; 579 $replace[ $tag_token ] = $tag_html; 573 preg_match_all( '#(<pre[^>]*>.+?</pre>)#i', $tokenized, $matches, PREG_SET_ORDER ); 574 foreach ( $matches as $i => $match ) { 575 $tag_html = str_replace( $replace, $search, $match[0] ); 576 $tag_token = $token . $i; 580 577 581 $html = str_replace( $tag_html, $tag_token, $html, $count ); 582 } 583 $pre = array_values( $replace ); 584 $tokens = array_keys( $replace ); 578 $found[ $tag_token ] = $tag_html; 579 $html = str_replace( $tag_html, $tag_token, $html, $count ); 585 580 } 586 581 587 $stripped = str_replace( array( "\r\n", "\n" ), '', $html ); 582 $replaced = str_replace( $replace, $search, $html ); 583 $stripped = str_replace( array( "\r\n", "\n" ), '', $replaced ); 584 $pre = array_values( $found ); 585 $tokens = array_keys( $found ); 586 588 587 return str_replace( $tokens, $pre, $stripped ); 589 588 } 590 589 }