435a436,483
>  * Helper to interact with database.
>  */
> function vote_up_down_submitVote($type, $cid, $value){
> 	if (!is_numeric($cid) || !is_numeric($value))
> 		return false;
> 
> 	// Sanity-check the incoming values.
> 	if ($value > 0) {
> 	  $vote->value = 1;
> 	}
> 	else if ($value < 0) {
> 	  $vote->value = -1;
> 	}
> 	else {
> 	  $vote->value = 0;
> 	}
> 	
> 	$vote->value_type = 'points';
> 	$vote->tag = variable_get('vote_up_down_tag', 'vote');
> 	
> 	// Userpoints integration.
> 	if (module_exists('userpoints')) {
> 	  global $user;
> 	  if ($type == 'node') {
> 		$node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.uid FROM {node} n WHERE n.nid = %d'), $cid));
> 	  } else {
> 		$node = db_fetch_object(db_query(db_rewrite_sql('SELECT c.uid FROM {comments} c WHERE c.cid = %d'), $cid));
> 	  }
> 	  $user_vote = votingapi_get_user_votes($type, $cid, $user->uid);
> 	  if ($user->uid && !$user_vote && ($node->uid != $user->uid) && ($vote->value != 0)) {
> 		userpoints_userpointsapi('points', variable_get('userpoints_vote_up_down', 0), $user->uid, 'Vote up/down points');
> 	  }
> 	}
> 	
> 	// Do the voting via voting api.
> 	if ($uid = _vote_up_down_get_uid()) {
> 	  if ($vote->value == 0) {
> 		votingapi_unset_vote($type, $cid, $uid);
> 	  }
> 	  else {
> 		votingapi_set_vote($type, $cid, $vote, $uid);
> 	  }
> 	}
> 	
> 	return true;
> }
> 
> /**
439,478c487
<   if (is_numeric($cid) && is_numeric($value)) {
< 
<     // Sanity-check the incoming values.
<     if ($value > 0) {
<       $vote->value = 1;
<     }
<     else if ($value < 0) {
<       $vote->value = -1;
<     }
<     else {
<       $vote->value = 0;
<     }
< 
<     $vote->value_type = 'points';
<     $vote->tag = variable_get('vote_up_down_tag', 'vote');
< 
<     // Userpoints integration.
<     if (module_exists('userpoints')) {
<       global $user;
<       if ($type == 'node') {
<         $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.uid FROM {node} n WHERE n.nid = %d'), $cid));
<       }
<       else {
<         $node = db_fetch_object(db_query(db_rewrite_sql('SELECT c.uid FROM {comments} c WHERE c.cid = %d'), $cid));
<       }
<       $user_vote = votingapi_get_user_votes($type, $cid, $user->uid);
<       if ($user->uid && !$user_vote && ($node->uid != $user->uid) && ($vote->value != 0)) {
<         userpoints_userpointsapi('points', variable_get('userpoints_vote_up_down', 0), $user->uid, 'Vote up/down points');
<       }
<     }
< 
<     // Do the voting via voting api.
<     if ($uid = _vote_up_down_get_uid()) {
<       if ($vote->value == 0) {
<         votingapi_unset_vote($type, $cid, $uid);
<       }
<       else {
<         votingapi_set_vote($type, $cid, $vote, $uid);
<       }
<     }
---
> 	vote_up_down_submitVote($type, $cid, $value);
488c497
<   }
---
>   
558a568,574
> /*
>  * Helper function
>  */
> function vote_up_down_points_result($type, $cid){
> 	return votingapi_get_voting_result($type, $cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum');
> }
> 
560c576
<   $vote_result = votingapi_get_voting_result($type, $cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum');
---
>   $vote_result = vote_up_down_points_result($type, $cid);
