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