Commit 95d149db authored by Mike Carper's avatar Mike Carper Committed by Michael Carper
Browse files

Issue #3263238 by mikeytown2: Simplify function calls in hook_init; fix php notice

parent 23e2aa1a
Loading
Loading
Loading
Loading
+37 −36
Changes for auc.module: 37 added lines, 36 removed lines.
Original line number Diff line number Diff line
@@ -13,8 +13,40 @@ function auc_init() {
  if (empty($_FILES)) {
    return;
  }
  module_load_include('inc', 'auc', 'auc.under_hood');

  if (!empty($_FILES['file']['name'])
    && $_FILES['file']['size'] > 16
    && $_FILES['file']['error'] == UPLOAD_ERR_OK
    && is_uploaded_file($_FILES['file']['tmp_name'])
  ) {
    auc_process_wrapper_init($_FILES['file']['name']);
  }
  if (!empty($_FILES['files']['name'])) {
    foreach ($_FILES['files']['name'] as $field_name => $value) {
      // Quick skip here.
      if ($_FILES['files']['size'][$field_name] < 16) {
        continue;
      }
      if ($_FILES['files']['error'][$field_name] != UPLOAD_ERR_OK) {
        continue;
      }
      if (!is_uploaded_file($_FILES['files']['tmp_name'][$field_name])) {
        continue;
      }

      auc_process_wrapper_init($_FILES['files']['name'][$field_name], $field_name);
    }
  }
}

/**
 * Get file extension and conversion process.
 *
 * @param string $file_name

 * @param string $field_name
 */
function auc_process_wrapper_init($file_name, $field_name = '') {
  // Eventually have configuration for this.
  $conversion_lut = array(
    // This will be processed with the imagemagick tool.
@@ -86,47 +118,16 @@ function auc_init() {
    ],
  );

  if (!empty($_FILES['file']['name'])
    && $_FILES['file']['size'] > 16
    && $_FILES['file']['error'] == UPLOAD_ERR_OK
    && is_uploaded_file($_FILES['file']['tmp_name'])
  ) {
    $path_parts = pathinfo($_FILES['file']['name']);

    // Lowercase for file extension.
    if (!empty($path_parts['extension']) && is_string($path_parts['extension'])) {
      $path_parts['extension'] = strtolower($path_parts['extension']);
    }

    if (!empty($conversion_lut[$path_parts['extension']])) {
      auc_process_wrapper($conversion_lut, $path_parts);
    }
  }
  if (!empty($_FILES['files']['name'])) {
    foreach ($_FILES['files']['name'] as $form_field_name => $value) {
  $path_parts = pathinfo($file_name);

      // Quick skip here.
      if ($_FILES['files']['size'][$form_field_name] < 16) {
        continue;
      }
      if ($_FILES['files']['error'][$form_field_name] != UPLOAD_ERR_OK) {
        continue;
      }
      if (!is_uploaded_file($_FILES['files']['tmp_name'][$form_field_name])) {
        continue;
      }

      $path_parts = pathinfo($_FILES['files']['name'][$form_field_name]);
  // Lowercase for file extension.
  if (!empty($path_parts['extension']) && is_string($path_parts['extension'])) {
    $path_parts['extension'] = strtolower($path_parts['extension']);
  }
      if (empty($conversion_lut[$path_parts['extension']])) {
        continue;
      }

      auc_process_wrapper($conversion_lut, $path_parts, $form_field_name);
    }
  if (!empty($path_parts['extension']) && !empty($conversion_lut[$path_parts['extension']])) {
    module_load_include('inc', 'auc', 'auc.under_hood');
    return auc_process_wrapper($conversion_lut, $path_parts, $field_name);
  }
}