From: moodler Date: Tue, 9 Mar 2004 06:44:27 +0000 (+0000) Subject: Filter text files as well X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b7a3d3b24c7d59a8d681c7e34a2c7082ba292130;p=moodle.git Filter text files as well --- diff --git a/file.php b/file.php index 6319b44075..42973de01d 100644 --- a/file.php +++ b/file.php @@ -37,10 +37,9 @@ $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"); @@ -48,12 +47,22 @@ 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 "
";
+            echo format_text(implode('', file($pathname)), FORMAT_MOODLE, $options, $courseid);  // Filter TEXT files
+            echo "
"; + } 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"); diff --git a/lib/weblib.php b/lib/weblib.php index 9cb5a85749..f800969eb5 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -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) {