$data) { $fields = node_import_fields('node:'.$type,TRUE); // Give fields a more descriptive title. foreach (array_keys($fields) as $key) { if (strstr($key, 'cck:field_')) { #dsm("match $key"); $field_options["$type $key"] = t('Content Profile: (!type) !key ', array('!key' => $fields[$key]['title'], '!type' => $type)); } } // skip merge if there are no fields on the content type if (count($field_options)) { $options['content_profile'] = array_merge($options['content_profile'], $field_options); } } /* We do not support taxonomy yet */ return $options; } /** * Implementation of hook_user_import_form_update_user(). */ function content_profile_user_import_form_update_user() { $form['content_profile'] = array('title' => t('Content Profile'), 'description' => t('Affected: fields in Content Profile nodes.')); return $form; } /** * Implementation of hook_user_import_data(). */ function content_profile_user_import_data($settings, $update_setting, $column_settings, $module, $field_id, $data, $column_id) { if ($module == 'content_profile') { return trim($data[$column_id]); } } /** * Implementation of hook_user_import_after_save(). */ function content_profile_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) { if (!is_array($fields['content_profile'])) return; // check if it's an existing user and if nodeprofile is to be updated if ($updated && $update_setting_per_module['content_profile'] == UPDATE_NONE) return; // arrange values by content type foreach ($fields['content_profile'] as $column_id => $column_data) { if (!empty($column_data)) { $keys = explode(' ', $column_id); $contentprofile[$keys[0]][$keys[1]] = $column_data; } } $contentprofile_types = (array) content_profile_get_types(); // process each nodeprofile content type foreach (array_keys($contentprofile_types) as $type) { content_profile_user_import_node($type, $contentprofile, $account, $fields, $updated, $update_setting_per_module['nodeprofile']); } return; } /** * create or update a node if appropriate */ function content_profile_user_import_node($type, $nodeprofile, $account, $fields, $updated, $update_setting) { if (empty($nodeprofile[$type])) return; $errors = array(); $title_empty = time(); // Look for an existing node, works because profile node types can only have one node per user. // if ($old_node = node_load(array('type' => $type, 'uid' => $account->uid))) { // // By explicitly setting a nid value, we force an update. // $node->nid = $old_node->nid; // } if ($updated) { $node = node_load(array('type' => $type, 'uid' => $account->uid)); } if (empty($node)) { $node = new StdClass(); $node->type = $type; $node->status = 1; $node->title = $title_empty; } // Assign the mapped fields to the $node. foreach ($nodeprofile[$type] as $column_id => $column_data) { if (!$updated) { $field_name = split(':',$column_id); $field_name = count($field_name)==3 ? $field_name[1]: $column_id; $node->$field_name = array(0 => array('value' => $column_data[0])); } elseif ($updated && $update_setting == UPDATE_ADD) { // remove '_value' from end of field id $field_name = substr($column_id,4); $current_content = content_format($field_name, $node->{$field_name}[0], 'default', $node); if (empty($current_content)) { unset($node->$field_name); $node->$field_name = $column_data[0]; } } elseif ($updated && $update_setting == UPDATE_REPLACE) { $field_name = substr($column_id,4); unset($node->$field_name); $node->$field_name = $column_data[0]; } } // Call the node import preparation. foreach (module_implements('node_import_prepare') as $module_name) { $function = $module_name . '_node_import_prepare'; $errors = array_merge((array)$errors, (array)$function($node, $preview > 0)); } if (empty($errors)) { $node->uid = $account->uid; $node->name = $account->name; // Assign a default title if one has not already been mapped. if (!isset($node->title) || empty($node->title) || $node->title == $title_empty) { $node->title = $node->name; } $node = node_submit($node); // make sure author is not changed when submited (hapens if existing node) $node->uid = $account->uid; $node->name = $account->name; node_save($node); } else { /** * @todo report errors */ } } } else { drupal_set_message(t('Please enable %module module!', array('%module' => 'node_import'))); }