Ejemplo n.º 1
0
 function getData($number)
 {
     $data = array();
     $a = getNextendYoutube();
     if (!$a) {
         return $data;
     }
     $client = $a[0];
     $youtube = $a[1];
     $playlist = $this->_data->get('youtubeplaylist', '');
     if ($playlist) {
         try {
             $videos = $youtube->playlistItems->listPlaylistItems('id,snippet', array('maxResults' => $number, 'playlistId' => $playlist));
             $i = 0;
             foreach ($videos['items'] as $k => $item) {
                 $data[$i] = array();
                 $data[$i]['video_id'] = $item['snippet']['resourceId']['videoId'];
                 $data[$i]['video_url'] = 'http://www.youtube.com/watch?v=' . $item['snippet']['resourceId']['videoId'];
                 $data[$i]['title'] = $item['snippet']['title'];
                 $data[$i]['description'] = $item['snippet']['description'];
                 $data[$i]['thumbnail_default'] = $item['snippet']['thumbnails']['default']['url'];
                 $data[$i]['thumbnail_medium'] = $item['snippet']['thumbnails']['medium']['url'];
                 $data[$i]['thumbnail_high'] = $item['snippet']['thumbnails']['high']['url'];
                 $data[$i]['channel_title'] = $item['snippet']['channelTitle'];
                 $data[$i]['channel_url'] = 'http://www.youtube.com/user/' . $item['snippet']['channelTitle'];
                 $i++;
             }
         } catch (Google_ServiceException $e) {
             echo sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
         } catch (Google_Exception $e) {
             echo sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
         }
     }
     return $data;
 }
 function fetchElement()
 {
     $this->_xml->addChild('option', 'Please choose')->addAttribute('value', 0);
     ob_start();
     $api = getNextendYoutube();
     $list = array();
     if ($api) {
         $google = $api[0];
         $youtube = $api[1];
         try {
             $playlists = $youtube->playlists->listPlaylists('id,snippet', array('mine' => true));
             foreach ($playlists['items'] as $k => $item) {
                 $list[$item['id']] = $item['snippet']['title'];
             }
         } catch (Google_ServiceException $e) {
             echo sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
         } catch (Google_Exception $e) {
             echo sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
         }
     }
     if ($list) {
         ob_end_clean();
         if (count($list)) {
             foreach ($list as $id => $name) {
                 $this->_xml->addChild('option', htmlentities($name))->addAttribute('value', $id);
             }
         }
     }
     $this->_value = $this->_form->get($this->_name, $this->_default);
     $html = parent::fetchElement();
     if (!$list) {
         $html .= ob_get_clean();
     }
     return $html;
 }
Ejemplo n.º 3
0
 function getData($number)
 {
     $data = array();
     $a = getNextendYoutube();
     if (!$a) {
         return $data;
     }
     $client = $a[0];
     $youtube = $a[1];
     try {
         $searchResponse = $youtube->search->listSearch('id,snippet', array('q' => $this->_data->get('youtubesearch', ''), 'maxResults' => $number, 'type' => 'video', 'videoEmbeddable' => 'true'));
         $i = 0;
         foreach ($searchResponse['items'] as $k => $item) {
             $data[$i] = array();
             $data[$i]['video_id'] = $item['id']['videoId'];
             $data[$i]['video_url'] = 'http://www.youtube.com/watch?v=' . $item['id']['videoId'];
             $data[$i]['title'] = $item['snippet']['title'];
             $data[$i]['description'] = $item['snippet']['description'];
             $data[$i]['thumbnail_default'] = $item['snippet']['thumbnails']['default']['url'];
             $data[$i]['thumbnail_medium'] = $item['snippet']['thumbnails']['medium']['url'];
             $data[$i]['thumbnail_high'] = $item['snippet']['thumbnails']['high']['url'];
             $data[$i]['channel_title'] = $item['snippet']['channelTitle'];
             $data[$i]['channel_url'] = 'http://www.youtube.com/user/' . $item['snippet']['channelTitle'];
             $i++;
         }
     } catch (Google_ServiceException $e) {
         echo sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
     } catch (Google_Exception $e) {
         echo sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
     }
     return $data;
 }