From 382606fb71a6b0192c8b40d362b12d6b017ac144 Mon Sep 17 00:00:00 2001 From: "Pierre Habouzit (MadCoder" Date: Tue, 24 May 2005 07:13:23 +0000 Subject: [PATCH] =?utf8?q?=A4=20thing=20+=20#294?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-archimport-id: opensource@polytechnique.org--2005/banana--mainline--1.0--patch-18 --- Changelog | 8 +++++ banana/misc.inc.php | 5 +++ banana/post.inc.php | 3 +- banana/spool.inc.php | 1 + banana/utf8.php | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 banana/utf8.php diff --git a/Changelog b/Changelog index f06f42f..b950355 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,12 @@ ================================================================================ +VERSION 1.1 + +Tue, 24 May 2005 Pierre Habouzit + + * Fix one problem with $this->ids beeing empty in Spool. + * Fix encoding issues since iconv truncates strings sometimes. + +================================================================================ VERSION 1.0 Fri, 07 Jan 2005 Pierre Habouzit diff --git a/banana/misc.inc.php b/banana/misc.inc.php index a72e6cf..ea88ccd 100644 --- a/banana/misc.inc.php +++ b/banana/misc.inc.php @@ -13,6 +13,11 @@ function _b_($str) { return utf8_decode(dgettext('banana', utf8_encode($str))); } +function to_html($str, $charset) { + require_once 'banana/utf8.php'; + return utf8entities(htmlentities(iconv($charset, 'utf8', $str), ENT_NOQUOTES, 'UTF-8')); +} + /******************************************************************************** * HEADER STUFF */ diff --git a/banana/post.inc.php b/banana/post.inc.php index 340d218..60f2986 100644 --- a/banana/post.inc.php +++ b/banana/post.inc.php @@ -44,7 +44,8 @@ class BananaPost } if (preg_match('!charset=([^;]*)\s*(;|$)!', $this->headers['content-type'], $matches)) { - $this->body = iconv($matches[1], 'iso-8859-15', $this->body); + require_once 'banana/misc.inc.php'; + $this->body = to_html($this->body, $matches[1]); } } diff --git a/banana/spool.inc.php b/banana/spool.inc.php index 1f9777d..f199342 100644 --- a/banana/spool.inc.php +++ b/banana/spool.inc.php @@ -202,6 +202,7 @@ class BananaSpool if (empty($since)) { return; } if (is_array($newpostsids = $banana->nntp->newnews($since, $this->group))) { + if (!is_array($this->ids)) { $this->ids = array(); } $newpostsids = array_intersect($newpostsids, array_keys($this->ids)); foreach ($newpostsids as $mid) { $this->overview[$this->ids[$mid]]->isread = false; diff --git a/banana/utf8.php b/banana/utf8.php new file mode 100644 index 0000000..6a9fb51 --- /dev/null +++ b/banana/utf8.php @@ -0,0 +1,88 @@ += 240) && ($asciiPos <= 255)) // 4 chars representing one unicode character + $i=4; + else if (($asciiPos >= 224) && ($asciiPos <= 239)) // 3 chars representing one unicode character + $i=3; + else if (($asciiPos >= 192) && ($asciiPos <= 223)) // 2 chars representing one unicode character + $i=2; + else // 1 char (lower ascii) + $i=1; + $thisLetter = substr($source, $pos, $i); + $pos += $i; + + // process the string representing the letter to a unicode entity + $thisLen = strlen($thisLetter); + $thisPos = 0; + $decimalCode = 0; + while ($thisPos < $thisLen) + { + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); + if ($thisPos == 0) + { + $charNum = intval($thisCharOrd - $decrement[$thisLen]); + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); + } + else + { + $charNum = intval($thisCharOrd - 128); + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); + } + + $thisPos++; + } + + $encodedLetter = '&#'. str_pad($decimalCode, ($thisLen==1)?3:5, '0', STR_PAD_LEFT).';'; + $encodedString .= $encodedLetter; + } + + return $encodedString; +} + +?> -- 2.1.4