. /** * Display H5P filter * * @package filter_displayh5p * @copyright 2019 Victor Deniz * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; use core_h5p\local\library\autoloader; /** * Display H5P filter * * This filter will replace any occurrence of H5P URLs with the corresponding H5P content embed code * * @package filter_displayh5p * @copyright 2019 Victor Deniz * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class filter_displayh5p 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()) { global $CFG, $USER; if (!is_string($text) or empty($text)) { // Non string data can not be filtered anyway. return $text; } // We are trying to minimize performance impact checking there's some H5P related URL. $h5purl = '(http[^ &<]*h5p)'; if (!preg_match($h5purl, $text)) { return $text; } $allowedsources = get_config('filter_displayh5p', 'allowedsources'); $allowedsources = array_filter(array_map('trim', explode("\n", $allowedsources))); $localsource = '('.preg_quote($CFG->wwwroot, '~').'/[^ &\#"\'<]*\.h5p([?][^ "\'<]*)?[^ \#"\'<]*)'; $allowedsources[] = $localsource; $params = array( 'tagbegin' => '