‪TYPO3CMS  11.5
AudioTagRenderer.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 = ['audio/mpeg', 'audio/wav', 'audio/x-wav', 'audio/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  // TODO $usedPathsRelativeToCurrentScript here as well
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  $additionalAttributes = [];
81  if (isset($options['additionalAttributes']) && is_array($options['additionalAttributes'])) {
82  $additionalAttributes[] = GeneralUtility::implodeAttributes($options['additionalAttributes'], true, true);
83  }
84  if (isset($options['data']) && is_array($options['data'])) {
85  array_walk($options['data'], static function (&$value, $key) {
86  $value = 'data-' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
87  });
88  $additionalAttributes[] = implode(' ', $options['data']);
89  }
90  if (!isset($options['controls']) || !empty($options['controls'])) {
91  $additionalAttributes[] = 'controls';
92  }
93  if (!empty($options['autoplay'])) {
94  $additionalAttributes[] = 'autoplay';
95  }
96  if (!empty($options['muted'])) {
97  $additionalAttributes[] = 'muted';
98  }
99  if (!empty($options['loop'])) {
100  $additionalAttributes[] = 'loop';
101  }
102  foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'preload', 'controlsList'] as $key) {
103  if (!empty($options[$key])) {
104  $additionalAttributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
105  }
106  }
107 
108  return sprintf(
109  '<audio%s><source src="%s" type="%s"></audio>',
110  empty($additionalAttributes) ? '' : ' ' . implode(' ', $additionalAttributes),
111  htmlspecialchars((string)$file->‪getPublicUrl()),
112  $file->‪getMimeType()
113  );
114  }
115 }
‪TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer\getPriority
‪int getPriority()
Definition: AudioTagRenderer.php:42
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:22
‪TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer\canRender
‪bool canRender(FileInterface $file)
Definition: AudioTagRenderer.php:53
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:33
‪TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer
Definition: AudioTagRenderer.php:26
‪TYPO3\CMS\Core\Resource\FileInterface\getProperty
‪string getProperty($key)
‪TYPO3\CMS\Core\Resource\Rendering
Definition: AudioTagRenderer.php:16
‪TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer\render
‪string render(FileInterface $file, $width, $height, array $options=[], $usedPathsRelativeToCurrentScript=false)
Definition: AudioTagRenderer.php:68
‪TYPO3\CMS\Core\Resource\Rendering\FileRendererInterface
Definition: FileRendererInterface.php:25
‪TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer\$possibleMimeTypes
‪array $possibleMimeTypes
Definition: AudioTagRenderer.php:31
‪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:50