[BUGFIX] Add available attributes to output of renderer classes 31/43731/4
authorFrans Saris <franssaris@gmail.com>
Fri, 2 Oct 2015 08:30:42 +0000 (10:30 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 3 Oct 2015 10:15:08 +0000 (12:15 +0200)
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>
typo3/sysext/core/Classes/Resource/Rendering/AudioTagRenderer.php
typo3/sysext/core/Classes/Resource/Rendering/VideoTagRenderer.php
typo3/sysext/core/Classes/Resource/Rendering/VimeoRenderer.php
typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php
typo3/sysext/core/Tests/Unit/Resource/Rendering/VimeoRendererTest.php
typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php

index 1fb3497..abe758b 100644 (file)
@@ -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>',
index 4cc281b..435c92e 100644 (file)
@@ -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()
                );
index 3b41b95..bcf1ef4 100644 (file)
@@ -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('&amp;', $urlParams)),
-               );
-               $width = (int)$width;
-               if (!empty($width)) {
-                       $attributes['width'] = $width;
+               $src = sprintf('//player.vimeo.com/video/%s?%s', $videoId, implode('&amp;', $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)
+               );
        }
 
 }
index a7c6b01..c45ab63 100644 (file)
@@ -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('&amp;', $urlParams)
-                       ),
+               $src = sprintf(
+                       '//www.youtube%s.com/embed/%s?%s',
+                       !empty($options['no-cookie']) ? '-nocookie' : '',
+                       $videoId,
+                       implode('&amp;', $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)
+               );
        }
 
 }
index cdca19c..0b94b87 100644 (file)
@@ -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&amp;byline=0&amp;portrait=0" width="300" height="200" allowfullscreen></iframe></div>',
+                       '<iframe src="//player.vimeo.com/video/7331?title=0&amp;byline=0&amp;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&amp;title=0&amp;byline=0&amp;portrait=0" width="300" height="200" allowfullscreen></iframe></div>',
+                       '<iframe src="//player.vimeo.com/video/7331?loop=1&amp;title=0&amp;byline=0&amp;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&amp;title=0&amp;byline=0&amp;portrait=0" width="300" height="200" allowfullscreen></iframe></div>',
+                       '<iframe src="//player.vimeo.com/video/7331?autoplay=1&amp;title=0&amp;byline=0&amp;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&amp;title=0&amp;byline=0&amp;portrait=0" width="300" height="200" allowfullscreen></iframe></div>',
+                       '<iframe src="//player.vimeo.com/video/7331?autoplay=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200"></iframe>',
                        $this->subject->render($fileResourceMock, '300m', '200', array('autoplay' => 1))
                );
        }
index e4cda14..37f8373 100644 (file)
@@ -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&amp;controls=2&amp;enablejsapi=1&amp;origin=test.server.org&amp;showinfo=0" width="300" height="200" allowfullscreen></iframe></div>',
+                       '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;controls=2&amp;enablejsapi=1&amp;origin=test.server.org&amp;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&amp;controls=2&amp;loop=1&amp;enablejsapi=1&amp;origin=test.server.org&amp;showinfo=0" width="300" height="200" allowfullscreen></iframe></div>',
+                       '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;controls=2&amp;loop=1&amp;enablejsapi=1&amp;origin=test.server.org&amp;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&amp;controls=2&amp;autoplay=1&amp;enablejsapi=1&amp;origin=test.server.org&amp;showinfo=0" width="300" height="200" allowfullscreen></iframe></div>',
+                       '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;controls=2&amp;autoplay=1&amp;enablejsapi=1&amp;origin=test.server.org&amp;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&amp;autoplay=1&amp;enablejsapi=1&amp;origin=test.server.org&amp;showinfo=0" width="300" height="200" allowfullscreen></iframe></div>',
+                       '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;autoplay=1&amp;enablejsapi=1&amp;origin=test.server.org&amp;showinfo=0" allowfullscreen width="300" height="200"></iframe>',
                        $this->subject->render($fileResourceMock, '300m', '200', array('controls' => 0, 'autoplay' => 1))
                );
        }