Skip to content
Snippets Groups Projects
Commit a0effa58 authored by Kevin von Spiczak's avatar Kevin von Spiczak
Browse files

[TASK] clean up/optimizations

parent bd1bbec7
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,10 @@ class VimeoController extends ActionController {
$this->view->assign('error', 'Please configure a client id and a client secret for sg_vimeo.');
return;
}
$vimeoService = GeneralUtility::makeInstance(VimeoService::class, $clientId, $clientSecret, $personalAccessToken);
/** @var VimeoService $vimeoService */
$vimeoService = GeneralUtility::makeInstance(
VimeoService::class, $clientId, $clientSecret, $personalAccessToken
);
$response = $vimeoService->getVimeoData($id, $maxResults, $isPrivate);
$response = $this->mapVimeoApiResponseWithPossibleCustomThumbnails($response);
if ($response === NULL) {
......@@ -70,6 +73,7 @@ class VimeoController extends ActionController {
$item['link'] = strstr($item['link'], '.com/', TRUE) . '.com/' . $item['videoId'];
}
}
unset($item);
}
$showApiResult = (int) ($this->settings['showApiResult'] ?? 1);
......@@ -96,7 +100,7 @@ class VimeoController extends ActionController {
* @return array|null
*/
protected function mapVimeoApiResponseWithPossibleCustomThumbnails(?array $response): ?array {
if ($response === NULL || !is_array($response) || !array_key_exists('items', $response)) {
if (!is_array($response) || !array_key_exists('items', $response)) {
return NULL;
}
......@@ -105,6 +109,7 @@ class VimeoController extends ActionController {
return $response;
}
/** @var FileRepository $fileRepository */
$fileRepository = GeneralUtility::makeInstance(FileRepository::class);
$fileObjects = $fileRepository->findByRelation(
'tt_content', 'tx_sgvimeo_thumbnail_image', $contentElementUid
......@@ -129,6 +134,7 @@ class VimeoController extends ActionController {
$processingInstructions = [
'crop' => $cropArea->isEmpty() ? NULL : $cropArea->makeAbsoluteBasedOnFile($fileObject),
];
/** @var ImageService $imageService */
$imageService = GeneralUtility::makeInstance(ImageService::class);
$processedImage = $imageService->applyProcessingInstructions($fileObject, $processingInstructions);
$response['items'][$index]['thumbnail'] = $imageService->getImageUri($processedImage);
......
......@@ -20,6 +20,7 @@ namespace SGalinski\SgVimeo\Hooks\PageLayoutView;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgComments\Domain\Model\Language;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
......@@ -52,7 +53,7 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
$drawItem = FALSE;
$this->adaptPluginHeaderContent($headerContent, $row);
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setPartialRootPaths(['EXT:sg_vimeo/Resources/Private/Partials/Backend']);
$view->setTemplateRootPaths(['EXT:sg_vimeo/Resources/Private/Templates/Vimeo']);
......@@ -106,6 +107,7 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
* @return string
*/
protected function getPluginNameForHeaderContent(int $pid, string $listType): string {
/** @var LanguageService $languageService */
$languageService = GeneralUtility::makeInstance(LanguageService::class);
$pluginName = $languageService->sL(
......
......@@ -93,6 +93,7 @@ class VimeoService implements LoggerAwareInterface {
*/
public function getVimeoData(string $vimeoId, int $maxResults, bool $isPrivate): ?array {
$this->maxResultsPerPage = $maxResults;
/** @var Registry $registry */
$registry = GeneralUtility::makeInstance(Registry::class);
$currentDay = date('Y-m-d', $GLOBALS['EXEC_TIME']);
$cacheKey = sha1($vimeoId . $maxResults);
......@@ -110,11 +111,11 @@ class VimeoService implements LoggerAwareInterface {
}
if (strpos($vimeoId, 'showcase') === 0) {
$showcaseId = preg_split('/\//', $vimeoId)[1];
$showcaseId = explode("\/", $vimeoId)[1];
$response['items'] = $this->addVideoIdsToResponse($this->getShowcaseVideos((int) $showcaseId));
$response['kind'] = 'showcase';
} else if (strpos($vimeoId, 'channel') === 0) {
$channelId = preg_split('/\//', $vimeoId)[1];
$channelId = explode("\/", $vimeoId)[1];
$response['items'] = $this->addVideoIdsToResponse($this->getChannelVideos($channelId));
$response['kind'] = 'channel';
} else {
......@@ -122,7 +123,6 @@ class VimeoService implements LoggerAwareInterface {
$response['kind'] = 'video';
}
if (!$disableVimeoCache) {
$response['CACHE_DATE'] = $currentDay;
$registry->set('sg_vimeo', $cacheKey, $response);
......@@ -138,7 +138,7 @@ class VimeoService implements LoggerAwareInterface {
* @return array|null
*/
protected function addVideoIdsToResponse(?array $response): ?array {
if ($response === NULL || !is_array($response)) {
if (!is_array($response)) {
return NULL;
}
......@@ -176,7 +176,7 @@ class VimeoService implements LoggerAwareInterface {
* @return array|null
*/
protected function preprocessApiResponse(?array $response): ?array {
if ($response === NULL || !is_array($response)) {
if (!is_array($response)) {
return NULL;
}
......
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