0) { $nids = array(); $term_nodes = _term_merge_select_nodes($tid); while ($node = db_fetch_object($term_nodes)) { $nids[] = $node->nid; } $term = taxonomy_get_term($tid); $children = taxonomy_get_tree($term->vid, $tid); foreach ($children as $child) { $exclude[] = $child->tid; } $exclude[] = $tid; $form['foster'] = _taxonomy_term_select(t('Foster term(s)'), 'foster', -1, $term->vid, t('One or more nodes are using this term. If you select one or more terms from the list above, these nodes will be associated with the selected terms.'), 1, NULL, $exclude); $form['#submit']['term_merge_term_delete_submit'] = array($nids); } } break; } } function term_merge_term_delete_submit($form_id, $form_values, $nids) { if(isset($form_values['foster'])) { $foster = $form_values['foster']; if (count($foster)>0) { while (list($tid, $object) = each($foster)) { $foster[$tid] = taxonomy_get_term($tid); } reset($foster); foreach($nids as $nid) { $node = node_load($nid); $terms = $node->taxonomy; while (list($tid,$object) = each($foster)) { $terms[$tid] = $object; } reset($foster); // note for 6.x: taxonomy_node_save was changed to take a $node object instead of $nid taxonomy_node_save($nid, $terms); drupal_set_message(t('Assigned foster terms to node %title.', array('%title' => theme('placeholder', check_plain($node->title))))); } } } } function _term_merge_select_nodes($tid) { // I would have liked to use taxonomy_select_nodes() instead, but that function // either uses a pager, or returns only the latest n nodes, and we need all of them // (including unpublished nodes) // generate an array of descendant term IDs to the right depth. $descendant_tids = array(); $term = taxonomy_get_term($tid); $tree = taxonomy_get_tree($term->vid, $tid, -1, NULL); $descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree)); $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids)); $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .')'; $result = db_query(db_rewrite_sql($sql)); return $result; } ?>