MDL-83268 core_h5p: Add core lib changes after upgrading it

This commit is contained in:
Sara Arjona 2024-09-25 15:47:10 +02:00
parent 15eb08acc2
commit 099f65274c
No known key found for this signature in database
10 changed files with 58 additions and 23 deletions

View File

@ -452,6 +452,11 @@ class framework implements H5PFrameworkInterface {
'width' => 'width',
'height' => 'height',
'Missing main library @library' => 'missingmainlibrary',
'Rotate Left' => 'rotateLeft',
'Rotate Right' => 'rotateRight',
'Crop Image' => 'cropImage',
'Confirm Crop' => 'confirmCrop',
'Cancel Crop' => 'cancelCrop',
];
if (isset($translationsmap[$message])) {

View File

@ -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 H5P\FileStorage 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::libraryToFolderName($library);
$dest = $this->path . '/libraries/' . H5PCore::libraryToFolderName($library);
// Make sure destination dir doesn't exist
\H5PCore::deleteFileTree($dest);
H5PCore::deleteFileTree($dest);
// Move library folder
self::copyFileTree($library['uploadDirectory'], $dest);
@ -64,7 +66,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);
}
@ -76,7 +78,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']}");
}
/**
@ -137,12 +139,12 @@ class H5PDefaultStorage implements \H5PFileStorage {
* Folder that library resides in
*/
public function exportLibrary($library, $target, $developmentPath=NULL) {
$srcFolder = \H5PCore::libraryToFolderName($library);
$srcFolder = H5PCore::libraryToFolderName($library);
$srcPath = ($developmentPath === NULL ? "/libraries/{$srcFolder}" : $developmentPath);
// Library folders inside the H5P zip file shall not contain patch version in the folder name
$library['patchVersionInFolderName'] = false;
$destinationFolder = \H5PCore::libraryToFolderName($library);
$destinationFolder = H5PCore::libraryToFolderName($library);
self::copyFileTree("{$this->path}{$srcPath}", "{$target}/{$destinationFolder}");
}
@ -301,7 +303,7 @@ class H5PDefaultStorage implements \H5PFileStorage {
* Save files uploaded through the editor.
* The files must be marked as temporary until the content form is saved.
*
* @param \H5peditorFile $file
* @param H5peditorFile $file
* @param int $contentid
*/
public function saveFile($file, $contentId) {

View File

@ -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.
*/

View File

@ -1,5 +1,7 @@
<?php
namespace Moodle;
/**
* The base class for H5P events. Extend to track H5P events in your system.
*

View File

@ -1,5 +1,7 @@
<?php
namespace Moodle;
/**
* File info?
*/
@ -145,7 +147,7 @@ interface H5PFileStorage {
* Save files uploaded through the editor.
* The files must be marked as temporary until the content form is saved.
*
* @param \H5peditorFile $file
* @param H5peditorFile $file
* @param int $contentId
*/
public function saveFile($file, $contentId);

View File

@ -1,4 +1,7 @@
<?php
namespace Moodle;
/**
* Utility class for handling metadata
*/

View File

@ -1,4 +1,9 @@
<?php
namespace Moodle;
use ZipArchive;
/**
* Interface defining functions the h5p library needs the framework to implement
*/
@ -1650,12 +1655,14 @@ class H5PStorage {
H5PMetadata::boolifyAndEncodeSettings($library['metadataSettings']) :
NULL;
// Save library folder
$this->h5pC->fs->saveLibrary($library);
// MOODLE PATCH: The library needs to be saved in database first before creating the files, because the libraryid is used
// as itemid for the files.
// Update our DB
$this->h5pF->saveLibraryData($library, $new);
// Save library folder
$this->h5pC->fs->saveLibrary($library);
// Remove cached assets that uses this library
if ($this->h5pC->aggregateAssets && isset($library['libraryId'])) {
$removedKeys = $this->h5pF->deleteCachedAssets($library['libraryId']);
@ -2149,7 +2156,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?
@ -2157,7 +2164,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;
@ -3324,21 +3331,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);
}
/**

View File

@ -1898,7 +1898,7 @@ H5P.MediaCopyright = function (copyright, labels, order, extraFields) {
* @param {string} source
* @param {number} width
* @param {number} height
* @param {string} alt
* @param {string} alt
* alternative text for the thumbnail
*/
H5P.Thumbnail = function (source, width, height, alt) {
@ -2377,6 +2377,11 @@ H5P.createTitle = function (rawTitle, maxLength) {
done('Not signed in.');
return;
}
// Moodle patch to let override this method.
if (H5P.contentUserDataAjax !== undefined) {
return H5P.contentUserDataAjax(contentId, dataType, subContentId, done, data, preload, invalidate, async);
}
// End of Moodle patch.
var options = {
url: H5PIntegration.ajax.contentUserData.replace(':contentId', contentId).replace(':dataType', dataType).replace(':subContentId', subContentId ? subContentId : 0),
@ -2720,7 +2725,7 @@ H5P.createTitle = function (rawTitle, maxLength) {
}
return path.substr(0, prefix.length) === prefix ? path : prefix + path;
}
return path; // Will automatically be looked for in tmp folder
});

View File

@ -4,7 +4,7 @@
<location>joubel/core</location>
<name>h5p-php-library</name>
<description>The general H5P library.</description>
<version>1.26</version>
<version>moodle-1.27.0</version>
<license>GPL</license>
<licenseversion>3.0+</licenseversion>
<repository>https://github.com/h5p/h5p-php-library/</repository>

View File

@ -48,6 +48,7 @@ $string['authorname'] = 'Author\'s name';
$string['authorrole'] = 'Author\'s role';
$string['back'] = 'Back';
$string['by'] = 'by';
$string['cancelCrop'] = 'Cancel crop';
$string['cancellabel'] = 'Cancel';
$string['cancelPublishConfirmationDialogCancelButtonText'] = 'No';
$string['cancelPublishConfirmationDialogConfirmButtonText'] = 'Yes';
@ -67,6 +68,7 @@ $string['changelog'] = 'Changelog';
$string['changeplaceholder'] = 'Photo cropped, text changed, etc.';
$string['city'] = 'City';
$string['close'] = 'Close';
$string['confirmCrop'] = 'Confirm crop';
$string['confirmdialogbody'] = 'Please confirm that you wish to proceed. This action cannot be undone.';
$string['confirmdialogheader'] = 'Confirm action';
$string['confirmlabel'] = 'Confirm';
@ -90,6 +92,7 @@ $string['couldNotParseJSONFromZip'] = 'Unable to parse JSON from the package: {$
$string['couldNotReadFileFromZip'] = 'Unable to read file from the package: {$a->%fileName}';
$string['country'] = 'Country';
$string['creativecommons'] = 'Creative Commons';
$string['cropImage'] = 'Crop image';
$string['currentStep'] = 'Step :step of :total';
$string['date'] = 'Date';
$string['deletelibraryconfirm'] = '<p>Are you sure you want to delete version <em>\'{$a->version}\'</em> from library <em>\'{$a->name}\'</em>? It will remove the library and all its uses.</p><p>This operation can not be undone.</p>';
@ -255,6 +258,8 @@ $string['reviewAndSave'] = 'Review & Save';
$string['reviewAndShare'] = 'Review & Share';
$string['reviewInfo'] = 'Review info';
$string['reviewMessage'] = 'Please review the info below before you share';
$string['rotateLeft'] = 'Rotate left';
$string['rotateRight'] = 'Rotate right';
$string['saveChanges'] = 'Save changes';
$string['screenshots'] = 'Screenshots';
$string['screenshotsDescription'] = 'Add up to five screenshots of your content';