Skip to content
Snippets Groups Projects
Commit e703dcf6 authored by Fabian Galinski's avatar Fabian Galinski :pouting_cat:
Browse files

[FEATURE] Allows to set an own youtube thumbnail for each video

parent 0b0cd11f
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,12 @@ namespace SGalinski\SgYoutube\Controller;
use Exception;
use SGalinski\SgYoutube\Service\YoutubeService;
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Service\ImageService;
/**
* The Youtube Controller
......@@ -68,6 +73,7 @@ class YoutubeController extends ActionController {
$jsonArray['items'], $id, $aspectRatio, $thumbnailType, $apiKey
);
$jsonArray['items'] = $this->mapJsonArrayWithPossibleCustomThumbnails($jsonArray['items']);
} catch (Exception $exception) {
return '<div style="color: red;">' . $exception->getMessage() . '</div>';
}
......@@ -82,4 +88,51 @@ class YoutubeController extends ActionController {
return NULL;
}
/**
* Maps the given jsonArray thumbnails with the possible custom ones from the plugin settings.
*
* @param array $jsonArray
* @return array
*/
protected function mapJsonArrayWithPossibleCustomThumbnails(array $jsonArray): array {
$contentElementUid = (int) $this->configurationManager->getContentObject()->data['uid'];
if ($contentElementUid <= 0) {
return $jsonArray;
}
$fileRepository = GeneralUtility::makeInstance(FileRepository::class);
$fileObjects = $fileRepository->findByRelation(
'tt_content', 'tx_sgyoutube_thumbnail_image', $contentElementUid
);
if (count($fileObjects) <= 0) {
return $jsonArray;
}
/**
* @var int $index
* @var FileReference $fileObject
*/
foreach ($fileObjects as $index => $fileObject) {
if (!isset($jsonArray[$index])) {
break;
}
$cropString = '';
if ($fileObject->hasProperty('crop') && $fileObject->getProperty('crop')) {
$cropString = $fileObject->getProperty('crop');
}
$cropVariantCollection = CropVariantCollection::create((string) $cropString);
$cropArea = $cropVariantCollection->getCropArea('default');
$processingInstructions = [
'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($fileObject),
];
$imageService = GeneralUtility::makeInstance(ImageService::class);
$processedImage = $imageService->applyProcessingInstructions($fileObject, $processingInstructions);
$jsonArray[$index]['thumbnail'] = $imageService->getImageUri($processedImage);
}
return $jsonArray;
}
}
......@@ -248,7 +248,13 @@ class YoutubeService {
}
if (!$videoId && isset($videoData['id'])) {
$videoId = trim($videoData['id']['videoId'] ?? $videoData['id']);
$videoId = $videoData['id']['videoId'] ?? $videoData['id'];
// This is a check, because the $videoData['id'] can be a whole sub-channel-id.
if (is_array($videoId)) {
continue;
}
$videoId = trim($videoId);
}
if (!$videoId) {
......
......@@ -25,6 +25,7 @@
</config>
</TCEforms>
</settings.id>
<settings.maxResults>
<TCEforms>
<exclude>0</exclude>
......@@ -42,6 +43,7 @@
</config>
</TCEforms>
</settings.maxResults>
<settings.showApiResult>
<TCEforms>
<exclude>0</exclude>
......@@ -53,6 +55,7 @@
</config>
</TCEforms>
</settings.showApiResult>
<settings.aspectRatio>
<TCEforms>
<label>LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:flexform.aspectRatio</label>
......@@ -72,6 +75,7 @@
</config>
</TCEforms>
</settings.aspectRatio>
<settings.thumbnailType>
<TCEforms>
<label>LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:flexform.thumbnailType</label>
......@@ -107,6 +111,83 @@
</config>
</TCEforms>
</settings.thumbnailType>
<settings.thumbnailImages>
<TCEforms>
<label>LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:flexform.thumbnailImages</label>
<config>
<type>inline</type>
<foreign_table>sys_file_reference</foreign_table>
<foreign_field>uid_foreign</foreign_field>
<foreign_table_field>tablenames</foreign_table_field>
<foreign_label>uid_local</foreign_label>
<foreign_sortby>sorting_foreign</foreign_sortby>
<foreign_selector>uid_local</foreign_selector>
<foreign_selector_fieldTcaOverride type="array">
<config>
<appearance>
<elementBrowserType>file</elementBrowserType>
<elementBrowserAllowed>jpg,png,svg,jpeg,gif</elementBrowserAllowed>
</appearance>
</config>
</foreign_selector_fieldTcaOverride>
<foreign_match_fields type="array">
<fieldname>tx_sgyoutube_thumbnail_image</fieldname>
</foreign_match_fields>
<filter type="array">
<userFunc>TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter->filterInlineChildren</userFunc>
<parameters>
<allowedFileExtensions>jpg,png,svg,jpeg,gif</allowedFileExtensions>
<disallowedFileExtensions></disallowedFileExtensions>
</parameters>
</filter>
<appearance type="array">
<useSortable>1</useSortable>
<headerThumbnail>
<field>uid_local</field>
<height>45m</height>
</headerThumbnail>
<enabledControls>
<info>1</info>
<new>0</new>
<dragdrop>1</dragdrop>
<sort>1</sort>
<hide>1</hide>
<delete>1</delete>
</enabledControls>
</appearance>
<overrideChildTca>
<columns type="array">
<uid_local type="array">
<config type="array">
<appearance type="array">
<elementBrowserType>file</elementBrowserType>
<elementBrowserAllowed>jpg,png,svg,jpeg,gif</elementBrowserAllowed>
</appearance>
</config>
</uid_local>
<crop type="array">
<config type="array">
<cropVariants type="array">
<medium type="array">
<disabled>1</disabled>
</medium>
<small type="array">
<disabled>1</disabled>
</small>
</cropVariants>
</config>
</crop>
</columns>
<types type="array">
<numIndex index="2">
<showitem>--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette</showitem>
</numIndex>
</types>
</overrideChildTca>
</config>
</TCEforms>
</settings.thumbnailImages>
</el>
</ROOT>
</sDEF>
......
......@@ -37,6 +37,10 @@
<source><![CDATA[Show API Result (Debug Output!)]]></source>
<target><![CDATA[Zeige API-Ergebnis an (Debug-Informationen!)]]></target>
</trans-unit>
<trans-unit id="flexform.thumbnailImages" approved="yes">
<source><![CDATA[Custom Thumbnails for the Videos (The first image will be set on the first Youtube Video, then the second image one to the second video and so on...)]]></source>
<target><![CDATA[Benutzerdefinierte Thumbnails für die Videos (Das erste Bild wird auf das erste Youtube-Video gesetzt, dann das zweite Bild auf das zweite Video und so weiter...)]]></target>
</trans-unit>
<trans-unit id="flexform.thumbnailType" approved="yes">
<source><![CDATA[Thumbnail Type (Resolution, Not all options are available always)]]></source>
<target><![CDATA[Thumbnail-Typ (Auflösung, Nicht immer sind alle Optionen vorhanden)]]></target>
......@@ -65,6 +69,10 @@
<source><![CDATA[Standard Resolution]]></source>
<target><![CDATA[Standard-Auflösung]]></target>
</trans-unit>
<trans-unit id="settings" approved="yes">
<source><![CDATA[Settings]]></source>
<target><![CDATA[Einstellungen]]></target>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
</xliff>
......@@ -29,6 +29,9 @@
<trans-unit id="flexform.showApiResult">
<source><![CDATA[Show API Result (Debug Output!)]]></source>
</trans-unit>
<trans-unit id="flexform.thumbnailImages">
<source><![CDATA[Custom Thumbnails for the Videos (The first image will be set on the first Youtube Video, then the second image one to the second video and so on...)]]></source>
</trans-unit>
<trans-unit id="flexform.thumbnailType">
<source><![CDATA[Thumbnail Type (Resolution, Not all options are available always)]]></source>
</trans-unit>
......@@ -50,6 +53,9 @@
<trans-unit id="flexform.thumbnailType.standard">
<source><![CDATA[Standard Resolution]]></source>
</trans-unit>
<trans-unit id="settings">
<source><![CDATA[Settings]]></source>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
</xliff>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment