Ticket #33106: 33106.4.patch
File 33106.4.patch, 4.3 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] || false === strpos( $content[$i], 'http' ) ) { 326 continue; 327 } 323 328 324 // Find URLs that are on their own line. 325 return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); 329 // Find URLs that are on their own line. 330 $content[$i] = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content[$i] ); 331 332 } 333 334 return implode( $content ); 326 335 } 327 336 328 337 /** -
src/wp-includes/formatting.php
504 504 // Standardize newline characters to "\n". 505 505 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); 506 506 507 // Strip newlines from all elements.508 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) );507 // Find newlines in all elements and add placeholders. 508 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " <!-- wpnl --> " ) ); 509 509 510 510 // Collapse line breaks before and after <option> elements so they don't get autop'd. 511 511 if ( strpos( $pee, '<option' ) !== false ) { … … 592 592 if ( !empty($pre_tags) ) 593 593 $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee); 594 594 595 // Restore newlines in all elements. 596 $pee = str_replace( " <!-- wpnl --> ", "\n", $pee ); 597 595 598 return $pee; 596 599 } 597 600 598 601 /** 599 * Replace characters or phrases within HTML elements only.602 * Separate HTML elements and comments from the text. 600 603 * 601 * @since 4.2. 3604 * @since 4.2.4 602 605 * 603 * @param string $haystack The text which has to be formatted. 604 * @param array $replace_pairs In the form array('from' => 'to', ...). 605 * @return string The formatted text. 606 * @param string $input The text which has to be formatted. 607 * @return array The formatted text. 606 608 */ 607 function wp_ replace_in_html_tags( $haystack, $replace_pairs) {609 function wp_html_split( $input ) { 608 610 // Find all elements. 609 611 $comments = 610 612 '!' // Start of comment, after the <. … … 614 616 . ')*+' // Loop possessively. 615 617 . '(?:-->)?'; // End of comment. If not found, match all input. 616 618 619 $cdata = 620 '!\[CDATA\[' // Start of comment, after the <. 621 . '[^\]]*+' // Consume non-]. 622 . '(?:' // Unroll the loop: Consume everything until ]]> is found. 623 . '](?!]>)' // One ] not followed by end of comment. 624 . '[^\]]*+' // Consume non-]. 625 . ')*+' // Loop possessively. 626 . '(?:]]>)?'; // End of comment. If not found, match all input. 627 617 628 $regex = 618 629 '/(' // Capture the entire match. 619 630 . '<' // Find start of element. … … 620 631 . '(?(?=!--)' // Is this a comment? 621 632 . $comments // Find end of comment. 622 633 . '|' 623 . '[^>]*>?' // Find end of element. If not found, match all input. 634 . '(?(?=!\[CDATA\[)' // Is this a comment? 635 . $cdata // Find end of comment. 636 . '|' 637 . '[^>]*>?' // Find end of element. If not found, match all input. 638 . ')' 624 639 . ')' 625 640 . ')/s'; 626 641 627 $textarr = preg_split( $regex, $haystack, -1, PREG_SPLIT_DELIM_CAPTURE ); 642 return preg_split( $regex, $input, -1, PREG_SPLIT_DELIM_CAPTURE ); 643 } 644 645 /** 646 * Replace characters or phrases within HTML elements only. 647 * 648 * @since 4.2.3 649 * 650 * @param string $haystack The text which has to be formatted. 651 * @param array $replace_pairs In the form array('from' => 'to', ...). 652 * @return string The formatted text. 653 */ 654 function wp_replace_in_html_tags( $haystack, $replace_pairs ) { 655 // Find all elements. 656 $textarr = wp_html_split( $haystack ); 628 657 $changed = false; 629 658 630 659 // Optimize when searching for one item.