]> git.mjollnir.org Git - moodle.git/commitdiff
Fix for bug 1106
authormoodler <moodler>
Tue, 9 Mar 2004 06:20:11 +0000 (06:20 +0000)
committermoodler <moodler>
Tue, 9 Mar 2004 06:20:11 +0000 (06:20 +0000)
When resource_filterexternalpages are turned on then uploaded HTML
files are also now filtered properly.

mod/resource/fetch.php
mod/resource/view.php

index e5722cffc79cc9a2ef9f2e7360b0473fa96e95d1..9ce62b58c123cba4579fe0cc6bee0397ae66c53d 100644 (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");
         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);
+    
+        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");
+        }
     
-    echo format_text($content->results,FORMAT_HTML);
+        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");
+        }
+    }
 ?>
index dfb3f64ff6416162fbb8c0e0a9c5480fbe41204b..ef1f834072c9e99f065d0a2041e984c5becabc33 100644 (file)
             $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";
             }