Merge pull request #9615 from creative-commoners/pulls/4.6/embed-iframe-dimensions

FIX Set iframe dimension attributes specified in shortcode
This commit is contained in:
Steve Boyd 2020-07-28 11:04:24 +12:00 committed by GitHub
commit 52d38a8b4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -160,6 +160,17 @@ class EmbedShortcodeProvider implements ShortcodeHandler
$arguments['style'] = 'width: ' . intval($arguments['width']) . 'px;';
}
// override iframe dimension attributes provided by webservice with ones specified in shortcode arguments
foreach (['width', 'height'] as $attr) {
if (!($value = $arguments[$attr] ?? false)) {
continue;
}
foreach (['"', "'"] as $quote) {
$rx = "/(<iframe .*?)$attr=$quote([0-9]+)$quote([^>]+>)/";
$content = preg_replace($rx, "$1{$attr}={$quote}{$value}{$quote}$3", $content);
}
}
$data = [
'Arguments' => $arguments,
'Attributes' => static::buildAttributeListFromArguments($arguments, ['width', 'height', 'url', 'caption']),

View File

@ -37,8 +37,8 @@ class EmbedShortcodeProviderTest extends SapphireTest
[
'url' => static::$test_youtube,
'caption' => 'A nice video',
'width' => 480,
'height' => 360,
'width' => 777,
'height' => 437,
],
[
'version' => '1.0',
@ -58,7 +58,7 @@ class EmbedShortcodeProviderTest extends SapphireTest
);
$this->assertEqualIgnoringWhitespace(
<<<EOS
<div style="width: 480px;"><iframe width="480" height="270" src="https://www.youtube.com/embed/dM15HfUYwF0?feature=oembed" frameborder="0" allowfullscreen></iframe>
<div style="width: 777px;"><iframe width="777" height="437" src="https://www.youtube.com/embed/dM15HfUYwF0?feature=oembed" frameborder="0" allowfullscreen></iframe>
<p class="caption">A nice video</p></div>
EOS
,