Index: vud.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/Attic/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 May 2010 13:17:37 -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/Attic/vud.module,v
retrieving revision 1.1.2.25
diff -u -p -r1.1.2.25 vud.module
--- vud.module	23 Apr 2010 05:10:16 -0000	1.1.2.25
+++ vud.module	10 May 2010 13:17:38 -0000
@@ -159,3 +159,30 @@ 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) {
+  db_query("SELECT status FROM {vud_status} WHERE type = '%s' AND content_id = %d", $type, $content_id);
+  if (db_affected_rows() > 0) {
+    db_query("UPDATE {vud_status} SET status = %d WHERE type = '%s' AND content_id = %d", $status, $type, $content_id);
+  }
+  else {
+    db_query("INSERT INTO {vud_status} (type, content_id, status) VALUES ('%s', %d, %d)", $type, $content_id, $status);
+  }
+}
+
+/**
+ * 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/Attic/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 May 2010 13:17:38 -0000
@@ -31,6 +31,7 @@ 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');
 }
 
 /**
Index: vud_node/vud_node.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vote_up_down/vud_node/Attic/vud_node.module,v
retrieving revision 1.1.2.30
diff -u -p -r1.1.2.30 vud_node.module
--- vud_node/vud_node.module	1 May 2010 08:18:23 -0000	1.1.2.30
+++ vud_node/vud_node.module	10 May 2010 13:17:38 -0000
@@ -70,6 +70,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.'),
@@ -112,66 +118,78 @@ return system_settings_form($form);
  */
 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':
+      if (vud_node_is_valid_node($node)) {
+        $node->vud_status = vud_status_get('node', $node->nid);
+      }
+      break;
+
     case 'view':
-      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 (vud_node_is_valid_node($node) && (($can_edit = user_access('use vote up/down on nodes')) || user_access('view vote up/down count on nodes'))) {
         $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');
         $vote_on_teaser = (bool)variable_get('vud_node_widget_vote_on_teaser', TRUE);
         $teaser = $a3;
 
-        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),
-                  '#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),
-                  '#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),
+                '#value' => theme(vud_theme_functions('vud_widget', 'node', $node->nid), $node->nid, 'node', $tag, $widget, !$vote_on_teaser || !$can_edit),
                 '#weight' => -10,
               );
-              break;
-          }
-
-          $widget_message = t('Sorry, there was problem on the vote.');
-          if (!$can_edit) {
-            $widget_message = t('You are not allowed to vote.');
-          }
-          elseif (!$vote_on_teaser) {
-            $widget_message = t('Please go to full version of this content to vote.');
-          }
-          drupal_add_js(
-            array(
-              'vud_node' => array('widget_message' => $widget_message),
-            ),
-            'setting'
-          );
+            }
+            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),
+                '#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),
+              '#weight' => -10,
+            );
+            break;
+        }
 
+        $widget_message = t('Sorry, there was problem on the vote.');
+        if (!$can_edit) {
+          $widget_message = t('You are not allowed to vote.');
+        }
+        elseif (!$vote_on_teaser) {
+          $widget_message = t('Please go to full version of this content to vote.');
         }
+        drupal_add_js(
+          array(
+            'vud_node' => array('widget_message' => $widget_message),
+          ),
+          'setting'
+        );
       }
       break;
-  }
+    }
 }
 
 /**
@@ -280,3 +298,113 @@ function vud_node_link($type, $object, $
   }
   return $links;
 }
+
+/**
+ * Helper function to check for valid individual nodes.
+ * 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 or FALSE
+ *   if voting was disabled for the node.
+ */
+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) {
+  if (isset($form['#node']) && $form_id == $form['#node']->type . '_node_form' && vud_node_is_valid_type($form['#node']->type)) {
+    $status = isset($form['#node']->vud_status) ? $form['#node']->vud_status : 0;
+    $form['vud'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Vote Up/Down'),
+      'vud_status' => array(
+        '#type' => 'checkbox',
+        '#title' => t('Enable up/down voting'),
+        '#default_value' => $status,
+      ),
+    );
+  }
+}
+
+/**
+ * Implementation of hook_content_extra_fields().
+ */
+function vud_node_content_extra_fields($type_name) {
+  if (vud_node_is_valid_type($type_name) && variable_get('vud_node_per_node', FALSE)) {
+    $extra = array();
+    $extra['vud'] = array(
+      'label' => t('Vote Up/Down'),
+      'description' => t('Vote Up/Down settings'),
+      'weight' => 0,
+    );
+  }
+  return $extra;
+}
