function youtubechannel_getview in YoutubeChannel 6
Same name and namespace in other branches
- 7.2 youtubechannel.module \youtubechannel_getview()
- 7 youtubechannel.module \youtubechannel_getview()
Function that build the Youtube videos as a Channel.
1 call to youtubechannel_getview()
- youtubechannel_block in ./youtubechannel.module 
- Implements hook_block().
File
- ./youtubechannel.module, line 78 
- module file for youtubechannel.
Code
function youtubechannel_getview() {
  $youtube_user = variable_get('youtubechannel_user', NULL);
  $max_results = variable_get('youtubechannel_video_limit', 5);
  $theme = variable_get('youtubechannel_theme', 'simple');
  drupal_add_css(drupal_get_path('module', 'youtubechannel') . '/themes/' . $theme . '/youtubechannel.css');
  drupal_add_js(drupal_get_path('module', 'youtubechannel') . '/js/youtubechannel.js', 'module', 'header');
  // Getting the video list.
  $path = "http://gdata.youtube.com/feeds/api/users/{$youtube_user}/uploads?max-results={$max_results}";
  $xmlfile = drupal_http_request($path);
  if ($xmlfile->code == 200) {
    $youtube_videos = simplexml_load_string($xmlfile->data);
    (array) $videos;
    if ($youtube_videos->entry) {
      foreach ($youtube_videos->entry as $key => $value) {
        if (preg_match("/videos\\/(.*)/", (string) $value->id, $match)) {
          $youtube_id = $match[1];
          $title = (string) $value->title;
          $thumb = theme('image', "http://i4.ytimg.com/vi/{$youtube_id}/default.jpg", $title, $title, NULL, FALSE);
          $videos[$youtube_id] = array(
            'thumb' => $thumb,
            'title' => $title,
          );
        }
      }
      $vars['width'] = check_plain(variable_get('youtubechannel_video_width', 200));
      $vars['height'] = check_plain(variable_get('youtubechannel_video_height', 150));
    }
    $vars['content'] = $videos;
    $vars['theme'] = $theme;
    return theme('youtubechannel_videos_tpl', $vars);
  }
  return t("Please configure this section in the !link", array(
    '!link' => l(t('admin page'), 'admin/settings/youtubechannel'),
  ));
}