From e83fd277178cd1cab4a50bdc7a33c16d8ee877b5 Mon Sep 17 00:00:00 2001 From: Victor Deniz Falcon Date: Fri, 27 Sep 2019 11:01:12 +0100 Subject: [PATCH] MDL-66397 filter_h5p: converts H5P URLs to embed code --- filter/h5p/classes/privacy/provider.php | 46 ++++++++++++ filter/h5p/filter.php | 120 ++++++++++++++++++++++++++++++++ filter/h5p/lang/en/filter_h5p.php | 34 +++++++++ filter/h5p/settings.php | 31 +++++++++ filter/h5p/tests/filter_test.php | 87 +++++++++++++++++++++++ filter/h5p/version.php | 29 ++++++++ lib/classes/plugin_manager.php | 2 +- 7 files changed, 348 insertions(+), 1 deletion(-) create mode 100644 filter/h5p/classes/privacy/provider.php create mode 100644 filter/h5p/filter.php create mode 100644 filter/h5p/lang/en/filter_h5p.php create mode 100644 filter/h5p/settings.php create mode 100644 filter/h5p/tests/filter_test.php create mode 100644 filter/h5p/version.php diff --git a/filter/h5p/classes/privacy/provider.php b/filter/h5p/classes/privacy/provider.php new file mode 100644 index 00000000000..215faccf3aa --- /dev/null +++ b/filter/h5p/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for filter_h5p. + * + * @package filter_h5p + * @copyright 2019 Victor Deniz + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace filter_h5p\privacy; + +defined('MOODLE_INTERNAL') || die; + +/** + * Privacy Subsystem for filter_h5p implementing null_provider. + * + * @copyright 2019 Victor Deniz + * @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/filter/h5p/filter.php b/filter/h5p/filter.php new file mode 100644 index 00000000000..fcb35ec4a88 --- /dev/null +++ b/filter/h5p/filter.php @@ -0,0 +1,120 @@ +. +/** + * H5P filter + * + * @package filter_h5p + * @copyright 2019 Victor Deniz + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +/** + * H5P filter + * + * This filter will replace any occurrence of H5P URLs with the corresponding H5P content embed code + * + * @package filter_h5p + * @copyright 2019 Victor Deniz + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class filter_h5p extends moodle_text_filter { + + /** + * @var boolean $loadresizerjs This is whether to request the resize.js script. + */ + private static $loadresizerjs = true; + + /** + * Function filter replaces any h5p-sources. + * + * @param string $text HTML content to process + * @param array $options options passed to the filters + * @return string + */ + public function filter($text, array $options = array()) { + + if (!is_string($text) or empty($text)) { + // Non string data can not be filtered anyway. + return $text; + } + + if (stripos($text, 'http') === false) { + return $text; + } + + $allowedsources = get_config('filter_h5p', 'allowedsources'); + $allowedsources = array_filter(array_map('trim', explode("\n", $allowedsources))); + if (empty($allowedsources)) { + return $text; + } + + $params = array( + 'tagbegin' => "