Ticket #31242: 31242.3.diff
File 31242.3.diff, 4.3 KB (added by , 10 years ago) |
---|
-
src/wp-includes/formatting.php
4106 4106 * 4107 4107 * @since 4.2.0 4108 4108 * 4109 * @param string $ content The content to encode.4109 * @param string $text The content to encode. 4110 4110 * @return string The encoded content. 4111 4111 */ 4112 function wp_staticize_emoji( $ content ) {4113 $ content = wp_encode_emoji( $content );4112 function wp_staticize_emoji( $text ) { 4113 $text = wp_encode_emoji( $text ); 4114 4114 4115 4115 if ( ! class_exists( 'DOMDocument' ) ) { 4116 return $ content;4116 return $text; 4117 4117 } 4118 4118 4119 4119 /** This filter is documented in wp-includes/script-loader.php */ … … 4121 4121 /** This filter is documented in wp-includes/script-loader.php */ 4122 4122 $ext = apply_filters( 'emoji_ext', '.png' ); 4123 4123 4124 $html = '<!DOCTYPE html><html><head></head><body>' . $content . '</body></html>'; 4124 $output = ''; 4125 // HTML loop taken from smiley function, which was taking from texturize function. It'll never be consolidated. 4126 $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between 4127 $stop = count( $textarr );// loop stuff 4125 4128 4126 $document = new DOMDocument; 4127 if ( ! $document->loadHTML( $html ) ) { 4128 return $content; 4129 } 4129 // Ignore proessing of specific tags 4130 $tags_to_ignore = 'code|pre|style|script|textarea'; 4131 $ignore_block_element = ''; 4130 4132 4131 $xpath = new DOMXPath( $document );4132 $textnodes = $xpath->query( '//text()' );4133 for ( $i = 0; $i < $stop; $i++ ) { 4134 $content = $textarr[$i]; 4133 4135 4134 foreach( $textnodes as $node ) { 4135 $originalText = $text = wp_encode_emoji( $node->nodeValue ); 4136 // If we're in an ignore block, wait until we find its closing tag 4137 if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) { 4138 $ignore_block_element = $matches[1]; 4139 } 4136 4140 4137 $matches = array(); 4138 if ( preg_match_all( '/(DZ(e[6-9a-f]|f[0-9a-f]);){2}/', $text, $matches ) ) { 4139 if ( ! empty( $matches[0] ) ) { 4140 foreach ( $matches[0] as $flag ) { 4141 $chars = str_replace( array( '&#x', ';'), '', $flag ); 4141 // If it's not a tag and not in ignore block 4142 if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) { 4143 $matches = array(); 4144 if ( preg_match_all( '/(DZ(e[6-9a-f]|f[0-9a-f]);){2}/', $content, $matches ) ) { 4145 if ( ! empty( $matches[0] ) ) { 4146 foreach ( $matches[0] as $flag ) { 4147 $chars = str_replace( array( '&#x', ';'), '', $flag ); 4142 4148 4143 list( $char1, $char2 ) = str_split( $chars, 5 );4144 $entity = '<img src="https:' . $cdn_url . $char1 . '-' . $char2 . $ext . '" class="wp-smiley" style="height: 1em;" />';4149 list( $char1, $char2 ) = str_split( $chars, 5 ); 4150 $entity = '<img src="https:' . $cdn_url . $char1 . '-' . $char2 . $ext . '" class="wp-smiley" style="height: 1em;" />'; 4145 4151 4146 $text = str_replace( $flag, $entity, $text ); 4152 $content = str_replace( $flag, $entity, $content ); 4153 } 4147 4154 } 4148 4155 } 4149 }4150 4156 4151 // Loosely match the Emoji Unicode range.4152 $regex = '/(&#x[2-3][0-9a-f]{3};|[1-6][0-9a-f]{2};)/';4157 // Loosely match the Emoji Unicode range. 4158 $regex = '/(&#x[2-3][0-9a-f]{3};|[1-6][0-9a-f]{2};)/'; 4153 4159 4154 $matches = array();4155 if ( preg_match_all( $regex, $text, $matches ) ) {4156 if ( ! empty( $matches[1] ) ) {4157 foreach ( $matches[1] as $emoji ) {4158 $char = str_replace( array( '&#x', ';'), '', $emoji );4159 $entity = '<img src="https:' . $cdn_url . $char . $ext . '" class="wp-smiley" style="height: 1em;" />';4160 $matches = array(); 4161 if ( preg_match_all( $regex, $content, $matches ) ) { 4162 if ( ! empty( $matches[1] ) ) { 4163 foreach ( $matches[1] as $emoji ) { 4164 $char = str_replace( array( '&#x', ';'), '', $emoji ); 4165 $entity = '<img src="https:' . $cdn_url . $char . $ext . '" class="wp-smiley" style="height: 1em;" />'; 4160 4166 4161 $text = str_replace( $emoji, $entity, $text ); 4167 $content = str_replace( $emoji, $entity, $content ); 4168 } 4162 4169 } 4163 4170 } 4164 4171 } 4165 4172 4166 if ( $originalText !== $text ) { 4167 $content = str_replace( $originalText, $text, $content ); 4173 // did we exit ignore block 4174 if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) { 4175 $ignore_block_element = ''; 4168 4176 } 4177 4178 $output .= $content; 4169 4179 } 4170 4180 4171 return $ content;4181 return $output; 4172 4182 } 4173 4183 4174 4184 /**