MDL-41580 SCORM: allow imsmanifest.xml to be used in file system repos

This commit is contained in:
Dan Marsden 2013-09-04 18:46:35 +12:00
parent 7f3836d15a
commit 361a47d409
11 changed files with 153 additions and 14 deletions

View file

@ -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)';

View file

@ -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');
}
}
/**

View file

@ -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;
}