From 31ff6a8e0439a4dd1b9a0c40f6445340ae65996d Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Sun, 7 Mar 2010 14:50:37 +0200 Subject: [PATCH] Feature #272 - HTML files: Passing read/detected encoding value to the browser using the HTTP-header (too). Thus, not well-formed html-files have good chance to be showed using the right encoding. --- main/inc/lib/document.lib.php | 36 +++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 07cc69eee0..236d778252 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -333,11 +333,19 @@ class DocumentManager { // Commented to avoid double caching declaration when playing with IE and HTTPS //header('Cache-Control: no-cache, must-revalidate'); //header('Pragma: no-cache'); - if ($content_type == 'text/plain') { - $encoding = @api_detect_encoding(strip_tags(file_get_contents($full_file_name))); - if (!empty($encoding)) { - $content_type .= '; charset='.$encoding; - } + switch ($content_type) { + case 'text/html': + $encoding = @api_detect_encoding_html(file_get_contents($full_file_name)); + if (!empty($encoding)) { + $content_type .= '; charset='.$encoding; + } + break; + case 'text/plain': + $encoding = @api_detect_encoding(strip_tags(file_get_contents($full_file_name))); + if (!empty($encoding)) { + $content_type .= '; charset='.$encoding; + } + break; } header('Content-type: '.$content_type); header('Content-Length: '.$len); @@ -401,11 +409,19 @@ class DocumentManager { header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); - if ($content_type == 'text/plain') { - $encoding = @api_detect_encoding(strip_tags($full_string)); - if (!empty($encoding)) { - $content_type .= '; charset='.$encoding; - } + switch ($content_type) { + case 'text/html': + $encoding = @api_detect_encoding($full_string); + if (!empty($encoding)) { + $content_type .= '; charset='.$encoding; + } + break; + case 'text/plain': + $encoding = @api_detect_encoding(strip_tags($full_string)); + if (!empty($encoding)) { + $content_type .= '; charset='.$encoding; + } + break; } header('Content-type: '.$content_type); header('Content-Length: '.$len);