Skip to content

Commit

Permalink
MDL-73853 core_h5p: Add core lib changes after upgrading it
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Nov 8, 2022
1 parent 7ea2b6b commit 288963e
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 112 deletions.
183 changes: 164 additions & 19 deletions h5p/classes/framework.php
Expand Up @@ -14,18 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* \core_h5p\framework class
*
* @package core_h5p
* @copyright 2019 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core_h5p;

use Moodle\H5PFrameworkInterface;
use Moodle\H5PCore;

// phpcs:disable moodle.NamingConventions.ValidFunctionName.LowercaseMethod

/**
* Moodle's implementation of the H5P framework interface.
*
Expand All @@ -41,7 +36,7 @@ class framework implements H5PFrameworkInterface {
/** @var string The path to the last uploaded h5p file */
private $lastuploadedfile;

/** @var stored_file The .h5p file */
/** @var \stored_file The .h5p file */
private $file;

/**
Expand All @@ -64,16 +59,22 @@ public function getPlatformInfo() {
}

/**
* Fetches a file from a remote server using HTTP GET.
* Fetches a file from a remote server using HTTP GET
* Implements fetchExternalData.
*
* @param string $url Where you want to get or send data
* @param array $data Data to post to the URL
* @param bool $blocking Set to 'FALSE' to instantly time out (fire and forget)
* @param string $stream Path to where the file should be saved
* @return string The content (response body). NULL if something went wrong
* @param string $url Where you want to get or send data.
* @param array $data Data to post to the URL.
* @param bool $blocking Set to 'FALSE' to instantly time out (fire and forget).
* @param string $stream Path to where the file should be saved.
* @param bool $fulldata Return additional response data such as headers and potentially other data
* @param array $headers Headers to send
* @param array $files Files to send
* @param string $method
*
* @return string|array The content (response body), or an array with data. NULL if something went wrong
*/
public function fetchExternalData($url, $data = null, $blocking = true, $stream = null) {
public function fetchExternalData($url, $data = null, $blocking = true, $stream = null, $fulldata = false, $headers = [],
$files = [], $method = 'POST') {

if ($stream === null) {
// Download file.
Expand Down Expand Up @@ -351,7 +352,101 @@ public function t($message, $replacements = array()) {
'Your PHP version does not support ZipArchive.' => 'noziparchive',
'Your PHP version is outdated. H5P requires version 5.2 to function properly. Version 5.6 or later is recommended.' => 'oldphpversion',
'Your server does not have SSL enabled. SSL should be enabled to ensure a secure connection with the H5P hub.' => 'sslnotenabled',
'Your site was successfully registered with the H5P Hub.' => 'successfullyregisteredwithhub'
'Your site was successfully registered with the H5P Hub.' => 'successfullyregisteredwithhub',
'Sharing <strong>:title</strong>' => 'mainTitle',
'Edit info for <strong>:title</strong>' => 'editInfoTitle',
'Back' => 'back',
'Next' => 'next',
'Review info' => 'reviewInfo',
'Share' => 'share',
'Save changes' => 'saveChanges',
'Register on the H5P Hub' => 'registerOnHub',
'Save account settings' => 'updateRegistrationOnHub',
'Required Info' => 'requiredInfo',
'Optional Info' => 'optionalInfo',
'Review & Share' => 'reviewAndShare',
'Review & Save' => 'reviewAndSave',
'Shared' => 'shared',
'Step :step of :total' => 'currentStep',
'All content details can be edited after sharing' => 'sharingNote',
'Select a license for your content' => 'licenseDescription',
'Select a license version' => 'licenseVersionDescription',
'Disciplines' => 'disciplineLabel',
'You can select multiple disciplines' => 'disciplineDescription',
'You can select up to :numDisciplines disciplines' => 'disciplineLimitReachedMessage',
'Type to search for disciplines' => 'discipline:searchPlaceholder',
'in' => 'discipline:in',
'Dropdown button' => 'discipline:dropdownButton',
'Remove :chip from the list' => 'removeChip',
'Add keywords' => 'keywordsPlaceholder',
'Keywords' => 'keywords',
'You can add multiple keywords separated by commas. Press "Enter" or "Add" to confirm keywords' => 'keywordsDescription',
'Alt text' => 'altText',
'Please review the info below before you share' => 'reviewMessage',
'Sub-content (images, questions etc.) will be shared under :license unless otherwise specified in the authoring tool' => 'subContentWarning',
'Disciplines' => 'disciplines',
'Short description' => 'shortDescription',
'Long description' => 'longDescription',
'Icon' => 'icon',
'Screenshots' => 'screenshots',
'Help me choose a license' => 'helpChoosingLicense',
'Share failed.' => 'shareFailed',
'Editing failed.' => 'editingFailed',
'Something went wrong, please try to share again.' => 'shareTryAgain',
'Please wait...' => 'pleaseWait',
'Language' => 'language',
'Level' => 'level',
'Short description of your content' => 'shortDescriptionPlaceholder',
'Long description of your content' => 'longDescriptionPlaceholder',
'Description' => 'description',
'640x480px. If not selected content will use category icon' => 'iconDescription',
'Add up to five screenshots of your content' => 'screenshotsDescription',
'Submitted!' => 'submitted',
'Is now submitted to H5P Hub' => 'isNowSubmitted',
'A change has been submited for' => 'changeHasBeenSubmitted',
'Your content will normally be available in the Hub within one business day.' => 'contentAvailable',
'Your content will update soon' => 'contentUpdateSoon',
'Content License Info' => 'contentLicenseTitle',
'Click on a specific license to get info about proper usage' => 'licenseDialogDescription',
'Publisher' => 'publisherFieldTitle',
'This will display as the "Publisher name" on shared content' => 'publisherFieldDescription',
'Email Address' => 'emailAddress',
'Publisher description' => 'publisherDescription',
'This will be displayed under "Publisher info" on shared content' => 'publisherDescriptionText',
'Contact Person' => 'contactPerson',
'Phone' => 'phone',
'Address' => 'address',
'City' => 'city',
'Zip' => 'zip',
'Country' => 'country',
'Organization logo or avatar' => 'logoUploadText',
'I accept the <a href=":url" target="_blank">terms of use</a>' => 'acceptTerms',
'You have successfully registered an account on the H5P Hub' => 'successfullyRegistred',
'You account details can be changed' => 'successfullyRegistredDescription',
'Your H5P Hub account settings have successfully been changed' => 'successfullyUpdated',
'here' => 'accountDetailsLinkText',
'H5P Hub Registration' => 'registrationTitle',
'An error occurred' => 'registrationFailed',
'We were not able to create an account at this point. Something went wrong. Try again later.' => 'registrationFailedDescription',
':length is the maximum number of characters' => 'maxLength',
'Keyword already exists!' => 'keywordExists',
'License details' => 'licenseDetails',
'Remove' => 'remove',
'Remove image' => 'removeImage',
'Cancel sharing' => 'cancelPublishConfirmationDialogTitle',
'Are you sure you want to cancel the sharing process?' => 'cancelPublishConfirmationDialogDescription',
'No' => 'cancelPublishConfirmationDialogCancelButtonText',
'Yes' => 'cancelPublishConfirmationDialogConfirmButtonText',
'Add' => 'add',
'Typical age' => 'age',
'The target audience of this content. Possible input formats separated by commas: "1,34-45,-50,59-".' => 'ageDescription',
'Invalid input format for Typical age. Possible input formats separated by commas: "1, 34-45, -50, -59-".' => 'invalidAge',
'H5P will reach out to the contact person in case there are any issues with the content shared by the publisher. The contact person\'s name or other information will not be published or shared with third parties' => 'contactPersonDescription',
'The email address will be used by H5P to reach out to the publisher in case of any issues with the content or in case the publisher needs to recover their account. It will not be published or shared with any third parties' => 'emailAddressDescription',
'Copyrighted material cannot be shared in the H5P Content Hub. If the content is licensed with a OER friendly license like Creative Commons, please choose the appropriate license. If not this content cannot be shared.' => 'copyrightWarning',
'Keywords already exists!' => 'keywordsExits',
'Some of these keywords already exist' => 'someKeywordsExits',
'Assistive Technologies label' => 'a11yTitle:label',
];

if (isset($translationsmap[$message])) {
Expand Down Expand Up @@ -652,7 +747,7 @@ public function mayUpdateLibraries() {
/**
* Get the .h5p file.
*
* @return stored_file The .h5p file.
* @return \stored_file The .h5p file.
*/
public function get_file(): \stored_file {
if (!isset($this->file)) {
Expand Down Expand Up @@ -1140,7 +1235,7 @@ public function unlockDependencyStorage() {
* Delete a library from database and file system.
* Implements deleteLibrary.
*
* @param stdClass $library Library object with id, name, major version and minor version
* @param \stdClass $library Library object with id, name, major version and minor version
*/
public function deleteLibrary($library) {
$factory = new \core_h5p\factory();
Expand Down Expand Up @@ -1679,4 +1774,54 @@ public function get_latest_library_version(string $machinename): ?\stdClass {

return null;
}

/**
* Replace content hub metadata cache
*
* @param JsonSerializable $metadata Metadata as received from content hub
* @param string $lang Language in ISO 639-1
*
* @return mixed
*/
public function replaceContentHubMetadataCache($metadata, $lang) {
debugging('The replaceContentHubMetadataCache() method is not implemented.', DEBUG_DEVELOPER);
return null;
}

/**
* Get content hub metadata cache from db
*
* @param string $lang Language code in ISO 639-1
*
* @return JsonSerializable Json string
*/
public function getContentHubMetadataCache($lang = 'en') {
debugging('The getContentHubMetadataCache() method is not implemented.', DEBUG_DEVELOPER);
return null;
}

/**
* Get time of last content hub metadata check
*
* @param string $lang Language code iin ISO 639-1 format
*
* @return string|null Time in RFC7231 format
*/
public function getContentHubMetadataChecked($lang = 'en') {
debugging('The getContentHubMetadataChecked() method is not implemented.', DEBUG_DEVELOPER);
return null;
}

/**
* Set time of last content hub metadata check
*
* @param int|null $time Time in RFC7231 format
* @param string $lang Language code iin ISO 639-1 format
*
* @return bool True if successful
*/
public function setContentHubMetadataChecked($time, $lang = 'en') {
debugging('The setContentHubMetadataChecked() method is not implemented.', DEBUG_DEVELOPER);
return false;
}
}
18 changes: 10 additions & 8 deletions h5p/h5plib/v124/joubel/core/h5p-default-storage.class.php
@@ -1,5 +1,7 @@
<?php

namespace Moodle;

/**
* File info?
*/
Expand All @@ -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;

/**
Expand All @@ -39,10 +41,10 @@ function __construct($path, $alteditorpath = NULL) {
* 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);
Expand All @@ -60,7 +62,7 @@ public function saveContent($source, $content) {
$dest = "{$this->path}/content/{$content['id']}";

// Remove any old content
\H5PCore::deleteFileTree($dest);
H5PCore::deleteFileTree($dest);

self::copyFileTree($source, $dest);
}
Expand All @@ -72,7 +74,7 @@ public function saveContent($source, $content) {
* Content properties
*/
public function deleteContent($content) {
\H5PCore::deleteFileTree("{$this->path}/content/{$content['id']}");
H5PCore::deleteFileTree("{$this->path}/content/{$content['id']}");
}

/**
Expand Down Expand Up @@ -133,7 +135,7 @@ public function exportContent($id, $target) {
* 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}");
}
Expand Down Expand Up @@ -292,7 +294,7 @@ public function getContent($file_path) {
* 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) {
Expand Down
2 changes: 2 additions & 0 deletions h5p/h5plib/v124/joubel/core/h5p-development.class.php
@@ -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.
*/
Expand Down
2 changes: 2 additions & 0 deletions h5p/h5plib/v124/joubel/core/h5p-event-base.class.php
@@ -1,5 +1,7 @@
<?php

namespace Moodle;

/**
* The base class for H5P events. Extend to track H5P events in your system.
*
Expand Down
4 changes: 3 additions & 1 deletion h5p/h5plib/v124/joubel/core/h5p-file-storage.interface.php
@@ -1,5 +1,7 @@
<?php

namespace Moodle;

/**
* File info?
*/
Expand Down Expand Up @@ -138,7 +140,7 @@ public function getContent($file_path);
* 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);
Expand Down
3 changes: 3 additions & 0 deletions h5p/h5plib/v124/joubel/core/h5p-metadata.class.php
@@ -1,4 +1,7 @@
<?php

namespace Moodle;

/**
* Utility class for handling metadata
*/
Expand Down

0 comments on commit 288963e

Please sign in to comment.