You are here

youtubechannel.module in YoutubeChannel 6

module file for youtubechannel.

File

youtubechannel.module
View source
<?php

/**
 * @file
 * module file for youtubechannel.
 */

/**
 * Implements hook_help().
 */
function youtubechannel_help($section) {
  switch ($section) {
    case 'admin/help#youtubechannel':
      return t("Youtube Channel let's you have a complete video list from an specific user inside your site,\n        you only have to configure the dimensions and the username that you'll use to feed the page.");
  }
}

/**
 * Implements hook_menu().
 */
function youtubechannel_menu() {
  $items = array();
  $items['admin/settings/youtubechannel'] = array(
    'title' => 'Youtube Channel',
    'description' => 'Configure the settings to be used for Youtube Channel.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'youtubechannel_settings_form',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'youtubechannel.admin.inc',
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

/**
 * Implements hook_block().
 */
function youtubechannel_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks = array();
    $blocks['youtubechannel'] = array(
      'info' => t('Youtube Channel'),
      'status' => 1,
      'region' => 'left',
    );
    return $blocks;
  }
  elseif ($op == 'view') {
    $block = array();
    switch ($delta) {
      case 0:
        $block['subject'] = t('Youtube Channel');
        $block['content'] = youtubechannel_getview();
        return $block;
    }
  }
}

/**
 * Implements hook_theme().
 */
function youtubechannel_theme() {
  return array(
    'youtubechannel_videos_tpl' => array(
      'arguments' => array(
        'vars' => NULL,
      ),
      'template' => 'youtubechannel_videos',
    ),
  );
}

/**
 * Function that build the Youtube videos as a Channel.
 */
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'),
  ));
}

Functions

Namesort descending Description
youtubechannel_block Implements hook_block().
youtubechannel_getview Function that build the Youtube videos as a Channel.
youtubechannel_help Implements hook_help().
youtubechannel_menu Implements hook_menu().
youtubechannel_theme Implements hook_theme().