--- author_taxonomy.module 2008-04-11 19:12:27.000000000 -0400 +++ author_taxonomy_new.module 2008-06-30 09:44:39.000000000 -0400 @@ -54,6 +54,13 @@ function author_taxonomy_admin_settings( '#description' => t('The taxonomy to use for content authors.'), ); + $form['author_taxonomy_overwrite_node'] = array( + '#type' => 'checkbox', + '#title' => t('Overwrite Real Node Author'), + '#default_value' => variable_get('author_taxonomy_overwrite_node', FALSE), + '#description' => t('Check this box to overwrite the real author of the node with an author corresponding to your taxonomy author term. If a match isn\'t found, the previous author will remain intact. Note that if you allow multiple values in your taxonomy or use freetagging with multiple entires, the first entry will replace the node author as only one can be assigned.'), + ); + $form['author_taxonomy_prepend_node'] = array( '#type' => 'checkbox', '#title' => t('Automatically add output to the beginning of the node'), @@ -115,6 +122,47 @@ function author_taxonomy_nodeapi(&$node, $node->content['body']['#value'] = author_taxonomy_output($node) . "\n" . $node->content['body']['#value']; } break; + + case 'submit': + $display = variable_get('author_taxonomy_overwrite_node', TRUE); + if($display){ + $vocab = variable_get('author_taxonomy_vocab', 1); + $info = taxonomy_get_vocabulary(variable_get('author_taxonomy_vocab', 1)); + $tags = $info->tags; + if($tags == '1'){ + if($node->taxonomy['tags'][$vocab] != ''){ + $authors = $node->taxonomy['tags'][$vocab]; + $author = explode(", ", $authors); + $instance_info = db_fetch_array(db_query("SELECT uid, name FROM {users} WHERE name = '%s'", $author[0])); + if($instance_info['name'] != ''){ + $node->uid = $instance_info['uid']; + $node->name = $instance_info['name']; + } + } + } + else{ + $vocab = taxonomy_get_vocabulary(variable_get('author_taxonomy_vocab', 1)); + $info = taxonomy_get_vocabulary(variable_get('author_taxonomy_vocab', 1)); + $multiple = $info->multiple; + if($multiple == '1'){ + $atid[] = $node->taxonomy[variable_get('author_taxonomy_vocab', 1)]; + $term = taxonomy_get_term(current($atid[0])); + } + else{ + $atid = $node->taxonomy[variable_get('author_taxonomy_vocab', 1)]; + $term = taxonomy_get_term($atid); + } + $author = $term->name; + if($author != ''){ + $instance_info = db_fetch_array(db_query("SELECT uid, name FROM {users} WHERE name = '%s'", $author)); + if($instance_info['name'] != ''){ + $node->uid = $instance_info['uid']; + $node->name = $instance_info['name']; + } + } + } + } + break; } }