diff --git a/Classes/Configuration/ExtensionConfiguration.php b/Classes/Configuration/ExtensionConfiguration.php new file mode 100644 index 0000000..7243703 --- /dev/null +++ b/Classes/Configuration/ExtensionConfiguration.php @@ -0,0 +1,69 @@ + + */ +class ExtensionConfiguration implements SingletonInterface +{ + protected string $baseUrl; + /** @var UrlParameters */ + protected array $urlParameters; + + /** + * @throws ExtensionConfigurationExtensionNotConfiguredException + * @throws ExtensionConfigurationPathDoesNotExistException + * @throws InvalidConfigurationException + */ + public function __construct( + protected CoreExtensionConfiguration $extConf + ) { + $baseUrl = $extConf->get('btu_vimp', 'baseUrl'); + if (! is_string($baseUrl)) { + throw new InvalidConfigurationException('Configuration "baseUrl" must be a string', 1728910000); + } + $this->baseUrl = $baseUrl; + + $urlParameters = $extConf->get('btu_vimp', 'urlParameters'); + if (! is_array($urlParameters)) { + throw new InvalidConfigurationException('Configuration "urlParameters" must be an array', 1728910010); + } + $this->urlParameters = $urlParameters; + } + + public function getBaseUrl(): string + { + return $this->baseUrl; + } + + /** + * @return UrlParameters + */ + public function getUrlParameters(): array + { + return $this->urlParameters; + } +} diff --git a/Classes/Exception/GenericException.php b/Classes/Exception/GenericException.php new file mode 100644 index 0000000..3fc2646 --- /dev/null +++ b/Classes/Exception/GenericException.php @@ -0,0 +1,21 @@ +baseUrl)) { - $this->baseUrl = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('btu_vimp', 'baseUrl'); - } + + $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class); } @@ -61,10 +56,7 @@ public function transformUrlToFile($url, Folder $targetFolder) { $mediaId = null; - if (isset($this->baseUrl) - && !empty($this->baseUrl) - && StringUtility::beginsWith($url, $this->baseUrl) - ) { + if (str_starts_with($url, $this->extConf->getBaseUrl())) { if (preg_match('/\/(?:video)\/([0-9a-z\-]+)\/([0-9a-z]+)/i', $url, $matches)) { $mediaTitle = $matches[1]; $mediaId = $matches[2]; @@ -118,8 +110,8 @@ public function getPreviewImage(File $file) { $videoId = $this->getOnlineMediaId($file); $temporaryFileName = $this->getTempFolderPath() . 'vimp_' . md5($videoId) . '.jpg'; - if (!file_exists($temporaryFileName)) { - $thumbnailUrl = $this->baseUrl . '/api/getPicture?type=medium&key=' . $videoId; + if (! file_exists($temporaryFileName)) { + $thumbnailUrl = $this->extConf->getBaseUrl() . '/api/getPicture?type=medium&key=' . $videoId; $previewImage = GeneralUtility::getUrl($thumbnailUrl); if ($previewImage !== false) { file_put_contents($temporaryFileName, $previewImage); diff --git a/Classes/Rendering/VimpRenderer.php b/Classes/Rendering/VimpRenderer.php index a5f9d31..90e3194 100644 --- a/Classes/Rendering/VimpRenderer.php +++ b/Classes/Rendering/VimpRenderer.php @@ -1,4 +1,6 @@ getOriginalFile(); } if ($orgFile instanceof File) { - $this->onlineMediaHelper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($orgFile); + $this->onlineMediaHelper = GeneralUtility::makeInstance(OnlineMediaHelperRegistry::class)->getOnlineMediaHelper($orgFile); } else { $this->onlineMediaHelper = false; } @@ -136,22 +137,24 @@ protected function collectOptions(array $options, FileInterface $file) */ protected function createVimpUrl(array $options, FileInterface $file) { - $videoId = $this->getVideoIdFromFile($file); - - $urlParams = []; - $urlParams[] = 'width=720'; - $urlParams[] = 'height=405'; - $urlParams[] = ((bool)$options['autoplay'] === true) ? 'autoplay=true' : 'autoplay=false'; - $urlParams[] = 'autolightsoff=false'; - $urlParams[] = 'loop=false'; - $urlParams[] = 'chapters=false'; - $urlParams[] = 'related=false'; - $urlParams[] = 'responsive=false'; - $urlParams[] = 't=0'; - - $baseUrl = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('btu_vimp', 'baseUrl'); - - return sprintf($baseUrl . 'media/embed?key=%s&%s', $videoId, implode('&', $urlParams)); + $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class); + + $urlParameters = $extConf->getUrlParameters(); + $urlParameters['key'] = $this->getVideoIdFromFile($file); + $urlParameters['autoplay'] = ($options['autoplay'] ?? false) === true; + + array_walk($urlParameters, static function (&$value, $key) { + $value = match ($value) { + true => 'true', + false => 'false', + default => $value, + }; + }); + + $urlParameters = http_build_query($urlParameters, '', '&'); + + $baseUrl = $extConf->getBaseUrl(); + return sprintf($baseUrl . 'media/embed?%s', $urlParameters); } /** @@ -214,7 +217,7 @@ protected function implodeAttributes(array $attributes): string if ($value === true) { $attributeList[] = $name; } else { - $attributeList[] = $name . '="' . htmlspecialchars($value, ENT_QUOTES | ENT_HTML5) . '"'; + $attributeList[] = $name . '="' . htmlspecialchars((string)$value, ENT_QUOTES | ENT_HTML5) . '"'; } } return implode(' ', $attributeList); diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..06ca8a7 --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,8 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + BTU\BtuVimp\: + resource: '../Classes/*' diff --git a/composer.json b/composer.json index cddb3fd..f399749 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,8 @@ "type": "typo3-cms-extension", "license": "GPL-2.0-or-later", "require": { - "typo3/cms-core": "^9.5|^10.4" + "php": "^8.0", + "typo3/cms-core": "^11.5|^12.4" }, "replace": { "btu/btu_vimp": "self.version", diff --git a/ext_conf_template.txt b/ext_conf_template.txt index 49dc358..10addfc 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -1,4 +1,23 @@ # cat=Settings/O; type=string; label= ViMP base url baseUrl = - +urlParameters { + # cat=urlParameters; type=int+; label=width of embedded videos + width = 720 + # cat=urlParameters; type=int+; label=height of embedded videos + height = 405 + # cat=urlParameters; type=boolean; label=autolightsoff of embedded videos + autolightsoff = false + # cat=urlParameters; type=boolean; label=show controls of embedded videos + controls = true + # cat=urlParameters; type=boolean; label=loop videos + loop = false + # cat=urlParameters; type=boolean; label=show chapters of embedded videos + chapters = false + # cat=urlParameters; type=boolean; label=show playlists of embedded videos + playlist = false + # cat=urlParameters; type=boolean; label=show related videos in embedded videos + related = false + # cat=urlParameters; type=boolean; label=responsive behavior + responsive = true +} diff --git a/ext_emconf.php b/ext_emconf.php index b069baa..d085bb1 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -10,7 +10,7 @@ 'version' => '1.1.1', 'constraints' => [ 'depends' => [ - 'typo3' => '9.5.0-10.4.99', + 'typo3' => '11.5.99-12.4.99', ], 'conflicts' => [], 'suggests' => [], diff --git a/ext_localconf.php b/ext_localconf.php index 95ad0a4..5120cc7 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,18 +1,23 @@ get('btu_vimp'); +use BTU\BtuVimp\Configuration\ExtensionConfiguration; +use BTU\BtuVimp\Helpers\VimpHelper; +use BTU\BtuVimp\Rendering\VimpRenderer; +use TYPO3\CMS\Core\Resource\Rendering\RendererRegistry; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +defined('TYPO3') || die(); - if (isset($extConf['baseUrl']) && !empty($extConf['baseUrl'])) { - $rendererRegistry = \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::getInstance(); - $rendererRegistry->registerRendererClass(\BTU\BtuVimp\Rendering\VimpRenderer::class); +(static function () { + $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class); + if (! empty($extConf->getBaseUrl())) { + $rendererRegistry = GeneralUtility::makeInstance(RendererRegistry::class); + $rendererRegistry->registerRendererClass(VimpRenderer::class); unset($rendererRegistry); $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'] .= ',vimp'; $GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['fileExtensionToMimeType']['vimp'] = 'video/vimp'; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['onlineMediaHelpers']['vimp'] = \BTU\BtuVimp\Helpers\VimpHelper::class; + $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['onlineMediaHelpers']['vimp'] = VimpHelper::class; } })(); diff --git a/ext_tables.php b/ext_tables.php index d152bfa..11a47af 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -1,13 +1,18 @@ registerIcon( 'mimetypes-media-video-vimp', - \TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class, + BitmapIconProvider::class, ['source' => 'EXT:btu_vimp/Resources/Public/Icons/mimetypes/media-video-vimp.png'] ); $iconRegistry->registerMimeTypeIcon(