$type_label) { $type_data = content_types($type); foreach ($type_data['fields'] as $field) { $key = $field['field_name']; $title = $field['widget']['label']; $field_options["$type $key"] = t('Content Profile: !key (!type)', array('!key' => $title, '!type' => $type_label)); } $options['content_profile'] = array_merge($options['content_profile'], $field_options); dpm($options); } /* // TODO // add taxonomy options // added here instead of taxonomy.inc because taxonomy is dependant on content_profile being used and a profile node being created if (!module_exists('taxonomy')) return $options; $content_profile_types = content_profile_get_types('names'); $vocabularies = taxonomy_get_vocabularies(); // add vocabulary as an option if it's associated with a content_profile content type foreach ($vocabularies as $vocabulary) { foreach ($vocabulary->nodes as $type) { $name = node_get_types('name', $type); if (in_array($name, $content_profile_types)) $options['taxonomy'][$vocabulary->vid] = t('Category: !vocabulary', array('!vocabulary' => $vocabulary->name)); } } */ 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' || $module == 'taxonomy') { 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 content_profile 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); $content_profile[$keys[0]][$keys[1]] = $column_data; } } $content_profile_types = (array) content_profile_get_types(); // process each content_profile content type foreach (array_keys($content_profile_types) as $type) { content_profile_user_import_node($type, $content_profile, $account, $fields, $updated, $update_setting_per_module['content_profile']); } return; } /** * create or update a node if appropriate */ function content_profile_user_import_node($type, $content_profile, $account, $fields, $updated, $update_setting) { if (empty($content_profile[$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 ($content_profile[$type] as $column_id => $column_data) { if (!$updated) { $node->$column_id = array(0 => array('value' => $column_data[0])); } elseif ($updated && $update_setting == UPDATE_ADD) { // remove '_value' from end of field id $current_content = content_format($field_name, $node->{$column_id}[0], 'default', $node); if (empty($current_content)) { unset($node->$column_id); $node->$column_id = array(array('value' => $column_data[0])); } } elseif ($updated && $update_setting == UPDATE_REPLACE) { unset($node->$column_id); $node->$column_id = array(array('value' => $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); // set taxonomy content_profile_user_import_taxonomy($node, $fields['taxonomy'], $updated, $update_setting); } else { /** * @todo report errors */ } } /** * set taxonomy for a node */ function content_profile_user_import_taxonomy($node, $field, $updated, $update_setting) { if (!module_exists('taxonomy') || (!$updated && empty($field)) || ($updated && $update_setting == UPDATE_ADD && empty($field))) return; $taxonomy = array(); $vocabularies = taxonomy_get_vocabularies($node->type); foreach ($vocabularies as $vid => $vocabulary) { // check vocabulary is freetaging if (empty($vocabulary->tags)) { // not freetaging /** * @todo add support for pre-defined taxonomy */ } else { // freetaging vocabulary if (!$updated || ($updated && $update_setting == UPDATE_REPLACE)) { $taxonomy['tags'][$vid] = $field[$vid][0]; } elseif ($updated && $update_setting == UPDATE_ADD) { // existing terms $terms_existing = taxonomy_node_get_terms_by_vocabulary($node, $vid, 'name'); $terms_all = array_keys($terms_existing); // new terms $terms_new = explode(',', $field[$vid][0]); if (is_array($terms_all) && is_array($terms_new)) $terms_all = array_merge($terms_new, $terms_all); if (is_array($terms_all)) $taxonomy['tags'][$vid] = implode(',', $terms_all); } } } if ((!$updated && empty($taxonomy)) || ($updated && $update_setting == UPDATE_ADD && empty($taxonomy))) return; taxonomy_node_save($node->nid, $taxonomy); } }