Ticket #6464: faster-smilies2.patch
File faster-smilies2.patch, 4.5 KB (added by , 17 years ago) |
---|
-
wp-includes/functions.php
2366 2366 return $input; 2367 2367 } 2368 2368 2369 2369 2370 /** 2370 2371 * Convert smiley code to the icon graphic file equivalent. 2371 2372 * … … 2376 2377 * to an array, with the key the code the blogger types in and the value the 2377 2378 * image file. 2378 2379 * 2379 * The $wp_smiliessearch global is for the regular expression array and is 2380 * set each time the function is called. The $wp_smiliesreplace is the full 2381 * replacement. Supposely, the $wp_smiliessearch array is looped over using 2382 * preg_replace() or just setting the array of $wp_smiliessearch along with the 2383 * array of $wp_smiliesreplace in the search and replace parameters of 2384 * preg_replace(), which would be faster and less overhead. Either way, both are 2385 * used with preg_replace() and can be defined after the function is called. 2380 * The $wp_smiliessearch global is for the regular expression and is set each 2381 * time the function is called. 2386 2382 * 2387 2383 * The full list of smilies can be found in the function and won't be listed in 2388 2384 * the description. Probably should create a Codex page for it, so that it is … … 2449 2445 ); 2450 2446 } 2451 2447 2452 $siteurl = get_option( 'siteurl' ); 2448 if (count($wpsmiliestrans) == 0) { 2449 return; 2450 } 2451 2452 ksort($wpsmiliestrans); 2453 2454 $wp_smiliessearch = '/(\s|^)'; 2455 2456 $subchar = ''; 2453 2457 foreach ( (array) $wpsmiliestrans as $smiley => $img ) { 2454 $wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/'; 2455 $smiley_masked = attribute_escape( trim( $smiley ) ); 2456 $wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> "; 2458 $firstchar = substr($smiley, 0, 1); 2459 $rest = substr($smiley, 1); 2460 2461 // new subpattern? 2462 if ($firstchar != $subchar) { 2463 if ($subchar != '') { 2464 $wp_smiliessearch .= ')|'; 2465 } 2466 $subchar = $firstchar; 2467 $wp_smiliessearch .= preg_quote($firstchar, '/') . '('; 2468 } else { 2469 $wp_smiliessearch .= '|'; 2470 } 2471 $wp_smiliessearch .= preg_quote($rest); 2457 2472 } 2473 2474 $wp_smiliessearch .= ')(\s|$)/'; 2458 2475 } 2459 2476 2460 2477 /** -
wp-includes/formatting.php
1218 1218 return "<a $text rel=\"nofollow\">"; 1219 1219 } 1220 1220 1221 1221 1222 /** 1223 * Convert one smiley code to the icon graphic file equivalent. 1224 * 1225 * Looks up one smiley code in the $wpsmiliestrans global array and returns an 1226 * <img> string for that smiley. 1227 * 1228 * @global array $wpsmiliestrans 1229 * @since 2.8.0 1230 * 1231 * @param string $smiley Smiley code to convert to image. 1232 * @return string Image string for smiley. 1233 */ 1234 function translate_smiley($smiley) { 1235 global $wpsmiliestrans; 1236 1237 if (count($smiley) == 0) { 1238 return ''; 1239 } 1240 1241 $smiley = trim(reset($smiley)); 1242 1243 $siteurl = get_option( 'siteurl' ); 1244 1245 $img = $wpsmiliestrans[$smiley]; 1246 1247 $smiley_masked = attribute_escape($smiley); 1248 1249 return " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> "; 1250 } 1251 1252 1253 /** 1222 1254 * Convert text equivalent of smilies to images. 1223 1255 * 1224 * Will only convert smilies if the option 'use_smilies' is true and the global s1225 * used in the function aren't empty.1256 * Will only convert smilies if the option 'use_smilies' is true and the global 1257 * used in the function isn't empty. 1226 1258 * 1227 1259 * @since 0.71 1228 * @uses $wp_smiliessearch , $wp_smiliesreplace Smiley replacement arrays.1260 * @uses $wp_smiliessearch 1229 1261 * 1230 1262 * @param string $text Content to convert smilies from text. 1231 1263 * @return string Converted content with text smilies replaced with images. … … 1233 1265 function convert_smilies($text) { 1234 1266 global $wp_smiliessearch, $wp_smiliesreplace; 1235 1267 $output = ''; 1236 if ( get_option('use_smilies') && !empty($wp_smiliessearch) && !empty($wp_smiliesreplace)) {1268 if ( get_option('use_smilies') && !empty($wp_smiliessearch) ) { 1237 1269 // HTML loop taken from texturize function, could possible be consolidated 1238 1270 $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between 1239 1271 $stop = count($textarr);// loop stuff 1240 1272 for ($i = 0; $i < $stop; $i++) { 1241 1273 $content = $textarr[$i]; 1242 1274 if ((strlen($content) > 0) && ('<' != $content{0})) { // If it's not a tag 1243 $content = preg_replace ($wp_smiliessearch, $wp_smiliesreplace, $content);1275 $content = preg_replace_callback($wp_smiliessearch, 'translate_smiley', $content); 1244 1276 } 1245 1277 $output .= $content; 1246 1278 }