FIX Set iframe dimension attributes specified in shortcode

This commit is contained in:
Steve Boyd 2020-07-27 18:04:03 +12:00
parent 886733ea70
commit f0936d4c1e
2 changed files with 14 additions and 3 deletions

View File

@ -141,6 +141,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
,