WP-Polls - Version 2.75.3

Version Description

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-Polls
Version 2.75.3
Comparing to
See all releases

Code changes from version 2.75.2 to 2.75.3

Files changed (5) hide show
  1. polls-js.dev.js +77 -107
  2. polls-js.js +1 -7
  3. polls-options.php +1 -1
  4. readme.txt +23 -2
  5. wp-polls.php +184 -161
polls-js.dev.js CHANGED
@@ -1,72 +1,60 @@
1
  // Variables
2
- var poll_id = 0;
3
- var poll_answer_id = '';
4
- var is_being_voted = false;
5
  pollsL10n.show_loading = parseInt(pollsL10n.show_loading);
6
  pollsL10n.show_fading = parseInt(pollsL10n.show_fading);
7
 
8
  // When User Vote For Poll
9
  function poll_vote(current_poll_id) {
10
  jQuery(document).ready(function($) {
11
- if(!is_being_voted) {
12
- set_is_being_voted(true);
13
- poll_id = current_poll_id;
14
- poll_answer_id = '';
15
- poll_multiple_ans = 0;
16
- poll_multiple_ans_count = 0;
17
- if($('#poll_multiple_ans_' + poll_id).length) {
18
- poll_multiple_ans = parseInt($('#poll_multiple_ans_' + poll_id).val());
19
- }
20
- $('#polls_form_' + poll_id + ' input:checkbox, #polls_form_' + poll_id + ' input:radio, #polls_form_' + poll_id + ' option').each(function(i){
21
- if ($(this).is(':checked') || $(this).is(':selected')) {
22
- if(poll_multiple_ans > 0) {
23
- poll_answer_id = $(this).val() + ',' + poll_answer_id;
24
- poll_multiple_ans_count++;
25
- } else {
26
- poll_answer_id = parseInt($(this).val());
27
- }
28
- }
29
- });
30
- if(poll_multiple_ans > 0) {
31
- if(poll_multiple_ans_count > 0 && poll_multiple_ans_count <= poll_multiple_ans) {
32
- poll_answer_id = poll_answer_id.substring(0, (poll_answer_id.length-1));
33
- poll_process();
34
- } else if(poll_multiple_ans_count == 0) {
35
- set_is_being_voted(false);
36
- alert(pollsL10n.text_valid);
37
- } else {
38
- set_is_being_voted(false);
39
- alert(pollsL10n.text_multiple + ' ' + poll_multiple_ans);
40
- }
41
- } else {
42
- if(poll_answer_id > 0) {
43
- poll_process();
44
- } else {
45
- set_is_being_voted(false);
46
- alert(pollsL10n.text_valid);
47
- }
48
- }
49
- } else {
50
- alert(pollsL10n.text_wait);
51
- }
52
  });
53
  }
54
 
55
  // Process Poll (User Click "Vote" Button)
56
- function poll_process() {
57
  jQuery(document).ready(function($) {
58
- poll_nonce = $('#poll_' + poll_id + '_nonce').val();
59
  if(pollsL10n.show_fading) {
60
- $('#polls-' + poll_id).fadeTo('def', 0);
61
  if(pollsL10n.show_loading) {
62
- $('#polls-' + poll_id + '-loading').show();
63
  }
64
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=process&poll_id=' + poll_id + '&poll_' + poll_id + '=' + poll_answer_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
65
  } else {
66
  if(pollsL10n.show_loading) {
67
- $('#polls-' + poll_id + '-loading').show();
68
  }
69
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=process&poll_id=' + poll_id + '&poll_' + poll_id + '=' + poll_answer_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
70
  }
71
  });
72
  }
