-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] handle video and audio elements in ce (#67)
- Loading branch information
1 parent
0bc5bf9
commit 9a98e95
Showing
4 changed files
with
208 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
/*** | ||
* | ||
* This file is part of the "headless" Extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.md file that was distributed with this source code. | ||
* | ||
* (c) 2019 | ||
* | ||
***/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FriendsOfTYPO3\Headless\Resource\Rendering; | ||
|
||
use TYPO3\CMS\Core\Resource\FileInterface; | ||
use TYPO3\CMS\Core\Resource\FileReference; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* Audio tag renderer class | ||
*/ | ||
class AudioTagRenderer extends \TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer | ||
{ | ||
/** | ||
* @return int | ||
*/ | ||
public function getPriority(): int | ||
{ | ||
return 2; | ||
} | ||
|
||
/** | ||
* Render for given File(Reference) html output | ||
* | ||
* @param FileInterface $file | ||
* @param int|string $width TYPO3 known format; examples: 220, 200m or 200c | ||
* @param int|string $height TYPO3 known format; examples: 220, 200m or 200c | ||
* @param array $options | ||
* @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl() | ||
* @return string | ||
*/ | ||
public function render(FileInterface $file, $width, $height, array $options = [], $usedPathsRelativeToCurrentScript = false) | ||
{ | ||
if ($options['returnUrl'] === true) { | ||
|
||
// If autoplay isn't set manually check if $file is a FileReference take autoplay from there | ||
if (!isset($options['autoplay']) && $file instanceof FileReference) { | ||
$autoplay = $file->getProperty('autoplay'); | ||
if ($autoplay !== null) { | ||
$options['autoplay'] = $autoplay; | ||
} | ||
} | ||
|
||
$additionalAttributes = []; | ||
if (isset($options['additionalAttributes']) && is_array($options['additionalAttributes'])) { | ||
$additionalAttributes[] = GeneralUtility::implodeAttributes($options['additionalAttributes'], true, true); | ||
} | ||
if (isset($options['data']) && is_array($options['data'])) { | ||
array_walk($options['data'], function (&$value, $key) { | ||
$value = 'data-' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"'; | ||
}); | ||
$additionalAttributes[] = implode(' ', $options['data']); | ||
} | ||
if (!isset($options['controls']) || !empty($options['controls'])) { | ||
$additionalAttributes[] = 'controls'; | ||
} | ||
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', 'controlsList'] as $key) { | ||
if (!empty($options[$key])) { | ||
$additionalAttributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"'; | ||
} | ||
} | ||
|
||
return htmlspecialchars(GeneralUtility::makeInstance(FileUtility::class)->getAbsoluteUrl($file->getPublicUrl($usedPathsRelativeToCurrentScript)), ENT_QUOTES | ENT_HTML5); | ||
} else { | ||
return parent::render(...func_get_args()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/*** | ||
* | ||
* This file is part of the "headless" Extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.md file that was distributed with this source code. | ||
* | ||
* (c) 2019 | ||
* | ||
***/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FriendsOfTYPO3\Headless\Resource\Rendering; | ||
|
||
use FriendsOfTYPO3\Headless\Utility\FileUtility; | ||
use TYPO3\CMS\Core\Resource\FileInterface; | ||
use TYPO3\CMS\Core\Resource\FileReference; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* Video tag renderer class | ||
*/ | ||
class VideoTagRenderer extends \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer | ||
{ | ||
/** | ||
* @return int | ||
*/ | ||
public function getPriority(): int | ||
{ | ||
return 2; | ||
} | ||
|
||
/** | ||
* Render for given File(Reference) html output | ||
* | ||
* @param FileInterface $file | ||
* @param int|string $width TYPO3 known format; examples: 220, 200m or 200c | ||
* @param int|string $height TYPO3 known format; examples: 220, 200m or 200c | ||
* @param array $options | ||
* @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl() | ||
* @return string | ||
*/ | ||
public function render(FileInterface $file, $width, $height, array $options = [], $usedPathsRelativeToCurrentScript = false) | ||
{ | ||
if ($options['returnUrl'] === true) { | ||
|
||
// If autoplay isn't set manually check if $file is a FileReference take autoplay from there | ||
if (!isset($options['autoplay']) && $file instanceof FileReference) { | ||
$autoplay = $file->getProperty('autoplay'); | ||
if ($autoplay !== null) { | ||
$options['autoplay'] = $autoplay; | ||
} | ||
} | ||
|
||
$attributes = []; | ||
if (isset($options['additionalAttributes']) && is_array($options['additionalAttributes'])) { | ||
$attributes[] = GeneralUtility::implodeAttributes($options['additionalAttributes'], true, true); | ||
} | ||
if (isset($options['data']) && is_array($options['data'])) { | ||
array_walk($options['data'], function (&$value, $key) { | ||
$value = 'data-' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"'; | ||
}); | ||
$attributes[] = implode(' ', $options['data']); | ||
} | ||
if ((int)$width > 0) { | ||
$attributes[] = 'width="' . (int)$width . '"'; | ||
} | ||
if ((int)$height > 0) { | ||
$attributes[] = 'height="' . (int)$height . '"'; | ||
} | ||
if (!isset($options['controls']) || !empty($options['controls'])) { | ||
$attributes[] = 'controls'; | ||
} | ||
if (!empty($options['autoplay'])) { | ||
$attributes[] = 'autoplay'; | ||
} | ||
if (!empty($options['muted'])) { | ||
$attributes[] = 'muted'; | ||
} | ||
if (!empty($options['loop'])) { | ||
$attributes[] = 'loop'; | ||
} | ||
if (isset($options['additionalConfig']) && is_array($options['additionalConfig'])) { | ||
foreach ($options['additionalConfig'] as $key => $value) { | ||
if ((bool)$value) { | ||
$attributes[] = htmlspecialchars($key); | ||
} | ||
} | ||
} | ||
|
||
return htmlspecialchars(GeneralUtility::makeInstance(FileUtility::class)->getAbsoluteUrl($file->getPublicUrl($usedPathsRelativeToCurrentScript)), ENT_QUOTES | ENT_HTML5); | ||
} else { | ||
return parent::render(...func_get_args()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters