MDL-71408 h5plib_v124: Add required changes after lib upgrade
- The mbstring extension is required since Moodle 3.9 onwards so the upgrading steps have been removed because they are not required any more. - The pull-request for fixing some minor PHP7.4 problems has been integrated so this patch is not required.
This commit is contained in:
@@ -2432,7 +2432,7 @@ class H5PCore {
|
||||
// Using content dependencies
|
||||
foreach ($dependencies as $dependency) {
|
||||
if (isset($dependency['path']) === FALSE) {
|
||||
$dependency['path'] = 'libraries/' . H5PCore::libraryToString($dependency, TRUE);
|
||||
$dependency['path'] = $this->getDependencyPath($dependency);
|
||||
$dependency['preloadedJs'] = explode(',', $dependency['preloadedJs']);
|
||||
$dependency['preloadedCss'] = explode(',', $dependency['preloadedCss']);
|
||||
}
|
||||
@@ -2452,6 +2452,16 @@ class H5PCore {
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the dependency.
|
||||
*
|
||||
* @param stdClass $dependency
|
||||
* @return string
|
||||
*/
|
||||
protected function getDependencyPath(array $dependency): string {
|
||||
return H5PCore::libraryToString($dependency, TRUE);
|
||||
}
|
||||
|
||||
private static function getDependenciesHash(&$dependencies) {
|
||||
// Build hash of dependencies
|
||||
$toHash = array();
|
||||
@@ -3202,21 +3212,23 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-9
File diff suppressed because one or more lines are too long
@@ -14,7 +14,7 @@ Removed:
|
||||
Added:
|
||||
* readme_moodle.txt
|
||||
|
||||
Downloaded version: 1.24 release
|
||||
Downloaded version: 1.24.2 release
|
||||
|
||||
Changes:
|
||||
1. In order to allow the dependency path to be overridden by child H5PCore classes, a couple of minor changes have been added to the
|
||||
@@ -31,33 +31,21 @@ https://github.com/h5p/h5p-php-library/compare/master...andrewnicols:libraryPath
|
||||
Hopefully, when upgrading, these patch won't be needed because it will be included in the H5P library by default.
|
||||
|
||||
|
||||
2. As the mbstring extension is optional in Moodle, the following changes have been hardcoded to the library:
|
||||
2.1. Comment the following methods in h5p.classes.php file where the extension_loaded('mbstring') is called:
|
||||
* isValidPackage
|
||||
* checkSetupErrorMessage
|
||||
* validateText
|
||||
* validateContentFiles
|
||||
2. Replace the $_SESSION references to $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).
|
||||
|
||||
2.2. Change all the mb_uses straight to the core_text() alternatives. Version 1.24 has 3 ocurrences in h5p.classes.php
|
||||
and 1 ocurrence in h5p-metadata.class.php.
|
||||
|
||||
3. Another PR has been sent to H5P library (https://github.com/h5p/h5p-php-library/pull/69) to fix some php74 minor problems. The same fix is being applied locally by MDL-67077. Once we import a new version, if it includes de fix, this won't be needed to reapply and can be removed.
|
||||
|
||||
4. Replace the $_SESSION references to $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).
|
||||
h5p.classes.php file:
|
||||
- Into hashToken method:
|
||||
Declare the global $SESSION.
|
||||
Change all the $_SESSION by $SESSION.
|
||||
A script for testing this part can be found in MDL-68068
|
||||
|
||||
The point 2 from above won't be needed once the mbstring extension becomes mandatory in Moodle. A request has been
|
||||
sent to MDL-65809.
|
||||
|
||||
5. Upgrade and patch JQuery library.
|
||||
3. Upgrade and patch JQuery library.
|
||||
Once https://github.com/h5p/h5p-php-library/issues/83 gets integrated in
|
||||
H5P PHP Library (upgrading the JQuery version), this change won't be needed.
|
||||
|
||||
5.1. Prepare the patched JQuery 1.12.4 library following these steps:
|
||||
3.1. Prepare the patched JQuery 1.12.4 library following these steps:
|
||||
a) Download the uncompressed JQuery Core 1.12.4 from https://code.jquery.com/jquery-1.12.4.js
|
||||
b) Add the patch in https://snyk.io/vuln/SNYK-JS-JQUERY-174006 to the downloaded file.
|
||||
You'll need to replace this code (line 212):
|
||||
@@ -75,15 +63,14 @@ H5P PHP Library (upgrading the JQuery version), this change won't be needed.
|
||||
}
|
||||
c) Minify the patched jquery-1-12.4.js.
|
||||
|
||||
5.2. Edit h5p/h5plib/v124/joubel/core/js/jquery.js and replace the JQuery piece of code
|
||||
3.2. Edit h5p/h5plib/v124/joubel/core/js/jquery.js and replace the JQuery piece of code
|
||||
(at the beginning of the file, above the comment "// Snap this specific version of jQuery into H5P. jQuery.noConflict will")
|
||||
with the previous patched and minified JQuery version.
|
||||
|
||||
5.3. Remove the following comment in h5p/h5plib/v124/joubel/core/js/jquery.js:
|
||||
3.3. Remove the following comment in h5p/h5plib/v124/joubel/core/js/jquery.js:
|
||||
|
||||
/**
|
||||
* jQuery v1.9.1
|
||||
*
|
||||
* @member
|
||||
*/
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<location>joubel/core</location>
|
||||
<name>h5p-php-library</name>
|
||||
<license>GPL-3.0</license>
|
||||
<version>1.24</version>
|
||||
<version>1.24.2</version>
|
||||
</library>
|
||||
<library>
|
||||
<location>joubel/editor</location>
|
||||
|
||||
+4
-1
@@ -1,9 +1,12 @@
|
||||
This files describes API changes in core libraries and APIs,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.9.7 ===
|
||||
* The third-party library h5p/h5plib/v124/core has been updated to version 1.24.2.
|
||||
|
||||
=== 3.9 ===
|
||||
* A new plugintype has been created, h5plib, for having installed more
|
||||
than one H5P library version.
|
||||
* H5P third-party libraries have been moved from /lib/h5p to h5p/h5plib/v124,
|
||||
as an h5plib plugintype.
|
||||
* H5P Editor PHP library added to h5plib v124 plugin.
|
||||
* H5P Editor PHP library added to h5plib v124 plugin.
|
||||
|
||||
Reference in New Issue
Block a user