TYPO3 CMS  TYPO3_8-7
VideoTagRenderer.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
30  protected $possibleMimeTypes = ['video/mp4', 'video/webm', 'video/ogg', 'video/x-m4v', 'application/ogg'];
31 
41  public function getPriority()
42  {
43  return 1;
44  }
45 
52  public function canRender(FileInterface $file)
53  {
54  return in_array($file->getMimeType(), $this->possibleMimeTypes, true);
55  }
56 
67  public function render(FileInterface $file, $width, $height, array $options = [], $usedPathsRelativeToCurrentScript = false)
68  {
69 
70  // If autoplay isn't set manually check if $file is a FileReference take autoplay from there
71  if (!isset($options['autoplay']) && $file instanceof FileReference) {
72  $autoplay = $file->getProperty('autoplay');
73  if ($autoplay !== null) {
74  $options['autoplay'] = $autoplay;
75  }
76  }
77 
78  $attributes = [];
79  if ((int)$width > 0) {
80  $attributes[] = 'width="' . (int)$width . '"';
81  }
82  if ((int)$height > 0) {
83  $attributes[] = 'height="' . (int)$height . '"';
84  }
85  if (!isset($options['controls']) || !empty($options['controls'])) {
86  $attributes[] = 'controls';
87  }
88  if (!empty($options['autoplay'])) {
89  $attributes[] = 'autoplay';
90  }
91  if (!empty($options['muted'])) {
92  $attributes[] = 'muted';
93  }
94  if (!empty($options['loop'])) {
95  $attributes[] = 'loop';
96  }
97  foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'controlsList', 'preload'] as $key) {
98  if (!empty($options[$key])) {
99  $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
100  }
101  }
102 
103  return sprintf(
104  '<video%s><source src="%s" type="%s"></video>',
105  empty($attributes) ? '' : ' ' . implode(' ', $attributes),
106  htmlspecialchars($file->getPublicUrl($usedPathsRelativeToCurrentScript)),
107  $file->getMimeType()
108  );
109  }
110 }
render(FileInterface $file, $width, $height, array $options=[], $usedPathsRelativeToCurrentScript=false)
getPublicUrl($relativeToCurrentScript=false)