You are here

function uploadfield_v_video in Video 6.3

Implementation of hook_v_video()

File

types/uploadfield/uploadfield.module, line 479

Code

function uploadfield_v_video($op, &$element) {
  global $user;
  switch ($op) {
    case 'insert':
    case 'update':

      // TODO : need to add validation on just submit scenario
      $field = content_fields($element['#field_name'], $element['#type_name']);

      // auto thumbnailing
      if ($field['widget']['autothumbnail']) {
        $update = NULL;
        $vidfile = $element['#value'];
        $vid = $vidfile['fid'];
        $vid_path = $vidfile['data']['video_thumb'];
        $vid_dir = explode('/', $vid_path);
        $vid_name = $vid_dir[count($vid_dir) - 1];
        $file = new stdClass();
        $file->uid = $user->uid;
        $file->status = FILE_STATUS_PERMANENT;
        $file->filename = $vid_name;
        $file->filepath = $vid_path;
        $file->filemime = file_get_mimetype($vid_name);
        $file->filesize = filesize($vid_path);
        $file->timestamp = time();
        if ($op == 'update') {
          $old_fid = $element['#default_value']['data']['video_thumb_fid'];
          $update = 'fid';
          $file->fid = $old_fid;
        }
        drupal_write_record('files', $file, $update);

        // get fid if and only if insert
        if ($op == 'insert') {
          $file->fid = db_last_insert_id('files', 'fid');
        }

        // add file id to the data
        $element['data']['video_thumb_fid'] = array(
          '#type' => 'value',
          '#value' => $file->fid,
        );
      }

      // auto covnersion
      if ($field['widget']['autoconversion'] && !$element['#value']['data']['bypass_autoconversion']) {
        video_auto_transcode_add_to_queue($element, $op);
      }
      break;
    case 'delete':

      //delete thumbnails
      break;
    case 'thumbs':
      include_once dirname(__FILE__) . '/uploadfield_thumb.inc';

      //create thumbs and display
      video_auto_thumb_process($element);
      break;
    case 'convert':
      include_once dirname(__FILE__) . '/uploadfield_convert.inc';

      //create FLV file

      //      video_auto_transcode_process($element);
      break;
  }
}