You are here

function video_add in Video 5

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

Create video submission page. Let the user select the actived video types or display the video form for the selected video type

1 string reference to 'video_add'
video_menu in ./video.module
Implementation of hook_menu().

File

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

Code

function video_add() {
  global $user;
  $edit = isset($_POST['edit']) ? $_POST['edit'] : '';

  // If a video type has been specified, validate its existence.
  $vtypes = video_get_types();
  if (arg(3) && in_array(arg(3), $vtypes)) {

    // is a valid video type
    $type = arg(3);

    // Initialize settings:
    $node = (object) array(
      'uid' => $user->uid,
      'name' => $user->name,
      'type' => 'video',
      'vtype' => $type,
    );
    $output = drupal_get_form('video_node_form', $node);
    drupal_set_title(t('Submit %name video', array(
      '%name' => $type,
    )));
  }
  else {
    if (count($vtypes) == 1) {

      // only one vtype active. redirect the user to the active type form
      // Initialize settings:
      $node = (object) array(
        'uid' => $user->uid,
        'name' => $user->name,
        'type' => 'video',
        'vtype' => $vtypes[0],
      );
      $output = drupal_get_form('video_node_form', $node);
      drupal_set_title(t('Submit %name video', array(
        '%name' => $vtypes[0],
      )));
    }
    else {
      if ($vtype = variable_get('video_default_video_type', 0)) {

        // Initialize settings:
        $node = (object) array(
          'uid' => $user->uid,
          'name' => $user->name,
          'type' => 'video',
          'vtype' => $vtype,
        );
        $output = drupal_get_form('video_node_form', $node);
        drupal_set_title(t('Submit %name video', array(
          '%name' => $vtype,
        )));
      }
      else {
        $output = video_types_page();
      }
    }
  }
  return $output;
}