You are here

function video_block in Video 5

Same name and namespace in other branches
  1. 6 video.module \video_block()
  2. 6.2 video.module \video_block()

Hook block. Does all the interaction with the drupal block system. Uses video_block_list() for DB queries.

Parameters

$op: string type of block

$delta: integer 0 for latest, 1 for played+downloaded, 2 for most played, 3 for most downloaded.

$edit: array holds the data submitted by the configure forms.

Return value

array

File

./video.module, line 879
Display video in Quicktime MOV, Realmedia RM, Flash FLV & SWF, or Windows Media WMV formats.

Code

function video_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks[0]['info'] = t('Latest videos');
    $blocks[1]['info'] = t('Top videos');
    $blocks[2]['info'] = t('Most played videos');
    $blocks[3]['info'] = t('Most downloaded');
    $blocks[4]['info'] = t('Random video');
    return $blocks;
  }
  else {
    if ($op == 'view') {
      switch ($delta) {
        case 0:
          return array(
            'subject' => variable_get('video_block_title_0', t('Latest videos')),
            'content' => video_block_list($delta),
          );
        case 1:
          return array(
            'subject' => variable_get('video_block_title_1', t('Top videos')),
            'content' => video_block_list($delta),
          );
        case 2:
          return array(
            'subject' => variable_get('video_block_title_2', t('Most played videos')),
            'content' => video_block_list($delta),
          );
        case 3:
          return array(
            'subject' => variable_get('video_block_title_3', t('Most downloaded')),
            'content' => video_block_list($delta),
          );
        case 4:
          return array(
            'subject' => variable_get('video_block_title_4', t('Random video')),
            'content' => video_block_list($delta),
          );
      }
    }
    else {
      if ($op == 'configure') {
        switch ($delta) {

          //Get the default title of the block incase the variable is not set yet.
          case 0:
            $default_title = t('Latest videos');
            break;
          case 1:
            $default_title = t('Top videos');
            break;
          case 2:
            $default_title = t('Most played videos');
            break;
          case 3:
            $default_title = t('Most downloaded');
            break;
          case 4:
            $default_title = t('Random video');
        }
        $form['video_block_title'] = array(
          '#type' => 'textfield',
          '#title' => t('Block display title'),
          '#default_value' => variable_get("video_block_title_{$delta}", $default_title),
        );
        $form['video_block_limit'] = array(
          '#type' => 'select',
          '#title' => t('Number of videos to list in block'),
          '#default_value' => variable_get("video_block_limit_{$delta}", 10),
          '#options' => drupal_map_assoc(array(
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12,
            13,
            14,
            15,
          )),
        );
        return $form;
      }
      else {
        if ($op == 'save') {
          variable_set("video_block_title_{$delta}", $edit['video_block_title']);
          variable_set("video_block_limit_{$delta}", $edit['video_block_limit']);
        }
      }
    }
  }
}