cvs: php-news-web / article.php common.inc

From: Date: Sun, 25 Sep 2005 19:14:46 +0000
Subject: cvs: php-news-web / article.php common.inc
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-29472@lists.php.net to get a copy of this message
nlopess Sun Sep 25 15:14:46 2005 EDT Modified files: /php-news-web article.php common.inc Log: fix another charset issue. fix a lot of E_NOTICES. add a note about charset conversions http://cvs.php.net/diff.php/php-news-web/article.php?r1=1.33&r2=1.34&ty=u Index: php-news-web/article.php diff -u php-news-web/article.php:1.33 php-news-web/article.php:1.34 --- php-news-web/article.php:1.33 Tue Sep 20 14:12:25 2005 +++ php-news-web/article.php Sun Sep 25 15:14:46 2005 @@ -46,19 +46,20 @@ if ($line == ".\r\n") break; if ($inheaders && ($line == "\n" || $line == "\r\n")) { $inheaders = 0; - if ($headers['content-type'] - && preg_match('/charset=("|\'|)([1-9a-zA-Z-]+)\1/is', $headers['content-type'], $m)) { - $charset = trim($m[2]); - } - if ($headers['content-type'] - && preg_match("/boundary=(\"|'|)(.+)\\1/is", $headers['content-type'], $m)) { - $boundaries[] = trim($m[2]); - $boundary = end($boundaries); - } - if ($headers['content-type'] - && preg_match("/([^;]+)(;|\$)/", $headers['content-type'], $m)) { - $mimetype = trim(strtolower($m[1])); - ++$mimecount; + if (isset($headers['content-type'])) { + if (preg_match('/charset=(["\']?)(\w+)\1/i', $headers['content-type'], $m)) { + $charset = trim($m[2]); + } + + if(preg_match('/boundary=(["\']?)(.+)\1/is', $headers['content-type'], $m)) { + $boundaries[] = trim($m[2]); + $boundary = end($boundaries); + } + + if (preg_match("/([^;]+)(;|\$)/", $headers['content-type'], $m)) { + $mimetype = trim(strtolower($m[1])); + ++$mimecount; + } } if (!$started) { head("$group: ".format_title($headers['subject'], $charset)); @@ -66,17 +67,17 @@ $started = 1; } - $encoding = strtolower(trim($headers['content-transfer-encoding'])); + $encoding = strtolower(trim(@$headers['content-transfer-encoding'])); if (strlen($mimetype) && $mimetype != "text/plain" && substr($mimetype,0,10) != "multipart/") { # Display a link to the attachment $name = ''; if ($headers['content-type'] - && preg_match("/name=(\"|'|)(.+)\\1/s", $headers['content-type'], $m)) { + && preg_match('/name=(["\']?)(.+)\1/s', $headers['content-type'], $m)) { $name = trim($m[2]); } else if ($headers['content-disposition'] - && preg_match("/filename=(\"|'|)(.+)\\1/s", $headers['content-type'], $m)) { + && preg_match('/filename=(["\']?)(.+)\1/s', $headers['content-type'], $m)) { $name = trim($m[2]); } @@ -150,7 +151,11 @@ $line = base64_decode($line); break; } - if (strlen($charset)) { + + // we can't convert it to UTF, because cvs commits don't have charset info + // so its preferable to leave it as-is, and let users choose the correct charset + // in their browser. this is specially important for php.doc.* groups + if ($charset) { $line = to_utf8($line, $charset); } http://cvs.php.net/diff.php/php-news-web/common.inc?r1=1.32&r2=1.33&ty=u Index: php-news-web/common.inc diff -u php-news-web/common.inc:1.32 php-news-web/common.inc:1.33 --- php-news-web/common.inc:1.32 Sat Apr 2 07:59:20 2005 +++ php-news-web/common.inc Sun Sep 25 15:14:46 2005 @@ -53,7 +53,7 @@ function to_utf8($str, $charset) { - $n = iconv(strlen($charset) ? $charset : "iso-8859-1", "utf-8", $str); + $n = iconv($charset ? $charset : 'iso-8859-1', 'utf-8', $str); if ($n === false) { return $str; }

« previous php.mirrors (#29472) next »