Merge branch 'MDL-67337-master' of git://github.com/aanabit/moodle
This commit is contained in:
@@ -74,6 +74,7 @@ class filter_displayh5p extends moodle_text_filter {
|
||||
$specialchars = ['?', '&'];
|
||||
$escapedspecialchars = ['\?', '&'];
|
||||
$h5pcontents = array();
|
||||
$h5plinks = array();
|
||||
|
||||
// Check all allowed sources.
|
||||
foreach ($allowedsources as $source) {
|
||||
@@ -82,7 +83,8 @@ class filter_displayh5p extends moodle_text_filter {
|
||||
|
||||
if (($source == $localsource)) {
|
||||
$params['tagbegin'] = '<iframe src="'.$CFG->wwwroot.'/h5p/embed.php?url=';
|
||||
$ultimatepattern = '#'.$source.'#';
|
||||
$escapechars = $source;
|
||||
$ultimatepattern = $source;
|
||||
} else {
|
||||
if (!stripos($source, 'embed')) {
|
||||
$params['urlmodifier'] = '/embed';
|
||||
@@ -90,7 +92,7 @@ class filter_displayh5p extends moodle_text_filter {
|
||||
// Convert special chars.
|
||||
$sourceid = str_replace('[id]', '[0-9]+', $source);
|
||||
$escapechars = str_replace($specialchars, $escapedspecialchars, $sourceid);
|
||||
$ultimatepattern = '#(' . $escapechars . ')#';
|
||||
$ultimatepattern = '(' . $escapechars . ')';
|
||||
}
|
||||
|
||||
// Improve performance creating filterobjects only when needed.
|
||||
@@ -101,15 +103,39 @@ class filter_displayh5p extends moodle_text_filter {
|
||||
$h5pcontenturl = new filterobject($source, null, null, false,
|
||||
false, null, [$this, 'filterobject_prepare_replacement_callback'], $params);
|
||||
|
||||
$h5pcontenturl->workregexp = $ultimatepattern;
|
||||
$h5pcontenturl->workregexp = '#'.$ultimatepattern.'#';
|
||||
$h5pcontents[] = $h5pcontenturl;
|
||||
|
||||
// Regex to find h5p extensions in an <a> tag.
|
||||
$linkregexp = '~<a [^>]*href=["\']('.$escapechars.'[^"\']*)["\'][^>]*>([^<]*)</a>~is';
|
||||
|
||||
$h5plinkurl = new filterobject($linkregexp, null, null, false,
|
||||
false, null, [$this, 'filterobject_prepare_replacement_callback'], $params);
|
||||
$h5plinkurl->workregexp = $linkregexp;
|
||||
$h5plinks[] = $h5plinkurl;
|
||||
}
|
||||
|
||||
if (empty($h5pcontents)) {
|
||||
if (empty($h5pcontents) && empty($h5links)) {
|
||||
// No matches to deal with.
|
||||
return $text;
|
||||
}
|
||||
|
||||
// Apply filter inside <a> tag href attribute.
|
||||
// We can not use filter_phrase function because it removes all tags and can not be applied in tag attributes.
|
||||
foreach ($h5plinks as $h5plink) {
|
||||
$text = preg_replace_callback($h5plink->workregexp,
|
||||
function ($matches) use ($h5plink) {
|
||||
if ($matches[1] == $matches[2]) {
|
||||
filter_prepare_phrase_for_replacement($h5plink);
|
||||
|
||||
return str_replace('$1', $matches[1], $h5plink->workreplacementphrase);
|
||||
} else {
|
||||
return $matches[0];
|
||||
}
|
||||
}, $text);
|
||||
|
||||
}
|
||||
|
||||
$result = filter_phrases($text, $h5pcontents, null, null, false, true);
|
||||
|
||||
// Encoding H5P file URLs.
|
||||
|
||||
@@ -35,13 +35,25 @@ Feature: Render H5P content using filters
|
||||
Then I should see "Lorum ipsum"
|
||||
|
||||
@javascript
|
||||
Scenario: Add an external H5P content URL in a link. Shouldn't be rendered.
|
||||
Scenario: Add an external H5P content URL in a link with the URL. Should be rendered.
|
||||
Given I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "PageName1"
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
# This content won't be displayed, so this scenario shouldn't be labeled as external.
|
||||
And I set the field "Page content" to "<a href='https://moodle.h5p.com/content/1290772960722742119/embed'>Go to https://moodle.h5p.com/content/1290772960722742119/embed</a>"
|
||||
And I set the field "Page content" to "<a href='https://moodle.h5p.com/content/1290772960722742119/embed'>https://moodle.h5p.com/content/1290772960722742119/embed</a>"
|
||||
When I click on "Save and display" "button"
|
||||
And I wait until the page is ready
|
||||
And I switch to "h5p-iframe" class iframe
|
||||
Then I should see "Lorum ipsum"
|
||||
|
||||
Scenario: Add an external H5P content URL in a link with text. Shouldn't be rendered.
|
||||
Given I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "PageName1"
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
# This content won't be displayed, so this scenario shouldn't be labeled as external.
|
||||
And I set the field "Page content" to "<a href='https://moodle.h5p.com/content/1290772960722742119/embed'>Here you are the content</a>"
|
||||
When I click on "Save and display" "button"
|
||||
And I wait until the page is ready
|
||||
Then ".h5p-iframe" "css_element" should not exist
|
||||
|
||||
@@ -42,7 +42,7 @@ class filter_displayh5p_testcase extends advanced_testcase {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
set_config('allowedsources',
|
||||
"https://h5p.org/h5p/embed/[id]\nhttps://moodle.h5p.com/content/[id]/embed\nhttps://moodle.h5p.com/content/[id]
|
||||
"https://moodle.h5p.com/content/[id]/embed\nhttps://moodle.h5p.com/content/[id]
|
||||
\nhttps://generic.wordpress.soton.ac.uk/altc/wp-admin/admin-ajax.php?action=h5p_embed&id=[id]",
|
||||
'filter_displayh5p');
|
||||
}
|
||||
@@ -74,16 +74,20 @@ class filter_displayh5p_testcase extends advanced_testcase {
|
||||
return [
|
||||
["http:://example.com", "#http:://example.com#"],
|
||||
["http://google.es/h5p/embed/3425234", "#http://google.es/h5p/embed/3425234#"],
|
||||
["https://h5p.org/h5p/embed/547225", "#<iframe src=\"https://h5p.org/h5p/embed/547225\"[^>]+?>#"],
|
||||
["https://moodle.h5p.com/content/1290729733828858779/embed", "#<iframe src=\"https://moodle.h5p.com/content/1290729733828858779/embed\"[^>]+?>#"],
|
||||
["https://moodle.h5p.com/content/1290729733828858779", "#<iframe src=\"https://moodle.h5p.com/content/1290729733828858779/embed\"[^>]+?>#"],
|
||||
["<a href=\"https://h5p.org/h5p/embed/547225\">link</a>", "#^((?!iframe).)*$#"],
|
||||
["this is a text with an h5p url https://h5p.org/h5p/embed/547225 inside",
|
||||
"#this is a text with an h5p url <iframe src=\"https://h5p.org/h5p/embed/547225\"(.|\n)*> inside#"],
|
||||
["<a href=\"https://moodle.h5p.com/content/1290848995208939539/embed\">https://moodle.h5p.com/content/1290848995208939539/embed</a>",
|
||||
"#<iframe src=\"https://moodle.h5p.com/content/1290848995208939539/embed\"[^>]+?>#"],
|
||||
["<a href=\"https://moodle.org\">https://moodle.h5p.com/content/1290848995208939539/embed</a>",
|
||||
"#^((?!iframe).)*$#"],
|
||||
["<a href=\"https://moodle.h5p.com/content/1290848995208939539/embed\">link</a>", "#^((?!iframe).)*$#"],
|
||||
["this is a text with an h5p url https://moodle.h5p.com/content/1290848995208939539/embed inside",
|
||||
"#this is a text with an h5p url <iframe src=\"https://moodle.h5p.com/content/1290848995208939539/embed\"(.|\n)*> inside#"],
|
||||
["https://generic.wordpress.soton.ac.uk/altc/wp-admin/admin-ajax.php?action=h5p_embed&id=13",
|
||||
"#<iframe src=\"https://generic.wordpress.soton.ac.uk/altc/wp-admin/admin-ajax.php\?action=h5p_embed\&\;id=13\"[^>]+?>#"],
|
||||
["https://h5p.org/h5p/embed/547225 another content in the same page https://moodle.h5p.com/content/1290729733828858779/embed",
|
||||
"#<iframe src=\"https://h5p.org/h5p/embed/547225\"[^>]+?>((?!<iframe).)*<iframe src=\"https://moodle.h5p.com/content/1290729733828858779/embed\"[^>]+?>#"],
|
||||
["https://moodle.h5p.com/content/1290848995208939539/embed another content in the same page https://moodle.h5p.com/content/1290729733828858779/embed",
|
||||
"#<iframe src=\"https://moodle.h5p.com/content/1290848995208939539/embed\"[^>]+?>((?!<iframe).)*".
|
||||
"<iframe src=\"https://moodle.h5p.com/content/1290729733828858779/embed\"[^>]+?>#"],
|
||||
[$CFG->wwwroot."/pluginfile.php/5/user/private/interactive-video.h5p?export=1&embed=1",
|
||||
"#<iframe src=\"{$CFG->wwwroot}/h5p/embed.php\?url=".rawurlencode("{$CFG->wwwroot}/pluginfile.php/5/user/private/interactive-video.h5p").
|
||||
"&export=1&embed=1\"[^>]*?></iframe>#"],
|
||||
|
||||
Reference in New Issue
Block a user