Merge branch 'master' of github.com:h5p/h5p-php-library

semi-fullscreen
Frode Petterson 2018-11-16 12:41:24 +01:00
commit 1cd7b67010
3 changed files with 47 additions and 27 deletions

View File

@ -64,15 +64,16 @@ abstract class H5PMetadata {
',"authorComments":' . (isset($content->author_comments) ? json_encode($content->author_comments) : 'null') . '}'; ',"authorComments":' . (isset($content->author_comments) ? json_encode($content->author_comments) : 'null') . '}';
} }
/** /**
* Make the metadata into an associative array keyed by the property names * Make the metadata into an associative array keyed by the property names
* @param mixed $metadata Array or object containing metadata * @param mixed $metadata Array or object containing metadata
* @param bool $include_title * @param bool $include_title
* @param bool $include_missing For metadata fields not being set, skip 'em.
* Relevant for content upgrade
* @param array $types * @param array $types
* @return array * @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(); $fields = array();
if (!is_array($metadata)) { if (!is_array($metadata)) {
@ -81,12 +82,21 @@ abstract class H5PMetadata {
foreach (self::$fields as $key => $config) { foreach (self::$fields as $key => $config) {
// Ignore title?
if ($key === 'title' && !$include_title) { if ($key === 'title' && !$include_title) {
continue; continue;
} }
if (array_key_exists($key, $metadata)) { $exists = array_key_exists($key, $metadata);
$value = $metadata[$key];
// 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('/(?<!^)[A-Z]/', '_$0', $key)); $db_field_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $key));
switch ($config['type']) { switch ($config['type']) {
@ -110,7 +120,6 @@ abstract class H5PMetadata {
$fields[$db_field_name] = $value; $fields[$db_field_name] = $value;
} }
}
return $fields; return $fields;
} }

View File

@ -1864,7 +1864,7 @@ class H5PCore {
'js/h5p-utils.js', '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 static $defaultLibraryWhitelistExtras = 'js css';
public $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $fs, $h5pD, $disableFileCheck; public $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $fs, $h5pD, $disableFileCheck;
@ -3402,8 +3402,14 @@ class H5PContentValidator {
*/ */
public function validateMetadata($metadata) { public function validateMetadata($metadata) {
$semantics = $this->getMetadataSemantics(); $semantics = $this->getMetadataSemantics();
$group = (object)$metadata; $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( $this->validateGroup($group, (object) array(
'type' => 'group', 'type' => 'group',
'fields' => $semantics, 'fields' => $semantics,

5
js/jquery.js vendored
View File

@ -13,3 +13,8 @@ var H5P = window.H5P = window.H5P || {};
* @member * @member
*/ */
H5P.jQuery = jQuery.noConflict(true); H5P.jQuery = jQuery.noConflict(true);
H5P.jQuery.ajaxPrefilter(function (s) {
if (s.crossDomain) {
s.contents.script = false;
}
});