Index: voting_actions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/voting_actions/voting_actions.module,v
retrieving revision 1.15.2.1
diff -u -r1.15.2.1 voting_actions.module
--- voting_actions.module	17 Apr 2007 21:59:36 -0000	1.15.2.1
+++ voting_actions.module	20 Nov 2007 15:59:54 -0000
@@ -1,10 +1,12 @@
 <?php
-// $Id: voting_actions.module,v 1.15.2.1 2007/04/17 21:59:36 eaton Exp $
+// $Id: voting_actions.module,v 1.15.2.4 2007/04/20 19:46:32 eaton Exp $
 
 /**
  * Lets users directly control the votingapi's integration with the actions module.
  */
- 
+ //include fix by newskicks team
+//visit us at: http://newskicks.com
+
 // Some initial constants.
 define(VOTING_ACTIONS_STATE_ENABLED, 1);
 define(VOTING_ACTIONS_STATE_OVERRIDDEN, 2);
@@ -79,8 +81,9 @@
 
 // Called by the Voting API whenever a result is calculated.
 function voting_actions_votingapi_results($cached, $votes, $content_type, $content_id) {
+//print "inside votingAPIresult<br>";
   $content = votingapi_load_content($content_id, $content_type);
-  if ($content == NULL) {
+  if ($content_type != 'node' || $content == NULL) {
     return;
   }
   $context = array(
@@ -101,7 +104,8 @@
 
 // Other helper functions build the actions cache from the database.
 function voting_actions_process_results($context) {
-  if (($data = cache_get('voting_actions_cache')) == FALSE) {
+//print "inside votingAPIProcessResult<br>";  
+if (($data = cache_get('voting_actions_cache')) == FALSE) {
     $action_sets = voting_actions_get_sets();
   }
   elseif (($action_sets = unserialize($data->data)) == FALSE) {
@@ -109,10 +113,10 @@
   }
   if (is_array($action_sets)) {
     foreach ($action_sets as $action_set) {
-      if (!empty($action_set['status'])) {
+      if (!empty($action_set['status']) && $action_set['status'] == VOTING_ACTIONS_STATE_ENABLED) {
         $actions = array();
-        if (_voting_actions_process_set($context, $action_set, $actions) == TRUE) {
-          actions_do($actions, $content);
+        if (_voting_actions_process_set($context, $action_set, $actions) === TRUE) {
+          actions_do($actions, $context['content']);
         }
       }
     }
@@ -124,6 +128,7 @@
  * Internal functions used to evaluate sets of actions, and individual conditions.
  */
 function _voting_actions_process_set($context = array(), $action_set = array(), &$actions) {  
+//print "inside votingAPIProcessSet<br>";
   // a little safety code to catch malformed sets.
   $action_set += _voting_actions_populate_set_defaults();
 
@@ -156,23 +161,23 @@
   if ($set_result == TRUE) {
     // Now check sub-actions.
 
-    foreach ($action_set['subsets'] as $subset) {
+    foreach ($action_set['sets'] as $subset) {
       // check the required flag of the subset. if it is, evaluate it.
       if ($subset['required'] == TRUE) {
         $set_result = $set_result && _voting_actions_process_set($context, $subset, $actions);
-        if ($set_result == FALSE) {
+        if ($set_result === FALSE) {
           return FALSE;
         }
       }
     }
 
-    if ($set_result == TRUE) {
+    if ($set_result === TRUE) {
       // It's still true after executing required subsets. Add the actions, then process optional subsets.
       foreach ($action_set['actions'] as $action) {
         $actions[] = $action;
       }
       
-      foreach ($action_set['subsets'] as $subset) {
+      foreach ($action_set['sets'] as $subset) {
         // now handle the non-required subsets
         if ($subset['required'] == FALSE) {
           _voting_actions_process_set($context, $subset, $actions);
@@ -185,12 +190,17 @@
 }
 
 function _voting_actions_process_condition($condition = array(), $context = array()) {
+//print "inside VotingActionProcessCondition<br>";
   $condition_cache = voting_actions_get_conditions();
   if ($condition_definition = $condition_cache[$condition['name']]) {
     $function = $condition_definition['eval_handler'];
+//print $function;
     if (function_exists($function)) {
       return $function($context, $condition);
     }
+     else{
+    print "Function Does not Exists?<br>";
+    }
   }
   
   return FALSE;
@@ -288,7 +298,7 @@
     }
     
     $set['status'] = voting_actions_get_status($set['name']);
-    $set['subsets'] = _voting_actions_load_sets_from_db($vasid);
+    $set['sets'] = _voting_actions_load_sets_from_db($set['vasid']);
     $sets[$set['name']] = $set;
   }
   
@@ -305,9 +315,7 @@
   db_query($sql, $vasid, $set['name'], $set['parent'],
     $set['source'], $set['description'], $set['condition_mask'], 
     $set['required'], $set['weight']);
-  
-  voting_actions_set_status($set['name'], $set['status']);
-  
+    
   if (is_array($set['conditions'])) {
     foreach ($set['conditions'] as $condition) {
       $condition['vasid'] = $vasid;
@@ -320,13 +328,6 @@
       db_query("INSERT INTO {voting_actions_action} (vasid, aid) VALUES (%d, '%s')", $vasid, $action);
     }
   }
-
-  if (is_array($set['sets'])) {
-    foreach ($set['sets'] as $sname => $subset) {
-      $subset['parent_name'] = $name;
-      _voting_actions_insert_set($subset);
-    }
-  }
 }
 
 function _voting_actions_insert_condition($condition) {
@@ -350,17 +351,23 @@
     $set['source'], $set['description'], $set['condition_mask'], 
     $set['required'], $set['weight'], $set['vasid']);
 
-  voting_actions_set_status($set['name'], $set['status']);
-
   if (is_array($set['conditions'])) {
+    // First we'll loop through and delete any that are
+    // in the db but not in the new version of the set.
+    $current_sets = array();
+    $current_sets['replacements'][] = $set['vasid'];
     foreach ($set['conditions'] as $condition) {
       if (isset($condition['vacid'])) {
-        if (!empty($condition['deleted'])) {
-          db_query("DELETE FROM {voting_actions_condition} WHERE vacid = %d", $set['vacid']);
-        }
-        else {
-          _voting_actions_update_condition($condition);
-        }
+        $current_sets['wildcards'][] = '%d';
+        $current_sets['replacements'][] = $condition['vacid'];
+      }
+    }
+    db_query("DELETE FROM {voting_actions_condition} WHERE vasid = %d AND vacid NOT IN (". implode(',', $current_sets['wildcards']) .")", $current_sets['replacements']);
+
+    foreach ($set['conditions'] as $condition) {
+      $condition['vasid'] = $set['vasid'];
+      if (isset($condition['vacid'])) {
+        _voting_actions_update_condition($condition);
       }
       else {
         _voting_actions_insert_condition($condition);
@@ -374,24 +381,7 @@
   db_query("DELETE FROM {voting_actions_action} WHERE vasid = %d", $set['vasid']);
   if (is_array($set['actions'])) {
     foreach ($set['actions'] as $action) {
-      db_query("INSERT INTO {voting_actions_action} (parent_name, aid) VALUES ('%s', %d)", $name, $set['vasid']);
-    }
-  }
-  
-  if (is_array($set['sets'])) {
-    foreach ($set['sets'] as $subset) {
-      if (isset($subset['vasid'])) {
-        _voting_actions_update_set($subset);
-      }
-      else {
-        _voting_actions_insert_set($subset);
-      }
-    }
-  }
-
-  if (is_array($set['deleted_sets'])) {
-    foreach ($set['deleted_sets'] as $subset) {
-      _voting_actions_delete_set($subset);
+      db_query("INSERT INTO {voting_actions_action} (vasid, aid) VALUES (%d, '%s')", $set['vasid'], $action);
     }
   }
 }
@@ -415,7 +405,6 @@
   db_query("DELETE FROM {voting_actions_condition} WHERE vasid = %d", $set['vasid']);
   db_query("DELETE FROM {voting_actions_action} WHERE vasid = %d", $set['vasid']);
   db_query("DELETE FROM {voting_actions_set} WHERE vasid = %d", $set['vasid']);
-  db_query("DELETE FROM {voting_actions_status} WHERE name = %d", $set['name']);
 }
 
 function _voting_actions_validate_set($set) {
@@ -454,17 +443,17 @@
 function _voting_actions_validate_condition($condition) {
   $errors = array();
   if (!is_array($condition)) {
-    $errors[] = "The condition is not an array!";
+    $errors[] = t("The condition is not an array!");
     return $errors;
   }
 
   if (!isset($condition['eval_handler'])) {
-    $errors[] = "The condition has no handler.";
+    $errors[] = t("The condition has no handler.");
   }
 
   if (!function_exists($condition['eval_handler'])) {
     $handler = $condition['eval_handler'];
-    $errors[] = "The condition has an invalid handler ($eval_handler).";
+    $errors[] = t("The condition has an invalid handler (@handler).", array('@handler' => $eval_handler));
   }
 
   return $errors;
@@ -478,6 +467,6 @@
     'weight' => 0,
     'conditions' => array(),
     'actions' => array(),
-    'subsets' => array(),
+    'sets' => array(),
   );
 }
\ No newline at end of file
Index: voting_actions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/voting_actions/voting_actions.inc,v
retrieving revision 1.7.2.1
diff -u -r1.7.2.1 voting_actions.inc
--- voting_actions.inc	17 Apr 2007 21:59:36 -0000	1.7.2.1
+++ voting_actions.inc	20 Nov 2007 15:59:36 -0000
@@ -1,11 +1,13 @@
 <?php
-// $Id: voting_actions.inc,v 1.7.2.1 2007/04/17 21:59:36 eaton Exp $
+// $Id: voting_actions.inc,v 1.7.2.5 2007/04/20 19:46:32 eaton Exp $
+//include fix by newskicks team
+//visit us at: http://newskicks.com
 
 function voting_actions_voting_actions_conditions() {
   $condition = array();
 
   $condition['individual_vote'] = array(
-    'name' => t('Individual vote'),
+    'name' => t('Any individual vote'),
     'description' => t('Return true if any item in the collection of cast votes matches these criteria.'),
     'eval_handler' => 'voting_actions_individual_vote_handler',
     'edit_handler' => 'voting_actions_vote_form',
@@ -19,7 +21,7 @@
   );
 
   $condition['vote_result'] = array(
-    'name' => t('Vote result'),
+    'name' => t('Any vote result'),
     'description' => t('Return true if a vote result matches these criteria.'),
     'eval_handler' => 'voting_actions_vote_result_handler',
     'edit_handler' => 'voting_actions_vote_result_form',
@@ -45,10 +47,10 @@
 function _voting_actions_string_operators() {
   return array(
     '==' => t('Is'),
+    '!=' => t('Is not'),
     'contains' => t('Contains'),
     'excludes' => t('Does not contain'),
     'starts' => t('Stars with'),
-    'ends' => t('Ends with'),
   );
 }
 
@@ -98,8 +100,13 @@
 }
 
 function voting_actions_all_votes_handler($context, $condition) {
+$i=0;
+//foreach ($context['votes'] as $vote){
+//$i++;
+//}
+//print "<br>votes:".$i;
   foreach ($context['votes'] as $vote) {
-    if (!empty($condition['data']['value_type'])) {
+if (!empty($condition['data']['value_type'])) {
       if ($condition['data']['value_type'] != $vote->value_type) {
         continue;
       }
@@ -109,14 +116,18 @@
         continue;
       }
     }
-    if (_voting_actions_compare($vote->value, $condition['data']['operator'], $condition['data']['value']) == FALSE) {
-      return FALSE;
+    $i+=$vote->value;
     }
-  }
-  return TRUE;
+    if (_voting_actions_compare($i, $condition['data']['operator'], $condition['data']['value']) == FALSE) {
+      return FALSE;
+      }
+   return TRUE;
 }
 
 function voting_actions_vote_form($values = array()) {
+  if ($values === NULL) {
+    $values = array();
+  }
   $values += array(
     'value_type' => '',
     'tag' => '',
@@ -126,13 +137,13 @@
 
   $form['value_type'] = array(
     '#type' => 'select',
-    '#options' => _voting_actions_table_values('value_type', 'vote', array('' => t('(Ignore)'), 'percent' => t('Percent'), 'points' => t('Points'))),
+    '#options' => _voting_actions_table_values('value_type', 'vote', array('' => t('--'), 'percent' => t('Percent'), 'points' => t('Points'))),
     '#default_value' => $values['value_type'],
   );
 
   $form['tag'] = array(
     '#type' => 'select',
-    '#options' => _voting_actions_table_values('tag', 'vote', array('' => t('(Ignore)'), 'percent' => t('Vote'))),
+    '#options' => _voting_actions_table_values('tag', 'vote', array('' => t('--'), 'vote' => t('Vote'))),
     '#default_value' => $values['tag'],
   );
 
@@ -145,6 +156,7 @@
   $form['value'] = array(
     '#type' => 'textfield',
     '#default_value' => $values['value'],
+    '#size' => 5,
   );
   return $form;
 }
@@ -176,7 +188,10 @@
   return TRUE;
 }
 
-function voting_actions_vote_results_form($values = array()) {
+function voting_actions_vote_result_form($values = array()) {
+  if ($values === NULL) {
+    $values = array();
+  }
   $values += array(
     'value_type' => '',
     'tag' => '',
@@ -187,19 +202,19 @@
 
   $form['value_type'] = array(
     '#type' => 'select',
-    '#options' => _voting_actions_table_values('value_type', 'cache', array('' => t('(Ignore)'), 'percent' => t('Percent'), 'points' => t('Points'))),
+    '#options' => _voting_actions_table_values('value_type', 'cache', array('' => t('--'), 'percent' => t('Percent'), 'points' => t('Points'))),
     '#default_value' => $values['value_type'],
   );
 
   $form['tag'] = array(
     '#type' => 'select',
-    '#options' => _voting_actions_table_values('tag', 'cache', array('' => t('(Ignore)'), 'percent' => t('Vote'))),
+    '#options' => _voting_actions_table_values('tag', 'cache', array('' => t('--'), 'vote' => t('Vote'))),
     '#default_value' => $values['tag'],
   );
 
   $form['function'] = array(
     '#type' => 'select',
-    '#options' => _voting_actions_table_values('function', 'cache', array('' => t('(Ignore)'), 'average' => t('Average'), 'count' => t('Count'))),
+    '#options' => _voting_actions_table_values('function', 'cache', array('' => t('--'), 'average' => t('Average'), 'count' => t('Count'))),
     '#default_value' => $values['function'],
   );
 
@@ -212,6 +227,7 @@
   $form['value'] = array(
     '#type' => 'textfield',
     '#default_value' => $values['value'],
+    '#size' => 5,
   );
   return $form;
 }
@@ -219,12 +235,45 @@
 
 // Returns true if a specific property of the content object matches the criteria.
 function voting_actions_content_property_handler($context, $condition) {
-  if (!empty($condition['data']['property']) && !empty($context['contet']->$condition['data']['property'])) {
-    return _voting_actions_compare($context['content']->$condition['data']['property'], $condition['data']['operator'], $condition['data']['value']);
+  if (($prop = $condition['data']['property']) && ($content = $context['content'])) {
+    return _voting_actions_compare($content->$prop, $condition['data']['operator'], $condition['data']['value']);
   }
   return FALSE;
 }
 
+function voting_actions_content_property_form($values = array()) {
+  if ($values === NULL) {
+    $values = array();
+  }
+  $values += array(
+    'property' => '',
+    'operator' => '',
+    'value' => '',
+  );
+
+  $form['property'] = array(
+    '#prefix' => '$node->',
+    '#type' => 'textfield',
+    '#default_value' => $values['property'],
+    '#size' => 10,
+  );
+
+  $options = array_merge(_voting_actions_string_operators(), _voting_actions_number_operators());
+
+  $form['operator'] = array(
+    '#type' => 'select',
+    '#options' => $options,
+    '#default_value' => $values['operator'],
+  );
+  
+  $form['value'] = array(
+    '#type' => 'textfield',
+    '#default_value' => $values['value'],
+    '#size' => 5,
+  );
+  return $form;
+}
+
 // Returns true if the author's content has the specified permission.
 function voting_actions_content_author_perm_handler($context, $condition) {
   if (!empty($context['content']->uid)) {
@@ -234,6 +283,16 @@
   return FALSE;
 }
 
+function voting_actions_content_author_perm_form($values = array()) {
+  $perms = module_invoke_all('perm');
+  $form['perm'] = array(
+    '#type' => 'select',
+    '#options' => $perms,
+    '#default_value' => $values['perm'],
+  );
+  return $form;
+}
+
 function _voting_actions_table_values($field = 'tag', $table = 'vote', $force = array()) {
   static $cached;
   if (!isset($cached[$table][$field])) {
@@ -259,6 +318,7 @@
       return ($left != $right);
       break;
     case "<":
+    //print "in less<br>";
       return ($left < $right);
       break;
     case "<=":
@@ -268,6 +328,7 @@
       return ($left >= $right);
       break;
     case ">":
+    //print "in greater<br>"."left".$left."right".$right;
       return ($left > $right);
       break;
     case "contains":
@@ -276,13 +337,25 @@
         return (isset($tmp[$right]));
       }
       else {
+        return (strrpos($left, $right) !== FALSE);
       }
       break;
     case "excludes":
+      if (is_array($left)) {
+        $tmp = array_flip($left);
+        return (!isset($tmp[$right]));
+      }
+      else {
+        return (strrpos($left, $right) === FALSE);
+      }
       break;
     case "starts":
-      break;
-    case "ends":
+      if (is_array($left)) {
+        return ($tmp[0] == $right);
+      }
+      else {
+        return (strrpos($left, $right) === 0);
+      }
       break;
   }
   return $default;