@@ -74,70 +62,52 @@ function poll_process() {
74
  // Poll's Result (User Click "View Results" Link)
75
  function poll_result(current_poll_id) {
76
  jQuery(document).ready(function($) {
77
- if(!is_being_voted) {
78
- set_is_being_voted(true);
79
- poll_id = current_poll_id;
80
- poll_nonce = $('#poll_' + poll_id + '_nonce').val();
81
- if(pollsL10n.show_fading) {
82
- $('#polls-' + poll_id).fadeTo('def', 0);
83
- if(pollsL10n.show_loading) {
84
- $('#polls-' + poll_id + '-loading').show();
85
- }
86
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=result&poll_id=' + poll_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
87
- } else {
88
- if(pollsL10n.show_loading) {
89
- $('#polls-' + poll_id + '-loading').show();
90
- }
91
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=result&poll_id=' + poll_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
92
- }
93
- } else {
94
- alert(pollsL10n.text_wait);
95
- }
96
  });
97
  }
98
 
99
  // Poll's Voting Booth (User Click "Vote" Link)
100
  function poll_booth(current_poll_id) {
101
  jQuery(document).ready(function($) {
102
- if(!is_being_voted) {
103
- set_is_being_voted(true);
104
- poll_id = current_poll_id;
105
- poll_nonce = $('#poll_' + poll_id + '_nonce').val();
106
- if(pollsL10n.show_fading) {
107
- $('#polls-' + poll_id).fadeTo('def', 0);
108
- if(pollsL10n.show_loading) {
109
- $('#polls-' + poll_id + '-loading').show();
110
- }
111
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=booth&poll_id=' + poll_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
112
- } else {
113
- if(pollsL10n.show_loading) {
114
- $('#polls-' + poll_id + '-loading').show();
115
- }
116
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=booth&poll_id=' + poll_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
117
- }
118
- } else {
119
- alert(pollsL10n.text_wait);
120
- }
121
  });
122
  }
123
 
124
  // Poll Process Successfully
125
- function poll_process_success(data) {
126
- jQuery(document).ready(function($) {
127
- $('#polls-' + poll_id).replaceWith(data);
128
- if(pollsL10n.show_loading) {
129
- $('#polls-' + poll_id + '-loading').hide();
130
- }
131
- if(pollsL10n.show_fading) {
132
- $('#polls-' + poll_id).fadeTo('def', 1);
133
- set_is_being_voted(false);
134
- } else {
135
- set_is_being_voted(false);
136
- }
137
- });
138
- }
139
-
140
- // Set is_being_voted Status
141
- function set_is_being_voted(voted_status) {
142
- is_being_voted = voted_status;
143
  }
1
  // Variables
 
 
 
2
  pollsL10n.show_loading = parseInt(pollsL10n.show_loading);
3
  pollsL10n.show_fading = parseInt(pollsL10n.show_fading);
4
 
5
  // When User Vote For Poll
6
  function poll_vote(current_poll_id) {
7
  jQuery(document).ready(function($) {
8
+ poll_answer_id = '';
9
+ poll_multiple_ans = 0;
10
+ poll_multiple_ans_count = 0;
11
+ if($('#poll_multiple_ans_' + current_poll_id).length) {
12
+ poll_multiple_ans = parseInt($('#poll_multiple_ans_' + current_poll_id).val());
13
+ }
14
+ $('#polls_form_' + current_poll_id + ' input:checkbox, #polls_form_' + current_poll_id + ' input:radio, #polls_form_' + current_poll_id + ' option').each(function(i){
15
+ if ($(this).is(':checked') || $(this).is(':selected')) {
16
+ if(poll_multiple_ans > 0) {
17
+ poll_answer_id = $(this).val() + ',' + poll_answer_id;
18
+ poll_multiple_ans_count++;
19
+ } else {
20
+ poll_answer_id = parseInt($(this).val());
21
+ }
22
+ }
23
+ });
24
+ if(poll_multiple_ans > 0) {
25
+ if(poll_multiple_ans_count > 0 && poll_multiple_ans_count <= poll_multiple_ans) {
26
+ poll_answer_id = poll_answer_id.substring(0, (poll_answer_id.length-1));
27
+ poll_process(current_poll_id, poll_answer_id);
28
+ } else if(poll_multiple_ans_count == 0) {
29
+ alert(pollsL10n.text_valid);
30
+ } else {
31
+ alert(pollsL10n.text_multiple + ' ' + poll_multiple_ans);
32
+ }
33
+ } else {
34
+ if(poll_answer_id > 0) {
35
+ poll_process(current_poll_id, poll_answer_id);
36
+ } else {
37
+ alert(pollsL10n.text_valid);
38
+ }
39
+ }
 
 
 
 
 
 
 
 
 
40
  });
41
  }
42
 
43
  // Process Poll (User Click "Vote" Button)
44
+ function poll_process(current_poll_id, poll_answer_id) {
45
  jQuery(document).ready(function($) {
46
+ poll_nonce = $('#poll_' + current_poll_id + '_nonce').val();
47
  if(pollsL10n.show_fading) {
48
+ $('#polls-' + current_poll_id).fadeTo('def', 0);
49
  if(pollsL10n.show_loading) {
50
+ $('#polls-' + current_poll_id + '-loading').show();
51
  }
52
+ $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=process&poll_id=' + current_poll_id + '&poll_' + current_poll_id + '=' + poll_answer_id + '&poll_' + current_poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success(current_poll_id)});
53
  } else {
54
  if(pollsL10n.show_loading) {
55
+ $('#polls-' + current_poll_id + '-loading').show();
56
  }
57
+ $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=process&poll_id=' + current_poll_id + '&poll_' + current_poll_id + '=' + poll_answer_id + '&poll_' + current_poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success(current_poll_id)});
58
  }
59
  });
60
  }
62
  // Poll's Result (User Click "View Results" Link)
63
  function poll_result(current_poll_id) {
64
  jQuery(document).ready(function($) {
65
+ poll_nonce = $('#poll_' + current_poll_id + '_nonce').val();
66
+ if(pollsL10n.show_fading) {
67
+ $('#polls-' + current_poll_id).fadeTo('def', 0);
68
+ if(pollsL10n.show_loading) {
69
+ $('#polls-' + current_poll_id + '-loading').show();
70
+ }
71
+ $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=result&poll_id=' + current_poll_id + '&poll_' + current_poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success(current_poll_id)});
72
+ } else {
73
+ if(pollsL10n.show_loading) {
74
+ $('#polls-' + current_poll_id + '-loading').show();
75
+ }
76
+ $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=result&poll_id=' + current_poll_id + '&poll_' + current_poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success(current_poll_id)});
77
+ }
 
 
 
 
 
 
78
  });
79
  }
80
 
81
  // Poll's Voting Booth (User Click "Vote" Link)
82
  function poll_booth(current_poll_id) {
83
  jQuery(document).ready(function($) {
84
+ poll_nonce = $('#poll_' + current_poll_id + '_nonce').val();
85
+ if(pollsL10n.show_fading) {
86
+ $('#polls-' + current_poll_id).fadeTo('def', 0);
87
+ if(pollsL10n.show_loading) {
88
+ $('#polls-' + current_poll_id + '-loading').show();
89
+ }
90
+ $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=booth&poll_id=' + current_poll_id + '&poll_' + current_poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success(current_poll_id)});
91
+ } else {
92
+ if(pollsL10n.show_loading) {
93
+ $('#polls-' + current_poll_id + '-loading').show();
94
+ }
95
+ $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=booth&poll_id=' + current_poll_id + '&poll_' + current_poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success(current_poll_id)});
96
+ }
 
 
 
 
 
 
97
  });
98
  }
99
 
100
  // Poll Process Successfully
101
+ function poll_process_success(current_poll_id) {
102
+ return function(data) {
103
+ jQuery(document).ready(function($) {
104
+ $('#polls-' + current_poll_id).replaceWith(data);
105
+ if(pollsL10n.show_loading) {
106
+ $('#polls-' + current_poll_id + '-loading').hide();
107
+ }
108
+ if(pollsL10n.show_fading) {
109
+ $('#polls-' + current_poll_id).fadeTo('def', 1);
110
+ }
111
+ });
112
+ }
 
 
 
 
 
 
113
  }
polls-js.js CHANGED
@@ -1,7 +1 @@
1
- var poll_id=0,poll_answer_id="",is_being_voted=!1;pollsL10n.show_loading=parseInt(pollsL10n.show_loading);pollsL10n.show_fading=parseInt(pollsL10n.show_fading);
2
- function poll_vote(b){jQuery(document).ready(function(a){is_being_voted?alert(pollsL10n.text_wait):(set_is_being_voted(!0),poll_id=b,poll_answer_id="",poll_multiple_ans_count=poll_multiple_ans=0,a("#poll_multiple_ans_"+poll_id).length&&(poll_multiple_ans=parseInt(a("#poll_multiple_ans_"+poll_id).val())),a("#polls_form_"+poll_id+" input:checkbox, #polls_form_"+poll_id+" input:radio, #polls_form_"+poll_id+" option").each(function(b){if(a(this).is(":checked")||a(this).is(":selected"))0<poll_multiple_ans?
3
- (poll_answer_id=a(this).val()+","+poll_answer_id,poll_multiple_ans_count++):poll_answer_id=parseInt(a(this).val())}),0<poll_multiple_ans?0<poll_multiple_ans_count&&poll_multiple_ans_count<=poll_multiple_ans?(poll_answer_id=poll_answer_id.substring(0,poll_answer_id.length-1),poll_process()):0==poll_multiple_ans_count?(set_is_being_voted(!1),alert(pollsL10n.text_valid)):(set_is_being_voted(!1),alert(pollsL10n.text_multiple+" "+poll_multiple_ans)):0<poll_answer_id?poll_process():(set_is_being_voted(!1),
4
- alert(pollsL10n.text_valid)))})}function poll_process(){jQuery(document).ready(function(b){poll_nonce=b("#poll_"+poll_id+"_nonce").val();pollsL10n.show_fading&&b("#polls-"+poll_id).fadeTo("def",0);pollsL10n.show_loading&&b("#polls-"+poll_id+"-loading").show();b.ajax({type:"POST",xhrFields:{withCredentials:!0},url:pollsL10n.ajax_url,data:"action=polls&view=process&poll_id="+poll_id+"&poll_"+poll_id+"="+poll_answer_id+"&poll_"+poll_id+"_nonce="+poll_nonce,cache:!1,success:poll_process_success})})}
5
- function poll_result(b){jQuery(document).ready(function(a){is_being_voted?alert(pollsL10n.text_wait):(set_is_being_voted(!0),poll_id=b,poll_nonce=a("#poll_"+poll_id+"_nonce").val(),pollsL10n.show_fading&&a("#polls-"+poll_id).fadeTo("def",0),pollsL10n.show_loading&&a("#polls-"+poll_id+"-loading").show(),a.ajax({type:"POST",xhrFields:{withCredentials:!0},url:pollsL10n.ajax_url,data:"action=polls&view=result&poll_id="+poll_id+"&poll_"+poll_id+"_nonce="+poll_nonce,cache:!1,success:poll_process_success}))})}
6
- function poll_booth(b){jQuery(document).ready(function(a){is_being_voted?alert(pollsL10n.text_wait):(set_is_being_voted(!0),poll_id=b,poll_nonce=a("#poll_"+poll_id+"_nonce").val(),pollsL10n.show_fading&&a("#polls-"+poll_id).fadeTo("def",0),pollsL10n.show_loading&&a("#polls-"+poll_id+"-loading").show(),a.ajax({type:"POST",xhrFields:{withCredentials:!0},url:pollsL10n.ajax_url,data:"action=polls&view=booth&poll_id="+poll_id+"&poll_"+poll_id+"_nonce="+poll_nonce,cache:!1,success:poll_process_success}))})}
7
- function poll_process_success(b){jQuery(document).ready(function(a){a("#polls-"+poll_id).replaceWith(b);pollsL10n.show_loading&&a("#polls-"+poll_id+"-loading").hide();pollsL10n.show_fading&&a("#polls-"+poll_id).fadeTo("def",1);set_is_being_voted(!1)})}function set_is_being_voted(b){is_being_voted=b};
1
+ function poll_vote(l){jQuery(document).ready(function(o){poll_answer_id="",poll_multiple_ans=0,poll_multiple_ans_count=0,o("#poll_multiple_ans_"+l).length&&(poll_multiple_ans=parseInt(o("#poll_multiple_ans_"+l).val())),o("#polls_form_"+l+" input:checkbox, #polls_form_"+l+" input:radio, #polls_form_"+l+" option").each(function(l){(o(this).is(":checked")||o(this).is(":selected"))&&(poll_multiple_ans>0?(poll_answer_id=o(this).val()+","+poll_answer_id,poll_multiple_ans_count++):poll_answer_id=parseInt(o(this).val()))}),poll_multiple_ans>0?poll_multiple_ans_count>0&&poll_multiple_ans_count<=poll_multiple_ans?(poll_answer_id=poll_answer_id.substring(0,poll_answer_id.length-1),poll_process(l,poll_answer_id)):0==poll_multiple_ans_count?alert(pollsL10n.text_valid):alert(pollsL10n.text_multiple+" "+poll_multiple_ans):poll_answer_id>0?poll_process(l,poll_answer_id):alert(pollsL10n.text_valid)})}function poll_process(l,o){jQuery(document).ready(function(s){poll_nonce=s("#poll_"+l+"_nonce").val(),pollsL10n.show_fading?(s("#polls-"+l).fadeTo("def",0),pollsL10n.show_loading&&s("#polls-"+l+"-loading").show(),s.ajax({type:"POST",xhrFields:{withCredentials:!0},url:pollsL10n.ajax_url,data:"action=polls&view=process&poll_id="+l+"&poll_"+l+"="+o+"&poll_"+l+"_nonce="+poll_nonce,cache:!1,success:poll_process_success(l)})):(pollsL10n.show_loading&&s("#polls-"+l+"-loading").show(),s.ajax({type:"POST",xhrFields:{withCredentials:!0},url:pollsL10n.ajax_url,data:"action=polls&view=process&poll_id="+l+"&poll_"+l+"="+o+"&poll_"+l+"_nonce="+poll_nonce,cache:!1,success:poll_process_success(l)}))})}function poll_result(l){jQuery(document).ready(function(o){poll_nonce=o("#poll_"+l+"_nonce").val(),pollsL10n.show_fading?(o("#polls-"+l).fadeTo("def",0),pollsL10n.show_loading&&o("#polls-"+l+"-loading").show(),o.ajax({type:"POST",xhrFields:{withCredentials:!0},url:pollsL10n.ajax_url,data:"action=polls&view=result&poll_id="+l+"&poll_"+l+"_nonce="+poll_nonce,cache:!1,success:poll_process_success(l)})):(pollsL10n.show_loading&&o("#polls-"+l+"-loading").show(),o.ajax({type:"POST",xhrFields:{withCredentials:!0},url:pollsL10n.ajax_url,data:"action=polls&view=result&poll_id="+l+"&poll_"+l+"_nonce="+poll_nonce,cache:!1,success:poll_process_success(l)}))})}function poll_booth(l){jQuery(document).ready(function(o){poll_nonce=o("#poll_"+l+"_nonce").val(),pollsL10n.show_fading?(o("#polls-"+l).fadeTo("def",0),pollsL10n.show_loading&&o("#polls-"+l+"-loading").show(),o.ajax({type:"POST",xhrFields:{withCredentials:!0},url:pollsL10n.ajax_url,data:"action=polls&view=booth&poll_id="+l+"&poll_"+l+"_nonce="+poll_nonce,cache:!1,success:poll_process_success(l)})):(pollsL10n.show_loading&&o("#polls-"+l+"-loading").show(),o.ajax({type:"POST",xhrFields:{withCredentials:!0},url:pollsL10n.ajax_url,data:"action=polls&view=booth&poll_id="+l+"&poll_"+l+"_nonce="+poll_nonce,cache:!1,success:poll_process_success(l)}))})}function poll_process_success(l){return function(o){jQuery(document).ready(function(s){s("#polls-"+l).replaceWith(o),pollsL10n.show_loading&&s("#polls-"+l+"-loading").hide(),pollsL10n.show_fading&&s("#polls-"+l).fadeTo("def",1)})}}pollsL10n.show_loading=parseInt(pollsL10n.show_loading),pollsL10n.show_fading=parseInt(pollsL10n.show_fading);
 
 
 
 
 
 
polls-options.php CHANGED
@@ -60,7 +60,7 @@ if( isset($_POST['Submit']) && $_POST['Submit'] ) {
60
  'loading' => isset( $_POST['poll_ajax_style_loading'] ) ? (int) sanitize_key( $_POST['poll_ajax_style_loading'] ) : 1,
61
  'fading' => isset( $_POST['poll_ajax_style_fading'] ) ? (int) sanitize_key( $_POST['poll_ajax_style_fading'] ) : 1
62
  );
63
- $poll_ans_sortby = isset( $_POST['poll_ans_sortby'] ) && in_array( $_POST['poll_ans_sortby'], array( 'polla_aid', 'polla_answers', 'RAND()' ), true ) ? $_POST['poll_ans_sortby'] : 'polla_aid';
64
  $poll_ans_sortorder = isset( $_POST['poll_ans_sortorder'] ) && in_array( $_POST['poll_ans_sortorder'], array( 'asc', 'desc' ), true ) ? $_POST['poll_ans_sortorder'] : 'asc';
65
  $poll_ans_result_sortby = isset( $_POST['poll_ans_result_sortby'] ) && in_array( $_POST['poll_ans_result_sortby'], array( 'polla_votes', 'polla_aid', 'polla_answers', 'RAND()' ), true ) ? $_POST['poll_ans_result_sortby'] : 'polla_votes';
66
  $poll_ans_result_sortorder = isset( $_POST['poll_ans_result_sortorder'] ) && in_array( $_POST['poll_ans_result_sortorder'], array( 'asc', 'desc' ), true ) ? $_POST['poll_ans_result_sortorder'] : 'desc';
60
  'loading' => isset( $_POST['poll_ajax_style_loading'] ) ? (int) sanitize_key( $_POST['poll_ajax_style_loading'] ) : 1,
61
  'fading' => isset( $_POST['poll_ajax_style_fading'] ) ? (int) sanitize_key( $_POST['poll_ajax_style_fading'] ) : 1
62
  );
