Source of file YouTube.php
Size: 2,898 Bytes - Last Modified: 2017-06-29T01:32:41+00:00
/var/www/docs.ssmods.com/process/src/code/core/YouTube.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 | <?php class YouTubeRequest extends SocialFeedRequest { protected function url() { $url = $this->connectionData['url'] . '&playlistId=' . $this->connectionData['playlistId'] . '&key=' . $this->connectionData['key']; return $url; } } class YouTubeFeed extends SocialFeed { const TYPE = 'youtube'; protected function getType() { return self::TYPE; } protected function createRequest($connectionData) { return new YouTubeRequest($connectionData); } protected function createPost($type, $sourceData) { return new YouTubePost($type, $sourceData); } protected function getPostsFromResponse($response) { $feedData = json_decode($response, true); if (isset($feedData['items']) && (!empty($feedData['items'])) ) { return $feedData['items']; } else { return array(); } } } class YouTubePost extends SocialFeedPost { protected function setID() { $this->postID = $this->sourceData['id']; } protected function setDate() { $sourceData = $this->sourceData; $date_str = substr( str_replace('T', ' ', $sourceData['snippet']["publishedAt"]), 0,19 ); //$this->postDate = DateTime::createFromFormat('D M d H:i:s ***** Y', $date_str); $this->postDate = DateTime::createFromFormat('Y-m-d H:i:s', $date_str); } protected function setValidity() { $post = $this->sourceData; $valid = true; if (empty($post)) { $valid = false; } $this->valid = $valid; } public function data() { $sourceData = $this->sourceData; $videoId = $sourceData['snippet']['resourceId']['videoId']; $link = 'https://www.youtube.com/watch?v=' . $videoId; $post = array( 'postType' => $this->type ,'postLink' => $link ,'date' => $this->postDate->format('Y-m-d H:m:s') ,'dateToShow' => $this->postDate->format('h:i:s A - j M Y') ,'title' => $sourceData['snippet']['title'] ,'description' => $sourceData['snippet']['description'] ,'picture' => $sourceData['snippet']['thumbnails']['medium']['url'] //320 x 180 ,'picture_default' => $sourceData['snippet']['thumbnails']['default']['url'] //120 x 90 ,'picture_medium' => $sourceData['snippet']['thumbnails']['medium']['url'] //320 x 180 ,'picture_high' => $sourceData['snippet']['thumbnails']['high']['url'] // 480 x 360 ,'picture_standard' => $sourceData['snippet']['thumbnails']['standard']['url'] // 640 x 480 ,'picture_maxres' => $sourceData['snippet']['thumbnails']['maxres']['url'] // 1280 x 720 ,'video_id' => $videoId ,'postID' => $this->postID() ); return $post; } } |