mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-17 20:15:08 +00:00
Backport r33469 and r33470 to 4.1.
See #33106. Built from https://develop.svn.wordpress.org/branches/4.1@33521 git-svn-id: http://core.svn.wordpress.org/branches/4.1@33488 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
cec063ad22
commit
922040e867
@ -312,11 +312,14 @@ class WP_Embed {
|
|||||||
* @return string Potentially modified $content.
|
* @return string Potentially modified $content.
|
||||||
*/
|
*/
|
||||||
public function autoembed( $content ) {
|
public function autoembed( $content ) {
|
||||||
// Strip newlines from all elements.
|
// Replace line breaks from all HTML elements with placeholders.
|
||||||
$content = wp_replace_in_html_tags( $content, array( "\n" => " " ) );
|
$content = wp_replace_in_html_tags( $content, array( "\n" => '<!-- wp-line-break -->' ) );
|
||||||
|
|
||||||
// Find URLs that are on their own line.
|
// Find URLs that are on their own line.
|
||||||
return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content );
|
$content = preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content );
|
||||||
|
|
||||||
|
// Put the line breaks back.
|
||||||
|
return str_replace( '<!-- wp-line-break -->', "\n", $content );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -410,8 +410,8 @@ function wpautop($pee, $br = true) {
|
|||||||
$pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
|
$pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
|
||||||
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
|
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
|
||||||
|
|
||||||
// Strip newlines from all elements.
|
// Find newlines in all elements and add placeholders.
|
||||||
$pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) );
|
$pee = wp_replace_in_html_tags( $pee, array( "\n" => " <!-- wpnl --> " ) );
|
||||||
|
|
||||||
if ( strpos( $pee, '<option' ) !== false ) {
|
if ( strpos( $pee, '<option' ) !== false ) {
|
||||||
// no P/BR around option
|
// no P/BR around option
|
||||||
@ -464,9 +464,59 @@ function wpautop($pee, $br = true) {
|
|||||||
if ( !empty($pre_tags) )
|
if ( !empty($pre_tags) )
|
||||||
$pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
|
$pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
|
||||||
|
|
||||||
|
// Restore newlines in all elements.
|
||||||
|
$pee = str_replace( " <!-- wpnl --> ", "\n", $pee );
|
||||||
|
|
||||||
return $pee;
|
return $pee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Separate HTML elements and comments from the text.
|
||||||
|
*
|
||||||
|
* @since 4.2.4
|
||||||
|
*
|
||||||
|
* @param string $input The text which has to be formatted.
|
||||||
|
* @return array The formatted text.
|
||||||
|
*/
|
||||||
|
function wp_html_split( $input ) {
|
||||||
|
static $regex;
|
||||||
|
|
||||||
|
if ( ! isset( $regex ) ) {
|
||||||
|
$comments =
|
||||||
|
'!' // Start of comment, after the <.
|
||||||
|
. '(?:' // Unroll the loop: Consume everything until --> is found.
|
||||||
|
. '-(?!->)' // Dash not followed by end of comment.
|
||||||
|
. '[^\-]*+' // Consume non-dashes.
|
||||||
|
. ')*+' // Loop possessively.
|
||||||
|
. '(?:-->)?'; // End of comment. If not found, match all input.
|
||||||
|
|
||||||
|
$cdata =
|
||||||
|
'!\[CDATA\[' // Start of comment, after the <.
|
||||||
|
. '[^\]]*+' // Consume non-].
|
||||||
|
. '(?:' // Unroll the loop: Consume everything until ]]> is found.
|
||||||
|
. '](?!]>)' // One ] not followed by end of comment.
|
||||||
|
. '[^\]]*+' // Consume non-].
|
||||||
|
. ')*+' // Loop possessively.
|
||||||
|
. '(?:]]>)?'; // End of comment. If not found, match all input.
|
||||||
|
|
||||||
|
$regex =
|
||||||
|
'/(' // Capture the entire match.
|
||||||
|
. '<' // Find start of element.
|
||||||
|
. '(?(?=!--)' // Is this a comment?
|
||||||
|
. $comments // Find end of comment.
|
||||||
|
. '|'
|
||||||
|
. '(?(?=!\[CDATA\[)' // Is this a comment?
|
||||||
|
. $cdata // Find end of comment.
|
||||||
|
. '|'
|
||||||
|
. '[^>]*>?' // Find end of element. If not found, match all input.
|
||||||
|
. ')'
|
||||||
|
. ')'
|
||||||
|
. ')/s';
|
||||||
|
}
|
||||||
|
|
||||||
|
return preg_split( $regex, $input, -1, PREG_SPLIT_DELIM_CAPTURE );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace characters or phrases within HTML elements only.
|
* Replace characters or phrases within HTML elements only.
|
||||||
*
|
*
|
||||||
@ -478,25 +528,7 @@ function wpautop($pee, $br = true) {
|
|||||||
*/
|
*/
|
||||||
function wp_replace_in_html_tags( $haystack, $replace_pairs ) {
|
function wp_replace_in_html_tags( $haystack, $replace_pairs ) {
|
||||||
// Find all elements.
|
// Find all elements.
|
||||||
$comments =
|
$textarr = wp_html_split( $haystack );
|
||||||
'!' // Start of comment, after the <.
|
|
||||||
. '(?:' // Unroll the loop: Consume everything until --> is found.
|
|
||||||
. '-(?!->)' // Dash not followed by end of comment.
|
|
||||||
. '[^\-]*+' // Consume non-dashes.
|
|
||||||
. ')*+' // Loop possessively.
|
|
||||||
. '(?:-->)?'; // End of comment. If not found, match all input.
|
|
||||||
|
|
||||||
$regex =
|
|
||||||
'/(' // Capture the entire match.
|
|
||||||
. '<' // Find start of element.
|
|
||||||
. '(?(?=!--)' // Is this a comment?
|
|
||||||
. $comments // Find end of comment.
|
|
||||||
. '|'
|
|
||||||
. '[^>]*>?' // Find end of element. If not found, match all input.
|
|
||||||
. ')'
|
|
||||||
. ')/s';
|
|
||||||
|
|
||||||
$textarr = preg_split( $regex, $haystack, -1, PREG_SPLIT_DELIM_CAPTURE );
|
|
||||||
$changed = false;
|
$changed = false;
|
||||||
|
|
||||||
// Optimize when searching for one item.
|
// Optimize when searching for one item.
|
||||||
|
@ -325,29 +325,10 @@ function do_shortcodes_in_html_tags( $content, $ignore_html ) {
|
|||||||
$trans = array( '[' => '[', ']' => ']' );
|
$trans = array( '[' => '[', ']' => ']' );
|
||||||
|
|
||||||
$pattern = get_shortcode_regex();
|
$pattern = get_shortcode_regex();
|
||||||
|
$textarr = wp_html_split( $content );
|
||||||
$comment_regex =
|
|
||||||
'!' // Start of comment, after the <.
|
|
||||||
. '(?:' // Unroll the loop: Consume everything until --> is found.
|
|
||||||
. '-(?!->)' // Dash not followed by end of comment.
|
|
||||||
. '[^\-]*+' // Consume non-dashes.
|
|
||||||
. ')*+' // Loop possessively.
|
|
||||||
. '(?:-->)?'; // End of comment. If not found, match all input.
|
|
||||||
|
|
||||||
$regex =
|
|
||||||
'/(' // Capture the entire match.
|
|
||||||
. '<' // Find start of element.
|
|
||||||
. '(?(?=!--)' // Is this a comment?
|
|
||||||
. $comment_regex // Find end of comment.
|
|
||||||
. '|'
|
|
||||||
. '[^>]*>?' // Find end of element. If not found, match all input.
|
|
||||||
. ')'
|
|
||||||
. ')/s';
|
|
||||||
|
|
||||||
$textarr = preg_split( $regex, $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
|
|
||||||
|
|
||||||
foreach ( $textarr as &$element ) {
|
foreach ( $textarr as &$element ) {
|
||||||
if ( '<' !== $element[0] ) {
|
if ( '' == $element || '<' !== $element[0] ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,7 +343,7 @@ function do_shortcodes_in_html_tags( $content, $ignore_html ) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) ) {
|
if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) || '<![CDATA[' === substr( $element, 0, 9 ) ) {
|
||||||
// Encode all [ and ] chars.
|
// Encode all [ and ] chars.
|
||||||
$element = strtr( $element, $trans );
|
$element = strtr( $element, $trans );
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user