63
+ $poll_ans_sortby = isset( $_POST['poll_ans_sortby'] ) && in_array( $_POST['poll_ans_sortby'], array( 'polla_votes', 'polla_aid', 'polla_answers', 'RAND()' ), true ) ? $_POST['poll_ans_sortby'] : 'polla_aid';
64
  $poll_ans_sortorder = isset( $_POST['poll_ans_sortorder'] ) && in_array( $_POST['poll_ans_sortorder'], array( 'asc', 'desc' ), true ) ? $_POST['poll_ans_sortorder'] : 'asc';
65
  $poll_ans_result_sortby = isset( $_POST['poll_ans_result_sortby'] ) && in_array( $_POST['poll_ans_result_sortby'], array( 'polla_votes', 'polla_aid', 'polla_answers', 'RAND()' ), true ) ? $_POST['poll_ans_result_sortby'] : 'polla_votes';
66
  $poll_ans_result_sortorder = isset( $_POST['poll_ans_result_sortorder'] ) && in_array( $_POST['poll_ans_result_sortorder'], array( 'asc', 'desc' ), true ) ? $_POST['poll_ans_result_sortorder'] : 'desc';
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: GamerZ
3
  Donate link: https://lesterchan.net/site/donation/
4
  Tags: poll, polls, polling, vote, booth, democracy, ajax, survey, post, widget
