/** * Init the extbase Context and the configurationBuilder * * @throws \Exception */ protected function init(&$PA) { $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); if (is_array($PA['row']['pi_flexform'])) { // TYPO3 7.5 and newer delivers an array $this->apiServerToken = $PA['row']['pi_flexform']['data']['sDefault']['lDEF']['settings.apiServerToken']['vDEF']; $this->ytChannelId = $PA['row']['pi_flexform']['data']['sDefault']['lDEF']['settings.channelId']['vDEF']; } else { // TYPO3 7.4 or older delivers a string $flexForm = GeneralUtility::xml2array($PA['row']['pi_flexform']); if (is_array($flexForm) && isset($flexForm['data']['sDefault']['lDEF']['settings.apiServerToken']['vDEF'])) { $this->apiServerToken = $flexForm['data']['sDefault']['lDEF']['settings.apiServerToken']['vDEF']; } if (is_array($flexForm) && isset($flexForm['data']['sDefault']['lDEF']['settings.channelId']['vDEF'])) { $this->ytChannelId = $flexForm['data']['sDefault']['lDEF']['settings.channelId']['vDEF']; } } if (!isset($this->apiServerToken)) { error_log("YouTube Playlist - PlaylistSelector: API Server Token could not be accessed."); } if (!isset($this->ytChannelId)) { error_log("YouTube Playlist - PlaylistSelector: YouTube Channel ID could not be accessed."); } $this->youTubeApi = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Powrup\\YoutubePlaylist\\Utility\\YouTubeApi', $this->apiServerToken); // Set Channel ID $this->youTubeApi->setChannelId($this->ytChannelId); }
/** * action show * * @return void */ public function showAction() { $this->youTubeApi->setChannelId($this->youtubeChannelId); // Playlist IDs $playlistIdStr = $this->settings["selectedPlaylists"]; if (empty($playlistIdStr)) { $this->addFlashMessage("You need to select at least one playlist in your plugin configuration.", $messageTitle = 'Ooops, you did it again', $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::WARNING, $storeInSession = TRUE); } else { $playlistIdArr = explode(",", $playlistIdStr); $videoArr = array(); $success = false; if (is_array($playlistIdArr)) { // if explode gives an array means: $playlistIdStr contains selected playlists // iterate through playlists and get videos foreach ($playlistIdArr as $playlistId) { $tmpPlVideos = array(); $tmpPlTitle = ""; /* @var \Google_Service_YouTube_PlaylistListResponse $playList */ $playList = $this->youTubeApi->getPlaylist($playlistId); if (isset($playList) && $playList !== false) { $success = true; $playListItems = $playList->getItems(); if (isset($playListItems) && !empty($playListItems)) { /* @var \Google_Service_YouTube_Playlist $playListItem */ $playListItem = $playListItems[0]; /* @var \Google_Service_YouTube_PlaylistSnippet $playListData */ $playListData = $playListItem->getSnippet(); $tmpPlTitle = $playListData->getTitle(); } /* @var \Google_Service_YouTube_PlaylistItemListResponse) $plVideos */ $plVideosStore = $this->youTubeApi->getPlaylistVideos($playlistId); if (isset($plVideosStore) && $plVideosStore !== false) { $plVideos = $plVideosStore->getItems(); if (isset($plVideos) && !empty($plVideos)) { /* @var \Google_Service_YouTube_Video $plVideo */ foreach ($plVideos as $plVideo) { /* @var \Google_Service_YouTube_VideoStatus $videoStatus */ $videoStatus = $plVideo->getStatus(); $privacyStatus = $videoStatus->getPrivacyStatus(); if ($privacyStatus === "public") { /* @var \Google_Service_YouTube_PlaylistItemSnippet $videoData */ $videoData = $plVideo->getSnippet(); /* @var \Google_Service_YouTube_ThumbnailDetails $thumbnails */ $thumbnails = $videoData->getThumbnails(); /* @var \Google_Service_YouTube_Thumbnail $thumbnail */ $thumbnail = $thumbnails->getMedium(); array_push($tmpPlVideos, array("thumb" => $thumbnail->getUrl(), "title" => $videoData->getTitle(), "description" => $videoData->getDescription(), "id" => $videoData->getResourceId()["videoId"])); } } $videoArr[$playlistId] = ["Title" => $tmpPlTitle, "Videos" => $tmpPlVideos]; } } } else { $this->addFlashMessage("Oops, you probably forgot to enter you channel id and server api token or your selected playlist does not container any videos.", $messageTitle = 'Ooops, you did it again', $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::WARNING, $storeInSession = TRUE); } } } } $this->view->assign("success", $success); $this->view->assign('playlists', $videoArr); }