Changeset 4511
- Timestamp:
- 11/21/2006 10:00:10 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/formatting.php
r4495 r4511 3 3 function wptexturize($text) { 4 4 global $wp_cockneyreplace; 5 $next = true; 5 6 $output = ''; 6 // Capture tags and everything inside them 7 $textarr = preg_split("/(<.*>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE); 8 $stop = count($textarr); $next = true; // loop stuff 9 for ($i = 0; $i < $stop; $i++) { 10 $curl = $textarr[$i]; 7 $curl = ''; 8 $textarr = preg_split('/(<.*>)/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); 9 $stop = count($textarr); 10 11 // if a plugin has provided an autocorrect array, use it 12 if ( isset($wp_cockneyreplace) ) { 13 $cockney = array_keys($wp_cockneyreplace); 14 $cockney_replace = array_values($wp_cockneyreplace); 15 } else { 16 $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause"); 17 $cockneyreplace = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round","’cause"); 18 } 19 20 $static_characters = array_merge(array('---', ' -- ', '--', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney); 21 $static_replacements = array_merge(array('—', ' — ', '–', 'xn--', '…', '“', '’s', '”', ' ™'), $cockneyreplace); 22 23 $dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/(\s|\A|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A)"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/'); 24 $dynamic_replacements = array('’$1','$1‘', '$1″', '$1′', '$1’$2', '$1“$2', '”$1', '’$1', '$1×$2'); 25 26 for ( $i = 0; $i < $stop; $i++ ) { 27 $curl = $textarr[$i]; 11 28 12 29 if (isset($curl{0}) && '<' != $curl{0} && $next) { // If it's not a tag 13 $curl = str_replace('---', '—', $curl); 14 $curl = str_replace(' -- ', ' — ', $curl); 15 $curl = str_replace('--', '–', $curl); 16 $curl = str_replace('xn–', 'xn--', $curl); 17 $curl = str_replace('...', '…', $curl); 18 $curl = str_replace('``', '“', $curl); 19 20 // if a plugin has provided an autocorrect array, use it 21 if ( isset($wp_cockneyreplace) ) { 22 $cockney = array_keys($wp_cockneyreplace); 23 $cockney_replace = array_values($wp_cockneyreplace); 24 } else { 25 $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause"); 26 $cockneyreplace = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round","’cause"); 27 } 28 29 $curl = str_replace($cockney, $cockneyreplace, $curl); 30 31 $curl = preg_replace("/'s/", '’s', $curl); 32 $curl = preg_replace("/'(\d\d(?:’|')?s)/", "’$1", $curl); 33 $curl = preg_replace('/(\s|\A|")\'/', '$1‘', $curl); 34 $curl = preg_replace('/(\d+)"/', '$1″', $curl); 35 $curl = preg_replace("/(\d+)'/", '$1′', $curl); 36 $curl = preg_replace("/(\S)'([^'\s])/", "$1’$2", $curl); 37 $curl = preg_replace('/(\s|\A)"(?!\s)/', '$1“$2', $curl); 38 $curl = preg_replace('/"(\s|\S|\Z)/', '”$1', $curl); 39 $curl = preg_replace("/'([\s.]|\Z)/", '’$1', $curl); 40 $curl = preg_replace("/ \(tm\)/i", ' ™', $curl); 41 $curl = str_replace("''", '”', $curl); 42 43 $curl = preg_replace('/(\d+)x(\d+)/', "$1×$2", $curl); 44 30 // static strings 31 $curl = str_replace($static_characters, $static_replacements, $curl); 32 33 // regular expressions 34 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 45 35 } elseif (strstr($curl, '<code') || strstr($curl, '<pre') || strstr($curl, '<kbd' || strstr($curl, '<style') || strstr($curl, '<script'))) { 46 // strstr is fast47 36 $next = false; 48 37 } else { 49 38 $next = true; 50 39 } 40 51 41 $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&$1', $curl); 52 42 $output .= $curl; 53 43 } 54 return $output; 44 45 return $output; 55 46 } 56 47
Note: See TracChangeset
for help on using the changeset viewer.