You are here

function node_import_check_filepath in Node import 6

Check if the value points to a valid filepath.

Uses: $field['to_directory'], $options['from_directory'], $options['manually_moved'].

Related topics

1 string reference to 'node_import_check_filepath'
node_import_fields in ./node_import.inc
Returns a list of available content fields for given node_import type.

File

./node_import.inc, line 1234
Public API of the Node import module.

Code

function node_import_check_filepath(&$value, $field, $options, $preview) {

  // No need to check empty values.
  if (drupal_strlen($value) == 0) {
    return TRUE;
  }

  // Where should be file be located?
  $find_in = isset($options['from_directory']) ? $options['from_directory'] : '';
  $find_in = node_import_directory() . (strlen($find_in) > 0 ? '/' . $find_in : '');
  if (isset($options['manually_moved']) && $options['manually_moved']) {
    $find_in = isset($field['to_directory']) ? $field['to_directory'] : '';
  }
  $find_in = file_create_path($find_in);

  // Check if the file exists.
  $filepath = $find_in . '/' . $value;
  if (file_check_location($filepath, $find_in) && file_exists($filepath)) {
    $value = $filepath;
    return TRUE;
  }
  node_import_input_error(t('Input error: %value is not allowed for %name (not a file in %path).', array(
    '%value' => $value,
    '%name' => $field['title'],
    '%path' => $find_in,
  )));
  $value = '';
  return FALSE;
}