*** extra_voting_forms.module 2009-12-06 03:10:22.000000000 +0200 --- extra_voting_forms.module.anonymous4 2009-12-12 00:06:24.000000000 +0200 *************** *** 574,580 **** // Convert the limit into seconds... $limit_every *= 3600; ! $result = db_result(db_query("SELECT COUNT(*) AS count FROM {votingapi_vote} WHERE uid = %d AND value_type = '%s' AND tag = '%s' AND timestamp > UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - %d", $account->uid, 'points', 'vote', $limit_every)); // Over the limit: don't accept it! if ($result > $limit) { --- 574,586 ---- // Convert the limit into seconds... $limit_every *= 3600; ! ! // Marinski: I added a query to get the relevant data for anonymous user. We must check the vote_source field for the IP and match it against the current user's IP ! if ($account->uid==0) { ! $result = db_result(db_query("SELECT COUNT(*) AS count FROM {votingapi_vote} WHERE uid = %d AND vote_source = '%s' AND value_type = '%s' AND tag = '%s' AND timestamp > UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - %d", 0, ip_address(), 'points', 'vote', $limit_every)); ! } else { ! $result = db_result(db_query("SELECT COUNT(*) AS count FROM {votingapi_vote} WHERE uid = %d AND value_type = '%s' AND tag = '%s' AND timestamp > UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - %d", $account->uid, 'points', 'vote', $limit_every)); ! } // Over the limit: don't accept it! if ($result > $limit) { *************** *** 616,623 **** $total_every *= 3600; // Find out how many points were awarded over the last however long ! $result = db_result(db_query("SELECT SUM(abs(value)) FROM {votingapi_vote} WHERE uid = %d AND value_type = '%s' AND tag = '%s' AND timestamp > UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - %d", $account->uid, 'points', 'vote', $total_every)); $result += abs($vote); --- 622,633 ---- $total_every *= 3600; // Find out how many points were awarded over the last however long ! // Marinski: I added a query to get the relevant data for anonymous user. We must check the vote_source field for the IP and match it against the current user's IP ! if ($account->uid==0) { ! $result = db_result(db_query("SELECT SUM(abs(value)) FROM {votingapi_vote} WHERE uid = %d AND vote_source = '%s' AND value_type = '%s' AND tag = '%s' AND timestamp > UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - %d", 0, ip_address(), 'points', 'vote', $total_every)); ! } else { $result = db_result(db_query("SELECT SUM(abs(value)) FROM {votingapi_vote} WHERE uid = %d AND value_type = '%s' AND tag = '%s' AND timestamp > UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - %d", $account->uid, 'points', 'vote', $total_every)); + } $result += abs($vote); *************** *** 733,739 **** // It's a direct form, and the user doesn't // have voting rights! ! if ($form_type != 'ajax' && $user->uid == 0) { drupal_goto(extra_voting_forms_anonymous_url(), "destination=". extra_voting_forms_destination($o) ); } --- 743,750 ---- // It's a direct form, and the user doesn't // have voting rights! ! // Marinski: check the anonymous user's access permissions to see if they must be redirected ! if ($form_type != 'ajax' && $user->uid == 0 && ! user_access('give points with extra voting forms') ) { drupal_goto(extra_voting_forms_anonymous_url(), "destination=". extra_voting_forms_destination($o) ); } *************** *** 773,779 **** } // The user is not logged in: RETURN with error ! if ($account->uid == 0) { return array( t("Only logged in users can vote!"), 0 ); } --- 784,791 ---- } // The user is not logged in: RETURN with error ! // Marinski: check if anonymous voting is allowed and if yes - skip check ! if ($account->uid == 0 && ! user_access('give points with extra voting forms') ) { return array( t("Only logged in users can vote!"), 0 ); } *************** *** 824,830 **** $criteria['tag'] = 'vote'; $criteria['uid'] = $account->uid; ! $existing_vote_cast = votingapi_select_votes($criteria); $existing_vote = (int)$existing_vote_cast[0]['value']; if ($only_one_vote_allowed && ! user_access('voting administrator', $account) && $existing_vote != 0) { --- 837,846 ---- $criteria['tag'] = 'vote'; $criteria['uid'] = $account->uid; ! // Marinski: This part is taken from the fivestar module :) ! $user_criteria = votingapi_current_user_identifier(); ! ! $existing_vote_cast = votingapi_select_votes($criteria + $user_criteria); $existing_vote = (int)$existing_vote_cast[0]['value']; if ($only_one_vote_allowed && ! user_access('voting administrator', $account) && $existing_vote != 0) { *************** *** 1105,1111 **** $criteria['value_type'] = 'points'; $criteria['tag'] = 'vote'; $criteria['uid'] = $user->uid; ! $existing_vote_cast = votingapi_select_votes($criteria); // Integer representation of the vote $existing_vote = (int)$existing_vote_cast[0]['value']; --- 1121,1131 ---- $criteria['value_type'] = 'points'; $criteria['tag'] = 'vote'; $criteria['uid'] = $user->uid; ! ! // Marinski: This part is taken from the fivestar module :) ! $user_criteria = votingapi_current_user_identifier(); ! ! $existing_vote_cast = votingapi_select_votes($criteria + $user_criteria); // Integer representation of the vote $existing_vote = (int)$existing_vote_cast[0]['value']; *************** *** 1125,1131 **** // Voting is "sort of" allowed to anonymous...! // The voter will be redirected... $draw_js_destination_variable_flag = FALSE; ! if ($user->uid == 0) { $voting_not_allowed_flag = FALSE; $draw_js_destination_variable_flag = TRUE; } --- 1145,1153 ---- // Voting is "sort of" allowed to anonymous...! // The voter will be redirected... $draw_js_destination_variable_flag = FALSE; ! ! // Marinski: Permission check, again ! if ($user->uid == 0 && !user_access('give points with extra voting forms')) { $voting_not_allowed_flag = FALSE; $draw_js_destination_variable_flag = TRUE; }