5
  Requires at least: 4.9.6
6
- Tested up to: 5.0
7
- Stable tag: 2.75.2
8
 
9
  Adds an AJAX poll system to your WordPress blog. You can also easily add a poll into your WordPress's blog post/page.
10
 
@@ -24,6 +24,11 @@ WP-Polls is extremely customizable via templates and css styles and there are to
24
  I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
25
 
26
  ## Changelog
 
 
 
 
 
27
  ### Versiob 2.75.2
28
  * FIXED: Missing str_replace for wp_polls_template filter
29
 
@@ -206,6 +211,14 @@ I spent most of my free time creating, updating, maintaining and supporting thes
206
  <?php endif; ?>
207
  ~~~
208
 
 
 
 
 
 
 
 
 
209
  ### To Display Total Poll Voters
210
 
211
  ~~~
@@ -213,3 +226,11 @@ I spent most of my free time creating, updating, maintaining and supporting thes
213
  <?php get_pollvoters(); ?>
214
  <?php endif; ?>
215
  ~~~
 
 
 
 
 
 
 
 
3
  Donate link: https://lesterchan.net/site/donation/
4
  Tags: poll, polls, polling, vote, booth, democracy, ajax, survey, post, widget
5
  Requires at least: 4.9.6
6
+ Tested up to: 5.3
7
+ Stable tag: 2.75.3
8
 
9
  Adds an AJAX poll system to your WordPress blog. You can also easily add a poll into your WordPress's blog post/page.
10
 
24
  I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
25
 
26
  ## Changelog
27
+ ### VErsion 2.75.3
28
+ * FIXED: Broken filter for templates
29
+ * FIXED: Divison by 0 by totalvoters
30
+ * FIXED: Add whitelist to sortby poll answers
31
+
32
  ### Versiob 2.75.2
33
  * FIXED: Missing str_replace for wp_polls_template filter
34
 
211
  <?php endif; ?>
212
  ~~~
213
 
214
+ ### To Display Poll Votes by ID
215
+
216
+ ~~~
217
+ <?php if ( function_exists( 'get_pollvotes_by_id' ) ): ?>
218
+ <?php get_pollvotes_by_id($poll_id); ?>
219
+ <?php endif; ?>
220
+ ~~~
221
+
222
  ### To Display Total Poll Voters
223
 
224
  ~~~
226
  <?php get_pollvoters(); ?>
227
  <?php endif; ?>
228
  ~~~
229
+
230
+ ### To Display Poll Time by ID and date format
231
+
232
+ ~~~
233
+ <?php if ( function_exists( 'get_polltime' ) ): ?>
234
+ <?php get_polltime( $poll_id, $date_format ); ?>
235
+ <?php endif; ?>
236
+ ~~~
wp-polls.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP-Polls
4
  Plugin URI: https://lesterchan.net/portfolio/programming/php/
5
  Description: Adds an AJAX poll system to your WordPress blog. You can easily include a poll into your WordPress's blog post/page. WP-Polls is extremely customizable via templates and css styles and there are tons of options for you to choose to ensure that WP-Polls runs the way you wanted. It now supports multiple selection of answers.
6
- Version: 2.75.2
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: https://lesterchan.net
9
  Text Domain: wp-polls
@@ -29,7 +29,7 @@ Text Domain: wp-polls
29
  */
30
 
31
  ### Version
32
- define( 'WP_POLLS_VERSION', '2.75.2' );
33
 
34
 
35
  ### Create Text Domain For Translations
@@ -406,17 +406,12 @@ function check_voted_username($poll_id) {
406
  }
407
  }
408
 
409
- add_filter('poll_template_voteheader_markup', 'poll_template_vote_markup', 10, 3);
410
- add_filter('poll_template_votebody_markup', 'poll_template_vote_markup', 10, 3);
411
- add_filter('poll_template_votefooter_markup', 'poll_template_vote_markup', 10, 3);
412
 
