Index: advpoll.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advpoll/advpoll.module,v
retrieving revision 1.21.2.88.2.23
diff -u -p -r1.21.2.88.2.23 advpoll.module
--- advpoll.module	30 May 2009 17:16:40 -0000	1.21.2.88.2.23
+++ advpoll.module	13 Aug 2009 15:36:36 -0000
@@ -1744,7 +1744,16 @@ function advpoll_writein_promote_form_su
  * Implementation of hook_theme().
  */
 function advpoll_theme() {
-  return array(
+  $funcs = array();
+
+  $modes = _advpoll_list_modes();
+  foreach ($modes as $mode) {
+    if (function_exists("_advpoll_{$mode['name']}_theme")) {
+      $modes += call_user_func("_advpoll_{$mode['name']}_theme");
+    }
+  }
+
+  return $modes + array(
     'advpoll_page' => array('arguments' => array('' => '')),
     'advpoll_block_latest_poll' => array('arguments' => array()),
     'advpoll_results' => array('arguments' => array('title' => '', 'results' => '', 'votes' => '', 'links' => '', 'nid' => '', 'voted' => '', 'cancel_vote' => '')),
Index: modes/binary.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advpoll/modes/binary.inc,v
retrieving revision 1.7.2.32.2.6
diff -u -p -r1.7.2.32.2.6 binary.inc
--- modes/binary.inc	11 Apr 2009 16:02:50 -0000	1.7.2.32.2.6
+++ modes/binary.inc	13 Aug 2009 15:36:36 -0000
@@ -14,6 +14,12 @@ function advpoll_info_binary() {
   );
 }
 
+function _advpoll_binary_theme() {
+  return array(
+    'advpoll_view_results_binary' => array('arguments' => array(), 'file' => 'modes/binary.inc'),
+  );
+}
+
 function advpoll_algorithms_binary() {
   return array('plurality' => t('Plurality'));
 }
@@ -156,16 +162,31 @@ function advpoll_view_results_binary($no
     arsort($votes);
 
     // Display results for each possible choice
+    $data = array();
     foreach ($votes as $i => $count) {
       $choice = $node->choice[$i];
       $percentage = round(100 * $votes[$i] / $total_votes, 0);
-      $output .= theme('advpoll_bar', _advpoll_choice_markup($choice['label'], $node->format, FALSE), $percentage, format_plural($count, '1 vote', '@count votes'), $choice);
+      $data[] = array(
+        'label' => _advpoll_choice_markup($choice['label'], $node->format, FALSE),
+        'percentage' => $percentage,
+        'votes' => format_plural($count, '1 vote', '@count votes'),
+        'choice' => $choice,
+      );
     }
+    $output = theme('advpoll_view_results_binary', $data);
   }
 
   return array('results' => $output, 'votes' => $total_votes);
 }
 
+function theme_advpoll_view_results_binary($data) {
+  $output = '';
+  foreach ($data as $result) {
+    $output .= theme('advpoll_bar', $result['label'], $result['percentage'], $result['votes'], $result['choice']);
+  }
+  return $output;
+}
+
 function advpoll_calculate_results_binary(&$cache, $node) {
   $result = db_query('SELECT uid, vote_source FROM {votingapi_vote} WHERE content_type = "advpoll" AND content_id = %d AND value_type = "option" GROUP BY uid, vote_source, timestamp', $node->nid);
   $total_votes = 0;
Index: modes/ranking.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advpoll/modes/ranking.inc,v
retrieving revision 1.8.2.37.2.11
diff -u -p -r1.8.2.37.2.11 ranking.inc
--- modes/ranking.inc	11 Apr 2009 16:02:50 -0000	1.8.2.37.2.11
+++ modes/ranking.inc	13 Aug 2009 15:36:36 -0000
@@ -14,6 +14,13 @@ function advpoll_info_ranking() {
   );
 }
 
+function _advpoll_ranking_theme() {
+  return array(
+    'advpoll_view_results_ranking' => array('arguments' => array(), 'file' => 'modes/ranking.inc'),
+  );
+}
+
+
 function advpoll_algorithms_ranking() {
   return array(
     'borda_count' => t('Borda count'),
@@ -256,6 +263,7 @@ function advpoll_view_results_ranking($n
 
     $output = '';
 
+    $data = array();
     if ($node->algorithm == 'borda_count') {
       for ($i = 0; $i < count($ranking); $i++) {
         $first_one = TRUE;
@@ -269,8 +277,14 @@ function advpoll_view_results_ranking($n
         }
 
         $percentage = round(100 * (isset($ranking[$i]->percentage) ? $ranking[$i]->percentage : 0), 0);
-        $output .= theme('advpoll_bar', $this_rank, $percentage, $ranking[$i]->view_score);
+        $data[] = array(
+          'label' => $this_rank,
+          'percentage' => $percentage,
+          'votes' => $ranking[$i]->view_score,
+          'choice' => NULL,
+        );
       }
+      $output = theme('advpoll_view_results_ranking', $data);
     }
     else {
       $output .= '<ol>';
@@ -326,6 +340,15 @@ function advpoll_view_results_ranking($n
   return array('results' => $output, 'votes' => $poll['total_votes']);
 }
 
+function theme_advpoll_view_results_ranking($data) {
+  $output = '';
+  foreach ($data as $result) {
+    $output .= theme('advpoll_bar', $result['label'], $result['percentage'], $result['votes'], $result['choice']);
+  }
+  return $output;
+}
+
+
 /**
  * Calculate the results for a ranking poll based on the algorithm.
  *
