diff --git a/h5p-development.class.php b/h5p-development.class.php index 1211517..5823a51 100644 --- a/h5p-development.class.php +++ b/h5p-development.class.php @@ -84,11 +84,14 @@ class H5PDevelopment { // TODO: Validate props? Not really needed, is it? this is a dev site. - // Save/update library. $library['libraryId'] = $this->h5pF->getLibraryId($library['machineName'], $library['majorVersion'], $library['minorVersion']); - if (!isset($library['metadata'])) { - $library['metadata'] = 1; - } + + // Convert metadataSettings values to boolean & json_encode it before saving + $library['metadataSettings'] = isset($library['metadataSettings']) ? + H5PMetadata::boolifyAndEncodeSettings($library['metadataSettings']) : + NULL; + + // Save/update library. $this->h5pF->saveLibraryData($library, $library['libraryId'] === FALSE); $library['path'] = 'development/' . $contents[$i]; diff --git a/h5p-metadata.class.php b/h5p-metadata.class.php index 9fb5686..4397d7e 100644 --- a/h5p-metadata.class.php +++ b/h5p-metadata.class.php @@ -114,4 +114,24 @@ abstract class H5PMetadata { return $fields; } + + /** + * The metadataSettings field in libraryJson uses 1 for true and 0 for false. + * Here we are converting these to booleans, and also doing JSON encoding. + * This is invoked before the library data is beeing inserted/updated to DB. + * + * @param array $metadataSettings + * @return string + */ + public static function boolifyAndEncodeSettings($metadataSettings) { + // Convert metadataSettings values to boolean + if (isset($metadataSettings['disable'])) { + $metadataSettings['disable'] = $metadataSettings['disable'] === 1; + } + if (isset($metadataSettings['disable'])) { + $metadataSettings['disableExtraTitleField'] = $metadataSettings['disableExtraTitleField'] === 1; + } + + return json_encode($metadataSettings); + } } diff --git a/h5p.classes.php b/h5p.classes.php index 668d6fa..c8e64ed 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -210,7 +210,9 @@ interface H5PFrameworkInterface { * - minorVersion: The library's minorVersion * - patchVersion: The library's patchVersion * - runnable: 1 if the library is a content type, 0 otherwise - * - metadata: 1 if the library should support setting metadata (copyright etc) + * - metadataSettings: Associative array containing: + * - disable: 1 if the library should not support setting metadata (copyright etc) + * - disableExtraTitleField: 1 if the library don't need the extra title field * - fullscreen(optional): 1 if the library supports fullscreen, 0 otherwise * - embedTypes(optional): list of supported embed types * - preloadedJs(optional): list of associative arrays containing: @@ -681,7 +683,10 @@ 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|GPL1|GPL2|GPL3|MPL|MPL2)$/', 'description' => '/^.{1,}$/', - 'metadata' => '/^(0|1)$/', + 'metadataSettings' => array( + 'disable' => '/^(0|1)$/', + 'disableExtraTitleField' => '/^(0|1)$/' + ), 'dynamicDependencies' => array( 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', 'majorVersion' => '/^[0-9]{1,5}$/', @@ -1440,10 +1445,11 @@ class H5PStorage { // Indicate that the dependencies of this library should be saved. $library['saveDependencies'] = TRUE; - // Save library meta data - if (!isset($library['metadata'])) { - $library['metadata'] = 1; - } + // Convert metadataSettings values to boolean & json_encode it before saving + $library['metadataSettings'] = isset($library['metadataSettings']) ? + H5PMetadata::boolifyAndEncodeSettings($library['metadataSettings']) : + NULL; + $this->h5pF->saveLibraryData($library, $new); // Save library folder