Added class to libraries.
parent
bf15f46d82
commit
f71bf70561
|
@ -58,7 +58,7 @@ interface H5PFrameworkInterface {
|
||||||
/**
|
/**
|
||||||
* Get id to an excisting library
|
* Get id to an excisting library
|
||||||
*
|
*
|
||||||
* @param string $machineName
|
* @param string $name
|
||||||
* The librarys machine name
|
* The librarys machine name
|
||||||
* @param int $majorVersion
|
* @param int $majorVersion
|
||||||
* The librarys major version
|
* The librarys major version
|
||||||
|
@ -67,7 +67,7 @@ interface H5PFrameworkInterface {
|
||||||
* @return int
|
* @return int
|
||||||
* The id of the specified library or FALSE
|
* The id of the specified library or FALSE
|
||||||
*/
|
*/
|
||||||
public function getLibraryId($machineName, $majorVersion, $minorVersion);
|
public function getLibraryId($name, $majorVersion, $minorVersion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the library a patched version of an excisting library?
|
* Is the library a patched version of an excisting library?
|
||||||
|
@ -142,14 +142,14 @@ interface H5PFrameworkInterface {
|
||||||
/**
|
/**
|
||||||
* Loads a library
|
* Loads a library
|
||||||
*
|
*
|
||||||
* @param string $machineName
|
* @param string $name
|
||||||
* @param int $majorVersion
|
* @param int $majorVersion
|
||||||
* @param int $minorVersion
|
* @param int $minorVersion
|
||||||
* @return array|FALSE
|
* @return array|FALSE
|
||||||
* Array representing the library with dependency descriptions
|
* Array representing the library with dependency descriptions
|
||||||
* FALSE if the library doesn't exist
|
* FALSE if the library doesn't exist
|
||||||
*/
|
*/
|
||||||
public function loadLibrary($machineName, $majorVersion, $minorVersion);
|
public function loadLibrary($name, $majorVersion, $minorVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
class H5PValidator {
|
class H5PValidator {
|
||||||
|
@ -161,11 +161,11 @@ class H5PValidator {
|
||||||
'title' => '/^.{1,255}$/',
|
'title' => '/^.{1,255}$/',
|
||||||
'language' => '/^[a-z]{1,5}$/',
|
'language' => '/^[a-z]{1,5}$/',
|
||||||
'preloadedDependencies' => array(
|
'preloadedDependencies' => array(
|
||||||
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
|
'name' => '/^[a-z0-9\-]{1,255}$/',
|
||||||
'majorVersion' => '/^[0-9]{1,5}$/',
|
'majorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'minorVersion' => '/^[0-9]{1,5}$/',
|
'minorVersion' => '/^[0-9]{1,5}$/',
|
||||||
),
|
),
|
||||||
'mainLibrary' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i',
|
'library_name' => '/^[a-z0-9\-]{1,255}$/',
|
||||||
'embedTypes' => array('iframe', 'div'),
|
'embedTypes' => array('iframe', 'div'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -175,19 +175,20 @@ class H5PValidator {
|
||||||
'author' => '/^.{1,255}$/',
|
'author' => '/^.{1,255}$/',
|
||||||
'license' => '/^(cc-by|cc-by-sa|cc-by-nd|cc-by-nc|cc-by-nc-sa|cc-by-nc-nd|pd|cr|MIT)$/',
|
'license' => '/^(cc-by|cc-by-sa|cc-by-nd|cc-by-nc|cc-by-nc-sa|cc-by-nc-nd|pd|cr|MIT)$/',
|
||||||
'dynamicDependencies' => array(
|
'dynamicDependencies' => array(
|
||||||
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
|
'name' => '/^[a-z0-9\-]{1,255}$/',
|
||||||
'majorVersion' => '/^[0-9]{1,5}$/',
|
'majorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'minorVersion' => '/^[0-9]{1,5}$/',
|
'minorVersion' => '/^[0-9]{1,5}$/',
|
||||||
),
|
),
|
||||||
'externalResources' => array(
|
'externalResources' => array(
|
||||||
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
|
'name' => '/^[a-z0-9\-]{1,255}$/',
|
||||||
'majorVersion' => '/^[0-9]{1,5}$/',
|
'majorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'minorVersion' => '/^[0-9]{1,5}$/',
|
'minorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'url' => '/^http:\/\/[a-z_\-\.0-9]+\.[a-z]{2, 10}$/i',
|
'url' => '/^http:\/\/[a-z_\-\.0-9]+\.[a-z]{2, 10}$/i',
|
||||||
'type' => '/^(css|js)$/',
|
'type' => '/^(css|js)$/',
|
||||||
),
|
),
|
||||||
'w' => '/^[0-9]{1,4}$/',
|
'width' => '/^[0-9]{1,4}$/',
|
||||||
'h' => '/^[0-9]{1,4}$/',
|
'height' => '/^[0-9]{1,4}$/',
|
||||||
|
'fullscreen' => 'boolean',
|
||||||
'metaKeywords' => '/^.{1,}$/',
|
'metaKeywords' => '/^.{1,}$/',
|
||||||
'metaDescription' => '/^.{1,}$/k',
|
'metaDescription' => '/^.{1,}$/k',
|
||||||
);
|
);
|
||||||
|
@ -198,7 +199,8 @@ class H5PValidator {
|
||||||
'majorVersion' => '/^[0-9]{1,5}$/',
|
'majorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'minorVersion' => '/^[0-9]{1,5}$/',
|
'minorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'patchVersion' => '/^[0-9]{1,5}$/',
|
'patchVersion' => '/^[0-9]{1,5}$/',
|
||||||
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
|
'name' => '/^[a-z0-9\-]{1,255}$/',
|
||||||
|
'class' => '/^[a-z0-9\.]{1,255}$/i',
|
||||||
'runnable' => '/^(0|1)$/',
|
'runnable' => '/^(0|1)$/',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -207,22 +209,22 @@ class H5PValidator {
|
||||||
'license' => '/^(cc-by|cc-by-sa|cc-by-nd|cc-by-nc|cc-by-nc-sa|cc-by-nc-nd|pd|cr|MIT)$/',
|
'license' => '/^(cc-by|cc-by-sa|cc-by-nd|cc-by-nc|cc-by-nc-sa|cc-by-nc-nd|pd|cr|MIT)$/',
|
||||||
'description' => '/^.{1,}$/',
|
'description' => '/^.{1,}$/',
|
||||||
'dynamicDependencies' => array(
|
'dynamicDependencies' => array(
|
||||||
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
|
'name' => '/^[a-z0-9\-]{1,255}$/',
|
||||||
'majorVersion' => '/^[0-9]{1,5}$/',
|
'majorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'minorVersion' => '/^[0-9]{1,5}$/',
|
'minorVersion' => '/^[0-9]{1,5}$/',
|
||||||
),
|
),
|
||||||
'preloadedDependencies' => array(
|
'preloadedDependencies' => array(
|
||||||
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
|
'name' => '/^[a-z0-9\-]{1,255}$/',
|
||||||
'majorVersion' => '/^[0-9]{1,5}$/',
|
'majorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'minorVersion' => '/^[0-9]{1,5}$/',
|
'minorVersion' => '/^[0-9]{1,5}$/',
|
||||||
),
|
),
|
||||||
'editorDependencies' => array(
|
'editorDependencies' => array(
|
||||||
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
|
'name' => '/^[a-z0-9\-]{1,255}$/',
|
||||||
'majorVersion' => '/^[0-9]{1,5}$/',
|
'majorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'minorVersion' => '/^[0-9]{1,5}$/',
|
'minorVersion' => '/^[0-9]{1,5}$/',
|
||||||
),
|
),
|
||||||
'externalResources' => array(
|
'externalResources' => array(
|
||||||
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
|
'name' => '/^[a-z0-9\-]{1,255}$/',
|
||||||
'majorVersion' => '/^[0-9]{1,5}$/',
|
'majorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'minorVersion' => '/^[0-9]{1,5}$/',
|
'minorVersion' => '/^[0-9]{1,5}$/',
|
||||||
'url' => '/^http:\/\/[a-z_\-\.0-9]+\.[a-z]{2, 10}$/i',
|
'url' => '/^http:\/\/[a-z_\-\.0-9]+\.[a-z]{2, 10}$/i',
|
||||||
|
@ -235,10 +237,11 @@ class H5PValidator {
|
||||||
'path' => '/^((\\\|\/)?[a-z_\-\s0-9]+)+\.css$/i',
|
'path' => '/^((\\\|\/)?[a-z_\-\s0-9]+)+\.css$/i',
|
||||||
),
|
),
|
||||||
'dropLibraryCss' => array(
|
'dropLibraryCss' => array(
|
||||||
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
|
'name' => '/^[a-z0-9\-]{1,255}$/',
|
||||||
),
|
),
|
||||||
'w' => '/^[0-9]{1,4}$/',
|
'width' => '/^[0-9]{1,4}$/',
|
||||||
'h' => '/^[0-9]{1,4}$/',
|
'height' => '/^[0-9]{1,4}$/',
|
||||||
|
'fullscreen' => 'boolean',
|
||||||
'embedTypes' => array('iframe', 'div'),
|
'embedTypes' => array('iframe', 'div'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -393,8 +396,8 @@ class H5PValidator {
|
||||||
$libraries['mainH5pData'] = $mainH5pData;
|
$libraries['mainH5pData'] = $mainH5pData;
|
||||||
$missingLibraries = $this->getMissingLibraries($libraries);
|
$missingLibraries = $this->getMissingLibraries($libraries);
|
||||||
foreach ($missingLibraries as $missing) {
|
foreach ($missingLibraries as $missing) {
|
||||||
if ($this->h5pF->getLibraryId($missing['machineName'], $missing['majorVersion'], $missing['minorVersion'])) {
|
if ($this->h5pF->getLibraryId($missing['name'], $missing['majorVersion'], $missing['minorVersion'])) {
|
||||||
unset($missingLibraries[$missing['machineName']]);
|
unset($missingLibraries[$missing['name']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$valid = empty($missingLibraries) && $valid;
|
$valid = empty($missingLibraries) && $valid;
|
||||||
|
@ -409,10 +412,10 @@ class H5PValidator {
|
||||||
* Use the dependency declarations to find any missing libraries
|
* Use the dependency declarations to find any missing libraries
|
||||||
*
|
*
|
||||||
* @param array $libraries
|
* @param array $libraries
|
||||||
* A multidimensional array of libraries keyed with machineName first and majorVersion second
|
* A multidimensional array of libraries keyed with name first and majorVersion second
|
||||||
* @return array
|
* @return array
|
||||||
* A list of libraries that are missing keyed with machineName and holds objects with
|
* A list of libraries that are missing keyed with name and holds objects with
|
||||||
* machineName, majorVersion and minorVersion properties
|
* name, majorVersion and minorVersion properties
|
||||||
*/
|
*/
|
||||||
private function getMissingLibraries($libraries) {
|
private function getMissingLibraries($libraries) {
|
||||||
$missing = array();
|
$missing = array();
|
||||||
|
@ -435,23 +438,23 @@ class H5PValidator {
|
||||||
* the provided list of libraries
|
* the provided list of libraries
|
||||||
*
|
*
|
||||||
* @param array $dependencies
|
* @param array $dependencies
|
||||||
* A list of objects with machineName, majorVersion and minorVersion properties
|
* A list of objects with name, majorVersion and minorVersion properties
|
||||||
* @param array $libraries
|
* @param array $libraries
|
||||||
* An array of libraries keyed with machineName
|
* An array of libraries keyed with name
|
||||||
* @return
|
* @return
|
||||||
* A list of libraries that are missing keyed with machineName and holds objects with
|
* A list of libraries that are missing keyed with name and holds objects with
|
||||||
* machineName, majorVersion and minorVersion properties
|
* name, majorVersion and minorVersion properties
|
||||||
*/
|
*/
|
||||||
private function getMissingDependencies($dependencies, $libraries) {
|
private function getMissingDependencies($dependencies, $libraries) {
|
||||||
$missing = array();
|
$missing = array();
|
||||||
foreach ($dependencies as $dependency) {
|
foreach ($dependencies as $dependency) {
|
||||||
if (isset($libraries[$dependency['machineName']])) {
|
if (isset($libraries[$dependency['name']])) {
|
||||||
if (!$this->h5pC->isSameVersion($libraries[$dependency['machineName']], $dependency)) {
|
if (!$this->h5pC->isSameVersion($libraries[$dependency['name']], $dependency)) {
|
||||||
$missing[$dependency['machineName']] = $dependency;
|
$missing[$dependency['name']] = $dependency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$missing[$dependency['machineName']] = $dependency;
|
$missing[$dependency['name']] = $dependency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $missing;
|
return $missing;
|
||||||
|
@ -720,8 +723,8 @@ class H5PStorage {
|
||||||
public function getLibraryUsage(&$librariesInUse, $jsonData, $dynamic = FALSE) {
|
public function getLibraryUsage(&$librariesInUse, $jsonData, $dynamic = FALSE) {
|
||||||
if (isset($jsonData['preloadedDependencies'])) {
|
if (isset($jsonData['preloadedDependencies'])) {
|
||||||
foreach ($jsonData['preloadedDependencies'] as $preloadedDependency) {
|
foreach ($jsonData['preloadedDependencies'] as $preloadedDependency) {
|
||||||
$library = $this->h5pF->loadLibrary($preloadedDependency['machineName'], $preloadedDependency['majorVersion'], $preloadedDependency['minorVersion']);
|
$library = $this->h5pF->loadLibrary($preloadedDependency['name'], $preloadedDependency['majorVersion'], $preloadedDependency['minorVersion']);
|
||||||
$librariesInUse[$preloadedDependency['machineName']] = array(
|
$librariesInUse[$preloadedDependency['name']] = array(
|
||||||
'library' => $library,
|
'library' => $library,
|
||||||
'preloaded' => $dynamic ? 0 : 1,
|
'preloaded' => $dynamic ? 0 : 1,
|
||||||
);
|
);
|
||||||
|
@ -730,9 +733,9 @@ class H5PStorage {
|
||||||
}
|
}
|
||||||
if (isset($jsonData['dynamicDependencies'])) {
|
if (isset($jsonData['dynamicDependencies'])) {
|
||||||
foreach ($jsonData['dynamicDependencies'] as $dynamicDependency) {
|
foreach ($jsonData['dynamicDependencies'] as $dynamicDependency) {
|
||||||
if (!isset($librariesInUse[$dynamicDependency['machineName']])) {
|
if (!isset($librariesInUse[$dynamicDependency['name']])) {
|
||||||
$library = $this->h5pF->loadLibrary($dynamicDependency['machineName'], $dynamicDependency['majorVersion'], $dynamicDependency['minorVersion']);
|
$library = $this->h5pF->loadLibrary($dynamicDependency['name'], $dynamicDependency['majorVersion'], $dynamicDependency['minorVersion']);
|
||||||
$librariesInUse[$dynamicDependency['machineName']] = array(
|
$librariesInUse[$dynamicDependency['name']] = array(
|
||||||
'library' => $library,
|
'library' => $library,
|
||||||
'preloaded' => 0,
|
'preloaded' => 0,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue