You are here

function _brightcove_upload_form_callback in Brightcove Video Connect 7.4

Same name and namespace in other branches
  1. 7.7 brightcove.module \_brightcove_upload_form_callback()
  2. 7.3 brightcove.module \_brightcove_upload_form_callback()
  3. 7.5 brightcove.module \_brightcove_upload_form_callback()
  4. 7.6 brightcove.module \_brightcove_upload_form_callback()

Upload the submitted video.

_state

Parameters

$form:

Return value

bool|StdClass

2 calls to _brightcove_upload_form_callback()
ajax_brightcove_media_upload_callback in brightcove_media/brightcove_media.module
Ajax callback for upload form
ajax_upload_video_dialog_close_callback in brightcove_field/brightcove_field.module

File

./brightcove.module, line 1034
Brightcove module is an integration layer between any modules using Brightcove API. It makes all necessary checks for the API and makes settings available to the user.

Code

function _brightcove_upload_form_callback(&$form, $form_state) {
  $limits['extensions'] = '3g2 3gp asf avi dv flv f4v m4v mov mp4 mpeg mpg mts m2ts qt wmv';
  $validators = array(
    'file_validate_extensions' => array(
      $limits['extensions'],
    ),
  );
  $file = file_save_upload('file_upload', $validators, drupal_realpath(file_default_scheme() . ':/'));
  if (!$file) {
    drupal_set_message(t('Only Video files are allowed here.'), 'error');
    return $form;
  }
  if ($file->filesize <= 0) {

    // Some uploaded files had zero size, that's an error.
    drupal_set_message(t('Uploaded file not found. Are you sure that you uploaded an existing file?'), 'error');
    return $form;
  }
  if (form_get_errors()) {
    return $form;
  }
  $meta = array(
    'name' => $form_state['values']['title'],
    'shortDescription' => $form_state['values']['short'],
    'longDescription' => $form_state['values']['long'],
    'linkText' => $form_state['values']['linktext'],
    'linkURL' => $form_state['values']['linkurl'],
    'economics' => $form_state['values']['economics'],
    'referenceId' => brightcove_generate_reference(),
  );
  if (!empty($form_state['values']['tags'])) {
    $meta['tags'] = explode(',', $form_state['values']['tags']);
  }
  if ($custom_fields = variable_get('brightcove_custom_fields', 0)) {
    $meta['customFields'] = array();
    for ($i = 0; $i < $custom_fields; ++$i) {
      $key = $form["custom_field_{$i}"]['#key'];
      $meta['customFields'][$key] = $form_state['values']["custom_field_{$i}"];
    }
  }
  $id = brightcove_upload_video(drupal_realpath($file->uri), $meta, $form_state['values']['encode_to']);
  if ($id) {

    // If the logo overlay options enabled.
    if ($form_state['values']['logo_enable']) {
      $params = array();

      // Save the image local.
      $image = file_load($form_state['values']['logo_image_upload']['fid']);
      if ($form_state['values']['logo_link']) {
        $params['linkURL'] = $form_state['values']['logo_link'];
      }
      if ($form_state['values']['logo_tooltip']) {
        $params['tooltip'] = $form_state['values']['logo_tooltip'];
      }
      if ($form_state['values']['logo_alignment']) {
        $params['alignment'] = $form_state['values']['logo_alignment'];
      }
      try {
        $response = brightcove_add_logo_overlay($id, $meta['referenceId'], $image, $params);
      } catch (Exception $e) {
        watchdog_exception('brightcove', $e
          ->getMessage());
      }
    }

    // We need to cache it and save it to session.
    // Brightcove Media API doesn't clear its cache when a new
    // video is uploaded, therefore the node save would fail.
    $_SESSION['brightcove']['video'][$id] = $id;

    // Invalidate BC cache
    brightcove_invalidate_cache('brightcove:video:list', TRUE);
    return $id;
  }
  return FALSE;
}