diff --git a/b2-include/b2functions.php b/b2-include/b2functions.php index 7ed9204ba1..877cab5c37 100644 --- a/b2-include/b2functions.php +++ b/b2-include/b2functions.php @@ -48,6 +48,55 @@ function mysql_oops($query) { /***** Formatting functions *****/ +function wptexturize($text) { + $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between + $stop = count($textarr); $next = true; // loop stuff + for ($i = 0; $i < $stop; $i++) { + $curl = $textarr[$i]; + if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko')) { + $curl = str_replace('', '“', $curl); + $curl = str_replace('', '”', $curl); + } + if ('<' != $curl{0} && $next) { // If it's not a tag + $curl = str_replace('---', '—', $curl); + $curl = str_replace('--', '–', $curl); + $curl = str_replace("...", '…', $curl); + $curl = str_replace('``', '“', $curl); + + // This is a hack, look at this more later. It works pretty well though. + $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round"); + $cockneyreplace = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round"); + $curl = str_replace($cockney, $cockneyreplace, $curl); + + + $curl = preg_replace("/'s/", "’s", $curl); + $curl = preg_replace("/'(\d\d(?:’|')?s)/", "’$1", $curl); + $curl = preg_replace('/(\s|\A|")\'/', '$1‘', $curl); + $curl = preg_replace("/(\d+)\"/", "$1″", $curl); + $curl = preg_replace("/(\d+)'/", "$1′", $curl); + $curl = preg_replace("/(\S)'([^'\s])/", "$1’$2", $curl); + $curl = preg_replace('/"([\s.]|\Z)/', '”$1', $curl); + $curl = preg_replace('/(\s|\A)"/', '$1“', $curl); + $curl = preg_replace("/'([\s.]|\Z)/", '’$1', $curl); + $curl = preg_replace("/\(tm\)/i", '™', $curl); + $curl = preg_replace("/\(c\)/i", '©', $curl); + $curl = preg_replace("/\(r\)/i", '®', $curl); + + $curl = str_replace("''", '”', $curl); + $curl = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $curl); + + $curl = preg_replace('/(d+)x(\d+)/', "$1×$2", $curl); + + } elseif (strstr($curl, '\n/", "\n", $content);