From 17ff7449ee23e406741406c836648704ab4be508 Mon Sep 17 00:00:00 2001 From: Moritz Ngo Date: Mon, 14 Oct 2024 12:02:04 +0200 Subject: [PATCH 1/7] [TASK] Prepare requirements for newer TYPO3 CMS versions --- composer.json | 2 +- ext_emconf.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index cddb3fd..33ffc9c 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "typo3-cms-extension", "license": "GPL-2.0-or-later", "require": { - "typo3/cms-core": "^9.5|^10.4" + "typo3/cms-core": "^9.5|^10.4|^11.5|^12.4" }, "replace": { "btu/btu_vimp": "self.version", diff --git a/ext_emconf.php b/ext_emconf.php index b069baa..6bd4362 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' => '9.5.0-12.4.99', ], 'conflicts' => [], 'suggests' => [], From f98c6bd7e1a6c2437f0d943128c156f43753e934 Mon Sep 17 00:00:00 2001 From: Moritz Ngo Date: Mon, 14 Oct 2024 14:29:36 +0200 Subject: [PATCH 2/7] [TASK] Raise requirement to PHP 8.0 and TYPO3 CMS v11 and above see https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.0/Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.html --- Classes/Helpers/VimpHelper.php | 2 ++ Classes/Rendering/VimpRenderer.php | 2 ++ composer.json | 3 ++- ext_emconf.php | 2 +- ext_localconf.php | 4 +++- ext_tables.php | 4 +++- 6 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Classes/Helpers/VimpHelper.php b/Classes/Helpers/VimpHelper.php index 749b4c0..4b49ddb 100644 --- a/Classes/Helpers/VimpHelper.php +++ b/Classes/Helpers/VimpHelper.php @@ -1,4 +1,6 @@ '1.1.1', 'constraints' => [ 'depends' => [ - 'typo3' => '9.5.0-12.4.99', + 'typo3' => '11.5.99-12.4.99', ], 'conflicts' => [], 'suggests' => [], diff --git a/ext_localconf.php b/ext_localconf.php index 95ad0a4..e09e2d9 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,5 +1,7 @@ Date: Mon, 14 Oct 2024 14:31:40 +0200 Subject: [PATCH 3/7] [CLEANUP] Use imported classes instead of FQCNs --- ext_localconf.php | 16 ++++++++++------ ext_tables.php | 7 +++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ext_localconf.php b/ext_localconf.php index e09e2d9..1e066dc 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,20 +1,24 @@ get('btu_vimp'); + $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('btu_vimp'); if (isset($extConf['baseUrl']) && !empty($extConf['baseUrl'])) { - $rendererRegistry = \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::getInstance(); - $rendererRegistry->registerRendererClass(\BTU\BtuVimp\Rendering\VimpRenderer::class); + $rendererRegistry = RendererRegistry::getInstance(); + $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 e80993f..11a47af 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -1,15 +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( From 80989b9bc0144f4124b7f6c196b44e6a458fc4ca Mon Sep 17 00:00:00 2001 From: Moritz Ngo Date: Mon, 14 Oct 2024 14:32:13 +0200 Subject: [PATCH 4/7] [BUGFIX] Remove/replace usage of deprecated functions --- Classes/Helpers/VimpHelper.php | 3 +-- Classes/Rendering/VimpRenderer.php | 3 +-- ext_localconf.php | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Classes/Helpers/VimpHelper.php b/Classes/Helpers/VimpHelper.php index 4b49ddb..eb21d85 100644 --- a/Classes/Helpers/VimpHelper.php +++ b/Classes/Helpers/VimpHelper.php @@ -21,7 +21,6 @@ use TYPO3\CMS\Core\Resource\Folder; use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\AbstractOnlineMediaHelper; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Core\Utility\StringUtility; /** * Vimp helper class @@ -65,7 +64,7 @@ public function transformUrlToFile($url, Folder $targetFolder) if (isset($this->baseUrl) && !empty($this->baseUrl) - && StringUtility::beginsWith($url, $this->baseUrl) + && str_starts_with($url, $this->baseUrl) ) { if (preg_match('/\/(?:video)\/([0-9a-z\-]+)\/([0-9a-z]+)/i', $url, $matches)) { $mediaTitle = $matches[1]; diff --git a/Classes/Rendering/VimpRenderer.php b/Classes/Rendering/VimpRenderer.php index 6b1fe58..69a1bfc 100644 --- a/Classes/Rendering/VimpRenderer.php +++ b/Classes/Rendering/VimpRenderer.php @@ -24,7 +24,6 @@ use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry; use TYPO3\CMS\Core\Resource\Rendering\FileRendererInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Object\ObjectManager; /** * Vimeo renderer class @@ -75,7 +74,7 @@ protected function getOnlineMediaHelper(FileInterface $file) $orgFile = $orgFile->getOriginalFile(); } if ($orgFile instanceof File) { - $this->onlineMediaHelper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($orgFile); + $this->onlineMediaHelper = GeneralUtility::makeInstance(OnlineMediaHelperRegistry::class)->getOnlineMediaHelper($orgFile); } else { $this->onlineMediaHelper = false; } diff --git a/ext_localconf.php b/ext_localconf.php index 1e066dc..24eafec 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -13,7 +13,7 @@ $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('btu_vimp'); if (isset($extConf['baseUrl']) && !empty($extConf['baseUrl'])) { - $rendererRegistry = RendererRegistry::getInstance(); + $rendererRegistry = GeneralUtility::makeInstance(RendererRegistry::class); $rendererRegistry->registerRendererClass(VimpRenderer::class); unset($rendererRegistry); From a92891a647b637af2c42fea02d551bf0fae5ae87 Mon Sep 17 00:00:00 2001 From: Moritz Ngo Date: Mon, 14 Oct 2024 16:44:37 +0200 Subject: [PATCH 5/7] [FEATURE] Introduce centralized ExtensionConfiguration class --- .../Configuration/ExtensionConfiguration.php | 51 +++++++++++++++++++ Classes/Exception/GenericException.php | 21 ++++++++ .../Exception/InvalidArgumentException.php | 19 +++++++ .../InvalidConfigurationException.php | 19 +++++++ Classes/Exception/LogicException.php | 19 +++++++ Classes/Exception/RuntimeException.php | 19 +++++++ Classes/Helpers/VimpHelper.php | 23 +++------ Classes/Rendering/VimpRenderer.php | 4 +- Configuration/Services.yaml | 8 +++ ext_localconf.php | 7 ++- 10 files changed, 168 insertions(+), 22 deletions(-) create mode 100644 Classes/Configuration/ExtensionConfiguration.php create mode 100644 Classes/Exception/GenericException.php create mode 100644 Classes/Exception/InvalidArgumentException.php create mode 100644 Classes/Exception/InvalidConfigurationException.php create mode 100644 Classes/Exception/LogicException.php create mode 100644 Classes/Exception/RuntimeException.php create mode 100644 Configuration/Services.yaml diff --git a/Classes/Configuration/ExtensionConfiguration.php b/Classes/Configuration/ExtensionConfiguration.php new file mode 100644 index 0000000..9ee3d45 --- /dev/null +++ b/Classes/Configuration/ExtensionConfiguration.php @@ -0,0 +1,51 @@ +get('btu_vimp', 'baseUrl'); + if (! is_string($baseUrl)) { + throw new InvalidConfigurationException('Configuration "baseUrl" must be a string', 1728910000); + } + $this->baseUrl = $baseUrl; + } + + public function getBaseUrl(): string + { + return $this->baseUrl; + } +} 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); } @@ -62,10 +56,7 @@ public function transformUrlToFile($url, Folder $targetFolder) { $mediaId = null; - if (isset($this->baseUrl) - && !empty($this->baseUrl) - && str_starts_with($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]; @@ -119,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 69a1bfc..5148c5a 100644 --- a/Classes/Rendering/VimpRenderer.php +++ b/Classes/Rendering/VimpRenderer.php @@ -16,7 +16,7 @@ * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; +use BTU\BtuVimp\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Resource\File; use TYPO3\CMS\Core\Resource\FileInterface; use TYPO3\CMS\Core\Resource\FileReference; @@ -150,7 +150,7 @@ protected function createVimpUrl(array $options, FileInterface $file) $urlParams[] = 'responsive=false'; $urlParams[] = 't=0'; - $baseUrl = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('btu_vimp', 'baseUrl'); + $baseUrl = GeneralUtility::makeInstance(ExtensionConfiguration::class)->getBaseUrl(); return sprintf($baseUrl . 'media/embed?key=%s&%s', $videoId, implode('&', $urlParams)); } 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/ext_localconf.php b/ext_localconf.php index 24eafec..5120cc7 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,18 +1,17 @@ get('btu_vimp'); - - if (isset($extConf['baseUrl']) && !empty($extConf['baseUrl'])) { + $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class); + if (! empty($extConf->getBaseUrl())) { $rendererRegistry = GeneralUtility::makeInstance(RendererRegistry::class); $rendererRegistry->registerRendererClass(VimpRenderer::class); unset($rendererRegistry); From c5561bf0e5ac49236d89bc93d18648ae28672e30 Mon Sep 17 00:00:00 2001 From: Moritz Ngo Date: Mon, 14 Oct 2024 15:44:25 +0200 Subject: [PATCH 6/7] [BUGFIX] Properly cast attribute values --- Classes/Rendering/VimpRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Rendering/VimpRenderer.php b/Classes/Rendering/VimpRenderer.php index 5148c5a..0e2aeaa 100644 --- a/Classes/Rendering/VimpRenderer.php +++ b/Classes/Rendering/VimpRenderer.php @@ -215,7 +215,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); From 9fd1f5bbccf56147e952efd35e9f88269d534bbe Mon Sep 17 00:00:00 2001 From: Moritz Ngo Date: Mon, 14 Oct 2024 17:03:02 +0200 Subject: [PATCH 7/7] [FEATURE] Add urlParameters to ExtConf --- .../Configuration/ExtensionConfiguration.php | 18 ++++++++++ Classes/Rendering/VimpRenderer.php | 34 ++++++++++--------- ext_conf_template.txt | 21 +++++++++++- 3 files changed, 56 insertions(+), 17 deletions(-) diff --git a/Classes/Configuration/ExtensionConfiguration.php b/Classes/Configuration/ExtensionConfiguration.php index 9ee3d45..7243703 100644 --- a/Classes/Configuration/ExtensionConfiguration.php +++ b/Classes/Configuration/ExtensionConfiguration.php @@ -24,10 +24,14 @@ /** * ExtensionConfiguration class + * + * @phpstan-type UrlParameters array */ class ExtensionConfiguration implements SingletonInterface { protected string $baseUrl; + /** @var UrlParameters */ + protected array $urlParameters; /** * @throws ExtensionConfigurationExtensionNotConfiguredException @@ -42,10 +46,24 @@ public function __construct( 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/Rendering/VimpRenderer.php b/Classes/Rendering/VimpRenderer.php index 0e2aeaa..90e3194 100644 --- a/Classes/Rendering/VimpRenderer.php +++ b/Classes/Rendering/VimpRenderer.php @@ -137,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)->getBaseUrl(); - - 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); } /** 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 +}