Browse Source

Add option to boost encoding detection for learning paths - see https://github.com/chamilo/chamilo-lms/pull/771

Yannick Warnier 9 years ago
parent
commit
c897c8e180
2 changed files with 17 additions and 8 deletions
  1. 15 7
      main/inc/lib/document.lib.php
  2. 2 1
      main/install/configuration.dist.php

+ 15 - 7
main/inc/lib/document.lib.php

@@ -323,11 +323,11 @@ class DocumentManager
         $len = filesize($full_file_name);
         // Fixing error when file name contains a ","
         $filename = str_replace(',', '', $filename);
+        global $_configuration;
 
         if ($forced) {
             // Force the browser to save the file instead of opening it
 
-            global $_configuration;
             if (isset($_configuration['enable_x_sendfile_headers']) &&
                 !empty($_configuration['enable_x_sendfile_headers'])) {
                 header("X-Sendfile: $filename");
@@ -364,15 +364,23 @@ class DocumentManager
             //header('Pragma: no-cache');
             switch ($content_type) {
                 case 'text/html':
-                    $encoding = @api_detect_encoding_html(file_get_contents($full_file_name));
-                    if (!empty($encoding)) {
-                        $content_type .= '; charset=' . $encoding;
+                    if (isset($_configuration['lp_fixed_encoding']) && $_configuration['lp_fixed_encoding'] === 'true') {
+                        $content_type .= '; charset=UTF-8';
+                    } else {
+                        $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;
+                    if (isset($_configuration['lp_fixed_encoding']) && $_configuration['lp_fixed_encoding'] === 'true') {
+                        $content_type .= '; charset=UTF-8';
+                    } else {
+                        $encoding = @api_detect_encoding(strip_tags(file_get_contents($full_file_name)));
+                        if (!empty($encoding)) {
+                            $content_type .= '; charset=' . $encoding;
+                        }
                     }
                     break;
                 case 'application/vnd.dwg':

+ 2 - 1
main/install/configuration.dist.php

@@ -213,4 +213,5 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE;
     'language',
     'extra_fields'
 ];*/
-
+// Boost option to ignore encoding check for learning paths
+//$_configuration['lp_fixed_encoding'] = 'false';