HFP-1905 Complete validation for h5p.json

pull/53/head
Oliver Tacke 2018-08-01 17:30:30 +02:00
parent 5be4ba1222
commit 6d50bae108
1 changed files with 17 additions and 8 deletions

View File

@ -620,22 +620,29 @@ class H5PValidator {
private $h5pOptional = array( private $h5pOptional = array(
'contentType' => '/^.{1,255}$/', 'contentType' => '/^.{1,255}$/',
'dynamicDependencies' => array(
'machineName' => '/^[\w0-9\-\.]{1,255}$/i',
'majorVersion' => '/^[0-9]{1,5}$/',
'minorVersion' => '/^[0-9]{1,5}$/',
),
// deprecated // deprecated
'author' => '/^.{1,255}$/', 'author' => '/^.{1,255}$/',
'authors' => array( 'authors' => array(
'name' => '/^.{1,255}$/', 'name' => '/^.{1,255}$/',
'role' => '/^\w+$/', 'role' => '/^\w+$/',
), ),
'license' => '/^(CC BY|CC BY-SA|CC BY-ND|CC BY-NC|CC BY-NC-SA|CC BY-NC-ND|GNU GPL|PD|ODC PDDL|CC PDM|U|C|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)$/', 'source' => '/^(http[s]?:\/\/.+)$/',
'licenseVersion' => '/^(1.0|2.0|2.5|3.0|4.0)$/', 'license' => '/^(CC BY|CC BY-SA|CC BY-ND|CC BY-NC|CC BY-NC-SA|CC BY-NC-ND|CC0 1\.0|GNU GPL|PD|ODC PDDL|CC PDM|U|C|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)$/',
'source' => '/^(http[s]?://.+)$', 'licenseVersion' => '/^(1\.0|2\.0|2\.5|3\.0|4\.0)$/',
'licenseExtras' => '/^.{1,5000}$/',
'yearsFrom' => '/^([0-9]{1,4})$/', 'yearsFrom' => '/^([0-9]{1,4})$/',
'yearsTo' => '/^([0-9]{1,4})$/', 'yearsTo' => '/^([0-9]{1,4})$/',
'dynamicDependencies' => array( 'changes' => array(
'machineName' => '/^[\w0-9\-\.]{1,255}$/i', 'date' => '/^[0-9]{2}-[0-9]{2}-[0-9]{2} [0-9]{1,2}:[0-9]{2}:[0-9]{2}$/',
'majorVersion' => '/^[0-9]{1,5}$/', 'author' => '/^.{1,255}$/',
'minorVersion' => '/^[0-9]{1,5}$/', 'log' => '/^.{1,5000}$/'
), ),
'authorComments' => '/^.{1,5000}$/',
'w' => '/^[0-9]{1,4}$/', 'w' => '/^[0-9]{1,4}$/',
'h' => '/^[0-9]{1,4}$/', 'h' => '/^[0-9]{1,4}$/',
// deprecated // deprecated
@ -1605,9 +1612,11 @@ Class H5PExport {
foreach(array('authors', 'source', 'license', 'licenseVersion', 'licenseExtras' ,'yearFrom', 'yearTo', 'changes', 'authorComments') as $field) { foreach(array('authors', 'source', 'license', 'licenseVersion', 'licenseExtras' ,'yearFrom', 'yearTo', 'changes', 'authorComments') as $field) {
if (isset($content['metadata'][$field])) { if (isset($content['metadata'][$field])) {
if (($field !== 'authors' && $field !== 'changes') || (count($content['metadata'][$field]) > 0)) {
$h5pJson[$field] = json_decode(json_encode($content['metadata'][$field], TRUE)); $h5pJson[$field] = json_decode(json_encode($content['metadata'][$field], TRUE));
} }
} }
}
// Remove all values that are not set // Remove all values that are not set
foreach ($h5pJson as $key => $value) { foreach ($h5pJson as $key => $value) {