Ticket #33106: 33106.2.patch
File 33106.2.patch, 3.5 KB (added by , 10 years ago) |
---|
-
src/wp-includes/class-wp-embed.php
318 318 * @return string Potentially modified $content. 319 319 */ 320 320 public function autoembed( $content ) { 321 // Strip newlines from all elements. 322 $content = wp_replace_in_html_tags( $content, array( "\n" => " " ) ); 321 // Avoid multiline elements and comments. 322 $content = wp_html_split( $content ); 323 for ( $i = 0, $c = count( $content ); $i < $c; $i += 2 ) { 324 325 if ( '' == $content[$i] ) continue; 323 326 324 // Find URLs that are on their own line. 325 return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); 327 // Find URLs that are on their own line. 328 $content[$i] = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content[$i] ); 329 330 } 331 332 return implode( $content ); 326 333 } 327 334 328 335 /** -
src/wp-includes/formatting.php
596 596 } 597 597 598 598 /** 599 * Replace characters or phrases within HTML elements only.599 * Separate HTML elements and comments from the text. 600 600 * 601 * @since 4.2. 3601 * @since 4.2.4 602 602 * 603 * @param string $haystack The text which has to be formatted. 604 * @param array $replace_pairs In the form array('from' => 'to', ...). 603 * @param string $input The text which has to be formatted. 605 604 * @return string The formatted text. 606 605 */ 607 function wp_ replace_in_html_tags( $haystack, $replace_pairs) {606 function wp_html_split( $input ) { 608 607 // Find all elements. 609 608 $comments = 610 609 '!' // Start of comment, after the <. … … 614 613 . ')*+' // Loop possessively. 615 614 . '(?:-->)?'; // End of comment. If not found, match all input. 616 615 616 $cdata = 617 '!\[CDATA\[' // Start of comment, after the <. 618 . '[^\]]*+' // Consume non-]. 619 . '(?:' // Unroll the loop: Consume everything until ]]> is found. 620 . '](?!]>)' // One ] not followed by end of comment. 621 . '[^\]]*+' // Consume non-]. 622 . ')*+' // Loop possessively. 623 . '(?:]]>)?'; // End of comment. If not found, match all input. 624 617 625 $regex = 618 626 '/(' // Capture the entire match. 619 627 . '<' // Find start of element. … … 620 628 . '(?(?=!--)' // Is this a comment? 621 629 . $comments // Find end of comment. 622 630 . '|' 623 . '[^>]*>?' // Find end of element. If not found, match all input. 631 . '(?(?=!\[CDATA\[)' // Is this a comment? 632 . $cdata // Find end of comment. 633 . '|' 634 . '[^>]*>?' // Find end of element. If not found, match all input. 635 . ')' 624 636 . ')' 625 637 . ')/s'; 626 638 627 $textarr = preg_split( $regex, $haystack, -1, PREG_SPLIT_DELIM_CAPTURE ); 639 return preg_split( $regex, $input, -1, PREG_SPLIT_DELIM_CAPTURE ); 640 } 641 642 /** 643 * Replace characters or phrases within HTML elements only. 644 * 645 * @since 4.2.3 646 * 647 * @param string $haystack The text which has to be formatted. 648 * @param array $replace_pairs In the form array('from' => 'to', ...). 649 * @return string The formatted text. 650 */ 651 function wp_replace_in_html_tags( $haystack, $replace_pairs ) { 652 // Find all elements. 653 $textarr = wp_html_split( $haystack ); 628 654 $changed = false; 629 655 630 656 // Optimize when searching for one item.