From 44dfbbc4f66e1f75206dd28b9a8ba409b570d57c Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Wed, 28 Nov 2012 14:45:54 +0100 Subject: [PATCH] Validate requirements on the option form --- h5p.classes.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index a367d31..9115591 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -40,7 +40,7 @@ class h5pValidator { 'w' => '/^[0-9]{1,4}$/', 'h' => '/^[0-9]{1,4}$/', 'metaKeywords' => '/^.{1,}$/', - 'metaDescription' => '/^.{1,}$/', + 'metaDescription' => '/^.{1,}$/k', ); public function __construct($h5pFramework) { @@ -122,7 +122,7 @@ class h5pValidator { } if (isset($h5pData->preloadedCss)) { if (!$this->isExcistingFiles($h5pData->preloadedCss, $tmp_dir, $file)) { - // TODO: Handle the fact that we are missing js files + // TODO: Handle the fact that we are missing css files } } } @@ -199,6 +199,10 @@ class h5pValidator { private function validateRequiredH5pData($h5pData, $requirements, $library_name) { $errors = array(); foreach ($requirements as $required => $requirement) { + if (is_int($required)) { + // We have an array of allowed options + return validateH5pDataOptions($h5pData, $requirements, $library_name); + } if (isset($h5pData[$required])) { array_merge($errors, validateRequirement($h5pData[$required], $requirement, $library_name, $required)); } @@ -209,6 +213,16 @@ class h5pValidator { return $errors; } + private function validateH5pDataOptions($selected, $allowed, $library_name) { + $errors = array(); + foreach ($selected as $value) { + if (!in_array($value, $allowed)) { + $errors[] = $this->t('Illegal option %option in %library', array('%option' => $value, '%library' => $library_name)); + } + } + return $errors; + } + /** * Recursive function for removing directories. *