From 6ef2f96e8bbb22798f77fabd8f3108769b73d2d7 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Fri, 23 Mar 2018 13:11:00 +0100 Subject: [PATCH] HFP-1905 Add logic for download/upload Add metadata fields to h5p.json --- h5p.classes.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index d8ed62e..3f54f0d 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -620,8 +620,17 @@ class H5PValidator { private $h5pOptional = array( 'contentType' => '/^.{1,255}$/', + // deprecated '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)$/', + 'authors' => array( + 'name' => '/^.{1,255}$/', + 'role' => '/^(Illustrator|Designer|Photographer)$/', + ), + '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)$/', + 'licenseVersion' => '/^(1.0|2.0|2.5|3.0|4.0)$/', + 'source' => '/^(http[s]?://.+)$', + 'yearsFrom' => '/^([0-9]{1,4})$/', + 'yearsTo' => '/^([0-9]{1,4})$/', 'dynamicDependencies' => array( 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', 'majorVersion' => '/^[0-9]{1,5}$/', @@ -629,7 +638,9 @@ class H5PValidator { ), 'w' => '/^[0-9]{1,4}$/', 'h' => '/^[0-9]{1,4}$/', + // deprecated 'metaKeywords' => '/^.{1,}$/', + // deprecated 'metaDescription' => '/^.{1,}$/', ); @@ -1584,14 +1595,30 @@ Class H5PExport { // Make embedType into an array $embedTypes = explode(', ', $content['embedType']); - // Build h5p.json + // Build h5p.json, the en-/de-coding will ensure proper escaping $h5pJson = array ( 'title' => $content['title'], 'language' => (isset($content['language']) && strlen(trim($content['language'])) !== 0) ? $content['language'] : 'und', 'mainLibrary' => $content['library']['name'], 'embedTypes' => $embedTypes, + 'authors' => json_decode(json_encode($content['metadata']['authors'], TRUE)), + 'source' => $content['metadata']['source'], + 'yearFrom' => $content['metadata']['yearFrom'], + 'yearTo' => $content['metadata']['yearTo'], + 'license' => $content['metadata']['license'], + 'licenseVersion' => $content['metadata']['licenseVersion'], + 'licenseExtras' => $content['metadata']['licenseExtras'], + 'changes' => json_decode(json_encode($content['metadata']['changes'], TRUE)), + 'authorComments' => $content['metadata']['authorComments'] ); + // Remove all values that are not set + foreach ($h5pJson as $key => $value) { + if (!isset($value)) { + unset($h5pJson[$key]); + } + } + // Add dependencies to h5p foreach ($content['dependencies'] as $dependency) { $library = $dependency['library'];