From 3cf4ab978b014bac37daf45f6b873dd1e1afb674 Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 11 Mar 2004 02:14:15 +0000 Subject: [PATCH] Added an option on the filters page to control whether uploaded files are parsed by filters. bug 1128 --- admin/filters.html | 15 +++++++++++++++ admin/filters.php | 2 ++ file.php | 30 ++++++++++++++++++------------ lang/en/admin.php | 1 + lang/en/moodle.php | 1 + lib/defaults.php | 1 + 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/admin/filters.html b/admin/filters.html index f98fe2498c..5f7f10fe5a 100644 --- a/admin/filters.html +++ b/admin/filters.html @@ -113,6 +113,21 @@ + + : + + filteruploadedfiles, "", "", ""); + ?> + + + + +   "> diff --git a/admin/filters.php b/admin/filters.php index 45373087b9..abb3b5df2a 100644 --- a/admin/filters.php +++ b/admin/filters.php @@ -32,6 +32,8 @@ $strinactive = get_string("inactive"); $strcachetext = get_string("cachetext", "admin"); $strconfigcachetext = get_string("configcachetext"); + $strfilteruploadedfiles = get_string("filteruploadedfiles", "admin"); + $strconfigfilteruploadedfiles = get_string("configfilteruploadedfiles"); print_header("$site->shortname: $strmanagefilters", "$site->fullname", "$stradministration -> ". diff --git a/file.php b/file.php index 42973de01d..3c4e0da045 100644 --- a/file.php +++ b/file.php @@ -49,20 +49,26 @@ header("Content-length: ".filesize($pathname)); - if ($mimetype == "text/html") { - header("Content-type: text/html"); - echo format_text(implode('', file($pathname)), FORMAT_HTML, NULL, $courseid); // Filter HTML files - - } else if ($mimetype == "text/plain") { - header("Content-type: text/html"); - $options->newlines = false; - echo "
";
-            echo format_text(implode('', file($pathname)), FORMAT_MOODLE, $options, $courseid);  // Filter TEXT files
-            echo "
"; - - } else { + if (empty($CFG->filteruploadedfiles)) { header("Content-type: $mimetype"); readfile($pathname); + + } else { /// Try and put the file through filters + if ($mimetype == "text/html") { + header("Content-type: text/html"); + echo format_text(implode('', file($pathname)), FORMAT_HTML, NULL, $courseid); + + } else if ($mimetype == "text/plain") { + header("Content-type: text/html"); + $options->newlines = false; + echo "
";
+                echo format_text(implode('', file($pathname)), FORMAT_MOODLE, $options, $courseid);
+                echo "
"; + + } else { /// Just send it out raw + header("Content-type: $mimetype"); + readfile($pathname); + } } } else { error("Sorry, but the file you are looking for was not found ($pathname)", "course/view.php?id=$courseid"); diff --git a/lang/en/admin.php b/lang/en/admin.php index fc8489e9d9..a7fff473ee 100755 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -3,6 +3,7 @@ $string['cachetext'] = 'Text cache lifetime'; +$string['filteruploadedfiles'] = 'Filter uploaded files'; $string['upgradelogs'] = 'For full functionality, your old logs need to be upgraded. More information'; $string['upgradelogsinfo'] = 'Some changes have way some logs are stored. To be able to view all of your old logs on a per-activity basis, your old logs need to be upgraded. Depending on your site this can take a long time (eg several hours) and can be quite taxing on the database for large sites. Once you start this process you should let it finish (by keeping the browser window open). Don\'t worry - your site will work fine for other people while the logs are being upgraded.

Do you want to upgrade your logs now?'; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 8da1d0f7cf..d6b4cebaef 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -131,6 +131,7 @@ $string['configcachetext'] = 'For larger sites or sites that use text filters, t $string['configcountry'] = 'If you set a country here, then this country will be selected by default on new user accounts. To force users to choose a country, just leave this unset.'; $string['configdebug'] = 'If you turn this on, then PHP\'s error_reporting will be increased so that more warnings are printed. This is only useful for developers.'; $string['configerrorlevel'] = 'Choose the amount of PHP warnings that you want to be displayed. Normal is usually the best choice.'; +$string['configfilteruploadedfiles'] = 'Enabling this setting will cause Moodle to process all uploaded HTML and text files with the filters before displaying them.'; $string['configforcelogin'] = 'Normally, the front page of the site and the course listings (but not courses) can be read by people without logging in to the site. If you want to force people to log in before they do ANYTHING on the site, then you should enable this setting.'; $string['configframename'] = 'If you are embedding Moodle within a web frame, then put the name of this frame here. Otherwise this value should remain as \'_top\''; $string['configfullnamedisplay'] = 'This defines how names are shown when they are displayed in full. For most mono-lingual sites the most efficient setting is the default \"Given names + Surname\", but you may choose to hide surnames altogether, or to leave it up to the current language pack to decide (some languages have different conventions).'; diff --git a/lib/defaults.php b/lib/defaults.php index c6a579cd89..cb581f24f1 100644 --- a/lib/defaults.php +++ b/lib/defaults.php @@ -10,6 +10,7 @@ "changepassword" => true, "country" => "", "debug" => 7, + "filteruploadedfiles" => true, "forcelogin" => false, "fullnamedisplay" => "firstname lastname", "framename" => "_top", -- 2.39.5