Load presave script if present in library.
pull/50/head
Thomas Horn Sivertsen 2018-01-19 14:42:43 +01:00
parent 95901159d0
commit 1b079d36f1
3 changed files with 31 additions and 1 deletions

View File

@ -451,6 +451,17 @@ class H5PDefaultStorage implements \H5PFileStorage {
return self::dirReady($this->path);
}
public function hasPresave($name) {
$filePath = implode(DIRECTORY_SEPARATOR, [
$this->path,
'libraries',
$name,
'presave.js',
]);
return file_exists($filePath);
}
/**
* Recursive function for copying directories.
*

View File

@ -190,4 +190,11 @@ interface H5PFileStorage {
* @return bool True if server has the proper write access
*/
public function hasWriteAccess();
/**
* Check if the library has a presave.js in the root folder
*
* @return string|null Path to script or null if missing
*/
public function hasPresave($name);
}

View File

@ -2109,14 +2109,18 @@ class H5PCore {
// Using content dependencies
foreach ($dependencies as $dependency) {
$libraryName = H5PCore::libraryToString($dependency, TRUE);
if (isset($dependency['path']) === FALSE) {
$dependency['path'] = 'libraries/' . H5PCore::libraryToString($dependency, TRUE);
$dependency['path'] = 'libraries/' . $libraryName;
$dependency['preloadedJs'] = explode(',', $dependency['preloadedJs']);
$dependency['preloadedCss'] = explode(',', $dependency['preloadedCss']);
}
$dependency['version'] = "?ver={$dependency['majorVersion']}.{$dependency['minorVersion']}.{$dependency['patchVersion']}";
$this->getDependencyAssets($dependency, 'preloadedJs', $files['scripts'], $prefix);
$this->getDependencyAssets($dependency, 'preloadedCss', $files['styles'], $prefix);
if( $this->fs->hasPresave($libraryName) ){
$this->addPresaveFile($files, $dependency, $prefix);
}
}
if ($this->aggregateAssets) {
@ -2130,6 +2134,14 @@ class H5PCore {
return $files;
}
public function addPresaveFile(&$assets, $library, $prefix = ''){
$this->getDependencyAssets([
'path' => 'libraries' . DIRECTORY_SEPARATOR . self::libraryToString($library, true),
'version' => array_key_exists('version', $library) ? $library['version'] : "?ver={$library['majorVersion']}.{$library['minorVersion']}.{$library['patchVersion']}",
'presaveJs' => ['presave.js']
], 'presaveJs', $assets['scripts'], $prefix);
}
private static function getDependenciesHash(&$dependencies) {
// Build hash of dependencies
$toHash = array();