diff --git a/h5p-metadata.class.php b/h5p-metadata.class.php index 3a504e3..73223b1 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; diff --git a/h5p.classes.php b/h5p.classes.php index b0099bc..d1c05fa 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1864,7 +1864,7 @@ class H5PCore { 'js/h5p-utils.js', ); - public static $defaultContentWhitelist = 'json png jpg jpeg gif bmp tif tiff svg eot ttf woff woff2 otf webm mp4 ogg mp3 wav txt pdf rtf doc docx xls xlsx ppt pptx odt ods odp xml csv diff patch swf md textile vtt webvtt'; + public static $defaultContentWhitelist = 'json png jpg jpeg gif bmp tif tiff svg eot ttf woff woff2 otf webm mp4 ogg mp3 m4a wav txt pdf rtf doc docx xls xlsx ppt pptx odt ods odp xml csv diff patch swf md textile vtt webvtt'; public static $defaultLibraryWhitelistExtras = 'js css'; public $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $fs, $h5pD, $disableFileCheck; @@ -3402,8 +3402,14 @@ class H5PContentValidator { */ public function validateMetadata($metadata) { $semantics = $this->getMetadataSemantics(); - $group = (object)$metadata; + + // Stop complaining about "invalid selected option in select" for + // old content without license chosen. + if (!isset($group->license)) { + $group->license = 'U'; + } + $this->validateGroup($group, (object) array( 'type' => 'group', 'fields' => $semantics, diff --git a/js/jquery.js b/js/jquery.js index 90a3b83..a05d556 100644 --- a/js/jquery.js +++ b/js/jquery.js @@ -13,3 +13,8 @@ var H5P = window.H5P = window.H5P || {}; * @member */ H5P.jQuery = jQuery.noConflict(true); +H5P.jQuery.ajaxPrefilter(function (s) { + if (s.crossDomain) { + s.contents.script = false; + } +});