You are here

function node_import_automap in Node import 6

Same name and namespace in other branches
  1. 5 node_import.api.inc \node_import_automap()

Return an autodetected mapping for given headers and content type.

The automapping is done by checking the column titles in the file, whether they match with the field name or field title.

Parameters

$type: String. The node_import type.

$headers: Array of column titles in the file.

Return value

Array of mapping.

Related topics

1 call to node_import_automap()
node_import_add_form_submit_reload in ./node_import.admin.inc

File

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

Code

function node_import_automap($type, $headers) {
  global $user;
  if (user_access('administer imports')) {
    $result = db_query("SELECT map FROM {node_import_tasks} WHERE type = '%s' AND LOWER(headers) = '%s' ORDER BY created DESC LIMIT 1", $type, strtolower(serialize($headers)));
  }
  else {
    $result = db_query("SELECT map FROM {node_import_tasks} WHERE type = '%s' AND LOWER(headers) = '%s' AND uid = %d ORDER BY created DESC LIMIT 1", $type, strtolower(serialize($headers)), $user->uid);
  }
  if ($map = db_result($result)) {
    return unserialize($map);
  }
  $map = array();
  $headers = array_map('drupal_strtolower', $headers);
  foreach (node_import_fields($type) as $fieldname => $fieldinfo) {
    if ($fieldinfo['is_mappable']) {
      $map[$fieldname] = '';
      if (($col = array_search(drupal_strtolower($fieldname), $headers)) !== FALSE || ($col = array_search(drupal_strtolower($fieldinfo['title']), $headers)) !== FALSE) {
        $map[$fieldname] = $col;
      }
    }
  }
  return $map;
}