From e5245b9638dc7f18ccba75d050ded1fc6cba0691 Mon Sep 17 00:00:00 2001 From: Frans Saris <franssaris@gmail.com> Date: Fri, 2 Oct 2015 10:30:42 +0200 Subject: [PATCH] [BUGFIX] Add available attributes to output of renderer classes The available renderer classes now add the attribute values passed as option to the rendered output. To keep the output of the available renderer classes consistent the wrapper div added by the YouTubeRenderer and VimeoRenderer have been dropped. Change-Id: Ia93c49cc07fe9b2b897d4aa70d32f56ebf005ddc Resolves: #70261 Releases: master Reviewed-on: http://review.typo3.org/43731 Reviewed-by: Daniel Goerz <ervaude@gmail.com> Tested-by: Daniel Goerz <ervaude@gmail.com> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> --- .../Resource/Rendering/AudioTagRenderer.php | 8 ++++ .../Resource/Rendering/VideoTagRenderer.php | 28 +++++++++---- .../Resource/Rendering/VimeoRenderer.php | 32 ++++++++------- .../Resource/Rendering/YouTubeRenderer.php | 39 ++++++++++--------- .../Resource/Rendering/VimeoRendererTest.php | 8 ++-- .../Rendering/YouTubeRendererTest.php | 8 ++-- 6 files changed, 73 insertions(+), 50 deletions(-) diff --git a/typo3/sysext/core/Classes/Resource/Rendering/AudioTagRenderer.php b/typo3/sysext/core/Classes/Resource/Rendering/AudioTagRenderer.php index 1fb3497e74a1..abe758b58ca3 100644 --- a/typo3/sysext/core/Classes/Resource/Rendering/AudioTagRenderer.php +++ b/typo3/sysext/core/Classes/Resource/Rendering/AudioTagRenderer.php @@ -79,9 +79,17 @@ class AudioTagRenderer implements FileRendererInterface { if (!empty($options['autoplay'])) { $additionalAttributes[] = 'autoplay'; } + if (!empty($options['muted'])) { + $additionalAttributes[] = 'muted'; + } if (!empty($options['loop'])) { $additionalAttributes[] = 'loop'; } + foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'preload'] as $key) { + if (!empty($options[$key])) { + $additionalAttributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"'; + } + } return sprintf( '<audio%s><source src="%s" type="%s"></audio>', diff --git a/typo3/sysext/core/Classes/Resource/Rendering/VideoTagRenderer.php b/typo3/sysext/core/Classes/Resource/Rendering/VideoTagRenderer.php index 4cc281bd1b7a..435c92e5d635 100644 --- a/typo3/sysext/core/Classes/Resource/Rendering/VideoTagRenderer.php +++ b/typo3/sysext/core/Classes/Resource/Rendering/VideoTagRenderer.php @@ -72,22 +72,34 @@ class VideoTagRenderer implements FileRendererInterface { } } - $additionalAttributes = array(); + $attributes = []; + if ((int)$width > 0) { + $attributes[] = 'width="' . (int)$width . '"'; + } + if ((int)$height > 0) { + $attributes[] = 'height="' . (int)$height . '"'; + } if (!isset($options['controls']) || !empty($options['controls'])) { - $additionalAttributes[] = 'controls'; + $attributes[] = 'controls'; } if (!empty($options['autoplay'])) { - $additionalAttributes[] = 'autoplay'; + $attributes[] = 'autoplay'; + } + if (!empty($options['muted'])) { + $attributes[] = 'muted'; } if (!empty($options['loop'])) { - $additionalAttributes[] = 'loop'; + $attributes[] = 'loop'; + } + foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick'] as $key) { + if (!empty($options[$key])) { + $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"'; + } } return sprintf( - '<video width="%d" height="%d"%s><source src="%s" type="%s"></video>', - (int)$width, - (int)$height, - empty($additionalAttributes) ? '' : ' ' . implode(' ', $additionalAttributes), + '<video%s><source src="%s" type="%s"></video>', + empty($attributes) ? '' : ' ' . implode(' ', $attributes), htmlspecialchars($file->getPublicUrl($usedPathsRelativeToCurrentScript)), $file->getMimeType() ); diff --git a/typo3/sysext/core/Classes/Resource/Rendering/VimeoRenderer.php b/typo3/sysext/core/Classes/Resource/Rendering/VimeoRenderer.php index 3b41b955318c..bcf1ef4a3da0 100644 --- a/typo3/sysext/core/Classes/Resource/Rendering/VimeoRenderer.php +++ b/typo3/sysext/core/Classes/Resource/Rendering/VimeoRenderer.php @@ -111,27 +111,29 @@ class VimeoRenderer implements FileRendererInterface { } $videoId = $this->getOnlineMediaHelper($file)->getOnlineMediaId($orgFile); - $attributes = array( - 'src' => sprintf('//player.vimeo.com/video/%s?%s', $videoId, implode('&', $urlParams)), - ); - $width = (int)$width; - if (!empty($width)) { - $attributes['width'] = $width; + $src = sprintf('//player.vimeo.com/video/%s?%s', $videoId, implode('&', $urlParams)); + + $attributes = ['allowfullscreen']; + if ((int)$width > 0) { + $attributes[] = 'width="' . (int)$width . '"'; } - $height = (int)$height; - if (!empty($height)) { - $attributes['height'] = $height; + if ((int)$height > 0) { + $attributes[] = 'height="' . (int)$height . '"'; } if (is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->config['config']['doctype'] !== 'html5') { - $attributes['frameborder'] = '0'; + $attributes[] = 'frameborder="0"'; } - $output = ''; - foreach ($attributes as $key => $value) { - $output .= $key . '="' . $value . '" '; + foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick'] as $key) { + if (!empty($options[$key])) { + $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"'; + } } - // wrap in div so you can make it responsive - return '<div class="video-container"><iframe ' . $output . 'allowfullscreen></iframe></div>'; + return sprintf( + '<iframe src="%s"%s></iframe>', + $src, + empty($attributes) ? '' : ' ' . implode(' ', $attributes) + ); } } diff --git a/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php b/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php index a7c6b01ccc54..c45ab6366aa4 100644 --- a/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php +++ b/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php @@ -116,33 +116,34 @@ class YouTubeRenderer implements FileRendererInterface { } $videoId = $this->getOnlineMediaHelper($file)->getOnlineMediaId($orgFile); - $attributes = array( - 'src' => sprintf( - '//www.youtube%s.com/embed/%s?%s', - !empty($options['no-cookie']) ? '-nocookie' : '', - $videoId, - implode('&', $urlParams) - ), + $src = sprintf( + '//www.youtube%s.com/embed/%s?%s', + !empty($options['no-cookie']) ? '-nocookie' : '', + $videoId, + implode('&', $urlParams) ); - $width = (int)$width; - if (!empty($width)) { - $attributes['width'] = $width; + $attributes = ['allowfullscreen']; + if ((int)$width > 0) { + $attributes[] = 'width="' . (int)$width . '"'; } - $height = (int)$height; - if (!empty($height)) { - $attributes['height'] = $height; + if ((int)$height > 0) { + $attributes[] = 'height="' . (int)$height . '"'; } if (is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->config['config']['doctype'] !== 'html5') { - $attributes['frameborder'] = '0'; + $attributes[] = 'frameborder="0"'; } - $output = ''; - foreach ($attributes as $key => $value) { - $output .= $key . '="' . $value . '" '; + foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'poster', 'preload'] as $key) { + if (!empty($options[$key])) { + $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"'; + } } - // wrap in div so you can make it responsive - return '<div class="video-container"><iframe ' . $output . 'allowfullscreen></iframe></div>'; + return sprintf( + '<iframe src="%s"%s></iframe>', + $src, + empty($attributes) ? '' : ' ' . implode(' ', $attributes) + ); } } diff --git a/typo3/sysext/core/Tests/Unit/Resource/Rendering/VimeoRendererTest.php b/typo3/sysext/core/Tests/Unit/Resource/Rendering/VimeoRendererTest.php index cdca19c8b71d..0b94b8756c2c 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/Rendering/VimeoRendererTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/Rendering/VimeoRendererTest.php @@ -85,7 +85,7 @@ class VimeoRendererTest extends UnitTestCase { $fileResourceMock = $this->getMock(File::class, array(), array(), '', FALSE); $this->assertSame( - '<div class="video-container"><iframe src="//player.vimeo.com/video/7331?title=0&byline=0&portrait=0" width="300" height="200" allowfullscreen></iframe></div>', + '<iframe src="//player.vimeo.com/video/7331?title=0&byline=0&portrait=0" allowfullscreen width="300" height="200"></iframe>', $this->subject->render($fileResourceMock, '300m', '200') ); } @@ -98,7 +98,7 @@ class VimeoRendererTest extends UnitTestCase { $fileResourceMock = $this->getMock(File::class, array(), array(), '', FALSE); $this->assertSame( - '<div class="video-container"><iframe src="//player.vimeo.com/video/7331?loop=1&title=0&byline=0&portrait=0" width="300" height="200" allowfullscreen></iframe></div>', + '<iframe src="//player.vimeo.com/video/7331?loop=1&title=0&byline=0&portrait=0" allowfullscreen width="300" height="200"></iframe>', $this->subject->render($fileResourceMock, '300m', '200', array('loop' => 1)) ); } @@ -111,7 +111,7 @@ class VimeoRendererTest extends UnitTestCase { $fileResourceMock = $this->getMock(File::class, array(), array(), '', FALSE); $this->assertSame( - '<div class="video-container"><iframe src="//player.vimeo.com/video/7331?autoplay=1&title=0&byline=0&portrait=0" width="300" height="200" allowfullscreen></iframe></div>', + '<iframe src="//player.vimeo.com/video/7331?autoplay=1&title=0&byline=0&portrait=0" allowfullscreen width="300" height="200"></iframe>', $this->subject->render($fileResourceMock, '300m', '200', array('autoplay' => 1)) ); } @@ -124,7 +124,7 @@ class VimeoRendererTest extends UnitTestCase { $fileResourceMock = $this->getMock(File::class, array(), array(), '', FALSE); $this->assertSame( - '<div class="video-container"><iframe src="//player.vimeo.com/video/7331?autoplay=1&title=0&byline=0&portrait=0" width="300" height="200" allowfullscreen></iframe></div>', + '<iframe src="//player.vimeo.com/video/7331?autoplay=1&title=0&byline=0&portrait=0" allowfullscreen width="300" height="200"></iframe>', $this->subject->render($fileResourceMock, '300m', '200', array('autoplay' => 1)) ); } diff --git a/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php b/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php index e4cda1489665..37f83732dac5 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php @@ -88,7 +88,7 @@ class YouTubeRendererTest extends UnitTestCase { $fileResourceMock = $this->getMock(File::class, array(), array(), '', FALSE); $this->assertSame( - '<div class="video-container"><iframe src="//www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=test.server.org&showinfo=0" width="300" height="200" allowfullscreen></iframe></div>', + '<iframe src="//www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=test.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', $this->subject->render($fileResourceMock, '300m', '200') ); } @@ -101,7 +101,7 @@ class YouTubeRendererTest extends UnitTestCase { $fileResourceMock = $this->getMock(File::class, array(), array(), '', FALSE); $this->assertSame( - '<div class="video-container"><iframe src="//www.youtube.com/embed/7331?autohide=1&controls=2&loop=1&enablejsapi=1&origin=test.server.org&showinfo=0" width="300" height="200" allowfullscreen></iframe></div>', + '<iframe src="//www.youtube.com/embed/7331?autohide=1&controls=2&loop=1&enablejsapi=1&origin=test.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', $this->subject->render($fileResourceMock, '300m', '200', array('loop' => 1)) ); } @@ -114,7 +114,7 @@ class YouTubeRendererTest extends UnitTestCase { $fileResourceMock = $this->getMock(File::class, array(), array(), '', FALSE); $this->assertSame( - '<div class="video-container"><iframe src="//www.youtube.com/embed/7331?autohide=1&controls=2&autoplay=1&enablejsapi=1&origin=test.server.org&showinfo=0" width="300" height="200" allowfullscreen></iframe></div>', + '<iframe src="//www.youtube.com/embed/7331?autohide=1&controls=2&autoplay=1&enablejsapi=1&origin=test.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', $this->subject->render($fileResourceMock, '300m', '200', array('autoplay' => 1)) ); } @@ -127,7 +127,7 @@ class YouTubeRendererTest extends UnitTestCase { $fileResourceMock = $this->getMock(File::class, array(), array(), '', FALSE); $this->assertSame( - '<div class="video-container"><iframe src="//www.youtube.com/embed/7331?autohide=1&autoplay=1&enablejsapi=1&origin=test.server.org&showinfo=0" width="300" height="200" allowfullscreen></iframe></div>', + '<iframe src="//www.youtube.com/embed/7331?autohide=1&autoplay=1&enablejsapi=1&origin=test.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', $this->subject->render($fileResourceMock, '300m', '200', array('controls' => 0, 'autoplay' => 1)) ); } -- GitLab