From fe3c5daedeb567ea31de3b4fd6736a1c8c4e233f Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 18 Oct 2010 11:41:11 +0000 Subject: [PATCH] adding support for directory links in file resource --- mod/resource/lib.php | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/mod/resource/lib.php b/mod/resource/lib.php index b5136f5ffbf..b3689474ec2 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -386,19 +386,32 @@ function resource_pluginfile($course, $cm, $context, $filearea, $args, $forcedow $fs = get_file_storage(); $relativepath = implode('/', $args); - $fullpath = "/$context->id/mod_resource/$filearea/0/$relativepath"; - if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { - $resource = $DB->get_record('resource', array('id'=>$cm->instance), 'id, legacyfiles', MUST_EXIST); - if ($resource->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) { - return false; - } - if (!$file = resourcelib_try_file_migration('/'.$relativepath, $cm->id, $cm->course, 'mod_resource', 'content', 0)) { - return false; + $fullpath = rtrim("/$context->id/mod_resource/$filearea/0/$relativepath", '/'); + do { + if (!$file = $fs->get_file_by_hash(sha1($fullpath))) { + if ($file = $fs->get_file_by_hash(sha1("$fullpath/.")) and $file->is_directory()) { + if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.htm"))) { + break; + } + if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.html"))) { + break; + } + if ($file = $fs->get_file_by_hash(sha1("$fullpath/Default.htm"))) { + break; + } + } + $resource = $DB->get_record('resource', array('id'=>$cm->instance), 'id, legacyfiles', MUST_EXIST); + if ($resource->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) { + return false; + } + if (!$file = resourcelib_try_file_migration('/'.$relativepath, $cm->id, $cm->course, 'mod_resource', 'content', 0)) { + return false; + } + // file migrate - update flag + $resource->legacyfileslast = time(); + $DB->update_record('resource', $resource); } - // file migrate - update flag - $resource->legacyfileslast = time(); - $DB->update_record('resource', $resource); - } + } while (false); // should we apply filters? $mimetype = $file->get_mimetype(); -- 2.43.0