From 08fda3e0f88b9721678cd230b74789aa390c3388 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Tue, 21 Jan 2020 13:45:10 +0100 Subject: [PATCH] MDL-67063 h5p: new h5plib plugintype for supporting multi coreAPI A new plugintype has been created for having more than one installed third-party H5P libraries. Existing libraries have been moved from lib/h5p to the new h5plib_v124 plugin. --- .eslintignore | 2 +- .stylelintignore | 2 +- admin/settings/h5p.php | 17 ++- filter/displayh5p/filter.php | 4 +- h5p/classes/autoloader.php | 60 --------- h5p/classes/core.php | 19 ++- h5p/classes/factory.php | 24 +++- h5p/classes/local/library/autoloader.php | 123 ++++++++++++++++++ h5p/classes/local/library/handler.php | 118 +++++++++++++++++ h5p/classes/player.php | 12 +- .../v124/classes/local/library/handler.php | 46 +++++++ h5p/h5plib/v124/classes/privacy/provider.php | 45 +++++++ .../h5plib/v124/joubel/core}/LICENSE.txt | 0 .../h5plib/v124/joubel/core}/README.txt | 0 .../h5plib/v124/joubel/core}/doc/spec_en.html | 0 .../h5plib/v124/joubel/core}/embed.php | 0 .../v124/joubel/core}/fonts/h5p-core-23.eot | Bin .../v124/joubel/core}/fonts/h5p-core-23.svg | 0 .../v124/joubel/core}/fonts/h5p-core-23.ttf | Bin .../v124/joubel/core}/fonts/h5p-core-23.woff | Bin .../core}/h5p-default-storage.class.php | 0 .../joubel/core}/h5p-development.class.php | 0 .../joubel/core}/h5p-event-base.class.php | 0 .../core}/h5p-file-storage.interface.php | 0 .../v124/joubel/core}/h5p-metadata.class.php | 0 .../h5plib/v124/joubel/core}/h5p.classes.php | 0 .../h5plib/v124/joubel/core}/images/h5p.svg | 0 .../v124/joubel/core}/images/throbber.gif | Bin .../v124/joubel/core}/js/h5p-action-bar.js | 0 .../core}/js/h5p-confirmation-dialog.js | 0 .../v124/joubel/core}/js/h5p-content-type.js | 0 .../core}/js/h5p-content-upgrade-process.js | 0 .../core}/js/h5p-content-upgrade-worker.js | 0 .../joubel/core}/js/h5p-content-upgrade.js | 0 .../v124/joubel/core}/js/h5p-data-view.js | 0 .../joubel/core}/js/h5p-display-options.js | 0 .../h5plib/v124/joubel/core}/js/h5p-embed.js | 0 .../joubel/core}/js/h5p-event-dispatcher.js | 0 .../joubel/core}/js/h5p-library-details.js | 0 .../v124/joubel/core}/js/h5p-library-list.js | 0 .../v124/joubel/core}/js/h5p-resizer.js | 0 .../h5plib/v124/joubel/core}/js/h5p-utils.js | 0 .../v124/joubel/core}/js/h5p-version.js | 0 .../v124/joubel/core}/js/h5p-x-api-event.js | 0 .../h5plib/v124/joubel/core}/js/h5p-x-api.js | 0 .../h5plib/v124/joubel/core}/js/h5p.js | 0 .../h5plib/v124/joubel/core}/js/jquery.js | 0 .../v124/joubel/core}/js/request-queue.js | 0 .../core}/js/settings/h5p-disable-hub.js | 0 .../v124/joubel/core}/readme_moodle.txt | 0 .../v124/joubel/core}/styles/h5p-admin.css | 0 .../core}/styles/h5p-confirmation-dialog.css | 0 .../joubel/core}/styles/h5p-core-button.css | 0 .../h5plib/v124/joubel/core}/styles/h5p.css | 0 h5p/h5plib/v124/lang/en/h5plib_v124.php | 29 +++++ h5p/h5plib/v124/thirdpartylibs.xml | 9 ++ h5p/h5plib/v124/version.php | 29 +++++ h5p/lib.php | 4 +- h5p/tests/event_h5p_deleted_test.php | 2 +- h5p/tests/event_h5p_viewed_test.php | 2 +- h5p/tests/external_test.php | 2 +- h5p/tests/generator/lib.php | 2 +- h5p/tests/generator_test.php | 2 +- h5p/tests/h5p_core_test.php | 2 + h5p/tests/h5p_file_storage_test.php | 4 +- h5p/upgrade.txt | 8 ++ lang/en/h5p.php | 6 +- lang/en/plugin.php | 2 + lib/adminlib.php | 41 ++++++ lib/classes/plugin_manager.php | 4 + lib/classes/plugininfo/h5plib.php | 88 +++++++++++++ lib/components.json | 3 +- lib/editor/atto/plugins/h5p/lib.php | 4 +- lib/tests/h5p_get_content_types_task_test.php | 2 +- lib/thirdpartylibs.xml | 6 - lib/upgrade.txt | 1 + 76 files changed, 625 insertions(+), 99 deletions(-) delete mode 100644 h5p/classes/autoloader.php create mode 100644 h5p/classes/local/library/autoloader.php create mode 100644 h5p/classes/local/library/handler.php create mode 100644 h5p/h5plib/v124/classes/local/library/handler.php create mode 100644 h5p/h5plib/v124/classes/privacy/provider.php rename {lib/h5p => h5p/h5plib/v124/joubel/core}/LICENSE.txt (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/README.txt (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/doc/spec_en.html (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/embed.php (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/fonts/h5p-core-23.eot (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/fonts/h5p-core-23.svg (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/fonts/h5p-core-23.ttf (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/fonts/h5p-core-23.woff (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/h5p-default-storage.class.php (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/h5p-development.class.php (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/h5p-event-base.class.php (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/h5p-file-storage.interface.php (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/h5p-metadata.class.php (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/h5p.classes.php (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/images/h5p.svg (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/images/throbber.gif (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-action-bar.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-confirmation-dialog.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-content-type.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-content-upgrade-process.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-content-upgrade-worker.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-content-upgrade.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-data-view.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-display-options.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-embed.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-event-dispatcher.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-library-details.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-library-list.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-resizer.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-utils.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-version.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-x-api-event.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p-x-api.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/h5p.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/jquery.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/request-queue.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/js/settings/h5p-disable-hub.js (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/readme_moodle.txt (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/styles/h5p-admin.css (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/styles/h5p-confirmation-dialog.css (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/styles/h5p-core-button.css (100%) rename {lib/h5p => h5p/h5plib/v124/joubel/core}/styles/h5p.css (100%) create mode 100644 h5p/h5plib/v124/lang/en/h5plib_v124.php create mode 100644 h5p/h5plib/v124/thirdpartylibs.xml create mode 100644 h5p/h5plib/v124/version.php create mode 100644 h5p/upgrade.txt create mode 100644 lib/classes/plugininfo/h5plib.php diff --git a/.eslintignore b/.eslintignore index 19f5a98b5fc..c111d11ca9c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -9,6 +9,7 @@ cache/stores/mongodb/MongoDB/ enrol/lti/ims-blti/ filter/algebra/AlgParser.pm filter/tex/mimetex.* +h5p/h5plib/v124/joubel/core/ lib/editor/atto/plugins/html/yui/src/codemirror/ lib/editor/atto/plugins/html/yui/src/beautify/ lib/editor/atto/yui/src/rangy/js/*.* @@ -63,7 +64,6 @@ lib/php-jwt/ lib/babel-polyfill/ lib/mdn-polyfills/ lib/emoji-data/ -lib/h5p/ media/player/videojs/amd/src/video-lazy.js media/player/videojs/amd/src/Youtube-lazy.js media/player/videojs/videojs/ diff --git a/.stylelintignore b/.stylelintignore index 4d4c82ff8d2..a828212ccbb 100644 --- a/.stylelintignore +++ b/.stylelintignore @@ -10,6 +10,7 @@ cache/stores/mongodb/MongoDB/ enrol/lti/ims-blti/ filter/algebra/AlgParser.pm filter/tex/mimetex.* +h5p/h5plib/v124/joubel/core/ lib/editor/atto/plugins/html/yui/src/codemirror/ lib/editor/atto/plugins/html/yui/src/beautify/ lib/editor/atto/yui/src/rangy/js/*.* @@ -64,7 +65,6 @@ lib/php-jwt/ lib/babel-polyfill/ lib/mdn-polyfills/ lib/emoji-data/ -lib/h5p/ media/player/videojs/amd/src/video-lazy.js media/player/videojs/amd/src/Youtube-lazy.js media/player/videojs/videojs/ diff --git a/admin/settings/h5p.php b/admin/settings/h5p.php index 881b34c2a9c..3b9302df95b 100644 --- a/admin/settings/h5p.php +++ b/admin/settings/h5p.php @@ -24,8 +24,21 @@ defined('MOODLE_INTERNAL') || die(); -// Settings page. +// H5P overview. $ADMIN->add('h5p', new admin_externalpage('h5poverview', get_string('h5poverview', 'core_h5p'), new moodle_url('/h5p/overview.php'), ['moodle/site:config'])); -$ADMIN->add('h5p', new admin_externalpage('h5psettings', get_string('h5pmanage', 'core_h5p'), + +// Manage H5P libraries page. +$ADMIN->add('h5p', new admin_externalpage('h5pmanagelibraries', get_string('h5pmanage', 'core_h5p'), new moodle_url('/h5p/libraries.php'), ['moodle/site:config', 'moodle/h5p:updatelibraries'])); + +// H5P settings. +$defaulth5plib = \core_h5p\local\library\autoloader::get_default_handler(); +if (!empty($defaulth5plib)) { + // As for now this page only has this setting, it will be hidden if there isn't any H5P libraries handler defined. + $settings = new admin_settingpage('h5psettings', new lang_string('h5psettings', 'core_h5p')); + $ADMIN->add('h5p', $settings); + + $settings->add(new admin_settings_h5plib_handler_select('h5plibraryhandler', new lang_string('h5plibraryhandler', 'core_h5p'), + new lang_string('h5plibraryhandler_help', 'core_h5p'), $defaulth5plib)); +} diff --git a/filter/displayh5p/filter.php b/filter/displayh5p/filter.php index 9e2bae7d174..2fbd02e0280 100644 --- a/filter/displayh5p/filter.php +++ b/filter/displayh5p/filter.php @@ -23,6 +23,8 @@ defined('MOODLE_INTERNAL') || die; +use core_h5p\local\library\autoloader; + /** * Display H5P filter * @@ -151,7 +153,7 @@ class filter_displayh5p extends moodle_text_filter { // We want to request the resizing script only once. if (self::$loadresizerjs) { - $resizerurl = new moodle_url('/lib/h5p/js/h5p-resizer.js'); + $resizerurl = autoloader::get_h5p_core_library_url('js/h5p-resizer.js'); $tagend .= ''; self::$loadresizerjs = false; } diff --git a/h5p/classes/autoloader.php b/h5p/classes/autoloader.php deleted file mode 100644 index 3e8daea83ef..00000000000 --- a/h5p/classes/autoloader.php +++ /dev/null @@ -1,60 +0,0 @@ -. - -/** - * H5P Autoloader. - * - * @package core_h5p - * @copyright 2019 Mihail Geshoski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace core_h5p; - -defined('MOODLE_INTERNAL') || die(); - -/** - * H5P Autoloader. - * - * @package core_h5p - * @copyright 2019 Mihail Geshoski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class autoloader { - public static function register(): void { - spl_autoload_register([self::class, 'autoload']); - } - - public static function autoload($classname): void { - global $CFG; - - $classes = [ - 'H5PCore' => '/lib/h5p/h5p.classes.php', - 'H5PHubEndpoints' => '/lib/h5p/h5p.classes.php', - 'H5PFrameworkInterface' => '/lib/h5p/h5p.classes.php', - 'H5PContentValidator' => 'lib/h5p/h5p.classes.php', - 'H5PValidator' => '/lib/h5p/h5p.classes.php', - 'H5PStorage' => '/lib/h5p/h5p.classes.php', - 'H5PDevelopment' => '/lib/h5p/h5p-development.class.php', - 'H5PFileStorage' => '/lib/h5p/h5p-file-storage.interface.php', - 'H5PMetadata' => '/lib/h5p/h5p-metadata.class.php', - ]; - - if (isset($classes[$classname])) { - require_once("{$CFG->dirroot}{$classes[$classname]}"); - } - } -} diff --git a/h5p/classes/core.php b/h5p/classes/core.php index 1458372c9af..3c15d85719d 100644 --- a/h5p/classes/core.php +++ b/h5p/classes/core.php @@ -32,6 +32,7 @@ use H5PCore; use H5PFrameworkInterface; use stdClass; use moodle_url; +use core_h5p\local\library\autoloader; /** * H5P core class, containing functions and storage shared by the other H5P classes. @@ -138,20 +139,24 @@ class core extends \H5PCore { } /** - * Get core JavaScript files. + * Get the list of JS scripts to include on the page. * * @return array The array containg urls of the core JavaScript files */ public static function get_scripts(): array { - global $CFG; - $cachebuster = '?ver='.$CFG->jsrev; - $liburl = $CFG->wwwroot . '/lib/h5p/'; - $urls = []; + global $PAGE; + $factory = new factory(); + $jsrev = $PAGE->requires->get_jsrev(); + $urls = []; foreach (self::$scripts as $script) { - $urls[] = new moodle_url($liburl . $script . $cachebuster); + $urls[] = autoloader::get_h5p_core_library_url($script, [ + 'ver' => $jsrev, + ]); } - $urls[] = new moodle_url("/h5p/js/h5p_overrides.js"); + $urls[] = new moodle_url("/h5p/js/h5p_overrides.js", [ + 'ver' => $jsrev, + ]); return $urls; } diff --git a/h5p/classes/factory.php b/h5p/classes/factory.php index 52c8cc09679..f1151799c96 100644 --- a/h5p/classes/factory.php +++ b/h5p/classes/factory.php @@ -27,11 +27,12 @@ namespace core_h5p; defined('MOODLE_INTERNAL') || die(); -use \core_h5p\framework as framework; -use \core_h5p\core as core; -use \H5PStorage as storage; -use \H5PValidator as validator; -use \H5PContentValidator as content_validator; +use core_h5p\local\library\autoloader; +use core_h5p\framework; +use core_h5p\core; +use H5PStorage as storage; +use H5PValidator as validator; +use H5PContentValidator as content_validator; /** * H5P factory class. @@ -43,6 +44,9 @@ use \H5PContentValidator as content_validator; */ class factory { + /** @var \core_h5p\local\library\autoloader The autoloader */ + protected $autoloader; + /** @var \core_h5p\core The Moodle H5PCore implementation */ protected $core; @@ -63,9 +67,19 @@ class factory { */ public function __construct() { // Loading classes we need from H5P third party library. + $this->autoloader = new autoloader(); autoloader::register(); } + /** + * Returns an instance of the \core_h5p\local\library\autoloader class. + * + * @return \core_h5p\local\library\autoloader + */ + public function get_autoloader(): autoloader { + return $this->autoloader; + } + /** * Returns an instance of the \core_h5p\framework class. * diff --git a/h5p/classes/local/library/autoloader.php b/h5p/classes/local/library/autoloader.php new file mode 100644 index 00000000000..39897d331dd --- /dev/null +++ b/h5p/classes/local/library/autoloader.php @@ -0,0 +1,123 @@ +. + +/** + * H5P autoloader management class. + * + * @package core_h5p + * @copyright 2019 Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core_h5p\local\library; + +defined('MOODLE_INTERNAL') || die(); + +/** + * H5P autoloader management class. + * + * @package core_h5p + * @copyright 2019 Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class autoloader { + + /** + * Returns the list of plugins that can work as H5P library handlers (have class PLUGINNAME\local\library\handler) + * @return array with the format: pluginname => class + */ + public static function get_all_handlers(): array { + $handlers = []; + foreach (\core_component::get_plugin_types() as $ptype => $unused) { + $plugins = \core_component::get_plugin_list_with_class($ptype, 'local\library\handler') + + \core_component::get_plugin_list_with_class($ptype, 'local_library_handler'); + // Allow plugins to have the class either with namespace or without (useful for unittest). + foreach ($plugins as $pname => $class) { + $handlers[$pname] = $class; + } + } + + return $handlers; + } + + /** + * Returns the default H5P library handler. + * @return string|null H5P library handler class + */ + public static function get_default_handler(): ?string { + $default = null; + $handlers = self::get_all_handlers(); + if (!empty($handlers)) { + // The default handler will be the first in the list. + $default = array_shift($handlers); + } + + return $default; + } + + /** + * Returns the current H5P library handler class. + * + * @return string H5P library handler class + * @throws \moodle_exception + */ + public static function get_handler_classname(): string { + global $CFG; + + $handlers = self::get_all_handlers(); + if (!empty($CFG->h5plibraryhandler)) { + if (isset($handlers[$CFG->h5plibraryhandler])) { + return $handlers[$CFG->h5plibraryhandler]; + } + } + + // If no handler has been defined or it doesn't exist, return the default one. + $defaulthandler = self::get_default_handler(); + if (empty($defaulthandler)) { + // If there is no default handler, throw an exception. + throw new \moodle_exception('noh5plibhandlerdefined', 'core_h5p'); + } + + return $defaulthandler; + } + + /** + * Get the current version of the H5P core library. + * + * @return string + */ + public static function get_h5p_version(): string { + return component_class_callback(self::get_handler_classname(), 'get_h5p_version', []); + } + + /** + * Get a URL for the current H5P Core Library. + * + * @param string $filepath The path within the h5p root + * @param array $params these params override current params or add new + * @return null|moodle_url + */ + public static function get_h5p_core_library_url(?string $filepath = null, ?array $params = null): ?\moodle_url { + return component_class_callback(self::get_handler_classname(), 'get_h5p_core_library_url', [$filepath, $params]); + } + + /** + * Register the H5P autoloader. + */ + public static function register(): void { + component_class_callback(self::get_handler_classname(), 'register', []); + } +} diff --git a/h5p/classes/local/library/handler.php b/h5p/classes/local/library/handler.php new file mode 100644 index 00000000000..9bb48649424 --- /dev/null +++ b/h5p/classes/local/library/handler.php @@ -0,0 +1,118 @@ +. + +/** + * Base class for library handlers. + * + * @package core_h5p + * @copyright 2019 Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core_h5p\local\library; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Base class for library handlers. + * + * If a new H5P libraries handler plugin has to be created, it has to define class + * PLUGINNAME\local\library\handler that extends \core_h5p\local\library\handler. + * + * @package core_h5p + * @copyright 2019 Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +abstract class handler { + + /** + * Get the current version of the H5P core library. + * + * @return string + */ + abstract public static function get_h5p_version(): string; + + /** + * Get the base path for the H5P Libraries. + * + * @return null|string + */ + public static function get_h5p_library_base(): ?string { + $h5pversion = static::get_h5p_version(); + return "/h5p/h5plib/v{$h5pversion}/joubel"; + } + + /** + * Get the base path for the current H5P Core Library. + * + * @param string $filepath The path within the H5P root + * @return null|string + */ + public static function get_h5p_core_library_base(?string $filepath = null): ?string { + return static::get_h5p_library_base() . "/core/{$filepath}"; + } + + /** + * Register the H5P autoloader. + */ + public static function register(): void { + spl_autoload_register([static::class, 'autoload']); + } + + /** + * SPL Autoloading function for H5P. + * + * @param string $classname The name of the class to load + */ + public static function autoload($classname): void { + global $CFG; + + $classes = static::get_class_list(); + + if (isset($classes[$classname])) { + require_once($CFG->dirroot . static::get_h5p_core_library_base($classes[$classname])); + } + } + + /** + * Get a URL for the current H5P Core Library. + * + * @param string $filepath The path within the h5p root + * @param array $params these params override current params or add new + * @return null|moodle_url + */ + public static function get_h5p_core_library_url(?string $filepath = null, ?array $params = null): ?\moodle_url { + return new \moodle_url(static::get_h5p_core_library_base($filepath), $params); + } + + /** + * Return the list of classes with their location within the joubel directory. + * + * @return array + */ + protected static function get_class_list(): array { + return [ + 'H5PCore' => 'h5p.classes.php', + 'H5PFrameworkInterface' => 'h5p.classes.php', + 'H5PContentValidator' => 'h5p.classes.php', + 'H5PValidator' => 'h5p.classes.php', + 'H5PStorage' => 'h5p.classes.php', + 'H5PDevelopment' => 'h5p-development.class.php', + 'H5PFileStorage' => 'h5p-file-storage.interface.php', + 'H5PMetadata' => 'h5p-metadata.class.php', + ]; + } +} diff --git a/h5p/classes/player.php b/h5p/classes/player.php index f9d32ab8dfb..b6c355e6422 100644 --- a/h5p/classes/player.php +++ b/h5p/classes/player.php @@ -26,6 +26,8 @@ namespace core_h5p; defined('MOODLE_INTERNAL') || die(); +use core_h5p\local\library\autoloader; + /** * H5P player class, for displaying any local H5P content. * @@ -598,13 +600,15 @@ class player { $cachebuster = $this->get_cache_buster(); // Use relative URL to support both http and https. - $liburl = $CFG->wwwroot . '/lib/h5p/'; + $liburl = autoloader::get_h5p_core_library_url()->out(); $relpath = '/' . preg_replace('/^[^:]+:\/\/[^\/]+\//', '', $liburl); // Add core stylesheets. foreach (core::$styles as $style) { $settings['core']['styles'][] = $relpath . $style . $cachebuster; - $this->cssrequires[] = new \moodle_url($liburl . $style . $cachebuster); + $this->cssrequires[] = autoloader::get_h5p_core_library_url($style, [ + 'ver' => $cachebuster, + ]); } // Add core JavaScript. foreach (core::get_scripts() as $script) { @@ -687,7 +691,7 @@ class player { 'crossorigin' => null, 'libraryConfig' => $this->core->h5pF->getLibraryConfig(), 'pluginCacheBuster' => $this->get_cache_buster(), - 'libraryUrl' => $basepath . 'lib/h5p/js', + 'libraryUrl' => autoloader::get_h5p_core_library_url('js'), 'moodleLibraryPaths' => $this->core->get_dependency_roots($this->h5pid), ); @@ -715,7 +719,7 @@ class player { global $OUTPUT; $template = new \stdClass(); - $template->resizeurl = new \moodle_url('/lib/h5p/js/h5p-resizer.js'); + $template->resizeurl = autoloader::get_h5p_core_library_url('js/h5p-resizer.js'); return $OUTPUT->render_from_template('core_h5p/h5presize', $template); } diff --git a/h5p/h5plib/v124/classes/local/library/handler.php b/h5p/h5plib/v124/classes/local/library/handler.php new file mode 100644 index 00000000000..f9a78517b8c --- /dev/null +++ b/h5p/h5plib/v124/classes/local/library/handler.php @@ -0,0 +1,46 @@ +. + +/** + * Handler for the version 1.24 of the H5P library. + * + * @package h5plib_v124 + * @copyright 2019 Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace h5plib_v124\local\library; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Handler for the version 1.24 of the H5P library. + * + * @package h5plib_v124 + * @copyright 2019 Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class handler extends \core_h5p\local\library\handler { + + /** + * Get the current version of the H5P core library. + * + * @return string + */ + public static function get_h5p_version(): string { + return '124'; + } +} diff --git a/h5p/h5plib/v124/classes/privacy/provider.php b/h5p/h5plib/v124/classes/privacy/provider.php new file mode 100644 index 00000000000..b6c82425d7a --- /dev/null +++ b/h5p/h5plib/v124/classes/privacy/provider.php @@ -0,0 +1,45 @@ +. + +/** + * Privacy provider implementation for the version 1.24 of the H5P library. + * + * @package h5plib_v124 + * @copyright 2020 Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace h5plib_v124\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy provider implementation for the version 1.24 of the H5P library. + * + * @copyright 2020 Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/lib/h5p/LICENSE.txt b/h5p/h5plib/v124/joubel/core/LICENSE.txt similarity index 100% rename from lib/h5p/LICENSE.txt rename to h5p/h5plib/v124/joubel/core/LICENSE.txt diff --git a/lib/h5p/README.txt b/h5p/h5plib/v124/joubel/core/README.txt similarity index 100% rename from lib/h5p/README.txt rename to h5p/h5plib/v124/joubel/core/README.txt diff --git a/lib/h5p/doc/spec_en.html b/h5p/h5plib/v124/joubel/core/doc/spec_en.html similarity index 100% rename from lib/h5p/doc/spec_en.html rename to h5p/h5plib/v124/joubel/core/doc/spec_en.html diff --git a/lib/h5p/embed.php b/h5p/h5plib/v124/joubel/core/embed.php similarity index 100% rename from lib/h5p/embed.php rename to h5p/h5plib/v124/joubel/core/embed.php diff --git a/lib/h5p/fonts/h5p-core-23.eot b/h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.eot similarity index 100% rename from lib/h5p/fonts/h5p-core-23.eot rename to h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.eot diff --git a/lib/h5p/fonts/h5p-core-23.svg b/h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.svg similarity index 100% rename from lib/h5p/fonts/h5p-core-23.svg rename to h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.svg diff --git a/lib/h5p/fonts/h5p-core-23.ttf b/h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.ttf similarity index 100% rename from lib/h5p/fonts/h5p-core-23.ttf rename to h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.ttf diff --git a/lib/h5p/fonts/h5p-core-23.woff b/h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.woff similarity index 100% rename from lib/h5p/fonts/h5p-core-23.woff rename to h5p/h5plib/v124/joubel/core/fonts/h5p-core-23.woff diff --git a/lib/h5p/h5p-default-storage.class.php b/h5p/h5plib/v124/joubel/core/h5p-default-storage.class.php similarity index 100% rename from lib/h5p/h5p-default-storage.class.php rename to h5p/h5plib/v124/joubel/core/h5p-default-storage.class.php diff --git a/lib/h5p/h5p-development.class.php b/h5p/h5plib/v124/joubel/core/h5p-development.class.php similarity index 100% rename from lib/h5p/h5p-development.class.php rename to h5p/h5plib/v124/joubel/core/h5p-development.class.php diff --git a/lib/h5p/h5p-event-base.class.php b/h5p/h5plib/v124/joubel/core/h5p-event-base.class.php similarity index 100% rename from lib/h5p/h5p-event-base.class.php rename to h5p/h5plib/v124/joubel/core/h5p-event-base.class.php diff --git a/lib/h5p/h5p-file-storage.interface.php b/h5p/h5plib/v124/joubel/core/h5p-file-storage.interface.php similarity index 100% rename from lib/h5p/h5p-file-storage.interface.php rename to h5p/h5plib/v124/joubel/core/h5p-file-storage.interface.php diff --git a/lib/h5p/h5p-metadata.class.php b/h5p/h5plib/v124/joubel/core/h5p-metadata.class.php similarity index 100% rename from lib/h5p/h5p-metadata.class.php rename to h5p/h5plib/v124/joubel/core/h5p-metadata.class.php diff --git a/lib/h5p/h5p.classes.php b/h5p/h5plib/v124/joubel/core/h5p.classes.php similarity index 100% rename from lib/h5p/h5p.classes.php rename to h5p/h5plib/v124/joubel/core/h5p.classes.php diff --git a/lib/h5p/images/h5p.svg b/h5p/h5plib/v124/joubel/core/images/h5p.svg similarity index 100% rename from lib/h5p/images/h5p.svg rename to h5p/h5plib/v124/joubel/core/images/h5p.svg diff --git a/lib/h5p/images/throbber.gif b/h5p/h5plib/v124/joubel/core/images/throbber.gif similarity index 100% rename from lib/h5p/images/throbber.gif rename to h5p/h5plib/v124/joubel/core/images/throbber.gif diff --git a/lib/h5p/js/h5p-action-bar.js b/h5p/h5plib/v124/joubel/core/js/h5p-action-bar.js similarity index 100% rename from lib/h5p/js/h5p-action-bar.js rename to h5p/h5plib/v124/joubel/core/js/h5p-action-bar.js diff --git a/lib/h5p/js/h5p-confirmation-dialog.js b/h5p/h5plib/v124/joubel/core/js/h5p-confirmation-dialog.js similarity index 100% rename from lib/h5p/js/h5p-confirmation-dialog.js rename to h5p/h5plib/v124/joubel/core/js/h5p-confirmation-dialog.js diff --git a/lib/h5p/js/h5p-content-type.js b/h5p/h5plib/v124/joubel/core/js/h5p-content-type.js similarity index 100% rename from lib/h5p/js/h5p-content-type.js rename to h5p/h5plib/v124/joubel/core/js/h5p-content-type.js diff --git a/lib/h5p/js/h5p-content-upgrade-process.js b/h5p/h5plib/v124/joubel/core/js/h5p-content-upgrade-process.js similarity index 100% rename from lib/h5p/js/h5p-content-upgrade-process.js rename to h5p/h5plib/v124/joubel/core/js/h5p-content-upgrade-process.js diff --git a/lib/h5p/js/h5p-content-upgrade-worker.js b/h5p/h5plib/v124/joubel/core/js/h5p-content-upgrade-worker.js similarity index 100% rename from lib/h5p/js/h5p-content-upgrade-worker.js rename to h5p/h5plib/v124/joubel/core/js/h5p-content-upgrade-worker.js diff --git a/lib/h5p/js/h5p-content-upgrade.js b/h5p/h5plib/v124/joubel/core/js/h5p-content-upgrade.js similarity index 100% rename from lib/h5p/js/h5p-content-upgrade.js rename to h5p/h5plib/v124/joubel/core/js/h5p-content-upgrade.js diff --git a/lib/h5p/js/h5p-data-view.js b/h5p/h5plib/v124/joubel/core/js/h5p-data-view.js similarity index 100% rename from lib/h5p/js/h5p-data-view.js rename to h5p/h5plib/v124/joubel/core/js/h5p-data-view.js diff --git a/lib/h5p/js/h5p-display-options.js b/h5p/h5plib/v124/joubel/core/js/h5p-display-options.js similarity index 100% rename from lib/h5p/js/h5p-display-options.js rename to h5p/h5plib/v124/joubel/core/js/h5p-display-options.js diff --git a/lib/h5p/js/h5p-embed.js b/h5p/h5plib/v124/joubel/core/js/h5p-embed.js similarity index 100% rename from lib/h5p/js/h5p-embed.js rename to h5p/h5plib/v124/joubel/core/js/h5p-embed.js diff --git a/lib/h5p/js/h5p-event-dispatcher.js b/h5p/h5plib/v124/joubel/core/js/h5p-event-dispatcher.js similarity index 100% rename from lib/h5p/js/h5p-event-dispatcher.js rename to h5p/h5plib/v124/joubel/core/js/h5p-event-dispatcher.js diff --git a/lib/h5p/js/h5p-library-details.js b/h5p/h5plib/v124/joubel/core/js/h5p-library-details.js similarity index 100% rename from lib/h5p/js/h5p-library-details.js rename to h5p/h5plib/v124/joubel/core/js/h5p-library-details.js diff --git a/lib/h5p/js/h5p-library-list.js b/h5p/h5plib/v124/joubel/core/js/h5p-library-list.js similarity index 100% rename from lib/h5p/js/h5p-library-list.js rename to h5p/h5plib/v124/joubel/core/js/h5p-library-list.js diff --git a/lib/h5p/js/h5p-resizer.js b/h5p/h5plib/v124/joubel/core/js/h5p-resizer.js similarity index 100% rename from lib/h5p/js/h5p-resizer.js rename to h5p/h5plib/v124/joubel/core/js/h5p-resizer.js diff --git a/lib/h5p/js/h5p-utils.js b/h5p/h5plib/v124/joubel/core/js/h5p-utils.js similarity index 100% rename from lib/h5p/js/h5p-utils.js rename to h5p/h5plib/v124/joubel/core/js/h5p-utils.js diff --git a/lib/h5p/js/h5p-version.js b/h5p/h5plib/v124/joubel/core/js/h5p-version.js similarity index 100% rename from lib/h5p/js/h5p-version.js rename to h5p/h5plib/v124/joubel/core/js/h5p-version.js diff --git a/lib/h5p/js/h5p-x-api-event.js b/h5p/h5plib/v124/joubel/core/js/h5p-x-api-event.js similarity index 100% rename from lib/h5p/js/h5p-x-api-event.js rename to h5p/h5plib/v124/joubel/core/js/h5p-x-api-event.js diff --git a/lib/h5p/js/h5p-x-api.js b/h5p/h5plib/v124/joubel/core/js/h5p-x-api.js similarity index 100% rename from lib/h5p/js/h5p-x-api.js rename to h5p/h5plib/v124/joubel/core/js/h5p-x-api.js diff --git a/lib/h5p/js/h5p.js b/h5p/h5plib/v124/joubel/core/js/h5p.js similarity index 100% rename from lib/h5p/js/h5p.js rename to h5p/h5plib/v124/joubel/core/js/h5p.js diff --git a/lib/h5p/js/jquery.js b/h5p/h5plib/v124/joubel/core/js/jquery.js similarity index 100% rename from lib/h5p/js/jquery.js rename to h5p/h5plib/v124/joubel/core/js/jquery.js diff --git a/lib/h5p/js/request-queue.js b/h5p/h5plib/v124/joubel/core/js/request-queue.js similarity index 100% rename from lib/h5p/js/request-queue.js rename to h5p/h5plib/v124/joubel/core/js/request-queue.js diff --git a/lib/h5p/js/settings/h5p-disable-hub.js b/h5p/h5plib/v124/joubel/core/js/settings/h5p-disable-hub.js similarity index 100% rename from lib/h5p/js/settings/h5p-disable-hub.js rename to h5p/h5plib/v124/joubel/core/js/settings/h5p-disable-hub.js diff --git a/lib/h5p/readme_moodle.txt b/h5p/h5plib/v124/joubel/core/readme_moodle.txt similarity index 100% rename from lib/h5p/readme_moodle.txt rename to h5p/h5plib/v124/joubel/core/readme_moodle.txt diff --git a/lib/h5p/styles/h5p-admin.css b/h5p/h5plib/v124/joubel/core/styles/h5p-admin.css similarity index 100% rename from lib/h5p/styles/h5p-admin.css rename to h5p/h5plib/v124/joubel/core/styles/h5p-admin.css diff --git a/lib/h5p/styles/h5p-confirmation-dialog.css b/h5p/h5plib/v124/joubel/core/styles/h5p-confirmation-dialog.css similarity index 100% rename from lib/h5p/styles/h5p-confirmation-dialog.css rename to h5p/h5plib/v124/joubel/core/styles/h5p-confirmation-dialog.css diff --git a/lib/h5p/styles/h5p-core-button.css b/h5p/h5plib/v124/joubel/core/styles/h5p-core-button.css similarity index 100% rename from lib/h5p/styles/h5p-core-button.css rename to h5p/h5plib/v124/joubel/core/styles/h5p-core-button.css diff --git a/lib/h5p/styles/h5p.css b/h5p/h5plib/v124/joubel/core/styles/h5p.css similarity index 100% rename from lib/h5p/styles/h5p.css rename to h5p/h5plib/v124/joubel/core/styles/h5p.css diff --git a/h5p/h5plib/v124/lang/en/h5plib_v124.php b/h5p/h5plib/v124/lang/en/h5plib_v124.php new file mode 100644 index 00000000000..ca5ea1a4a92 --- /dev/null +++ b/h5p/h5plib/v124/lang/en/h5plib_v124.php @@ -0,0 +1,29 @@ +. + +/** + * Strings for component 'h5p_v124' + * + * @package h5plib_v124 + * @copyright 2019 Andrew Nicols + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$string['pluginname'] = 'H5P framework v1.24'; +$string['pluginname_help'] = 'H5P framework. Version 1.24'; +$string['privacy:metadata'] = 'H5P framework v1.24 do not store any personal data.'; diff --git a/h5p/h5plib/v124/thirdpartylibs.xml b/h5p/h5plib/v124/thirdpartylibs.xml new file mode 100644 index 00000000000..000c977835c --- /dev/null +++ b/h5p/h5plib/v124/thirdpartylibs.xml @@ -0,0 +1,9 @@ + + + + joubel/core + h5p-php-library + GPL-3.0 + 1.24 + + diff --git a/h5p/h5plib/v124/version.php b/h5p/h5plib/v124/version.php new file mode 100644 index 00000000000..1e450cce5fa --- /dev/null +++ b/h5p/h5plib/v124/version.php @@ -0,0 +1,29 @@ +. + +/** + * Version information. + * + * @package h5plib_v124 + * @copyright 2019 Andrew Nicols + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->version = 2019121300; // The current module version (Date: YYYYMMDDXX) +$plugin->requires = 2019051100; // Requires this Moodle version +$plugin->component = 'h5plib_v124'; // Full name of the plugin (used for diagnostics). diff --git a/h5p/lib.php b/h5p/lib.php index deccba44862..b640925fde9 100644 --- a/h5p/lib.php +++ b/h5p/lib.php @@ -23,6 +23,8 @@ */ defined('MOODLE_INTERNAL') || die(); +use core_h5p\local\library\autoloader; + /** * Serve the files from the core_h5p file areas. * @@ -44,7 +46,7 @@ function core_h5p_pluginfile($course, $cm, $context, string $filearea, array $ar global $DB; // Require classes from H5P third party library - \core_h5p\autoloader::register(); + autoloader::register(); $filesettingsset = false; diff --git a/h5p/tests/event_h5p_deleted_test.php b/h5p/tests/event_h5p_deleted_test.php index 5159b7e762f..c2c65f5766f 100644 --- a/h5p/tests/event_h5p_deleted_test.php +++ b/h5p/tests/event_h5p_deleted_test.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -use core_h5p\autoloader; +use core_h5p\local\library\autoloader; /** * Tests for h5p deleted event. diff --git a/h5p/tests/event_h5p_viewed_test.php b/h5p/tests/event_h5p_viewed_test.php index 451ba4e6820..75a7671b348 100644 --- a/h5p/tests/event_h5p_viewed_test.php +++ b/h5p/tests/event_h5p_viewed_test.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -use core_h5p\autoloader; +use core_h5p\local\library\autoloader; /** * Tests for h5p viewed event. diff --git a/h5p/tests/external_test.php b/h5p/tests/external_test.php index b9ae3ca7188..737c7cc638f 100644 --- a/h5p/tests/external_test.php +++ b/h5p/tests/external_test.php @@ -33,7 +33,7 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php'); use core_h5p\external; use core_h5p\file_storage; -use core_h5p\autoloader; +use core_h5p\local\library\autoloader; /** * Core h5p external functions tests diff --git a/h5p/tests/generator/lib.php b/h5p/tests/generator/lib.php index 5f4654e957f..5d7ee9f547c 100644 --- a/h5p/tests/generator/lib.php +++ b/h5p/tests/generator/lib.php @@ -23,7 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use core_h5p\autoloader; +use core_h5p\local\library\autoloader; use core_h5p\core; defined('MOODLE_INTERNAL') || die(); diff --git a/h5p/tests/generator_test.php b/h5p/tests/generator_test.php index 118484ca8ee..60fd74fbd40 100644 --- a/h5p/tests/generator_test.php +++ b/h5p/tests/generator_test.php @@ -25,7 +25,7 @@ namespace core_h5p; -use core_h5p\autoloader; +use core_h5p\local\library\autoloader; defined('MOODLE_INTERNAL') || die(); diff --git a/h5p/tests/h5p_core_test.php b/h5p/tests/h5p_core_test.php index 648b64e99b4..a814c44f79a 100644 --- a/h5p/tests/h5p_core_test.php +++ b/h5p/tests/h5p_core_test.php @@ -25,6 +25,8 @@ namespace core_h5p; +use core_h5p\local\library\autoloader; + defined('MOODLE_INTERNAL') || die(); /** diff --git a/h5p/tests/h5p_file_storage_test.php b/h5p/tests/h5p_file_storage_test.php index d6199e40581..fa83984b541 100644 --- a/h5p/tests/h5p_file_storage_test.php +++ b/h5p/tests/h5p_file_storage_test.php @@ -26,7 +26,7 @@ namespace core_h5p\local\tests; use core_h5p\file_storage; -use core_h5p\autoloader; +use core_h5p\local\library\autoloader; use core_h5p\helper; use file_archive; use zip_archive; @@ -617,4 +617,4 @@ class h5p_file_storage_testcase extends \advanced_testcase { ], ]; } -} \ No newline at end of file +} diff --git a/h5p/upgrade.txt b/h5p/upgrade.txt new file mode 100644 index 00000000000..e5060d41f41 --- /dev/null +++ b/h5p/upgrade.txt @@ -0,0 +1,8 @@ +This files describes API changes in core libraries and APIs, +information provided here is intended especially for developers. + +=== 3.9 === +* A new plugintype has been created, h5plib, for having installed more +than one H5P library version. +* H5P third-party libraries have been moved from /lib/h5p to h5p/h5plib/v124, +as an h5plib plugintype. diff --git a/lang/en/h5p.php b/lang/en/h5p.php index 355f523d967..c1a44946295 100644 --- a/lang/en/h5p.php +++ b/lang/en/h5p.php @@ -91,11 +91,14 @@ $string['h5p'] = 'H5P'; $string['h5ptitle'] = 'Visit h5p.org to check out more content.'; $string['h5pfilenotfound'] = 'H5P file not found'; $string['h5pinvalidurl'] = 'Invalid H5P content URL.'; +$string['h5plibraryhandler'] = 'H5P framework handler'; +$string['h5plibraryhandler_help'] = 'The H5P framework used to display any H5P content.'; $string['h5pprivatefile'] = 'This H5P content can\'t be displayed because you don\'t have access to the .h5p file.'; $string['h5pmanage'] = 'Manage H5P content types'; $string['h5poverview'] = 'H5P overview'; $string['h5ppackage'] = 'H5P content type'; $string['h5ppackage_help'] = 'An H5P content type is a file with an H5P or ZIP extension containing all libraries required to display the content.'; +$string['h5psettings'] = 'H5P settings'; $string['hideadvanced'] = 'Hide advanced'; $string['installedcontentlibraries'] = 'Installed H5P libraries'; $string['installedcontenttypes'] = 'Installed H5P content types'; @@ -145,8 +148,9 @@ $string['missingmbstring'] = 'The mbstring PHP extension is not loaded. It is re $string['missinguploadpermissions'] = 'Note that the libraries may exist in the file you uploaded, but you\'re not allowed to upload new libraries. Please contact your administrator.'; $string['nocopyright'] = 'No copyright information available for this content.'; $string['noextension'] = 'The file you uploaded is not a valid HTML5 Package. (It doesn\'t have the .h5p file extension.)'; -$string['nopermissiontodeploy'] = 'This file can\'t be displayed because it has been uploaded by a user without the required capability to deploy H5P content.'; +$string['noh5plibhandlerdefined'] = 'There isn\'t any H5P framework handler installed, so H5P content can\'t be displayed.'; $string['nojson'] = 'The main h5p.json file is not valid'; +$string['nopermissiontodeploy'] = 'This file can\'t be displayed because it has been uploaded by a user without the required capability to deploy H5P content.'; $string['notrustablefile'] = 'This file can\'t be displayed because it has been uploaded by a user without the capability to update H5P content types. Please contact your administrator to ask for the content type to be installed.'; $string['nounzip'] = 'The file you uploaded is not a valid HTML5 Package. (It is not possible to unzip it.)'; $string['offlineDialogBody'] = 'We were unable to send information about your completion of this task. Please check your internet connection.'; diff --git a/lang/en/plugin.php b/lang/en/plugin.php index 94c56163987..caaf671d8ed 100644 --- a/lang/en/plugin.php +++ b/lang/en/plugin.php @@ -149,6 +149,8 @@ $string['type_gradereport'] = 'Gradebook report'; $string['type_gradereport_plural'] = 'Gradebook reports'; $string['type_gradingform'] = 'Advanced grading method'; $string['type_gradingform_plural'] = 'Advanced grading methods'; +$string['type_h5plib'] = 'H5P framework'; +$string['type_h5plib_plural'] = 'H5P frameworks'; $string['type_mlbackend'] = 'Machine learning backend'; $string['type_mlbackend_plural'] = 'Machine learning backends'; $string['type_local'] = 'Local plugin'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 854486a6bc4..3f0dc85ada1 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -11208,3 +11208,44 @@ class admin_setting_configthemepreset extends admin_setting_configselect { return true; } } + +/** + * Selection of plugins that can work as H5P libraries handlers + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2020 Sara Arjona + */ +class admin_settings_h5plib_handler_select extends admin_setting_configselect { + + /** + * Constructor + * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' + * for ones in config_plugins. + * @param string $visiblename localised + * @param string $description long localised info + * @param string $defaultsetting + */ + public function __construct($name, $visiblename, $description, $defaultsetting = '') { + parent::__construct($name, $visiblename, $description, $defaultsetting, null); + } + + /** + * Lazy-load the available choices for the select box + */ + public function load_choices() { + if (during_initial_install()) { + return false; + } + if (is_array($this->choices)) { + return true; + } + + $this->choices = \core_h5p\local\library\autoloader::get_all_handlers(); + foreach ($this->choices as $name => $class) { + $this->choices[$name] = new lang_string('sitepolicyhandlerplugin', 'core_admin', + ['name' => new lang_string('pluginname', $name), 'component' => $name]); + } + + return true; + } +} diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 7ac652d77a2..86b2751f379 100644 --- a/lib/classes/plugin_manager.php +++ b/lib/classes/plugin_manager.php @@ -1881,6 +1881,10 @@ class core_plugin_manager { 'rubric', 'guide' ), + 'h5plib' => array( + 'v124' + ), + 'local' => array( ), diff --git a/lib/classes/plugininfo/h5plib.php b/lib/classes/plugininfo/h5plib.php new file mode 100644 index 00000000000..02765eeac17 --- /dev/null +++ b/lib/classes/plugininfo/h5plib.php @@ -0,0 +1,88 @@ +. + +/** + * Defines classes used for plugin info. + * + * @package core + * @copyright 2019 Andrew Nicols + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace core\plugininfo; + +use moodle_url; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Class for H5P libraries. + */ +class h5plib extends base { + + /** + * Defines if there should be a way to uninstall the plugin via the administration UI. + * + * @return bool + */ + public function is_uninstall_allowed(): bool { + return true; + } + + /** + * H5P versions cannot be disabled. + * + * @return boolean + */ + public function is_enabled(): bool { + return true; + } + + /** + * Return URL used for management of plugins of this type. + * @return moodle_url + */ + public static function get_manage_url(): \moodle_url { + return new moodle_url('/admin/settings.php', ['section' => 'h5psettings']); + } + + /** + * Loads plugin settings to the settings tree + * + * This function usually includes settings.php file in plugins folder. + * Alternatively it can create a link to some settings page (instance of admin_externalpage) + * + * @param \part_of_admin_tree $adminroot + * @param string $parentnodename + * @param bool $hassiteconfig whether the current user has moodle/site:config capability + */ + public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them. + $ADMIN = $adminroot; // May be used in settings.php. + $plugininfo = $this; // Also can be used inside settings.php. + + if (!$this->is_installed_and_upgraded()) { + return; + } + + if (!$hassiteconfig) { + return; + } + + if (file_exists($this->full_path('settings.php'))) { + include($this->full_path('settings.php')); + } + } +} \ No newline at end of file diff --git a/lib/components.json b/lib/components.json index 680f7c02197..5796992996e 100644 --- a/lib/components.json +++ b/lib/components.json @@ -36,7 +36,8 @@ "cachelock": "cache\/locks", "fileconverter": "files\/converter", "theme": "theme", - "local": "local" + "local": "local", + "h5plib": "h5p\/h5plib" }, "subsystems": { "access": null, diff --git a/lib/editor/atto/plugins/h5p/lib.php b/lib/editor/atto/plugins/h5p/lib.php index 60b34e7c604..404f2e1394a 100644 --- a/lib/editor/atto/plugins/h5p/lib.php +++ b/lib/editor/atto/plugins/h5p/lib.php @@ -24,6 +24,8 @@ defined('MOODLE_INTERNAL') || die(); +use core_h5p\local\library\autoloader; + /** * Set params for this button. * @@ -81,7 +83,7 @@ function atto_h5p_strings_for_js() { ); $PAGE->requires->strings_for_js($strings, 'atto_h5p'); - $PAGE->requires->js(new moodle_url('/lib/h5p/js/h5p-resizer.js')); + $PAGE->requires->js(autoloader::get_h5p_core_library_url('js/h5p-resizer.js')); } diff --git a/lib/tests/h5p_get_content_types_task_test.php b/lib/tests/h5p_get_content_types_task_test.php index 21dd1850d92..3502a1bf285 100644 --- a/lib/tests/h5p_get_content_types_task_test.php +++ b/lib/tests/h5p_get_content_types_task_test.php @@ -22,7 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use core_h5p\autoloader; +use core_h5p\local\library\autoloader; use core_h5p\h5p_test_factory; defined('MOODLE_INTERNAL') || die(); diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index fea8015f6ec..e2c5f4a5a80 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -320,10 +320,4 @@ MIT 4.1.0 - - h5p - h5p-php-library - GPL-3.0 - 1.24 - diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 6d37db4e2a2..b647892d022 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -35,6 +35,7 @@ information provided here is intended especially for developers. * The 'xxxx_check_password_policy' callback now only fires if $CFG->passwordpolicy is true * grade_item::update_final_grade() can now take an optional parameter to set the grade->timemodified. If not present the current time will carry on being used. * lib/outputrequirementslib::get_jsrev now is public, it can be called from other classes. +* H5P libraries have been moved from /lib/h5p to h5p/h5plib as an h5plib plugintype. === 3.8 === * Add CLI option to notify all cron tasks to stop: admin/cli/cron.php --stop