--- extra_voting_forms.module	2008-01-12 08:38:46.000000000 +0800
+++ extra_voting_forms.module	2008-01-18 19:33:15.000000000 +0800
@@ -1,5 +1,4 @@
 <?php
-
 // $Id: extra_voting_forms.module,v 1.5 2008/01/12 00:38:46 mercmobily Exp $
 
 /**
@@ -8,11 +7,11 @@
  * @author Tony Mobily    (The lot apart from the javascript)
  * @author Jake McGraw    (The javascript)
  * @author Anthony Taylor (The javascript)
-*/
+ */
 
 /**
  * Implementation of hook_help().
-*/
+ */
 function extra_voting_forms_help($section) {
   switch ($section) {
     case 'admin/modules#description':
@@ -23,9 +22,8 @@ function extra_voting_forms_help($sectio
 
 /** 
  * Implementation of hook_perm(). 
-*/
+ */
 function extra_voting_forms_perm() {
-
   return array('give points with extra voting forms',
                'voting administrator',
                'voting vote bonus',
@@ -34,9 +32,9 @@ function extra_voting_forms_perm() {
 }
 
 /**
-  Implementation of hook_menu.
-*/
-function extra_voting_forms_menu($may_cache){
+ * Implementation of hook_menu.
+ */
+function extra_voting_forms_menu($may_cache) {
   $items = array();
 
   // CACHABLE ENTRIES
@@ -51,11 +49,12 @@ function extra_voting_forms_menu($may_ca
       'callback' => 'drupal_get_form',
       'callback arguments' => array('extra_voting_forms_admin_settings'),
       'access' => user_access('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM);
-
+      'type' => MENU_NORMAL_ITEM
+    );
 
   // NON-CACHABLE ENTRIES
-   } else { 
+  } 
+  else { 
 
     $items[] = array(
       'path' => 'extra_voting_forms/handle',
@@ -63,55 +62,52 @@ function extra_voting_forms_menu($may_ca
       'description' => t('Voting system'),
       'callback' => 'extra_voting_forms_handle',
       'access' => TRUE,
-       'type' => MENU_CALLBACK);
+      'type' => MENU_CALLBACK
+    );
 
     // Create the $css_file_complete variable
-    $css_file='extra_voting_forms_all.css';
-    $widget_dir=variable_get('extra_voting_forms_widget_dir', 'default');
-    $css_file_complete=drupal_get_path('module', 'extra_voting_forms') .'/widgets/'.$widget_dir.'/'.$css_file;
+    $css_file = 'extra_voting_forms_all.css';
+    $widget_dir = variable_get('extra_voting_forms_widget_dir', 'default');
+    $css_file_complete = drupal_get_path('module', 'extra_voting_forms') .'/widgets/'. $widget_dir .'/'. $css_file;
 
     // Add the css - the user-specified one if there is one, or the
     // module's
     drupal_add_css($css_file_complete, 'module');
 
     // Add jquery.js
-    drupal_add_js('misc/jquery.js','core');
+    drupal_add_js('misc/jquery.js', 'core');
 
     // Add the module-specific js file
-    drupal_add_js(drupal_get_path('module', 'extra_voting_forms').'/extra_voting_forms.js');
-
+    drupal_add_js(drupal_get_path('module', 'extra_voting_forms') .'/extra_voting_forms.js');
    } 
 
   // That's all!
   return $items;
-
 }
 
-
 // TODO: COMMENT AND PLACE THIS FUNCTION
-function extra_voting_forms_insert_js_css(){
+function extra_voting_forms_insert_js_css() {
 
  // Set the right javascript to see of only one vote is allowed
-  $only_one='0';
-  if(variable_get('extra_voting_forms_only_one_vote', FALSE) && ! user_access('voting administrator')){
-    $only_one='1';
+  $only_one = '0';
+  if (variable_get('extra_voting_forms_only_one_vote', FALSE) && ! user_access('voting administrator')) {
+    $only_one = '1';
   }
 
   // Set the anonymous URL 
-  $login_page= extra_voting_forms_anonymous_url();
+  $login_page = extra_voting_forms_anonymous_url();
 
   // Get the base path
-  $base_path= base_path();
-
+  $base_path = base_path();
 
   // Create the $css_file_complete variable
-  $css_file='extra_voting_forms_js.css';
-  $bp=substr($base_path,1,strlen($base_path));
-  $widget_dir=variable_get('extra_voting_forms_widget_dir', 'default');
-  $css_file_complete=$bp.drupal_get_path('module', 'extra_voting_forms') .'/widgets/'.$widget_dir.'/'.$css_file;
+  $css_file ='extra_voting_forms_js.css';
+  $bp = substr($base_path, 1, strlen($base_path));
+  $widget_dir = variable_get('extra_voting_forms_widget_dir', 'default');
+  $css_file_complete = $bp . drupal_get_path('module', 'extra_voting_forms') .'/widgets/'. $widget_dir .'/'. $css_file;
 
   return '<script type="text/javascript">
-document.write(\'<style type="text/css" media="all">@import "/'.$css_file_complete.'";</style>\');'."
+document.write(\'<style type="text/css" media="all">@import "/'. $css_file_complete .'";</style>\');'."
 
       var karma_only_one_vote = $only_one;
       var karma_login_page = \"$login_page\";
@@ -126,8 +122,8 @@ document.write(\'<style type="text/css" 
  *
  * @return
  *   The config form
-*/
-function extra_voting_forms_admin_settings(){
+ */
+function extra_voting_forms_admin_settings() {
 
   $form['extra_voting_forms_widget_dir'] = array(
     '#type' => 'textfield', 
@@ -136,8 +132,8 @@ function extra_voting_forms_admin_settin
     '#size' => 35, 
     '#maxlength' => 128, 
     '#required' => FALSE,
-    '#default_value' => variable_get('extra_voting_forms_widget_dir', 'default') );
-
+    '#default_value' => variable_get('extra_voting_forms_widget_dir', 'default') 
+  );
 
   $form['extra_voting_forms_node_types_applied'] = array(
     '#type' => 'checkboxes',
@@ -146,7 +142,7 @@ function extra_voting_forms_admin_settin
     '#options' => node_get_types('names')
   );
 
-  $form['extra_voting_forms_allow_karma_for_comments']=array(
+  $form['extra_voting_forms_allow_karma_for_comments'] = array(
     '#type' => 'checkbox', 
     '#title' => t('Allow karma for comments'),
     '#default_value' => variable_get('extra_voting_forms_allow_karma_for_comments', TRUE), 
@@ -168,57 +164,66 @@ function extra_voting_forms_admin_settin
     '#collapsed' => FALSE
   );
 
-  $form['link_sections']['extra_voting_forms_display_in_node_link']=array(
+  $form['link_sections']['extra_voting_forms_display_in_node_link'] = array(
     '#type' => 'checkbox', 
     '#title' => t('Display the karma form in the links section of a node'),
     '#description' => t('NOTE: if you don\'t tick this box, you\'ll need to have <code> &lt;? print extra_voting_forms_show_form($node,\'n\') ?&gt;</code> in your node template!'),
-    '#default_value' =>variable_get('extra_voting_forms_display_in_node_link', TRUE), 
+    '#default_value' => variable_get('extra_voting_forms_display_in_node_link', TRUE), 
    );
 
-  $form['link_sections']['extra_voting_forms_display_in_node_link_style']=array(
+  $form['link_sections']['extra_voting_forms_display_in_node_link_style'] = array(
     '#type' => 'select',
     '#title' => t('Form style...'),
     '#default_value' => variable_get('extra_voting_forms_display_in_node_link_style', 2),
-    '#options' => array(1=>t('Selection - full'),2=>t('Selection - negatives only'), 3=>t('Up, down'), 4=>t('Up only')  ),
+    '#options' => array(
+      1 => t('Selection - full'),
+      2 => t('Selection - negatives only'), 
+      3 => t('Up, down'), 
+      4 => t('Up only')
+    ),
     '#description' =>  t('Please see documentation to know what each style is'),
    );
 
-
-  $form['link_sections']['extra_voting_forms_display_in_comment_link']=array(
+  $form['link_sections']['extra_voting_forms_display_in_comment_link'] = array(
     '#type' => 'checkbox', 
     '#title' => t('Display the karma form in the links section of a comment'),
     '#description' => t('NOTE: if you don\'t tick this box, you\'ll need to have <code> &lt;? print extra_voting_forms_show_form($comment,\'c\') ?&gt;</code> in your comment template!'),
     '#default_value' => variable_get('extra_voting_forms_display_in_comment_link', TRUE), 
    );
 
-    $form['link_sections']['extra_voting_forms_display_in_comment_link_style']=array(
+  $form['link_sections']['extra_voting_forms_display_in_comment_link_style'] = array(
       '#type' => 'select',
       '#title' => t('Form style...'),
       '#default_value' => variable_get('extra_voting_forms_display_in_comment_link_style', 3),
-      '#options' => array(1=>t('Selection - full'),2=>t('Selection - negatives only'), 3=>t('Up, down'), 4=>t('Up only')  ),
+      '#options' => array(
+        1 => t('Selection - full'),
+        2 => t('Selection - negatives only'), 
+        3 => t('Up, down'), 
+        4 => t('Up only')  
+      ),
       '#description' =>  t('Please see documentation to know what each style is'),
    );
 
-  $form['extra_voting_forms_only_one_vote']=array(
+  $form['extra_voting_forms_only_one_vote'] = array(
     '#type' => 'checkbox', 
     '#title' => t('Only allow one vote - no re-voting allowed'),
     '#default_value' => variable_get('extra_voting_forms_only_one_vote', TRUE), 
    );
 
-  $form['extra_voting_forms_hide_given_select_votes']=array(
+  $form['extra_voting_forms_hide_given_select_votes'] = array(
     '#type' => 'checkbox', 
     '#title' => t('Will hide the vote given by the select box'),
     '#default_value' => variable_get('extra_voting_forms_hide_given_select_votes', FALSE), 
    );
 
-
   $form['extra_voting_forms_vote_within_hours_n'] = array(
     '#type' => 'textfield', 
     '#title' => t('Do not allow voting for nodes older than: (In hours, 0 for "forever")'),
     '#size' => 5, 
     '#maxlength' => 5, 
     '#required' => TRUE,
-    '#default_value' => variable_get('extra_voting_forms_vote_within_hours_n', 72) );
+    '#default_value' => variable_get('extra_voting_forms_vote_within_hours_n', 72) 
+  );
 
   $form['extra_voting_forms_vote_within_hours_c'] = array(
     '#type' => 'textfield', 
@@ -226,8 +231,8 @@ function extra_voting_forms_admin_settin
     '#size' => 5, 
     '#maxlength' => 5, 
     '#required' => TRUE,
-    '#default_value' => variable_get('extra_voting_forms_vote_within_hours_c', 168) );
-
+    '#default_value' => variable_get('extra_voting_forms_vote_within_hours_c', 168) 
+  );
 
   $form['voting_range'] = array(
     '#type' => 'fieldset',
@@ -240,7 +245,8 @@ function extra_voting_forms_admin_settin
     '#size' => 2, 
     '#maxlength' => 2, 
     '#required' => TRUE,
-    '#default_value' => variable_get('extra_voting_forms_range_users_plus_n', 1) );
+    '#default_value' => variable_get('extra_voting_forms_range_users_plus_n', 1)
+  );
 
   $form['voting_range']['extra_voting_forms_range_users_minus_n'] = array(
     '#type' => 'textfield', 
@@ -248,7 +254,8 @@ function extra_voting_forms_admin_settin
     '#size' => 2, 
     '#maxlength' => 2, 
     '#required' => TRUE,
-    '#default_value' => variable_get('extra_voting_forms_range_users_minus_n', 3) );
+    '#default_value' => variable_get('extra_voting_forms_range_users_minus_n', 3) 
+  );
 
   $form['voting_range']['extra_voting_forms_range_users_plus_c'] = array(
     '#type' => 'textfield', 
@@ -256,7 +263,8 @@ function extra_voting_forms_admin_settin
     '#size' => 2, 
     '#maxlength' => 2, 
     '#required' => TRUE,
-    '#default_value' => variable_get('extra_voting_forms_range_users_plus_c', 1) );
+    '#default_value' => variable_get('extra_voting_forms_range_users_plus_c', 1) 
+  );
 
   $form['voting_range']['extra_voting_forms_range_users_minus_c'] = array(
     '#type' => 'textfield', 
@@ -264,8 +272,8 @@ function extra_voting_forms_admin_settin
     '#size' => 2, 
     '#maxlength' => 2, 
     '#required' => TRUE,
-    '#default_value' => variable_get('extra_voting_forms_range_users_minus_c', 1) );
-
+    '#default_value' => variable_get('extra_voting_forms_range_users_minus_c', 1) 
+  );
 
   $form['voting_range']['bonus_range_n'] = array(
     '#type' => 'fieldset',
@@ -280,7 +288,7 @@ function extra_voting_forms_admin_settin
     '#size' => 2, 
     '#maxlength' => 2, 
     '#required' => FALSE,
-    '#default_value'=>variable_get('extra_voting_forms_vote_bonus_admin_minus_n',0), 
+    '#default_value' => variable_get('extra_voting_forms_vote_bonus_admin_minus_n', 0), 
     '#description' =>  t('If you set it to 3, the admin will have an extra 3 points in the negative karma range set'),
     );
 
@@ -290,9 +298,10 @@ function extra_voting_forms_admin_settin
     '#size' => 2, 
     '#maxlength' => 2, 
     '#required' => FALSE,
-    '#default_value'=>variable_get('extra_voting_forms_vote_bonus_admin_plus_n', 0), 
+    '#default_value' => variable_get('extra_voting_forms_vote_bonus_admin_plus_n', 0), 
     '#description' =>  t('If you set it to 3, the admin will have an extra 3 points in the positive range set'),
-    '#weight' => -10);
+    '#weight' => -10
+  );
 
   $form['voting_range']['bonus_range_n']['extra_voting_forms_vote_bonus_minus_n'] = array(
     '#type' => 'textfield', 
@@ -317,14 +326,13 @@ function extra_voting_forms_admin_settin
     '#collapsed' => FALSE
   );
 
-
   $form['voting_range']['bonus_range_c']['extra_voting_forms_vote_bonus_admin_minus_c'] = array(
     '#type' => 'textfield', 
     '#title' => t('Extra NEGATIVE range values for adminstrators'),
     '#size' => 2, 
     '#maxlength' => 2, 
     '#required' => FALSE,
-    '#default_value'=>variable_get('extra_voting_forms_vote_bonus_admin_plus_c', 0), 
+    '#default_value' => variable_get('extra_voting_forms_vote_bonus_admin_plus_c', 0), 
     '#description' =>  t('If you set it to 3, the admin will have an extra 3 points in the range set'),
    );
 
@@ -334,7 +342,7 @@ function extra_voting_forms_admin_settin
     '#size' => 2, 
     '#maxlength' => 2, 
     '#required' => TRUE,
-    '#default_value'=>variable_get('extra_voting_forms_vote_bonus_admin_plus_c', 0), 
+    '#default_value' => variable_get('extra_voting_forms_vote_bonus_admin_plus_c', 0), 
     '#description' =>  t('If you set it to 3, the admin will have an extra 3 points in the range set'),
    );
 
@@ -357,10 +365,9 @@ function extra_voting_forms_admin_settin
   $form['up_down_voting_power'] = array(
     '#type' => 'fieldset',
     '#description' => t('How much points voting up/down will give. These values NEED to be within the range specified above!'),
-    '#title' => t('Up/Down voting values')
+    '#title' => t('Up/Down voting values'),
   );
 
-
   $form['up_down_voting_power']['extra_voting_forms_updown_voting_up_n'] = array(
     '#type' => 'textfield', 
     '#title' => t('How much voting power when a story is voted UP - NODES'),
@@ -397,50 +404,50 @@ function extra_voting_forms_admin_settin
     '#default_value' => variable_get('extra_voting_forms_updown_voting_down_c', '-1'), 
    );
 
-
   $form['anti_abuse'] = array(
     '#type' => 'fieldset',
     '#title' => t('Anti-abuse system')
   );
 
-
   $form['anti_abuse']['extra_voting_forms_abuse_raw_votes'] = array(
     '#type' => 'textfield', 
     '#title' => t('This is the maximum number of times a user can award points...'),
     '#size' => 4, 
     '#maxlength' => 4, 
-    '#default_value' => variable_get('extra_voting_forms_abuse_raw_votes', '') );
+    '#default_value' => variable_get('extra_voting_forms_abuse_raw_votes', '')
+  );
 
   $form['anti_abuse']['extra_voting_forms_abuse_raw_votes_every'] = array(
     '#type' => 'textfield', 
     '#title' => t('...every how many hours?'),
     '#size' => 4, 
     '#maxlength' => 4, 
-    '#default_value' => variable_get('extra_voting_forms_abuse_raw_votes_every', '') );
-
+    '#default_value' => variable_get('extra_voting_forms_abuse_raw_votes_every', '')
+  );
 
   $form['anti_abuse']['extra_voting_forms_abuse_total_points'] = array(
     '#type' => 'textfield', 
     '#title' => t('This is the maximum amount of points a user can award in total...'),
     '#size' => 4, 
     '#maxlength' => 4, 
-    '#default_value' => variable_get('extra_voting_forms_abuse_total_points', '') );
+    '#default_value' => variable_get('extra_voting_forms_abuse_total_points', '')
+  );
 
   $form['anti_abuse']['extra_voting_forms_abuse_total_every'] = array(
     '#type' => 'textfield', 
     '#title' => t('...every how many hours?'),
     '#size' => 4, 
     '#maxlength' => 4, 
-    '#default_value' => variable_get('extra_voting_forms_abuse_total_every', '') );
+    '#default_value' => variable_get('extra_voting_forms_abuse_total_every', '')
+  );
 
   $result = db_query('SELECT rid, name FROM {role} ORDER BY name');
   $role_options = array();
-  $role_options[0]=t("None");
+  $role_options[0] = t("None");
   while ($role = db_fetch_object($result)) {
-    if($role->rid != 1 && $role->rid != 2){
+    if ($role->rid != 1 && $role->rid != 2) {
       $role_options[$role->rid] = $role->name;
     }   
-
   }
 
   $form['explanations'] = array(
@@ -450,14 +457,13 @@ function extra_voting_forms_admin_settin
     '#collapsed' => TRUE,
   );
 
-
-  for($i=-6;$i<=6;$i++){
-    $form['explanations']['extra_voting_forms_explanation_'.$i]=array(
+  for ($i = -6;$i <= 6;$i++) {
+    $form['explanations']['extra_voting_forms_explanation_'. $i] = array(
       '#type' => 'textfield', 
-      '#title' => t('Explanation for field ').$i,
+      '#title' => t('Explanation for field ') . $i,
       '#size' => 20, 
       '#maxlength' => 40, 
-      '#default_value' => variable_get('extra_voting_forms_explanation_'.$i, '')
+      '#default_value' => variable_get('extra_voting_forms_explanation_'. $i, ''),
    );
   }
 
@@ -465,25 +471,23 @@ function extra_voting_forms_admin_settin
       '#type' => 'fieldset',
       '#title' => t('Karma to display'),
       '#description' => t('IMPORTANT: you NEED to run a mass-recalculation of the karma cache for these changes to take effect!'),
-
     );
 
-  $display_karma_options[0]=t("Do not display karma at all");
-  $display_karma_options[1]=t("Display the actual karma");
-
+  $display_karma_options[0] = t("Do not display karma at all");
+  $display_karma_options[1] = t("Display the actual karma");
 
   $form['vote_to_display']['extra_voting_forms_display_karma_for_n'] = array(
     '#title' => t('Karma to display for nodes'),
     '#type' => 'radios',
     '#options' => $display_karma_options,
-    '#default_value' => variable_get('extra_voting_forms_display_karma_for_n',1),
+    '#default_value' => variable_get('extra_voting_forms_display_karma_for_n', 1),
   );
 
   $form['vote_to_display']['extra_voting_forms_display_karma_for_c'] = array(
     '#title' => t('Karma to display for comments'),
     '#type' => 'radios',
     '#options' => $display_karma_options,
-    '#default_value' =>variable_get('extra_voting_forms_display_karma_for_c',1),
+    '#default_value' => variable_get('extra_voting_forms_display_karma_for_c', 1),
   );
 
   return system_settings_form($form);
@@ -494,19 +498,16 @@ function extra_voting_forms_admin_settin
  * Used to validate extra_voting_forms_admin_settings()
  * The only interesting part is that it will "derail" the flow in case
  * the user clicked on the "Mass recalculation" button
-*/
-function extra_voting_forms_admin_settings_validate($form_id, $form_values){
-
+ */
+function extra_voting_forms_admin_settings_validate($form_id, $form_values) {
 }
 
-
 /* **************************************************************
  *
  *             FUNCTIONS TO DO SOME ABUSE CHECKS
  *
  * **************************************************************
-*/
-
+ */
 
 /**
  * It checks if the user has voted on too many different objects, regardless
@@ -518,31 +519,31 @@ function extra_voting_forms_admin_settin
  * @return
  *   TRUE if the user is above his/her allowance
  *   FALSE otherwise.
-*/
-function extra_voting_forms_too_many_votes_cast($account=NULL){
+ */
+function extra_voting_forms_too_many_votes_cast($account = NULL) {
   global $user;
 
   // Check which account to vote from
-  if($account == NULL){
+  if ($account == NULL) {
     $account=$user;
   }
 
   // Get the limit
-  $limit=variable_get('extra_voting_forms_abuse_raw_votes', '');
-  $limit_every= variable_get('extra_voting_forms_abuse_raw_votes_every','');
+  $limit = variable_get('extra_voting_forms_abuse_raw_votes', '');
+  $limit_every = variable_get('extra_voting_forms_abuse_raw_votes_every', '');
 
   // There is no limit: do nothing
-  if($limit == ''){
+  if ($limit == '') {
     return FALSE;
   }
 
   // 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='points' AND tag='vote' AND timestamp >  UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - %d",$account->uid,$limit_every));
+  $result = db_result(db_query("SELECT COUNT(*) AS count FROM {votingapi_vote} WHERE uid = %d AND value_type = 'points' AND tag = 'vote' AND timestamp > UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - %d", $account->uid, $limit_every));
 
   // Over the limit: don't accept it!
-  if($result > $limit){
+  if ($result > $limit) {
     return TRUE;
   }
 
@@ -560,39 +561,37 @@ function extra_voting_forms_too_many_vot
  * @return
  *   TRUE if $vote would get the user to go over the configured limit.
  *   FALSE otherwise.
-*/
-function extra_voting_forms_too_many_votes_total($vote,$account=NULL){
+ */
+function extra_voting_forms_too_many_votes_total($vote, $account = NULL) {
   global $user;
 
   // Check which account to vote from
-  if($account == NULL){
-    $account=$user;
+  if ($account == NULL) {
+    $account = $user;
   }
 
-  $total_points=variable_get('extra_voting_forms_abuse_total_points', '');
-  $total_every =variable_get('extra_voting_forms_abuse_total_every', '');
+  $total_points = variable_get('extra_voting_forms_abuse_total_points', '');
+  $total_every = variable_get('extra_voting_forms_abuse_total_every', '');
 
   // If person_points is not set, don't bother
-  if($total_points == ''){
+  if ($total_points == '') {
     return FALSE;
   }
 
-
   // Convert total_every into seconds...
   $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='points' AND tag='vote' AND timestamp > UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - %d",$account->uid,$total_every));
+  $result = db_result(db_query("SELECT SUM(abs(value)) FROM {votingapi_vote} WHERE uid = %d AND value_type = 'points' AND tag = 'vote' AND timestamp > UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - %d", $account->uid, $total_every));
   $result += abs($vote);
  
   // Return TRUE if the result is outside the allowable range
-  if($result + $vote > $total_points || $result  <  ($total_points * -1 ) ){
+  if ($result + $vote > $total_points || $result < ($total_points * -1 )) {
     return TRUE;
   }
 
   // ALl OK!
   return FALSE;
-
 }
 
 /* **************************************************************
@@ -600,8 +599,7 @@ function extra_voting_forms_too_many_vot
  *             FUNCTIONS TO DO SOME ABUSE CHECKS
  *
  * **************************************************************
-*/
-
+ */
 
 /**
  * It loads a $o object, based on its sk_ fields. This is important
@@ -613,16 +611,16 @@ function extra_voting_forms_too_many_vot
  * 
  * @return
  *   The object loaded.
-*/
-function extra_voting_forms_load_object($o){
+ */
+function extra_voting_forms_load_object($o) {
 
   // It's a comment
-  if($o->sk_type == 'c'){
+  if ($o->sk_type == 'c') {
 
     // Try to load the comment. If it can't, just redirect to the
     // home page
-    $r=_comment_load($o->sk_id);
-    if(!$r){
+    $r = _comment_load($o->sk_id);
+    if (!$r) {
       return NULL;
     }
     $r->sk_id = $r->cid;
@@ -631,12 +629,12 @@ function extra_voting_forms_load_object(
   }
 
   // It's a node
-  if($o->sk_type == 'n'){
+  if ($o->sk_type == 'n') {
 
     // Try to load the comment. If it can't, just redirect to the
     // home page
-    $r=node_load($o->sk_id);
-    if(!$r){
+    $r = node_load($o->sk_id);
+    if (!$r) {
       return NULL;
     }
     $r->sk_id = $r->nid;
@@ -652,7 +650,7 @@ function extra_voting_forms_load_object(
  *       FUNCTIONS TO MANAGE THE ACTUAL VOTING PROCESS
  *
  * **************************************************************
-*/
+ */
 
 /**
  * It handles the actual request. This is a "preparation" function.
@@ -666,8 +664,8 @@ function extra_voting_forms_load_object(
  * @return
  *   The response. It might be just a string (no page template, or anything)
  *   or it could be a full page.
-*/
-function extra_voting_forms_handle(){
+ */
+function extra_voting_forms_handle() {
 
   global $_REQUEST, $user;
 
@@ -682,50 +680,46 @@ function extra_voting_forms_handle(){
 
 
     // If otype isn't 'c' or 'n', return to the home page
-    if($otype != 'c' && $otype != 'n'){
-      exit(extra_voting_forms_return($form_type,$o,t('Error in the form'),'') );
+    if ($otype != 'c' && $otype != 'n') {
+      exit(extra_voting_forms_return($form_type, $o, t('Error in the form'), '') );
     }
 
     // Create the object, and load it
-    $o= new stdClass();
+    $o = new stdClass();
     $o->sk_id = $oid;
     $o->sk_type = $otype;
-    $o=extra_voting_forms_load_object($o);
-    if(!$o){
-      exit(extra_voting_forms_return($form_type,$o,t('Error loading the object!'),''));
+    $o = extra_voting_forms_load_object($o);
+    if (!$o) {
+      exit(extra_voting_forms_return($form_type, $o, t('Error loading the object!'), ''));
     }
 
     // Check that $form_type is sane. extra_voting_forms_return does NOT
     // check it as a parameter
-    if($form_type != 'ajax' && $form_type != 'form'){
-      drupal_set_message(t('Error in the parameters!'),'error');
-      drupal_goto('node/'.$o->nid);
+    if ($form_type != 'ajax' && $form_type != 'form') {
+      drupal_set_message(t('Error in the parameters!'), 'error');
+      drupal_goto('node/'. $o->nid);
     }    
 
-
-
     // 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) );
+    if ($form_type != 'ajax' && $user->uid == 0) {
+      drupal_goto(extra_voting_forms_anonymous_url(), "destination=". extra_voting_forms_destination($o) );
     }
 
     // Give the vote and return. $give_vote_return will return the error
     // message (if there was one) or '' if all went OK. This is exactly what
     // extra_voting_forms_return expects, which is handy...
-    list($give_vote_return,$k)=extra_voting_forms_give_vote($o,$karma_vote);
+    list($give_vote_return, $k) = extra_voting_forms_give_vote($o, $karma_vote);
     
-    if(! variable_get('extra_voting_forms_display_karma_for_'.$o->sk_type, 0) ){
-      $k='';
+    if (! variable_get('extra_voting_forms_display_karma_for_'. $o->sk_type, 0) ) {
+      $k = '';
     }
 
-    exit( extra_voting_forms_return($form_type,$o,$give_vote_return,$k) );
-
+    exit( extra_voting_forms_return($form_type, $o, $give_vote_return, $k) );
   }
 
 }
 
-
 /**
  * Give a karmic vote to a particular object
  *
@@ -739,123 +733,119 @@ function extra_voting_forms_handle(){
  *   $return is the error message. It is an empty string '' if everything 
  *   was good. OR, an error message if things didn't go so well.
  *   $total_karma is the object's total karma after the vote.
-*/
-function extra_voting_forms_give_vote($o,$vote,$account=NULL){
+ */
+function extra_voting_forms_give_vote($o, $vote, $account = NULL) {
   global $user;
 
   // Check which account to vote from
-  if($account == NULL){
+  if ($account == NULL) {
     $account=$user;
   }
 
   // The user is not logged in: RETURN with error
-  if($account->uid == 0){
-    return array( t("Only logged in users can vote!"),0 );
+  if ($account->uid == 0) {
+    return array( t("Only logged in users can vote!"), 0 );
   }
  
   // The user can't vote on his/her own comments, return error
   // (Note: admin and the karma admin can!)
-  if($o->sk_type == 'c' && $account->uid == $o->uid && $account->uid != 1 & ! user_access('voting administrator',$account)){
-    return array( t("You can't vote on your own comments!"),0 );
+  if ($o->sk_type == 'c' && $account->uid == $o->uid && $account->uid != 1 & ! user_access('voting administrator', $account)) {
+    return array( t("You can't vote on your own comments!"), 0 );
   }
 
   // The user does not have voting rights: RETURN with error
-  if(!user_access('give points with extra voting forms',$account)){
-    return array( t("You are not allowed to vote"),0 );
+  if (!user_access('give points with extra voting forms', $account)) {
+    return array( t("You are not allowed to vote"), 0 );
   }
 
   // The module is set so that it doesn't give the ability to vote
   // based on comments. Return an error
-  if($o->sk_type == 'c' && !variable_get('extra_voting_forms_allow_karma_for_comments', FALSE)){
-    return array( t("This module doesn't allow giving karma for comments"),0 );
+  if ($o->sk_type == 'c' && !variable_get('extra_voting_forms_allow_karma_for_comments', FALSE)) {
+    return array( t("This module doesn't allow giving karma for comments"), 0 );
   }
 
   // The module is set so that it doesn't give the ability to vote
   // based on this particulat note type. Return an error
-  $types= variable_get('extra_voting_forms_node_types_applied', array()  );
-  if($o->sk_type == 'n' && ! $types[$o->type] ) {
-    return array( t("This module doesn't allow giving karma for this kind of node types"),0 );
+  $types = variable_get('extra_voting_forms_node_types_applied', array() );
+  if ($o->sk_type == 'n' && ! $types[$o->type] ) {
+    return array( t("This module doesn't allow giving karma for this kind of node types"), 0 );
   }
 
   // Vote out of range: RETURN with error
-  $accepted_range_plus =extra_voting_forms_range_calculator($o->sk_type,'plus',$account);
-  $accepted_range_minus=extra_voting_forms_range_calculator($o->sk_type,'minus',$account);
-  if($vote > $accepted_range_plus || $vote < $accepted_range_minus ){
-    return array( t('Your vote was outside the acceptable range!'),0 );
+  $accepted_range_plus = extra_voting_forms_range_calculator($o->sk_type, 'plus', $account);
+  $accepted_range_minus = extra_voting_forms_range_calculator($o->sk_type, 'minus', $account);
+  if ($vote > $accepted_range_plus || $vote < $accepted_range_minus ) {
+    return array( t('Your vote was outside the acceptable range!'), 0 );
   }
 
   // Is only one vote allowed?
-  $only_one_vote_allowed=variable_get('extra_voting_forms_only_one_vote', FALSE);
-  $existing_vote_cast=votingapi_get_vote(extra_voting_forms_c($o->sk_type),$o->sk_id,'points','vote',$account->uid);
+  $only_one_vote_allowed = variable_get('extra_voting_forms_only_one_vote', FALSE);
+  $existing_vote_cast = votingapi_get_vote(extra_voting_forms_c($o->sk_type), $o->sk_id, 'points', 'vote', $account->uid);
 
-  $existing_vote=(int)$existing_vote_cast->value;
+  $existing_vote = (int)$existing_vote_cast->value;
 
-  if($only_one_vote_allowed && ! user_access('voting administrator',$account) && $existing_vote != 0){
-    return array( t('You can only vote once!'),0 );
+  if ($only_one_vote_allowed && ! user_access('voting administrator', $account) && $existing_vote != 0) {
+    return array( t('You can only vote once!'), 0 );
   }
 
   // Check the time limit on the voting form
-  if($o->sk_type == 'c'){
-    $t=$o->timestamp;
-  } else {
-    $t=$o->created;
-  }
-  $time_limit=variable_get('extra_voting_forms_vote_within_hours_'.$o->sk_type, 0);
-  if($time_limit && ! user_access('voting administrator',$account) ){
-    $cutoff_time=(time()-$time_limit*60*60);
-    if($t < $cutoff_time){
-      return array( t('This element no longer accepts votes!'),0 );
+  if ($o->sk_type == 'c') {
+    $t = $o->timestamp;
+  }
+  else {
+    $t = $o->created;
+  }
+  $time_limit = variable_get('extra_voting_forms_vote_within_hours_'. $o->sk_type, 0);
+  if ($time_limit && ! user_access('voting administrator', $account) ) {
+    $cutoff_time = (time() - $time_limit * 60 * 60);
+    if ($t < $cutoff_time) {
+      return array( t('This element no longer accepts votes!'), 0 );
     }
   }
-
 
   // Only check for abuse if the user is not allowed to bypass the
   // anti-abuse system
-  if(! user_access('bypass voting anti-abuse system',$account) ){
-
+  if (! user_access('bypass voting anti-abuse system', $account) ) {
 
     // Anti-abuse: check that the person's threshhold hasn't been
     // reached IN GENERAL
-    if( extra_voting_forms_too_many_votes_total($vote,$account)){
-      return array( t('Your have already given too many karma points for now!'),0 );
+    if ( extra_voting_forms_too_many_votes_total($vote, $account)) {
+      return array( t('Your have already given too many karma points for now!'), 0 );
     }
 
     // Anti-abuse: check that the person hasn't cast too many raw votes
-    if(extra_voting_forms_too_many_votes_cast($account)){
-      return array( t('Your have already cast enough votes for now!'),0 );
+    if (extra_voting_forms_too_many_votes_cast($account)) {
+      return array( t('Your have already cast enough votes for now!'), 0 );
     }
   }
 
-
   // Give the actual vote using the Voting API - thanks Eaton!
-  $v= new stdClass();
-  $v->value=$vote;
-  $v->value_type='points';
-  $v->tag='vote';
+  $v = new stdClass();
+  $v->value = $vote;
+  $v->value_type = 'points';
+  $v->tag = 'vote';
   votingapi_set_vote(extra_voting_forms_c($o->sk_type), $o->sk_id, $v, $account->uid);
 
   // Get the current number of votes
-  #$r=(int)votingapi_get_voting_results_function($o->sk_type,$o->sk_id,'sum'); # CHECKME
-  $r = votingapi_get_voting_result(extra_voting_forms_c($o->sk_type),$o->sk_id,'points','vote','sum');
+  //$r=(int)votingapi_get_voting_results_function($o->sk_type,$o->sk_id,'sum'); # CHECKME
+  $r = votingapi_get_voting_result(extra_voting_forms_c($o->sk_type), $o->sk_id, 'points', 'vote', 'sum');
   $r = (int)$r->value;
   
-
   return array('', $r);
 
 }
 
-function extra_voting_forms_c($sk_type){
-  return $sk_type=='n' ? 'node'  : 'comment';
+function extra_voting_forms_c($sk_type) {
+  return $sk_type == 'n' ? 'node' : 'comment';
 }
 
 /**
- 
  * What it does depends largely on $form_type:
  *
  * - If $form_type is "ajax", then it returns either:
  *   -- {"karma_aggregate":$current_karma, "error":"$error"} (ERRORS)
-*    -- {"karma_aggregate":$current_karma} (ALL OK)
-
+ *    -- {"karma_aggregate":$current_karma} (ALL OK)
+ *
  * - If $form_type is "form", then it redirects to the right 
  *   page that held $comment, after setting the error using
  *    drupal_set_message('...','error')
@@ -869,30 +859,31 @@ function extra_voting_forms_c($sk_type){
  * @return
  *   A redirection to the right node if $form_type is 'form', OR
  *   just a string (no page templates) if $form_type is 'ajax'
-*/
-function extra_voting_forms_return($form_type,$object,$error,$current_karma){
+ */
+function extra_voting_forms_return($form_type, $object, $error, $current_karma) {
 
-  if($form_type == 'ajax'){
+  if ($form_type == 'ajax') {
 
     // Adjust the string for Ajax...
-    if($current_karma===''){
-      $current_karma='"Undefined"';
+    if ($current_karma === '') {
+      $current_karma = '"Undefined"';
     }
 
     // Return the right thing to the javascript
-    if($error != ''){
+    if ($error != '') {
       return "{\"karma_aggregate\":$current_karma, \"error\":\"$error\"}";
-      #drupal_set_message($error);
-    } else {
+      //drupal_set_message($error);
+    }
+    else {
       return "{\"karma_aggregate\":$current_karma}";
-
     }
+  }
+  else { 
 
-  } else { 
-
-    if($error != ''){
-      drupal_set_message($error,'error');
-    } else {
+    if ($error != '') {
+      drupal_set_message($error, 'error');
+    }
+    else {
       drupal_set_message(t('Thank you for voting!'));
     }
     drupal_goto(referer_uri());
@@ -906,22 +897,22 @@ function extra_voting_forms_return($form
  *
  * @return
  *   The template form for the javascriop. It won't show in the page.
-*/
-function extra_voting_forms_js_variables(){
+ */
+function extra_voting_forms_js_variables() {
 
   // Set the right javascript to see of only one vote is allowed
-  $only_one='0';
-  if(variable_get('extra_voting_forms_only_one_vote', FALSE) && ! user_access('voting administrator')){
-    $only_one='1';
+  $only_one = '0';
+  if (variable_get('extra_voting_forms_only_one_vote', FALSE) && ! user_access('voting administrator')) {
+    $only_one = '1';
   }
 
   // Set the anonymous URL 
-  $login_page= extra_voting_forms_anonymous_url();
+  $login_page = extra_voting_forms_anonymous_url();
 
   // Get the base path
-  $base_path= base_path();
+  $base_path = base_path();
 
-  # Create the javascript blurb with the variable names
+  // Create the javascript blurb with the variable names
   $output = "
     <script type=\"text/javascript\">
       var karma_only_one_vote = $only_one;
@@ -934,49 +925,49 @@ function extra_voting_forms_js_variables
   return $output;
 }
 
-
-function extra_voting_forms_anonymous_url(){
+function extra_voting_forms_anonymous_url() {
  
   // Set where the user should be redirected
-  $anonymous_url=variable_get('extra_voting_forms_anonymous_url','');
+  $anonymous_url = variable_get('extra_voting_forms_anonymous_url', '');
 
-  if($anonymous_url != ''){
+  if ($anonymous_url != '') {
     // The anonymous action is selected by the user
-    $action=$anonymous_url;
-  } else {
+    $action = $anonymous_url;
+  }
+  else {
     // Use the default user/login action
     // Note: I want a clean URL, without leading "/"
-    $action=substr(url("user/login"),1);
+    $action = substr(url("user/login"), 1);
   }    
 
-  return($action);
+  return $action;
 }
 
-# TODO: DOCUMENT/PLACE THIS FUNCTION
-function extra_voting_forms_destination($o){
+// TODO: DOCUMENT/PLACE THIS FUNCTION
+function extra_voting_forms_destination($o) {
 
   // Define the destination variable
-  if($o->sk_type == 'n'){
-    $destination=url('node/'.$o->sk_id,NULL,NULL,FALSE);
-   } else {
-    $destination=url('node/'.$o->nid,NULL,'comment-'. $o->sk_id,FALSE);
+  if ($o->sk_type == 'n') {
+    $destination=url('node/'. $o->sk_id, NULL, NULL, FALSE);
+  }
+  else {
+    $destination=url('node/'. $o->nid, NULL, 'comment-'. $o->sk_id, FALSE);
   }
-  $destination=substr($destination,1);
-  return(urlencode($destination));
+  $destination = substr($destination, 1);
+  return urlencode($destination);
 }
 
-# TODO: DOCUMENT AND PLACE THIS FUNCTION
-function extra_voting_forms_js_destination_field($o,$flag){
+// TODO: DOCUMENT AND PLACE THIS FUNCTION
+function extra_voting_forms_js_destination_field($o, $flag) {
 
   // Settle this one straight away
-  if(!$flag){
+  if (!$flag) {
     return;
   }
 
-  return "<input type=\"hidden\" name=\"js_destination\" value=\"".extra_voting_forms_destination($o)."\" />";
+  return "<input type=\"hidden\" name=\"js_destination\" value=\"". extra_voting_forms_destination($o) ."\" />";
 }
 
-
 /**
  * It display the karma form for a particular comment. This is used
  * both by the hook_link (in case the form needs to be in the links) and
@@ -997,29 +988,29 @@ function extra_voting_forms_js_destinati
  * @return
  *   The form. It checks if the comment had been buried - if so, returns
  *   nothing.
-*/
-function extra_voting_forms_show_form($o,$force_type,$style=1,$substyle='big'){
+ */
+function extra_voting_forms_show_form($o, $force_type, $style = 1, $substyle = 'big') {
   global $user;
 
   // Sets the right "extra sk variables" for the object according to the
   // forced type
-  if($force_type == 'c'){
+  if ($force_type == 'c') {
     $o->sk_id   = $o->cid;
     $o->sk_type = 'c';
-  } else {
+  }
+  else {
     $o->sk_id   = $o->nid;
     $o->sk_type = 'n';
   }
 
   // Just a small sanity check on the form style
-  if($substyle != 'big' && $substyle != 'small'){
+  if ($substyle != 'big' && $substyle != 'small') {
     $substyle="big";
   }
 
   // Define $form_style. If a parameter was passed, use the parameter.
   // Otherwise, get the style from the global variables
-  $form_style=$style.'_'.$substyle;
-
+  $form_style = $style .'_'. $substyle;
 
   // ****************************************************************
   // ** CHECK THAT THE FORM ACTUALLY NEEDS TO COME OUT
@@ -1027,20 +1018,20 @@ function extra_voting_forms_show_form($o
 
   // The module is set so that it doesn't give the ability to vote
   // based on comments. Don't return the form.
-  if($o->sk_type == 'c' && !variable_get('extra_voting_forms_allow_karma_for_comments', FALSE)){
+  if ($o->sk_type == 'c' && !variable_get('extra_voting_forms_allow_karma_for_comments', FALSE)) {
     return '';
   }
 
   // The module is set so that it doesn't give the ability to vote
   // based on this particulat note type. Don't return the form.
-  $types= variable_get('extra_voting_forms_node_types_applied', array()  );
-  if($o->sk_type == 'n' && ! $types[$o->type] ) {
+  $types = variable_get('extra_voting_forms_node_types_applied', array() );
+  if ($o->sk_type == 'n' && ! $types[$o->type] ) {
     return '';
   }
 
   // Don't offer the form if the comment is the user's AND the user is not
   // a karma administrator or "admin"
-  if($o->sk_type == 'c' && $user->uid == $o->uid && $user->uid != 1 && ! user_access('voting administrator')){
+  if ($o->sk_type == 'c' && $user->uid == $o->uid && $user->uid != 1 && ! user_access('voting administrator')) {
     $voting_not_allowed=TRUE;
   }
 
@@ -1048,94 +1039,90 @@ function extra_voting_forms_show_form($o
   // ** SET THE BASIC VARIABLES
   // ****************************************************************
 
-
   // This will get the record. If != NULL, then a vote (even 0) WAS cast
-  $existing_vote_cast=votingapi_get_vote(extra_voting_forms_c($o->sk_type),$o->sk_id,'points','vote',$user->uid);
+  $existing_vote_cast = votingapi_get_vote(extra_voting_forms_c($o->sk_type), $o->sk_id, 'points', 'vote', $user->uid);
 
   // Integer representation of the vote
-  $existing_vote=(int)$existing_vote_cast->value;
+  $existing_vote = (int)$existing_vote_cast->value;
 
   // If only one vote is allowed, and a vote has already been cast, then
   // set the variable "voting_not_allowed" which will be used in the form
-  $only_one_vote_allowed=variable_get('extra_voting_forms_only_one_vote', FALSE);
-  if($only_one_vote_allowed && ! user_access('voting administrator') && $existing_vote_cast){
-    $voting_not_allowed=TRUE;
+  $only_one_vote_allowed = variable_get('extra_voting_forms_only_one_vote', FALSE);
+  if ($only_one_vote_allowed && ! user_access('voting administrator') && $existing_vote_cast) {
+    $voting_not_allowed = TRUE;
   }
 
   // If the user is anonymous, DO ALLOW TO VOTE! However,
   // the action will be differeit - it will go to /user/login instead!
   // This needs to be done AFTER OTHER CHECKS ON THE ABILITY TO VOTE
-  $action=base_path()."extra_voting_forms/handle";
+  $action = base_path() ."extra_voting_forms/handle";
 
   // Voting is "sort of" allowed to anonymous...! 
   // The voter will be redirected...
-  $draw_js_destination_variable=FALSE;
-  if ($user->uid == 0){
-    $voting_not_allowed=FALSE;
-    $draw_js_destination_variable=TRUE;
+  $draw_js_destination_variable = FALSE;
+  if ($user->uid == 0) {
+    $voting_not_allowed = FALSE;
+    $draw_js_destination_variable = TRUE;
   }
 
-
   // Don't allow showing the form past its time limit
-  if($o->sk_type == 'c'){
-    $t=$o->timestamp;
-  } else {
-    $t=$o->created;
-  }
-  $time_limit=variable_get('extra_voting_forms_vote_within_hours_'.$o->sk_type, 0);
-  if($time_limit && !user_access('voting administrator') ){
-    $cutoff_time=(time()-$time_limit*60*60);
-    if($t < $cutoff_time){
-      $voting_not_allowed=TRUE;
+  if ($o->sk_type == 'c') {
+    $t = $o->timestamp;
+  }
+  else {
+    $t = $o->created;
+  }
+  $time_limit = variable_get('extra_voting_forms_vote_within_hours_'. $o->sk_type, 0);
+  if ($time_limit && !user_access('voting administrator') ) {
+    $cutoff_time = (time() - $time_limit * 60 * 60);
+    if ($t < $cutoff_time) {
+      $voting_not_allowed = TRUE;
     }
   }
-
 
   // Set up the range
-  $range_plus = extra_voting_forms_range_calculator($o->sk_type,'plus'); 
-  $range_minus = extra_voting_forms_range_calculator($o->sk_type,'minus'); 
-
+  $range_plus = extra_voting_forms_range_calculator($o->sk_type, 'plus'); 
+  $range_minus = extra_voting_forms_range_calculator($o->sk_type, 'minus'); 
 
   // Set the default value. Note: the range might have gone down
   // since the last vote. So, check it
-  $default=$existing_vote;
-  if($existing_vote < $range_minus){
-    $default=$range_minus;
+  $default = $existing_vote;
+  if ($existing_vote < $range_minus) {
+    $default = $range_minus;
   }
-  if($existing_vote > $range_plus){
-    $default=$range_plus;
+  if ($existing_vote > $range_plus) {
+    $default = $range_plus;
   }
 
-
   // The variable "existing_vote_display" will be FALSE if the
   // existing karma is not to be shown, and TRUE otherwise
-  if( variable_get('extra_voting_forms_display_karma_for_'.$o->sk_type, 0)){
-
+  if ( variable_get('extra_voting_forms_display_karma_for_'. $o->sk_type, 0)) {
 
     // If the node doesn't have an ID, then voting is not allowed and
     // the existing vote is 1. This
     // is here because forms can be in the "preview" bit of the deal...!
     // Note: this needs to be a last-minute thing...
-    if($o->sk_id == 0){
-      $voting_not_allowed=TRUE;
-      $existing_vote_display=1;  
-    } else {
-      $r = votingapi_get_voting_result(extra_voting_forms_c($o->sk_type),$o->sk_id,'points','vote','sum');
+    if ($o->sk_id == 0) {
+      $voting_not_allowed = TRUE;
+      $existing_vote_display = 1;  
+    }
+    else {
+      $r = votingapi_get_voting_result(extra_voting_forms_c($o->sk_type), $o->sk_id, 'points', 'vote', 'sum');
       $existing_vote_display = (int)$r->value;
     }
-  } else {
+  }
+  else {
     $existing_vote_display = FALSE;
   }
 
-
   // This will be attached to the form's style
-  if($o->promote){
-    $is_promoted=TRUE;
-    $is_promoted_class='_promoted';
-  } else {
-    $is_promoted=FALSE;
-    $is_promoted_class='';
-
+  if ($o->promote) {
+    $is_promoted = TRUE;
+    $is_promoted_class = '_promoted';
+  }
+  else {
+    $is_promoted = FALSE;
+    $is_promoted_class = '';
   } 
 
   // JAKE: The following variables are set here:
@@ -1147,90 +1134,87 @@ function extra_voting_forms_show_form($o
   //                          displayed. Otherwise, it's the number 
   // $is_promoted           - TRUE if the node is promoted
 
-
   // ****************************************************************
   // ** DRAW THE FORM - JAKE, THIS IS WHERE YOU CHANGE THINGS
   // ****************************************************************
 
-  if($voting_not_allowed){
-    $voting_not_allowed_str=' disabled="disabled" ';
-    $clickable_string='_not_clickable';
-  }else {
-    $clickable_string='_clickable';
+  if ($voting_not_allowed) {
+    $voting_not_allowed_str = ' disabled="disabled" ';
+    $clickable_string = '_not_clickable';
   }
-
-  $karma_score_display='';
-  if($existing_vote_display !== FALSE ){
-    $karma_score_display='<span class="karma_score">'.$existing_vote_display.'</span>';
+  else {
+    $clickable_string = '_clickable';
   }
 
+  $karma_score_display = '';
+  if ($existing_vote_display !== FALSE ) {
+    $karma_score_display = '<span class="karma_score">'. $existing_vote_display .'</span>';
+  }
 
   // Make up the string to tell the system if a form refers to
   // something with negative value
-  if($default < 0){
-    $negative_karma_str='<div class="has_negative_karma"></div>';
+  if ($default < 0) {
+    $negative_karma_str = '<div class="has_negative_karma"></div>';
   }
 
-  switch($form_style) {
+  switch ($form_style) {
     // Form type 1 (Karma Vote Up/Down, multiple values)
     case 1:
     // Form type 2 (Karma Vote Down, multiple values)
     case 2:
 
       // Form Style 2 Negatives only
-      if ($form_style==2) {
+      if ($form_style == 2) {
         $range_plus = -0;
       }
 
-
       // If this config flag is on, then it won't show the
       // vote given while reloading the form.
-      $hiding_select_vote=FALSE;
-      if( variable_get('extra_voting_forms_hide_given_select_votes', FALSE) && $existing_vote ){
-        $default=0;
-        $hiding_select_vote=TRUE;
+      $hiding_select_vote = FALSE;
+      if ( variable_get('extra_voting_forms_hide_given_select_votes', FALSE) && $existing_vote ) {
+        $default = 0;
+        $hiding_select_vote = TRUE;
       }
 
       // Build option list, check for selected
-      for($i=$range_plus; $i >= $range_minus; $i--) {
+      for ($i = $range_plus; $i >= $range_minus; $i--) {
 
         // Create teh $select variable
-        $selected='';
-        if($i == $default){
+        $selected = '';
+        if ($i == $default) {
           $selected=" selected ";
         }
 
         // Create the $vote_description variable
-        $vote_description=variable_get('extra_voting_forms_explanation_'.$i,'');
+        $vote_description = variable_get('extra_voting_forms_explanation_'. $i, '');
 
         // Adds to the description of "0" if a vote had already been cast
         // and the system is not allowed to show the vote
-        if($i == 0 && $hiding_select_vote){
-          $vote_description.=t(' - Already voted');
+        if ($i == 0 && $hiding_select_vote) {
+          $vote_description .= t(' - Already voted');
         }
 
         // Adds the option
-        $options .= '<option value="'.$i.'"'.$selected.'>'.$i. ' ' . $vote_description .'</option>';
+        $options .= '<option value="'. $i .'"'. $selected .'>'. $i .' '. $vote_description .'</option>';
       }
 
-
       // Generate form
-       # <div class="extra_voting_forms karma_'.$o->sk_type.'_'.$form_style.'">
+      // <div class="extra_voting_forms karma_'.$o->sk_type.'_'.$form_style.'">
       $form .= '
-        <div class="extra_voting_forms karma_'.$form_style.'">
-        <form action="'.$action.'" method="get" class="karma_form'.$is_promoted_class.'" id="'.($form_style==1?'z':'y').$o->sk_id.'">
-          '.$negative_karma_str.'
-          '.$karma_score_display.'
+        <div class="extra_voting_forms karma_'. $form_style .'">
+        <form action="'. $action .'" method="get" class="karma_form'. $is_promoted_class .'" id="'. ($form_style == 1 ? 'z' : 'y') . $o->sk_id .'">
+          '. $negative_karma_str .'
+          '. $karma_score_display .'
           <span class="karma_buttons">
-            <select name="karma_vote" '.$voting_not_allowed_str.'>'
-              .$options.'
+            <select name="karma_vote" '. $voting_not_allowed_str .'>'
+              . $options .'
             </select>
-            <input type="hidden" name="oid" value="'.$o->sk_id.'"/>
-            <input type="hidden" name="otype" value="'.$o->sk_type.'"/>
-            <input type="hidden" name="form_style" value="'.$form_style.'"/>
+            <input type="hidden" name="oid" value="'. $o->sk_id .'"/>
+            <input type="hidden" name="otype" value="'. $o->sk_type .'"/>
+            <input type="hidden" name="form_style" value="'. $form_style .'"/>
             <input type="hidden" name="form_type" value="form"/>
-            <input type="submit" name="submit" value="Vote" '.$voting_not_allowed_str.'/>
-            '.extra_voting_forms_js_destination_field($o,$draw_js_destination_variable).'
+            <input type="submit" name="submit" value="Vote" '. $voting_not_allowed_str .'/>
+            '. extra_voting_forms_js_destination_field($o, $draw_js_destination_variable) .'
           </span>
         </form>
         </div>';
@@ -1241,25 +1225,25 @@ function extra_voting_forms_show_form($o
 
       // Generate form type 3
       $form .= '
-        <div class="extra_voting_forms karma_'.$form_style.'">
-        <form action="'.$action.'" method="get" class="karma_form'.$is_promoted_class.'" id="x'.$o->sk_id.'">
-          '.$negative_karma_str.'
-          '.$karma_score_display.'
+        <div class="extra_voting_forms karma_'. $form_style .'">
+        <form action="'. $action .'" method="get" class="karma_form'. $is_promoted_class .'" id="x'. $o->sk_id .'">
+          '. $negative_karma_str .'
+          '. $karma_score_display .'
           <span class="karma_buttons">
-            <label class="karma_up'.($default>0?'_clicked':'_not_clicked').$clickable_string.'" for="u'.$o->sk_id.'">
-              <input id="u'.$o->sk_id.'" type="radio" name="karma_vote" value="'.variable_get('extra_voting_forms_updown_voting_up_'.$o->sk_type, '').'"'.($default>0?' checked="checked"':'').'/>
+            <label class="karma_up'. ($default > 0 ? '_clicked' : '_not_clicked') . $clickable_string .'" for="u'. $o->sk_id .'">
+              <input id="u'. $o->sk_id .'" type="radio" name="karma_vote" value="'. variable_get('extra_voting_forms_updown_voting_up_'. $o->sk_type, '') .'"'. ($default > 0 ? ' checked="checked"' : '') .'/>
               <span>Up</span>
             </label>
-            <label class="karma_down'.($default<0?'_clicked':'_not_clicked').$clickable_string.'" for="d'.$o->sk_id.'">
-              <input id="d'.$o->sk_id.'" type="radio" name="karma_vote" value="'.variable_get('extra_voting_forms_updown_voting_down_'.$o->sk_type, '').'"'.($default<0?' class="karma_clicked" checked="checked"':'').'/>
+            <label class="karma_down'. ($default < 0 ? '_clicked' : '_not_clicked') . $clickable_string .'" for="d'. $o->sk_id .'">
+              <input id="d'. $o->sk_id .'" type="radio" name="karma_vote" value="'. variable_get('extra_voting_forms_updown_voting_down_'. $o->sk_type, '') .'"'. ($default < 0 ? ' class="karma_clicked" checked="checked"' : '') .'/>
               <span>Down</span>
             </label>
-            <input type="hidden" name="oid" value="'.$o->sk_id.'"/>
-            <input type="hidden" name="otype" value="'.$o->sk_type.'"/>
-            <input type="hidden" name="form_style" value="'.$form_style.'"/>
+            <input type="hidden" name="oid" value="'. $o->sk_id .'"/>
+            <input type="hidden" name="otype" value="'. $o->sk_type .'"/>
+            <input type="hidden" name="form_style" value="'. $form_style .'"/>
             <input type="hidden" name="form_type" value="form"/>
-            <input type="submit" name="submit" value="Vote" '.$voting_not_allowed_str.'/>
-            '.extra_voting_forms_js_destination_field($o,$draw_js_destination_variable).'
+            <input type="submit" name="submit" value="Vote" '. $voting_not_allowed_str .'/>
+            '. extra_voting_forms_js_destination_field($o, $draw_js_destination_variable) .'
           </span>
         </form></div>';
       break;
@@ -1269,21 +1253,21 @@ function extra_voting_forms_show_form($o
 
       // Generate form type 4
       $form .= '
-        <div class="extra_voting_forms karma_'.$form_style.'">
-        <form action="'.$action.'" method="get" class="karma_form'.$is_promoted_class.'" id="w'.$o->sk_id.'">
-          '.$negative_karma_str.'
-          '.$karma_score_display.'
+        <div class="extra_voting_forms karma_'. $form_style .'">
+        <form action="'. $action .'" method="get" class="karma_form'. $is_promoted_class .'" id="w'. $o->sk_id .'">
+          '. $negative_karma_str .'
+          '. $karma_score_display .'
           <span class="karma_buttons">
-            <label class="karma_up'.($default>0?'_clicked':'_not_clicked').$clickable_string.'" for="u'.$o->sk_id.'">
-              <input id="u'.$o->sk_id.'" type="radio" name="karma_vote" value="'. variable_get('extra_voting_forms_updown_voting_up_'.$o->sk_type, '').'"/>
+            <label class="karma_up'. ($default > 0 ? '_clicked' : '_not_clicked') . $clickable_string .'" for="u'. $o->sk_id .'">
+              <input id="u'. $o->sk_id .'" type="radio" name="karma_vote" value="'. variable_get('extra_voting_forms_updown_voting_up_'. $o->sk_type, '') .'"/>
               <span>Up</span>
             </label>
-            <input type="hidden" name="oid" value="'.$o->sk_id.'"/>
-            <input type="hidden" name="otype" value="'.$o->sk_type.'"/>
-            <input type="hidden" name="form_style" value="'.$form_style.'"/>
+            <input type="hidden" name="oid" value="'. $o->sk_id .'"/>
+            <input type="hidden" name="otype" value="'. $o->sk_type .'"/>
+            <input type="hidden" name="form_style" value="'. $form_style .'"/>
             <input type="hidden" name="form_type" value="form"/>
-            <input type="submit" name="submit" value="Vote" '.$voting_not_allowed_str.'/>
-            '.extra_voting_forms_js_destination_field($o,$draw_js_destination_variable).'
+            <input type="submit" name="submit" value="Vote" '. $voting_not_allowed_str .'/>
+            '. extra_voting_forms_js_destination_field($o, $draw_js_destination_variable) .'
           </span>
         </form></div>';
     break;
@@ -1299,92 +1283,87 @@ function extra_voting_forms_show_form($o
  *
  * @return
  *   The range
-*/
-function extra_voting_forms_range_calculator($type,$plus_or_minus,$account=NULL){
+ */
+function extra_voting_forms_range_calculator($type, $plus_or_minus, $account = NULL) {
   global $user;
 
   // Check which account to vote from
-  if($account == NULL){
+  if ($account == NULL) {
     $account=$user;
   }
 
   // Check the parameters
-  if($type != 'c' && $type != 'n'){
+  if ($type != 'c' && $type != 'n') {
     return 0;
   }
-  if($plus_or_minus != 'plus' && $plus_or_minus != 'minus'){
+  if ($plus_or_minus != 'plus' && $plus_or_minus != 'minus') {
     return 0;
   }
   
-
-  $range=0;
+  $range = 0;
 
   $range += variable_get("extra_voting_forms_range_users_${plus_or_minus}_$type", 0);
-  if(user_access('voting vote bonus',$account)){
-    $range += variable_get("extra_voting_forms_vote_bonus_${plus_or_minus}_$type",0);
+  if (user_access('voting vote bonus', $account)) {
+    $range += variable_get("extra_voting_forms_vote_bonus_${plus_or_minus}_$type", 0);
   }
-  if(user_access('voting administrator',$account)){
-    $range += variable_get("extra_voting_forms_vote_bonus_admin_${plus_or_minus}_$type",0);
+  if (user_access('voting administrator', $account)) {
+    $range += variable_get("extra_voting_forms_vote_bonus_admin_${plus_or_minus}_$type", 0);
   }
 
-
   // Return a negative range if "minus" was requested
-  if($plus_or_minus == 'minus'){
+  if ($plus_or_minus == 'minus') {
     $range = $range * -1;
   }
 
-  #drupal_set_message("Requested: $type, $plus_or_minus ; Returned: $range");
+  //drupal_set_message("Requested: $type, $plus_or_minus ; Returned: $range");
   return $range;
 
 }
 
-
-
 /** 
  * Implementation of hook_link(). 
  * This will show the form in the link IF the admin set the module
  * to do so, IF the user can vote, IF the user is not anonymous,
  * Note that extra_voting_forms_show_form does all the checking to see
  * if the comment was buried
-*/
+ */
 function extra_voting_forms_link($type, $node = 0, $main = 0) {
 
   // Are we displaying the node's "links" section?
   //
   
-  if($type == 'comment' ){
+  if ($type == 'comment' ) {
 
     // If the system allow karma for comments, AND if the user decided to
     // show the karma form in the "links" section, then add the link
-    if(variable_get('extra_voting_forms_display_in_comment_link', FALSE)){
-      if( variable_get('extra_voting_forms_allow_karma_for_comments', FALSE)){
+    if (variable_get('extra_voting_forms_display_in_comment_link', FALSE)) {
+      if ( variable_get('extra_voting_forms_allow_karma_for_comments', FALSE)) {
       
-        $style=variable_get('extra_voting_forms_display_in_comment_link_style',1);
+        $style = variable_get('extra_voting_forms_display_in_comment_link_style', 1);
 
         // Add the link
-        $output['extra_voting_forms'] = array('title' => extra_voting_forms_show_form($node,'c',$style,'small'), "html" => true);
-        return($output); 
+        $output['extra_voting_forms'] = array('title' => extra_voting_forms_show_form($node, 'c', $style, 'small'), "html" => true);
+        return $output; 
       }
     }
   }
 
-
   // Are we displaying the node's "links" section?
   //
-  if($type == 'node'){
+  if ($type == 'node') {
 
     // If the system allow karma for nodes, AND if the user decided to
     // show the karma form in the "links" section, then add the link
-    if(variable_get('extra_voting_forms_display_in_node_link', FALSE)){
-      if( in_array($node->type, variable_get('extra_voting_forms_node_types_applied', array()), TRUE) ){
+    if (variable_get('extra_voting_forms_display_in_node_link', FALSE)) {
+      if ( in_array($node->type, variable_get('extra_voting_forms_node_types_applied', array()), TRUE) ) {
 
-        $style=variable_get('extra_voting_forms_display_in_node_link_style',1);
+        $style = variable_get('extra_voting_forms_display_in_node_link_style', 1);
 
         // Add the link
-        $output['extra_voting_forms'] = array('title' => extra_voting_forms_show_form($node,'n',$style,'small'), "html" => true);
+        $output['extra_voting_forms'] = array('title' => extra_voting_forms_show_form($node, 'n', $style, 'small'), "html" => true);
       }
     }
-    return($output); 
+    return $output; 
   }
   
 }
