From 5c13fbc204fd8f6106e39a92d6618023d56f8858 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Fri, 31 Dec 2004 15:04:42 +0000 Subject: [PATCH] RESOLVE MAJOR BOTTOLNECK (and even bugs) of banana : building the Whole spool for xorg.promo.2002 with more than 1800 posts takes less than 3 secs !!! the 2 array_map of the headerDecode function took more than 11secs before to do their job (for the both) ---> now it takes less than the second ! oh yeah ! --- include/encoding.inc.php | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/include/encoding.inc.php b/include/encoding.inc.php index 256146e..9d30000 100644 --- a/include/encoding.inc.php +++ b/include/encoding.inc.php @@ -11,36 +11,14 @@ * @param STRING $_value string to decode */ -function headerDecode($_value) { - if (eregi('=\?.*\?.\?.*\?=',$_value)) { // is there anything encoded ? - if (eregi('=\?(.*)\?Q\?.*\?=',$_value,$charset)) { // quoted-printable decoding - $result1 = eregi_replace('(.*)=\?.*\?Q\?(.*)\?=(.*)','\1',$_value); - $result2 = eregi_replace('(.*)=\?.*\?Q\?(.*)\?=(.*)','\2',$_value); - $result3 = eregi_replace('(.*)=\?.*\?Q\?(.*)\?=(.*)','\3',$_value); - $result2 = str_replace("_"," ",quoted_printable_decode($result2)); - if ($charset[1] == "UTF-8") { - $result2 = utf8_decode($result2); - } - $newvalue = $result1.$result2.$result3; - } - if (eregi('=\?(.*)\?B\?.*\?=',$_value,$charset)) { // base64 decoding - $result1 = eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\1',$_value); - $result2 = eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\2',$_value); - $result3 = eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\3',$_value); - $result2 = base64_decode($result2); - if ($charset[1] == "UTF-8") { - $result2 = utf8_decode($result2); - } - $newvalue = $result1.$result2.$result3; - } - if (!isset($newvalue)) { // nothing of the above, must be an unknown encoding... - $newvalue = $_value; - } else { - $newvalue=headerDecode($newvalue); // maybe there are more encoded - } - return($newvalue); // parts - } else { // there wasn't anything encoded, return the original string - return($_value); - } +function _headerdecode($charset, $c, $str) { + $s = ($c == 'Q') ? quoted_printable_decode($str) : base64_decode($str); + $s = iconv($charset, 'iso-8859-15', $s); + return str_replace('_', ' ', $s); +} + +function headerDecode($value) { + $val = preg_replace('/(=\?[^?]*\?[BQ]\?[^?]*\?=) (=\?[^?]*\?[BQ]\?[^?]*\?=)/', '\1\2', $value); + return preg_replace('/=\?([^?]*)\?([BQ])\?([^?]*)\?=/e', '_headerdecode("\1", "\2", "\3")', $val); } ?> -- 2.1.4