From 705d8e34719880bd6153d3682d3cf9c604f75642 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 7 Feb 2025 08:45:12 +0000 Subject: [PATCH] MDL-84480 files: correct text formatting params when filtering files. --- lib/filelib.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/filelib.php b/lib/filelib.php index 68f662f5a4f..6510990c076 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -2616,7 +2616,8 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring if ($mimetype == 'text/html' || $mimetype == 'application/xhtml+xml' || file_is_svg_image_from_mimetype($mimetype)) { $options = new stdClass(); $options->noclean = true; - $options->nocache = true; // temporary workaround for MDL-5136 + $options->context = context_course::instance($COURSE->id); + if (is_object($path)) { $text = $path->get_content(); } else if ($pathisstring) { @@ -2624,15 +2625,16 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring } else { $text = implode('', file($path)); } - $output = format_text($text, FORMAT_HTML, $options, $COURSE->id); + $output = format_text($text, FORMAT_HTML, $options); readstring_accel($output, $mimetype); - } else if (($mimetype == 'text/plain') and ($filter == 1)) { // only filter text if filter all files is selected $options = new stdClass(); $options->newlines = false; $options->noclean = true; + $options->context = context_course::instance($COURSE->id); + if (is_object($path)) { $text = htmlentities($path->get_content(), ENT_QUOTES, 'UTF-8'); } else if ($pathisstring) { @@ -2640,10 +2642,9 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring } else { $text = htmlentities(implode('', file($path)), ENT_QUOTES, 'UTF-8'); } - $output = '
'. format_text($text, FORMAT_MOODLE, $options, $COURSE->id) .'
'; + $output = '
'. format_text($text, FORMAT_MOODLE, $options) .'
'; readstring_accel($output, $mimetype); - } else { // send the contents if ($pathisstring) {