--- vote_up_down.module.orig 2007-08-24 01:15:48.000000000 -0400 +++ vote_up_down.module 2007-09-03 05:31:55.000000000 -0400 @@ -315,6 +315,13 @@ '#size' => 5, '#maxlength' => 5, ); + $form['vote_updown_points']['userpoints_vote_up_down_content_rating'] = array( + '#type' => 'textfield', + '#title' => t('Points from ratings on submitted content (requires the Vote up/down module)'), + '#default_value' => variable_get('userpoints_vote_up_down_content_rating', 0), + '#size' => 5, + '#maxlength' => 5, + ); return $form; break; @@ -471,9 +478,35 @@ 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); + } else { + 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)); + } + if (votingapi_get_user_votes($type, $cid, $user->uid)) { + // we record the current rating of the node + $vote_result = votingapi_get_voting_result($type, $cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum'); + $vote_old = $vote_result; + // let the module do its work + votingapi_set_vote($type, $cid, $vote, $uid); + // get the new rating + $vote_result = votingapi_get_voting_result($type, $cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum'); + $vote_new = $vote_result; + // calculate the difference + $diff->value = $vote_new->value - $vote_old->value; + // and add/subtract the same number of userpoints + if ( variable_get('userpoints_vote_up_down_content_rating', 0) ) { + userpoints_userpointsapi('points', ($diff->value * variable_get('userpoints_vote_up_down_content_rating', 0)), $node->uid, 'Vote up/down karma'); + } + } else { + votingapi_set_vote($type, $cid, $vote, $uid); + // or, if it's the first time that user votes, just send the same vote to userpoints + if ( variable_get('userpoints_vote_up_down_content_rating', 0) ) { + userpoints_userpointsapi('points', ($vote->value * variable_get('userpoints_vote_up_down_content_rating', 0)), $node->uid, 'Vote up/down karma'); + } + } } }