From a5acd003d06707063e2bd9db4e8f75338edce380 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Sun, 27 Jan 2013 23:08:48 +0100 Subject: [PATCH] Rename init to main_library and remove init from libraries, add schema to db --- h5p.classes.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 813be01..06e76bb 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -122,7 +122,7 @@ class h5pValidator { 'majorVersion' => '/^[0-9]{1,5}$/', 'minorVersion' => '/^[0-9]{1,5}$/', ), - // 'init' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i', + 'mainLibrary' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i', 'embedTypes' => array('iframe', 'div'), ); @@ -160,7 +160,6 @@ class h5pValidator { ); private $libraryOptional = array( - // 'init' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i', '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)$/', 'description' => '/^.{1,}$/', @@ -300,17 +299,17 @@ class h5pValidator { continue; } - // validate json if a schema file is provided - $schemaPath = $file_path . DIRECTORY_SEPARATOR . 'schema.json'; - if (file_exists($schemaPath)) { - $schema = $this->getJsonData($schemaPath); - if ($schema === FALSE) { - $this->h5pF->setErrorMessage($this->h5pF->t('Invalid schema.json file has been included in the library %name', array('%name' => $file))); + // validate json if a semantics file is provided + $semanticsPath = $file_path . DIRECTORY_SEPARATOR . 'semantics.json'; + if (file_exists($semanticsPath)) { + $semantics = $this->getJsonData($semanticsPath, TRUE); + if ($semantics === FALSE) { + $this->h5pF->setErrorMessage($this->h5pF->t('Invalid semantics.json file has been included in the library %name', array('%name' => $file))); $valid = FALSE; continue; } else { - $h5pData->schema = $schema; + $h5pData['semantics'] = $semantics; } } @@ -560,7 +559,7 @@ class h5pValidator { return $valid; } - private function getJsonData($file_path) { + private function getJsonData($file_path, $return_as_string = FALSE) { $json = file_get_contents($file_path); if (!$json) { return FALSE; @@ -569,7 +568,7 @@ class h5pValidator { if (!$jsonData) { return FALSE; } - return $jsonData; + return $return_as_string ? $json : $jsonData; } private function arrayCopy(array $array) {