You are here

function node_import_check_user_reference in Node import 6

Check if the value is a valid user (by uid, name or email).

Uses: $field['output_format']. Either 'uid' (default), 'name' or 'email'.

Related topics

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

File

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

Code

function node_import_check_user_reference(&$value, $field, $options, $preview) {
  if (($uid = node_import_get_object('user', $value)) !== NULL || ($uid = db_result(db_query("SELECT uid FROM {users} WHERE uid = %d OR LOWER(name) = '%s' OR LOWER(mail) = '%s' LIMIT 1", is_numeric($value) && intval($value) > 0 ? $value : -1, drupal_strtolower($value), drupal_strtolower($value))))) {
    node_import_set_object('user', $value, $uid);
    $value = $uid;
    $field['output_format'] = isset($field['output_format']) ? $field['output_format'] : 'uid';
    switch ($field['output_format']) {
      case 'name':
        if (($name = node_import_get_object('user:name', $uid)) || ($name = db_result(db_query("SELECT name FROM {users} WHERE uid = %d LIMIT 1", $uid)))) {
          $value = $name;
          node_import_set_object('user:name', $uid, $name);
        }
        break;
      case 'email':
        if (($email = node_import_get_object('user:email', $uid)) || ($email = db_result(db_query("SELECT mail FROM {users} WHERE uid = %d LIMIT 1", $uid)))) {
          $value = $email;
          node_import_set_object('user:email', $uid, $email);
        }
        break;
      case 'uid':
      default:
        break;
    }
    return TRUE;
  }
  node_import_input_error(t('Input error: %value is not allowed for %name (not an user).', array(
    '%value' => $value,
    '%name' => $field['title'],
  )));
  return FALSE;
}