mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-71970 h5plib_v124: Add namespace to H5P core library
The joubel/core is a third-party library. A namespace has been added to avoid collision with other plugins using it (such as mod_hvp). That way, they will be able to have a different version without side effects.
This commit is contained in:
parent
1a63bccf46
commit
88c5228e61
7 changed files with 34 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Moodle;
|
||||
/**
|
||||
* File info?
|
||||
*/
|
||||
|
@ -9,13 +10,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 +40,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 +61,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 +73,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 +134,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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -19,13 +19,13 @@ Downloaded version: 1.24.2 release
|
|||
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 2435:
|
||||
- Into the getDependenciesFiles method, the line 2440:
|
||||
$dependency['path'] = 'libraries/' . H5PCore::libraryToString($dependency, TRUE);
|
||||
|
||||
has been changed to:
|
||||
$dependency['path'] = $this->getDependencyPath($dependency);
|
||||
|
||||
- The method getDependencyPath has been added (line 2455). It might be rewritten by child classes.
|
||||
- The method getDependencyPath has been added (line 2466). 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.
|
||||
|
@ -74,3 +74,11 @@ with the previous patched and minified JQuery version.
|
|||
*
|
||||
* @member
|
||||
*/
|
||||
|
||||
|
||||
4. Add namespace to this library to avoid collision. It means:
|
||||
|
||||
- Add the "namespace Moodle;" line at the top of all the h5p*.php files in the root folder.
|
||||
- Replace \H5Pxxx uses to H5Pxxx (for instance, in h5p-default-storage.class.php there are several references to \H5PCore that
|
||||
must be replaced with H5PCore).
|
||||
- Add "use ZipArchive;" in h5p.classes.h5p (check that it's still used before replacing it when upgrading the library).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue