]> git.mjollnir.org Git - moodle.git/commitdiff
Filter text files as well
authormoodler <moodler>
Tue, 9 Mar 2004 06:44:27 +0000 (06:44 +0000)
committermoodler <moodler>
Tue, 9 Mar 2004 06:44:27 +0000 (06:44 +0000)
file.php
lib/weblib.php

index 6319b4407507809cefbdec18e527e15d33ecaf74..42973de01d453561f0c1326eaca46760fc3f281d 100644 (file)
--- a/file.php
+++ b/file.php
     $pathname = "$CFG->dataroot$pathinfo";
     $filename = $args[$numargs-1];
 
-    $mimetype = mimeinfo("type", $filename);
-
     if (file_exists($pathname)) {
         $lastmodified = filemtime($pathname);
+        $mimetype = mimeinfo("type", $filename);
 
         header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
         header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
         header("Pragma: ");
         header("Content-disposition: inline; filename=$filename");
         header("Content-length: ".filesize($pathname));
-        header("Content-type: $mimetype");
+
 
         if ($mimetype == "text/html") {
-            echo format_text(implode('', file($pathname)), FORMAT_HTML);  // Filter HTML files
+            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 "<pre>";
+            echo format_text(implode('', file($pathname)), FORMAT_MOODLE, $options, $courseid);  // Filter TEXT files
+            echo "</pre>";
+
         } else {
-            readfile("$pathname");
+            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");
index 9cb5a85749c24a13c707aef797b2582ac59f2325..f800969eb50b5b08b877946ff1cbb46c98322eba 100644 (file)
@@ -551,7 +551,10 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL
             if (!isset($options->para)) {
                 $options->para=true;
             }
-            $text = text_to_html($text, $options->smiley, $options->para);
+            if (!isset($options->newlines)) {
+                $options->newlines=true;
+            }
+            $text = text_to_html($text, $options->smiley, $options->para, $options->newlines);
             $text = filter_text($text, $courseid);
             break;
     }
@@ -694,7 +697,7 @@ function replace_smilies(&$text) {
     $text = str_replace($e, $img, $text);
 }
 
-function text_to_html($text, $smiley=true, $para=true) {
+function text_to_html($text, $smiley=true, $para=true, $newlines=true) {
 /// Given plain text, makes it into HTML as nicely as possible.
 /// May contain HTML tags already
 
@@ -710,7 +713,9 @@ function text_to_html($text, $smiley=true, $para=true) {
     convert_urls_into_links($text);
 
 /// Make returns into HTML newlines.
-    $text = nl2br($text);
+    if ($newlines) {
+        $text = nl2br($text);
+    }
 
 /// Turn smileys into images.
     if ($smiley) {