--- C:/cygwin/home/patchedfiles/fivestar.module	Tue Apr 14 09:08:15 2009
+++ Z:/environment/www/modules/sites/all/modules/fivestar/fivestar.module	Thu Apr 16 11:51:21 2009
@@ -814,7 +814,7 @@
   $uid = empty($uid) ? $user->uid : $uid;
 
   // Bail out if the user's trying to vote on an invalid object.
-  if (!$skip_validation && !fivestar_validate_target($type, $cid, $uid)) {
+  if (!$skip_validation && !fivestar_validate_target($type, $cid, $tag, $uid)) {
     return array();
   }
 
@@ -1093,7 +1093,6 @@
   if (strpos($form_id, 'fivestar_form') !== FALSE) {
     if ($form_id == 'fivestar_form_'. $args[0] .'_'. $args[1] .'_'. $args[2]) {
       $forms[$form_id] = array('callback' => 'fivestar_form');
-      dsm($forms);
       return $forms;
     }
   }
--- C:/cygwin/home/patchedfiles/fivestar_comment.module	Tue Apr 14 09:08:15 2009
+++ Z:/environment/www/modules/sites/all/modules/fivestar/fivestar_comment.module	Thu Apr 16 11:56:37 2009
@@ -20,8 +20,13 @@
  * Form alter specification for comments.
  */
 function fivestar_comment_form_alter(&$form, &$form_state, $form_id) {
+  
   // Comment settings.
   if ($form_id == 'fivestar_node_type_tag_form') {
+    $tag = $form_state['fivestar_tag'];
+    $type_name = $form_state['fivestar_node_type'];
+    $var_suffix = fivestar_var_suffix($type_name, $tag);
+    
     $form['fivestar']['comment'] = array(
       '#type' => 'fieldset',
       '#title' => t('Comment widget'),
@@ -36,7 +41,9 @@
         FIVESTAR_COMMENT_OPTIONAL => t('Optional rating'),
         FIVESTAR_COMMENT_REQUIRED => t('Required rating'),
       ),
-      '#default_value' => variable_get('fivestar_comment_'. $form['#node_type']->type, FIVESTAR_COMMENT_DISABLED),
+      //'#default_value' => variable_get('fivestar_comment_'. $form['#node_type']->type, FIVESTAR_COMMENT_DISABLED),
+      '#default_value' => variable_get('fivestar_comment'. $var_suffix, FIVESTAR_COMMENT_DISABLED),
+      
     );
     $form['fivestar']['comment']['fivestar_comment_preview'] = array(
       '#type' => 'item',
@@ -54,36 +61,45 @@
   // Comment form. Do not allow ratings inside of threads.
   if ($form_id == 'comment_form' && empty($form['pid']['#value']) && user_access('rate content')) {
     $node = node_load($form['nid']['#value']);
-    if (variable_get('fivestar_comment_'. $node->type, FIVESTAR_COMMENT_DISABLED)) {
-      // Splice in the fivestar right before the body.
-      $new_form = array();
-      foreach ($form as $key => $element) {
-        if ($key == 'comment_filter') {
+    
+    // Splice in the fivestar right before the body.
+    $new_form = array();
+    foreach ($form as $key => $element) {
+      if ($key == 'comment_filter') {
+        foreach (fivestar_get_tags() as $tag) {
           if ($form['cid']['#value']) {
             $current_rating = fivestar_comment_load($form['cid']['#value'], $form['nid']['#value']);
-            $default_value = $current_rating['value'];
+            $default_value = $current_rating[$tag]['value'];
           }
           else {
-            $votes = fivestar_get_votes('node', $form['nid']['#value']);
+            $votes = fivestar_get_votes('node', $form['nid']['#value'], $tag);
             $default_value = isset($votes['user']['value']) ? $votes['user']['value'] : 0;
           }
-          $new_form['fivestar_rating'] = array(
-            '#type' => 'fivestar',
-            '#title' => t('Rating'),
-            '#stars' => variable_get('fivestar_stars_'. $node->type, 5),
-            '#allow_clear' => variable_get('fivestar_comment_'. $node->type, FIVESTAR_COMMENT_DISABLED) == FIVESTAR_COMMENT_OPTIONAL ? 1 : 0,
-            '#content_id' => $node->nid,
-            '#required' => variable_get('fivestar_comment_'. $node->type, FIVESTAR_COMMENT_DISABLED) == FIVESTAR_COMMENT_REQUIRED ? 1 : 0,
-            '#default_value' => $default_value,
-            '#labels' => variable_get('fivestar_labels_'. $node->type, array()),
-          );
+        
+          if (fivestar_validate_target('node', $node->nid, $tag)) {
+            $var_suffix = fivestar_var_suffix($node->type, $tag); 
+            
+            if (variable_get('fivestar_comment'. $var_suffix, FIVESTAR_COMMENT_DISABLED)) {
+              $new_form['fivestar_rating']['fivestar_rating_tag_'. $tag] = array(
+              '#type' => 'fivestar',
+              '#title' => t($tag),
+              '#stars' => variable_get('fivestar_stars_'. $node->type, 5),
+              '#allow_clear' => variable_get('fivestar_comment_'. $var_suffix, FIVESTAR_COMMENT_DISABLED) == FIVESTAR_COMMENT_OPTIONAL ? 1 : 0,
+              '#content_id' => $node->nid,
+              '#required' => variable_get('fivestar_comment_'. $var_suffix, FIVESTAR_COMMENT_DISABLED) == FIVESTAR_COMMENT_REQUIRED ? 1 : 0,
+              '#default_value' => $default_value,
+              '#labels' => variable_get('fivestar_labels_'. $var_suffix, array()),
+              );
+            }
+          }
         }
-        $new_form[$key] = $element;
-      }
-      if ($new_form['fivestar_rating']) {
-        $form = $new_form;
       }
+      $new_form[$key] = $element;
+    }
+    if ($new_form['fivestar_rating']) {
+      $form = $new_form;
     }
+    
   }
 }
 
@@ -91,6 +107,11 @@
  * Implementation of hook_comment().
  */
 function fivestar_comment(&$comment, $op) {
+  // Performance tweak don't do any processing on validate or publish
+  if ($op == 'validate' || $op == 'publish') {
+    return;
+  }
+
   if (is_array($comment) && is_numeric($comment['nid'])) {
     $nid = $comment['nid'];
   }
@@ -103,67 +124,90 @@
 
   if (isset($nid)) {
     $node = node_load($nid);
-    $fivestar_status = variable_get('fivestar_comment_'. $node->type, FIVESTAR_COMMENT_DISABLED);
   }
 
   switch ($op) {
     case 'view':
-      if ($fivestar_status != FIVESTAR_COMMENT_DISABLED) {
-        if (!isset($comment->fivestar_rating)) {
-          $current_rating = fivestar_comment_load($comment->cid, $comment->nid);
-          $comment->fivestar_rating = isset($current_rating['value']) ? $current_rating['value'] : NULL;
-        }
-        $comment->fivestar_rating = $comment->fivestar_rating;
-        $comment->fivestar_view = theme('fivestar_static', $comment->fivestar_rating, variable_get('fivestar_stars_'. $node->type, 5));
-        if ($comment->fivestar_rating) {
-          // Implement the theme in template.php to change the order:
-          $comment->comment = theme('fivestar_comment_view', $comment->comment, $comment->fivestar_view);
+      foreach (fivestar_get_tags() as $tag) {
+        $var_suffix = fivestar_var_suffix($node->type, $tag); 
+        $fivestar_status = variable_get('fivestar_comment'. $var_suffix, FIVESTAR_COMMENT_DISABLED);
+    
+        if ($fivestar_status != FIVESTAR_COMMENT_DISABLED) {
+          $fivestar_rating_tag = fivestar_rating_tag_.$tag;
+          if (!isset($comment->$fivestar_rating_tag)) {
+            $current_rating = fivestar_comment_load($comment->cid, $comment->nid);
+            $comment->$fivestar_rating_tag = isset($current_rating[$tag]['value']) ? $current_rating[$tag]['value'] : NULL;
+          }
+          $comment->$fivestar_rating_tag = $comment->$fivestar_rating_tag;
+          $comment->fivestar_view .= theme('fivestar_static', $comment->$fivestar_rating_tag, variable_get('fivestar_stars_'. $node->type, 5));
         }
       }
+      $comment->comment .= theme('fivestar_comment_view', $comment->comment, $comment->fivestar_view);
       break;
     case 'insert':
-      if ($fivestar_status != FIVESTAR_COMMENT_DISABLED) {
-        $comment = (object)$comment; // Comment module is inconsistent about comment data structures.
-        if ($comment->fivestar_rating) {
-          fivestar_comment_insert($comment->cid, $comment->nid, $comment->uid, $comment->fivestar_rating);
+      foreach (fivestar_get_tags() as $tag) {
+        $var_suffix = fivestar_var_suffix($node->type, $tag); 
+        $fivestar_status = variable_get('fivestar_comment'. $var_suffix, FIVESTAR_COMMENT_DISABLED);
+        
+        if ($fivestar_status != FIVESTAR_COMMENT_DISABLED) {
+          $fivestar_rating_tag = fivestar_rating_tag_.$tag;
+          $comment = (object)$comment; // Comment module is inconsistent about comment data structures.
+          if ($comment->$fivestar_rating_tag) {
+            fivestar_comment_insert($comment->cid, $comment->nid, $comment->uid, $comment->$fivestar_rating_tag, $tag);
+          }
+          $comment = (array)$comment;
         }
-        $comment = (array)$comment;
       }
     case 'update':
-      if ($fivestar_status != FIVESTAR_COMMENT_DISABLED) {
-        $comment = (object)$comment; // Comment module is inconsistent about comment data structures.
-        $current_rating = fivestar_comment_load($comment->cid, $comment->nid);
-        if ($comment->fivestar_rating) {
-          if (isset($current_rating['value'])) {
-            fivestar_comment_update($comment->cid, $comment->nid, $comment->uid, $comment->fivestar_rating);
+      foreach (fivestar_get_tags() as $tag) {
+        $var_suffix = fivestar_var_suffix($node->type, $tag); 
+        $fivestar_status = variable_get('fivestar_comment'. $var_suffix, FIVESTAR_COMMENT_DISABLED);
+        
+        if ($fivestar_status != FIVESTAR_COMMENT_DISABLED) {
+          $fivestar_rating_tag = fivestar_rating_tag_.$tag;
+          $comment = (object)$comment; // Comment module is inconsistent about comment data structures.
+          $current_rating = fivestar_comment_load($comment->cid, $comment->nid);
+          if ($comment->$fivestar_rating_tag) {
+            if (isset($current_rating[$tag]['value'])) {
+              fivestar_comment_update($comment->cid, $comment->nid, $comment->uid, $comment->$fivestar_rating_tag, $tag);
+            }
+            else {
+              fivestar_comment_insert($comment->cid, $comment->nid, $comment->uid, $comment->$fivestar_rating_tag, $tag);
+            }
           }
-          else {
-            fivestar_comment_insert($comment->cid, $comment->nid, $comment->uid, $comment->fivestar_rating);
+          elseif ($fivestar_status != FIVESTAR_COMMENT_DISABLED && isset($current_rating[$tag]['vote_id'])) {
+            $votes_for_deletion[] = fivestar_comment_vote_to_delete($comment->cid, $comment->nid, $current_rating[$tag]['vote_id']);
           }
+          $comment = (array)$comment;
         }
-        elseif ($fivestar_status != FIVESTAR_COMMENT_DISABLED && isset($current_rating['value'])) {
-          fivestar_comment_delete($comment->cid, $comment->nid, $comment->uid);
-        }
-        $comment = (array)$comment;
       }
+      
+      fivestar_comment_delete($comment->cid, $comment->nid, $votes_for_deletion);
       break;
     case 'delete':
-      $current_rating = fivestar_comment_load($comment->cid, $comment->nid);
-      if (isset($current_rating['value'])) {
-        fivestar_comment_delete($comment->cid, $comment->nid, $current_rating['vote_id']);
+      foreach (fivestar_get_tags() as $tag) {
+        $current_rating = fivestar_comment_load($comment->cid, $comment->nid);
+        if (isset($current_rating[$tag]['vote_id'])) {
+          $votes_for_deletion[] = fivestar_comment_vote_to_delete($comment->cid, $comment->nid, $current_rating[$tag]['vote_id']);  
+        }
       }
+      fivestar_comment_delete($comment->cid, $comment->nid, $votes_for_deletion);
       break;
   }
 }
 
 /**
- * Get a current rating for a comment.
+ * Get a current rating(s) for a comment.
  */
 function fivestar_comment_load($cid, $nid, $reset = FALSE) {
   global $user;
   static $cids = array();
   if (!isset($cids[$cid]) || $reset) {
-    $cids[$cid] = db_fetch_array(db_query('SELECT * FROM {fivestar_comment} WHERE cid = %d', $cid));
+    $result = db_query('SELECT * FROM {fivestar_comment} WHERE cid = %d', $cid);
+    
+    while($data = db_fetch_array($result)) {
+      $cids[$cid][$data['tag']] = $data;
+    }
   }
   return $cids[$cid];
 }
@@ -171,33 +215,47 @@
 /**
  * Update a fivestar comment value.
  */
-function fivestar_comment_update($cid, $nid, $uid, $value) {
-  $vote = _fivestar_cast_vote('node', $nid, $value, 'vote', $uid);
-  db_query('UPDATE {fivestar_comment} SET value = %d, vote_id = %d WHERE cid = %d', $value, $vote['user']['vote_id'], $cid);
+function fivestar_comment_update($cid, $nid, $uid, $value, $tag = 'vote') {
+  $vote = _fivestar_cast_vote('node', $nid, $value, $tag, $uid);
+  db_query("UPDATE {fivestar_comment} SET value = %d, vote_id = %d WHERE cid = %d AND tag = '%s'", $value, $vote['user']['vote_id'], $cid, $tag);
 }
 
 /**
  * Insert a fivestar comment value.
  */
-function fivestar_comment_insert($cid, $nid, $uid, $value) {
-  $vote = _fivestar_cast_vote('node', $nid, $value, 'vote', $uid);
-  db_query('INSERT INTO {fivestar_comment} (cid, value) VALUES (%d, %d)', $cid, $vote['user']['vote_id'], $value);
+function fivestar_comment_insert($cid, $nid, $uid, $value, $tag = 'vote') {
+  $vote = _fivestar_cast_vote('node', $nid, $value, $tag, $uid);
+  
+  if (isset($vote['user']['vote_id'])) {
+    db_query("INSERT INTO {fivestar_comment} (cid, vote_id, value, tag) VALUES (%d, %d, %d, '%s')", $cid, $vote['user']['vote_id'], $value, $tag);
+  }
 }
 
 /**
  * Delete any value for a comment and update their vote.
  */
-function fivestar_comment_delete($cid, $nid, $vote_id) {
-  db_query('DELETE FROM {fivestar_comment} WHERE cid = %d', $cid);
+function fivestar_comment_delete($cid, $nid, $votes_for_deletion) {
+  if (isset($votes_for_deletion)) {
+    db_query('DELETE FROM {fivestar_comment} WHERE cid = %d', $cid);
+    votingapi_delete_votes($votes_for_deletion);
+    votingapi_recalculate_results('node', $nid);
+  }
+}
 
+/**
+ * Create a vote for deletion
+ */
+function fivestar_comment_vote_to_delete($cid, $nid, $vote_id) {
   $vote = array();
   $vote['content_id'] = $nid;
   $vote['content_type'] = 'node';
   $vote['vote_id'] = $vote_id;
-  votingapi_delete_votes(array($vote));
-  votingapi_recalculate_results('node', $nid);
+  return $vote;
 }
 
+/**
+ * Theme fivestar comment view
+ */
 function theme_fivestar_comment_view($comment, $fivestar) {
   return $fivestar . $comment;
 }
--- C:/cygwin/home/drupaldev/fivestar-DRUPAL-6--1/fivestar_comment.install	Sun Oct 05 22:09:00 2008
+++ Z:/environment/www/modules/sites/all/modules/fivestar/fivestar_comment.install	Thu Apr 16 15:07:24 2009
@@ -50,3 +50,36 @@
 
   return $ret;
 }
+
+/**
+ * Add tag column to the fivestar_comment table. It populates any existing data
+ * with the default value for the tag column (i.e. vote)
+ */
+function fivestar_comment_update_6101() {
+  $ret = array();
+
+  // Do longer need the vote_id index from previous update as it it is now
+  // a composite key and will have an index by default
+  db_drop_index($ret, 'fivestar_comment', 'vote_id');
+  
+  // Need to add an index otherwise won't be able to drop primary on serial column
+  // see: http://drupal.org/node/190027 for more info
+  db_add_index($ret, 'fivestar_comment', 'cid', array('cid'));
+  db_drop_primary_key($ret, 'fivestar_comment');
+  db_add_primary_key($ret, 'fivestar_comment', array('cid', 'vote_id'));
+  db_drop_index($ret, 'fivestar_comment', 'cid');
+
+  // Add new tag field, allow nulls until field data entered 
+  db_add_field($ret, 'fivestar_comment', 'tag', array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'default' => 'vote'));
+  
+  // Lets make sure the new tag column has the default data for any existing rows
+  $comments = db_query('SELECT * FROM {fivestar_comment}');
+  while ($comment = db_fetch_object($comments)) {
+    db_query("UPDATE {fivestar_comment} SET tag = '%s' WHERE cid = %d", 'vote', $comment->cid);
+  }
+  
+  // Set field to not allow nulls
+  db_change_field($ret, 'fivestar_comment', 'tag', 'tag', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'));
+
+  return $ret;
+}
