$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");
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;
}
$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
convert_urls_into_links($text);
/// Make returns into HTML newlines.
- $text = nl2br($text);
+ if ($newlines) {
+ $text = nl2br($text);
+ }
/// Turn smileys into images.
if ($smiley) {