rewrote convert_chars - hi again guys! :)

git-svn-id: http://svn.automattic.com/wordpress/trunk@306 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
michelvaldrighi 2003-08-12 16:43:24 +00:00
parent 805ab8be54
commit 3f3adc6824

View File

@ -196,76 +196,36 @@ function get_weekstartend($mysqlstring, $start_of_week) {
return $week; return $week;
} }
function convert_chars($content,$flag="html") { // html/unicode entities output, defaults to html function convert_chars($content,$flag='obsolete attribute left there for backwards compatibility') { // html/unicode entities output
$newcontent = "";
global $convert_chars2unicode, $convert_entities2unicode, $leavecodealone, $use_htmltrans; global $use_htmltrans, $b2_htmltrans, $b2_htmltranswinuni;
global $b2_htmltrans, $b2_htmltranswinuni;
// removes metadata tags
$content = preg_replace('/<title>(.+?)<\/title>/','',$content);
$content = preg_replace('/<category>(.+?)<\/category>/','',$content);
if ($use_htmltrans) {
// converts lone & characters into &#38; (a.k.a. &amp;)
$content = preg_replace('/&[^#](?![a-z]*;)/ie', '"&#38;".substr("\0",1)', $content);
// converts HTML-entities to their display values in order to convert them again later
$content = preg_replace('/['.chr(127).'-'.chr(255).']/e', '"&#".ord(\0).";"', $content );
$content = strtr($content, $b2_htmltrans);
// now converting: Windows CP1252 => Unicode (valid HTML)
// (if you've ever pasted text from MSWord, you'll understand)
$content = strtr($content, $b2_htmltranswinuni);
### this is temporary - will be replaced by proper config stuff
$convert_chars2unicode = 1;
if (($leavecodealone) || (!$use_htmltrans)) {
$convert_chars2unicode = 0;
} }
###
// you can delete these 2 lines if you don't like <br /> and <hr />
// converts HTML-entities to their display values in order to convert them again later $content = str_replace("<br>","<br />",$content);
$content = str_replace("<hr>","<hr />",$content);
$content = preg_replace("/<title>(.+?)<\/title>/","",$content);
$content = preg_replace("/<category>(.+?)<\/category>/","",$content);
# $content = str_replace("&amp;","&#38;",$content);
$content = strtr($content, $b2_htmltrans);
return $content; return $content;
// the following is the slowest. code. ever.
/*
for ($i=0; $i<strlen($content); $i=$i+1) {
$j = substr($content,$i,1);
$jnext = substr($content,$i+1,1);
$jord = ord($j);
if ($convert_chars2unicode) {
switch($flag) {
case "unicode":
// $j = str_replace("&","&#38;",$j);
if (($jord>=128) || ($j == "&") || (($jord>=128) && ($jord<=159))) {
$j = "&#".$jord.";";
}
break;
case "html":
if (($jord>=128) || (($jord>=128) && ($jord<=159))) {
$j = "&#".$jord.";"; // $j = htmlentities($j);
} elseif (($j == "&") && ($jnext != "#")) {
$j = "&amp;";
}
break;
case "xml":
if ($jord>=128) {
$j = "&#".$jord.";"; // $j = htmlentities($j);
// $j = htmlentities($j);
} elseif (($j == "&") && ($jnext != "#")) {
$j = "&#38;";
}
break;
}
}
$newcontent .= $j;
}
// now converting: Windows CP1252 => Unicode (valid HTML)
// (if you've ever pasted text from MSWord, you'll understand)
$newcontent = strtr($newcontent, $b2_htmltranswinuni);
// you can delete these 2 lines if you don't like <br /> and <hr />
$newcontent = str_replace("<br>","<br />",$newcontent);
$newcontent = str_replace("<hr>","<hr />",$newcontent);
return $newcontent;
*/
} }
function convert_bbcode($content) { function convert_bbcode($content) {