================================================================================
+VERSION 1.1
+
+Tue, 24 May 2005 Pierre Habouzit <pierre.habouzit@m4x.org>
+
+ * 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 <pierre.habouzit@m4x.org>
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
*/
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;
--- /dev/null
+<?php\r
+\r
+/**\r
+ * Transforme une chaine encodée en UTF-8, et la convertit\r
+ * en entitiées unicode &#xxx; pour que ça s'affiche correctement\r
+ * dans les navigateurs, sans forcément tenir compte du meta\r
+ * content-type charset...\r
+ * @param String $source la chaine en UTF-8\r
+ * @return String les entitées\r
+ * @access public\r
+ * @see http://www.php.net/utf8_decode\r
+ */\r
+function utf8entities($source)\r
+{\r
+ // array used to figure what number to decrement from character order value \r
+ // according to number of characters used to map unicode to ascii by utf-8\r
+ $decrement[4] = 240;\r
+ $decrement[3] = 224;\r
+ $decrement[2] = 192;\r
+ $decrement[1] = 0;\r
+ \r
+ // the number of bits to shift each charNum by\r
+ $shift[1][0] = 0;\r
+ $shift[2][0] = 6;\r
+ $shift[2][1] = 0;\r
+ $shift[3][0] = 12;\r
+ $shift[3][1] = 6;\r
+ $shift[3][2] = 0;\r
+ $shift[4][0] = 18;\r
+ $shift[4][1] = 12;\r
+ $shift[4][2] = 6;\r
+ $shift[4][3] = 0;\r
+ \r
+ $pos = 0;\r
+ $len = strlen($source);\r
+ $encodedString = '';\r
+ while ($pos < $len)\r
+ {\r
+ $charPos = $source{$pos};\r
+ $asciiPos = ord($charPos);\r
+ if ($asciiPos < 128)\r
+ {\r
+ $encodedString .= $charPos;\r
+ $pos++;\r
+ continue;\r
+ }\r
+ \r
+ $i=1;\r
+ if (($asciiPos >= 240) && ($asciiPos <= 255)) // 4 chars representing one unicode character\r
+ $i=4;\r
+ else if (($asciiPos >= 224) && ($asciiPos <= 239)) // 3 chars representing one unicode character\r
+ $i=3;\r
+ else if (($asciiPos >= 192) && ($asciiPos <= 223)) // 2 chars representing one unicode character\r
+ $i=2;\r
+ else // 1 char (lower ascii)\r
+ $i=1;\r
+ $thisLetter = substr($source, $pos, $i);\r
+ $pos += $i;\r
+ \r
+ // process the string representing the letter to a unicode entity\r
+ $thisLen = strlen($thisLetter);\r
+ $thisPos = 0;\r
+ $decimalCode = 0;\r
+ while ($thisPos < $thisLen)\r
+ {\r
+ $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));\r
+ if ($thisPos == 0)\r
+ {\r
+ $charNum = intval($thisCharOrd - $decrement[$thisLen]);\r
+ $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);\r
+ }\r
+ else\r
+ {\r
+ $charNum = intval($thisCharOrd - 128);\r
+ $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);\r
+ }\r
+ \r
+ $thisPos++;\r
+ }\r
+ \r
+ $encodedLetter = '&#'. str_pad($decimalCode, ($thisLen==1)?3:5, '0', STR_PAD_LEFT).';';\r
+ $encodedString .= $encodedLetter;\r
+ }\r
+ \r
+ return $encodedString;\r
+}\r
+\r
+?>\r