Skip to content

Commit

Permalink
MDL-71408 h5plib_v124: Upgrade H5P core library to 1.24.02
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona authored and Jenkins committed May 4, 2021
1 parent 62b4eba commit ac7cd6c
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 84 deletions.
Binary file modified h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.eot
Binary file not shown.
68 changes: 34 additions & 34 deletions h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.ttf
Binary file not shown.
Binary file modified h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.woff
Binary file not shown.
2 changes: 1 addition & 1 deletion h5p/h5plib/v124/joubel/core/h5p-metadata.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function toDBArray($metadata, $include_title = true, $include_miss
switch ($config['type']) {
case 'text':
if ($value !== null && strlen($value) > $config['maxLength']) {
$value = \core_text::substr($value, 0, $config['maxLength']);
$value = mb_substr($value, 0, $config['maxLength']);
}
$types[] = '%s';
break;
Expand Down
54 changes: 19 additions & 35 deletions h5p/h5plib/v124/joubel/core/h5p.classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,14 +758,11 @@ public function isValidPackage($skipContent = FALSE, $upgradeOnly = FALSE) {
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();
Expand Down Expand Up @@ -812,7 +809,7 @@ public function isValidPackage($skipContent = FALSE, $upgradeOnly = FALSE) {
}
$totalSize += $fileStat['size'];

$fileName = \core_text::strtolower($fileStat['name']);
$fileName = mb_strtolower($fileStat['name']);
if (preg_match('/(^[\._]|\/[\._])/', $fileName) !== 0) {
continue; // Skip any file or folder starting with a . or _
}
Expand Down Expand Up @@ -2435,7 +2432,7 @@ public function getDependenciesFiles($dependencies, $prefix = '') {
// Using content dependencies
foreach ($dependencies as $dependency) {
if (isset($dependency['path']) === FALSE) {
$dependency['path'] = $this->getDependencyPath($dependency);
$dependency['path'] = 'libraries/' . H5PCore::libraryToString($dependency, TRUE);
$dependency['preloadedJs'] = explode(',', $dependency['preloadedJs']);
$dependency['preloadedCss'] = explode(',', $dependency['preloadedCss']);
}
Expand All @@ -2455,16 +2452,6 @@ public function getDependenciesFiles($dependencies, $prefix = '') {
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();
Expand Down Expand Up @@ -3215,23 +3202,21 @@ private static function getTimeFactor() {
* @return string
*/
private static function hashToken($action, $time_factor) {
global $SESSION;

if (!isset($SESSION->h5p_token)) {
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);
}

/**
Expand Down Expand Up @@ -3318,15 +3303,12 @@ public function checkSetupErrorMessage() {
$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());
Expand Down Expand Up @@ -3674,13 +3656,12 @@ public function validateText(&$text, $semantics) {

// 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');
}
*/
$text = \core_text::substr($text, 0, $semantics->maxLength);
else {
$text = mb_substr($text, 0, $semantics->maxLength);
}
}

// Check if string is according to optional regexp in semantics
Expand Down Expand Up @@ -3730,14 +3711,11 @@ public function validateContentFiles($contentPath, $isLibrary = FALSE) {
// 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;
}
*/
if (!preg_match($wl_regex, \core_text::strtolower($file))) {
else if (!preg_match($wl_regex, mb_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;
}
Expand Down Expand Up @@ -4279,7 +4257,7 @@ private function _filter_xss_split($m, $store = FALSE) {
return '<';
}

if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9\-]+)([^>]*)>?|(<!--.*?-->)$%', $string, $matches)) {
if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9\-]+)\s*([^>]*)>?|(<!--.*?-->)$%', $string, $matches)) {
// Seriously malformed.
return '';
}
Expand Down Expand Up @@ -4341,7 +4319,13 @@ private function _filter_xss_attributes($attr, $allowedStyles = FALSE) {
// Attribute name, href for instance.
if (preg_match('/^([-a-zA-Z]+)/', $attr, $match)) {
$attrName = strtolower($match[1]);
$skip = ($attrName == 'style' || substr($attrName, 0, 2) == 'on');
$skip = (
$attrName == 'style' ||
substr($attrName, 0, 2) == 'on' ||
substr($attrName, 0, 1) == '-' ||
// Ignore long attributes to avoid unnecessary processing overhead.
strlen($attrName) > 96
);
$working = $mode = 1;
$attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
}
Expand Down
2 changes: 1 addition & 1 deletion h5p/h5plib/v124/joubel/core/images/h5p.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 13 additions & 3 deletions h5p/h5plib/v124/joubel/core/js/h5p.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ H5P.t = function (key, vars, ns) {
H5P.Dialog = function (name, title, content, $element) {
/** @alias H5P.Dialog# */
var self = this;
var $dialog = H5P.jQuery('<div class="h5p-popup-dialog h5p-' + name + '-dialog">\
var $dialog = H5P.jQuery('<div class="h5p-popup-dialog h5p-' + name + '-dialog" role="dialog" tabindex="-1">\
<div class="h5p-inner">\
<h2>' + title + '</h2>\
<div class="h5p-scroll-content">' + content + '</div>\
Expand All @@ -1053,6 +1053,12 @@ H5P.Dialog = function (name, title, content, $element) {
.click(function () {
self.close();
})
.keypress(function (e) {
if (e.which === 13 || e.which === 32) {
self.close();
return false;
}
})
.end()
.find('a')
.click(function (e) {
Expand All @@ -1072,6 +1078,7 @@ H5P.Dialog = function (name, title, content, $element) {
$dialog.addClass('h5p-open'); // Fade in
// Triggering an event, in case something has to be done after dialog has been opened.
H5P.jQuery(self).trigger('dialog-opened', [$dialog]);
$dialog.focus();
}, 1);
};

Expand All @@ -1083,6 +1090,8 @@ H5P.Dialog = function (name, title, content, $element) {
setTimeout(function () {
$dialog.remove();
H5P.jQuery(self).trigger('dialog-closed', [$dialog]);
$element.attr('tabindex', '-1');
$element.focus();
}, 200);
};
};
Expand Down Expand Up @@ -1363,11 +1372,11 @@ H5P.openEmbedDialog = function ($element, embedCode, resizeCode, size, instance)
var $expander = H5P.jQuery(this);
var $content = $expander.next();
if ($content.is(':visible')) {
$expander.removeClass('h5p-open').text(H5P.t('showAdvanced'));
$expander.removeClass('h5p-open').text(H5P.t('showAdvanced')).attr('aria-expanded', 'true');
$content.hide();
}
else {
$expander.addClass('h5p-open').text(H5P.t('hideAdvanced'));
$expander.addClass('h5p-open').text(H5P.t('hideAdvanced')).attr('aria-expanded', 'false');
$content.show();
}
$dialog.find('.h5p-embed-code-container').each(function () {
Expand All @@ -1378,6 +1387,7 @@ H5P.openEmbedDialog = function ($element, embedCode, resizeCode, size, instance)
$dialog.find('.h5p-expander').click(expand).keypress(function (event) {
if (event.keyCode === 32) {
expand.apply(this);
return false;
}
});
}).on('dialog-closed', function () {
Expand Down
11 changes: 9 additions & 2 deletions h5p/h5plib/v124/joubel/core/js/jquery.js

Large diffs are not rendered by default.

34 changes: 26 additions & 8 deletions h5p/h5plib/v124/joubel/core/styles/h5p.css
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ div.h5p-fullscreen {
color: #999;
text-decoration: none;
outline: none;
line-height: 23px;
line-height: 22px;
}
.h5p-actions > .h5p-button:hover {
color: #666;
Expand All @@ -223,8 +223,8 @@ div.h5p-fullscreen {
.h5p-actions > .h5p-button:before {
font-family: 'H5P';
font-size: 20px;
line-height: 20px;
vertical-align: top;
line-height: 23px;
vertical-align: bottom;
padding-right: 0;
}
.h5p-actions > .h5p-button.h5p-export:before {
Expand Down Expand Up @@ -367,10 +367,6 @@ div.h5p-fullscreen {
}
.h5p-popup-dialog .h5p-close {
cursor: pointer;
}
.h5p-popup-dialog .h5p-close:after {
font-family: 'H5P';
content: "\e894";
font-size: 2em;
position: absolute;
right: 0;
Expand All @@ -383,6 +379,10 @@ div.h5p-fullscreen {
text-indent: -0.065em;
z-index: 3
}
.h5p-popup-dialog .h5p-close:after {
font-family: 'H5P';
content: "\e894";
}
.h5p-popup-dialog .h5p-close:hover:after,
.h5p-popup-dialog .h5p-close:focus:after {
color: #454545;
Expand Down Expand Up @@ -412,7 +412,6 @@ div.h5p-fullscreen {
.h5p-expander {
cursor: pointer;
font-size: 1.125em;
outline: none;
margin: 0.5em 0 0;
display: inline-block;
}
Expand Down Expand Up @@ -543,6 +542,25 @@ div.h5p-fullscreen {
opacity: 0;
visibility: hidden;
}
.h5p-content code,
.h5peditor code {
color: #3d3d3d;
background: #e0e0e0;
border-radius: 2px;
padding: 0 5px;
}
.h5p-content pre > code,
.h5peditor pre > code {
background-color: #fafafa;
padding: 5px;
display: block;
line-height: normal;
border: 1px solid #c7c7c7;
border-left-width: 4px;
max-width: 100%;
white-space: pre;
overflow: auto;
}


/* This is loaded as part of Core and not Editor since this needs to be outside the editor iframe */
Expand Down

0 comments on commit ac7cd6c

Please sign in to comment.