You are here

function video_embed_field_generate_videos in Video Embed Field 7.2

Generates a pseudo random bunch of youtube videos.

Return value

array A bunch of youtube videos.

1 call to video_embed_field_generate_videos()
video_embed_field_retrieve_video in ./video_embed_field.devel_generate.inc
Retrieves a random youtube video info from the bunch.

File

./video_embed_field.devel_generate.inc, line 65
Devel generate support for video_embed_field module.

Code

function video_embed_field_generate_videos() {
  $videos =& drupal_static(__FUNCTION__);
  if (!isset($videos)) {
    $videos = array();

    // Create random video seed.
    $video_id = user_password(2);

    // Using cURL php extension to make the request to youtube API.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    // $feed holds a rss feed xml returned by youtube API.
    $feed = curl_exec($ch);
    curl_close($ch);

    // Using SimpleXML to parse youtube’s feed.
    $xml = simplexml_load_string($feed);
    foreach ($xml->entry as $entry) {
      $videos[] = array(
        'video_url' => $entry
          ->children('media', TRUE)->group->player
          ->attributes()->url,
        'description' => $entry->title,
      );
    }
    if (empty($videos)) {
      video_embed_field_generate_videos();
    }
  }
  return $videos;
}