From 1a9a9b8b0b4aed4c46a1206d081a9fb7c8dd586b Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Thu, 2 May 2013 17:09:48 +0200 Subject: [PATCH] Add code for supporting language files. The code doesn't work but doesn't seem to break anything either. --- h5p.classes.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index c1abcc2..e792732 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -450,6 +450,25 @@ class H5PValidator { } } + // validate language folder if it exists + $languagePath = $filePath . DIRECTORY_SEPARATOR . 'language'; + if (is_dir($languagePath)) { + $languageFiles = scandir($languagePath); + foreach ($languageFiles as $languageFile) { + if (preg_match('/^(-?[a-z]+){1,7}\.json$/i', $file) === 0) { + $this->h5pF->setErrorMessage($this->h5pF->t('Invalid language file %file in library %library', array('%file' => $languageFile, '%library' => $file))); + return FALSE; + } + $languageJson = $this->getJsonData($languageFile, TRUE); + if ($languageJson === FALSE) { + $this->h5pF->setErrorMessage($this->h5pF->t('Invalid language file %languageFile has been included in the library %name', array('%languageFile' => $languageFile, '%name' => $file))); + return FALSE; + } + $parts = explode('.', $languageFile); // $parts[0] is the language code + $h5pData['language'][$parts[0]] = $languageJson; + } + } + $validLibrary = $this->isValidH5pData($h5pData, $file, $this->libraryRequired, $this->libraryOptional); if (isset($h5pData['preloadedJs'])) {