From: Petr Skoda Date: Mon, 18 Oct 2010 11:41:11 +0000 (+0000) Subject: adding support for directory links in file resource X-Git-Tag: v2.0.0-rc2~497 X-Git-Url: http://git.moodle.org/gw?p=moodle.git;a=commitdiff_plain;h=fe3c5daedeb567ea31de3b4fd6736a1c8c4e233f;hp=2f65797837ef84ab0307f04cf92bb87b1b044e51;ds=sidebyside adding support for directory links in file resource --- 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();