]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14589 new file not found general function
authorskodak <skodak>
Sat, 16 Aug 2008 17:23:19 +0000 (17:23 +0000)
committerskodak <skodak>
Sat, 16 Aug 2008 17:23:19 +0000 (17:23 +0000)
file.php
lib/filelib.php
pluginfile.php

index 6cee7c1731ec6a36ee85133c9df35fb678a6d237..3f71631a719d2e9ba4a76b37b9d4fbcd041117f0 100644 (file)
--- a/file.php
+++ b/file.php
@@ -76,7 +76,7 @@
             $fullpath .= '/';
         }
         if (!$file = $fs->get_file_by_hash(sha1($fullpath.'/.'))) {
-            not_found();
+            send_file_not_found();
         }
     }
     // do not serve dirs
@@ -84,7 +84,7 @@
         if (!$file = $fs->get_file_by_hash(sha1($fullpath.'index.html'))) {
             if (!$file = $fs->get_file_by_hash(sha1($fullpath.'index.htm'))) {
                 if (!$file = $fs->get_file_by_hash(sha1($fullpath.'Default.htm'))) {
-                    not_found();
+                    send_file_not_found();
                 }
             }
         }
@@ -96,9 +96,4 @@
     session_write_close(); // unlock session during fileserving
     send_stored_file($file, $lifetime, $CFG->filteruploadedfiles, $forcedownload);
 
-    function not_found() {
-        global $CFG, $COURSE;
-        header('HTTP/1.0 404 not found');
-        print_error('filenotfound', 'error', $CFG->wwwroot.'/course/view.php?id='.$COURSE->id); //this is not displayed on IIS??
-    }
 
index a2443c49e833077041b453b8045274671a2ecb76..6837e4347c37333d58dec77fe4f8d2007442e9dd 100644 (file)
@@ -561,6 +561,16 @@ function get_mimetype_description($mimetype,$capitalise=false) {
     return $result;
 }
 
+/**
+ * Reprot file is not found or not accessible
+ * @return does not return, terminates script
+ */
+function send_file_not_found() {
+    global $CFG, $COURSE;
+    header('HTTP/1.0 404 not found');
+    print_error('filenotfound', 'error', $CFG->wwwroot.'/course/view.php?id='.$COURSE->id); //this is not displayed on IIS??
+}
+
 /**
  * Handles the sending of temporary file to user, download is forced.
  * File is deleted after abort or succesful sending.
index 41a74fc2c2ece5682a5017aa8eaef50dad5af239..ed3c18d2f2da361b5d1650acd0edd30e7848512e 100644 (file)
                 }
                 if ($CFG->bloglevel == BLOG_USER_LEVEL) {
                     if ($USER->id != $entry->userid) {
-                        not_found();
+                        send_file_not_found();
                     }
                 }
             }
             $entryid = (int)array_shift($args);
             if (!$entry = $DB->get_record('post', array('module'=>'blog', 'id'=>$entryid))) {
-                not_found();
+                send_file_not_found();
             }
             if ('publishstate' === 'public') {
                 if ($CFG->forcelogin) {
@@ -62,7 +62,7 @@
             } else if ('publishstate' === 'draft') {
                 require_login();
                 if ($USER->id != $entry->userid) {
-                    not_found();
+                    send_file_not_found();
                 }
             }
 
             $fullpath = $context->id.'blog'.$entryid.$relativepath;
 
             if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
-                not_found();
+                send_file_not_found();
             }
 
             send_stored_file($file, 10*60, 0, true); // download MUST be forced - security!
 
         } else {
-            not_found();
+            send_file_not_found();
         }
 
 
     } else if ($context->contextlevel == CONTEXT_USER) {
-        not_found();
+        send_file_not_found();
 
 
     } else if ($context->contextlevel == CONTEXT_COURSECAT) {
         if ($filearea !== 'intro') {
-            not_found();
+            send_file_not_found();
         }
 
         if ($CFG->forcelogin) {
         $fullpath = $context->id.'intro0'.$relativepath;
 
         if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->get_filename() == '.') {
-            not_found();
+            send_file_not_found();
         }
 
         session_write_close(); // unlock session during fileserving
 
     } else if ($context->contextlevel == CONTEXT_COURSE) {
         if ($filearea !== 'intro' and $filearea !== 'backup') {
-            not_found();
+            send_file_not_found();
         }
 
         if (!$course = $DB->get_record('course', array('id'=>$context->instanceid))) {
         $fullpath = $context->id.'intro0'.$relativepath;
 
         if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
-            not_found();
+            send_file_not_found();
         }
 
         session_write_close(); // unlock session during fileserving
     } else if ($context->contextlevel == CONTEXT_MODULE) {
         
         if (!$coursecontext = get_context_instance_by_id(get_parent_contextid($context))) {
-            not_found();
+            send_file_not_found();
         }
 
         if (!$course = $DB->get_record('course', array('id'=>$coursecontext->instanceid))) {
-            not_found();
+            send_file_not_found();
         }
         $modinfo = get_fast_modinfo($course);
         if (empty($modinfo->cms[$context->instanceid])) {
-            not_found();
+            send_file_not_found();
         }
 
         $cminfo = $modinfo->cms[$context->instanceid];
                 }
             }
         }
-        not_found();
+        send_file_not_found();
 
     } else if ($context->contextlevel == CONTEXT_BLOCK) {
         //not supported yet
-        not_found();
+        send_file_not_found();
 
 
     } else {
-        not_found();
-    }
-
-
-    function not_found() {
-        global $CFG;
-        header('HTTP/1.0 404 not found');
-        print_error('filenotfound', 'error', $CFG->wwwroot.'/'); //this is not displayed on IIS??
+        send_file_not_found();
     }