You are here

function flashnode_node_form_submit in Flash Node 6.2

Same name and namespace in other branches
  1. 6.3 flashnode.module \flashnode_node_form_submit()

Perform some post-processing on submitted form to populate node with data from the uploaded file

File

./flashnode.module, line 822

Code

function flashnode_node_form_submit($form, &$form_state) {

  // Get upload filesize limits
  global $user;
  $limits = _flashnode_file_limits($user);

  // Use file validators to confirm upload size and extensions
  $validators = array(
    'file_validate_size' => array(
      $limits['file_size'],
      $limits['user_size'],
    ),
    'file_validate_extensions' => array(
      $limits['extensions'],
    ),
  );

  // Check if the upload is valid and move to the temporary folder
  if ($file = file_save_upload('flashfile', $validators, file_create_path(variable_get('flashnode_default_path', FLASHNODE_DEFAULT_PATH) . '/temp'))) {

    // Add needed file data to the $form_state['values'] array
    $form_state['values']['flashnode']['filepath'] = $file->filepath;
    $form_state['values']['flashnode']['filename'] = $file->filename;
    $form_state['values']['flashnode']['fid'] = $file->fid;
    $form_state['values']['new_file'] = TRUE;

    // Reset default height so we force defaults to be repopulated in a few moments
    unset($form_state['values']['flashnode']['_height']);

    // If the height and width settings are not available to this user then reset them everytime we get a new file
    // Otherwise the height/width will be locked to the first file that is uploaded
    global $user;
    if (!user_access('use basic options') && $user->uid != 1) {
      unset($form_state['values']['flashnode']['height']);
      unset($form_state['values']['flashnode']['width']);
    }

    // If upload is not swf remind user to set movie size
    if (!preg_match('@swf$@i', $file->filename)) {
      drupal_set_message(t('Remember you might have to set the movie size for flv or mp3 files as flash node cannot always automatically determine the player size!'), 'warning');
    }
  }

  // See if the default height and width need to be populated (previewing an existing node, or a new file)
  if (!$form_state['values']['flashnode']['_height']) {

    // Try to get the file settings for this file, using image_get_info
    $info = image_get_info($form_state['values']['flashnode']['filepath']);
    $form_state['values']['flashnode']['_height'] = $info['height'];
    $form_state['values']['flashnode']['_width'] = $info['width'];
  }

  // If width field is empty then reset it to the default width
  if (empty($form_state['values']['flashnode']['width'])) {
    $form_state['values']['flashnode']['width'] = $form_state['values']['flashnode']['_width'];
    $form_state['rebuild'] = TRUE;
  }

  // If height field is empty then reset it to the default height
  if (empty($form_state['values']['flashnode']['height'])) {
    $form_state['values']['flashnode']['height'] = $form_state['values']['flashnode']['_height'];
    $form_state['rebuild'] = TRUE;
  }
}