? .project
? sites/all/modules/coder
? sites/all/modules/devel
? sites/default/.DS_Store
? sites/default/files
? sites/default/settings.php
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.481
diff -u -p -r1.481 taxonomy.module
--- modules/taxonomy/taxonomy.module	27 Jun 2009 19:49:07 -0000	1.481
+++ modules/taxonomy/taxonomy.module	28 Jun 2009 16:17:14 -0000
@@ -1825,3 +1825,118 @@ function taxonomy_hook_info() {
     ),
   );
 }
+
+/**
+ * Implementation of hook_node_operations().
+ */
+function taxonomy_node_operations() {
+  $operations = array(
+    'taxonomy_multiple_node_add_term' => array(
+      'label' => t('Add a term to nodes'),
+      'callback' => NULL,
+    ),
+  );
+  return $operations;
+}
+
+/**
+ * Form alter for node_admin_content.
+ *
+ * Provides additional node operation settings.
+ */
+function taxonomy_form_node_admin_content_alter(&$form, $form_state) {
+  // Perform node operation for taxonomy.
+  if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'taxonomy_multiple_node_add_term' && count($form_state['input']['nodes']) && !isset($form_state['values']['additional'])) {
+    //$form = array();
+    $nodes = $form_state['input']['nodes'];
+    // Preserve values form form submission.
+    $form['admin']['nodes']['#default_value'] = $nodes;
+    $form['admin']['options']['operation']['#default_value'] = $form_state['values']['operation'];
+    $form['admin']['options']['operation']['#disabled'] = TRUE;
+    // Additional information for operation.
+    $form['admin']['options']['additional'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Additional information'),
+      '#weight' => 1,
+      '#tree' => TRUE,
+    );
+    $form['admin']['options']['additional']['term'] = array(
+      '#type' => 'select',
+      '#title' => t('Taxonomy term'),
+      '#options' => taxonomy_form_all(),
+      '#description' => t('Select the term to be added to a node. The vocabulary has to be activated for the depending node type.'),
+      '#required' => TRUE,
+    );
+    $form['admin']['options']['additional']['override'] = array(
+      '#type' => 'checkbox',
+      '#description' => t('When checked, an existing value will be overridden for non-multiple select vocabularies.'),
+      '#title' => t('Override single term'),
+    );
+    // Show submit button beneath additions.
+    $form['admin']['options']['submit']['#weight'] = 2;
+    $form['admin']['options']['submit']['#submit'][] = 'taxonomy_term_add_node_operation_submit';
+    $form['admin']['options']['submit']['#suffix'] = l(t('Cancel'), 'admin/content/content');
+  }
+}
+
+/**
+ * Additional submit for taxonomy_multiple_node_add_term operation.
+ */
+function taxonomy_term_add_node_operation_submit($form, &$form_state) {
+  $nodes = $form_state['input']['nodes'];
+  $tid = $form_state['values']['additional']['term'];
+  $override = $form_state['values']['additional']['override'];
+  $term = taxonomy_term_load($tid);  
+  if ($term == FALSE) return ;
+  $voc = taxonomy_vocabulary_load($term->vid);
+  if (!count($voc->nodes)) return ;
+  // TODO: increase performance.
+  foreach ($nodes as $nid) {
+    $node = node_load($nid);
+    if (in_array($node->type, $voc->nodes)) {
+      $to_change = TRUE;
+      $terms = $node->taxonomy;
+      // Single selects override, when override was checked
+      if (!$voc->multiple) {
+        foreach ($terms as $t) {
+          if ($t->vid == $term->vid) {
+            if ($override) {
+              unset($node->taxonomy[$t->tid]);
+              $node->taxonomy[$tid];
+            }
+            else {
+              $to_change = FALSE;
+              $exists = ($t->tid == $tid);
+            }
+            break;
+          }
+        }
+      }
+      else {
+        if (array_key_exists($tid, $terms)) {
+          $to_change = FALSE;
+          $exists = TRUE;
+        }
+        else {
+          $terms[$tid] = TRUE;
+        }
+      }
+      // Only will save new term, when it actually shall be added or override
+      // an existing term.
+      if ($to_change) {
+        $terms = array_keys($terms);
+        taxonomy_node_save($node, $terms);
+        drupal_set_message(t('Term %term added to node %node.', array('%term' => $term->name, '%node' => $node->title)));
+      }
+      elseif ($exists) {
+        drupal_set_message(t('Term %term allready exists for node %node', array('%term' => $term->name, '%node' => $node->title)));
+      }
+      else {
+        drupal_set_message(t('Node %node allready contains a term for vocabulary %voc', array('%node' => $node->title, '%voc' => $voc->name)), 'warning');
+      }
+    }
+    else {
+      drupal_set_message(t('Terms from vocabulary %voc may not be set to %node (node of type %type).', array('%node' => $node->title, '%voc' => $voc->name, '%type' => $node->type)), 'warning');
+    }   
+  }
+}
\ No newline at end of file
