Skip to content
Snippets Groups Projects
Commit 8ec8bc04 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

[FEATURE] Render videos like requested from Vimeo, Always show API debug if...

[FEATURE] Render videos like requested from Vimeo, Always show API debug if wanted, Add missing allow rules to the iframe
parent 6638560e
No related branches found
No related tags found
No related merge requests found
<?php <?php
namespace SGalinski\SgVimeo\Controller;
/*************************************************************** /***************************************************************
* Copyright notice * Copyright notice
* (c) sgalinski Internet Services (https://www.sgalinski.de) * (c) sgalinski Internet Services (https://www.sgalinski.de)
...@@ -20,7 +18,8 @@ namespace SGalinski\SgVimeo\Controller; ...@@ -20,7 +18,8 @@ namespace SGalinski\SgVimeo\Controller;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use http\Exception\RuntimeException; namespace SGalinski\SgVimeo\Controller;
use SGalinski\SgVimeo\Service\VimeoService; use SGalinski\SgVimeo\Service\VimeoService;
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection; use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
use TYPO3\CMS\Core\Resource\FileReference; use TYPO3\CMS\Core\Resource\FileReference;
...@@ -45,25 +44,16 @@ class VimeoController extends ActionController { ...@@ -45,25 +44,16 @@ class VimeoController extends ActionController {
$clientId = $this->settings['clientId']; $clientId = $this->settings['clientId'];
$clientSecret = $this->settings['clientSecret']; $clientSecret = $this->settings['clientSecret'];
$personalAccessToken = $this->settings['personalAccessToken']; $personalAccessToken = $this->settings['personalAccessToken'];
if (trim($clientId) === '' || trim($clientSecret) === '') { if (trim($clientId) === '' || trim($clientSecret) === '') {
$this->view->assign('error', 'Please configure a client id and a client secret for sg_vimeo.'); $this->view->assign('error', 'Please configure a client id and a client secret for sg_vimeo.');
return; return;
} }
$filterIds = explode(',', $filterIds); $filterIds = GeneralUtility::trimExplode(',', $filterIds);
foreach ($filterIds as &$filterId) {
$filterId = trim($filterId, " ");
}
$maxResultsWithFilters = (string) ($maxResults + count($filterIds)); $maxResultsWithFilters = (string) ($maxResults + count($filterIds));
/** @var VimeoService $vimeoService */
$vimeoService = GeneralUtility::makeInstance( $vimeoService = GeneralUtility::makeInstance(
VimeoService::class, VimeoService::class, $clientId, $clientSecret, $personalAccessToken
$clientId,
$clientSecret,
$personalAccessToken
); );
try { try {
$response = $vimeoService->getVimeoData($id, $maxResultsWithFilters); $response = $vimeoService->getVimeoData($id, $maxResultsWithFilters);
...@@ -84,7 +74,6 @@ class VimeoController extends ActionController { ...@@ -84,7 +74,6 @@ class VimeoController extends ActionController {
// Fix the array indexes from previous filtering // Fix the array indexes from previous filtering
$response['items'] = array_values($response['items']); $response['items'] = array_values($response['items']);
while (count($response['items']) > $maxResults) { while (count($response['items']) > $maxResults) {
array_pop($response['items']); array_pop($response['items']);
} }
...@@ -99,21 +88,20 @@ class VimeoController extends ActionController { ...@@ -99,21 +88,20 @@ class VimeoController extends ActionController {
if (!((int) $endOfLink === $item['videoId'])) { if (!((int) $endOfLink === $item['videoId'])) {
$item['link'] = strstr($item['link'], '.com/', TRUE) . '.com/' . $item['videoId']; $item['link'] = strstr($item['link'], '.com/', TRUE) . '.com/' . $item['videoId'];
} }
if (isset($item['embed']['html'])) {
$embedLink = [];
preg_match('/src="([^"]+)"/is', $item['embed']['html'], $embedLink);
$item['embedLink'] = html_entity_decode($embedLink[1]);
}
} }
unset($item); unset($item);
} }
$showApiResult = (int) ($this->settings['showApiResult'] ?? 1);
$context = \TYPO3\CMS\Core\Core\Environment::getContext();
// disable API debug output in production context
if ($context->isProduction()) {
$showApiResult = 0;
}
$this->view->assignMultiple( $this->view->assignMultiple(
[ [
'response' => $response, 'response' => $response,
'showApiResult' => $showApiResult, 'showApiResult' => (int) ($this->settings['showApiResult'] ?? 1),
'showTitle' => (int) ($this->settings['showTitle'] ?? 1), 'showTitle' => (int) ($this->settings['showTitle'] ?? 1),
'showDescription' => (int) ($this->settings['showDescription'] ?? 1), 'showDescription' => (int) ($this->settings['showDescription'] ?? 1),
] ]
......
...@@ -124,7 +124,7 @@ class VimeoService implements LoggerAwareInterface { ...@@ -124,7 +124,7 @@ class VimeoService implements LoggerAwareInterface {
$response['items'] = $this->addVideoIdsToResponse($this->getChannelVideos($channelId)); $response['items'] = $this->addVideoIdsToResponse($this->getChannelVideos($channelId));
$response['kind'] = 'channel'; $response['kind'] = 'channel';
} else { } else {
$response['items'] = $this->addVideoIdsToResponse($this->getVideo($vimeoId)); $response['items'] = $this->addVideoIdsToResponse($this->getVideo((int) $vimeoId));
$response['kind'] = 'video'; $response['kind'] = 'video';
} }
...@@ -227,10 +227,10 @@ class VimeoService implements LoggerAwareInterface { ...@@ -227,10 +227,10 @@ class VimeoService implements LoggerAwareInterface {
* Returns a single video for the given $videoId * Returns a single video for the given $videoId
* *
* @see https://developer.vimeo.com/api/reference/videos#get_video * @see https://developer.vimeo.com/api/reference/videos#get_video
* @param string $videoId * @param int $videoId
* @return array|null * @return array|null
*/ */
public function getVideo(string $videoId): ?array { public function getVideo(int $videoId): ?array {
// use field filtering, to save on quota, see: https://developer.vimeo.com/guidelines/rate-limiting // use field filtering, to save on quota, see: https://developer.vimeo.com/guidelines/rate-limiting
$fieldsToSelect = 'uri,name,description,link,embed,pictures,release_time,width,height'; $fieldsToSelect = 'uri,name,description,link,embed,pictures,release_time,width,height';
try { try {
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
<f:variable name="feedCount" value="{response.items -> f:count()}"/> <f:variable name="feedCount" value="{response.items -> f:count()}"/>
<f:comment><!--Handle the container classes--></f:comment> <f:comment><!--Handle the container classes--></f:comment>
<f:variable name="classes"> <f:variable name="classes">
<f:if condition="{feedCount} > 4"> <f:if condition="{feedCount} > 4">
...@@ -116,7 +115,8 @@ ...@@ -116,7 +115,8 @@
<f:render section="vimeoItem" arguments="{ <f:render section="vimeoItem" arguments="{
feedItem: feedItem, feedItem: feedItem,
titleChars: 100, titleChars: 100,
descChars: \"{f:if(condition: '{feedCount} < 3', then: '300', else: '90')}\"}" /> descChars: '{f:if(condition: \'{feedCount} < 3\', then: \'300\', else: \'90\')}'
}" />
</li> </li>
</f:if> </f:if>
</f:for> </f:for>
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
<f:section name="vimeoItem"> <f:section name="vimeoItem">
<div class="sg-video__item"> <div class="sg-video__item">
<a class="sg-video__image-container sg-vimeo-item" href="{feedItem.link}" target="_blank" <a class="sg-video__image-container sg-vimeo-item" href="{f:if(condition: '{feedItem.embedLink}', then: '{feedItem.embedLink}', else: '{feedItem.link}')}" target="_blank"
data-disable-lightbox="{settings.disableLightbox}" data-disable-lightbox="{settings.disableLightbox}"
data-disable-lightbox-mobile="{settings.disableLightboxMobile}"> data-disable-lightbox-mobile="{settings.disableLightboxMobile}">
<f:if condition="{feedItem.thumbnail}"> <f:if condition="{feedItem.thumbnail}">
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
<f:if condition="{feedItem.pictures.base_link}"> <f:if condition="{feedItem.pictures.base_link}">
<img class="sg-video__image" src="{feedItem.pictures.base_link}_{feedItem.width}x{feedItem.height}?r=pad" alt="{item.name}" width="{feedItem.width}" height="{feedItem.height}" loading="lazy"/> <img class="sg-video__image" src="{feedItem.pictures.base_link}_{feedItem.width}x{feedItem.height}?r=pad" alt="{item.name}" width="{feedItem.width}" height="{feedItem.height}" loading="lazy"/>
</f:if> </f:if>
<f:comment> <f:comment><!--
<f:if condition="{feedItem.pictures.sizes}"> <f:if condition="{feedItem.pictures.sizes}">
<f:for each="{feedItem.pictures.sizes}" as="picture" iteration="iterator"> <f:for each="{feedItem.pictures.sizes}" as="picture" iteration="iterator">
<f:if condition="{iterator.isLast}"> <f:if condition="{iterator.isLast}">
...@@ -144,7 +144,7 @@ ...@@ -144,7 +144,7 @@
</f:if> </f:if>
</f:for> </f:for>
</f:if> </f:if>
</f:comment> --></f:comment>
</f:else> </f:else>
</f:if> </f:if>
</a> </a>
......
...@@ -39,23 +39,22 @@ export default class SgVimeoLightbox { ...@@ -39,23 +39,22 @@ export default class SgVimeoLightbox {
const item = event.currentTarget; const item = event.currentTarget;
item.classList.add('no-lightbox'); item.classList.add('no-lightbox');
const videoId = this.getVideoIdFromUrl(item.href);
const videoImage = item.querySelector('.sg-video__image'); const videoImage = item.querySelector('.sg-video__image');
const height = videoImage.offsetHeight; const height = videoImage.offsetHeight;
const width = videoImage.offsetWidth; const width = videoImage.offsetWidth;
const iframe = document.createElement('iframe'); const iframe = document.createElement('iframe');
if (item.href.indexOf('?') > 0) {
iframe.src = item.href + '&dnt=1&autoplay=1';
} else {
iframe.src = item.href + '?dnt=1&autoplay=1';
}
iframe.width = width; iframe.width = width;
iframe.height = height; iframe.height = height;
iframe.style.border = 'none'; iframe.style.border = 'none';
iframe.src = `https://player.vimeo.com/video/${videoId}?dnt=1&autoplay=1`;
iframe.allowFullscreen = true; iframe.allowFullscreen = true;
iframe.allow = 'autoplay; fullscreen; picture-in-picture';
item.replaceChild(iframe, videoImage); item.replaceChild(iframe, videoImage);
} }
getVideoIdFromUrl(url) {
const splitUrl = url.split('/');
return splitUrl[splitUrl.length - 1];
}
} }
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