MDL-73119 contentbank: Add pluginfile callback to content type plugins
This commit is contained in:
@@ -658,4 +658,17 @@ class contenttype_test extends \advanced_testcase {
|
||||
$url = $contenttype->get_download_url($content);
|
||||
$this->assertEmpty($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests pluginfile result.
|
||||
*
|
||||
* @covers ::pluginfile
|
||||
*/
|
||||
public function test_pluginfile() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$systemcontext = context_system::instance();
|
||||
$contenttype = new contenttype($systemcontext);
|
||||
$this->assertIsCallable([$contenttype, 'pluginfile']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,4 +100,20 @@ class contenttype extends \core_contentbank\contenttype {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This implements custom file serving.
|
||||
*
|
||||
* @param stdClass $course the course object
|
||||
* @param stdClass $cm the course module object
|
||||
* @param \context $context the context
|
||||
* @param string $filearea the name of the file area
|
||||
* @param array $args extra arguments (itemid, path)
|
||||
* @param bool $forcedownload whether or not force download
|
||||
* @param array $options additional options affecting the file serving
|
||||
* @return void
|
||||
*/
|
||||
public static function pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []): void {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-5
@@ -5129,16 +5129,26 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null, $offlin
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
$componentargs = fullclone($args);
|
||||
$itemid = (int)array_shift($args);
|
||||
$filename = array_pop($args);
|
||||
$filepath = $args ? '/'.implode('/', $args).'/' : '/';
|
||||
if (!$file = $fs->get_file($context->id, $component, $filearea, $itemid, $filepath, $filename) or
|
||||
$file->is_directory()) {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
\core\session\manager::write_close(); // Unlock session during file serving.
|
||||
send_stored_file($file, 0, 0, true, $sendfileoptions); // must force download - security!
|
||||
|
||||
$contenttype = $DB->get_field('contentbank_content', 'contenttype', ['id' => $itemid]);
|
||||
if (component_class_callback("\\{$contenttype}\\contenttype", 'pluginfile',
|
||||
[$course, null, $context, $filearea, $componentargs, $forcedownload, $sendfileoptions], false) === false) {
|
||||
|
||||
if (!$file = $fs->get_file($context->id, $component, $filearea, $itemid, $filepath, $filename) or
|
||||
|
||||
$file->is_directory()) {
|
||||
send_file_not_found();
|
||||
|
||||
} else {
|
||||
send_stored_file($file, 0, 0, true, $sendfileoptions); // Must force download - security!
|
||||
}
|
||||
}
|
||||
} else if (strpos($component, 'mod_') === 0) {
|
||||
$modname = substr($component, 4);
|
||||
if (!file_exists("$CFG->dirroot/mod/$modname/lib.php")) {
|
||||
|
||||
Reference in New Issue
Block a user