You are here

function _brightcove_upload_form_callback in Brightcove Video Connect 7.5

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.4 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

1 call to _brightcove_upload_form_callback()
ajax_upload_video_dialog_close_callback in brightcove_field/brightcove_field.module

File

./brightcove.module, line 1064
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, 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());
      }
    }

    // Cache video temporary, because Brightcove cache is not cleared promptly, so we
    // might not get the video object for a while.
    $video = (object) $meta;
    $video->id = $id;
    brightcove_cache_set('brightcove:video:' . $id, $video);

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