diff --git a/h5p/h5plib/v126/joubel/core/h5p-default-storage.class.php b/h5p/h5plib/v126/joubel/core/h5p-default-storage.class.php index c1eeaeca8b2..80757d19f59 100644 --- a/h5p/h5plib/v126/joubel/core/h5p-default-storage.class.php +++ b/h5p/h5plib/v126/joubel/core/h5p-default-storage.class.php @@ -1,5 +1,7 @@ path . '/libraries/' . \H5PCore::libraryToFolderName($library); + $dest = $this->path . '/libraries/' . H5PCore::libraryToFolderName($library); // Make sure destination dir doesn't exist - \H5PCore::deleteFileTree($dest); + H5PCore::deleteFileTree($dest); // Move library folder self::copyFileTree($library['uploadDirectory'], $dest); @@ -64,7 +66,7 @@ class H5PDefaultStorage implements \H5PFileStorage { $dest = "{$this->path}/content/{$content['id']}"; // Remove any old content - \H5PCore::deleteFileTree($dest); + H5PCore::deleteFileTree($dest); self::copyFileTree($source, $dest); } @@ -76,7 +78,7 @@ class H5PDefaultStorage implements \H5PFileStorage { * Content properties */ public function deleteContent($content) { - \H5PCore::deleteFileTree("{$this->path}/content/{$content['id']}"); + H5PCore::deleteFileTree("{$this->path}/content/{$content['id']}"); } /** @@ -137,7 +139,7 @@ class H5PDefaultStorage implements \H5PFileStorage { * Folder that library resides in */ public function exportLibrary($library, $target, $developmentPath=NULL) { - $folder = \H5PCore::libraryToFolderName($library); + $folder = H5PCore::libraryToFolderName($library); $srcPath = ($developmentPath === NULL ? "/libraries/{$folder}" : $developmentPath); self::copyFileTree("{$this->path}{$srcPath}", "{$target}/{$folder}"); diff --git a/h5p/h5plib/v126/joubel/core/h5p-development.class.php b/h5p/h5plib/v126/joubel/core/h5p-development.class.php index c2244025b25..b85df27150d 100644 --- a/h5p/h5plib/v126/joubel/core/h5p-development.class.php +++ b/h5p/h5plib/v126/joubel/core/h5p-development.class.php @@ -1,5 +1,7 @@ h5pC->fs->saveLibrary($library); - + // MOODLE PATCH: The library needs to be saved in database first before creating the files, because the libraryid is used + // as itemid for the files. // Update our DB $this->h5pF->saveLibraryData($library, $new); + // Save library folder + $this->h5pC->fs->saveLibrary($library); + // Remove cached assets that uses this library if ($this->h5pC->aggregateAssets && isset($library['libraryId'])) { $removedKeys = $this->h5pF->deleteCachedAssets($library['libraryId']); @@ -2148,7 +2155,7 @@ class H5PCore { * * @param H5PFrameworkInterface $H5PFramework * The frameworks implementation of the H5PFrameworkInterface - * @param string|\H5PFileStorage $path H5P file storage directory or class. + * @param string|H5PFileStorage $path H5P file storage directory or class. * @param string $url To file storage directory. * @param string $language code. Defaults to english. * @param boolean $export enabled? @@ -2156,7 +2163,7 @@ class H5PCore { public function __construct(H5PFrameworkInterface $H5PFramework, $path, $url, $language = 'en', $export = FALSE) { $this->h5pF = $H5PFramework; - $this->fs = ($path instanceof \H5PFileStorage ? $path : new \H5PDefaultStorage($path)); + $this->fs = ($path instanceof H5PFileStorage ? $path : new H5PDefaultStorage($path)); $this->url = $url; $this->exportEnabled = $export; @@ -3323,21 +3330,22 @@ class H5PCore { * @return string */ private static function hashToken($action, $time_factor) { - if (!isset($_SESSION['h5p_token'])) { + global $SESSION; + if (!isset($SESSION->h5p_token)) { // Create an unique key which is used to create action tokens for this session. if (function_exists('random_bytes')) { - $_SESSION['h5p_token'] = base64_encode(random_bytes(15)); + $SESSION->h5p_token = base64_encode(random_bytes(15)); } else if (function_exists('openssl_random_pseudo_bytes')) { - $_SESSION['h5p_token'] = base64_encode(openssl_random_pseudo_bytes(15)); + $SESSION->h5p_token = base64_encode(openssl_random_pseudo_bytes(15)); } else { - $_SESSION['h5p_token'] = uniqid('', TRUE); + $SESSION->h5p_token = uniqid('', TRUE); } } // Create hash and return - return substr(hash('md5', $action . $time_factor . $_SESSION['h5p_token']), -16, 13); + return substr(hash('md5', $action . $time_factor . $SESSION->h5p_token), -16, 13); } /** diff --git a/h5p/h5plib/v126/joubel/core/js/h5p.js b/h5p/h5plib/v126/joubel/core/js/h5p.js index f03a9598ce0..f6716506f38 100644 --- a/h5p/h5plib/v126/joubel/core/js/h5p.js +++ b/h5p/h5plib/v126/joubel/core/js/h5p.js @@ -1040,7 +1040,7 @@ H5P.t = function (key, vars, ns) { * @param {H5P.jQuery} $element * Which DOM element the dialog should be inserted after. * @param {H5P.jQuery} $returnElement - * Which DOM element the focus should be moved to on close + * Which DOM element the focus should be moved to on close */ H5P.Dialog = function (name, title, content, $element, $returnElement) { /** @alias H5P.Dialog# */ @@ -1894,7 +1894,7 @@ H5P.MediaCopyright = function (copyright, labels, order, extraFields) { * @param {string} source * @param {number} width * @param {number} height - * @param {string} alt + * @param {string} alt * alternative text for the thumbnail */ H5P.Thumbnail = function (source, width, height, alt) { @@ -2373,6 +2373,11 @@ H5P.createTitle = function (rawTitle, maxLength) { done('Not signed in.'); return; } + // Moodle patch to let override this method. + if (H5P.contentUserDataAjax !== undefined) { + return H5P.contentUserDataAjax(contentId, dataType, subContentId, done, data, preload, invalidate, async); + } + // End of Moodle patch. var options = { url: H5PIntegration.ajax.contentUserData.replace(':contentId', contentId).replace(':dataType', dataType).replace(':subContentId', subContentId ? subContentId : 0), @@ -2716,7 +2721,7 @@ H5P.createTitle = function (rawTitle, maxLength) { } return path.substr(0, prefix.length) === prefix ? path : prefix + path; } - + return path; // Will automatically be looked for in tmp folder }); diff --git a/h5p/h5plib/v126/joubel/core/readme_moodle.txt b/h5p/h5plib/v126/joubel/core/readme_moodle.txt index c44077ba5c0..862029dcc9b 100644 --- a/h5p/h5plib/v126/joubel/core/readme_moodle.txt +++ b/h5p/h5plib/v126/joubel/core/readme_moodle.txt @@ -3,6 +3,9 @@ H5P PHP library Downloaded last release from: https://github.com/h5p/h5p-php-library/tags +When no new tags are released, a specific commit can also be used. In that case, the version number used in the thirdpartylibs.xml +will be -. For instance, master-f3579c0. + Import procedure: * Remove the content in this folder (but the readme_moodle.txt) * Copy all the files from the folder repository in this directory. @@ -13,6 +16,11 @@ Removed: * .travis.yml Changed: + 0. Open the new version of joubel/core/h5p.classes.php and at the beginning of the H5PCore class (around line 2082), check the + value of the coreApi minor and major versions. If they are different from the values in the current Moodle version, instead of + upgrading the library in the current h5plib_vxxx, a new h5plib_vX.Y should be released (as it was done in MDL-80544). The new + h5plib module should be named taking into account that X is the coreApi.majorVersion and Y is the coreApi.minorVersion. + 1. Replace the $_SESSION references with $SESSION. That implies that the information is saved to backends, so only the Moodle one should be used by core (core should be free from $_SESSION and always use $SESSION). More specifically, in h5p.classes.php file, into hashToken() method: @@ -50,9 +58,3 @@ instance, if a new method is added to h5p-file-storage.interface.php, it should // End of Moodle patch. var options = { - -Notes: - * 2023-05-10 To avoid PHP 8.2 deprecations, please apply below patches: - - https://github.com/h5p/h5p-php-library/pull/146 - - https://github.com/h5p/h5p-php-library/pull/148 - See MDL-78147 for more details. diff --git a/h5p/h5plib/v126/thirdpartylibs.xml b/h5p/h5plib/v126/thirdpartylibs.xml index 534745b3e0b..0fa7a2f7df1 100644 --- a/h5p/h5plib/v126/thirdpartylibs.xml +++ b/h5p/h5plib/v126/thirdpartylibs.xml @@ -4,7 +4,7 @@ joubel/core h5p-php-library The general H5P library. - moodle-1.23 + 1.26 GPL 3.0+ https://github.com/h5p/h5p-php-library/