Unverified Commit a8df185c authored by Lester Chan's avatar Lester Chan
Browse files

Fix Division by 0

parent 24b97f77
......@@ -3,7 +3,7 @@ Contributors: GamerZ
Donate link: https://lesterchan.net/site/donation/
Tags: poll, polls, polling, vote, booth, democracy, ajax, survey, post, widget
Requires at least: 4.9.6
Tested up to: 5.0
Tested up to: 5.1
Stable tag: 2.75.3
Adds an AJAX poll system to your WordPress blog. You can also easily add a poll into your WordPress's blog post/page.
......@@ -26,6 +26,7 @@ I spent most of my free time creating, updating, maintaining and supporting thes
## Changelog
### VErsion 2.75.3
* FIXED: Broken filter for templates
* FIXED: Divison by 0 by totalvoters
### Versiob 2.75.2
* FIXED: Missing str_replace for wp_polls_template filter
......@@ -229,6 +230,6 @@ I spent most of my free time creating, updating, maintaining and supporting thes
```php
<?php if ( function_exists( 'get_polltime' ) ): ?>
<?php get_polltime($poll_id, $date_format); ?>
<?php get_polltime( $poll_id, $date_format ); ?>
<?php endif; ?>
```
......@@ -603,6 +603,11 @@ function display_pollresult( $poll_id, $user_voted = array(), $display_loading =
if ( $poll_question_totalvotes > 0 ) {
$poll_totalvotes_zero = false;
}
// Is The Poll Total Voters 0?
$poll_totalvoters_zero = true;
if ( $poll_question_totalvoters > 0 ) {
$poll_totalvoters_zero = false;
}
// Print Out Result Header Template
$temp_pollresult .= "<div id=\"polls-$poll_question_id\" class=\"wp-polls\">\n";
$temp_pollresult .= "\t\t$template_question\n";
......@@ -615,7 +620,7 @@ function display_pollresult( $poll_id, $user_voted = array(), $display_loading =
$poll_answer_percentage = 0;
$poll_multiple_answer_percentage = 0;
$poll_answer_imagewidth = 1;
if ( ! $poll_totalvotes_zero && $poll_answer_votes > 0 ) {
if ( ! $poll_totalvotes_zero && ! $poll_totalvoters_zero && $poll_answer_votes > 0 ) {
$poll_answer_percentage = round( ( $poll_answer_votes / $poll_question_totalvotes ) * 100 );
$poll_multiple_answer_percentage = round( ( $poll_answer_votes / $poll_question_totalvoters ) * 100 );
$poll_answer_imagewidth = round( $poll_answer_percentage );
......@@ -880,13 +885,13 @@ if(!function_exists('get_pollvoters')) {
}
### Function: Get Poll Time Based on Poll ID and Date Format
if(!function_exists('get_polltime')) {
function get_polltime($poll_id, $date_format = 'd/m/Y', $display = true) {
if ( ! function_exists( 'get_polltime' ) ) {
function get_polltime( $poll_id, $date_format = 'd/m/Y', $display = true ) {
global $wpdb;
$poll_id = (int) $poll_id;
$timestamp = (int) $wpdb->get_var( $wpdb->prepare("SELECT pollq_timestamp FROM $wpdb->pollsq WHERE pollq_id = %d LIMIT 1", $poll_id));
$timestamp = (int) $wpdb->get_var( $wpdb->prepare( "SELECT pollq_timestamp FROM $wpdb->pollsq WHERE pollq_id = %d LIMIT 1", $poll_id ) );
$formatted_date = date( $date_format, $timestamp );
if($display) {
if ( $display ) {
echo $formatted_date;
} else {
return $formatted_date;
......@@ -1047,12 +1052,17 @@ function polls_archive() {
if($polls_question['totalvotes'] > 0) {
$poll_totalvotes_zero = false;
}
$poll_start_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $polls_question['start']));
if(empty($polls_question['end'])) {
$poll_end_date = __('No Expiry', 'wp-polls');
} else {
$poll_end_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $polls_question['end']));
}
// Is The Poll Total Voters 0?
$poll_totalvoters_zero = true;
if($polls_question['totalvotesr'] > 0) {
$poll_totalvoters_zero = false;
}
$poll_start_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $polls_question['start']));
if(empty($polls_question['end'])) {
$poll_end_date = __('No Expiry', 'wp-polls');
} else {
$poll_end_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $polls_question['end']));
}
// Archive Poll Header
$template_archive_header = removeslashes(get_option('poll_template_pollarchiveheader'));
// Poll Question Variables
......@@ -1078,7 +1088,7 @@ function polls_archive() {
$poll_answer_percentage = 0;
$poll_multiple_answer_percentage = 0;
$poll_answer_imagewidth = 1;
if ( ! $poll_totalvotes_zero && $polls_answer['votes'] > 0 ) {
if ( ! $poll_totalvotes_zero && ! $poll_totalvoters_zero && $polls_answer['votes'] > 0 ) {
$poll_answer_percentage = round( ( $polls_answer['votes'] / $polls_question['totalvotes'] ) * 100 );
$poll_multiple_answer_percentage = round( ( $polls_answer['votes'] / $polls_question['totalvoters'] ) * 100 );
$poll_answer_imagewidth = round( $poll_answer_percentage * 0.9 );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment