From 8aec33351ecd5b28bfedfc731365036ad90ac5e1 Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid Date: Thu, 6 Jan 2022 08:26:52 +0100 Subject: [PATCH 01/20] [TASK] Fix rector issues --- Classes/Service/YoutubeService.php | 22 +++++++++++----------- Configuration/TCA/Overrides/tt_content.php | 2 +- ext_localconf.php | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Classes/Service/YoutubeService.php b/Classes/Service/YoutubeService.php index b406514..70f88fb 100644 --- a/Classes/Service/YoutubeService.php +++ b/Classes/Service/YoutubeService.php @@ -40,13 +40,13 @@ use TYPO3\CMS\Core\Utility\VersionNumberUtility; * YouTube Helper Service */ class YoutubeService { - const API_URL = 'https://www.googleapis.com/youtube/v3/'; - const API_CHANNEL = 'search'; - const API_PLAYLIST = 'playlistItems'; - const API_VIDEO = 'videos'; - const API_PART = 'snippet'; - const API_PART_LOCALIZATIONS = 'localizations'; - const API_ORDER_BY = 'date'; + public const API_URL = 'https://www.googleapis.com/youtube/v3/'; + public const API_CHANNEL = 'search'; + public const API_PLAYLIST = 'playlistItems'; + public const API_VIDEO = 'videos'; + public const API_PART = 'snippet'; + public const API_PART_LOCALIZATIONS = 'localizations'; + public const API_ORDER_BY = 'date'; /** * Maps the json array from the YouTube call to return some unified value. The output from YouTube is pretty @@ -158,7 +158,7 @@ class YoutubeService { $localizationData = $this->getDetailedVideoInformationForJsonArray( $jsonArray, $apiKey, self::API_PART_LOCALIZATIONS ); - if (!isset($localizationData['items']) || count($localizationData['items']) <= 0) { + if (!isset($localizationData['items']) || (is_countable($localizationData['items']) ? count($localizationData['items']) : 0) <= 0) { return $jsonArray; } @@ -190,7 +190,7 @@ class YoutubeService { } foreach ($localizationData['items'] as $index => $localizationEntry) { - if (!isset($localizationEntry['localizations']) || count($localizationEntry['localizations']) <= 0) { + if (!isset($localizationEntry['localizations']) || (is_countable($localizationEntry['localizations']) ? count($localizationEntry['localizations']) : 0) <= 0) { continue; } @@ -266,7 +266,7 @@ class YoutubeService { } $result = $this->getJsonAsArray('', '10', $apiKey, $apiUrl . '?' . $query); - if (!isset($result['items']) || count($result['items']) <= 0) { + if (!isset($result['items']) || (is_countable($result['items']) ? count($result['items']) : 0) <= 0) { return $jsonArray; } @@ -339,7 +339,7 @@ class YoutubeService { throw new InvalidArgumentException('No items array.', 403); } - if (count($jsonArray['items']) < 1) { + if ((is_countable($jsonArray['items']) ? count($jsonArray['items']) : 0) < 1) { throw new InvalidArgumentException('No items found.', 403); } diff --git a/Configuration/TCA/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php index c12eb26..9905671 100644 --- a/Configuration/TCA/Overrides/tt_content.php +++ b/Configuration/TCA/Overrides/tt_content.php @@ -6,7 +6,7 @@ $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['sgyoutube_yo ); \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin( - 'SGalinski.sg_youtube', + 'Srectorprefix20211231gYoutube', 'Youtube', 'YouTube Videos' ); diff --git a/ext_localconf.php b/ext_localconf.php index 71c8207..cc53c63 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -24,15 +24,15 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -if (!defined('TYPO3_MODE')) { +if (!defined('TYPO3')) { die('Access denied.'); } \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( - 'SGalinski.sg_youtube', + 'Srectorprefix20211231gYoutube', 'Youtube', [ - 'Youtube' => 'index', + \SGalinski\Srectorprefix20211231gYoutube\Controller\YoutubeController::class => 'index', ], // non-cacheable actions -- GitLab From 824abcccef1800324e361eff2a788df3d1e7989c Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid Date: Thu, 6 Jan 2022 08:28:23 +0100 Subject: [PATCH 02/20] [TASK] Adjust version requirements to include TYPO3 11 and exclude TYPO3 9 --- composer.json | 4 ++-- ext_emconf.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 253ca14..5d90cf5 100644 --- a/composer.json +++ b/composer.json @@ -4,9 +4,9 @@ "description": "Embed YouTube Videos of a Playlist or Channel", "homepage": "https://www.sgalinski.de", "license": "GPL-2.0-or-later", - "version": "4.6.3", + "version": "5.0.0-dev", "require": { - "typo3/cms-core": "^9.5.4 || ^10.4.0", + "typo3/cms-core": "^10.4.0 || ^11.5.0", "sgalinski/project-theme-lightbox": "^1.0.0" }, "require-dev": { diff --git a/ext_emconf.php b/ext_emconf.php index e7eb5ff..98d8929 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -36,10 +36,10 @@ $EM_CONF['sg_youtube'] = [ 'uploadfolder' => '0', 'createDirs' => '', 'clearCacheOnLoad' => 0, - 'version' => '4.6.3', + 'version' => '5.0.0-dev', 'constraints' => [ 'depends' => [ - 'typo3' => '9.5.0-10.4.99', + 'typo3' => '10.4.0-11.5.99', 'project_theme_lightbox' => '^1.0.0', ], 'conflicts' => [], -- GitLab From 27a96003f5e784a38e1968283d4b1f5066d2ac04 Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid Date: Thu, 6 Jan 2022 08:31:38 +0100 Subject: [PATCH 03/20] [BUGFIX] Fix phpstan issues --- Classes/Hooks/PageLayoutView/PluginRenderer.php | 4 ++-- ext_localconf.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Classes/Hooks/PageLayoutView/PluginRenderer.php b/Classes/Hooks/PageLayoutView/PluginRenderer.php index 9b7e3da..46e0f14 100644 --- a/Classes/Hooks/PageLayoutView/PluginRenderer.php +++ b/Classes/Hooks/PageLayoutView/PluginRenderer.php @@ -87,8 +87,8 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { * Adapts the given $headerContent. * To be used in all plugin previews so the Header Contents appear similarly. * - * @param $headerContent - * @param $row + * @param string $headerContent + * @param array $row */ protected function adaptPluginHeaderContent(&$headerContent, $row): void { $headerContent = '

' . $this->getPluginNameForHeaderContent( diff --git a/ext_localconf.php b/ext_localconf.php index cc53c63..c158104 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -29,10 +29,10 @@ if (!defined('TYPO3')) { } \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( - 'Srectorprefix20211231gYoutube', + 'SgYoutube', 'Youtube', [ - \SGalinski\Srectorprefix20211231gYoutube\Controller\YoutubeController::class => 'index', + \SGalinski\SgYoutube\Controller\YoutubeController::class => 'index', ], // non-cacheable actions -- GitLab From 4595bf4189b53671af06b7ee5afe844e93c47f1a Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid Date: Thu, 6 Jan 2022 08:33:03 +0100 Subject: [PATCH 04/20] [TASK] Add the moved extension icon --- Resources/Public/Icons/Extension.png | Bin 0 -> 825 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Resources/Public/Icons/Extension.png diff --git a/Resources/Public/Icons/Extension.png b/Resources/Public/Icons/Extension.png new file mode 100644 index 0000000000000000000000000000000000000000..67fda8fec210ccf660363ff30c10f19513b4bfb2 GIT binary patch literal 825 zcmV-91IGM`P)(*1 zK~y-)jZ&N)jxscqAlpz~9M3N58n{Mpi^5--dkgEYGELJ+(uFVf6Lp)9=1 zE+j&4iX=-xNQ$&1M`=wVu!Vt$jE-&jH{I6UJZ|TF-DsLl>ACs%-k0y;eV*t2fFLmG zQa8@y{W&S44cdgq213HH2iRTeyh)eZ3E&$`=}CrRDgpQmgwz6nfsoyawoFkAzzg82 zwCW2aU8($?n3?Gah#~;A8VH#KP_Uhl*+P^LpcjBfUR#6mMAlOJ{YRmSNM$$xSk308 zuIlO#@A7g4!?FM{2%yp^2=?vLJ^;`tA|l-x?avl7I=Z41k;-s~)#{e~eqVBKZd9Yi z5_Yb>ev#!k3BXwZPl6dt2h+3?-GsNdu5PhDI+`}b#(FJ%eU6RB^ziUZV|+X{5b`Rh z*&NTaww_K000{t}RbDQs3GuKB1^>LJCaN_*f5~OHdt_M-0j2*8vel!_4yCU22OU(M ztyck{Bkk>uftHp?D$Akb$_ftU zj30o}C Date: Thu, 6 Jan 2022 08:35:12 +0100 Subject: [PATCH 05/20] [BUGFIX] Fix broken plugin name --- Configuration/TCA/Overrides/tt_content.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Configuration/TCA/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php index 9905671..739e84b 100644 --- a/Configuration/TCA/Overrides/tt_content.php +++ b/Configuration/TCA/Overrides/tt_content.php @@ -6,7 +6,7 @@ $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['sgyoutube_yo ); \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin( - 'Srectorprefix20211231gYoutube', + 'SgYoutube', 'Youtube', 'YouTube Videos' ); -- GitLab From 75c35f7ef44dc29bf63f7a6c5b8ba4a68c041607 Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid Date: Thu, 6 Jan 2022 10:38:28 +0100 Subject: [PATCH 06/20] [TASK] Implement Fluid Based Page Module approach of rendering the backend preview --- .../Hooks/PageLayoutView/PluginRenderer.php | 7 ++ Classes/Preview/PreviewRenderer.php | 114 ++++++++++++++++++ Configuration/Services.yaml | 11 ++ Configuration/TCA/Overrides/tt_content.php | 4 + 4 files changed, 136 insertions(+) create mode 100644 Classes/Preview/PreviewRenderer.php create mode 100644 Configuration/Services.yaml diff --git a/Classes/Hooks/PageLayoutView/PluginRenderer.php b/Classes/Hooks/PageLayoutView/PluginRenderer.php index 46e0f14..8e87c3a 100644 --- a/Classes/Hooks/PageLayoutView/PluginRenderer.php +++ b/Classes/Hooks/PageLayoutView/PluginRenderer.php @@ -32,6 +32,7 @@ use \TYPO3\CMS\Core\Localization\LanguageService; * Renders back-end preview for the SG YouTube Videos plugin * * @package SGalinski\SgYoutube\Hooks + * @deprecated All of this class will be removed when TYPO3 10 support is dropped */ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { /** @@ -44,10 +45,16 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { * @param array $row Record row of tt_content * @return void * @noinspection ReferencingObjectsInspection + * @deprecated All of this class will be removed when TYPO3 10 support is dropped */ public function preProcess( PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row ): void { + trigger_error( + 'Using the old style of rendering backend previews is deprecated and will not longer work when TYPO3 10' + . ' support is dropped! Please switch to using the Fluid Based Page Module instead!', + E_DEPRECATED + ); if ($row['list_type'] === 'sgyoutube_youtube') { $drawItem = FALSE; diff --git a/Classes/Preview/PreviewRenderer.php b/Classes/Preview/PreviewRenderer.php new file mode 100644 index 0000000..28f5108 --- /dev/null +++ b/Classes/Preview/PreviewRenderer.php @@ -0,0 +1,114 @@ +languageService = $languageService; + } + + /** + * Dedicated method for rendering preview header HTML for + * the page module only. Receives $item which is an instance of + * GridColumnItem which has a getter method to return the record. + * + * @param GridColumnItem + * @return string + */ + public function renderPageModulePreviewHeader(GridColumnItem $item): string { + $label = BackendUtility::getLabelFromItemListMerged( + $item->getRecord()['pid'], 'tt_content', 'list_type', $item->getRecord()['list_type'] + ); + return '

' . $this->languageService->sL($label) . '

'; + } + + /** + * Dedicated method for rendering preview body HTML for + * the page module only. + * + * @param GridColumnItem $item + * @return string + */ + public function renderPageModulePreviewContent(GridColumnItem $item): string { + $view = GeneralUtility::makeInstance(StandaloneView::class); + $view->setPartialRootPaths(['EXT:sg_youtube/Resources/Private/Partials/Backend']); + $view->setTemplateRootPaths(['EXT:sg_youtube/Resources/Private/Templates/Youtube']); + $view->setTemplate('Backend.html'); + $view->assign('uid', $item->getRecord()['uid']); + + // Get available plugin settings and their values from flexform + $pluginConfiguration = GeneralUtility::xml2array( + $item->getRecord()['pi_flexform'], 'T3DataStructure' + )['data']['sDEF']['lDEF']; + + $templateData = [ + 'youtubeId' => $pluginConfiguration['settings.id']['vDEF'], + 'maxResults' => $pluginConfiguration['settings.maxResults']['vDEF'], + 'showTitle' => (int) ($pluginConfiguration['settings.showTitle']['vDEF'] ?? 1), + 'showDescription' => (int) ($pluginConfiguration['settings.showDescription']['vDEF'] ?? 1), + 'disableLightbox' => $pluginConfiguration['settings.disableLightbox']['vDEF'], + 'disableLightboxMobile' => $pluginConfiguration['settings.disableLightboxMobile']['vDEF'], + 'aspectRatio' => $pluginConfiguration['settings.aspectRatio']['vDEF'], + 'thumbnailType' => $pluginConfiguration['settings.thumbnailType']['vDEF'], + 'thumbnailImagesCount' => $pluginConfiguration['settings.thumbnailImages']['vDEF'], + 'showApiResult' => $pluginConfiguration['settings.showApiResult']['vDEF'], + ]; + + $view->assign('data', $templateData); + return $view->render(); + } + + /** + * Render a footer for the record to display in page module below + * the body of the item's preview. + * + * @param GridColumnItem $item + * @return string + */ + public function renderPageModulePreviewFooter(GridColumnItem $item): string { + return ''; + } + + /** + * Dedicated method for wrapping a preview header and body HTML. + * + * @param string $previewHeader + * @param string $previewContent + * @param GridColumnItem $item + * @return string + */ + public function wrapPageModulePreview(string $previewHeader, string $previewContent, GridColumnItem $item): string { + return $previewHeader . '
' . $previewContent; + } +} \ No newline at end of file diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..5e57a0f --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,11 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + SGalinski\SgYoutube\: + resource: '../Classes/*' + + SGalinski\SgYoutube\Preview\PreviewRenderer: + public: true \ No newline at end of file diff --git a/Configuration/TCA/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php index 739e84b..9e9cdaa 100644 --- a/Configuration/TCA/Overrides/tt_content.php +++ b/Configuration/TCA/Overrides/tt_content.php @@ -10,3 +10,7 @@ $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['sgyoutube_yo 'Youtube', 'YouTube Videos' ); + +// add the backend preview for the youtube plugin +$GLOBALS['TCA']['tt_content']['types']['list']['previewRenderer']['sgyoutube_youtube'] = + \SGalinski\SgYoutube\Preview\PreviewRenderer::class; \ No newline at end of file -- GitLab From 3ec451b709811b0852de20b4df215fbf20db477c Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid Date: Thu, 6 Jan 2022 10:40:13 +0100 Subject: [PATCH 07/20] [BUGFIX] Fix docbloc @param --- Classes/Preview/PreviewRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Preview/PreviewRenderer.php b/Classes/Preview/PreviewRenderer.php index 28f5108..d0de245 100644 --- a/Classes/Preview/PreviewRenderer.php +++ b/Classes/Preview/PreviewRenderer.php @@ -43,7 +43,7 @@ class PreviewRenderer implements PreviewRendererInterface { * the page module only. Receives $item which is an instance of * GridColumnItem which has a getter method to return the record. * - * @param GridColumnItem + * @param GridColumnItem $item * @return string */ public function renderPageModulePreviewHeader(GridColumnItem $item): string { -- GitLab From f7a0fe83092c948ac4d019e7b921e786582d9e2d Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid Date: Thu, 6 Jan 2022 10:44:26 +0100 Subject: [PATCH 08/20] [TASK] Run CS fixer --- Classes/Controller/YoutubeController.php | 14 +- .../Hooks/PageLayoutView/PluginRenderer.php | 25 ++- Classes/Preview/PreviewRenderer.php | 157 +++++++++--------- Classes/Service/YoutubeService.php | 21 ++- Configuration/TCA/Overrides/tt_content.php | 7 +- 5 files changed, 125 insertions(+), 99 deletions(-) diff --git a/Classes/Controller/YoutubeController.php b/Classes/Controller/YoutubeController.php index e800c20..8d21fe4 100644 --- a/Classes/Controller/YoutubeController.php +++ b/Classes/Controller/YoutubeController.php @@ -59,7 +59,7 @@ class YoutubeController extends ActionController { $apiKey = $this->settings['apiKey']; $thumbnailType = $this->settings['thumbnailType']; $aspectRatio = $this->settings['aspectRatio']; - $showApiResult = (boolean) $this->settings['showApiResult']; + $showApiResult = (bool) $this->settings['showApiResult']; $debugOutput = ''; try { @@ -70,7 +70,11 @@ class YoutubeController extends ActionController { } $jsonArray['items'] = $this->youtubeService->mapArray( - $jsonArray['items'], $id, $aspectRatio, $thumbnailType, $apiKey + $jsonArray['items'], + $id, + $aspectRatio, + $thumbnailType, + $apiKey ); $jsonArray['items'] = $this->mapJsonArrayWithPossibleCustomThumbnails($jsonArray['items']); @@ -105,7 +109,9 @@ class YoutubeController extends ActionController { $fileRepository = GeneralUtility::makeInstance(FileRepository::class); $fileObjects = $fileRepository->findByRelation( - 'tt_content', 'tx_sgyoutube_thumbnail_image', $contentElementUid + 'tt_content', + 'tx_sgyoutube_thumbnail_image', + $contentElementUid ); if (count($fileObjects) <= 0) { return $jsonArray; @@ -125,7 +131,7 @@ class YoutubeController extends ActionController { $cropVariantCollection = CropVariantCollection::create((string) $cropString); $cropArea = $cropVariantCollection->getCropArea('default'); $processingInstructions = [ - 'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($fileObject), + 'crop' => $cropArea->isEmpty() ? NULL : $cropArea->makeAbsoluteBasedOnFile($fileObject), ]; $imageService = GeneralUtility::makeInstance(ImageService::class); $processedImage = $imageService->applyProcessingInstructions($fileObject, $processingInstructions); diff --git a/Classes/Hooks/PageLayoutView/PluginRenderer.php b/Classes/Hooks/PageLayoutView/PluginRenderer.php index 8e87c3a..7af0d9a 100644 --- a/Classes/Hooks/PageLayoutView/PluginRenderer.php +++ b/Classes/Hooks/PageLayoutView/PluginRenderer.php @@ -23,9 +23,9 @@ namespace SGalinski\SgYoutube\Hooks\PageLayoutView; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\View\PageLayoutView; use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; -use \TYPO3\CMS\Core\Localization\LanguageService; /** * Class PluginRenderer @@ -48,11 +48,15 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { * @deprecated All of this class will be removed when TYPO3 10 support is dropped */ public function preProcess( - PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row + PageLayoutView &$parentObject, + &$drawItem, + &$headerContent, + &$itemContent, + array &$row ): void { trigger_error( - 'Using the old style of rendering backend previews is deprecated and will not longer work when TYPO3 10' - . ' support is dropped! Please switch to using the Fluid Based Page Module instead!', + 'Using the old style of rendering backend previews is deprecated and will not longer work when TYPO3 10' + . ' support is dropped! Please switch to using the Fluid Based Page Module instead!', E_DEPRECATED ); if ($row['list_type'] === 'sgyoutube_youtube') { @@ -68,7 +72,8 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { // Get available plugin settings and their values from flexform $pluginConfiguration = GeneralUtility::xml2array( - $row['pi_flexform'], 'T3DataStructure' + $row['pi_flexform'], + 'T3DataStructure' )['data']['sDEF']['lDEF']; $templateData = [ @@ -99,8 +104,9 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { */ protected function adaptPluginHeaderContent(&$headerContent, $row): void { $headerContent = '

' . $this->getPluginNameForHeaderContent( - (int) $row['pid'], $row['list_type'] - ) . $headerContent . '

'; + (int) $row['pid'], + $row['list_type'] + ) . $headerContent . '

'; } /** @@ -116,7 +122,10 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { $pluginName = $languageService->sL( BackendUtility::getLabelFromItemListMerged( - $pid, 'tt_content', 'list_type', $listType + $pid, + 'tt_content', + 'list_type', + $listType ) ); return '' . $pluginName . ' '; diff --git a/Classes/Preview/PreviewRenderer.php b/Classes/Preview/PreviewRenderer.php index d0de245..473b4ee 100644 --- a/Classes/Preview/PreviewRenderer.php +++ b/Classes/Preview/PreviewRenderer.php @@ -18,7 +18,7 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ - namespace SGalinski\SgYoutube\Preview; +namespace SGalinski\SgYoutube\Preview; use TYPO3\CMS\Backend\Preview\PreviewRendererInterface; use TYPO3\CMS\Backend\Utility\BackendUtility; @@ -28,87 +28,90 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; class PreviewRenderer implements PreviewRendererInterface { - /** - * @var LanguageService $languageService - */ - protected LanguageService $languageService; + /** + * @var LanguageService $languageService + */ + protected LanguageService $languageService; - public function __construct(LanguageService $languageService) - { - $this->languageService = $languageService; - } + public function __construct(LanguageService $languageService) { + $this->languageService = $languageService; + } - /** - * Dedicated method for rendering preview header HTML for - * the page module only. Receives $item which is an instance of - * GridColumnItem which has a getter method to return the record. - * - * @param GridColumnItem $item - * @return string - */ - public function renderPageModulePreviewHeader(GridColumnItem $item): string { - $label = BackendUtility::getLabelFromItemListMerged( - $item->getRecord()['pid'], 'tt_content', 'list_type', $item->getRecord()['list_type'] - ); - return '

' . $this->languageService->sL($label) . '

'; - } + /** + * Dedicated method for rendering preview header HTML for + * the page module only. Receives $item which is an instance of + * GridColumnItem which has a getter method to return the record. + * + * @param GridColumnItem $item + * @return string + */ + public function renderPageModulePreviewHeader(GridColumnItem $item): string { + $label = BackendUtility::getLabelFromItemListMerged( + $item->getRecord()['pid'], + 'tt_content', + 'list_type', + $item->getRecord()['list_type'] + ); + return '

' . $this->languageService->sL($label) . '

'; + } - /** - * Dedicated method for rendering preview body HTML for - * the page module only. - * - * @param GridColumnItem $item - * @return string - */ - public function renderPageModulePreviewContent(GridColumnItem $item): string { - $view = GeneralUtility::makeInstance(StandaloneView::class); - $view->setPartialRootPaths(['EXT:sg_youtube/Resources/Private/Partials/Backend']); - $view->setTemplateRootPaths(['EXT:sg_youtube/Resources/Private/Templates/Youtube']); - $view->setTemplate('Backend.html'); - $view->assign('uid', $item->getRecord()['uid']); + /** + * Dedicated method for rendering preview body HTML for + * the page module only. + * + * @param GridColumnItem $item + * @return string + */ + public function renderPageModulePreviewContent(GridColumnItem $item): string { + $view = GeneralUtility::makeInstance(StandaloneView::class); + $view->setPartialRootPaths(['EXT:sg_youtube/Resources/Private/Partials/Backend']); + $view->setTemplateRootPaths(['EXT:sg_youtube/Resources/Private/Templates/Youtube']); + $view->setTemplate('Backend.html'); + $view->assign('uid', $item->getRecord()['uid']); - // Get available plugin settings and their values from flexform - $pluginConfiguration = GeneralUtility::xml2array( - $item->getRecord()['pi_flexform'], 'T3DataStructure' - )['data']['sDEF']['lDEF']; + // Get available plugin settings and their values from flexform + $pluginConfiguration = GeneralUtility::xml2array( + $item->getRecord()['pi_flexform'], + 'T3DataStructure' + )['data']['sDEF']['lDEF']; - $templateData = [ - 'youtubeId' => $pluginConfiguration['settings.id']['vDEF'], - 'maxResults' => $pluginConfiguration['settings.maxResults']['vDEF'], - 'showTitle' => (int) ($pluginConfiguration['settings.showTitle']['vDEF'] ?? 1), - 'showDescription' => (int) ($pluginConfiguration['settings.showDescription']['vDEF'] ?? 1), - 'disableLightbox' => $pluginConfiguration['settings.disableLightbox']['vDEF'], - 'disableLightboxMobile' => $pluginConfiguration['settings.disableLightboxMobile']['vDEF'], - 'aspectRatio' => $pluginConfiguration['settings.aspectRatio']['vDEF'], - 'thumbnailType' => $pluginConfiguration['settings.thumbnailType']['vDEF'], - 'thumbnailImagesCount' => $pluginConfiguration['settings.thumbnailImages']['vDEF'], - 'showApiResult' => $pluginConfiguration['settings.showApiResult']['vDEF'], - ]; + $templateData = [ + 'youtubeId' => $pluginConfiguration['settings.id']['vDEF'], + 'maxResults' => $pluginConfiguration['settings.maxResults']['vDEF'], + 'showTitle' => (int) ($pluginConfiguration['settings.showTitle']['vDEF'] ?? 1), + 'showDescription' => (int) ($pluginConfiguration['settings.showDescription']['vDEF'] ?? 1), + 'disableLightbox' => $pluginConfiguration['settings.disableLightbox']['vDEF'], + 'disableLightboxMobile' => $pluginConfiguration['settings.disableLightboxMobile']['vDEF'], + 'aspectRatio' => $pluginConfiguration['settings.aspectRatio']['vDEF'], + 'thumbnailType' => $pluginConfiguration['settings.thumbnailType']['vDEF'], + 'thumbnailImagesCount' => $pluginConfiguration['settings.thumbnailImages']['vDEF'], + 'showApiResult' => $pluginConfiguration['settings.showApiResult']['vDEF'], + ]; - $view->assign('data', $templateData); - return $view->render(); - } + $view->assign('data', $templateData); + return $view->render(); + } - /** - * Render a footer for the record to display in page module below - * the body of the item's preview. - * - * @param GridColumnItem $item - * @return string - */ - public function renderPageModulePreviewFooter(GridColumnItem $item): string { - return ''; - } + /** + * Render a footer for the record to display in page module below + * the body of the item's preview. + * + * @param GridColumnItem $item + * @return string + */ + public function renderPageModulePreviewFooter(GridColumnItem $item): string { + return ''; + } - /** - * Dedicated method for wrapping a preview header and body HTML. - * - * @param string $previewHeader - * @param string $previewContent - * @param GridColumnItem $item - * @return string - */ - public function wrapPageModulePreview(string $previewHeader, string $previewContent, GridColumnItem $item): string { - return $previewHeader . '
' . $previewContent; - } -} \ No newline at end of file + /** + * Dedicated method for wrapping a preview header and body HTML. + * + * @param string $previewHeader + * @param string $previewContent + * @param GridColumnItem $item + * @return string + */ + public function wrapPageModulePreview(string $previewHeader, string $previewContent, GridColumnItem $item): string { + return $previewHeader . '
' . $previewContent; + } +} diff --git a/Classes/Service/YoutubeService.php b/Classes/Service/YoutubeService.php index 70f88fb..8735866 100644 --- a/Classes/Service/YoutubeService.php +++ b/Classes/Service/YoutubeService.php @@ -60,7 +60,11 @@ class YoutubeService { * @return array */ public function mapArray( - $jsonArray = [], $youtubeId = '', $aspectRatio = '16:9', $thumbnailType = 'byAspectRatio', $apiKey = '' + $jsonArray = [], + $youtubeId = '', + $aspectRatio = '16:9', + $thumbnailType = 'byAspectRatio', + $apiKey = '' ): array { if (count($jsonArray) <= 0) { return $jsonArray; @@ -156,7 +160,9 @@ class YoutubeService { } $localizationData = $this->getDetailedVideoInformationForJsonArray( - $jsonArray, $apiKey, self::API_PART_LOCALIZATIONS + $jsonArray, + $apiKey, + self::API_PART_LOCALIZATIONS ); if (!isset($localizationData['items']) || (is_countable($localizationData['items']) ? count($localizationData['items']) : 0) <= 0) { return $jsonArray; @@ -202,11 +208,11 @@ class YoutubeService { break; } - if (!$title && isset($localizations[$languageIsoCode]['title'])) { + if (!$title && isset($localizations[$languageIsoCode]['title'])) { $title = $localizations[$languageIsoCode]['title']; } - if (!$description && isset($localizations[$languageIsoCode]['description'])) { + if (!$description && isset($localizations[$languageIsoCode]['description'])) { $description = $localizations[$languageIsoCode]['description']; } } @@ -309,19 +315,20 @@ class YoutubeService { curl_setopt($ch, CURLOPT_URL, $url); $jsonString = curl_exec($ch); curl_close($ch); - } elseif (ini_get('allow_url_fopen')) { $jsonString = file_get_contents($url); } else { throw new InvalidArgumentException( - 'The system doesn\'t have CURL enabled and "allow_url_fopen" is disabled.', 403 + 'The system doesn\'t have CURL enabled and "allow_url_fopen" is disabled.', + 403 ); } $jsonArray = ($jsonString !== '' ? json_decode($jsonString, TRUE) : []); if ($jsonArray === NULL) { throw new InvalidArgumentException( - 'There is something wrong with loaded JSON or encoded data is deeper than the recursion limit.', 403 + 'There is something wrong with loaded JSON or encoded data is deeper than the recursion limit.', + 403 ); } diff --git a/Configuration/TCA/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php index 9e9cdaa..1e0f082 100644 --- a/Configuration/TCA/Overrides/tt_content.php +++ b/Configuration/TCA/Overrides/tt_content.php @@ -2,7 +2,8 @@ $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['sgyoutube_youtube'] = 'pi_flexform'; \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue( - 'sgyoutube_youtube', 'FILE:EXT:sg_youtube/Configuration/FlexForms/flexform_sgyoutube_youtube.xml' + 'sgyoutube_youtube', + 'FILE:EXT:sg_youtube/Configuration/FlexForms/flexform_sgyoutube_youtube.xml' ); \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin( @@ -12,5 +13,5 @@ $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['sgyoutube_yo ); // add the backend preview for the youtube plugin -$GLOBALS['TCA']['tt_content']['types']['list']['previewRenderer']['sgyoutube_youtube'] = - \SGalinski\SgYoutube\Preview\PreviewRenderer::class; \ No newline at end of file +$GLOBALS['TCA']['tt_content']['types']['list']['previewRenderer']['sgyoutube_youtube'] = + \SGalinski\SgYoutube\Preview\PreviewRenderer::class; -- GitLab From 2407b9d3c7e2b19a862d9c985c262e3c295b1d4a Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid Date: Thu, 6 Jan 2022 11:00:39 +0100 Subject: [PATCH 09/20] [TASK] Remove version check for TYPO3 >9 because we are only supporting >10 --- .../Hooks/PageLayoutView/PluginRenderer.php | 2 +- Classes/Service/YoutubeService.php | 26 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Classes/Hooks/PageLayoutView/PluginRenderer.php b/Classes/Hooks/PageLayoutView/PluginRenderer.php index 7af0d9a..3ed7b69 100644 --- a/Classes/Hooks/PageLayoutView/PluginRenderer.php +++ b/Classes/Hooks/PageLayoutView/PluginRenderer.php @@ -57,7 +57,7 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { trigger_error( 'Using the old style of rendering backend previews is deprecated and will not longer work when TYPO3 10' . ' support is dropped! Please switch to using the Fluid Based Page Module instead!', - E_DEPRECATED + E_USER_DEPRECATED ); if ($row['list_type'] === 'sgyoutube_youtube') { $drawItem = FALSE; diff --git a/Classes/Service/YoutubeService.php b/Classes/Service/YoutubeService.php index 8735866..5b99588 100644 --- a/Classes/Service/YoutubeService.php +++ b/Classes/Service/YoutubeService.php @@ -88,22 +88,18 @@ class YoutubeService { $aspectRatio = '16:9'; } - // Localization is just available from TYPO3 9.X.X - if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '>=')) { - $context = GeneralUtility::makeInstance(Context::class); - - try { - /** @var LanguageAspect $languageAspect */ - $languageAspect = $context->getAspect('language'); - $currentLanguageUid = $languageAspect->getId(); - } catch (AspectNotFoundException $e) { - // Can't be possible to land here, otherwise the whole frontend would be weird as hell.. - $currentLanguageUid = 0; - } + $context = GeneralUtility::makeInstance(Context::class); + try { + /** @var LanguageAspect $languageAspect */ + $languageAspect = $context->getAspect('language'); + $currentLanguageUid = $languageAspect->getId(); + } catch (AspectNotFoundException $e) { + // Can't be possible to land here, otherwise the whole frontend would be weird as hell.. + $currentLanguageUid = 0; + } - if ($currentLanguageUid > 0 && $youtubeId && $apiKey) { - $jsonArray = $this->addLocalizationData($jsonArray, $apiKey, $currentLanguageUid); - } + if ($currentLanguageUid > 0 && $youtubeId && $apiKey) { + $jsonArray = $this->addLocalizationData($jsonArray, $apiKey, $currentLanguageUid); } $result = []; -- GitLab From 5e9ce515f422309d93919f6b5b04b2f3c1f91c6c Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid Date: Thu, 6 Jan 2022 11:41:40 +0100 Subject: [PATCH 10/20] [BUGFIX] Change API caller Change the way the YouTube API is called to RequestFactory, because we do not want to care manually what method of fetching urls is available on the server. --- Classes/Service/YoutubeService.php | 58 ++++++++++++++++++------------ 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/Classes/Service/YoutubeService.php b/Classes/Service/YoutubeService.php index 5b99588..c21799b 100644 --- a/Classes/Service/YoutubeService.php +++ b/Classes/Service/YoutubeService.php @@ -26,15 +26,17 @@ namespace SGalinski\SgYoutube\Service; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use Exception; +use GuzzleHttp\Exception\ClientException; use InvalidArgumentException; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; use TYPO3\CMS\Core\Context\LanguageAspect; +use TYPO3\CMS\Core\Http\RequestFactory; use TYPO3\CMS\Core\Http\ServerRequest; use TYPO3\CMS\Core\Registry; use TYPO3\CMS\Core\Site\Entity\Site; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Core\Utility\VersionNumberUtility; /** * YouTube Helper Service @@ -164,15 +166,11 @@ class YoutubeService { return $jsonArray; } - /** @var ServerRequest $request */ - $request = $GLOBALS['TYPO3_REQUEST']; - $attributes = $request->getAttributes(); - if (!isset($attributes['site'])) { + $site = $this->getSite(); + if ($site === NULL) { return $jsonArray; } - /** @var Site $site */ - $site = $attributes['site']; $languages = $site->getLanguages(); $currentSiteLanguage = $languages[$currentLanguageUid]; if (!$currentSiteLanguage) { @@ -304,22 +302,22 @@ class YoutubeService { } } - if (function_exists('curl_init')) { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($ch, CURLOPT_URL, $url); - $jsonString = curl_exec($ch); - curl_close($ch); - } elseif (ini_get('allow_url_fopen')) { - $jsonString = file_get_contents($url); - } else { - throw new InvalidArgumentException( - 'The system doesn\'t have CURL enabled and "allow_url_fopen" is disabled.', - 403 - ); + $requestFactory = GeneralUtility::makeInstance(RequestFactory::class); + try { + $site = $this->getSite(); + if ($site === NULL) { + throw new Exception('No site object found!'); + } + $response = $requestFactory->request($url, 'GET', [ + 'headers' => [ + 'Referer' => $site->getBase()->getHost() + ] + ]); + $jsonString = (string) $response->getBody(); + } catch (ClientException $exception) { + $jsonString = (string) $exception->getResponse()->getBody(); } - + $jsonArray = ($jsonString !== '' ? json_decode($jsonString, TRUE) : []); if ($jsonArray === NULL) { throw new InvalidArgumentException( @@ -399,4 +397,20 @@ class YoutubeService { return $youtubeId; } + + /** + * Get the current site of the request + * + * @return Site|null + */ + protected function getSite(): ?Site { + /** @var ServerRequest $request */ + $request = $GLOBALS['TYPO3_REQUEST']; + $attributes = $request->getAttributes(); + if (!isset($attributes['site'])) { + return NULL; + } + + return $attributes['site']; + } } -- GitLab From 41af8b2b049e4d681541ff1d0d535a9f95ea8e00 Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid Date: Thu, 6 Jan 2022 11:54:32 +0100 Subject: [PATCH 11/20] [TASK] Remove unused br in preview --- Classes/Preview/PreviewRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Preview/PreviewRenderer.php b/Classes/Preview/PreviewRenderer.php index 473b4ee..1c27be0 100644 --- a/Classes/Preview/PreviewRenderer.php +++ b/Classes/Preview/PreviewRenderer.php @@ -112,6 +112,6 @@ class PreviewRenderer implements PreviewRendererInterface { * @return string */ public function wrapPageModulePreview(string $previewHeader, string $previewContent, GridColumnItem $item): string { - return $previewHeader . '
' . $previewContent; + return $previewHeader . $previewContent; } } -- GitLab From 8e93e989fc6904fa8c75cc7e74db1448865da7df Mon Sep 17 00:00:00 2001 From: Matthias Adrowski Date: Fri, 4 Feb 2022 10:45:17 +0100 Subject: [PATCH 12/20] [TASK] Update Services.yaml, TS Setup --- Configuration/Services.yaml | 9 ++++++--- Configuration/TypoScript/setup.typoscript | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 5e57a0f..d97fa1c 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -2,10 +2,13 @@ services: _defaults: autowire: true autoconfigure: true - public: false + public: true SGalinski\SgYoutube\: resource: '../Classes/*' - + SGalinski\SgYoutube\Preview\PreviewRenderer: - public: true \ No newline at end of file + public: true + + SGalinski\SgYoutube\Service\YoutubeService: + public: true diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index 32b5bbd..381ab31 100644 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -20,3 +20,4 @@ plugin.tx_sgyoutube { } } } +plugin.tx_sgyoutube_youtube < plugin.tx_sgyoutube -- GitLab From b327700d9b7a4641740ab91967ef3f0a971f640a Mon Sep 17 00:00:00 2001 From: Matthias Adrowski Date: Fri, 4 Feb 2022 11:01:41 +0100 Subject: [PATCH 13/20] [TASK] Remove old js dependency --- .../Public/JavaScript/youtubeLightbox.js | 93 ------------------- 1 file changed, 93 deletions(-) delete mode 100644 Resources/Public/JavaScript/youtubeLightbox.js diff --git a/Resources/Public/JavaScript/youtubeLightbox.js b/Resources/Public/JavaScript/youtubeLightbox.js deleted file mode 100644 index 92d7878..0000000 --- a/Resources/Public/JavaScript/youtubeLightbox.js +++ /dev/null @@ -1,93 +0,0 @@ -/** - * JavaScript module for the sg-youtube plugin - * - * @deprecated since version 4.4.0 and will be removed in 5.0.0 - */ -module.exports = function() { - 'use strict'; - - const $ = require('jquery'); - require('magnific-popup'); - - /** - * Initialize the whole Popup setup - */ - function init(section) { - $(`${section || ''} .sg-youtube-item`).each(function (index, item) { - let $youtubeItem = $(item), - viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0); - if (($youtubeItem.data('disable-lightbox') && viewportWidth >= 680) || - ($youtubeItem.data('disable-lightbox-mobile') && viewportWidth < 680) - ) { - $youtubeItem.on('click', replaceThumbnailWithVideo); - } else { - $youtubeItem.magnificPopup({ - type: 'iframe', - iframe: { - patterns: { - youtube: { - index: 'youtube.com/', - id: function(url) { - return prepareVideoUrl(url); - }, - src: '//www.youtube-nocookie.com/embed/%id%' - } - } - } - }); - } - }); - } - - /** - * Replaces the given element behind the event with a youtube video. - * - * @param {Event} event - */ - function replaceThumbnailWithVideo(event) { - event.preventDefault(); - let $youtubeItem = $(event.currentTarget); - - // This needs to be done, because the height of inline elements is always 0, if on auto... - $youtubeItem.css('display', 'block'); - - let queryString = prepareVideoUrl($youtubeItem.attr('href')), - $thumbnailElement = $youtubeItem.find('.sg-youtube-image'), - width = $thumbnailElement.outerWidth() + 'px', - height = $thumbnailElement.outerHeight() + 'px'; - $thumbnailElement.replaceWith('
'); - } - - /** - * Prepares the given url, or returns null. - * - * @param {string} url - * @return {string|null} - */ - function prepareVideoUrl(url) { - let matches = url.match(/watch\?v=(.*)&list=(.*)/); - if (!matches) { - // check if the list parameter is missing - matches = url.match(/watch\?v=([^?&]*)/); - if (!matches) { - return null; - } - } - let [, videoString] = matches, - queryParameterSeparator = '?'; - if (matches[2]) { - videoString += '?list=' + matches[2]; - queryParameterSeparator = '&'; - - } - - return videoString + queryParameterSeparator + 'autoplay=1&rel=0'; - } - - init(); -}; -- GitLab From d83e7c02619c7235617e05e63b97c147e0ff9b32 Mon Sep 17 00:00:00 2001 From: Matthias Adrowski Date: Mon, 7 Feb 2022 13:25:39 +0100 Subject: [PATCH 14/20] [TASK] error fixes --- Classes/Service/CachedImageService.php | 2 +- Configuration/Services.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Classes/Service/CachedImageService.php b/Classes/Service/CachedImageService.php index 3632be9..8770e5f 100644 --- a/Classes/Service/CachedImageService.php +++ b/Classes/Service/CachedImageService.php @@ -73,7 +73,7 @@ class CachedImageService { * * @param string $cacheDirectory */ - public function __construct($cacheDirectory) { + public function __construct(string $cacheDirectory = '') { $this->cacheDirectory = ltrim($cacheDirectory, '/'); } diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index d97fa1c..53ba195 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -12,3 +12,4 @@ services: SGalinski\SgYoutube\Service\YoutubeService: public: true + autowire: false -- GitLab From 00c20861cfd92995eb957f0fa7d0efaa84811e4c Mon Sep 17 00:00:00 2001 From: Matthias Adrowski Date: Mon, 14 Feb 2022 13:52:01 +0100 Subject: [PATCH 15/20] [TASK] Migrate to PreviewService --- .../Hooks/PageLayoutView/PluginRenderer.php | 37 +++----- Classes/Preview/PreviewRenderer.php | 32 ++----- Classes/Preview/PreviewService.php | 86 +++++++++++++++++++ 3 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 Classes/Preview/PreviewService.php diff --git a/Classes/Hooks/PageLayoutView/PluginRenderer.php b/Classes/Hooks/PageLayoutView/PluginRenderer.php index 3ed7b69..65f7456 100644 --- a/Classes/Hooks/PageLayoutView/PluginRenderer.php +++ b/Classes/Hooks/PageLayoutView/PluginRenderer.php @@ -20,6 +20,7 @@ namespace SGalinski\SgYoutube\Hooks\PageLayoutView; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use SGalinski\SgYoutube\Preview\PreviewService; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\View\PageLayoutView; use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface; @@ -35,6 +36,13 @@ use TYPO3\CMS\Fluid\View\StandaloneView; * @deprecated All of this class will be removed when TYPO3 10 support is dropped */ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { + + protected PreviewService $previewService; + + public function init() { + $this->previewService = GeneralUtility::makeInstance(PreviewService::class); + } + /** * Preprocesses the preview rendering of a content element of type "sg_youtube" * @@ -54,6 +62,7 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { &$itemContent, array &$row ): void { + $this->init(); trigger_error( 'Using the old style of rendering backend previews is deprecated and will not longer work when TYPO3 10' . ' support is dropped! Please switch to using the Fluid Based Page Module instead!', @@ -64,33 +73,7 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { $this->adaptPluginHeaderContent($headerContent, $row); - $view = GeneralUtility::makeInstance(StandaloneView::class); - $view->setPartialRootPaths(['EXT:sg_youtube/Resources/Private/Partials/Backend']); - $view->setTemplateRootPaths(['EXT:sg_youtube/Resources/Private/Templates/Youtube']); - $view->setTemplate('Backend.html'); - $view->assign('uid', $row['uid']); - - // Get available plugin settings and their values from flexform - $pluginConfiguration = GeneralUtility::xml2array( - $row['pi_flexform'], - 'T3DataStructure' - )['data']['sDEF']['lDEF']; - - $templateData = [ - 'youtubeId' => $pluginConfiguration['settings.id']['vDEF'], - 'maxResults' => $pluginConfiguration['settings.maxResults']['vDEF'], - 'showTitle' => (int) ($pluginConfiguration['settings.showTitle']['vDEF'] ?? 1), - 'showDescription' => (int) ($pluginConfiguration['settings.showDescription']['vDEF'] ?? 1), - 'disableLightbox' => $pluginConfiguration['settings.disableLightbox']['vDEF'], - 'disableLightboxMobile' => $pluginConfiguration['settings.disableLightboxMobile']['vDEF'], - 'aspectRatio' => $pluginConfiguration['settings.aspectRatio']['vDEF'], - 'thumbnailType' => $pluginConfiguration['settings.thumbnailType']['vDEF'], - 'thumbnailImagesCount' => $pluginConfiguration['settings.thumbnailImages']['vDEF'], - 'showApiResult' => $pluginConfiguration['settings.showApiResult']['vDEF'], - ]; - - $view->assign('data', $templateData); - + $view = $this->previewService->getPluginPreview($row); $itemContent .= $view->render(); } } diff --git a/Classes/Preview/PreviewRenderer.php b/Classes/Preview/PreviewRenderer.php index 1c27be0..73e7b16 100644 --- a/Classes/Preview/PreviewRenderer.php +++ b/Classes/Preview/PreviewRenderer.php @@ -33,8 +33,11 @@ class PreviewRenderer implements PreviewRendererInterface { */ protected LanguageService $languageService; - public function __construct(LanguageService $languageService) { + protected PreviewService $previewService; + + public function __construct(LanguageService $languageService, PreviewService $previewService) { $this->languageService = $languageService; + $this->previewService = $previewService; } /** @@ -63,32 +66,7 @@ class PreviewRenderer implements PreviewRendererInterface { * @return string */ public function renderPageModulePreviewContent(GridColumnItem $item): string { - $view = GeneralUtility::makeInstance(StandaloneView::class); - $view->setPartialRootPaths(['EXT:sg_youtube/Resources/Private/Partials/Backend']); - $view->setTemplateRootPaths(['EXT:sg_youtube/Resources/Private/Templates/Youtube']); - $view->setTemplate('Backend.html'); - $view->assign('uid', $item->getRecord()['uid']); - - // Get available plugin settings and their values from flexform - $pluginConfiguration = GeneralUtility::xml2array( - $item->getRecord()['pi_flexform'], - 'T3DataStructure' - )['data']['sDEF']['lDEF']; - - $templateData = [ - 'youtubeId' => $pluginConfiguration['settings.id']['vDEF'], - 'maxResults' => $pluginConfiguration['settings.maxResults']['vDEF'], - 'showTitle' => (int) ($pluginConfiguration['settings.showTitle']['vDEF'] ?? 1), - 'showDescription' => (int) ($pluginConfiguration['settings.showDescription']['vDEF'] ?? 1), - 'disableLightbox' => $pluginConfiguration['settings.disableLightbox']['vDEF'], - 'disableLightboxMobile' => $pluginConfiguration['settings.disableLightboxMobile']['vDEF'], - 'aspectRatio' => $pluginConfiguration['settings.aspectRatio']['vDEF'], - 'thumbnailType' => $pluginConfiguration['settings.thumbnailType']['vDEF'], - 'thumbnailImagesCount' => $pluginConfiguration['settings.thumbnailImages']['vDEF'], - 'showApiResult' => $pluginConfiguration['settings.showApiResult']['vDEF'], - ]; - - $view->assign('data', $templateData); + $view = $this->previewService->getPluginPreview($item->getRecord()); return $view->render(); } diff --git a/Classes/Preview/PreviewService.php b/Classes/Preview/PreviewService.php new file mode 100644 index 0000000..efcd955 --- /dev/null +++ b/Classes/Preview/PreviewService.php @@ -0,0 +1,86 @@ +setPartialRootPaths(['EXT:sg_youtube/Resources/Private/Partials/Backend']); + $view->setTemplateRootPaths(['EXT:sg_youtube/Resources/Private/Templates/Youtube']); + $view->setTemplate('Backend.html'); + $view->assign('uid', $row['uid']); + + // Get available plugin settings and their values from flexform + $pluginConfiguration = GeneralUtility::xml2array( + $row['pi_flexform'], + 'T3DataStructure' + )['data']['sDEF']['lDEF']; + + $templateData = [ + 'youtubeId' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.id'), + 'maxResults' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.maxResults'), + 'showTitle' => (int) ($this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.showTitle') ?? 1), + 'showDescription' => (int) ($this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.showDescription') ?? 1), + 'disableLightbox' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.disableLightbox'), + 'disableLightboxMobile' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.disableLightboxMobile'), + 'aspectRatio' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.aspectRatio'), + 'thumbnailType' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.thumbnailType'), + 'thumbnailImagesCount' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.thumbnailImages'), + 'showApiResult' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.showApiResult'), + ]; + + $view->assign('data', $templateData); + return $view; + } + + /** + * @param array $conf + * @param string $key + * @param string $returnType + * @return array|mixed|string + */ + private function passVDefOnKeyToTemplate(array $conf, string $key, string $returnType = '') { + if(isset($conf[$key])) { + return $conf[$key]['vDEF']; + } + + // check if we got a possible returntype: + if($returnType === self::RETURNTYPE_ARR) { + return []; + } + + return ''; + } +} -- GitLab From e6ef302fef6b03392b2648264c6efe6e3980edb3 Mon Sep 17 00:00:00 2001 From: Matthias Adrowski Date: Mon, 14 Feb 2022 17:34:53 +0100 Subject: [PATCH 16/20] [TASK] Adopt version dependencies --- UPGRADE.md | 1 + composer.json | 5 +---- ext_emconf.php | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index b669916..e50e081 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,6 +1,7 @@ ## Version 5 - `youtubeLightbox.js` (deprecated since 4.4.0) using magnific-popup and jQuery removed in favor of `sgYoutubeLightbox.js` (vanilla JS). - Extension `project_theme_lightbox` required starting with version 5.0.0. +- Dropped TYPO3 9 Support ## Version 4.4 ```project_theme_lightbox``` integration - The magnific popup integration is deprecated and will be removed in later versions. diff --git a/composer.json b/composer.json index 5d90cf5..8a0b5d7 100644 --- a/composer.json +++ b/composer.json @@ -7,10 +7,7 @@ "version": "5.0.0-dev", "require": { "typo3/cms-core": "^10.4.0 || ^11.5.0", - "sgalinski/project-theme-lightbox": "^1.0.0" - }, - "require-dev": { - "roave/security-advisories": "dev-master" + "sgalinski/project-theme-lightbox": "^2.0.0" }, "replace": { "sgalinski/sg_youtube": "self.version" diff --git a/ext_emconf.php b/ext_emconf.php index 98d8929..5c32d7d 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -40,7 +40,7 @@ $EM_CONF['sg_youtube'] = [ 'constraints' => [ 'depends' => [ 'typo3' => '10.4.0-11.5.99', - 'project_theme_lightbox' => '^1.0.0', + 'project_theme_lightbox' => '1.0.0-2.9.99', ], 'conflicts' => [], 'suggests' => [], -- GitLab From 3190d8abf117ff9dc367b22ca6f2b57d6dcecc7d Mon Sep 17 00:00:00 2001 From: Matthias Adrowski Date: Tue, 15 Mar 2022 15:26:30 +0100 Subject: [PATCH 17/20] [TASK] Update TYPO3 Constant + guards --- Configuration/TCA/Overrides/sys_template.php | 2 +- Configuration/TCA/Overrides/tt_content.php | 2 +- ext_localconf.php | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php index 2940744..ab9038a 100644 --- a/Configuration/TCA/Overrides/sys_template.php +++ b/Configuration/TCA/Overrides/sys_template.php @@ -1,5 +1,5 @@ Date: Wed, 22 Jun 2022 08:17:32 +0200 Subject: [PATCH 18/20] [TASK] Update UPGRADE.md --- UPGRADE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/UPGRADE.md b/UPGRADE.md index e50e081..ac1134c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,6 +2,7 @@ - `youtubeLightbox.js` (deprecated since 4.4.0) using magnific-popup and jQuery removed in favor of `sgYoutubeLightbox.js` (vanilla JS). - Extension `project_theme_lightbox` required starting with version 5.0.0. - Dropped TYPO3 9 Support +- Dropped php 7.3 Support ## Version 4.4 ```project_theme_lightbox``` integration - The magnific popup integration is deprecated and will be removed in later versions. -- GitLab From e5160a5ea5e0a701d914589c98f34551cc64cca3 Mon Sep 17 00:00:00 2001 From: Matthias Adrowski Date: Wed, 29 Jun 2022 12:04:31 +0200 Subject: [PATCH 19/20] [TASK] ECS --- Classes/Hooks/PageLayoutView/PluginRenderer.php | 1 - Classes/Preview/PreviewService.php | 5 ++--- Configuration/TCA/Overrides/sys_template.php | 1 + Configuration/TCA/Overrides/tt_content.php | 1 + 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Classes/Hooks/PageLayoutView/PluginRenderer.php b/Classes/Hooks/PageLayoutView/PluginRenderer.php index 65f7456..6780e18 100644 --- a/Classes/Hooks/PageLayoutView/PluginRenderer.php +++ b/Classes/Hooks/PageLayoutView/PluginRenderer.php @@ -36,7 +36,6 @@ use TYPO3\CMS\Fluid\View\StandaloneView; * @deprecated All of this class will be removed when TYPO3 10 support is dropped */ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { - protected PreviewService $previewService; public function init() { diff --git a/Classes/Preview/PreviewService.php b/Classes/Preview/PreviewService.php index efcd955..1d88d9f 100644 --- a/Classes/Preview/PreviewService.php +++ b/Classes/Preview/PreviewService.php @@ -26,7 +26,6 @@ use TYPO3\CMS\Fluid\View\StandaloneView; * PreviewService, to get Views while we have to duplicate previewCode */ class PreviewService { - public const RETURNTYPE_ARR = 'array'; /** @@ -72,12 +71,12 @@ class PreviewService { * @return array|mixed|string */ private function passVDefOnKeyToTemplate(array $conf, string $key, string $returnType = '') { - if(isset($conf[$key])) { + if (isset($conf[$key])) { return $conf[$key]['vDEF']; } // check if we got a possible returntype: - if($returnType === self::RETURNTYPE_ARR) { + if ($returnType === self::RETURNTYPE_ARR) { return []; } diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php index ab9038a..3749ff0 100644 --- a/Configuration/TCA/Overrides/sys_template.php +++ b/Configuration/TCA/Overrides/sys_template.php @@ -1,4 +1,5 @@ Date: Fri, 1 Jul 2022 14:39:03 +0200 Subject: [PATCH 20/20] [TASK] Update requirements --- README.md | 2 +- ext_emconf.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d28075..fcedb83 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Repository: https://gitlab.sgalinski.de/typo3/sg_youtube Please report bugs here: https://gitlab.sgalinski.de/typo3/sg_youtube -TYPO3 version: >9.5 +TYPO3 version: >10.4 ## Installation / Integration diff --git a/ext_emconf.php b/ext_emconf.php index 4ce7419..d89aa14 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -41,6 +41,7 @@ $EM_CONF['sg_youtube'] = [ 'depends' => [ 'typo3' => '10.4.0-11.5.99', 'project_theme_lightbox' => '1.0.0-2.9.99', + 'php' => '7.4.0-8.1.99', ], 'conflicts' => [], 'suggests' => [], -- GitLab