From 4a41265a23bededea713418880e47fa7af10985e Mon Sep 17 00:00:00 2001 From: Frank Ronny Larsen Date: Sat, 23 Feb 2013 22:51:47 +0100 Subject: [PATCH 1/4] DEVEL: Added defaultStyles setting to library dependencies --- h5p.classes.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 7b941dc..af35495 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -164,6 +164,7 @@ class H5PValidator { 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', 'majorVersion' => '/^[0-9]{1,5}$/', 'minorVersion' => '/^[0-9]{1,5}$/', + 'defaultStyles' => '/^(true|false)$/', ), 'mainLibrary' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i', 'embedTypes' => array('iframe', 'div'), @@ -178,6 +179,7 @@ class H5PValidator { 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', 'majorVersion' => '/^[0-9]{1,5}$/', 'minorVersion' => '/^[0-9]{1,5}$/', + 'defaultStyles' => '/^(true|false)$/', ), 'externalResources' => array( 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', From 027a32baf1c3cddf48e57c59709500f91cb6f5b2 Mon Sep 17 00:00:00 2001 From: Frank Ronny Larsen Date: Sat, 23 Feb 2013 23:29:41 +0100 Subject: [PATCH 2/4] 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); } From 6daf5ce803f4848dfc7ecb0a5b12ed1ea696fee5 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Mon, 25 Feb 2013 14:15:52 +0100 Subject: [PATCH 3/4] Fixed video --- js/h5p.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index 8f01338..0cd835c 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -63,7 +63,7 @@ H5P.Coords = function(x, y, w, h) { // function to call when finished. // // TODO: Try to get rid of content path. -H5P.playVideo = function ($target, params, cp, onEnded) { +H5P.playVideo = function ($target, params, skipButtonText, cp, onEnded) { var $ = H5P.jQuery; var width = 635, // TODO: These should come from some dimension setting. @@ -87,13 +87,14 @@ H5P.playVideo = function ($target, params, cp, onEnded) { video.height = height; if (video.canPlayType !== undefined) { - for (var key in params) { + for (var i = 0; i < params.length; i++) { + var file = params[i]; // TODO: The files should probably be in their own group. - if (key.indexOf('video') === 0) { - if (video.canPlayType(key)) { + if (file.mime.indexOf('video') === 0) { + if (video.canPlayType(file.mime)) { var source = document.createElement('source'); - source.src = cp + params[key]; - source.type = key; + source.src = cp + file.path; + source.type = file.mime; video.appendChild(source); willWork = willWork || true; } @@ -107,7 +108,7 @@ H5P.playVideo = function ($target, params, cp, onEnded) { }); } } - + var fplayer = undefined; if (!willWork) { // use flowplayer fallback @@ -122,10 +123,10 @@ H5P.playVideo = function ($target, params, cp, onEnded) { }, { buffering: true, clip: { - url: window.location.protocol + '//' + window.location.host + cp + params['video/mp4'], + url: window.location.protocol + '//' + window.location.host + cp + params[0].path, autoPlay: true, autoBuffering: true, - onFinish: function (ev) { + onFinish: function () { onEnded(); }, onError: function () { @@ -144,8 +145,8 @@ H5P.playVideo = function ($target, params, cp, onEnded) { return; } - if (params.skipButtonText) { - var $skipButton = $('').click(function (ev) { + if (skipButtonText) { + var $skipButton = $('').click(function (ev) { if (fplayer !== undefined) { // Must stop this first. Errorama if we don't fplayer.stop().close().unload(); From ad828c198467585a599403ea5b19fd0ccf973cba Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Mon, 25 Feb 2013 15:45:34 +0100 Subject: [PATCH 4/4] Fixed php notice. --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 86257f3..c09fdbe 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -723,7 +723,7 @@ class H5PStorage { $librariesInUse[$preloadedDependency['machineName']] = array( 'library' => $library, 'preloaded' => $dynamic ? 0 : 1, - 'default_styles' => $preloadedDependency['defaultStyles'] ? 1 : 0, + 'default_styles' => isset($preloadedDependency['defaultStyles']) && $preloadedDependency['defaultStyles'] ? 1 : 0, ); $this->getLibraryUsage($librariesInUse, $library, $dynamic); }