mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-41580 SCORM: allow imsmanifest.xml to be used in file system repos
This commit is contained in:
parent
7f3836d15a
commit
361a47d409
11 changed files with 153 additions and 14 deletions
|
@ -30,9 +30,12 @@ $string['filesystem:view'] = 'View file system repository';
|
|||
$string['information'] = 'These folders are within the <b>{$a}</b> directory.';
|
||||
$string['invalidpath'] = 'Invalid root path';
|
||||
$string['path'] = 'Select a subdirectory';
|
||||
$string['relativefiles'] = 'Allow relative files';
|
||||
$string['relativefiles_desc'] = 'This allows all files in the repository to be accessible using relative links.';
|
||||
$string['root'] = 'Root';
|
||||
$string['nosubdir'] = 'You need to create at least one folder inside the <b>{$a}</b> directory so you can select it here.';
|
||||
$string['pluginname_help'] = 'Create repository from local directory';
|
||||
$string['pluginname'] = 'File system';
|
||||
$string['enablecourseinstances'] = 'Allow admins to add a file system repository instance to a course (configurable only by admins)';
|
||||
$string['enableuserinstances'] = 'Allow admins to add a file system repository instance for personal use (configurable only by admins)';
|
||||
|
||||
|
|
|
@ -194,11 +194,12 @@ class repository_filesystem extends repository {
|
|||
}
|
||||
|
||||
public static function get_instance_option_names() {
|
||||
return array('fs_path');
|
||||
return array('fs_path', 'relativefiles');
|
||||
}
|
||||
|
||||
public function set_option($options = array()) {
|
||||
$options['fs_path'] = clean_param($options['fs_path'], PARAM_PATH);
|
||||
$options['relativefiles'] = clean_param($options['relativefiles'], PARAM_INT);
|
||||
$ret = parent::set_option($options);
|
||||
return $ret;
|
||||
}
|
||||
|
@ -229,6 +230,10 @@ class repository_filesystem extends repository {
|
|||
}
|
||||
closedir($handle);
|
||||
}
|
||||
$mform->addElement('checkbox', 'relativefiles', get_string('relativefiles', 'repository_filesystem'),
|
||||
get_string('relativefiles_desc', 'repository_filesystem'));
|
||||
$mform->setType('relativefiles', PARAM_INT);
|
||||
|
||||
} else {
|
||||
$mform->addElement('static', null, '', get_string('nopermissions', 'error', get_string('configplugin', 'repository_filesystem')));
|
||||
return false;
|
||||
|
@ -461,6 +466,44 @@ class repository_filesystem extends repository {
|
|||
mtrace(" instance {$this->id}: deleted $deletedcount thumbnails");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a file relative to this file in the repository and sends it to the browser.
|
||||
*
|
||||
* @param stored_file $mainfile The main file we are trying to access relative files for.
|
||||
* @param string $relativepath the relative path to the file we are trying to access.
|
||||
*/
|
||||
public function send_relative_file(stored_file $mainfile, $relativepath) {
|
||||
global $CFG;
|
||||
// Check if this repository is allowed to use relative linking.
|
||||
$allowlinks = $this->supports_relative_file();
|
||||
$lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400;
|
||||
if (!empty($allowlinks)) {
|
||||
// Get path to the mainfile.
|
||||
$mainfilepath = $mainfile->get_source();
|
||||
|
||||
// Strip out filename from the path.
|
||||
$filename = $mainfile->get_filename();
|
||||
$basepath = strstr($mainfilepath, $filename, true);
|
||||
|
||||
$fullrelativefilepath = realpath($this->root_path.$basepath.$relativepath);
|
||||
|
||||
// Sanity check to make sure this path is inside this repository and the file exists.
|
||||
if (strpos($fullrelativefilepath, $this->root_path) === 0 && file_exists($fullrelativefilepath)) {
|
||||
send_file($fullrelativefilepath, basename($relativepath), $lifetime, 0);
|
||||
}
|
||||
}
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
/**
|
||||
* helper function to check if the repository supports send_relative_file.
|
||||
*
|
||||
* @return true|false
|
||||
*/
|
||||
public function supports_relative_file() {
|
||||
return $this->get_option('relativefiles');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,6 +44,9 @@ class repository_filesystem_generator extends testing_repository_generator {
|
|||
if (!isset($record['fs_path'])) {
|
||||
$record['fs_path'] = '/i/do/not/exist';
|
||||
}
|
||||
if (!isset($record['relativefiles'])) {
|
||||
$record['relativefiles'] = 0;
|
||||
}
|
||||
return $record;
|
||||
}
|
||||
|
||||
|
|
|
@ -2866,6 +2866,31 @@ abstract class repository implements cacheable_object {
|
|||
$classname = $data['class'];
|
||||
return new $classname($data['id'], $data['ctxid'], $data['options'], $data['readonly']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a file relative to this file in the repository and sends it to the browser.
|
||||
* Used to allow relative file linking within a repository without creating file records
|
||||
* for linked files
|
||||
*
|
||||
* Repositories that overwrite this must be very careful - see filesystem repository for example.
|
||||
*
|
||||
* @param stored_file $mainfile The main file we are trying to access relative files for.
|
||||
* @param string $relativepath the relative path to the file we are trying to access.
|
||||
*
|
||||
*/
|
||||
public function send_relative_file(stored_file $mainfile, $relativepath) {
|
||||
// This repository hasn't implemented this so send_file_not_found.
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
/**
|
||||
* helper function to check if the repository supports send_relative_file.
|
||||
*
|
||||
* @return true|false
|
||||
*/
|
||||
public function supports_relative_file() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,9 @@ http://docs.moodle.org/dev/Repository_API
|
|||
* get_option() now always return null when the first parameter ($config) is not empty, and
|
||||
no value was found for this $config. Previously this could sometimes return an empty array().
|
||||
* The function repository_attach_id() was removed, it was never used and was not useful.
|
||||
* New functions send_relative_file() and supports_relative_file() to allow sending relative linked
|
||||
files - see filesystem repository for example.
|
||||
|
||||
|
||||
=== 2.5 ===
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue