From 579ba96b49831450bc422f87e934f2b8e002911f Mon Sep 17 00:00:00 2001 From: thomasmars Date: Fri, 1 Jun 2018 11:09:45 +0200 Subject: [PATCH 1/2] HFP-1942 Add crossorigin api call. Update minor version of core since interface changes --- h5p.classes.php | 2 +- js/h5p.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 310de97..2efebbd 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1773,7 +1773,7 @@ class H5PCore { public static $coreApi = array( 'majorVersion' => 1, - 'minorVersion' => 15 + 'minorVersion' => 16 ); public static $styles = array( 'styles/h5p.css', diff --git a/js/h5p.js b/js/h5p.js index 1b899d3..ef56834 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -1938,6 +1938,16 @@ H5P.createTitle = function (rawTitle, maxLength) { } }; + /** + * Get crossorigin option that is set for site. Usefull for setting crossorigin policy for elements. + * + * @returns {string|null} Returns the string that should be set as crossorigin policy for elements or null if + * no policy is set. + */ + H5P.getCrossOrigin = function () { + return H5PIntegration.crossorigin ? H5PIntegration.crossorigin : null; + }; + /** * Async error handling. * From 715fa6f80311adf605898fcf2dfed690b6cc8c4e Mon Sep 17 00:00:00 2001 From: Paal Joergensen Date: Thu, 1 Nov 2018 14:42:12 +0100 Subject: [PATCH 2/2] HFP-2378 Add option to overwrite unset metadata fields --- h5p-metadata.class.php | 59 ++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/h5p-metadata.class.php b/h5p-metadata.class.php index 3a504e3..8462fa4 100644 --- a/h5p-metadata.class.php +++ b/h5p-metadata.class.php @@ -64,15 +64,16 @@ abstract class H5PMetadata { ',"authorComments":' . (isset($content->author_comments) ? json_encode($content->author_comments) : 'null') . '}'; } - /** * Make the metadata into an associative array keyed by the property names * @param mixed $metadata Array or object containing metadata * @param bool $include_title + * @param bool $include_missing For metadata fields not being set, skip 'em. + * Relevant for content upgrade * @param array $types * @return array */ - public static function toDBArray($metadata, $include_title = true, &$types = array()) { + public static function toDBArray($metadata, $include_title = true, $include_missing = true, &$types = array()) { $fields = array(); if (!is_array($metadata)) { @@ -81,35 +82,43 @@ abstract class H5PMetadata { foreach (self::$fields as $key => $config) { + // Ignore title? if ($key === 'title' && !$include_title) { continue; } - if (array_key_exists($key, $metadata)) { - $value = $metadata[$key]; - $db_field_name = strtolower(preg_replace('/(? $config['maxLength']) { - $value = mb_substr($value, 0, $config['maxLength']); - } - $types[] = '%s'; - break; - - case 'int': - $value = ($value !== null) ? intval($value): null; - $types[] = '%d'; - break; - - case 'json': - $value = ($value !== null) ? json_encode($value) : null; - $types[] = '%s'; - break; - } - - $fields[$db_field_name] = $value; + // Don't include missing fields + if (!$include_missing && !exists) { + continue; } + + $value = $exists ? $metadata[$key] : null; + + // lowerCamelCase to snake_case + $db_field_name = strtolower(preg_replace('/(? $config['maxLength']) { + $value = mb_substr($value, 0, $config['maxLength']); + } + $types[] = '%s'; + break; + + case 'int': + $value = ($value !== null) ? intval($value) : null; + $types[] = '%d'; + break; + + case 'json': + $value = ($value !== null) ? json_encode($value) : null; + $types[] = '%s'; + break; + } + + $fields[$db_field_name] = $value; } return $fields;