MDL-73830 h5plib_v124: Add required changes after lib upgrade

This commit is contained in:
cescobedo
2022-02-28 07:29:47 +01:00
parent 20916ff72a
commit 20fd467f35
10 changed files with 53 additions and 29 deletions
@@ -1,5 +1,7 @@
<?php
namespace Moodle;
/**
* File info?
*/
@@ -9,13 +11,13 @@
* operations using PHP's standard file operation functions.
*
* Some implementations of H5P that doesn't use the standard file system will
* want to create their own implementation of the \H5P\FileStorage interface.
* want to create their own implementation of the H5PFileStorage interface.
*
* @package H5P
* @copyright 2016 Joubel AS
* @license MIT
*/
class H5PDefaultStorage implements \H5PFileStorage {
class H5PDefaultStorage implements H5PFileStorage {
private $path, $alteditorpath;
/**
@@ -39,10 +41,10 @@ class H5PDefaultStorage implements \H5PFileStorage {
* Library properties
*/
public function saveLibrary($library) {
$dest = $this->path . '/libraries/' . \H5PCore::libraryToString($library, TRUE);
$dest = $this->path . '/libraries/' . H5PCore::libraryToString($library, TRUE);
// Make sure destination dir doesn't exist
\H5PCore::deleteFileTree($dest);
H5PCore::deleteFileTree($dest);
// Move library folder
self::copyFileTree($library['uploadDirectory'], $dest);
@@ -60,7 +62,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);
}
@@ -72,7 +74,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']}");
}
/**
@@ -133,7 +135,7 @@ class H5PDefaultStorage implements \H5PFileStorage {
* Folder that library resides in
*/
public function exportLibrary($library, $target, $developmentPath=NULL) {
$folder = \H5PCore::libraryToString($library, TRUE);
$folder = H5PCore::libraryToString($library, TRUE);
$srcPath = ($developmentPath === NULL ? "/libraries/{$folder}" : $developmentPath);
self::copyFileTree("{$this->path}{$srcPath}", "{$target}/{$folder}");
}
@@ -1,5 +1,7 @@
<?php
namespace Moodle;
/**
* This is a data layer which uses the file system so it isn't specific to any framework.
*/
@@ -1,5 +1,7 @@
<?php
namespace Moodle;
/**
* The base class for H5P events. Extend to track H5P events in your system.
*
@@ -1,5 +1,7 @@
<?php
namespace Moodle;
/**
* File info?
*/
@@ -1,4 +1,7 @@
<?php
namespace Moodle;
/**
* Utility class for handling metadata
*/
+25 -8
View File
@@ -1,4 +1,9 @@
<?php
namespace Moodle;
use ZipArchive;
/**
* Interface defining functions the h5p library needs the framework to implement
*/
@@ -2057,7 +2062,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?
@@ -2065,7 +2070,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;
@@ -2432,7 +2437,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 +2457,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 +3217,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);
}
/**
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
H5P PHP library
---------------
Downloaded last release from: https://github.com/h5p/h5p-php-library/releases
Downloaded last release from: https://github.com/h5p/h5p-php-library/tags
Import procedure:
@@ -14,18 +14,19 @@ Removed:
Added:
* readme_moodle.txt
Downloaded version: 1.24.2 release
NOTICE:
* We are following the composer version, 1.24.x according the suggestion from Joubel.
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
h5p.classes.php file:
- Into the getDependenciesFiles method, the line 2440:
- Into the getDependenciesFiles method, the line 2435:
$dependency['path'] = 'libraries/' . H5PCore::libraryToString($dependency, TRUE);
has been changed to:
$dependency['path'] = $this->getDependencyPath($dependency);
- The method getDependencyPath has been added (line 2466). It might be rewritten by child classes.
- The method getDependencyPath has been added (line 2460). 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.
@@ -38,6 +39,7 @@ h5p.classes.php file:
- Into hashToken method:
Declare the global $SESSION.
Change all the $_SESSION by $SESSION.
Change all the $_SESSION['xxxx'] by $SESSION->xxxx.
A script for testing this part can be found in MDL-68068
+1 -1
View File
@@ -4,7 +4,7 @@
<location>joubel/core</location>
<name>h5p-php-library</name>
<license>GPL-3.0</license>
<version>1.24.2</version>
<version>1.24.3</version>
</library>
<library>
<location>joubel/editor</location>
+1
View File
@@ -9,6 +9,7 @@ H5P content or not. Default value for this parameter is false.
* H5P subsystem is allowed to act as an API (level 2) too.
* Plugins can now implement h5p\canedit::can_edit_content method to define, if required, any custom behaviour for deciding
whether an H5P content can be edited or not. The specific plugin check will completely override the generic check.
* The third-party library h5p/h5plib/v124/core has been updated to version 1.24.3.
=== 3.11 ===
* Added $skipcapcheck parameter to H5P constructor, api::create_content_from_pluginfile_url() and