diff --git a/votingapi.admin.inc b/votingapi.admin.inc index 5aa6d41..d8d8a53 100644 --- a/votingapi.admin.inc +++ b/votingapi.admin.inc @@ -19,6 +19,14 @@ function votingapi_settings_form($form_state) { '#options' => $period ); + $form['votingapi_registered_user_window'] = array( + '#type' => 'select', + '#title' => t('Registered user vote rollover'), + '#description' => t('The amount of time that must pass before two registered user votes from the same user ID are considered unique. Setting this to \'never\' will eliminate most double-voting for registered users.'), + '#default_value' => variable_get('votingapi_registered_user_window', -1), + '#options' => $period + ); + $form['votingapi_calculation_schedule'] = array( '#type' => 'radios', '#title' => t('Vote tallying'), diff --git a/votingapi.install b/votingapi.install index 8412c6f..f3977d3 100644 --- a/votingapi.install +++ b/votingapi.install @@ -129,6 +129,7 @@ function votingapi_uninstall() { $variables = array( 'votingapi_last_cron', 'votingapi_anonymous_window', + 'votingapi_registered_user_window', 'votingapi_calculation_schedule', ); foreach ($variables as $variable) { diff --git a/votingapi.module b/votingapi.module index e165392..aebde3e 100644 --- a/votingapi.module +++ b/votingapi.module @@ -366,9 +366,36 @@ function votingapi_delete_results($vote_results = array()) { * An array of votes matching the criteria. */ function votingapi_select_votes($criteria = array(), $limit = 0) { - $anon_window = variable_get('votingapi_anonymous_window', 86400); - if (!empty($criteria['vote_source']) && $anon_window >= 0) { - $criteria['timestamp'] = REQUEST_TIME - $anon_window; + $anon_window = variable_get('votingapi_anonymous_window', 3600); + $user_window = variable_get('votingapi_registered_user_window', 0); + + if (!empty($criteria['vote_source'])) { + switch($anon_window){ + case 0: + $criteria['timestamp'] = time(); + break; + case -1: + //do nothing, all votes will be deleted + break; + default: + $criteria['timestamp'] = time() - $anon_window; + break; + } + } + //happens even if the above was also called + if (!empty($criteria['uid']) && $criteria['uid'] > 0) { + switch($user_window){ + case 0: + $criteria['timestamp'] = time(); + break; + case -1: + //do nothing, all votes will be deleted + unset($criteria['timestamp']); + break; + default: + $criteria['timestamp'] = time() - $user_window; + break; + } } $function = variable_get('votingapi_storage_module', 'votingapi') . '_votingapi_storage_select_votes'; return $function($criteria, $limit);