MDL-66609 core_h5p: Change core files when upgrading lib
This commit contains the changes required when upgrading the H5P PHP library.
This commit is contained in:
committed by
Andrew Nicols
parent
6415316646
commit
5da7a7fc31
@@ -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;
|
||||
|
||||
+26
-6
@@ -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();
|
||||
@@ -3303,12 +3316,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 +3672,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 +3728,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;
|
||||
}
|
||||
|
||||
@@ -14,18 +14,34 @@ Removed:
|
||||
Added:
|
||||
* readme_moodle.txt
|
||||
|
||||
Downloaded version: 1.23.1 release
|
||||
Downloaded version: 1.24 release
|
||||
|
||||
|
||||
=== 3.8 ===
|
||||
* In order to allow the dependency path to be overridden by child H5PCore classes, a couple of minor changes have been added to the
|
||||
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
|
||||
h5p.classes.php file:
|
||||
- Into the getDependenciesFiles method, the line 2435:
|
||||
$dependency['path'] = 'libraries/' . H5PCore::libraryToString($dependency, TRUE);
|
||||
|
||||
has been changed to:
|
||||
$dependency['path'] = $this->getDependencyPath($dependency);
|
||||
$dependency['path'] = $this->getDependencyPath($dependency);
|
||||
|
||||
- The method getDependencyPath has been added (line 2455). It might be rewritten by child classes.
|
||||
A PR has been sent to the H5P library with these changes:
|
||||
https://github.com/h5p/h5p-php-library/compare/master...andrewnicols:libraryPathSubclass
|
||||
Hopefully, when upgrading, these patch won't be needed because it will be included in the H5P library by default.
|
||||
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.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.
|
||||
|
||||
|
||||
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.
|
||||
@@ -318,6 +318,6 @@
|
||||
<location>h5p</location>
|
||||
<name>h5p-php-library</name>
|
||||
<license>GPL-3.0</license>
|
||||
<version>1.23.1</version>
|
||||
<version>1.24</version>
|
||||
</library>
|
||||
</libraries>
|
||||
|
||||
Reference in New Issue
Block a user