From b86824b69817bd7b0b86c16ef4b2d8fac8319de0 Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Wed, 9 Jun 2010 02:46:26 -0500
Subject: [PATCH] bug #426740 by marvil07: Alternate points style template not used

---
 vote_up_down.module |   54 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 45 insertions(+), 9 deletions(-)

diff --git vote_up_down.module vote_up_down.module
index 512b4cd..bd3cbab 100644
--- vote_up_down.module
+++ vote_up_down.module
@@ -564,8 +564,12 @@ function vote_up_down_vote($type, $cid, $value, $tag = NULL, $ajax = FALSE, $alt
 
 
     if ($ajax) {
-      $style = ($alt == TRUE ? 'alt' : '');
-      print theme('vote_up_down_points', $cid, $type, NULL, $style);
+      if ($alt == TRUE) {
+        print theme('vote_up_down_points_alt', $cid, $type, NULL, 'alt');
+      }
+      else {
+        print theme('vote_up_down_points', $cid, $type, NULL, '');
+      }
       exit();
     }
     else {
@@ -673,7 +677,7 @@ function template_preprocess_vote_up_down_widget_alt(&$variables) {
   drupal_add_css(drupal_get_path('module', 'vote_up_down') .'/vote_up_down.css');
   drupal_add_js(drupal_get_path('module', 'vote_up_down') .'/ajax_vote_up_down.js');
 
-  $variables['points'] = theme('vote_up_down_points', $cid, $type, $tag, 'alt');
+  $variables['points'] = theme('vote_up_down_points_alt', $cid, $type, $tag, 'alt');
   if ((user_access('use vote up') || user_access('use vote down')) && ($user->uid || variable_get('vote_up_down_anonymous_vote', 0))) {
     $criteria = array(
       'content_type' => $type,
@@ -691,7 +695,7 @@ function template_preprocess_vote_up_down_widget_alt(&$variables) {
     }
 
     $token = drupal_get_token("vote_up_down/$type/$cid/1");
-    $variables['title'] = url("vote_up_down/$type/$cid/1/$tag/1", array('query' => 'token='. $token));
+    $variables['title'] = url("vote_up_down/$type/$cid/1/$tag/1/alt", array('query' => 'token='. $token));
     $variables['link'] = l('', "vote_up_down/$type/$cid/1/$tag", array(
                                                'attributes' => array(
                                                  'class' => $variables['class'],
@@ -723,6 +727,34 @@ function template_preprocess_vote_up_down_points(&$variables) {
   $vote_result = (int)votingapi_select_single_result_value($criteria);
   if ($vote_result > 0) {
     $variables['class'] = 'positive';
+  }
+  else {
+    if ($vote_result < 0) {
+      $variables['class'] = 'negative';
+    }
+    else {
+      $variables['class'] = 'neutral';
+    }
+  }
+  $variables['points_labelled'] = format_plural($vote_result, '1 point', '@count points');
+}
+
+/**
+ * Preprocess function for the points in the alt display style.
+ */
+function template_preprocess_vote_up_down_points_alt(&$variables) {
+  $tag = isset($variables['tag']) ? $variables['tag'] : variable_get('vote_up_down_tag', 'vote');
+
+  $criteria = array(
+    'content_type' => $variables['type'],
+    'content_id' => $variables['cid'],
+    'value_type' => 'points',
+    'tag' => $tag,
+    'function' => 'sum'
+  );
+  $vote_result = (int)votingapi_select_single_result_value($criteria);
+  if ($vote_result > 0) {
+    $variables['class'] = 'positive';
     $variables['points'] = '+'. $vote_result;
   }
   else {
@@ -735,10 +767,6 @@ function template_preprocess_vote_up_down_points(&$variables) {
     }
   }
   $variables['label'] = format_plural($vote_result, 'point', 'points');
-  $variables['points_labelled'] = format_plural($vote_result, '1 point', '@count points');
-  if (isset($variables['style'])) {
-    $variables['template_files'][] = 'vote_up_down_points_'. $variables['style'];
-  }
 }
 
 /**
@@ -786,10 +814,18 @@ function vote_up_down_theme() {
         'cid' => NULL,
         'type' => NULL,
         'tag' => NULL,
-        'style' => NULL,
       ),
       'template' => 'theme/vote_up_down_points',
     ),
+    'vote_up_down_points_alt' => array(
+      'file' => 'vote_up_down.module',
+      'arguments' => array(
+        'cid' => NULL,
+        'type' => NULL,
+        'tag' => NULL,
+      ),
+      'template' => 'theme/vote_up_down_points_alt',
+    ),
     'vote_up_down_whovoted_block' => array(
       'file' => 'vote_up_down.module',
       'arguments' => array(
-- 
1.7.1

