MDL-71408 lib: Add required changes after lib upgrade

- The pull-request for fixing some minor PHP7.4 problems has been
integrated so this patch is not required
This commit is contained in:
Sara Arjona
2021-04-30 19:14:10 +01:00
committed by Víctor Déniz
parent 45cd4e36fb
commit cd89f55a46
6 changed files with 51 additions and 32 deletions
+1 -1
View File
@@ -107,7 +107,7 @@ abstract class H5PMetadata {
switch ($config['type']) {
case 'text':
if ($value !== null && strlen($value) > $config['maxLength']) {
$value = mb_substr($value, 0, $config['maxLength']);
$value = \core_text::substr($value, 0, $config['maxLength']);
}
$types[] = '%s';
break;
+33 -11
View File
@@ -758,11 +758,14 @@ class H5PValidator {
unlink($tmpPath);
return FALSE;
}
// Moodle: the extension mbstring is optional.
/*
if (!extension_loaded('mbstring')) {
$this->h5pF->setErrorMessage($this->h5pF->t('The mbstring PHP extension is not loaded. H5P need this to function properly'), 'mbstring-unsupported');
unlink($tmpPath);
return FALSE;
}
*/
// Create a temporary dir to extract package in.
$tmpDir = $this->h5pF->getUploadedH5pFolderPath();
@@ -809,7 +812,7 @@ class H5PValidator {
}
$totalSize += $fileStat['size'];
$fileName = mb_strtolower($fileStat['name']);
$fileName = \core_text::strtolower($fileStat['name']);
if (preg_match('/(^[\._]|\/[\._])/', $fileName) !== 0) {
continue; // Skip any file or folder starting with a . or _
}
@@ -2432,7 +2435,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 +2455,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 +3215,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);
}
/**
@@ -3303,12 +3318,15 @@ class H5PCore {
$setup->disable_hub = TRUE;
}
// Moodle: the extension mbstring is optional.
/*
if (!extension_loaded('mbstring')) {
$setup->errors[] = $this->h5pF->t(
'The mbstring PHP extension is not loaded. H5P needs this to function properly'
);
$setup->disable_hub = TRUE;
}
*/
// Check php version >= 5.2
$php_version = explode('.', phpversion());
@@ -3656,12 +3674,13 @@ class H5PContentValidator {
// Check if string is within allowed length
if (isset($semantics->maxLength)) {
// Moodle: the extension mbstring is optional.
/*
if (!extension_loaded('mbstring')) {
$this->h5pF->setErrorMessage($this->h5pF->t('The mbstring PHP extension is not loaded. H5P need this to function properly'), 'mbstring-unsupported');
}
else {
$text = mb_substr($text, 0, $semantics->maxLength);
}
*/
$text = \core_text::substr($text, 0, $semantics->maxLength);
}
// Check if string is according to optional regexp in semantics
@@ -3711,11 +3730,14 @@ class H5PContentValidator {
// file name, 2. testing against a returned error array that could
// never be more than 1 element long anyway, 3. recreating the regex
// for every file.
// Moodle: the extension mbstring is optional.
/*
if (!extension_loaded('mbstring')) {
$this->h5pF->setErrorMessage($this->h5pF->t('The mbstring PHP extension is not loaded. H5P need this to function properly'), 'mbstring-unsupported');
$valid = FALSE;
}
else if (!preg_match($wl_regex, mb_strtolower($file))) {
*/
if (!preg_match($wl_regex, \core_text::strtolower($file))) {
$this->h5pF->setErrorMessage($this->h5pF->t('File "%filename" not allowed. Only files with the following extensions are allowed: %files-allowed.', array('%filename' => $file, '%files-allowed' => $whitelist)), 'not-in-whitelist');
$valid = FALSE;
}
+2 -9
View File
File diff suppressed because one or more lines are too long
+11 -10
View File
@@ -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
@@ -41,23 +41,25 @@ Hopefully, when upgrading, these patch won't be needed because it will be includ
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.
These points (2.1 and 2.2) won't be needed once the mbstring extension becomes mandatory in Moodle. A request was
sent to MDL-65809 and it's required from Moodle 3.9 onwards.
3. 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).
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.
4. 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:
4.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 +77,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
4.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:
4.3. Remove the following comment in h5p/h5plib/v124/joubel/core/js/jquery.js:
/**
* jQuery v1.9.1
*
* @member
*/
+1 -1
View File
@@ -324,7 +324,7 @@
<location>h5p</location>
<name>h5p-php-library</name>
<license>GPL-3.0</license>
<version>1.24</version>
<version>1.24.2</version>
</library>
<library>
<location>mdn-polyfills</location>
+3
View File
@@ -1,6 +1,9 @@
This files describes API changes in core libraries and APIs,
information provided here is intended especially for developers.
=== 3.8.9 ===
* The third-party library h5p/h5plib/v124/core has been updated to version 1.24.2.
=== 3.8.6 ===
* New DML function $DB->delete_records_subquery() to delete records based on a subquery in a way
that will work across databases.