From 9e5fa330f33f012252a79fa18117443a912f3c23 Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 16 Aug 2008 17:23:19 +0000 Subject: [PATCH] MDL-14589 new file not found general function --- file.php | 9 ++------- lib/filelib.php | 10 ++++++++++ pluginfile.php | 39 ++++++++++++++++----------------------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/file.php b/file.php index 6cee7c1731..3f71631a71 100644 --- 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?? - } diff --git a/lib/filelib.php b/lib/filelib.php index a2443c49e8..6837e4347c 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -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. diff --git a/pluginfile.php b/pluginfile.php index 41a74fc2c2..ed3c18d2f2 100644 --- a/pluginfile.php +++ b/pluginfile.php @@ -43,13 +43,13 @@ } 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(); } } @@ -72,23 +72,23 @@ $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) { @@ -100,7 +100,7 @@ $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 @@ -109,7 +109,7 @@ } 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))) { @@ -129,7 +129,7 @@ $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 @@ -139,15 +139,15 @@ } 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]; @@ -162,20 +162,13 @@ } } } - 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(); } -- 2.39.5