From 027a32baf1c3cddf48e57c59709500f91cb6f5b2 Mon Sep 17 00:00:00 2001 From: Frank Ronny Larsen Date: Sat, 23 Feb 2013 23:29:41 +0100 Subject: [PATCH] Fixes for defaultStyles, adds boolean requirement parsing too --- h5p.classes.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index af35495..86257f3 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -164,7 +164,7 @@ class H5PValidator { 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', 'majorVersion' => '/^[0-9]{1,5}$/', 'minorVersion' => '/^[0-9]{1,5}$/', - 'defaultStyles' => '/^(true|false)$/', + 'defaultStyles' => 'boolean', ), 'mainLibrary' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i', 'embedTypes' => array('iframe', 'div'), @@ -179,7 +179,7 @@ class H5PValidator { 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', 'majorVersion' => '/^[0-9]{1,5}$/', 'minorVersion' => '/^[0-9]{1,5}$/', - 'defaultStyles' => '/^(true|false)$/', + 'defaultStyles' => 'boolean', ), 'externalResources' => array( 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', @@ -546,16 +546,24 @@ class H5PValidator { $valid = TRUE; if (is_string($requirement)) { - // The requirement is a regexp, match it against the data - if (is_string($h5pData) || is_int($h5pData)) { - if (preg_match($requirement, $h5pData) === 0) { - $this->h5pF->setErrorMessage($this->h5pF->t("Invalid data provided for %property in %library", array('%property' => $property_name, '%library' => $library_name))); - $valid = FALSE; + if ($requirement == 'boolean') { + if (!is_bool($h5pData)) { + $this->h5pF->setErrorMessage($this->h5pF->t("Invalid data provided for %property in %library. Boolean expected.", array('%property' => $property_name, '%library' => $library_name))); + $valid = FALSE; } } else { - $this->h5pF->setErrorMessage($this->h5pF->t("Invalid data provided for %property in %library", array('%property' => $property_name, '%library' => $library_name))); - $valid = FALSE; + // The requirement is a regexp, match it against the data + if (is_string($h5pData) || is_int($h5pData)) { + if (preg_match($requirement, $h5pData) === 0) { + $this->h5pF->setErrorMessage($this->h5pF->t("Invalid data provided for %property in %library", array('%property' => $property_name, '%library' => $library_name))); + $valid = FALSE; + } + } + else { + $this->h5pF->setErrorMessage($this->h5pF->t("Invalid data provided for %property in %library", array('%property' => $property_name, '%library' => $library_name))); + $valid = FALSE; + } } } elseif (is_array($requirement)) { @@ -715,6 +723,7 @@ class H5PStorage { $librariesInUse[$preloadedDependency['machineName']] = array( 'library' => $library, 'preloaded' => $dynamic ? 0 : 1, + 'default_styles' => $preloadedDependency['defaultStyles'] ? 1 : 0, ); $this->getLibraryUsage($librariesInUse, $library, $dynamic); }