‪TYPO3CMS  10.4
VideoTagRenderer.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
26 {
32  protected ‪$possibleMimeTypes = ['video/mp4', 'video/webm', 'video/ogg', 'video/x-m4v', 'application/ogg'];
33 
43  public function ‪getPriority()
44  {
45  return 1;
46  }
47 
54  public function ‪canRender(‪FileInterface $file)
55  {
56  return in_array($file->‪getMimeType(), $this->possibleMimeTypes, true);
57  }
58 
69  public function ‪render(‪FileInterface $file, $width, $height, array $options = [], $usedPathsRelativeToCurrentScript = false)
70  {
71 
72  // If autoplay isn't set manually check if $file is a FileReference take autoplay from there
73  if (!isset($options['autoplay']) && $file instanceof ‪FileReference) {
74  $autoplay = $file->‪getProperty('autoplay');
75  if ($autoplay !== null) {
76  $options['autoplay'] = $autoplay;
77  }
78  }
79 
80  $attributes = [];
81  if (isset($options['additionalAttributes']) && is_array($options['additionalAttributes'])) {
82  $attributes[] = GeneralUtility::implodeAttributes($options['additionalAttributes'], true, true);
83  }
84  if (isset($options['data']) && is_array($options['data'])) {
85  array_walk($options['data'], function (&$value, $key) {
86  $value = 'data-' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
87  });
88  $attributes[] = implode(' ', $options['data']);
89  }
90  if ((int)$width > 0) {
91  $attributes[] = 'width="' . (int)$width . '"';
92  }
93  if ((int)$height > 0) {
94  $attributes[] = 'height="' . (int)$height . '"';
95  }
96  if (!isset($options['controls']) || !empty($options['controls'])) {
97  $attributes[] = 'controls';
98  }
99  if (!empty($options['autoplay'])) {
100  $attributes[] = 'autoplay';
101  }
102  if (!empty($options['muted'])) {
103  $attributes[] = 'muted';
104  }
105  if (!empty($options['loop'])) {
106  $attributes[] = 'loop';
107  }
108  if (isset($options['additionalConfig']) && is_array($options['additionalConfig'])) {
109  foreach ($options['additionalConfig'] as $key => $value) {
110  if ((bool)$value) {
111  $attributes[] = htmlspecialchars($key);
112  }
113  }
114  }
115 
116  foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'controlsList', 'preload'] as $key) {
117  if (!empty($options[$key])) {
118  $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
119  }
120  }
121 
122  // Clean up duplicate attributes
123  $attributes = array_unique($attributes);
124 
125  return sprintf(
126  '<video%s><source src="%s" type="%s"></video>',
127  empty($attributes) ? '' : ' ' . implode(' ', $attributes),
128  htmlspecialchars((string)$file->‪getPublicUrl($usedPathsRelativeToCurrentScript)),
129  $file->‪getMimeType()
130  );
131  }
132 }
‪TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer\canRender
‪bool canRender(FileInterface $file)
Definition: VideoTagRenderer.php:53
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:22
‪TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer
Definition: VideoTagRenderer.php:26
‪TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer\getPriority
‪int getPriority()
Definition: VideoTagRenderer.php:42
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:33
‪TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer\render
‪string render(FileInterface $file, $width, $height, array $options=[], $usedPathsRelativeToCurrentScript=false)
Definition: VideoTagRenderer.php:68
‪TYPO3\CMS\Core\Resource\FileInterface\getProperty
‪string getProperty($key)
‪TYPO3\CMS\Core\Resource\Rendering
Definition: AudioTagRenderer.php:16
‪TYPO3\CMS\Core\Resource\Rendering\FileRendererInterface
Definition: FileRendererInterface.php:25
‪TYPO3\CMS\Core\Resource\FileInterface\getPublicUrl
‪string null getPublicUrl($relativeToCurrentScript=false)
‪TYPO3\CMS\Core\Resource\FileInterface\getMimeType
‪string getMimeType()
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer\$possibleMimeTypes
‪array $possibleMimeTypes
Definition: VideoTagRenderer.php:31