'GROUP_ID', default => 'CHANNEL_ID', }; $arParams['CHANNEL_ID'] = TSolution::getFrontParametrValue($paramName.'_'.strtoupper($arParams['VIDEO_SOURCE'])); } if (in_array($arParams['VIDEO_SOURCE'], ['youtube', 'vk'])) { if ($arParams['API_TOKEN'] === 'FROM_THEME') { $arParams['API_TOKEN'] = TSolution::getFrontParametrValue('API_TOKEN_'.strtoupper($arParams['VIDEO_SOURCE'])); } } if ($arParams['VIDEO_SOURCE'] === 'youtube') { if (!$arParams['PLAYLIST_ID'] || $arParams['PLAYLIST_ID'] === 'FROM_THEME') { $arParams['PLAYLIST_ID'] = TSolution::getFrontParametrValue('PLAYLIST_ID_'.strtoupper($arParams['VIDEO_SOURCE'])); } } return $arParams; } public function executeComponent() { if ( $this->startResultCache( $this->arParams['CACHE_TIME'] ) ) { $this->arResult = $this->arResultSet(); if ($this->arResult['error']) { $this->showError($this->arResult['error']['error_msg']); } else { $this->includeComponentTemplate(); } } return $this->arResult; } protected function arResultSet(): array { $obVideo = TSolution\Social\Video\Factory::create($this->arParams['VIDEO_SOURCE'], $this->prepareVideoOptions()); if (is_object($obVideo) && method_exists($obVideo, 'getVideo')) { $result = $obVideo->getVideo(); } else { $result = [ 'error' => [ 'error_msg' => Loc::getMessage('NO_ITEMS_FOUND'), ], ]; } if ($result['error']) { $this->AbortResultCache(); return $result; } $this->setRightLink($obVideo); $arResult = [ 'ITEMS' => $result, ]; return $arResult; } protected function prepareVideoOptions(): array { $options = [ 'channel_id' => $this->arParams['CHANNEL_ID'], 'count' => ($this->arParams['COUNT_ELEMENTS'] ?: $this->arParams['ELEMENTS_ROW']), 'api_token' => '', ]; if ($this->arParams['API_TOKEN']) { $options['api_token'] = $this->arParams['API_TOKEN']; } if ($this->arParams['PLAYLIST_ID']) { $options['playlist_id'] = $this->arParams['PLAYLIST_ID']; } if ($this->arParams['SORT']) { $options['sort'] = $this->arParams['SORT']; } return $options; } protected function setRightLink($obVideo) { if ( !$this->arParams['RIGHT_LINK'] || $this->arParams['RIGHT_LINK'] !== 'FROM_THEME' ) { return; } $this->arParams['RIGHT_LINK'] = $obVideo->getRightLinkBase(); $this->arParams['RIGHT_LINK_EXTERNAL'] = true; } protected function showError(string $error) { if ($GLOBALS['USER']->IsAdmin()) { ?>
Error [getName();?>]: