Index: vud.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud.install,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 vud.install
--- vud.install	16 Aug 2009 19:22:05 -0000	1.1.2.5
+++ vud.install	10 Jun 2010 15:02:46 -0000
@@ -17,7 +17,41 @@ function vud_install() {
  * Implementation of hook_schema().
  */
 function vud_schema() {
-  return array();
+  $schema = array();
+
+  $schema['vud_status'] = array(
+    'fields' => array(
+      'vudid' => array(
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'type' => array(
+        'type' => 'varchar',
+        'length' => '32',
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'content_id' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'status' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array('vudid'),
+    'unique keys' => array(
+      'vudid_type_content_id' => array('vudid', 'type', 'content_id'),
+    ),
+  );
+
+  return $schema;
 }
 
 /**
Index: vud.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud.module,v
retrieving revision 1.1.2.29
diff -u -p -r1.1.2.29 vud.module
--- vud.module	31 May 2010 03:17:52 -0000	1.1.2.29
+++ vud.module	10 Jun 2010 15:02:46 -0000
@@ -193,3 +193,35 @@ function vud_ctools_plugin_directory($mo
     return $plugin;
   }
 }
+
+/**
+ * Helper function to get status for a piece of content.
+ */
+function vud_status_get($type, $content_id) {
+  return (int) db_result(db_query("SELECT status FROM {vud_status} WHERE type = '%s' AND content_id = %d", $type, $content_id));
+}
+
+/**
+ * Helper function to save status for a piece of content.
+ */
+function vud_status_save($type, $content_id, $status) {
+  $object = array(
+    'type' => $type,
+    'content_id' => $content_id,
+    'status' => $status,
+  );
+  db_query("SELECT status FROM {vud_status} WHERE type = '%s' AND content_id = %d", $type, $content_id);
+  if (db_affected_rows() > 0) {
+    drupal_write_record('vud_status', $object, array('type', 'content_id'));
+  }
+  else {
+    drupal_write_record('vud_status', $object);
+  }
+}
+
+/**
+ * Helper function to delete status for a piece of content.
+ */
+function vud_status_delete($type, $content_id) {
+  db_query("DELETE FROM {vud_status} WHERE type = '%s' AND content_id = %d", $type, $content_id);
+}
Index: vud_node/vud_node.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud_node/vud_node.install,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 vud_node.install
--- vud_node/vud_node.install	15 Jan 2010 02:36:29 -0000	1.1.2.4
+++ vud_node/vud_node.install	10 Jun 2010 15:02:46 -0000
@@ -31,6 +31,8 @@ function vud_node_uninstall() {
   variable_del('vud_node_votes');
   variable_del('vud_node_reset');
   variable_del('vud_node_widget_vote_on_teaser');
+  variable_del('vud_node_per_node');
+  db_query("DELETE FROM {variable} WHERE name LIKE 'vud_node_default_status_%'");
 }
 
 /**
Index: vud_node/vud_node.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud_node/vud_node.module,v
retrieving revision 1.1.2.34
diff -u -p -r1.1.2.34 vud_node.module
--- vud_node/vud_node.module	31 May 2010 03:15:09 -0000	1.1.2.34
+++ vud_node/vud_node.module	10 Jun 2010 15:02:47 -0000
@@ -56,7 +56,7 @@ function vud_node_tab_view_stats($node) 
     return FALSE;
   }
 
-  if (in_array($node->type, variable_get('vud_node_types', array()), TRUE)) {
+  if (vud_node_is_valid_node($node)) {
     return TRUE;
   }
 }
@@ -72,6 +72,12 @@ function vud_node_admin_settings() {
     '#default_value' => variable_get('vud_node_types', array()),
     '#options'       => node_get_types('names'),
   );
+  $form['vud_node_per_node'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Toggle on/off per node'),
+    '#description' => t('Check this if it should be possible to turn off voting on a per node basis.'),
+    '#default_value' => variable_get('vud_node_per_node', FALSE),
+  );
   $form['vud_node_widget'] = array(
     '#title'         => t('Widget selection'),
     '#description'   => t('Select the voting widget theme that will be displayed.'),
@@ -121,6 +127,21 @@ function vud_node_vud_widget_message_cod
  */
 function vud_node_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   switch ($op) {
+    case 'insert':
+    case 'update':
+      if (isset($node->vud_status)) {
+        vud_status_save('node', $node->nid, $node->vud_status);
+      }
+      break;
+
+    case 'delete':
+      vud_status_delete('node', $node->nid);
+      break;
+
+    case 'load':
+      $node->vud_status = vud_status_get('node', $node->nid);
+      break;
+
     case 'view':
       // avoid showing the widget in some node builds
       $exclude_modes = array(
@@ -132,8 +153,7 @@ function vud_node_nodeapi(&$node, $op, $
       if (in_array($node->build_mode, $exclude_modes)) {
         break;
       }
-      if (($can_edit=user_access('use vote up/down on nodes')) || user_access('view vote up/down count on nodes')) {
-        $node_type = in_array($node->type, variable_get('vud_node_types', array()), TRUE);
+      if ((($can_edit=user_access('use vote up/down on nodes')) || user_access('view vote up/down count on nodes')) && vud_node_is_valid_node($node)) {
         $widget_showmode = variable_get('vud_node_widget_show', VUD_NODE_DISPLAY_BOTH);
         $tag = variable_get('vud_tag', 'vote');
         $widget = variable_get('vud_node_widget', 'plain');
@@ -147,39 +167,35 @@ function vud_node_nodeapi(&$node, $op, $
           $widget_message_code = VUD_NODE_WIDGET_MESSAGE_TEASER_DENIED;
         }
 
-        if ($node_type) {
-
-          switch ($widget_showmode) {
-            case VUD_NODE_DISPLAY_TEASER_ONLY:
-              if ($teaser == 1) {
-                $node->content['vud_node_widget_display'] = array(
-                  '#value' => theme(vud_theme_functions('vud_widget', 'node', $node->nid), $node->nid, 'node', $tag, $widget, !$vote_on_teaser || !$can_edit, $widget_message_code),
-                  '#weight' => -10,
-                );
-              }
-              break;
-            case VUD_NODE_DISPLAY_FULL_ONLY:
-              if ($teaser == 0) {
-                $node->content['vud_node_widget_display'] = array(
-                  '#value' => theme(vud_theme_functions('vud_widget', 'node', $node->nid), $node->nid, 'node', $tag, $widget, !$can_edit, $widget_message_code),
-                  '#weight' => -10,
-                );
-              }
-              break;
-            case VUD_NODE_DISPLAY_BOTH:
-              if ($teaser == 1) {
-                $readonly = !$vote_on_teaser || !$can_edit;
-              }
-              else {
-                $readonly = !$can_edit;
-              }
+        switch ($widget_showmode) {
+          case VUD_NODE_DISPLAY_TEASER_ONLY:
+            if ($teaser == 1) {
               $node->content['vud_node_widget_display'] = array(
-                '#value' => theme(vud_theme_functions('vud_widget', 'node', $node->nid), $node->nid, 'node', $tag, $widget, $readonly, $widget_message_code),
+                '#value' => theme(vud_theme_functions('vud_widget', 'node', $node->nid), $node->nid, 'node', $tag, $widget, !$vote_on_teaser || !$can_edit, $widget_message_code),
                 '#weight' => -10,
               );
-              break;
-          }
-
+            }
+            break;
+          case VUD_NODE_DISPLAY_FULL_ONLY:
+            if ($teaser == 0) {
+              $node->content['vud_node_widget_display'] = array(
+                '#value' => theme(vud_theme_functions('vud_widget', 'node', $node->nid), $node->nid, 'node', $tag, $widget, !$can_edit, $widget_message_code),
+                '#weight' => -10,
+              );
+            }
+            break;
+          case VUD_NODE_DISPLAY_BOTH:
+            if ($teaser == 1) {
+              $readonly = !$vote_on_teaser || !$can_edit;
+            }
+            else {
+              $readonly = !$can_edit;
+            }
+            $node->content['vud_node_widget_display'] = array(
+              '#value' => theme(vud_theme_functions('vud_widget', 'node', $node->nid), $node->nid, 'node', $tag, $widget, $readonly, $widget_message_code),
+              '#weight' => -10,
+            );
+            break;
         }
       }
       break;
@@ -248,8 +264,10 @@ function vud_node_link($type, $object, $
   switch ($type) {
     case 'node':
       $node = &$object;
+      if (!vud_node_is_valid_node($node)) {
+        return;
+      }
       $votes_display_mode = variable_get('vud_node_votes', VUD_NODE_DISPLAY_BOTH);
-      $node_type = in_array($node->type, variable_get('vud_node_types', array()), TRUE);
       $widget_theme = variable_get('vud_node_widget', 'plain');
       $tag = variable_get('vud_tag', 'vote');
       $view_vud_node_votes_count = user_access('view vote up/down count on nodes') || user_access('use vote up/down on nodes');
@@ -257,7 +275,7 @@ function vud_node_link($type, $object, $
         case VUD_NODE_DISPLAY_NO:
           break;
         case VUD_NODE_DISPLAY_TEASER_ONLY:
-          if (($teaser == 1) && $node_type && $view_vud_node_votes_count) {
+          if (($teaser == 1) && $view_vud_node_votes_count) {
             $links['vud_node_votes_count'] = array(
               'title' => theme(vud_theme_functions('vud_votes', 'node', $node->nid), $node->nid, $type, $tag, $widget_theme),
               'html'  => TRUE,
@@ -265,7 +283,7 @@ function vud_node_link($type, $object, $
           }
           break;
         case VUD_NODE_DISPLAY_FULL_ONLY:
-          if (($teaser == 0) && $node_type && $view_vud_node_votes_count) {
+          if (($teaser == 0) && $view_vud_node_votes_count) {
             $links['vud_node_votes_count'] = array(
               'title' => theme(vud_theme_functions('vud_votes', 'node', $node->nid), $node->nid, $type, $tag, $widget_theme),
               'html'  => TRUE,
@@ -273,7 +291,7 @@ function vud_node_link($type, $object, $
           }
           break;
         case VUD_NODE_DISPLAY_BOTH:
-          if ($node_type && $view_vud_node_votes_count) {
+          if ($view_vud_node_votes_count) {
             $links['vud_node_votes_count'] = array(
               'title' => theme(vud_theme_functions('vud_votes', 'node', $node->nid), $node->nid, $type, $tag, $widget_theme),
               'html'  => TRUE,
@@ -281,7 +299,7 @@ function vud_node_link($type, $object, $
           }
           break;
       }
-      if ($node_type && variable_get('vud_node_reset', 0)) {
+      if (variable_get('vud_node_reset', 0)) {
         $reset_token = drupal_get_token("votereset/node/$node->nid/$tag");
         $links['vud_node_votes_reset_link'] = array(
           'title' => t('Reset your vote'),
@@ -293,3 +311,119 @@ function vud_node_link($type, $object, $
   }
   return $links;
 }
+
+/**
+ * Helper function to check for valid nodes. Valid nodes are nodes of a voting
+ * enabled content type and where voting of that particular node has not been
+ * disabled.
+ *
+ * Use vud_node_is_valid_type() if you only wan't to check for valid node
+ * types.
+ *
+ * @param $node
+ *   Either a full node object or a node ID.
+ *
+ * @param $reset
+ *   Whether or not to reset the static cache.
+ *
+ * @return
+ *   Return TRUE if voting is enabled for the node. Returns FALSE if voting was
+ *   disabled for the node, or if it was a node of an invalid content type.
+ */
+function vud_node_is_valid_node($node, $reset = FALSE) {
+  static $cache = array();
+
+  // The argument was a node object.
+  if (is_object($node)) {
+    $nid = $node->nid;
+    $node_type = $node->type;
+  }
+  // The argument was a node id.
+  else {
+    $nid = $node;
+    // We have to limit the result if revisions is enabled.
+    // Because if revisions is enabled we will have multiple
+    // rows returned.
+    $node_type = db_result(db_query('SELECT type FROM {node} WHERE nid = %d LIMIT 1', $nid));
+  }
+
+  if (!isset($cache[$nid]) || $reset) {
+    // First, check if the node type is valid.
+    if (vud_node_is_valid_type($node_type, $reset)) {
+      // We've enabled the ability to toggle voting on/off per
+      // node, so we must check the status in the db.
+      if (variable_get('vud_node_per_node', FALSE)) {
+        $cache[$nid] = vud_status_get('node', $nid);
+      }
+      else {
+        $cache[$nid] = TRUE;
+      }
+    }
+    else {
+      $cache[$nid] = FALSE;
+    }
+  }
+  return $cache[$nid];
+}
+
+/**
+ * Helper function to check for valid node types.
+ *
+ * @param $type_name
+ *   The machine readable name of a node type.
+ *
+ * @param $reset
+ *   Whether or not to reset the static cache.
+ *
+ * @return
+ *   TRUE for node types that has voting enabled, otherwise FALSE. 
+ */
+function vud_node_is_valid_type($type_name, $reset = FALSE) {
+  static $cache = array();
+  if (!isset($cache[$type_name]) || $reset) {
+    // The parameter was a content type name string.
+    if (is_string($type_name) && in_array($type_name, array_filter(variable_get('vud_node_types', array())))) {
+      $cache[$type_name] = TRUE;
+    }
+    else {
+      $cache[$type_name] = FALSE;
+    }
+  }
+  return $cache[$type_name];
+}
+
+/**
+ * Implementation of hook_form_alter().
+ */
+function vud_node_form_alter(&$form, &$form_state, $form_id) {
+  $node = isset($form['#node']) ? $form['#node'] : NULL;
+
+  if (!empty($node) && $form_id == $node->type . '_node_form' && vud_node_is_valid_type($node->type) && variable_get('vud_node_per_node', FALSE)) {
+    $form['vud'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Vote Up/Down'),
+      'vud_status' => array(
+        '#type' => 'checkbox',
+        '#title' => t('Enable up/down voting'),
+        '#description' => t('Check this if voting shall be enabled for this node.'),
+        '#default_value' => isset($node->vud_status) ? $node->vud_status : variable_get('vud_node_default_status_' . $node->type, TRUE),
+      ),
+    );
+  }
+  elseif (isset($form['#node_type']) && $form_id = 'node_type_form' && vud_node_is_valid_type($form['#node_type']->type)) {
+    $form['#submit'][] = 'vud_node_type_form_submit';
+    $form['workflow']['vud_status'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Enable vote up/down by default'),
+      '#description' => t('Check this if voting shall be enabled by default for this node type.'),
+      '#default_value' => variable_get('vud_node_default_status_' . $form['#node_type']->type, TRUE),
+    );
+  }
+}
+
+/**
+ * Submit callback for the node type form.
+ */
+function vud_node_type_form_submit($form, &$form_state) {
+  variable_set('vud_node_default_status_' . $form_state['values']['type'], $form_state['values']['vud_status']);
+}
