Index: modules/poll.module =================================================================== RCS file: /cvs/drupal/drupal/modules/poll.module,v retrieving revision 1.173 diff -u -F^f -r1.173 poll.module --- modules/poll.module 11 Oct 2005 19:44:35 -0000 1.173 +++ modules/poll.module 26 Oct 2005 14:59:16 -0000 @@ -334,32 +334,53 @@ function theme_poll_view_voting($form) { * Generates a graphical representation of the results of a poll. */ function poll_view_results(&$node, $teaser, $page, $block) { - // Display the results - // Count the votes and find the maximum foreach ($node->choice as $choice) { - $votestotal += $choice['chvotes']; - $votesmax = max($votesmax, $choice['chvotes']); + $total_votes += $choice['chvotes']; + $max_votes = max($max_votes, $choice['chvotes']); } - // Output the divs for the text, bars and percentages - $output .= '
'; - if ($block) { - $output .= '
'. check_plain($node->title) .'
'; - } foreach ($node->choice as $i => $choice) { if ($choice['chtext'] != '') { - $percentage = round($choice['chvotes'] * 100 / max($votestotal, 1)); - $output .= '
'. check_plain($choice['chtext']) .'
'; - $output .= '
'; - $output .= '
'; - $output .= '
'; - $output .= '
'. $percentage .'%'. (!$block ? ' ('. format_plural($choice['chvotes'], '1 vote', '%count votes') .')' : '') .'
'; + $poll_results .= theme('poll_bar', check_plain($choice['chtext']), round($choice['chvotes'] * 100 / max($total_votes, 1)), format_plural($choice['chvotes'], '1 vote', '%count votes'), $block); } } - $output .= '
'. t('Total votes') .": $votestotal
"; - $output .= '
'; + $output .= theme('poll_results', check_plain($node->title), $poll_results, $total_votes, $node->links, $block); + + return $output; +} + +function theme_poll_results($title, $results, $votes, $links, $block) { + if ($block) { + $output .= '
'; + $output .= '
'. $title .'
'; + $output .= $results; + $output .= '
'. t('Total votes: %votes', array('%votes' => $votes)) .'
'; + $output .= '
'; + $output .= ''; + } + else { + $output .= '
'; + $output .= $results; + $output .= '
'. t('Total votes: %votes', array('%votes' => $votes)) .'
'; + $output .= '
'; + } + + return $output; +} + +function theme_poll_bar($title, $percentage, $votes, $block) { + if ($block) { + $output = '
'. $title .'
'; + $output .= '
'; + $output .= '
'. $percentage .'%
'; + } + else { + $output = '
'. $title .'
'; + $output .= '
'; + $output .= '
'. $percentage .'% ('. $votes .')
'; + } return $output; } @@ -423,13 +444,6 @@ function poll_view(&$node, $teaser = FAL global $user; $output = ''; - if ($node->allowvotes && ($block || arg(2) != 'results')) { - $output .= poll_view_voting($node, $teaser, $page, $block); - } - else { - $output .= poll_view_results($node, $teaser, $page, $block); - } - // Special display for side-block if ($block) { // No 'read more' link @@ -441,7 +455,14 @@ function poll_view(&$node, $teaser = FAL $links[] = l(t('results'), 'node/'. $node->nid .'/results', array('title' => t('View the current poll results.'))); } - $output .= ''; + $node->links = $links; + } + + if ($node->allowvotes && ($block || arg(2) != 'results')) { + $output .= poll_view_voting($node, $teaser, $page, $block); + } + else { + $output .= poll_view_results($node, $teaser, $page, $block); } $node->body = $node->teaser = $output; @@ -462,6 +483,4 @@ function poll_update($node) { db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $chtext, $chvotes, $i++); } } -} - - +} \ No newline at end of file