Fix for bug 1106

When resource_filterexternalpages are turned on then uploaded HTML
files are also now filtered properly.
This commit is contained in:
moodler 2004-03-09 06:20:11 +00:00
parent a9f80673b6
commit e359234d0f
2 changed files with 47 additions and 5 deletions

View File

@ -3,8 +3,9 @@
require_once("../../config.php");
require_once("lib.php");
require_variable($id); // Course Module ID
require_variable($url); // url to fetch
require_variable($id); // Course Module ID
optional_variable($url); // url to fetch, or
optional_variable($file); // file to fetch
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
@ -18,7 +19,48 @@
error("Resource ID was incorrect");
}
$content = resource_fetch_remote_file($cm, $url);
if ($url) {
$content = resource_fetch_remote_file($cm, $url);
echo format_text($content->results, FORMAT_HTML);
} else if ($file) {
$pathinfo = urldecode($file);
echo format_text($content->results,FORMAT_HTML);
if (! $args = parse_slash_arguments($pathinfo)) {
error("No valid arguments supplied");
}
$numargs = count($args);
$courseid = (integer)$args[0];
if ($courseid != $course->id) { // Light security check
error("Course IDs don't match");
}
if ($course->category) {
require_login($courseid);
}
$pathname = "$CFG->dataroot$pathinfo";
$filename = $args[$numargs-1];
if (file_exists($pathname)) {
$lastmodified = filemtime($pathname);
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
header("Pragma: ");
header("Content-disposition: inline; filename=$filename");
header("Content-length: ".filesize($pathname));
header("Content-type: text/html");
$content = implode('', file($pathname));
echo format_text($content, FORMAT_HTML);
} else {
error("Sorry, but the file you are looking for was not found ($pathname)", "course/view.php?id=$courseid");
}
}
?>

View File

@ -166,7 +166,7 @@
$fullurl = "$CFG->wwwroot$relativeurl";
if ($CFG->resource_filterexternalpages and $resourcetype == "html") {
$fullurl = "$CFG->wwwroot/mod/resource/fetch.php?id=$cm->id&url=$fullurl";
$fullurl = "$CFG->wwwroot/mod/resource/fetch.php?id=$cm->id&file=/$course->id/$resource->reference";
}