413
- function poll_template_vote_markup($template, $poll_db_object, $variables) {
414
-
415
- foreach($variables as $placeholder => $value) {
416
- $template = str_replace($placeholder, $value, $template);
417
- }
418
-
419
- return $template;
420
  }
421
 
422
 
@@ -445,23 +440,15 @@ function display_pollvote($poll_id, $display_loading = true) {
445
 
446
  $template_question = removeslashes(get_option('poll_template_voteheader'));
447
 
448
- $template_question = apply_filters( 'wp_polls_template_voteheader_markup', str_replace( array(
449
- '%POLL_QUESTION%',
450
- '%POLL_ID%',
451
- '%POLL_TOTALVOTES%',
452
- '%POLL_TOTALVOTERS%',
453
- '%POLL_START_DATE%',
454
- '%POLL_END_DATE%',
455
- '%POLL_MULTIPLE_ANS_MAX%'
456
- ), array(
457
- $poll_question_text,
458
- $poll_question_id,
459
- $poll_question_totalvotes,
460
- $poll_question_totalvoters,
461
- $poll_start_date,
462
- $poll_end_date,
463
- $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
464
- ), $template_question ) );
465
 
466
  // Get Poll Answers Data
467
  list($order_by, $sort_order) = _polls_get_ans_sort();
@@ -487,23 +474,15 @@ function display_pollvote($poll_id, $display_loading = true) {
487
  $poll_multiple_answer_percentage = $poll_question_totalvoters > 0 ? round( ( $poll_answer_votes / $poll_question_totalvoters ) * 100 ) : 0;
488
  $template_answer = removeslashes( get_option( 'poll_template_votebody' ) );
489
 
490
- $template_answer = apply_filters( 'wp_polls_template_votebody_markup', str_replace( array(
491
- '%POLL_ID%',
492
- '%POLL_ANSWER_ID%',
493
- '%POLL_ANSWER%',
494
- '%POLL_ANSWER_VOTES%',
495
- '%POLL_ANSWER_PERCENTAGE%',
496
- '%POLL_MULTIPLE_ANSWER_PERCENTAGE%' ,
497
- '%POLL_CHECKBOX_RADIO%'
498
- ), array(
499
- $poll_question_id,
500
- $poll_answer_id,
501
- $poll_answer_text,
502
- number_format_i18n( $poll_answer_votes ),
503
- $poll_answer_percentage,
504
- $poll_multiple_answer_percentage,
505
- $poll_multiple_ans > 0 ? 'checkbox' : 'radio'
506
- ), $template_answer ) );
507
 
508
  // Print Out Voting Form Body Template
509
  $temp_pollvote .= "\t\t$template_answer\n";
@@ -521,19 +500,13 @@ function display_pollvote($poll_id, $display_loading = true) {
521
  // Voting Form Footer Variables
522
  $template_footer = removeslashes(get_option('poll_template_votefooter'));
523
 
524
- $template_footer = apply_filters( 'wp_polls_template_votefooter_markup', str_replace( array(
525
- '%POLL_ID%',
526
- '%POLL_RESULT_URL%',
527
- '%POLL_START_DATE%',
528
- '%POLL_END_DATE%',
529
- '%POLL_MULTIPLE_ANS_MAX%'
530
- ), array(
531
- $poll_question_id,
532
- $poll_result_url,
533
- $poll_start_date,
534
- $poll_end_date,
535
- $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
536
- ), $template_footer ) );
537
 
538
  // Print Out Voting Form Footer Template
539
  $temp_pollvote .= "\t\t$template_footer\n";
@@ -625,11 +598,9 @@ function display_pollresult( $poll_id, $user_voted = array(), $display_loading =
625
  if ( $poll_question && $poll_answers ) {
626
  // Store The Percentage Of The Poll
627
  $poll_answer_percentage_array = array();
628
- // Is The Poll Total Votes 0?
629
- $poll_totalvotes_zero = true;
630
- if ( $poll_question_totalvotes > 0 ) {
631
- $poll_totalvotes_zero = false;
632
- }
633
  // Print Out Result Header Template
634
  $temp_pollresult .= "<div id=\"polls-$poll_question_id\" class=\"wp-polls\">\n";
635
  $temp_pollresult .= "\t\t$template_question\n";
@@ -642,7 +613,7 @@ function display_pollresult( $poll_id, $user_voted = array(), $display_loading =
642
  $poll_answer_percentage = 0;
643
  $poll_multiple_answer_percentage = 0;
644
  $poll_answer_imagewidth = 1;
645
- if ( ! $poll_totalvotes_zero && $poll_answer_votes > 0 ) {
646
  $poll_answer_percentage = round( ( $poll_answer_votes / $poll_question_totalvotes ) * 100 );
647
  $poll_multiple_answer_percentage = round( ( $poll_answer_votes / $poll_question_totalvoters ) * 100 );
648
  $poll_answer_imagewidth = round( $poll_answer_percentage );
@@ -878,6 +849,20 @@ if(!function_exists('get_pollvotes')) {
878
  }
879
  }
880
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
881
 
882
  ### Function: Get Poll Total Voters
883
  if(!function_exists('get_pollvoters')) {
@@ -892,6 +877,21 @@ if(!function_exists('get_pollvoters')) {
892
  }
893
  }
894
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
895
 
896
  ### Function: Check Voted To Get Voted Answer
897
  function check_voted_multiple($poll_id, $polls_ips) {
@@ -1041,16 +1041,14 @@ function polls_archive() {
1041
  $poll_least_votes = 0;
1042
  $poll_least_percentage = 0;
1043
  // Is The Poll Total Votes 0?
1044
- $poll_totalvotes_zero = true;
1045
- if($polls_question['totalvotes'] > 0) {
1046
- $poll_totalvotes_zero = false;
 
 
 
 
1047
  }
1048
- $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']));
1049
- if(empty($polls_question['end'])) {
1050
- $poll_end_date = __('No Expiry', 'wp-polls');
1051
- } else {
1052
- $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']));
1053
- }
1054
  // Archive Poll Header
1055
  $template_archive_header = removeslashes(get_option('poll_template_pollarchiveheader'));
1056
  // Poll Question Variables
@@ -1076,7 +1074,7 @@ function polls_archive() {
1076
  $poll_answer_percentage = 0;
1077
  $poll_multiple_answer_percentage = 0;
1078
  $poll_answer_imagewidth = 1;
1079
- if ( ! $poll_totalvotes_zero && $polls_answer['votes'] > 0 ) {
1080
  $poll_answer_percentage = round( ( $polls_answer['votes'] / $polls_question['totalvotes'] ) * 100 );
1081
  $poll_multiple_answer_percentage = round( ( $polls_answer['votes'] / $polls_question['totalvoters'] ) * 100 );
1082
  $poll_answer_imagewidth = round( $poll_answer_percentage * 0.9 );
@@ -1345,6 +1343,111 @@ function in_pollarchive() {
1345
  return true;
1346
  }
1347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1348
 
1349
  ### Function: Vote Poll
1350
  add_action('wp_ajax_polls', 'vote_poll');
@@ -1376,92 +1479,12 @@ function vote_poll() {
1376
  switch( sanitize_key( $_REQUEST['view'] ) ) {
1377
  // Poll Vote
1378
  case 'process':
1379
- do_action('wp_polls_vote_poll');
1380
- $poll_aid_array = array_unique( array_map('intval', array_map('sanitize_key', explode( ',', $_POST["poll_$poll_id"] ) ) ) );
1381
- $polla_aids = $wpdb->get_col( $wpdb->prepare( "SELECT polla_aid FROM $wpdb->pollsa WHERE polla_qid = %d", $poll_id ) );
1382
-
1383
- $is_real = count( array_intersect( $poll_aid_array, $polla_aids ) ) === count( $poll_aid_array );
1384
- // The multiple ifs is ugly, I know it. Feel free to send a PR to fix it
1385
- if( $is_real ) {
1386
- if($poll_id > 0 && !empty($poll_aid_array) && check_allowtovote()) {
1387
- $is_poll_open = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->pollsq WHERE pollq_id = %d AND pollq_active = 1", $poll_id ) );
1388
- if ( $is_poll_open > 0 ) {
1389
- $check_voted = check_voted($poll_id);
1390
- if ( empty( $check_voted ) ) {
1391
- if (!empty($user_identity)) {
1392
- $pollip_user = $user_identity;
1393
- } elseif ( ! empty( $_COOKIE['comment_author_' . COOKIEHASH] ) ) {
1394
- $pollip_user = $_COOKIE['comment_author_' . COOKIEHASH];
1395
- } else {
1396
- $pollip_user = __('Guest', 'wp-polls');
1397
- }
1398
- $pollip_user = sanitize_text_field( $pollip_user );
1399
- $pollip_userid = $user_ID;
1400
- $pollip_ip = poll_get_ipaddress();
1401
- $pollip_host = poll_get_hostname();
1402
- $pollip_timestamp = current_time('timestamp');
1403
- $poll_logging_method = (int) get_option('poll_logging_method');
1404
- // Only Create Cookie If User Choose Logging Method 1 Or 3
1405
- if ( $poll_logging_method === 1 || $poll_logging_method === 3 ) {
1406
- $cookie_expiry = (int) get_option('poll_cookielog_expiry');
1407
- if ($cookie_expiry === 0) {
1408
- $cookie_expiry = YEAR_IN_SECONDS;
1409
- }
1410
- setcookie( 'voted_' . $poll_id, implode(',', $poll_aid_array ), $pollip_timestamp + $cookie_expiry, apply_filters( 'wp_polls_cookiepath', SITECOOKIEPATH ) );
1411
- }
1412
- $i = 0;
1413
- foreach ($poll_aid_array as $polla_aid) {
1414
- $update_polla_votes = $wpdb->query( "UPDATE $wpdb->pollsa SET polla_votes = (polla_votes + 1) WHERE polla_qid = $poll_id AND polla_aid = $polla_aid" );
1415
- if (!$update_polla_votes) {
1416
- unset($poll_aid_array[$i]);
1417
- }
1418
- $i++;
1419
- }
1420
- $vote_q = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes+" . count( $poll_aid_array ) . "), pollq_totalvoters = (pollq_totalvoters + 1) WHERE pollq_id = $poll_id AND pollq_active = 1");
1421
- if ($vote_q) {
1422
- foreach ($poll_aid_array as $polla_aid) {
1423
- // Log Ratings In DB If User Choose Logging Method 2, 3 or 4
1424
- if ( $poll_logging_method > 1 ){
1425
- $wpdb->insert(
1426
- $wpdb->pollsip,
1427
- array(
1428
- 'pollip_qid' => $poll_id,
1429
- 'pollip_aid' => $polla_aid,
1430
- 'pollip_ip' => $pollip_ip,
1431
- 'pollip_host' => $pollip_host,
1432
- 'pollip_timestamp' => $pollip_timestamp,
1433
- 'pollip_user' => $pollip_user,
1434
- 'pollip_userid' => $pollip_userid
1435
- ),
1436
- array(
1437
- '%s',
1438
- '%s',
1439
- '%s',
1440
- '%s',
1441
- '%s',
1442
- '%s',
1443
- '%d'
1444
- )
1445
- );
1446
- }
1447
- }
1448
- echo display_pollresult($poll_id, $poll_aid_array, false);
1449
- do_action( 'wp_polls_vote_poll_success' );
1450
- } else {
1451
- printf(__('Unable To Update Poll Total Votes And Poll Total Voters. Poll ID #%s', 'wp-polls'), $poll_id);
1452
- } // End if($vote_a)
1453
- } else {
1454
- printf(__('You Had Already Voted For This Poll. Poll ID #%s', 'wp-polls'), $poll_id);
1455
- } // End if($check_voted)
1456
- } else {
1457
- printf( __( 'Poll ID #%s is closed', 'wp-polls' ), $poll_id );
1458
- } // End if($is_poll_open > 0)
1459
- } else {
1460
- printf(__('Invalid Poll ID. Poll ID #%s', 'wp-polls'), $poll_id);
1461
- } // End if($poll_id > 0 && !empty($poll_aid_array) && check_allowtovote())
1462
- } else {
1463
- printf(__('Invalid Answer to Poll ID #%s', 'wp-polls'), $poll_id);
1464
- } //End if(!isRealAnswer($poll_id,$poll_aid))
1465
  break;
1466
  // Poll Result
1467
  case 'result':
3
  Plugin Name: WP-Polls
4
  Plugin URI: https://lesterchan.net/portfolio/programming/php/
5
  Description: Adds an AJAX poll system to your WordPress blog. You can easily include a poll into your WordPress's blog post/page. WP-Polls is extremely customizable via templates and css styles and there are tons of options for you to choose to ensure that WP-Polls runs the way you wanted. It now supports multiple selection of answers.
6
+ Version: 2.75.3
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: https://lesterchan.net
9
  Text Domain: wp-polls
29
  */
30
 
31
  ### Version
32
+ define( 'WP_POLLS_VERSION', '2.75.3' );
33
 
34
 
35
  ### Create Text Domain For Translations
406
  }
407
  }
408
 
409
+ add_filter( 'wp_polls_template_voteheader_markup', 'poll_template_vote_markup', 10, 3 );
410
+ add_filter( 'wp_polls_template_votebody_markup', 'poll_template_vote_markup', 10, 3 );
411
+ add_filter( 'wp_polls_template_votefooter_markup', 'poll_template_vote_markup', 10, 3) ;
412
 
413
+ function poll_template_vote_markup( $template, $object, $variables ) {
414
+ return str_replace( array_keys( $variables ), array_values( $variables ), $template ) ;
 
 
 
 
 
415
  }
416
 
417
 
440
 
441
  $template_question = removeslashes(get_option('poll_template_voteheader'));
442
 
443
+ $template_question = apply_filters( 'wp_polls_template_voteheader_markup', $template_question, $poll_question, array(
444
+ '%POLL_QUESTION%' => $poll_question_text,
445
+ '%POLL_ID%' => $poll_question_id,
446
+ '%POLL_TOTALVOTES%' => $poll_question_totalvotes,
447
+ '%POLL_TOTALVOTERS%' => $poll_question_totalvoters,
448
+ '%POLL_START_DATE%' => $poll_start_date,
449
+ '%POLL_END_DATE%' => $poll_end_date,
450
+ '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
451
+ ) );
 
 
 
 
 
 
 
 
452
 
453
  // Get Poll Answers Data
454
  list($order_by, $sort_order) = _polls_get_ans_sort();
474
  $poll_multiple_answer_percentage = $poll_question_totalvoters > 0 ? round( ( $poll_answer_votes / $poll_question_totalvoters ) * 100 ) : 0;
475
  $template_answer = removeslashes( get_option( 'poll_template_votebody' ) );
476
 
477
+ $template_answer = apply_filters( 'wp_polls_template_votebody_markup', $template_answer, $poll_answer, array(
478
+ '%POLL_ID%' => $poll_question_id,
479
+ '%POLL_ANSWER_ID%' => $poll_answer_id,
480
+ '%POLL_ANSWER%' => $poll_answer_text,
481
+ '%POLL_ANSWER_VOTES%' => number_format_i18n( $poll_answer_votes ),
482
+ '%POLL_ANSWER_PERCENTAGE%' => $poll_answer_percentage,
483
+ '%POLL_MULTIPLE_ANSWER_PERCENTAGE%' => $poll_multiple_answer_percentage,
484
+ '%POLL_CHECKBOX_RADIO%' => $poll_multiple_ans > 0 ? 'checkbox' : 'radio'
485
+ ) );
 
 
 
 
 
 
 
 
486
 
487
  // Print Out Voting Form Body Template
488
  $temp_pollvote .= "\t\t$template_answer\n";
500
  // Voting Form Footer Variables
501
  $template_footer = removeslashes(get_option('poll_template_votefooter'));
502
 
503
+ $template_footer = apply_filters( 'wp_polls_template_votefooter_markup', $template_footer, $poll_question, array(
504
+ '%POLL_ID%' => $poll_question_id,
505
+ '%POLL_RESULT_URL%' => $poll_result_url,
506
+ '%POLL_START_DATE%' => $poll_start_date,
507
+ '%POLL_END_DATE%' => $poll_end_date,
508
+ '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
509
+ ) );
 
 
 
 
 
 
510
 
511
  // Print Out Voting Form Footer Template
512
  $temp_pollvote .= "\t\t$template_footer\n";
598
  if ( $poll_question && $poll_answers ) {
599
  // Store The Percentage Of The Poll
600
  $poll_answer_percentage_array = array();
601
+ // Is The Poll Total Votes or Voters 0?
602
+ $poll_totalvotes_zero = $poll_question_totalvotes <= 0;
603
+ $poll_totalvoters_zero = $poll_question_totalvoters <= 0;
 
 
604
  // Print Out Result Header Template
605
  $temp_pollresult .= "<div id=\"polls-$poll_question_id\" class=\"wp-polls\">\n";
606
  $temp_pollresult .= "\t\t$template_question\n";
613
  $poll_answer_percentage = 0;
614
  $poll_multiple_answer_percentage = 0;
615
  $poll_answer_imagewidth = 1;
616
+ if ( ! $poll_totalvotes_zero && ! $poll_totalvoters_zero && $poll_answer_votes > 0 ) {
617
  $poll_answer_percentage = round( ( $poll_answer_votes / $poll_question_totalvotes ) * 100 );
618
  $poll_multiple_answer_percentage = round( ( $poll_answer_votes / $poll_question_totalvoters ) * 100 );
619
  $poll_answer_imagewidth = round( $poll_answer_percentage );
849
  }
850
  }
851
 
852
+ ### Function: Get Poll Votes Based on Poll ID
853
+ if(!function_exists('get_pollvotes_by_id')) {
854
+ function get_pollvotes_by_id($poll_id, $display = true) {
855
+ global $wpdb;
856
+ $poll_id = (int) $poll_id;
857
+ $totalvotes = (int) $wpdb->get_var( $wpdb->prepare("SELECT pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = %d LIMIT 1", $poll_id));
858
+ if($display) {
859
+ echo $totalvotes;
860
+ } else {
861
+ return $totalvotes;
862
+ }
863
+ }
864
+ }
865
+
866
 
867
  ### Function: Get Poll Total Voters
868
  if(!function_exists('get_pollvoters')) {
877
  }
878
  }
879
 
880
+ ### Function: Get Poll Time Based on Poll ID and Date Format
881
+ if ( ! function_exists( 'get_polltime' ) ) {
882
+ function get_polltime( $poll_id, $date_format = 'd/m/Y', $display = true ) {
883
+ global $wpdb;
884
+ $poll_id = (int) $poll_id;
885
+ $timestamp = (int) $wpdb->get_var( $wpdb->prepare( "SELECT pollq_timestamp FROM $wpdb->pollsq WHERE pollq_id = %d LIMIT 1", $poll_id ) );
886
+ $formatted_date = date( $date_format, $timestamp );
887
+ if ( $display ) {
888
+ echo $formatted_date;
889
+ } else {
890
+ return $formatted_date;
891
+ }
892
+ }
893
+ }
894
+
895
 
896
  ### Function: Check Voted To Get Voted Answer
897
  function check_voted_multiple($poll_id, $polls_ips) {
1041
  $poll_least_votes = 0;
1042
  $poll_least_percentage = 0;
1043
  // Is The Poll Total Votes 0?
1044
+ $poll_totalvotes_zero = $polls_question['totalvotes'] <= 0;
1045
+ $poll_totalvoters_zero = $polls_question['totalvoters'] <= 0;
1046
+ $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']));
1047
+ if(empty($polls_question['end'])) {
1048
+ $poll_end_date = __('No Expiry', 'wp-polls');
1049
+ } else {
1050
+ $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']));
1051
  }
 
 
 
 
 
 
1052
  // Archive Poll Header
1053
  $template_archive_header = removeslashes(get_option('poll_template_pollarchiveheader'));
1054
  // Poll Question Variables
1074
  $poll_answer_percentage = 0;
1075
  $poll_multiple_answer_percentage = 0;
1076
  $poll_answer_imagewidth = 1;
1077
+ if ( ! $poll_totalvotes_zero && ! $poll_totalvoters_zero && $polls_answer['votes'] > 0 ) {
1078
  $poll_answer_percentage = round( ( $polls_answer['votes'] / $polls_question['totalvotes'] ) * 100 );
1079
  $poll_multiple_answer_percentage = round( ( $polls_answer['votes'] / $polls_question['totalvoters'] ) * 100 );
1080
  $poll_answer_imagewidth = round( $poll_answer_percentage * 0.9 );
1343
  return true;
1344
  }
1345
 
1346
+ function vote_poll_process($poll_id, $poll_aid_array = [])
1347
+ {
1348
+ global $wpdb, $user_identity, $user_ID;
1349
+
1350
+ do_action('wp_polls_vote_poll');
1351
+
1352
+ $polla_aids = $wpdb->get_col( $wpdb->prepare( "SELECT polla_aid FROM $wpdb->pollsa WHERE polla_qid = %d", $poll_id ) );
1353
+ $is_real = count( array_intersect( $poll_aid_array, $polla_aids ) ) === count( $poll_aid_array );
1354
+
1355
+ if( !$is_real ) {
1356
+ throw new InvalidArgumentException(sprintf(__('Invalid Answer to Poll ID #%s', 'wp-polls'), $poll_id));
1357
+ }
1358
+
1359
+ if (!check_allowtovote()) {
1360
+ throw new InvalidArgumentException(sprintf(__('User is not allowed to vote for Poll ID #%s', 'wp-polls'), $poll_id));
1361
+ }
1362
+
1363
+ if (empty($poll_aid_array)) {
1364
+ throw new InvalidArgumentException(sprintf(__('No anwsers given for Poll ID #%s', 'wp-polls'), $poll_id));
1365
+ }
1366
+
1367
+ if($poll_id === 0) {
1368
+ throw new InvalidArgumentException(sprintf(__('Invalid Poll ID. Poll ID #%s', 'wp-polls'), $poll_id));
1369
+ }
1370
+
1371
+ $is_poll_open = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->pollsq WHERE pollq_id = %d AND pollq_active = 1", $poll_id ) );
1372
+
1373
+ if ($is_poll_open === 0) {
1374
+ throw new InvalidArgumentException(sprintf(__( 'Poll ID #%s is closed', 'wp-polls' ), $poll_id ));
1375
+ }
1376
+
1377
+ $check_voted = check_voted($poll_id);
1378
+ if ( !empty( $check_voted ) ) {
1379
+ throw new InvalidArgumentException(sprintf(__('You Had Already Voted For This Poll. Poll ID #%s', 'wp-polls'), $poll_id));
1380
+ }
1381
+
1382
+ if (!empty($user_identity)) {
1383
+ $pollip_user = $user_identity;
1384
+ } elseif ( ! empty( $_COOKIE['comment_author_' . COOKIEHASH] ) ) {
1385
+ $pollip_user = $_COOKIE['comment_author_' . COOKIEHASH];
1386
+ } else {
1387
+ $pollip_user = __('Guest', 'wp-polls');
1388
+ }
1389
+
1390
+ $pollip_user = sanitize_text_field( $pollip_user );
1391
+ $pollip_userid = $user_ID;
1392
+ $pollip_ip = poll_get_ipaddress();
1393
+ $pollip_host = poll_get_hostname();
1394
+ $pollip_timestamp = current_time('timestamp');
1395
+ $poll_logging_method = (int) get_option('poll_logging_method');
1396
+
1397
+ // Only Create Cookie If User Choose Logging Method 1 Or 3
1398
+ if ( $poll_logging_method === 1 || $poll_logging_method === 3 ) {
1399
+ $cookie_expiry = (int) get_option('poll_cookielog_expiry');
1400
+ if ($cookie_expiry === 0) {
1401
+ $cookie_expiry = YEAR_IN_SECONDS;
1402
+ }
1403
+ setcookie( 'voted_' . $poll_id, implode(',', $poll_aid_array ), $pollip_timestamp + $cookie_expiry, apply_filters( 'wp_polls_cookiepath', SITECOOKIEPATH ) );
1404
+ }
1405
+
1406
+ $i = 0;
1407
+ foreach ($poll_aid_array as $polla_aid) {
1408
+ $update_polla_votes = $wpdb->query( "UPDATE $wpdb->pollsa SET polla_votes = (polla_votes + 1) WHERE polla_qid = $poll_id AND polla_aid = $polla_aid" );
1409
+ if (!$update_polla_votes) {
1410
+ unset($poll_aid_array[$i]);
1411
+ }
1412
+ $i++;
1413
+ }
1414
+
1415
+ $vote_q = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes+" . count( $poll_aid_array ) . "), pollq_totalvoters = (pollq_totalvoters + 1) WHERE pollq_id = $poll_id AND pollq_active = 1");
1416
+ if (!$vote_q) {
1417
+ throw new InvalidArgumentException(sprintf(__('Unable To Update Poll Total Votes And Poll Total Voters. Poll ID #%s', 'wp-polls'), $poll_id));
1418
+ }
1419
+
1420
+ foreach ($poll_aid_array as $polla_aid) {
1421
+ // Log Ratings In DB If User Choose Logging Method 2, 3 or 4
1422
+ if ( $poll_logging_method > 1 ){
1423
+ $wpdb->insert(
1424
+ $wpdb->pollsip,
1425
+ array(
1426
+ 'pollip_qid' => $poll_id,
1427
+ 'pollip_aid' => $polla_aid,
1428
+ 'pollip_ip' => $pollip_ip,
1429
+ 'pollip_host' => $pollip_host,
1430
+ 'pollip_timestamp' => $pollip_timestamp,
1431
+ 'pollip_user' => $pollip_user,
1432
+ 'pollip_userid' => $pollip_userid
1433
+ ),
1434
+ array(
1435
+ '%s',
1436
+ '%s',
1437
+ '%s',
1438
+ '%s',
1439
+ '%s',
1440
+ '%s',
1441
+ '%d'
1442
+ )
1443
+ );
1444
+ }
1445
+ }
1446
+ do_action( 'wp_polls_vote_poll_success' );
1447
+
1448
+ return display_pollresult($poll_id, $poll_aid_array, false);
1449
+ }
1450
+
1451
 
1452
  ### Function: Vote Poll
1453
  add_action('wp_ajax_polls', 'vote_poll');
1479
  switch( sanitize_key( $_REQUEST['view'] ) ) {
1480
  // Poll Vote
1481
  case 'process':
1482
+ try {
1483
+ $poll_aid_array = array_unique( array_map('intval', array_map('sanitize_key', explode( ',', $_POST["poll_$poll_id"] ) ) ) );
1484
+ echo vote_poll_process($poll_id, $poll_aid_array);
1485
+ } catch (Exception $e) {
1486
+ echo $e->getMessage();
1487
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1488
  break;
1489
  // Poll Result
1490
  case 'result':