WP-Polls - Version 2.72

Version Description

N/A

Download this release

Release Info

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

Code changes from version 2.71 to 2.72

Files changed (6) hide show
  1. polls-add.php +186 -152
  2. polls-logs.php +337 -354
  3. polls-manager.php +488 -448
  4. polls-options.php +0 -11
  5. readme.txt +7 -1
  6. wp-polls.php +1626 -1550
polls-add.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  ### Check Whether User Can Manage Polls
3
  if(!current_user_can('manage_polls')) {
4
- die('Access Denied');
5
  }
6
 
7
  ### Poll Manager
@@ -10,88 +10,122 @@ $base_page = 'admin.php?page='.$base_name;
10
 
11
  ### Form Processing
12
  if(!empty($_POST['do'])) {
13
- // Decide What To Do
14
- switch($_POST['do']) {
15
- // Add Poll
16
- case __('Add Poll', 'wp-polls'):
17
- check_admin_referer('wp-polls_add-poll');
18
- // Poll Question
19
- $pollq_question = addslashes( wp_kses_post( trim( $_POST['pollq_question'] ) ) );
20
- if( ! empty( $pollq_question ) ) {
21
- // Poll Start Date
22
- $timestamp_sql = '';
23
- $pollq_timestamp_day = intval($_POST['pollq_timestamp_day']);
24
- $pollq_timestamp_month = intval($_POST['pollq_timestamp_month']);
25
- $pollq_timestamp_year = intval($_POST['pollq_timestamp_year']);
26
- $pollq_timestamp_hour = intval($_POST['pollq_timestamp_hour']);
27
- $pollq_timestamp_minute = intval($_POST['pollq_timestamp_minute']);
28
- $pollq_timestamp_second = intval($_POST['pollq_timestamp_second']);
29
- $pollq_timestamp = gmmktime($pollq_timestamp_hour, $pollq_timestamp_minute, $pollq_timestamp_second, $pollq_timestamp_month, $pollq_timestamp_day, $pollq_timestamp_year);
30
- if ($pollq_timestamp > current_time('timestamp')) {
31
- $pollq_active = -1;
32
- } else {
33
- $pollq_active = 1;
34
- }
35
- // Poll End Date
36
- $pollq_expiry_no = intval($_POST['pollq_expiry_no']);
37
- if ($pollq_expiry_no == 1) {
38
- $pollq_expiry = '';
39
- } else {
40
- $pollq_expiry_day = intval($_POST['pollq_expiry_day']);
41
- $pollq_expiry_month = intval($_POST['pollq_expiry_month']);
42
- $pollq_expiry_year = intval($_POST['pollq_expiry_year']);
43
- $pollq_expiry_hour = intval($_POST['pollq_expiry_hour']);
44
- $pollq_expiry_minute = intval($_POST['pollq_expiry_minute']);
45
- $pollq_expiry_second = intval($_POST['pollq_expiry_second']);
46
- $pollq_expiry = gmmktime($pollq_expiry_hour, $pollq_expiry_minute, $pollq_expiry_second, $pollq_expiry_month, $pollq_expiry_day, $pollq_expiry_year);
47
- if ($pollq_expiry <= current_time('timestamp')) {
48
- $pollq_active = 0;
49
- }
50
- }
51
- // Mutilple Poll
52
- $pollq_multiple_yes = intval($_POST['pollq_multiple_yes']);
53
- $pollq_multiple = 0;
54
- if ($pollq_multiple_yes == 1) {
55
- $pollq_multiple = intval($_POST['pollq_multiple']);
56
- } else {
57
- $pollq_multiple = 0;
58
- }
59
- // Insert Poll
60
- $add_poll_question = $wpdb->query("INSERT INTO $wpdb->pollsq VALUES (0, '$pollq_question', '$pollq_timestamp', 0, $pollq_active, '$pollq_expiry', $pollq_multiple, 0)");
61
- if (!$add_poll_question) {
62
- $text .= '<p style="color: red;">' . sprintf(__('Error In Adding Poll \'%s\'.', 'wp-polls'), stripslashes($pollq_question)) . '</p>';
63
- }
64
- // Add Poll Answers
65
- $polla_answers = $_POST['polla_answers'];
66
- $polla_qid = intval($wpdb->insert_id);
67
- foreach ($polla_answers as $polla_answer) {
68
- $polla_answer = addslashes( wp_kses_post( trim( $polla_answer ) ) );
69
- if( ! empty( $polla_answer ) ) {
70
- $add_poll_answers = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answer', 0)");
71
- if (!$add_poll_answers) {
72
- $text .= '<p style="color: red;">' . sprintf(__('Error In Adding Poll\'s Answer \'%s\'.', 'wp-polls'), stripslashes($polla_answer)) . '</p>';
73
- }
74
- } else {
75
- $text .= '<p style="color: red;">' . __( 'Poll\'s Answer is empty.', 'wp-polls' ) . '</p>';
76
- }
77
- }
78
- // Update Lastest Poll ID To Poll Options
79
- $latest_pollid = polls_latest_id();
80
- $update_latestpoll = update_option('poll_latestpoll', $latest_pollid);
81
- if ( empty( $text ) ) {
82
- $text = '<p style="color: green;">' . sprintf( __( 'Poll \'%s\' (ID: %s) added successfully. Embed this poll with the shortcode: %s or go back to <a href="%s">Manage Polls</a>', 'wp-polls' ), stripslashes( $pollq_question ), $latest_pollid, '<input type="text" value=\'[poll id="' . $latest_pollid . '"]\' readonly="readonly" size="10" />', $base_page ) . '</p>';
83
- } else {
84
- if( $add_poll_question ) {
85
- $text .= '<p style="color: green;">' . sprintf( __( 'Poll \'%s\' (ID: %s) (Shortcode: %s) added successfully, but there are some errors with the Poll\'s Answers. Embed this poll with the shortcode: %s or go back to <a href="%s">Manage Polls</a>', 'wp-polls' ), stripslashes( $pollq_question ), $latest_pollid, '<input type="text" value=\'[poll id="' . $latest_pollid . '"]\' readonly="readonly" size="10" />' ) .'</p>';
86
- }
87
- }
88
- do_action( 'wp_polls_add_poll', $latest_pollid );
89
- cron_polls_place();
90
- } else {
91
- $text .= '<p style="color: red;">' . __( 'Poll Question is empty.', 'wp-polls' ) . '</p>';
92
- }
93
- break;
94
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  }
96
 
97
  ### Add Poll Form
@@ -102,73 +136,73 @@ $count = 0;
102
  <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
103
  <?php wp_nonce_field('wp-polls_add-poll'); ?>
104
  <div class="wrap">
105
- <h2><?php _e('Add Poll', 'wp-polls'); ?></h2>
106
- <!-- Poll Question -->
107
- <h3><?php _e('Poll Question', 'wp-polls'); ?></h3>
108
- <table class="form-table">
109
- <tr>
110
- <th width="20%" scope="row" valign="top"><?php _e('Question', 'wp-polls') ?></th>
111
- <td width="80%"><input type="text" size="70" name="pollq_question" value="" /></td>
112
- </tr>
113
- </table>
114
- <!-- Poll Answers -->
115
- <h3><?php _e('Poll Answers', 'wp-polls'); ?></h3>
116
- <table class="form-table">
117
- <tfoot>
118
- <tr>
119
- <td width="20%">&nbsp;</td>
120
- <td width="80%"><input type="button" value="<?php _e('Add Answer', 'wp-polls') ?>" onclick="add_poll_answer_add();" class="button" /></td>
121
- </tr>
122
- </tfoot>
123
- <tbody id="poll_answers">
124
- <?php
125
- for($i = 1; $i <= $poll_noquestion; $i++) {
126
- echo "<tr id=\"poll-answer-$i\">\n";
127
- echo "<th width=\"20%\" scope=\"row\" valign=\"top\">".sprintf(__('Answer %s', 'wp-polls'), number_format_i18n($i))."</th>\n";
128
- echo "<td width=\"80%\"><input type=\"text\" size=\"50\" maxlength=\"200\" name=\"polla_answers[]\" />&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\"".__('Remove', 'wp-polls')."\" onclick=\"remove_poll_answer_add(".$i.");\" class=\"button\" /></td>\n";
129
- echo "</tr>\n";
130
- $count++;
131
- }
132
- ?>
133
- </tbody>
134
- </table>
135
- <!-- Poll Multiple Answers -->
136
- <h3><?php _e('Poll Multiple Answers', 'wp-polls') ?></h3>
137
- <table class="form-table">
138
- <tr>
139
- <th width="40%" scope="row" valign="top"><?php _e('Allows Users To Select More Than One Answer?', 'wp-polls'); ?></th>
140
- <td width="60%">
141
- <select name="pollq_multiple_yes" id="pollq_multiple_yes" size="1" onchange="check_pollq_multiple();">
142
- <option value="0"><?php _e('No', 'wp-polls'); ?></option>
143
- <option value="1"><?php _e('Yes', 'wp-polls'); ?></option>
144
- </select>
145
- </td>
146
- </tr>
147
- <tr>
148
- <th width="40%" scope="row" valign="top"><?php _e('Maximum Number Of Selected Answers Allowed?', 'wp-polls') ?></th>
149
- <td width="60%">
150
- <select name="pollq_multiple" id="pollq_multiple" size="1" disabled="disabled">
151
- <?php
152
- for($i = 1; $i <= $poll_noquestion; $i++) {
153
- echo "<option value=\"$i\">".number_format_i18n($i)."</option>\n";
154
- }
155
- ?>
156
- </select>
157
- </td>
158
- </tr>
159
- </table>
160
- <!-- Poll Start/End Date -->
161
- <h3><?php _e('Poll Start/End Date', 'wp-polls'); ?></h3>
162
- <table class="form-table">
163
- <tr>
164
- <th width="20%" scope="row" valign="top"><?php _e('Start Date/Time', 'wp-polls') ?></th>
165
- <td width="80%"><?php poll_timestamp(current_time('timestamp')); ?></td>
166
- </tr>
167
- <tr>
168
- <th width="20%" scope="row" valign="top"><?php _e('End Date/Time', 'wp-polls') ?></th>
169
- <td width="80%"><input type="checkbox" name="pollq_expiry_no" id="pollq_expiry_no" value="1" checked="checked" onclick="check_pollexpiry();" />&nbsp;&nbsp;<label for="pollq_expiry_no"><?php _e('Do NOT Expire This Poll', 'wp-polls'); ?></label><?php poll_timestamp(current_time('timestamp'), 'pollq_expiry', 'none'); ?></td>
170
- </tr>
171
- </table>
172
- <p style="text-align: center;"><input type="submit" name="do" value="<?php _e('Add Poll', 'wp-polls'); ?>" class="button-primary" />&nbsp;&nbsp;<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-polls'); ?>" class="button" onclick="javascript:history.go(-1)" /></p>
173
  </div>
174
- </form>
1
  <?php
2
  ### Check Whether User Can Manage Polls
3
  if(!current_user_can('manage_polls')) {
4
+ die('Access Denied');
5
  }
6
 
7
  ### Poll Manager
10
 
11
  ### Form Processing
12
  if(!empty($_POST['do'])) {
13
+ // Decide What To Do
14
+ switch($_POST['do']) {
15
+ // Add Poll
16
+ case __('Add Poll', 'wp-polls'):
17
+ check_admin_referer('wp-polls_add-poll');
18
+ // Poll Question
19
+ $pollq_question = wp_kses_post( trim( $_POST['pollq_question'] ) );
20
+ if( ! empty( $pollq_question ) ) {
21
+ // Poll Start Date
22
+ $timestamp_sql = '';
23
+ $pollq_timestamp_day = intval($_POST['pollq_timestamp_day']);
24
+ $pollq_timestamp_month = intval($_POST['pollq_timestamp_month']);
25
+ $pollq_timestamp_year = intval($_POST['pollq_timestamp_year']);
26
+ $pollq_timestamp_hour = intval($_POST['pollq_timestamp_hour']);
27
+ $pollq_timestamp_minute = intval($_POST['pollq_timestamp_minute']);
28
+ $pollq_timestamp_second = intval($_POST['pollq_timestamp_second']);
29
+ $pollq_timestamp = gmmktime($pollq_timestamp_hour, $pollq_timestamp_minute, $pollq_timestamp_second, $pollq_timestamp_month, $pollq_timestamp_day, $pollq_timestamp_year);
30
+ if ($pollq_timestamp > current_time('timestamp')) {
31
+ $pollq_active = -1;
32
+ } else {
33
+ $pollq_active = 1;
34
+ }
35
+ // Poll End Date
36
+ $pollq_expiry_no = isset( $_POST['pollq_expiry_no'] ) ? intval($_POST['pollq_expiry_no']) : 0;
37
+ if ($pollq_expiry_no == 1) {
38
+ $pollq_expiry = '';
39
+ } else {
40
+ $pollq_expiry_day = intval($_POST['pollq_expiry_day']);
41
+ $pollq_expiry_month = intval($_POST['pollq_expiry_month']);
42
+ $pollq_expiry_year = intval($_POST['pollq_expiry_year']);
43
+ $pollq_expiry_hour = intval($_POST['pollq_expiry_hour']);
44
+ $pollq_expiry_minute = intval($_POST['pollq_expiry_minute']);
45
+ $pollq_expiry_second = intval($_POST['pollq_expiry_second']);
46
+ $pollq_expiry = gmmktime($pollq_expiry_hour, $pollq_expiry_minute, $pollq_expiry_second, $pollq_expiry_month, $pollq_expiry_day, $pollq_expiry_year);
47
+ if ($pollq_expiry <= current_time('timestamp')) {
48
+ $pollq_active = 0;
49
+ }
50
+ }
51
+ // Mutilple Poll
52
+ $pollq_multiple_yes = intval($_POST['pollq_multiple_yes']);
53
+ $pollq_multiple = 0;
54
+ if ($pollq_multiple_yes == 1) {
55
+ $pollq_multiple = intval($_POST['pollq_multiple']);
56
+ } else {
57
+ $pollq_multiple = 0;
58
+ }
59
+ // Insert Poll
60
+ $add_poll_question = $wpdb->insert(
61
+ $wpdb->pollsq,
62
+ array(
63
+ 'pollq_question' => $pollq_question,
64
+ 'pollq_timestamp' => $pollq_timestamp,
65
+ 'pollq_totalvotes' => 0,
66
+ 'pollq_active' => $pollq_active,
67
+ 'pollq_expiry' => $pollq_expiry,
68
+ 'pollq_multiple' => $pollq_multiple,
69
+ 'pollq_totalvoters' => 0
70
+ ),
71
+ array(
72
+ '%s',
73
+ '%s',
74
+ '%d',
75
+ '%d',
76
+ '%s',
77
+ '%d',
78
+ '%d'
79
+ )
80
+ );
81
+ if ( ! $add_poll_question ) {
82
+ $text .= '<p style="color: red;">' . sprintf(__('Error In Adding Poll \'%s\'.', 'wp-polls'), $pollq_question) . '</p>';
83
+ }
84
+ // Add Poll Answers
85
+ $polla_answers = $_POST['polla_answers'];
86
+ $polla_qid = intval( $wpdb->insert_id );
87
+ foreach ($polla_answers as $polla_answer) {
88
+ $polla_answer = wp_kses_post( trim( $polla_answer ) );
89
+ if( ! empty( $polla_answer ) ) {
90
+ $add_poll_answers = $wpdb->insert(
91
+ $wpdb->pollsa,
92
+ array(
93
+ 'polla_qid' => $polla_qid,
94
+ 'polla_answers' => $polla_answer,
95
+ 'polla_votes' => 0
96
+ ),
97
+ array(
98
+ '%d',
99
+ '%s',
100
+ '%d'
101
+ )
102
+ );
103
+ if ( ! $add_poll_answers ) {
104
+ $text .= '<p style="color: red;">' . sprintf(__('Error In Adding Poll\'s Answer \'%s\'.', 'wp-polls'), $polla_answer) . '</p>';
105
+ }
106
+ } else {
107
+ $text .= '<p style="color: red;">' . __( 'Poll\'s Answer is empty.', 'wp-polls' ) . '</p>';
108
+ }
109
+ }
110
+ // Update Lastest Poll ID To Poll Options
111
+ $latest_pollid = polls_latest_id();
112
+ $update_latestpoll = update_option('poll_latestpoll', $latest_pollid);
113
+ // If poll starts in the future use the correct poll ID
114
+ $latest_pollid = ( $latest_pollid < $polla_qid ) ? $polla_qid : $latest_pollid;
115
+ if ( empty( $text ) ) {
116
+ $text = '<p style="color: green;">' . sprintf( __( 'Poll \'%s\' (ID: %s) added successfully. Embed this poll with the shortcode: %s or go back to <a href="%s">Manage Polls</a>', 'wp-polls' ), $pollq_question, $latest_pollid, '<input type="text" value=\'[poll id="' . $latest_pollid . '"]\' readonly="readonly" size="10" />', $base_page ) . '</p>';
117
+ } else {
118
+ if( $add_poll_question ) {
119
+ $text .= '<p style="color: green;">' . sprintf( __( 'Poll \'%s\' (ID: %s) (Shortcode: %s) added successfully, but there are some errors with the Poll\'s Answers. Embed this poll with the shortcode: %s or go back to <a href="%s">Manage Polls</a>', 'wp-polls' ), $pollq_question, $latest_pollid, '<input type="text" value=\'[poll id="' . $latest_pollid . '"]\' readonly="readonly" size="10" />' ) .'</p>';
120
+ }
121
+ }
122
+ do_action( 'wp_polls_add_poll', $latest_pollid );
123
+ cron_polls_place();
124
+ } else {
125
+ $text .= '<p style="color: red;">' . __( 'Poll Question is empty.', 'wp-polls' ) . '</p>';
126
+ }
127
+ break;
128
+ }
129
  }
130
 
131
  ### Add Poll Form
136
  <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
137
  <?php wp_nonce_field('wp-polls_add-poll'); ?>
138
  <div class="wrap">
139
+ <h2><?php _e('Add Poll', 'wp-polls'); ?></h2>
140
+ <!-- Poll Question -->
141
+ <h3><?php _e('Poll Question', 'wp-polls'); ?></h3>
142
+ <table class="form-table">
143
+ <tr>
144
+ <th width="20%" scope="row" valign="top"><?php _e('Question', 'wp-polls') ?></th>
145
+ <td width="80%"><input type="text" size="70" name="pollq_question" value="" /></td>
146
+ </tr>
147
+ </table>
148
+ <!-- Poll Answers -->
149
+ <h3><?php _e('Poll Answers', 'wp-polls'); ?></h3>
150
+ <table class="form-table">
151
+ <tfoot>
152
+ <tr>
153
+ <td width="20%">&nbsp;</td>
154
+ <td width="80%"><input type="button" value="<?php _e('Add Answer', 'wp-polls') ?>" onclick="add_poll_answer_add();" class="button" /></td>
155
+ </tr>
156
+ </tfoot>
157
+ <tbody id="poll_answers">
158
+ <?php
159
+ for($i = 1; $i <= $poll_noquestion; $i++) {
160
+ echo "<tr id=\"poll-answer-$i\">\n";
161
+ echo "<th width=\"20%\" scope=\"row\" valign=\"top\">".sprintf(__('Answer %s', 'wp-polls'), number_format_i18n($i))."</th>\n";
162
+ echo "<td width=\"80%\"><input type=\"text\" size=\"50\" maxlength=\"200\" name=\"polla_answers[]\" />&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\"".__('Remove', 'wp-polls')."\" onclick=\"remove_poll_answer_add(".$i.");\" class=\"button\" /></td>\n";
163
+ echo "</tr>\n";
164
+ $count++;
165
+ }
166
+ ?>
167
+ </tbody>
168
+ </table>
169
+ <!-- Poll Multiple Answers -->
170
+ <h3><?php _e('Poll Multiple Answers', 'wp-polls') ?></h3>
171
+ <table class="form-table">
172
+ <tr>
173
+ <th width="40%" scope="row" valign="top"><?php _e('Allows Users To Select More Than One Answer?', 'wp-polls'); ?></th>
174
+ <td width="60%">
175
+ <select name="pollq_multiple_yes" id="pollq_multiple_yes" size="1" onchange="check_pollq_multiple();">
176
+ <option value="0"><?php _e('No', 'wp-polls'); ?></option>
177
+ <option value="1"><?php _e('Yes', 'wp-polls'); ?></option>
178
+ </select>
179
+ </td>
180
+ </tr>
181
+ <tr>
182
+ <th width="40%" scope="row" valign="top"><?php _e('Maximum Number Of Selected Answers Allowed?', 'wp-polls') ?></th>
183
+ <td width="60%">
184
+ <select name="pollq_multiple" id="pollq_multiple" size="1" disabled="disabled">
185
+ <?php
186
+ for($i = 1; $i <= $poll_noquestion; $i++) {
187
+ echo "<option value=\"$i\">".number_format_i18n($i)."</option>\n";
188
+ }
189
+ ?>
190
+ </select>
191
+ </td>
192
+ </tr>
193
+ </table>
194
+ <!-- Poll Start/End Date -->
195
+ <h3><?php _e('Poll Start/End Date', 'wp-polls'); ?></h3>
196
+ <table class="form-table">
197
+ <tr>
198
+ <th width="20%" scope="row" valign="top"><?php _e('Start Date/Time', 'wp-polls') ?></th>
199
+ <td width="80%"><?php poll_timestamp(current_time('timestamp')); ?></td>
200
+ </tr>
201
+ <tr>
202
+ <th width="20%" scope="row" valign="top"><?php _e('End Date/Time', 'wp-polls') ?></th>
203
+ <td width="80%"><input type="checkbox" name="pollq_expiry_no" id="pollq_expiry_no" value="1" checked="checked" onclick="check_pollexpiry();" />&nbsp;&nbsp;<label for="pollq_expiry_no"><?php _e('Do NOT Expire This Poll', 'wp-polls'); ?></label><?php poll_timestamp(current_time('timestamp'), 'pollq_expiry', 'none'); ?></td>
204
+ </tr>
205
+ </table>
206
+ <p style="text-align: center;"><input type="submit" name="do" value="<?php _e('Add Poll', 'wp-polls'); ?>" class="button-primary" />&nbsp;&nbsp;<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-polls'); ?>" class="button" onclick="javascript:history.go(-1)" /></p>
207
  </div>
208
+ </form>
polls-logs.php CHANGED
@@ -1,42 +1,25 @@
1
  <?php
2
- /*
3
- +----------------------------------------------------------------+
4
- | |
5
- | WordPress Plugin: WP-Polls |
6
- | Copyright (c) 2012 Lester "GaMerZ" Chan |
7
- | |
8
- | File Written By: |
9
- | - Lester "GaMerZ" Chan |
10
- | - http://lesterchan.net |
11
- | |
12
- | File Information: |
13
- | - Polls Logs |
14
- | - wp-content/plugins/wp-polls/polls-logs.php |
15
- | |
16
- +----------------------------------------------------------------+
17
- */
18
-
19
-
20
  ### Check Whether User Can Manage Polls
21
- if(!current_user_can('manage_polls')) {
22
- die('Access Denied');
23
  }
24
 
25
 
26
  ### Variables
27
  $max_records = 2000;
28
  $pollip_answers = array();
29
- $poll_question_data = $wpdb->get_row("SELECT pollq_multiple, pollq_question, pollq_totalvoters FROM $wpdb->pollsq WHERE pollq_id = $poll_id");
30
  $poll_question = wp_kses_post( stripslashes( $poll_question_data->pollq_question ) );
31
- $poll_totalvoters = intval($poll_question_data->pollq_totalvoters);
32
- $poll_multiple = intval($poll_question_data->pollq_multiple);
33
- $poll_registered = $wpdb->get_var("SELECT COUNT(pollip_userid) FROM $wpdb->pollsip WHERE pollip_qid = $poll_id AND pollip_userid > 0");
34
- $poll_comments = $wpdb->get_var("SELECT COUNT(pollip_user) FROM $wpdb->pollsip WHERE pollip_qid = $poll_id AND pollip_user != '".__('Guest', 'wp-polls')."' AND pollip_userid = 0");
35
- $poll_guest = $wpdb->get_var("SELECT COUNT(pollip_user) FROM $wpdb->pollsip WHERE pollip_qid = $poll_id AND pollip_user = '".__('Guest', 'wp-polls')."'");
36
- $poll_totalrecorded = ($poll_registered+$poll_comments+$poll_guest);
37
- $poll_answers_data = $wpdb->get_results("SELECT polla_aid, polla_answers FROM $wpdb->pollsa WHERE polla_qid = $poll_id ORDER BY ".get_option('poll_ans_sortby').' '.get_option('poll_ans_sortorder'));
38
- $poll_voters = $wpdb->get_col("SELECT DISTINCT pollip_user FROM $wpdb->pollsip WHERE pollip_qid = $poll_id AND pollip_user != '".__('Guest', 'wp-polls')."' ORDER BY pollip_user ASC");
39
- $poll_logs_count = $wpdb->get_var("SELECT COUNT(pollip_id) FROM $wpdb->pollsip WHERE pollip_qid = $poll_id");
 
40
 
41
  $exclude_registered = 0;
42
  $exclude_comment = 0;
@@ -44,349 +27,349 @@ $exclude_guest = 0;
44
 
45
  ### Process Filters
46
  if(!empty($_POST['do'])) {
47
- check_admin_referer('wp-polls_logs');
48
- $registered_sql = '';
49
- $comment_sql = '';
50
- $guest_sql = '';
51
- $users_voted_for_sql = '';
52
- $what_user_voted_sql = '';
53
- $num_choices_sql = '';
54
- $num_choices_sign_sql = '';
55
- $order_by = '';
56
- switch(intval($_POST['filter'])) {
57
- case 1:
58
- $users_voted_for = intval($_POST['users_voted_for']);
59
- $exclude_registered = isset($_POST['exclude_registered']) && intval($_POST['exclude_registered']) == 1;
60
- $exclude_comment = isset($_POST['exclude_comment']) && intval($_POST['exclude_comment']) == 1;
61
- $exclude_guest = isset($_POST['exclude_guest']) && intval($_POST['exclude_guest']) == 1;
62
- $users_voted_for_sql = "AND pollip_aid = $users_voted_for";
63
- if($exclude_registered) {
64
- $registered_sql = 'AND pollip_userid = 0';
65
- }
66
- if($exclude_comment) {
67
- if(!$exclude_registered) {
68
- $comment_sql = 'AND pollip_userid > 0';
69
- } else {
70
- $comment_sql = 'AND pollip_user = \''.__('Guest', 'wp-polls').'\'';
71
- }
72
- }
73
- if($exclude_guest) {
74
- $guest_sql = 'AND pollip_user != \''.__('Guest', 'wp-polls').'\'';
75
- }
76
- $order_by = 'pollip_timestamp DESC';
77
- break;
78
- case 2:
79
- $exclude_registered_2 = intval($_POST['exclude_registered_2']);
80
- $exclude_comment_2 = intval($_POST['exclude_comment_2']);
81
- $num_choices = intval($_POST['num_choices']);
82
- $num_choices_sign = addslashes($_POST['num_choices_sign']);
83
- switch($num_choices_sign) {
84
- case 'more':
85
- $num_choices_sign_sql = '>';
86
- break;
87
- case 'more_exactly':
88
- $num_choices_sign_sql = '>=';
89
- break;
90
- case 'exactly':
91
- $num_choices_sign_sql = '=';
92
- break;
93
- case 'less_exactly':
94
- $num_choices_sign_sql = '<=';
95
- break;
96
- case 'less':
97
- $num_choices_sign_sql = '<';
98
- break;
99
- }
100
- if($exclude_registered_2) {
101
- $registered_sql = 'AND pollip_userid = 0';
102
- }
103
- if($exclude_comment_2) {
104
- if(!$exclude_registered_2) {
105
- $comment_sql = 'AND pollip_userid > 0';
106
- } else {
107
- $comment_sql = 'AND pollip_user = \''.__('Guest', 'wp-polls').'\'';
108
- }
109
- }
110
- $guest_sql = 'AND pollip_user != \''.__('Guest', 'wp-polls').'\'';
111
- $num_choices_query = $wpdb->get_col("SELECT pollip_user, COUNT(pollip_ip) AS num_choices FROM $wpdb->pollsip WHERE pollip_qid = $poll_id GROUP BY pollip_ip, pollip_user HAVING num_choices $num_choices_sign_sql $num_choices");
112
- $num_choices_sql = 'AND pollip_user IN (\''.implode('\',\'',$num_choices_query).'\')';
113
- $order_by = 'pollip_user, pollip_ip';
114
- break;
115
- case 3;
116
- $what_user_voted = addslashes($_POST['what_user_voted']);
117
- $what_user_voted_sql = "AND pollip_user = '$what_user_voted'";
118
- $order_by = 'pollip_user, pollip_ip';
119
- break;
120
- }
121
- $poll_ips = $wpdb->get_results("SELECT $wpdb->pollsip.* FROM $wpdb->pollsip WHERE pollip_qid = $poll_id $users_voted_for_sql $registered_sql $comment_sql $guest_sql $what_user_voted_sql $num_choices_sql ORDER BY $order_by");
122
  } else {
123
- $poll_ips = $wpdb->get_results("SELECT pollip_aid, pollip_ip, pollip_host, pollip_timestamp, pollip_user FROM $wpdb->pollsip WHERE pollip_qid = $poll_id ORDER BY pollip_aid ASC, pollip_user ASC LIMIT $max_records");
124
  }
125
  ?>
126
  <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade">'.stripslashes($text).'</div>'; } else { echo '<div id="message" class="updated" style="display: none;"></div>'; } ?>
127
  <div class="wrap">
128
- <h2><?php _e('Poll\'s Logs', 'wp-polls'); ?></h2>
129
- <h3><?php echo $poll_question; ?></h3>
130
- <p>
131
- <?php printf(_n('There are a total of <strong>%s</strong> recorded vote for this poll.', 'There are a total of <strong>%s</strong> recorded votes for this poll.', $poll_totalrecorded, 'wp-polls'), number_format_i18n($poll_totalrecorded)); ?><br />
132
- <?php printf(_n('<strong>&raquo;</strong> <strong>%s</strong> vote is cast by registered users', '<strong>&raquo;</strong> <strong>%s</strong> votes are cast by registered users', $poll_registered, 'wp-polls'), number_format_i18n($poll_registered)); ?><br />
133
- <?php printf(_n('<strong>&raquo;</strong> <strong>%s</strong> vote is cast by comment authors', '<strong>&raquo;</strong> <strong>%s</strong> votes are cast by comment authors', $poll_comments, 'wp-polls'), number_format_i18n($poll_comments)); ?><br />
134
- <?php printf(_n('<strong>&raquo;</strong> <strong>%s</strong> vote is cast by guests', '<strong>&raquo;</strong> <strong>%s</strong> votes are cast by guests', $poll_guest, 'wp-polls'), number_format_i18n($poll_guest)); ?>
135
- </p>
136
  </div>
137
  <?php if($poll_totalrecorded > 0 && apply_filters( 'poll_log_show_log_filter', true )) { ?>
138
  <div class="wrap">
139
- <h3><?php _e('Filter Poll\'s Logs', 'wp-polls') ?></h3>
140
- <table width="100%" border="0" cellspacing="0" cellpadding="0">
141
- <tr>
142
- <td width="50%">
143
- <form method="post" action="<?php echo admin_url('admin.php?page='.$base_name.'&amp;mode=logs&amp;id='.$poll_id); ?>">
144
- <?php wp_nonce_field('wp-polls_logs'); ?>
145
- <p style="display: none;"><input type="hidden" name="filter" value="1" /></p>
146
- <table class="form-table">
147
- <tr>
148
- <th scope="row" valign="top"><?php _e('Display All Users That Voted For', 'wp-polls'); ?></th>
149
- <td>
150
- <select name="users_voted_for" size="1">
151
- <?php
152
- if($poll_answers_data) {
153
- foreach($poll_answers_data as $data) {
154
- $polla_id = intval($data->polla_aid);
155
- $polla_answers = stripslashes( strip_tags( esc_attr( $data->polla_answers ) ) );
156
- if($polla_id == $users_voted_for) {
157
- echo '<option value="'.$polla_id .'" selected="selected">'.$polla_answers.'</option>';
158
- } else {
159
- echo '<option value="'.$polla_id .'">'.$polla_answers.'</option>';
160
- }
161
- $pollip_answers[$polla_id] = $polla_answers;
162
- }
163
- }
164
- ?>
165
- </select>
166
- </td>
167
- </tr>
168
- <tr>
169
- <th scope="row" valign="top"><?php _e('Voters To EXCLUDE', 'wp-polls'); ?></th>
170
- <td>
171
- <input type="checkbox" id="exclude_registered_1" name="exclude_registered" value="1" <?php checked('1', $exclude_registered); ?> />&nbsp;<label for="exclude_registered_1"><?php _e('Registered Users', 'wp-polls'); ?></label><br />
172
- <input type="checkbox" id="exclude_comment_1" name="exclude_comment" value="1" <?php checked('1', $exclude_comment); ?> />&nbsp;<label for="exclude_comment_1"><?php _e('Comment Authors', 'wp-polls'); ?></label><br />
173
- <input type="checkbox" id="exclude_guest_1" name="exclude_guest" value="1" <?php checked('1', $exclude_guest); ?> />&nbsp;<label for="exclude_guest_1"><?php _e('Guests', 'wp-polls'); ?></label>
174
- </td>
175
- </tr>
176
- <tr>
177
- <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Filter', 'wp-polls'); ?>" class="button" /></td>
178
- </tr>
179
- </table>
180
- </form>
181
- </td>
182
- <td width="50%">
183
- <?php if($poll_multiple > 0) { ?>
184
- <form method="post" action="<?php echo admin_url('admin.php?page='.$base_name.'&amp;mode=logs&amp;id='.$poll_id); ?>">
185
- <?php wp_nonce_field('wp-polls_logs'); ?>
186
- <p style="display: none;"><input type="hidden" name="filter" value="2" /></p>
187
- <table class="form-table">
188
- <tr>
189
- <th scope="row" valign="top"><?php _e('Display Users That Voted For', 'wp-polls'); ?></th>
190
- <td>
191
- <select name="num_choices_sign" size="1">
192
- <option value="more" <?php selected('more', $num_choices_sign); ?>><?php _e('More Than', 'wp-polls'); ?></option>
193
- <option value="more_exactly" <?php selected('more_exactly', $num_choices_sign); ?>><?php _e('More Than Or Exactly', 'wp-polls'); ?></option>
194
- <option value="exactly" <?php selected('exactly', $num_choices_sign); ?>><?php _e('Exactly', 'wp-polls'); ?></option>
195
- <option value="less_exactly" <?php selected('less_exactly', $num_choices_sign); ?>><?php _e('Less Than Or Exactly', 'wp-polls'); ?></option>
196
- <option value="less" <?php selected('less', $num_choices_sign); ?>><?php _e('Less Than', 'wp-polls'); ?></option>
197
- </select>
198
- &nbsp;&nbsp;
199
- <select name="num_choices" size="1">
200
- <?php
201
- for($i = 1; $i <= $poll_multiple; $i++) {
202
- if($i == 1) {
203
- echo '<option value="1">'.__('1 Answer', 'wp-polls').'</option>';
204
- } else {
205
- if($i == $num_choices) {
206
- echo '<option value="'.$i.'" selected="selected">'.sprintf(_n('%s Answer', '%s Answers', $i, 'wp-polls'), number_format_i18n($i)).'</option>';
207
- } else {
208
- echo '<option value="'.$i.'">'.sprintf(_n('%s Answer', '%s Answers', $i, 'wp-polls'), number_format_i18n($i)).'</option>';
209
- }
210
- }
211
- }
212
- ?>
213
- </select>
214
- </td>
215
- </tr>
216
- <tr>
217
- <th scope="row" valign="top"><?php _e('Voters To EXCLUDE', 'wp-polls'); ?></th>
218
- <td>
219
- <input type="checkbox" id="exclude_registered_2" name="exclude_registered_2" value="1" <?php checked('1', $exclude_registered_2); ?> />&nbsp;<label for="exclude_registered_2"><?php _e('Registered Users', 'wp-polls'); ?></label><br />
220
- <input type="checkbox" id="exclude_comment_2" name="exclude_comment_2" value="1" <?php checked('1', $exclude_comment_2); ?> />&nbsp;<label for="exclude_comment_2"><?php _e('Comment Authors', 'wp-polls'); ?></label><br />
221
- <?php _e('Guests will automatically be excluded', 'wp-polls'); ?>
222
- </td>
223
- </tr>
224
- <tr>
225
- <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Filter', 'wp-polls'); ?>" class="button" /></td>
226
- </tr>
227
- </table>
228
- </form>
229
- <?php } else { ?>
230
- &nbsp;
231
- <?php } // End if($poll_multiple > -1) ?>
232
- </td>
233
- </tr>
234
- <tr>
235
- <td>
236
- <?php if($poll_voters) { ?>
237
- <form method="post" action="<?php echo admin_url('admin.php?page='.$base_name.'&amp;mode=logs&amp;id='.$poll_id); ?>">
238
- <?php wp_nonce_field('wp-polls_logs'); ?>
239
- <p style="display: none;"><input type="hidden" name="filter" value="3" /></p>
240
- <table class="form-table">
241
- <tr>
242
- <th scope="row" valign="top"><?php _e('Display What This User Has Voted', 'wp-polls'); ?></th>
243
- <td>
244
- <select name="what_user_voted" size="1">
245
- <?php
246
- if($poll_voters) {
247
- foreach($poll_voters as $pollip_user) {
248
- if($pollip_user == $what_user_voted) {
249
- echo '<option value="' . stripslashes( esc_attr( $pollip_user ) ) . '" selected="selected">' . stripslashes( esc_attr( $pollip_user ) ) . '</option>';
250
- } else {
251
- echo '<option value="' . stripslashes( esc_attr( $pollip_user ) ) . '">' . stripslashes( esc_attr( $pollip_user ) ) . '</option>';
252
- }
253
- }
254
- }
255
- ?>
256
- </select>
257
- </td>
258
- </tr>
259
- <tr>
260
- <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Filter', 'wp-polls'); ?>" class="button" /></td>
261
- </tr>
262
- </table>
263
- </form>
264
- <?php } else { ?>
265
- &nbsp;
266
- <?php } // End if($poll_multiple > -1) ?>
267
- </td>
268
- <td align="center"><input type="button" value="<?php _e('Clear Filter', 'wp-polls'); ?>" onclick="self.location.href = '<?php echo esc_attr( $base_page ); ?>&amp;mode=logs&amp;id=<?php echo $poll_id; ?>';" class="button" /></td>
269
- </tr>
270
- </table>
271
  </div>
272
  <p>&nbsp;</p>
273
  <?php } // End if($poll_totalrecorded > 0) ?>
274
  <div class="wrap">
275
- <h3><?php _e('Poll Logs', 'wp-polls'); ?></h3>
276
- <div id="poll_logs_display">
277
- <?php
278
- if($poll_ips) {
279
- if(empty($_POST['do'])) {
280
- echo '<p>'.sprintf(__('This default filter is limited to display only <strong>%s</strong> records.', 'wp-polls'), number_format_i18n($max_records)).'</p>';
281
- }
282
- echo '<table class="widefat">'."\n";
283
- $k = 1;
284
- $j = 0;
285
- $poll_last_aid = -1;
286
  $temp_pollip_user = null;
287
- if(isset($_POST['filter']) && intval($_POST['filter']) > 1) {
288
- echo "<tr class=\"thead\">\n";
289
- echo "<th>".__('Answer', 'wp-polls')."</th>\n";
290
- echo "<th>".__('IP', 'wp-polls')."</th>\n";
291
- echo "<th>".__('Host', 'wp-polls')."</th>\n";
292
- echo "<th>".__('Date', 'wp-polls')."</th>\n";
293
- echo "</tr>\n";
294
- foreach($poll_ips as $poll_ip) {
295
- $pollip_aid = intval($poll_ip->pollip_aid);
296
- $pollip_user = stripslashes($poll_ip->pollip_user);
297
- $pollip_ip = $poll_ip->pollip_ip;
298
- $pollip_host = $poll_ip->pollip_host;
299
- $pollip_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_ip->pollip_timestamp));
300
 
301
  $i = 0;
302
  if($i % 2 == 0) {
303
- $style = '';
304
- } else {
305
- $style = 'class="alternate"';
306
- }
307
- if($pollip_user != $temp_pollip_user) {
308
- echo '<tr class="highlight">'."\n";
309
- echo "<td colspan=\"4\"><strong>".__('User', 'wp-polls')." ".number_format_i18n($k).": $pollip_user</strong></td>\n";
310
- echo '</tr>';
311
- $k++;
312
- }
313
- echo "<tr $style>\n";
314
- echo "<td>{$pollip_answers[$pollip_aid]}</td>\n";
315
- echo "<td><a href=\"http://ipinfo.io/$pollip_ip\" title=\"$pollip_ip\">$pollip_ip</a></td>\n";
316
- echo "<td>$pollip_host</td>\n";
317
- echo "<td>$pollip_date</td>\n";
318
- echo "</tr>\n";
319
- $temp_pollip_user = $pollip_user;
320
- $i++;
321
- $j++;
322
- }
323
- } else {
324
- foreach($poll_ips as $poll_ip) {
325
- $pollip_aid = intval($poll_ip->pollip_aid);
326
- $pollip_user = apply_filters( 'poll_log_secret_ballot', stripslashes($poll_ip->pollip_user) );
327
- $pollip_ip = $poll_ip->pollip_ip;
328
- $pollip_host = $poll_ip->pollip_host;
329
- $pollip_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_ip->pollip_timestamp));
330
- if($pollip_aid != $poll_last_aid) {
331
- if($pollip_aid == 0) {
332
- echo "<tr class=\"highlight\">\n<td colspan=\"4\"><strong>$pollip_answers[$pollip_aid]</strong></td>\n</tr>\n";
333
- } else {
334
- echo "<tr class=\"highlight\">\n<td colspan=\"4\"><strong>".__('Answer', 'wp-polls')." ".number_format_i18n($k).": $pollip_answers[$pollip_aid]</strong></td>\n</tr>\n";
335
- $k++;
336
- }
337
- echo "<tr class=\"thead\">\n";
338
- echo "<th>".__('No.', 'wp-polls')."</th>\n";
339
- echo "<th>".__('User', 'wp-polls')."</th>\n";
340
- echo "<th>".__('IP/Host', 'wp-polls')."</th>\n";
341
- echo "<th>".__('Date', 'wp-polls')."</th>\n";
342
- echo "</tr>\n";
343
- $i = 1;
344
- }
345
- if($i%2 == 0) {
346
- $style = '';
347
- } else {
348
- $style = 'class="alternate"';
349
- }
350
- echo "<tr $style>\n";
351
- echo "<td>".number_format_i18n($i)."</td>\n";
352
- echo "<td>$pollip_user</td>\n";
353
- echo "<td><a href=\"http://ipinfo.io/$pollip_ip\" title=\"$pollip_ip\">$pollip_ip</a> / $pollip_host</td>\n";
354
- echo "<td>$pollip_date</td>\n";
355
- echo "</tr>\n";
356
- $poll_last_aid = $pollip_aid;
357
- $i++;
358
- $j++;
359
- }
360
- }
361
- echo "<tr class=\"highlight\">\n";
362
- echo "<td colspan=\"4\">".sprintf(__('Total number of records that matches this filter: <strong>%s</strong>', 'wp-polls'), number_format_i18n($j))."</td>";
363
- echo "</tr>\n";
364
- echo '</table>'."\n";
365
- }
366
- ?>
367
- </div>
368
- <?php if(!empty($_POST['do'])) { ?>
369
- <br class="clear" /><div id="poll_logs_display_none" style="text-align: center; display: <?php if(!$poll_ips) { echo 'block'; } else { echo 'none'; } ?>;" ><?php _e('No poll logs matches the filter.', 'wp-polls'); ?></div>
370
- <?php } else { ?>
371
- <br class="clear" /><div id="poll_logs_display_none" style="text-align: center; display: <?php if(!$poll_logs_count) { echo 'block'; } else { echo 'none'; } ?>;" ><?php _e('No poll logs available for this poll.', 'wp-polls'); ?></div>
372
- <?php } ?>
373
  </div>
374
  <p>&nbsp;</p>
375
 
376
  <!-- Delete Poll Logs -->
377
  <div class="wrap">
378
- <h3><?php _e('Delete Poll Logs', 'wp-polls'); ?></h3>
379
- <br class="clear" />
380
- <div align="center" id="poll_logs">
381
- <?php if($poll_logs_count) { ?>
382
- <strong><?php _e('Are You Sure You Want To Delete Logs For This Poll Only?', 'wp-polls'); ?></strong><br /><br />
383
- <input type="checkbox" id="delete_logs_yes" name="delete_logs_yes" value="yes" />&nbsp;<label for="delete_logs_yes"><?php _e('Yes', 'wp-polls'); ?></label><br /><br />
384
- <input type="button" name="do" value="<?php _e('Delete Logs For This Poll Only', 'wp-polls'); ?>" class="button" onclick="delete_this_poll_logs(<?php echo $poll_id; ?>, '<?php printf(esc_js(__('You are about to delete poll logs for this poll \'%s\' ONLY. This action is not reversible.', 'wp-polls')), htmlspecialchars( $poll_question ) ); ?>', '<?php echo wp_create_nonce('wp-polls_delete-poll-logs'); ?>');" />
385
- <?php
386
- } else {
387
- _e('No poll logs available for this poll.', 'wp-polls');
388
- }
389
- ?>
390
- </div>
391
- <p><?php _e('Note: If your logging method is by IP and Cookie or by Cookie, users may still be unable to vote if they have voted before as the cookie is still stored in their computer.', 'wp-polls'); ?></p>
392
  </div>
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  ### Check Whether User Can Manage Polls
3
+ if( ! current_user_can( 'manage_polls' ) ) {
4
+ die( 'Access Denied' );
5
  }
6
 
7
 
8
  ### Variables
9
  $max_records = 2000;
10
  $pollip_answers = array();
11
+ $poll_question_data = $wpdb->get_row( $wpdb->prepare( "SELECT pollq_multiple, pollq_question, pollq_totalvoters FROM $wpdb->pollsq WHERE pollq_id = %d", $poll_id ) );
12
  $poll_question = wp_kses_post( stripslashes( $poll_question_data->pollq_question ) );
13
+ $poll_totalvoters = intval( $poll_question_data->pollq_totalvoters );
14
+ $poll_multiple = intval( $poll_question_data->pollq_multiple );
15
+ $poll_registered = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(pollip_userid) FROM $wpdb->pollsip WHERE pollip_qid = %d AND pollip_userid > 0", $poll_id ) );
16
+ $poll_comments = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(pollip_user) FROM $wpdb->pollsip WHERE pollip_qid = %d AND pollip_user != %s AND pollip_userid = 0", $poll_id, __( 'Guest', 'wp-polls' ) ) );
17
+ $poll_guest = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(pollip_user) FROM $wpdb->pollsip WHERE pollip_qid = %d AND pollip_user = %s", $poll_id, __( 'Guest', 'wp-polls' ) ) );
18
+ $poll_totalrecorded = ( $poll_registered + $poll_comments + $poll_guest );
19
+ list( $order_by, $sort_order ) = _polls_get_ans_sort();
20
+ $poll_answers_data = $wpdb->get_results( $wpdb->prepare( "SELECT polla_aid, polla_answers FROM $wpdb->pollsa WHERE polla_qid = %d ORDER BY $order_by $sort_order", $poll_id ) );
21
+ $poll_voters = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT pollip_user FROM $wpdb->pollsip WHERE pollip_qid = %d AND pollip_user != %s ORDER BY pollip_user ASC", $poll_id, __( 'Guest', 'wp-polls' ) ) );
22
+ $poll_logs_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(pollip_id) FROM $wpdb->pollsip WHERE pollip_qid = %d", $poll_id ) );
23
 
24
  $exclude_registered = 0;
25
  $exclude_comment = 0;
27
 
28
  ### Process Filters
29
  if(!empty($_POST['do'])) {
30
+ check_admin_referer('wp-polls_logs');
31
+ $registered_sql = '';
32
+ $comment_sql = '';
33
+ $guest_sql = '';
34
+ $users_voted_for_sql = '';
35
+ $what_user_voted_sql = '';
36
+ $num_choices_sql = '';
37
+ $num_choices_sign_sql = '';
38
+ $order_by = '';
39
+ switch(intval($_POST['filter'])) {
40
+ case 1:
41
+ $users_voted_for = intval( $_POST['users_voted_for'] );
42
+ $exclude_registered = isset( $_POST['exclude_registered'] ) && intval( $_POST['exclude_registered'] ) === 1;
43
+ $exclude_comment = isset( $_POST['exclude_comment'] ) && intval( $_POST['exclude_comment'] ) === 1;
44
+ $exclude_guest = isset( $_POST['exclude_guest'] ) && intval( $_POST['exclude_guest'] ) === 1;
45
+ $users_voted_for_sql = "AND pollip_aid = $users_voted_for";
46
+ if($exclude_registered) {
47
+ $registered_sql = 'AND pollip_userid = 0';
48
+ }
49
+ if($exclude_comment) {
50
+ if(!$exclude_registered) {
51
+ $comment_sql = 'AND pollip_userid > 0';
52
+ } else {
53
+ $comment_sql = 'AND pollip_user = \''.__('Guest', 'wp-polls').'\'';
54
+ }
55
+ }
56
+ if($exclude_guest) {
57
+ $guest_sql = 'AND pollip_user != \''.__('Guest', 'wp-polls').'\'';
58
+ }
59
+ $order_by = 'pollip_timestamp DESC';
60
+ break;
61
+ case 2:
62
+ $exclude_registered_2 = intval( $_POST['exclude_registered_2'] );
63
+ $exclude_comment_2 = intval( $_POST['exclude_comment_2'] );
64
+ $num_choices = intval( $_POST['num_choices']);
65
+ $num_choices_sign = esc_sql( $_POST['num_choices_sign'] );
66
+ switch($num_choices_sign) {
67
+ case 'more':
68
+ $num_choices_sign_sql = '>';
69
+ break;
70
+ case 'more_exactly':
71
+ $num_choices_sign_sql = '>=';
72
+ break;
73
+ case 'exactly':
74
+ $num_choices_sign_sql = '=';
75
+ break;
76
+ case 'less_exactly':
77
+ $num_choices_sign_sql = '<=';
78
+ break;
79
+ case 'less':
80
+ $num_choices_sign_sql = '<';
81
+ break;
82
+ }
83
+ if($exclude_registered_2) {
84
+ $registered_sql = 'AND pollip_userid = 0';
85
+ }
86
+ if($exclude_comment_2) {
87
+ if(!$exclude_registered_2) {
88
+ $comment_sql = 'AND pollip_userid > 0';
89
+ } else {
90
+ $comment_sql = 'AND pollip_user = \''.__('Guest', 'wp-polls').'\'';
91
+ }
92
+ }
93
+ $guest_sql = 'AND pollip_user != \''.__('Guest', 'wp-polls').'\'';
94
+ $num_choices_query = $wpdb->get_col("SELECT pollip_user, COUNT(pollip_ip) AS num_choices FROM $wpdb->pollsip WHERE pollip_qid = $poll_id GROUP BY pollip_ip, pollip_user HAVING num_choices $num_choices_sign_sql $num_choices");
95
+ $num_choices_sql = 'AND pollip_user IN (\''.implode('\',\'',$num_choices_query).'\')';
96
+ $order_by = 'pollip_user, pollip_ip';
97
+ break;
98
+ case 3;
99
+ $what_user_voted = esc_sql( $_POST['what_user_voted'] );
100
+ $what_user_voted_sql = "AND pollip_user = '$what_user_voted'";
101
+ $order_by = 'pollip_user, pollip_ip';
102
+ break;
103
+ }
104
+ $poll_ips = $wpdb->get_results("SELECT $wpdb->pollsip.* FROM $wpdb->pollsip WHERE pollip_qid = $poll_id $users_voted_for_sql $registered_sql $comment_sql $guest_sql $what_user_voted_sql $num_choices_sql ORDER BY $order_by");
105
  } else {
106
+ $poll_ips = $wpdb->get_results( $wpdb->prepare( "SELECT pollip_aid, pollip_ip, pollip_host, pollip_timestamp, pollip_user FROM $wpdb->pollsip WHERE pollip_qid = %d ORDER BY pollip_aid ASC, pollip_user ASC LIMIT %d", $poll_id, $max_records ) );
107
  }
108
  ?>
109
  <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade">'.stripslashes($text).'</div>'; } else { echo '<div id="message" class="updated" style="display: none;"></div>'; } ?>
110
  <div class="wrap">
111
+ <h2><?php _e('Poll\'s Logs', 'wp-polls'); ?></h2>
112
+ <h3><?php echo $poll_question; ?></h3>
113
+ <p>
114
+ <?php printf(_n('There are a total of <strong>%s</strong> recorded vote for this poll.', 'There are a total of <strong>%s</strong> recorded votes for this poll.', $poll_totalrecorded, 'wp-polls'), number_format_i18n($poll_totalrecorded)); ?><br />
115
+ <?php printf(_n('<strong>&raquo;</strong> <strong>%s</strong> vote is cast by registered users', '<strong>&raquo;</strong> <strong>%s</strong> votes are cast by registered users', $poll_registered, 'wp-polls'), number_format_i18n($poll_registered)); ?><br />
116
+ <?php printf(_n('<strong>&raquo;</strong> <strong>%s</strong> vote is cast by comment authors', '<strong>&raquo;</strong> <strong>%s</strong> votes are cast by comment authors', $poll_comments, 'wp-polls'), number_format_i18n($poll_comments)); ?><br />
117
+ <?php printf(_n('<strong>&raquo;</strong> <strong>%s</strong> vote is cast by guests', '<strong>&raquo;</strong> <strong>%s</strong> votes are cast by guests', $poll_guest, 'wp-polls'), number_format_i18n($poll_guest)); ?>
118
+ </p>
119
  </div>
120
  <?php if($poll_totalrecorded > 0 && apply_filters( 'poll_log_show_log_filter', true )) { ?>
121
  <div class="wrap">
122
+ <h3><?php _e('Filter Poll\'s Logs', 'wp-polls') ?></h3>
123
+ <table width="100%" border="0" cellspacing="0" cellpadding="0">
124
+ <tr>
125
+ <td width="50%">
126
+ <form method="post" action="<?php echo admin_url('admin.php?page='.$base_name.'&amp;mode=logs&amp;id='.$poll_id); ?>">
127
+ <?php wp_nonce_field('wp-polls_logs'); ?>
128
+ <p style="display: none;"><input type="hidden" name="filter" value="1" /></p>
129
+ <table class="form-table">
130
+ <tr>
131
+ <th scope="row" valign="top"><?php _e('Display All Users That Voted For', 'wp-polls'); ?></th>
132
+ <td>
133
+ <select name="users_voted_for" size="1">
134
+ <?php
135
+ if($poll_answers_data) {
136
+ foreach($poll_answers_data as $data) {
137
+ $polla_id = intval($data->polla_aid);
138
+ $polla_answers = stripslashes( strip_tags( esc_attr( $data->polla_answers ) ) );
139
+ if($polla_id == $users_voted_for) {
140
+ echo '<option value="'.$polla_id .'" selected="selected">'.$polla_answers.'</option>';
141
+ } else {
142
+ echo '<option value="'.$polla_id .'">'.$polla_answers.'</option>';
143
+ }
144
+ $pollip_answers[$polla_id] = $polla_answers;
145
+ }
146
+ }
147
+ ?>
148
+ </select>
149
+ </td>
150
+ </tr>
151
+ <tr>
152
+ <th scope="row" valign="top"><?php _e('Voters To EXCLUDE', 'wp-polls'); ?></th>
153
+ <td>
154
+ <input type="checkbox" id="exclude_registered_1" name="exclude_registered" value="1" <?php checked('1', $exclude_registered); ?> />&nbsp;<label for="exclude_registered_1"><?php _e('Registered Users', 'wp-polls'); ?></label><br />
155
+ <input type="checkbox" id="exclude_comment_1" name="exclude_comment" value="1" <?php checked('1', $exclude_comment); ?> />&nbsp;<label for="exclude_comment_1"><?php _e('Comment Authors', 'wp-polls'); ?></label><br />
156
+ <input type="checkbox" id="exclude_guest_1" name="exclude_guest" value="1" <?php checked('1', $exclude_guest); ?> />&nbsp;<label for="exclude_guest_1"><?php _e('Guests', 'wp-polls'); ?></label>
157
+ </td>
158
+ </tr>
159
+ <tr>
160
+ <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Filter', 'wp-polls'); ?>" class="button" /></td>
161
+ </tr>
162
+ </table>
163
+ </form>
164
+ </td>
165
+ <td width="50%">
166
+ <?php if($poll_multiple > 0) { ?>
167
+ <form method="post" action="<?php echo admin_url('admin.php?page='.$base_name.'&amp;mode=logs&amp;id='.$poll_id); ?>">
168
+ <?php wp_nonce_field('wp-polls_logs'); ?>
169
+ <p style="display: none;"><input type="hidden" name="filter" value="2" /></p>
170
+ <table class="form-table">
171
+ <tr>
172
+ <th scope="row" valign="top"><?php _e('Display Users That Voted For', 'wp-polls'); ?></th>
173
+ <td>
174
+ <select name="num_choices_sign" size="1">
175
+ <option value="more" <?php selected('more', $num_choices_sign); ?>><?php _e('More Than', 'wp-polls'); ?></option>
176
+ <option value="more_exactly" <?php selected('more_exactly', $num_choices_sign); ?>><?php _e('More Than Or Exactly', 'wp-polls'); ?></option>
177
+ <option value="exactly" <?php selected('exactly', $num_choices_sign); ?>><?php _e('Exactly', 'wp-polls'); ?></option>
178
+ <option value="less_exactly" <?php selected('less_exactly', $num_choices_sign); ?>><?php _e('Less Than Or Exactly', 'wp-polls'); ?></option>
179
+ <option value="less" <?php selected('less', $num_choices_sign); ?>><?php _e('Less Than', 'wp-polls'); ?></option>
180
+ </select>
181
+ &nbsp;&nbsp;
182
+ <select name="num_choices" size="1">
183
+ <?php
184
+ for($i = 1; $i <= $poll_multiple; $i++) {
185
+ if($i == 1) {
186
+ echo '<option value="1">'.__('1 Answer', 'wp-polls').'</option>';
187
+ } else {
188
+ if($i == $num_choices) {
189
+ echo '<option value="'.$i.'" selected="selected">'.sprintf(_n('%s Answer', '%s Answers', $i, 'wp-polls'), number_format_i18n($i)).'</option>';
190
+ } else {
191
+ echo '<option value="'.$i.'">'.sprintf(_n('%s Answer', '%s Answers', $i, 'wp-polls'), number_format_i18n($i)).'</option>';
192
+ }
193
+ }
194
+ }
195
+ ?>
196
+ </select>
197
+ </td>
198
+ </tr>
199
+ <tr>
200
+ <th scope="row" valign="top"><?php _e('Voters To EXCLUDE', 'wp-polls'); ?></th>
201
+ <td>
202
+ <input type="checkbox" id="exclude_registered_2" name="exclude_registered_2" value="1" <?php checked('1', $exclude_registered_2); ?> />&nbsp;<label for="exclude_registered_2"><?php _e('Registered Users', 'wp-polls'); ?></label><br />
203
+ <input type="checkbox" id="exclude_comment_2" name="exclude_comment_2" value="1" <?php checked('1', $exclude_comment_2); ?> />&nbsp;<label for="exclude_comment_2"><?php _e('Comment Authors', 'wp-polls'); ?></label><br />
204
+ <?php _e('Guests will automatically be excluded', 'wp-polls'); ?>
205
+ </td>
206
+ </tr>
207
+ <tr>
208
+ <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Filter', 'wp-polls'); ?>" class="button" /></td>
209
+ </tr>
210
+ </table>
211
+ </form>
212
+ <?php } else { ?>
213
+ &nbsp;
214
+ <?php } // End if($poll_multiple > -1) ?>
215
+ </td>
216
+ </tr>
217
+ <tr>
218
+ <td>
219
+ <?php if($poll_voters) { ?>
220
+ <form method="post" action="<?php echo admin_url('admin.php?page='.$base_name.'&amp;mode=logs&amp;id='.$poll_id); ?>">
221
+ <?php wp_nonce_field('wp-polls_logs'); ?>
222
+ <p style="display: none;"><input type="hidden" name="filter" value="3" /></p>
223
+ <table class="form-table">
224
+ <tr>
225
+ <th scope="row" valign="top"><?php _e('Display What This User Has Voted', 'wp-polls'); ?></th>
226
+ <td>
227
+ <select name="what_user_voted" size="1">
228
+ <?php
229
+ if($poll_voters) {
230
+ foreach($poll_voters as $pollip_user) {
231
+ if($pollip_user == $what_user_voted) {
232
+ echo '<option value="' . stripslashes( esc_attr( $pollip_user ) ) . '" selected="selected">' . stripslashes( esc_attr( $pollip_user ) ) . '</option>';
233
+ } else {
234
+ echo '<option value="' . stripslashes( esc_attr( $pollip_user ) ) . '">' . stripslashes( esc_attr( $pollip_user ) ) . '</option>';
235
+ }
236
+ }
237
+ }
238
+ ?>
239
+ </select>
240
+ </td>
241
+ </tr>
242
+ <tr>
243
+ <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Filter', 'wp-polls'); ?>" class="button" /></td>
244
+ </tr>
245
+ </table>
246
+ </form>
247
+ <?php } else { ?>
248
+ &nbsp;
249
+ <?php } // End if($poll_multiple > -1) ?>
250
+ </td>
251
+ <td align="center"><input type="button" value="<?php _e('Clear Filter', 'wp-polls'); ?>" onclick="self.location.href = '<?php echo esc_attr( $base_page ); ?>&amp;mode=logs&amp;id=<?php echo $poll_id; ?>';" class="button" /></td>
252
+ </tr>
253
+ </table>
254
  </div>
255
  <p>&nbsp;</p>
256
  <?php } // End if($poll_totalrecorded > 0) ?>
257
  <div class="wrap">
258
+ <h3><?php _e('Poll Logs', 'wp-polls'); ?></h3>
259
+ <div id="poll_logs_display">
260
+ <?php
261
+ if($poll_ips) {
262
+ if(empty($_POST['do'])) {
263
+ echo '<p>'.sprintf(__('This default filter is limited to display only <strong>%s</strong> records.', 'wp-polls'), number_format_i18n($max_records)).'</p>';
264
+ }
265
+ echo '<table class="widefat">'."\n";
266
+ $k = 1;
267
+ $j = 0;
268
+ $poll_last_aid = -1;
269
  $temp_pollip_user = null;
270
+ if(isset($_POST['filter']) && intval($_POST['filter']) > 1) {
271
+ echo "<tr class=\"thead\">\n";
272
+ echo "<th>".__('Answer', 'wp-polls')."</th>\n";
273
+ echo "<th>".__('IP', 'wp-polls')."</th>\n";
274
+ echo "<th>".__('Host', 'wp-polls')."</th>\n";
275
+ echo "<th>".__('Date', 'wp-polls')."</th>\n";
276
+ echo "</tr>\n";
277
+ foreach($poll_ips as $poll_ip) {
278
+ $pollip_aid = intval($poll_ip->pollip_aid);
279
+ $pollip_user = stripslashes($poll_ip->pollip_user);
280
+ $pollip_ip = $poll_ip->pollip_ip;
281
+ $pollip_host = $poll_ip->pollip_host;
282
+ $pollip_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_ip->pollip_timestamp));
283
 
284
  $i = 0;
285
  if($i % 2 == 0) {
286
+ $style = '';
287
+ } else {
288
+ $style = 'class="alternate"';
289
+ }
290
+ if($pollip_user != $temp_pollip_user) {
291
+ echo '<tr class="highlight">'."\n";
292
+ echo "<td colspan=\"4\"><strong>".__('User', 'wp-polls')." ".number_format_i18n($k).": $pollip_user</strong></td>\n";
293
+ echo '</tr>';
294
+ $k++;
295
+ }
296
+ echo "<tr $style>\n";
297
+ echo "<td>{$pollip_answers[$pollip_aid]}</td>\n";
298
+ echo "<td><a href=\"http://ipinfo.io/$pollip_ip\" title=\"$pollip_ip\">$pollip_ip</a></td>\n";
299
+ echo "<td>$pollip_host</td>\n";
300
+ echo "<td>$pollip_date</td>\n";
301
+ echo "</tr>\n";
302
+ $temp_pollip_user = $pollip_user;
303
+ $i++;
304
+ $j++;
305
+ }
306
+ } else {
307
+ foreach($poll_ips as $poll_ip) {
308
+ $pollip_aid = intval($poll_ip->pollip_aid);
309
+ $pollip_user = apply_filters( 'poll_log_secret_ballot', stripslashes($poll_ip->pollip_user) );
310
+ $pollip_ip = $poll_ip->pollip_ip;
311
+ $pollip_host = $poll_ip->pollip_host;
312
+ $pollip_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_ip->pollip_timestamp));
313
+ if($pollip_aid != $poll_last_aid) {
314
+ if($pollip_aid == 0) {
315
+ echo "<tr class=\"highlight\">\n<td colspan=\"4\"><strong>$pollip_answers[$pollip_aid]</strong></td>\n</tr>\n";
316
+ } else {
317
+ echo "<tr class=\"highlight\">\n<td colspan=\"4\"><strong>".__('Answer', 'wp-polls')." ".number_format_i18n($k).": $pollip_answers[$pollip_aid]</strong></td>\n</tr>\n";
318
+ $k++;
319
+ }
320
+ echo "<tr class=\"thead\">\n";
321
+ echo "<th>".__('No.', 'wp-polls')."</th>\n";
322
+ echo "<th>".__('User', 'wp-polls')."</th>\n";
323
+ echo "<th>".__('IP/Host', 'wp-polls')."</th>\n";
324
+ echo "<th>".__('Date', 'wp-polls')."</th>\n";
325
+ echo "</tr>\n";
326
+ $i = 1;
327
+ }
328
+ if($i%2 == 0) {
329
+ $style = '';
330
+ } else {
331
+ $style = 'class="alternate"';
332
+ }
333
+ echo "<tr $style>\n";
334
+ echo "<td>".number_format_i18n($i)."</td>\n";
335
+ echo "<td>$pollip_user</td>\n";
336
+ echo "<td><a href=\"http://ipinfo.io/$pollip_ip\" title=\"$pollip_ip\">$pollip_ip</a> / $pollip_host</td>\n";
337
+ echo "<td>$pollip_date</td>\n";
338
+ echo "</tr>\n";
339
+ $poll_last_aid = $pollip_aid;
340
+ $i++;
341
+ $j++;
342
+ }
343
+ }
344
+ echo "<tr class=\"highlight\">\n";
345
+ echo "<td colspan=\"4\">".sprintf(__('Total number of records that matches this filter: <strong>%s</strong>', 'wp-polls'), number_format_i18n($j))."</td>";
346
+ echo "</tr>\n";
347
+ echo '</table>'."\n";
348
+ }
349
+ ?>
350
+ </div>
351
+ <?php if(!empty($_POST['do'])) { ?>
352
+ <br class="clear" /><div id="poll_logs_display_none" style="text-align: center; display: <?php if(!$poll_ips) { echo 'block'; } else { echo 'none'; } ?>;" ><?php _e('No poll logs matches the filter.', 'wp-polls'); ?></div>
353
+ <?php } else { ?>
354
+ <br class="clear" /><div id="poll_logs_display_none" style="text-align: center; display: <?php if(!$poll_logs_count) { echo 'block'; } else { echo 'none'; } ?>;" ><?php _e('No poll logs available for this poll.', 'wp-polls'); ?></div>
355
+ <?php } ?>
356
  </div>
357
  <p>&nbsp;</p>
358
 
359
  <!-- Delete Poll Logs -->
360
  <div class="wrap">
361
+ <h3><?php _e('Delete Poll Logs', 'wp-polls'); ?></h3>
362
+ <br class="clear" />
363
+ <div align="center" id="poll_logs">
364
+ <?php if($poll_logs_count) { ?>
365
+ <strong><?php _e('Are You Sure You Want To Delete Logs For This Poll Only?', 'wp-polls'); ?></strong><br /><br />
366
+ <input type="checkbox" id="delete_logs_yes" name="delete_logs_yes" value="yes" />&nbsp;<label for="delete_logs_yes"><?php _e('Yes', 'wp-polls'); ?></label><br /><br />
367
+ <input type="button" name="do" value="<?php _e('Delete Logs For This Poll Only', 'wp-polls'); ?>" class="button" onclick="delete_this_poll_logs(<?php echo $poll_id; ?>, '<?php printf(esc_js(__('You are about to delete poll logs for this poll \'%s\' ONLY. This action is not reversible.', 'wp-polls')), htmlspecialchars( $poll_question ) ); ?>', '<?php echo wp_create_nonce('wp-polls_delete-poll-logs'); ?>');" />
368
+ <?php
369
+ } else {
370
+ _e('No poll logs available for this poll.', 'wp-polls');
371
+ }
372
+ ?>
373
+ </div>
374
+ <p><?php _e('Note: If your logging method is by IP and Cookie or by Cookie, users may still be unable to vote if they have voted before as the cookie is still stored in their computer.', 'wp-polls'); ?></p>
375
  </div>
polls-manager.php CHANGED
@@ -1,473 +1,513 @@
1
  <?php
2
- /*
3
- +----------------------------------------------------------------+
4
- | |
5
- | WordPress Plugin: WP-Polls |
6
- | Copyright (c) 2012 Lester "GaMerZ" Chan |
7
- | |
8
- | File Written By: |
9
- | - Lester "GaMerZ" Chan |
10
- | - http://lesterchan.net |
11
- | |
12
- | File Information: |
13
- | - Manage Your Polls |
14
- | - wp-content/plugins/wp-polls/polls-manager.php |
15
- | |
16
- +----------------------------------------------------------------+
17
- */
18
-
19
  ### Check Whether User Can Manage Polls
20
  if(!current_user_can('manage_polls')) {
21
- die('Access Denied');
22
  }
23
 
24
  ### Variables Variables Variables
25
  $base_name = plugin_basename('wp-polls/polls-manager.php');
26
  $base_page = 'admin.php?page='.$base_name;
27
- $mode = (isset($_GET['mode']) ? trim($_GET['mode']) : '');
28
- $poll_id = (isset($_GET['id']) ? intval($_GET['id']) : 0);
29
- $poll_aid = (isset($_GET['aid']) ? intval($_GET['aid']) : 0);
30
 
31
  ### Form Processing
32
  if(!empty($_POST['do'])) {
33
- // Decide What To Do
34
- switch($_POST['do']) {
35
- // Edit Poll
36
- case __('Edit Poll', 'wp-polls'):
37
- check_admin_referer('wp-polls_edit-poll');
38
- // Poll ID
39
- $pollq_id = intval($_POST['pollq_id']);
40
- // Poll Total Votes
41
- $pollq_totalvotes = intval($_POST['pollq_totalvotes']);
42
- // Poll Total Voters
43
- $pollq_totalvoters = intval($_POST['pollq_totalvoters']);
44
- // Poll Question
45
- $pollq_question = addslashes( wp_kses_post( trim( $_POST['pollq_question'] ) ) );
46
- // Poll Active
47
- $pollq_active = intval($_POST['pollq_active']);
48
- // Poll Start Date
49
- $edit_polltimestamp = isset($_POST['edit_polltimestamp']) && intval($_POST['edit_polltimestamp']) == 1;
50
- $timestamp_sql = '';
51
- if($edit_polltimestamp == 1) {
52
- $pollq_timestamp_day = intval($_POST['pollq_timestamp_day']);
53
- $pollq_timestamp_month = intval($_POST['pollq_timestamp_month']);
54
- $pollq_timestamp_year = intval($_POST['pollq_timestamp_year']);
55
- $pollq_timestamp_hour = intval($_POST['pollq_timestamp_hour']);
56
- $pollq_timestamp_minute = intval($_POST['pollq_timestamp_minute']);
57
- $pollq_timestamp_second = intval($_POST['pollq_timestamp_second']);
58
- $pollq_timestamp = gmmktime($pollq_timestamp_hour, $pollq_timestamp_minute, $pollq_timestamp_second, $pollq_timestamp_month, $pollq_timestamp_day, $pollq_timestamp_year);
59
- $timestamp_sql = ", pollq_timestamp = '$pollq_timestamp'";
60
- if($pollq_timestamp > current_time('timestamp')) {
61
- $pollq_active = -1;
62
- }
63
- }
64
- // Poll End Date
65
- $pollq_expiry_no = intval($_POST['pollq_expiry_no']);
66
- if($pollq_expiry_no == 1) {
67
- $pollq_expiry = '';
68
- } else {
69
- $pollq_expiry_day = intval($_POST['pollq_expiry_day']);
70
- $pollq_expiry_month = intval($_POST['pollq_expiry_month']);
71
- $pollq_expiry_year = intval($_POST['pollq_expiry_year']);
72
- $pollq_expiry_hour = intval($_POST['pollq_expiry_hour']);
73
- $pollq_expiry_minute = intval($_POST['pollq_expiry_minute']);
74
- $pollq_expiry_second = intval($_POST['pollq_expiry_second']);
75
- $pollq_expiry = gmmktime($pollq_expiry_hour, $pollq_expiry_minute, $pollq_expiry_second, $pollq_expiry_month, $pollq_expiry_day, $pollq_expiry_year);
76
- if($pollq_expiry <= current_time('timestamp')) {
77
- $pollq_active = 0;
78
- }
79
- if($edit_polltimestamp == 1) {
80
- if($pollq_expiry < $pollq_timestamp) {
81
- $pollq_active = 0;
82
- }
83
- }
84
- }
85
- // Mutilple Poll
86
- $pollq_multiple_yes = intval($_POST['pollq_multiple_yes']);
87
- $pollq_multiple = 0;
88
- if($pollq_multiple_yes == 1) {
89
- $pollq_multiple = intval($_POST['pollq_multiple']);
90
- } else {
91
- $pollq_multiple = 0;
92
- }
93
- // Update Poll's Question
94
- $edit_poll_question = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_question = '$pollq_question', pollq_totalvotes = $pollq_totalvotes, pollq_expiry = '$pollq_expiry', pollq_active = $pollq_active, pollq_multiple = $pollq_multiple, pollq_totalvoters = $pollq_totalvoters $timestamp_sql WHERE pollq_id = $pollq_id");
95
- if(!$edit_poll_question) {
96
- $text = '<p style="color: blue">'.sprintf(__('No Changes Had Been Made To Poll\'s Question \'%s\'.', 'wp-polls'), stripslashes($pollq_question)).'</p>';
97
- }
98
- // Update Polls' Answers
99
- $polla_aids = array();
100
- $get_polla_aids = $wpdb->get_results("SELECT polla_aid FROM $wpdb->pollsa WHERE polla_qid = $pollq_id ORDER BY polla_aid ASC");
101
- if($get_polla_aids) {
102
- foreach($get_polla_aids as $get_polla_aid) {
103
- $polla_aids[] = intval($get_polla_aid->polla_aid);
104
- }
105
- foreach($polla_aids as $polla_aid) {
106
- $polla_answers = addslashes( wp_kses_post( trim( $_POST['polla_aid-'.$polla_aid] ) ) );
107
- $polla_votes = intval($_POST['polla_votes-'.$polla_aid]);
108
- $edit_poll_answer = $wpdb->query("UPDATE $wpdb->pollsa SET polla_answers = '$polla_answers', polla_votes = $polla_votes WHERE polla_qid = $pollq_id AND polla_aid = $polla_aid");
109
- if(!$edit_poll_answer) {
110
- $text .= '<p style="color: blue">'.sprintf(__('No Changes Had Been Made To Poll\'s Answer \'%s\'.', 'wp-polls'), stripslashes($polla_answers)).'</p>';
111
- } else {
112
- $text .= '<p style="color: green">'.sprintf(__('Poll\'s Answer \'%s\' Edited Successfully.', 'wp-polls'), stripslashes($polla_answers)).'</p>';
113
- }
114
- }
115
- } else {
116
- $text .= '<p style="color: red">'.sprintf(__('Invalid Poll \'%s\'.', 'wp-polls'), stripslashes($pollq_question)).'</p>';
117
- }
118
- // Add Poll Answers (If Needed)
119
- $polla_answers_new = isset($_POST['polla_answers_new']) ? $_POST['polla_answers_new'] : null;
120
- if(!empty($polla_answers_new)) {
121
- $i = 0;
122
- $polla_answers_new_votes = $_POST['polla_answers_new_votes'];
123
- foreach($polla_answers_new as $polla_answer_new) {
124
- $polla_answer_new = addslashes( wp_kses_post( trim( $polla_answer_new ) ) );
125
- if(!empty($polla_answer_new)) {
126
- $polla_answer_new_vote = intval($polla_answers_new_votes[$i]);
127
- $add_poll_answers = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $pollq_id, '$polla_answer_new', $polla_answer_new_vote)");
128
- if(!$add_poll_answers) {
129
- $text .= '<p style="color: red;">'.sprintf(__('Error In Adding Poll\'s Answer \'%s\'.', 'wp-polls'), stripslashes($polla_answer_new)).'</p>';
130
- } else {
131
- $text .= '<p style="color: green;">'.sprintf(__('Poll\'s Answer \'%s\' Added Successfully.', 'wp-polls'), stripslashes($polla_answer_new)).'</p>';
132
- }
133
- }
134
- $i++;
135
- }
136
- }
137
- if(empty($text)) {
138
- $text = '<p style="color: green">'.sprintf(__('Poll \'%s\' Edited Successfully.', 'wp-polls'), stripslashes($pollq_question)).'</p>';
139
- }
140
- // Update Lastest Poll ID To Poll Options
141
- $latest_pollid = polls_latest_id();
142
- $update_latestpoll = update_option('poll_latestpoll', $latest_pollid);
143
- do_action( 'wp_polls_update_poll', $latest_pollid );
144
- cron_polls_place();
145
- break;
146
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  }
148
 
149
  ### Determines Which Mode It Is
150
  switch($mode) {
151
- // Poll Logging
152
- case 'logs':
153
- require('polls-logs.php');
154
- break;
155
- // Edit A Poll
156
- case 'edit':
157
- $last_col_align = is_rtl() ? 'right' : 'left';
158
- $poll_question = $wpdb->get_row("SELECT pollq_question, pollq_timestamp, pollq_totalvotes, pollq_active, pollq_expiry, pollq_multiple, pollq_totalvoters FROM $wpdb->pollsq WHERE pollq_id = $poll_id");
159
- $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = $poll_id ORDER BY polla_aid ASC");
160
- $poll_noquestion = $wpdb->get_var("SELECT COUNT(polla_aid) FROM $wpdb->pollsa WHERE polla_qid = $poll_id");
161
- $poll_question_text = stripslashes($poll_question->pollq_question);
162
- $poll_totalvotes = intval($poll_question->pollq_totalvotes);
163
- $poll_timestamp = $poll_question->pollq_timestamp;
164
- $poll_active = intval($poll_question->pollq_active);
165
- $poll_expiry = trim($poll_question->pollq_expiry);
166
- $poll_multiple = intval($poll_question->pollq_multiple);
167
- $poll_totalvoters = intval($poll_question->pollq_totalvoters);
168
  ?>
169
- <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade">'.stripslashes($text).'</div>'; } else { echo '<div id="message" class="updated" style="display: none;"></div>'; } ?>
170
 
171
- <!-- Edit Poll -->
172
- <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__).'&amp;mode=edit&amp;id='.$poll_id); ?>">
173
- <?php wp_nonce_field('wp-polls_edit-poll'); ?>
174
- <input type="hidden" name="pollq_id" value="<?php echo $poll_id; ?>" />
175
- <input type="hidden" name="pollq_active" value="<?php echo $poll_active; ?>" />
176
- <div class="wrap">
177
- <h2><?php _e('Edit Poll', 'wp-polls'); ?></h2>
178
- <!-- Poll Question -->
179
- <h3><?php _e('Poll Question', 'wp-polls'); ?></h3>
180
- <table class="form-table">
181
- <tr>
182
- <th width="20%" scope="row" valign="top"><?php _e('Question', 'wp-polls') ?></th>
183
- <td width="80%"><input type="text" size="70" name="pollq_question" value="<?php echo esc_attr( $poll_question_text ); ?>" /></td>
184
- </tr>
185
- </table>
186
- <!-- Poll Answers -->
187
- <h3><?php _e('Poll Answers', 'wp-polls'); ?></h3>
188
- <table class="form-table">
189
- <thead>
190
- <tr>
191
- <th width="20%" scope="row" valign="top"><?php _e('Answer No.', 'wp-polls') ?></th>
192
- <th width="60%" scope="row" valign="top"><?php _e('Answer Text', 'wp-polls') ?></th>
193
- <th width="20%" scope="row" valign="top" style="text-align: <?php echo $last_col_align; ?>;"><?php _e('No. Of Votes', 'wp-polls') ?></th>
194
- </tr>
195
- </thead>
196
- <tbody id="poll_answers">
197
- <?php
198
- $i=1;
199
- $poll_actual_totalvotes = 0;
200
- if($poll_answers) {
201
- $pollip_answers = array();
202
- $pollip_answers[0] = __('Null Votes', 'wp-polls');
203
- foreach($poll_answers as $poll_answer) {
204
- $polla_aid = intval($poll_answer->polla_aid);
205
- $polla_answers = stripslashes($poll_answer->polla_answers);
206
- $polla_votes = intval($poll_answer->polla_votes);
207
- $pollip_answers[$polla_aid] = $polla_answers;
208
- echo "<tr id=\"poll-answer-$polla_aid\">\n";
209
- echo '<th width="20%" scope="row" valign="top">'.sprintf(__('Answer %s', 'wp-polls'), number_format_i18n($i)).'</th>'."\n";
210
- echo "<td width=\"60%\"><input type=\"text\" size=\"50\" maxlength=\"200\" name=\"polla_aid-$polla_aid\" value=\"". esc_attr( $polla_answers ) . "\" />&nbsp;&nbsp;&nbsp;";
211
- echo "<input type=\"button\" value=\"".__('Delete', 'wp-polls')."\" onclick=\"delete_poll_ans($poll_id, $polla_aid, $polla_votes, '".sprintf(esc_js(__('You are about to delete this poll\'s answer \'%s\'.', 'wp-polls')), esc_js( esc_attr( $polla_answers ) ) ) . "', '".wp_create_nonce('wp-polls_delete-poll-answer')."');\" class=\"button\" /></td>\n";
212
- echo '<td width="20%" align="'.$last_col_align.'">'.number_format_i18n($polla_votes)." <input type=\"text\" size=\"4\" id=\"polla_votes-$polla_aid\" name=\"polla_votes-$polla_aid\" value=\"$polla_votes\" onblur=\"check_totalvotes();\" /></td>\n</tr>\n";
213
- $poll_actual_totalvotes += $polla_votes;
214
- $i++;
215
- }
216
- }
217
- ?>
218
- </tbody>
219
- <tbody>
220
- <tr>
221
- <td width="20%">&nbsp;</td>
222
- <td width="60%"><input type="button" value="<?php _e('Add Answer', 'wp-polls') ?>" onclick="add_poll_answer_edit();" class="button" /></td>
223
- <td width="20%" align="<?php echo $last_col_align; ?>"><strong><?php _e('Total Votes:', 'wp-polls'); ?></strong> <strong id="poll_total_votes"><?php echo number_format_i18n($poll_actual_totalvotes); ?></strong> <input type="text" size="4" readonly="readonly" id="pollq_totalvotes" name="pollq_totalvotes" value="<?php echo $poll_actual_totalvotes; ?>" onblur="check_totalvotes();" /></td>
224
- </tr>
225
- <tr>
226
- <td width="20%">&nbsp;</td>
227
- <td width="60%">&nbsp;</td>
228
- <td width="20%" align="<?php echo $last_col_align; ?>"><strong><?php _e('Total Voters:', 'wp-polls'); ?> <?php echo number_format_i18n($poll_totalvoters); ?></strong> <input type="text" size="4" name="pollq_totalvoters" value="<?php echo $poll_totalvoters; ?>" /></td>
229
- </tr>
230
- </tbody>
231
- </table>
232
- <!-- Poll Multiple Answers -->
233
- <h3><?php _e('Poll Multiple Answers', 'wp-polls') ?></h3>
234
- <table class="form-table">
235
- <tr>
236
- <th width="40%" scope="row" valign="top"><?php _e('Allows Users To Select More Than One Answer?', 'wp-polls'); ?></th>
237
- <td width="60%">
238
- <select name="pollq_multiple_yes" id="pollq_multiple_yes" size="1" onchange="check_pollq_multiple();">
239
- <option value="0"<?php selected('0', $poll_multiple); ?>><?php _e('No', 'wp-polls'); ?></option>
240
- <option value="1"<?php if($poll_multiple > 0) { echo ' selected="selected"'; } ?>><?php _e('Yes', 'wp-polls'); ?></option>
241
- </select>
242
- </td>
243
- </tr>
244
- <tr>
245
- <th width="40%" scope="row" valign="top"><?php _e('Maximum Number Of Selected Answers Allowed?', 'wp-polls') ?></th>
246
- <td width="60%">
247
- <select name="pollq_multiple" id="pollq_multiple" size="1" <?php if($poll_multiple == 0) { echo 'disabled="disabled"'; } ?>>
248
- <?php
249
- for($i = 1; $i <= $poll_noquestion; $i++) {
250
- if($poll_multiple > 0 && $poll_multiple == $i) {
251
- echo "<option value=\"$i\" selected=\"selected\">".number_format_i18n($i)."</option>\n";
252
- } else {
253
- echo "<option value=\"$i\">".number_format_i18n($i)."</option>\n";
254
- }
255
- }
256
- ?>
257
- </select>
258
- </td>
259
- </tr>
260
- </table>
261
- <!-- Poll Start/End Date -->
262
- <h3><?php _e('Poll Start/End Date', 'wp-polls'); ?></h3>
263
- <table class="form-table">
264
- <tr>
265
- <th width="20%" scope="row" valign="top"><?php _e('Start Date/Time', 'wp-polls'); ?></th>
266
- <td width="80%">
267
- <?php echo mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_timestamp)); ?><br />
268
- <input type="checkbox" name="edit_polltimestamp" id="edit_polltimestamp" value="1" onclick="check_polltimestamp()" />&nbsp;<label for="edit_polltimestamp"><?php _e('Edit Start Date/Time', 'wp-polls'); ?></label><br />
269
- <?php poll_timestamp($poll_timestamp, 'pollq_timestamp', 'none'); ?>
270
- </td>
271
- </tr>
272
- <tr>
273
- <th width="20%" scope="row" valign="top"><?php _e('End Date/Time', 'wp-polls'); ?></th>
274
- <td width="80%">
275
- <?php
276
- if(empty($poll_expiry)) {
277
- _e('This Poll Will Not Expire', 'wp-polls');
278
- } else {
279
- echo mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_expiry));
280
- }
281
- ?>
282
- <br />
283
- <input type="checkbox" name="pollq_expiry_no" id="pollq_expiry_no" value="1" onclick="check_pollexpiry();" <?php if(empty($poll_expiry)) { echo 'checked="checked"'; } ?> />
284
- <label for="pollq_expiry_no"><?php _e('Do NOT Expire This Poll', 'wp-polls'); ?></label><br />
285
- <?php
286
- if(empty($poll_expiry)) {
287
- poll_timestamp(current_time('timestamp'), 'pollq_expiry', 'none');
288
- } else {
289
- poll_timestamp($poll_expiry, 'pollq_expiry');
290
- }
291
- ?>
292
- </td>
293
- </tr>
294
- </table>
295
- <p style="text-align: center;">
296
- <input type="submit" name="do" value="<?php _e('Edit Poll', 'wp-polls'); ?>" class="button-primary" />&nbsp;&nbsp;
297
- <?php
298
- if($poll_active == 1) {
299
- $poll_open_display = 'none';
300
- $poll_close_display = 'inline';
301
- } else {
302
- $poll_open_display = 'inline';
303
- $poll_close_display = 'none';
304
- }
305
- ?>
306
- <input type="button" class="button" name="do" id="close_poll" value="<?php _e('Close Poll', 'wp-polls'); ?>" onclick="closing_poll(<?php echo $poll_id; ?>, '<?php printf(esc_js(__('You are about to CLOSE this poll \'%s\'.', 'wp-polls')), esc_attr( esc_js( $poll_question_text ) ) ); ?>', '<?php echo wp_create_nonce('wp-polls_close-poll'); ?>');" style="display: <?php echo $poll_close_display; ?>;" />
307
- <input type="button" class="button" name="do" id="open_poll" value="<?php _e('Open Poll', 'wp-polls'); ?>" onclick="opening_poll(<?php echo $poll_id; ?>, '<?php printf(esc_js(__('You are about to OPEN this poll \'%s\'.', 'wp-polls')), esc_attr( esc_js( $poll_question_text ) ) ); ?>', '<?php echo wp_create_nonce('wp-polls_open-poll'); ?>');" style="display: <?php echo $poll_open_display; ?>;" />
308
- &nbsp;&nbsp;<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-polls'); ?>" class="button" onclick="javascript:history.go(-1)" />
309
- </p>
310
- </div>
311
- </form>
 
312
  <?php
313
- break;
314
- // Main Page
315
- default:
316
- $polls = $wpdb->get_results("SELECT * FROM $wpdb->pollsq ORDER BY pollq_timestamp DESC");
317
- $total_ans = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->pollsa");
318
- $total_votes = 0;
319
- $total_voters = 0;
320
  ?>
321
- <!-- Last Action -->
322
- <div id="message" class="updated" style="display: none;"></div>
323
 
324
- <!-- Manage Polls -->
325
- <div class="wrap">
326
- <h2><?php _e('Manage Polls', 'wp-polls'); ?></h2>
327
- <h3><?php _e('Polls', 'wp-polls'); ?></h3>
328
- <br style="clear" />
329
- <table class="widefat">
330
- <thead>
331
- <tr>
332
- <th><?php _e('ID', 'wp-polls'); ?></th>
333
- <th><?php _e('Question', 'wp-polls'); ?></th>
334
- <th><?php _e('Total Voters', 'wp-polls'); ?></th>
335
- <th><?php _e('Start Date/Time', 'wp-polls'); ?></th>
336
- <th><?php _e('End Date/Time', 'wp-polls'); ?></th>
337
- <th><?php _e('Status', 'wp-polls'); ?></th>
338
- <th colspan="3"><?php _e('Action', 'wp-polls'); ?></th>
339
- </tr>
340
- </thead>
341
- <tbody id="manage_polls">
342
- <?php
343
- if($polls) {
344
- if(function_exists('dynamic_sidebar')) {
345
- $options = get_option('widget_polls');
346
- $multiple_polls = explode(',', $options['multiple_polls']);
347
- } else {
348
- $multiple_polls = array();
349
- }
350
- $i = 0;
351
- $current_poll = intval(get_option('poll_currentpoll'));
352
- $latest_poll = intval(get_option('poll_latestpoll'));
353
- foreach($polls as $poll) {
354
- $poll_id = intval($poll->pollq_id);
355
- $poll_question = stripslashes($poll->pollq_question);
356
- $poll_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll->pollq_timestamp));
357
- $poll_totalvotes = intval($poll->pollq_totalvotes);
358
- $poll_totalvoters = intval($poll->pollq_totalvoters);
359
- $poll_active = intval($poll->pollq_active);
360
- $poll_expiry = trim($poll->pollq_expiry);
361
- if(empty($poll_expiry)) {
362
- $poll_expiry_text = __('No Expiry', 'wp-polls');
363
- } else {
364
- $poll_expiry_text = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_expiry));
365
- }
366
- if($i%2 == 0) {
367
- $style = 'class="alternate"';
368
- } else {
369
- $style = '';
370
- }
371
- if($current_poll > 0) {
372
- if($current_poll == $poll_id) {
373
- $style = 'class="highlight"';
374
- }
375
- } elseif($current_poll == 0) {
376
- if($poll_id == $latest_poll) {
377
- $style = 'class="highlight"';
378
- }
379
- } else if(in_array($poll_id, $multiple_polls)) {
380
- $style = 'class="highlight"';
381
- }
382
- echo "<tr id=\"poll-$poll_id\" $style>\n";
383
- echo '<td><strong>'.number_format_i18n($poll_id).'</strong></td>'."\n";
384
- echo '<td>';
385
- if($current_poll > 0) {
386
- if($current_poll == $poll_id) {
387
- echo '<strong>'.__('Displayed:', 'wp-polls').'</strong> ';
388
- }
389
- } elseif($current_poll == 0) {
390
- if($poll_id == $latest_poll) {
391
- echo '<strong>'.__('Displayed:', 'wp-polls').'</strong> ';
392
- }
393
- } else if(in_array($poll_id, $multiple_polls)) {
394
- echo '<strong>'.__('Displayed:', 'wp-polls').'</strong> ';
395
- }
396
- echo wp_kses_post( $poll_question )."</td>\n";
397
- echo '<td>'.number_format_i18n($poll_totalvoters)."</td>\n";
398
- echo "<td>$poll_date</td>\n";
399
- echo "<td>$poll_expiry_text</td>\n";
400
- echo '<td>';
401
- if($poll_active == 1) {
402
- _e('Open', 'wp-polls');
403
- } elseif($poll_active == -1) {
404
- _e('Future', 'wp-polls');
405
- } else {
406
- _e('Closed', 'wp-polls');
407
- }
408
- echo "</td>\n";
409
- echo "<td><a href=\"$base_page&amp;mode=logs&amp;id=$poll_id\" class=\"edit\">".__('Logs', 'wp-polls')."</a></td>\n";
410
- echo "<td><a href=\"$base_page&amp;mode=edit&amp;id=$poll_id\" class=\"edit\">".__('Edit', 'wp-polls')."</a></td>\n";
411
- echo "<td><a href=\"#DeletePoll\" onclick=\"delete_poll($poll_id, '".sprintf(esc_js(__('You are about to delete this poll, \'%s\'.', 'wp-polls')), esc_js($poll_question))."', '".wp_create_nonce('wp-polls_delete-poll')."');\" class=\"delete\">".__('Delete', 'wp-polls')."</a></td>\n";
412
- echo '</tr>';
413
- $i++;
414
- $total_votes+= $poll_totalvotes;
415
- $total_voters+= $poll_totalvoters;
416
 
417
- }
418
- } else {
419
- echo '<tr><td colspan="9" align="center"><strong>'.__('No Polls Found', 'wp-polls').'</strong></td></tr>';
420
- }
421
- ?>
422
- </tbody>
423
- </table>
424
- </div>
425
- <p>&nbsp;</p>
426
 
427
- <!-- Polls Stats -->
428
- <div class="wrap">
429
- <h3><?php _e('Polls Stats:', 'wp-polls'); ?></h3>
430
- <br style="clear" />
431
- <table class="widefat">
432
- <tr>
433
- <th><?php _e('Total Polls:', 'wp-polls'); ?></th>
434
- <td><?php echo number_format_i18n($i); ?></td>
435
- </tr>
436
- <tr class="alternate">
437
- <th><?php _e('Total Polls\' Answers:', 'wp-polls'); ?></th>
438
- <td><?php echo number_format_i18n($total_ans); ?></td>
439
- </tr>
440
- <tr>
441
- <th><?php _e('Total Votes Cast:', 'wp-polls'); ?></th>
442
- <td><?php echo number_format_i18n($total_votes); ?></td>
443
- </tr>
444
- <tr class="alternate">
445
- <th><?php _e('Total Voters:', 'wp-polls'); ?></th>
446
- <td><?php echo number_format_i18n($total_voters); ?></td>
447
- </tr>
448
- </table>
449
- </div>
450
- <p>&nbsp;</p>
451
 
452
- <!-- Delete Polls Logs -->
453
- <div class="wrap">
454
- <h3><?php _e('Polls Logs', 'wp-polls'); ?></h3>
455
- <br style="clear" />
456
- <div align="center" id="poll_logs">
457
- <?php
458
- $poll_ips = intval($wpdb->get_var("SELECT COUNT(pollip_id) FROM $wpdb->pollsip"));
459
- if($poll_ips > 0) {
460
- ?>
461
- <strong><?php _e('Are You Sure You Want To Delete All Polls Logs?', 'wp-polls'); ?></strong><br /><br />
462
- <input type="checkbox" name="delete_logs_yes" id="delete_logs_yes" value="yes" />&nbsp;<label for="delete_logs_yes"><?php _e('Yes', 'wp-polls'); ?></label><br /><br />
463
- <input type="button" value="<?php _e('Delete All Logs', 'wp-polls'); ?>" class="button" onclick="delete_poll_logs('<?php echo esc_js(__('You are about to delete all poll logs. This action is not reversible.', 'wp-polls')); ?>', '<?php echo wp_create_nonce('wp-polls_delete-polls-logs'); ?>');" />
464
- <?php
465
- } else {
466
- _e('No poll logs available.', 'wp-polls');
467
- }
468
- ?>
469
- </div>
470
- <p><?php _e('Note: If your logging method is by IP and Cookie or by Cookie, users may still be unable to vote if they have voted before as the cookie is still stored in their computer.', 'wp-polls'); ?></p>
471
- </div>
472
  <?php
473
  } // End switch($mode)
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  ### Check Whether User Can Manage Polls
3
  if(!current_user_can('manage_polls')) {
4
+ die('Access Denied');
5
  }
6
 
7
  ### Variables Variables Variables
8
  $base_name = plugin_basename('wp-polls/polls-manager.php');
9
  $base_page = 'admin.php?page='.$base_name;
10
+ $mode = ( isset( $_GET['mode'] ) ? trim( $_GET['mode'] ) : '' );
11
+ $poll_id = ( isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0 );
12
+ $poll_aid = ( isset( $_GET['aid'] ) ? intval( $_GET['aid'] ) : 0 );
13
 
14
  ### Form Processing
15
  if(!empty($_POST['do'])) {
16
+ // Decide What To Do
17
+ switch($_POST['do']) {
18
+ // Edit Poll
19
+ case __('Edit Poll', 'wp-polls'):
20
+ check_admin_referer( 'wp-polls_edit-poll' );
21
+ // Poll ID
22
+ $pollq_id = intval( $_POST['pollq_id'] );
23
+ // Poll Total Votes
24
+ $pollq_totalvotes = intval($_POST['pollq_totalvotes']);
25
+ // Poll Total Voters
26
+ $pollq_totalvoters = intval($_POST['pollq_totalvoters']);
27
+ // Poll Question
28
+ $pollq_question = esc_sql( wp_kses_post( trim( $_POST['pollq_question'] ) ) );
29
+ // Poll Active
30
+ $pollq_active = intval($_POST['pollq_active']);
31
+ // Poll Start Date
32
+ $pollq_timestamp = isset( $_POST['poll_timestamp_old'] ) ? $_POST['poll_timestamp_old'] : current_time( 'timestamp' );
33
+ $edit_polltimestamp = isset( $_POST['edit_polltimestamp'] ) && intval( $_POST['edit_polltimestamp'] ) === 1;
34
+ if($edit_polltimestamp == 1) {
35
+ $pollq_timestamp_day = intval($_POST['pollq_timestamp_day']);
36
+ $pollq_timestamp_month = intval($_POST['pollq_timestamp_month']);
37
+ $pollq_timestamp_year = intval($_POST['pollq_timestamp_year']);
38
+ $pollq_timestamp_hour = intval($_POST['pollq_timestamp_hour']);
39
+ $pollq_timestamp_minute = intval($_POST['pollq_timestamp_minute']);
40
+ $pollq_timestamp_second = intval($_POST['pollq_timestamp_second']);
41
+ $pollq_timestamp = gmmktime($pollq_timestamp_hour, $pollq_timestamp_minute, $pollq_timestamp_second, $pollq_timestamp_month, $pollq_timestamp_day, $pollq_timestamp_year);
42
+ if($pollq_timestamp > current_time('timestamp')) {
43
+ $pollq_active = -1;
44
+ }
45
+ }
46
+ // Poll End Date
47
+ $pollq_expiry_no = isset( $_POST['pollq_expiry_no'] ) ? intval( $_POST['pollq_expiry_no'] ) : 0;
48
+ if($pollq_expiry_no == 1) {
49
+ $pollq_expiry = '';
50
+ } else {
51
+ $pollq_expiry_day = intval($_POST['pollq_expiry_day']);
52
+ $pollq_expiry_month = intval($_POST['pollq_expiry_month']);
53
+ $pollq_expiry_year = intval($_POST['pollq_expiry_year']);
54
+ $pollq_expiry_hour = intval($_POST['pollq_expiry_hour']);
55
+ $pollq_expiry_minute = intval($_POST['pollq_expiry_minute']);
56
+ $pollq_expiry_second = intval($_POST['pollq_expiry_second']);
57
+ $pollq_expiry = gmmktime($pollq_expiry_hour, $pollq_expiry_minute, $pollq_expiry_second, $pollq_expiry_month, $pollq_expiry_day, $pollq_expiry_year);
58
+ if($pollq_expiry <= current_time('timestamp')) {
59
+ $pollq_active = 0;
60
+ }
61
+ if($edit_polltimestamp == 1) {
62
+ if($pollq_expiry < $pollq_timestamp) {
63
+ $pollq_active = 0;
64
+ }
65
+ }
66
+ }
67
+ // Mutilple Poll
68
+ $pollq_multiple_yes = intval($_POST['pollq_multiple_yes']);
69
+ $pollq_multiple = 0;
70
+ if($pollq_multiple_yes == 1) {
71
+ $pollq_multiple = intval($_POST['pollq_multiple']);
72
+ } else {
73
+ $pollq_multiple = 0;
74
+ }
75
+ // Update Poll's Question
76
+ $text = '';
77
+ $edit_poll_question = $wpdb->update(
78
+ $wpdb->pollsq,
79
+ array(
80
+ 'pollq_question' => $pollq_question,
81
+ 'pollq_timestamp' => $pollq_timestamp,
82
+ 'pollq_totalvotes' => $pollq_totalvotes,
83
+ 'pollq_active' => $pollq_active,
84
+ 'pollq_expiry' => $pollq_expiry,
85
+ 'pollq_multiple' => $pollq_multiple,
86
+ 'pollq_totalvoters' => $pollq_totalvoters
87
+ ),
88
+ array(
89
+ 'pollq_id' => $pollq_id
90
+ ),
91
+ array(
92
+ '%s',
93
+ '%s',
94
+ '%d',
95
+ '%d',
96
+ '%s',
97
+ '%d',
98
+ '%d'
99
+ ),
100
+ array(
101
+ '%d'
102
+ )
103
+ );
104
+ if( ! $edit_poll_question ) {
105
+ $text = '<p style="color: blue">'.sprintf(__('No Changes Had Been Made To Poll\'s Question \'%s\'.', 'wp-polls'), stripslashes($pollq_question)).'</p>';
106
+ }
107
+ // Update Polls' Answers
108
+ $polla_aids = array();
109
+ $get_polla_aids = $wpdb->get_results( $wpdb->prepare( "SELECT polla_aid FROM $wpdb->pollsa WHERE polla_qid = %d ORDER BY polla_aid ASC", $pollq_id ) );
110
+ if($get_polla_aids) {
111
+ foreach($get_polla_aids as $get_polla_aid) {
112
+ $polla_aids[] = intval($get_polla_aid->polla_aid);
113
+ }
114
+ foreach($polla_aids as $polla_aid) {
115
+ $polla_answers = wp_kses_post( trim( $_POST['polla_aid-'.$polla_aid] ) );
116
+ $polla_votes = intval($_POST['polla_votes-'.$polla_aid]);
117
+ $edit_poll_answer = $wpdb->update(
118
+ $wpdb->pollsa,
119
+ array(
120
+ 'polla_answers' => $polla_answers,
121
+ 'polla_votes' => $polla_votes
122
+ ),
123
+ array(
124
+ 'polla_qid' => $pollq_id,
125
+ 'polla_aid' => $polla_aid
126
+ ),
127
+ array(
128
+ '%s',
129
+ '%d'
130
+ ),
131
+ array(
132
+ '%d',
133
+ '%d'
134
+ )
135
+ );
136
+ if( ! $edit_poll_answer ) {
137
+ $text .= '<p style="color: blue">'.sprintf(__('No Changes Had Been Made To Poll\'s Answer \'%s\'.', 'wp-polls'), $polla_answers ).'</p>';
138
+ } else {
139
+ $text .= '<p style="color: green">'.sprintf(__('Poll\'s Answer \'%s\' Edited Successfully.', 'wp-polls'), $polla_answers ).'</p>';
140
+ }
141
+ }
142
+ } else {
143
+ $text .= '<p style="color: red">'.sprintf(__('Invalid Poll \'%s\'.', 'wp-polls'), stripslashes($pollq_question)).'</p>';
144
+ }
145
+ // Add Poll Answers (If Needed)
146
+ $polla_answers_new = isset($_POST['polla_answers_new']) ? $_POST['polla_answers_new'] : null;
147
+ if(!empty($polla_answers_new)) {
148
+ $i = 0;
149
+ $polla_answers_new_votes = $_POST['polla_answers_new_votes'];
150
+ foreach($polla_answers_new as $polla_answer_new) {
151
+ $polla_answer_new = wp_kses_post( trim( $polla_answer_new ) );
152
+ if(!empty($polla_answer_new)) {
153
+ $polla_answer_new_vote = intval( $polla_answers_new_votes[$i] );
154
+ $add_poll_answers = $wpdb->insert(
155
+ $wpdb->pollsa,
156
+ array(
157
+ 'polla_qid' => $pollq_id,
158
+ 'polla_answers' => $polla_answer_new,
159
+ 'polla_votes' => $polla_answer_new_vote
160
+ ),
161
+ array(
162
+ '%d',
163
+ '%s',
164
+ '%d'
165
+ )
166
+ );
167
+ if( ! $add_poll_answers ) {
168
+ $text .= '<p style="color: red;">'.sprintf(__('Error In Adding Poll\'s Answer \'%s\'.', 'wp-polls'), $polla_answer_new).'</p>';
169
+ } else {
170
+ $text .= '<p style="color: green;">'.sprintf(__('Poll\'s Answer \'%s\' Added Successfully.', 'wp-polls'), $polla_answer_new).'</p>';
171
+ }
172
+ }
173
+ $i++;
174
+ }
175
+ }
176
+ if(empty($text)) {
177
+ $text = '<p style="color: green">'.sprintf(__('Poll \'%s\' Edited Successfully.', 'wp-polls'), stripslashes($pollq_question)).'</p>';
178
+ }
179
+ // Update Lastest Poll ID To Poll Options
180
+ $latest_pollid = polls_latest_id();
181
+ $update_latestpoll = update_option('poll_latestpoll', $latest_pollid);
182
+ do_action( 'wp_polls_update_poll', $latest_pollid );
183
+ cron_polls_place();
184
+ break;
185
+ }
186
  }
187
 
188
  ### Determines Which Mode It Is
189
  switch($mode) {
190
+ // Poll Logging
191
+ case 'logs':
192
+ require('polls-logs.php');
193
+ break;
194
+ // Edit A Poll
195
+ case 'edit':
196
+ $last_col_align = is_rtl() ? 'right' : 'left';
197
+ $poll_question = $wpdb->get_row( $wpdb->prepare( "SELECT pollq_question, pollq_timestamp, pollq_totalvotes, pollq_active, pollq_expiry, pollq_multiple, pollq_totalvoters FROM $wpdb->pollsq WHERE pollq_id = %d", $poll_id ) );
198
+ $poll_answers = $wpdb->get_results( $wpdb->prepare( "SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = %d ORDER BY polla_aid ASC", $poll_id ) );
199
+ $poll_noquestion = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(polla_aid) FROM $wpdb->pollsa WHERE polla_qid = %d", $poll_id ) );
200
+ $poll_question_text = stripslashes($poll_question->pollq_question);
201
+ $poll_totalvotes = intval($poll_question->pollq_totalvotes);
202
+ $poll_timestamp = $poll_question->pollq_timestamp;
203
+ $poll_active = intval($poll_question->pollq_active);
204
+ $poll_expiry = trim($poll_question->pollq_expiry);
205
+ $poll_multiple = intval($poll_question->pollq_multiple);
206
+ $poll_totalvoters = intval($poll_question->pollq_totalvoters);
207
  ?>
208
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade">'.stripslashes($text).'</div>'; } else { echo '<div id="message" class="updated" style="display: none;"></div>'; } ?>
209
 
210
+ <!-- Edit Poll -->
211
+ <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__).'&amp;mode=edit&amp;id='.$poll_id); ?>">
212
+ <?php wp_nonce_field('wp-polls_edit-poll'); ?>
213
+ <input type="hidden" name="pollq_id" value="<?php echo $poll_id; ?>" />
214
+ <input type="hidden" name="pollq_active" value="<?php echo $poll_active; ?>" />
215
+ <input type="hidden" name="poll_timestamp_old" value="<?php echo $poll_timestamp; ?>" />
216
+ <div class="wrap">
217
+ <h2><?php _e('Edit Poll', 'wp-polls'); ?></h2>
218
+ <!-- Poll Question -->
219
+ <h3><?php _e('Poll Question', 'wp-polls'); ?></h3>
220
+ <table class="form-table">
221
+ <tr>
222
+ <th width="20%" scope="row" valign="top"><?php _e('Question', 'wp-polls') ?></th>
223
+ <td width="80%"><input type="text" size="70" name="pollq_question" value="<?php echo esc_attr( $poll_question_text ); ?>" /></td>
224
+ </tr>
225
+ </table>
226
+ <!-- Poll Answers -->
227
+ <h3><?php _e('Poll Answers', 'wp-polls'); ?></h3>
228
+ <table class="form-table">
229
+ <thead>
230
+ <tr>
231
+ <th width="20%" scope="row" valign="top"><?php _e('Answer No.', 'wp-polls') ?></th>
232
+ <th width="60%" scope="row" valign="top"><?php _e('Answer Text', 'wp-polls') ?></th>
233
+ <th width="20%" scope="row" valign="top" style="text-align: <?php echo $last_col_align; ?>;"><?php _e('No. Of Votes', 'wp-polls') ?></th>
234
+ </tr>
235
+ </thead>
236
+ <tbody id="poll_answers">
237
+ <?php
238
+ $i=1;
239
+ $poll_actual_totalvotes = 0;
240
+ if($poll_answers) {
241
+ $pollip_answers = array();
242
+ $pollip_answers[0] = __('Null Votes', 'wp-polls');
243
+ foreach($poll_answers as $poll_answer) {
244
+ $polla_aid = intval($poll_answer->polla_aid);
245
+ $polla_answers = stripslashes($poll_answer->polla_answers);
246
+ $polla_votes = intval($poll_answer->polla_votes);
247
+ $pollip_answers[$polla_aid] = $polla_answers;
248
+ echo "<tr id=\"poll-answer-$polla_aid\">\n";
249
+ echo '<th width="20%" scope="row" valign="top">'.sprintf(__('Answer %s', 'wp-polls'), number_format_i18n($i)).'</th>'."\n";
250
+ echo "<td width=\"60%\"><input type=\"text\" size=\"50\" maxlength=\"200\" name=\"polla_aid-$polla_aid\" value=\"". esc_attr( $polla_answers ) . "\" />&nbsp;&nbsp;&nbsp;";
251
+ echo "<input type=\"button\" value=\"".__('Delete', 'wp-polls')."\" onclick=\"delete_poll_ans($poll_id, $polla_aid, $polla_votes, '".sprintf(esc_js(__('You are about to delete this poll\'s answer \'%s\'.', 'wp-polls')), esc_js( esc_attr( $polla_answers ) ) ) . "', '".wp_create_nonce('wp-polls_delete-poll-answer')."');\" class=\"button\" /></td>\n";
252
+ echo '<td width="20%" align="'.$last_col_align.'">'.number_format_i18n($polla_votes)." <input type=\"text\" size=\"4\" id=\"polla_votes-$polla_aid\" name=\"polla_votes-$polla_aid\" value=\"$polla_votes\" onblur=\"check_totalvotes();\" /></td>\n</tr>\n";
253
+ $poll_actual_totalvotes += $polla_votes;
254
+ $i++;
255
+ }
256
+ }
257
+ ?>
258
+ </tbody>
259
+ <tbody>
260
+ <tr>
261
+ <td width="20%">&nbsp;</td>
262
+ <td width="60%"><input type="button" value="<?php _e('Add Answer', 'wp-polls') ?>" onclick="add_poll_answer_edit();" class="button" /></td>
263
+ <td width="20%" align="<?php echo $last_col_align; ?>"><strong><?php _e('Total Votes:', 'wp-polls'); ?></strong> <strong id="poll_total_votes"><?php echo number_format_i18n($poll_actual_totalvotes); ?></strong> <input type="text" size="4" readonly="readonly" id="pollq_totalvotes" name="pollq_totalvotes" value="<?php echo $poll_actual_totalvotes; ?>" onblur="check_totalvotes();" /></td>
264
+ </tr>
265
+ <tr>
266
+ <td width="20%">&nbsp;</td>
267
+ <td width="60%">&nbsp;</td>
268
+ <td width="20%" align="<?php echo $last_col_align; ?>"><strong><?php _e('Total Voters:', 'wp-polls'); ?> <?php echo number_format_i18n($poll_totalvoters); ?></strong> <input type="text" size="4" name="pollq_totalvoters" value="<?php echo $poll_totalvoters; ?>" /></td>
269
+ </tr>
270
+ </tbody>
271
+ </table>
272
+ <!-- Poll Multiple Answers -->
273
+ <h3><?php _e('Poll Multiple Answers', 'wp-polls') ?></h3>
274
+ <table class="form-table">
275
+ <tr>
276
+ <th width="40%" scope="row" valign="top"><?php _e('Allows Users To Select More Than One Answer?', 'wp-polls'); ?></th>
277
+ <td width="60%">
278
+ <select name="pollq_multiple_yes" id="pollq_multiple_yes" size="1" onchange="check_pollq_multiple();">
279
+ <option value="0"<?php selected('0', $poll_multiple); ?>><?php _e('No', 'wp-polls'); ?></option>
280
+ <option value="1"<?php if($poll_multiple > 0) { echo ' selected="selected"'; } ?>><?php _e('Yes', 'wp-polls'); ?></option>
281
+ </select>
282
+ </td>
283
+ </tr>
284
+ <tr>
285
+ <th width="40%" scope="row" valign="top"><?php _e('Maximum Number Of Selected Answers Allowed?', 'wp-polls') ?></th>
286
+ <td width="60%">
287
+ <select name="pollq_multiple" id="pollq_multiple" size="1" <?php if($poll_multiple == 0) { echo 'disabled="disabled"'; } ?>>
288
+ <?php
289
+ for($i = 1; $i <= $poll_noquestion; $i++) {
290
+ if($poll_multiple > 0 && $poll_multiple == $i) {
291
+ echo "<option value=\"$i\" selected=\"selected\">".number_format_i18n($i)."</option>\n";
292
+ } else {
293
+ echo "<option value=\"$i\">".number_format_i18n($i)."</option>\n";
294
+ }
295
+ }
296
+ ?>
297
+ </select>
298
+ </td>
299
+ </tr>
300
+ </table>
301
+ <!-- Poll Start/End Date -->
302
+ <h3><?php _e('Poll Start/End Date', 'wp-polls'); ?></h3>
303
+ <table class="form-table">
304
+ <tr>
305
+ <th width="20%" scope="row" valign="top"><?php _e('Start Date/Time', 'wp-polls'); ?></th>
306
+ <td width="80%">
307
+ <?php echo mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_timestamp)); ?><br />
308
+ <input type="checkbox" name="edit_polltimestamp" id="edit_polltimestamp" value="1" onclick="check_polltimestamp()" />&nbsp;<label for="edit_polltimestamp"><?php _e('Edit Start Date/Time', 'wp-polls'); ?></label><br />
309
+ <?php poll_timestamp($poll_timestamp, 'pollq_timestamp', 'none'); ?>
310
+ </td>
311
+ </tr>
312
+ <tr>
313
+ <th width="20%" scope="row" valign="top"><?php _e('End Date/Time', 'wp-polls'); ?></th>
314
+ <td width="80%">
315
+ <?php
316
+ if(empty($poll_expiry)) {
317
+ _e('This Poll Will Not Expire', 'wp-polls');
318
+ } else {
319
+ echo mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_expiry));
320
+ }
321
+ ?>
322
+ <br />
323
+ <input type="checkbox" name="pollq_expiry_no" id="pollq_expiry_no" value="1" onclick="check_pollexpiry();" <?php if(empty($poll_expiry)) { echo 'checked="checked"'; } ?> />
324
+ <label for="pollq_expiry_no"><?php _e('Do NOT Expire This Poll', 'wp-polls'); ?></label><br />
325
+ <?php
326
+ if(empty($poll_expiry)) {
327
+ poll_timestamp(current_time('timestamp'), 'pollq_expiry', 'none');
328
+ } else {
329
+ poll_timestamp($poll_expiry, 'pollq_expiry');
330
+ }
331
+ ?>
332
+ </td>
333
+ </tr>
334
+ </table>
335
+ <p style="text-align: center;">
336
+ <input type="submit" name="do" value="<?php _e('Edit Poll', 'wp-polls'); ?>" class="button-primary" />&nbsp;&nbsp;
337
+ <?php
338
+ if($poll_active == 1) {
339
+ $poll_open_display = 'none';
340
+ $poll_close_display = 'inline';
341
+ } else {
342
+ $poll_open_display = 'inline';
343
+ $poll_close_display = 'none';
344
+ }
345
+ ?>
346
+ <input type="button" class="button" name="do" id="close_poll" value="<?php _e('Close Poll', 'wp-polls'); ?>" onclick="closing_poll(<?php echo $poll_id; ?>, '<?php printf(esc_js(__('You are about to CLOSE this poll \'%s\'.', 'wp-polls')), esc_attr( esc_js( $poll_question_text ) ) ); ?>', '<?php echo wp_create_nonce('wp-polls_close-poll'); ?>');" style="display: <?php echo $poll_close_display; ?>;" />
347
+ <input type="button" class="button" name="do" id="open_poll" value="<?php _e('Open Poll', 'wp-polls'); ?>" onclick="opening_poll(<?php echo $poll_id; ?>, '<?php printf(esc_js(__('You are about to OPEN this poll \'%s\'.', 'wp-polls')), esc_attr( esc_js( $poll_question_text ) ) ); ?>', '<?php echo wp_create_nonce('wp-polls_open-poll'); ?>');" style="display: <?php echo $poll_open_display; ?>;" />
348
+ &nbsp;&nbsp;<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-polls'); ?>" class="button" onclick="javascript:history.go(-1)" />
349
+ </p>
350
+ </div>
351
+ </form>
352
  <?php
353
+ break;
354
+ // Main Page
355
+ default:
356
+ $polls = $wpdb->get_results( "SELECT * FROM $wpdb->pollsq ORDER BY pollq_timestamp DESC" );
357
+ $total_ans = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->pollsa" );
358
+ $total_votes = 0;
359
+ $total_voters = 0;
360
  ?>
361
+ <!-- Last Action -->
362
+ <div id="message" class="updated" style="display: none;"></div>
363
 
364
+ <!-- Manage Polls -->
365
+ <div class="wrap">
366
+ <h2><?php _e('Manage Polls', 'wp-polls'); ?></h2>
367
+ <h3><?php _e('Polls', 'wp-polls'); ?></h3>
368
+ <br style="clear" />
369
+ <table class="widefat">
370
+ <thead>
371
+ <tr>
372
+ <th><?php _e('ID', 'wp-polls'); ?></th>
373
+ <th><?php _e('Question', 'wp-polls'); ?></th>
374
+ <th><?php _e('Total Voters', 'wp-polls'); ?></th>
375
+ <th><?php _e('Start Date/Time', 'wp-polls'); ?></th>
376
+ <th><?php _e('End Date/Time', 'wp-polls'); ?></th>
377
+ <th><?php _e('Status', 'wp-polls'); ?></th>
378
+ <th colspan="3"><?php _e('Action', 'wp-polls'); ?></th>
379
+ </tr>
380
+ </thead>
381
+ <tbody id="manage_polls">
382
+ <?php
383
+ if($polls) {
384
+ if(function_exists('dynamic_sidebar')) {
385
+ $options = get_option('widget_polls');
386
+ $multiple_polls = explode(',', $options['multiple_polls']);
387
+ } else {
388
+ $multiple_polls = array();
389
+ }
390
+ $i = 0;
391
+ $current_poll = intval(get_option('poll_currentpoll'));
392
+ $latest_poll = intval(get_option('poll_latestpoll'));
393
+ foreach($polls as $poll) {
394
+ $poll_id = intval($poll->pollq_id);
395
+ $poll_question = stripslashes($poll->pollq_question);
396
+ $poll_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll->pollq_timestamp));
397
+ $poll_totalvotes = intval($poll->pollq_totalvotes);
398
+ $poll_totalvoters = intval($poll->pollq_totalvoters);
399
+ $poll_active = intval($poll->pollq_active);
400
+ $poll_expiry = trim($poll->pollq_expiry);
401
+ if(empty($poll_expiry)) {
402
+ $poll_expiry_text = __('No Expiry', 'wp-polls');
403
+ } else {
404
+ $poll_expiry_text = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_expiry));
405
+ }
406
+ if($i%2 == 0) {
407
+ $style = 'class="alternate"';
408
+ } else {
409
+ $style = '';
410
+ }
411
+ if($current_poll > 0) {
412
+ if($current_poll == $poll_id) {
413
+ $style = 'class="highlight"';
414
+ }
415
+ } elseif($current_poll == 0) {
416
+ if($poll_id == $latest_poll) {
417
+ $style = 'class="highlight"';
418
+ }
419
+ } else if(in_array($poll_id, $multiple_polls)) {
420
+ $style = 'class="highlight"';
421
+ }
422
+ echo "<tr id=\"poll-$poll_id\" $style>\n";
423
+ echo '<td><strong>'.number_format_i18n($poll_id).'</strong></td>'."\n";
424
+ echo '<td>';
425
+ if($current_poll > 0) {
426
+ if($current_poll == $poll_id) {
427
+ echo '<strong>'.__('Displayed:', 'wp-polls').'</strong> ';
428
+ }
429
+ } elseif($current_poll == 0) {
430
+ if($poll_id == $latest_poll) {
431
+ echo '<strong>'.__('Displayed:', 'wp-polls').'</strong> ';
432
+ }
433
+ } else if(in_array($poll_id, $multiple_polls)) {
434
+ echo '<strong>'.__('Displayed:', 'wp-polls').'</strong> ';
435
+ }
436
+ echo wp_kses_post( $poll_question )."</td>\n";
437
+ echo '<td>'.number_format_i18n($poll_totalvoters)."</td>\n";
438
+ echo "<td>$poll_date</td>\n";
439
+ echo "<td>$poll_expiry_text</td>\n";
440
+ echo '<td>';
441
+ if($poll_active == 1) {
442
+ _e('Open', 'wp-polls');
443
+ } elseif($poll_active == -1) {
444
+ _e('Future', 'wp-polls');
445
+ } else {
446
+ _e('Closed', 'wp-polls');
447
+ }
448
+ echo "</td>\n";
449
+ echo "<td><a href=\"$base_page&amp;mode=logs&amp;id=$poll_id\" class=\"edit\">".__('Logs', 'wp-polls')."</a></td>\n";
450
+ echo "<td><a href=\"$base_page&amp;mode=edit&amp;id=$poll_id\" class=\"edit\">".__('Edit', 'wp-polls')."</a></td>\n";
451
+ echo "<td><a href=\"#DeletePoll\" onclick=\"delete_poll($poll_id, '".sprintf(esc_js(__('You are about to delete this poll, \'%s\'.', 'wp-polls')), esc_js($poll_question))."', '".wp_create_nonce('wp-polls_delete-poll')."');\" class=\"delete\">".__('Delete', 'wp-polls')."</a></td>\n";
452
+ echo '</tr>';
453
+ $i++;
454
+ $total_votes+= $poll_totalvotes;
455
+ $total_voters+= $poll_totalvoters;
456
 
457
+ }
458
+ } else {
459
+ echo '<tr><td colspan="9" align="center"><strong>'.__('No Polls Found', 'wp-polls').'</strong></td></tr>';
460
+ }
461
+ ?>
462
+ </tbody>
463
+ </table>
464
+ </div>
465
+ <p>&nbsp;</p>
466
 
467
+ <!-- Polls Stats -->
468
+ <div class="wrap">
469
+ <h3><?php _e('Polls Stats:', 'wp-polls'); ?></h3>
470
+ <br style="clear" />
471
+ <table class="widefat">
472
+ <tr>
473
+ <th><?php _e('Total Polls:', 'wp-polls'); ?></th>
474
+ <td><?php echo number_format_i18n($i); ?></td>
475
+ </tr>
476
+ <tr class="alternate">
477
+ <th><?php _e('Total Polls\' Answers:', 'wp-polls'); ?></th>
478
+ <td><?php echo number_format_i18n($total_ans); ?></td>
479
+ </tr>
480
+ <tr>
481
+ <th><?php _e('Total Votes Cast:', 'wp-polls'); ?></th>
482
+ <td><?php echo number_format_i18n($total_votes); ?></td>
483
+ </tr>
484
+ <tr class="alternate">
485
+ <th><?php _e('Total Voters:', 'wp-polls'); ?></th>
486
+ <td><?php echo number_format_i18n($total_voters); ?></td>
487
+ </tr>
488
+ </table>
489
+ </div>
490
+ <p>&nbsp;</p>
491
 
492
+ <!-- Delete Polls Logs -->
493
+ <div class="wrap">
494
+ <h3><?php _e('Polls Logs', 'wp-polls'); ?></h3>
495
+ <br style="clear" />
496
+ <div align="center" id="poll_logs">
497
+ <?php
498
+ $poll_ips = intval( $wpdb->get_var( "SELECT COUNT(pollip_id) FROM $wpdb->pollsip" ) );
499
+ if($poll_ips > 0) {
500
+ ?>
501
+ <strong><?php _e('Are You Sure You Want To Delete All Polls Logs?', 'wp-polls'); ?></strong><br /><br />
502
+ <input type="checkbox" name="delete_logs_yes" id="delete_logs_yes" value="yes" />&nbsp;<label for="delete_logs_yes"><?php _e('Yes', 'wp-polls'); ?></label><br /><br />
503
+ <input type="button" value="<?php _e('Delete All Logs', 'wp-polls'); ?>" class="button" onclick="delete_poll_logs('<?php echo esc_js(__('You are about to delete all poll logs. This action is not reversible.', 'wp-polls')); ?>', '<?php echo wp_create_nonce('wp-polls_delete-polls-logs'); ?>');" />
504
+ <?php
505
+ } else {
506
+ _e('No poll logs available.', 'wp-polls');
507
+ }
508
+ ?>
509
+ </div>
510
+ <p><?php _e('Note: If your logging method is by IP and Cookie or by Cookie, users may still be unable to vote if they have voted before as the cookie is still stored in their computer.', 'wp-polls'); ?></p>
511
+ </div>
512
  <?php
513
  } // End switch($mode)
polls-options.php CHANGED
@@ -44,7 +44,6 @@ if( isset($_POST['Submit']) && $_POST['Submit'] ) {
44
  $poll_archive_perpage = intval($_POST['poll_archive_perpage']);
45
  $poll_archive_displaypoll = intval($_POST['poll_archive_displaypoll']);
46
  $poll_archive_url = esc_url_raw( strip_tags( trim( $_POST['poll_archive_url'] ) ) );
47
- $poll_archive_show = intval($_POST['poll_archive_show']);
48
  $poll_currentpoll = intval($_POST['poll_currentpoll']);
49
  $poll_close = intval($_POST['poll_close']);
50
  $poll_logging_method = intval($_POST['poll_logging_method']);
@@ -61,7 +60,6 @@ if( isset($_POST['Submit']) && $_POST['Submit'] ) {
61
  $update_poll_queries[] = update_option('poll_archive_perpage', $poll_archive_perpage);
62
  $update_poll_queries[] = update_option('poll_archive_displaypoll', $poll_archive_displaypoll);
63
  $update_poll_queries[] = update_option('poll_archive_url', $poll_archive_url);
64
- $update_poll_queries[] = update_option('poll_archive_show', $poll_archive_show);
65
  $update_poll_queries[] = update_option('poll_currentpoll', $poll_currentpoll);
66
  $update_poll_queries[] = update_option('poll_close', $poll_close);
67
  $update_poll_queries[] = update_option('poll_logging_method', $poll_logging_method);
@@ -318,15 +316,6 @@ if( isset($_POST['Submit']) && $_POST['Submit'] ) {
318
  <th scope="row" valign="top"><?php _e('Poll Archive URL:', 'wp-polls'); ?></th>
319
  <td><input type="text" name="poll_archive_url" value="<?php echo esc_url( get_option( 'poll_archive_url' ) ); ?>" size="50" dir="ltr" /></td>
320
  </tr>
321
- <tr>
322
- <th scope="row" valign="top"><?php _e('Display Poll Archive Link Below Poll?', 'wp-polls'); ?></th>
323
- <td>
324
- <select name="poll_archive_show" size="1">
325
- <option value="0"<?php selected('0', get_option('poll_archive_show')); ?>><?php _e('No', 'wp-polls'); ?></option>
326
- <option value="1"<?php selected('1', get_option('poll_archive_show')); ?>><?php _e('Yes', 'wp-polls'); ?></option>
327
- </select>
328
- </td>
329
- </tr>
330
  <tr>
331
  <th scope="row" valign="top"><?php _e('Note', 'wp-polls'); ?></th>
332
  <td><em><?php _e('Only polls\' results will be shown in the Poll Archive regardless of whether the poll is closed or opened.', 'wp-polls'); ?></em></td>
44
  $poll_archive_perpage = intval($_POST['poll_archive_perpage']);
45
  $poll_archive_displaypoll = intval($_POST['poll_archive_displaypoll']);
46
  $poll_archive_url = esc_url_raw( strip_tags( trim( $_POST['poll_archive_url'] ) ) );
 
47
  $poll_currentpoll = intval($_POST['poll_currentpoll']);
48
  $poll_close = intval($_POST['poll_close']);
49
  $poll_logging_method = intval($_POST['poll_logging_method']);
60
  $update_poll_queries[] = update_option('poll_archive_perpage', $poll_archive_perpage);
61
  $update_poll_queries[] = update_option('poll_archive_displaypoll', $poll_archive_displaypoll);
62
  $update_poll_queries[] = update_option('poll_archive_url', $poll_archive_url);
 
63
  $update_poll_queries[] = update_option('poll_currentpoll', $poll_currentpoll);
64
  $update_poll_queries[] = update_option('poll_close', $poll_close);
65
  $update_poll_queries[] = update_option('poll_logging_method', $poll_logging_method);
316
  <th scope="row" valign="top"><?php _e('Poll Archive URL:', 'wp-polls'); ?></th>
317
  <td><input type="text" name="poll_archive_url" value="<?php echo esc_url( get_option( 'poll_archive_url' ) ); ?>" size="50" dir="ltr" /></td>
318
  </tr>
 
 
 
 
 
 
 
 
 
319
  <tr>
320
  <th scope="row" valign="top"><?php _e('Note', 'wp-polls'); ?></th>
321
  <td><em><?php _e('Only polls\' results will be shown in the Poll Archive regardless of whether the poll is closed or opened.', 'wp-polls'); ?></em></td>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://lesterchan.net/site/donation/
4
  Tags: poll, polls, polling, vote, booth, democracy, ajax, survey, post, widget
5
  Requires at least: 3.9
6
  Tested up to: 4.4
7
- Stable tag: 2.71
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
 
@@ -27,6 +27,12 @@ WP-Polls is extremely customizable via templates and css styles and there are to
27
  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.
28
 
29
  == Changelog ==
 
 
 
 
 
 
30
  = Version 2.71 =
31
  * FIXED: Use wp_kses_post() to get filter always bad tags
32
 
4
  Tags: poll, polls, polling, vote, booth, democracy, ajax, survey, post, widget
5
  Requires at least: 3.9
6
  Tested up to: 4.4
7
+ Stable tag: 2.72
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
 
27
  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.
28
 
29
  == Changelog ==
30
+ = Version 2.72 =
31
+ * NEW: Use translate.wordpress.org to translate the plugin
32
+ * FIXED: SQL Injection fixes. Props [Jay Dansand](https://github.com/jaydansand)
33
+ * FIXED: Use $wpdb->insert(), $wpdb->update() and $wpdb->delete() as much as possible
34
+ * FIXED Remove poll_archive_show option from UI
35
+
36
  = Version 2.71 =
37
  * FIXED: Use wp_kses_post() to get filter always bad tags
38
 
wp-polls.php CHANGED
@@ -1,42 +1,42 @@
1
  <?php
2
  /*
3
  Plugin Name: WP-Polls
4
- Plugin URI: http://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.71
7
  Author: Lester 'GaMerZ' Chan
8
- Author URI: http://lesterchan.net
9
  Text Domain: wp-polls
10
  */
11
 
12
 
13
  /*
14
- Copyright 2015 Lester Chan (email : lesterchan@gmail.com)
15
 
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License as published by
18
- the Free Software Foundation; either version 2 of the License, or
19
- (at your option) any later version.
20
 
21
- This program is distributed in the hope that it will be useful,
22
- but WITHOUT ANY WARRANTY; without even the implied warranty of
23
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
- GNU General Public License for more details.
25
 
26
- You should have received a copy of the GNU General Public License
27
- along with this program; if not, write to the Free Software
28
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
  */
30
 
31
 
32
  ### Version
33
- define( 'WP_POLLS_VERSION', 2.70 );
34
 
35
 
36
  ### Create Text Domain For Translations
37
  add_action( 'plugins_loaded', 'polls_textdomain' );
38
  function polls_textdomain() {
39
- load_plugin_textdomain( 'wp-polls', false, dirname( plugin_basename( __FILE__ ) ) );
40
  }
41
 
42
 
@@ -50,193 +50,193 @@ $wpdb->pollsip = $wpdb->prefix.'pollsip';
50
  ### Function: Poll Administration Menu
51
  add_action( 'admin_menu', 'poll_menu' );
52
  function poll_menu() {
53
- add_menu_page( __( 'Polls', 'wp-polls' ), __( 'Polls', 'wp-polls' ), 'manage_polls', 'wp-polls/polls-manager.php', '', 'dashicons-chart-bar' );
54
 
55
- add_submenu_page( 'wp-polls/polls-manager.php', __( 'Manage Polls', 'wp-polls'), __( 'Manage Polls', 'wp-polls' ), 'manage_polls', 'wp-polls/polls-manager.php' );
56
- add_submenu_page( 'wp-polls/polls-manager.php', __( 'Add Poll', 'wp-polls'), __( 'Add Poll', 'wp-polls' ), 'manage_polls', 'wp-polls/polls-add.php' );
57
- add_submenu_page( 'wp-polls/polls-manager.php', __( 'Poll Options', 'wp-polls'), __( 'Poll Options', 'wp-polls' ), 'manage_polls', 'wp-polls/polls-options.php' );
58
- add_submenu_page( 'wp-polls/polls-manager.php', __( 'Poll Templates', 'wp-polls'), __( 'Poll Templates', 'wp-polls' ), 'manage_polls', 'wp-polls/polls-templates.php' );
59
  }
60
 
61
 
62
  ### Function: Get Poll
63
  function get_poll($temp_poll_id = 0, $display = true) {
64
- global $wpdb, $polls_loaded;
65
- // Poll Result Link
66
- if(isset($_GET['pollresult'])) {
67
- $pollresult_id = intval($_GET['pollresult']);
68
- } else {
69
- $pollresult_id = 0;
70
- }
71
- $temp_poll_id = intval($temp_poll_id);
72
- // Check Whether Poll Is Disabled
73
- if(intval(get_option('poll_currentpoll')) == -1) {
74
- if($display) {
75
- echo stripslashes(get_option('poll_template_disable'));
76
- return;
77
- } else {
78
- return stripslashes(get_option('poll_template_disable'));
79
- }
80
- // Poll Is Enabled
81
- } else {
82
- do_action('wp_polls_get_poll');
83
- // Hardcoded Poll ID Is Not Specified
84
- switch($temp_poll_id) {
85
- // Random Poll
86
- case -2:
87
- $poll_id = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq WHERE pollq_active = 1 ORDER BY RAND() LIMIT 1");
88
- break;
89
- // Latest Poll
90
- case 0:
91
- // Random Poll
92
- if(intval(get_option('poll_currentpoll')) == -2) {
93
- $random_poll_id = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq WHERE pollq_active = 1 ORDER BY RAND() LIMIT 1");
94
- $poll_id = intval($random_poll_id);
95
- if($pollresult_id > 0) {
96
- $poll_id = $pollresult_id;
97
- } elseif(intval($_POST['poll_id']) > 0) {
98
- $poll_id = intval($_POST['poll_id']);
99
- }
100
- // Current Poll ID Is Not Specified
101
- } elseif(intval(get_option('poll_currentpoll')) == 0) {
102
- // Get Lastest Poll ID
103
- $poll_id = intval(get_option('poll_latestpoll'));
104
- } else {
105
- // Get Current Poll ID
106
- $poll_id = intval(get_option('poll_currentpoll'));
107
- }
108
- break;
109
- // Take Poll ID From Arguments
110
- default:
111
- $poll_id = $temp_poll_id;
112
- }
113
- }
114
-
115
- // Assign All Loaded Poll To $polls_loaded
116
- if(empty($polls_loaded)) {
117
- $polls_loaded = array();
118
- }
119
- if(!in_array($poll_id, $polls_loaded)) {
120
- $polls_loaded[] = $poll_id;
121
- }
122
-
123
- // User Click on View Results Link
124
- if($pollresult_id == $poll_id) {
125
- if($display) {
126
- echo display_pollresult($poll_id);
127
- return;
128
- } else {
129
- return display_pollresult($poll_id);
130
- }
131
- // Check Whether User Has Voted
132
- } else {
133
- $poll_active = $wpdb->get_var("SELECT pollq_active FROM $wpdb->pollsq WHERE pollq_id = $poll_id");
134
- $poll_active = intval($poll_active);
135
- $check_voted = check_voted($poll_id);
136
- if($poll_active == 0) {
137
- $poll_close = intval(get_option('poll_close'));
138
- } else {
139
- $poll_close = 0;
140
- }
141
- if(intval($check_voted) > 0 || (is_array($check_voted) && sizeof($check_voted) > 0) || ($poll_active == 0 && $poll_close == 1)) {
142
- if($display) {
143
- echo display_pollresult($poll_id, $check_voted);
144
- return;
145
- } else {
146
- return display_pollresult($poll_id, $check_voted);
147
- }
148
- } elseif(!check_allowtovote() || ($poll_active == 0 && $poll_close == 3)) {
149
- $disable_poll_js = '<script type="text/javascript">jQuery("#polls_form_'.$poll_id.' :input").each(function (i){jQuery(this).attr("disabled","disabled")});</script>';
150
- if($display) {
151
- echo display_pollvote($poll_id).$disable_poll_js;
152
- return;
153
- } else {
154
- return display_pollvote($poll_id).$disable_poll_js;
155
- }
156
- } elseif($poll_active == 1) {
157
- if($display) {
158
- echo display_pollvote($poll_id);
159
- return;
160
- } else {
161
- return display_pollvote($poll_id);
162
- }
163
- }
164
- }
165
  }
166
 
167
 
168
  ### Function: Enqueue Polls JavaScripts/CSS
169
  add_action('wp_enqueue_scripts', 'poll_scripts');
170
  function poll_scripts() {
171
- if(@file_exists(get_stylesheet_directory().'/polls-css.css')) {
172
- wp_enqueue_style('wp-polls', get_stylesheet_directory_uri().'/polls-css.css', false, WP_POLLS_VERSION, 'all');
173
- } else {
174
- wp_enqueue_style('wp-polls', plugins_url('wp-polls/polls-css.css'), false, WP_POLLS_VERSION, 'all');
175
- }
176
- if( is_rtl() ) {
177
- if(@file_exists(get_stylesheet_directory().'/polls-css-rtl.css')) {
178
- wp_enqueue_style('wp-polls-rtl', get_stylesheet_directory_uri().'/polls-css-rtl.css', false, WP_POLLS_VERSION, 'all');
179
- } else {
180
- wp_enqueue_style('wp-polls-rtl', plugins_url('wp-polls/polls-css-rtl.css'), false, WP_POLLS_VERSION, 'all');
181
- }
182
- }
183
- $pollbar = get_option( 'poll_bar' );
184
- if( $pollbar['style'] === 'use_css' ) {
185
- $pollbar_css = '.wp-polls .pollbar {'."\n";
186
- $pollbar_css .= "\t".'margin: 1px;'."\n";
187
- $pollbar_css .= "\t".'font-size: '.($pollbar['height']-2).'px;'."\n";
188
- $pollbar_css .= "\t".'line-height: '.$pollbar['height'].'px;'."\n";
189
- $pollbar_css .= "\t".'height: '.$pollbar['height'].'px;'."\n";
190
- $pollbar_css .= "\t".'background: #'.$pollbar['background'].';'."\n";
191
- $pollbar_css .= "\t".'border: 1px solid #'.$pollbar['border'].';'."\n";
192
- $pollbar_css .= '}'."\n";
193
- } else {
194
- $pollbar_css = '.wp-polls .pollbar {'."\n";
195
- $pollbar_css .= "\t".'margin: 1px;'."\n";
196
- $pollbar_css .= "\t".'font-size: '.($pollbar['height']-2).'px;'."\n";
197
- $pollbar_css .= "\t".'line-height: '.$pollbar['height'].'px;'."\n";
198
- $pollbar_css .= "\t".'height: '.$pollbar['height'].'px;'."\n";
199
- $pollbar_css .= "\t".'background-image: url(\''.plugins_url('wp-polls/images/'.$pollbar['style'].'/pollbg.gif').'\');'."\n";
200
- $pollbar_css .= "\t".'border: 1px solid #'.$pollbar['border'].';'."\n";
201
- $pollbar_css .= '}'."\n";
202
- }
203
- wp_add_inline_style( 'wp-polls', $pollbar_css );
204
- $poll_ajax_style = get_option('poll_ajax_style');
205
- wp_enqueue_script('wp-polls', plugins_url('wp-polls/polls-js.js'), array('jquery'), WP_POLLS_VERSION, true);
206
- wp_localize_script('wp-polls', 'pollsL10n', array(
207
- 'ajax_url' => admin_url('admin-ajax.php'),
208
- 'text_wait' => __('Your last request is still being processed. Please wait a while ...', 'wp-polls'),
209
- 'text_valid' => __('Please choose a valid poll answer.', 'wp-polls'),
210
- 'text_multiple' => __('Maximum number of choices allowed: ', 'wp-polls'),
211
- 'show_loading' => intval($poll_ajax_style['loading']),
212
- 'show_fading' => intval($poll_ajax_style['fading'])
213
- ));
214
  }
215
 
216
 
217
  ### Function: Enqueue Polls Stylesheets/JavaScripts In WP-Admin
218
  add_action('admin_enqueue_scripts', 'poll_scripts_admin');
219
  function poll_scripts_admin($hook_suffix) {
220
- $poll_admin_pages = array('wp-polls/polls-manager.php', 'wp-polls/polls-add.php', 'wp-polls/polls-options.php', 'wp-polls/polls-templates.php', 'wp-polls/polls-uninstall.php');
221
- if(in_array($hook_suffix, $poll_admin_pages)) {
222
- wp_enqueue_style('wp-polls-admin', plugins_url('wp-polls/polls-admin-css.css'), false, WP_POLLS_VERSION, 'all');
223
- wp_enqueue_script('wp-polls-admin', plugins_url('wp-polls/polls-admin-js.js'), array('jquery'), WP_POLLS_VERSION, true);
224
- wp_localize_script('wp-polls-admin', 'pollsAdminL10n', array(
225
- 'admin_ajax_url' => admin_url('admin-ajax.php'),
226
- 'text_direction' => is_rtl() ? 'right' : 'left',
227
- 'text_delete_poll' => __('Delete Poll', 'wp-polls'),
228
- 'text_no_poll_logs' => __('No poll logs available.', 'wp-polls'),
229
- 'text_delete_all_logs' => __('Delete All Logs', 'wp-polls'),
230
- 'text_checkbox_delete_all_logs' => __('Please check the \\\'Yes\\\' checkbox if you want to delete all logs.', 'wp-polls'),
231
- 'text_delete_poll_logs' => __('Delete Logs For This Poll Only', 'wp-polls'),
232
- 'text_checkbox_delete_poll_logs' => __('Please check the \\\'Yes\\\' checkbox if you want to delete all logs for this poll ONLY.', 'wp-polls'),
233
- 'text_delete_poll_ans' => __('Delete Poll Answer', 'wp-polls'),
234
- 'text_open_poll' => __('Open Poll', 'wp-polls'),
235
- 'text_close_poll' => __('Close Poll', 'wp-polls'),
236
- 'text_answer' => __('Answer', 'wp-polls'),
237
- 'text_remove_poll_answer' => __('Remove', 'wp-polls')
238
- ));
239
- }
240
  }
241
 
242
 
@@ -247,163 +247,163 @@ add_action('admin_footer-page-new.php', 'poll_footer_admin');
247
  add_action('admin_footer-page.php', 'poll_footer_admin');
248
  function poll_footer_admin() {
249
  ?>
250
- <script type="text/javascript">
251
- QTags.addButton('ed_wp_polls', '<?php echo esc_js(__('Poll', 'wp-polls')); ?>', function() {
252
- var poll_id = jQuery.trim(prompt('<?php echo esc_js(__('Enter Poll ID', 'wp-polls')); ?>'));
253
- while(isNaN(poll_id)) {
254
- poll_id = jQuery.trim(prompt("<?php echo esc_js(__('Error: Poll ID must be numeric', 'wp-polls')); ?>\n\n<?php echo esc_js(__('Please enter Poll ID again', 'wp-polls')); ?>"));
255
- }
256
- if (poll_id >= -1 && poll_id != null && poll_id != "") {
257
- QTags.insertContent('[poll id="' + poll_id + '"]');
258
- }
259
- });
260
- </script>
261
  <?php
262
  }
263
 
264
  ### Function: Add Quick Tag For Poll In TinyMCE >= WordPress 2.5
265
  add_action('init', 'poll_tinymce_addbuttons');
266
  function poll_tinymce_addbuttons() {
267
- if(!current_user_can('edit_posts') && ! current_user_can('edit_pages')) {
268
- return;
269
- }
270
- if(get_user_option('rich_editing') == 'true') {
271
- add_filter('mce_external_plugins', 'poll_tinymce_addplugin');
272
- add_filter('mce_buttons', 'poll_tinymce_registerbutton');
273
- add_filter('wp_mce_translation', 'poll_tinymce_translation');
274
- }
275
  }
276
  function poll_tinymce_registerbutton($buttons) {
277
- array_push($buttons, 'separator', 'polls');
278
- return $buttons;
279
  }
280
  function poll_tinymce_addplugin($plugin_array) {
281
- if(WP_DEBUG) {
282
- $plugin_array['polls'] = plugins_url( 'wp-polls/tinymce/plugins/polls/plugin.js?v=' . WP_POLLS_VERSION );
283
- } else {
284
- $plugin_array['polls'] = plugins_url( 'wp-polls/tinymce/plugins/polls/plugin.min.js?v=' . WP_POLLS_VERSION );
285
- }
286
- return $plugin_array;
287
  }
288
  function poll_tinymce_translation($mce_translation) {
289
- $mce_translation['Enter Poll ID'] = esc_js(__('Enter Poll ID', 'wp-polls'));
290
- $mce_translation['Error: Poll ID must be numeric'] = esc_js(__('Error: Poll ID must be numeric', 'wp-polls'));
291
- $mce_translation['Please enter Poll ID again'] = esc_js(__('Please enter Poll ID again', 'wp-polls'));
292
- $mce_translation['Insert Poll'] = esc_js(__('Insert Poll', 'wp-polls'));
293
- return $mce_translation;
294
  }
295
 
296
 
297
  ### Function: Check Who Is Allow To Vote
298
  function check_allowtovote() {
299
- global $user_ID;
300
- $user_ID = intval($user_ID);
301
- $allow_to_vote = intval(get_option('poll_allowtovote'));
302
- switch($allow_to_vote) {
303
- // Guests Only
304
- case 0:
305
- if($user_ID > 0) {
306
- return false;
307
- }
308
- return true;
309
- break;
310
- // Registered Users Only
311
- case 1:
312
- if($user_ID == 0) {
313
- return false;
314
- }
315
- return true;
316
- break;
317
- // Registered Users And Guests
318
- case 2:
319
- default:
320
- return true;
321
- }
322
  }
323
 
324
 
325
  ### Funcrion: Check Voted By Cookie Or IP
326
  function check_voted($poll_id) {
327
- $poll_logging_method = intval(get_option('poll_logging_method'));
328
- switch($poll_logging_method) {
329
- // Do Not Log
330
- case 0:
331
- return 0;
332
- break;
333
- // Logged By Cookie
334
- case 1:
335
- return check_voted_cookie($poll_id);
336
- break;
337
- // Logged By IP
338
- case 2:
339
- return check_voted_ip($poll_id);
340
- break;
341
- // Logged By Cookie And IP
342
- case 3:
343
- $check_voted_cookie = check_voted_cookie($poll_id);
344
- if(!empty($check_voted_cookie)) {
345
- return $check_voted_cookie;
346
- } else {
347
- return check_voted_ip($poll_id);
348
- }
349
- break;
350
- // Logged By Username
351
- case 4:
352
- return check_voted_username($poll_id);
353
- break;
354
- }
355
  }
356
 
357
 
358
  ### Function: Check Voted By Cookie
359
  function check_voted_cookie($poll_id) {
360
- if(!empty($_COOKIE["voted_$poll_id"])) {
361
- $get_voted_aids = explode(',', $_COOKIE["voted_$poll_id"]);
362
- } else {
363
- $get_voted_aids = 0;
364
- }
365
- return $get_voted_aids;
366
  }
367
 
368
 
369
  ### Function: Check Voted By IP
370
- function check_voted_ip($poll_id) {
371
- global $wpdb;
372
- $log_expiry = intval(get_option('poll_cookielog_expiry'));
373
- $log_expiry_sql = '';
374
- if($log_expiry > 0) {
375
- $log_expiry_sql = 'AND ('.current_time('timestamp').'-(pollip_timestamp+0)) < '.$log_expiry;
376
- }
377
- // Check IP From IP Logging Database
378
- $get_voted_aids = $wpdb->get_col("SELECT pollip_aid FROM $wpdb->pollsip WHERE pollip_qid = $poll_id AND pollip_ip = '".get_ipaddress()."' $log_expiry_sql");
379
- if($get_voted_aids) {
380
- return $get_voted_aids;
381
- } else {
382
- return 0;
383
- }
384
  }
385
 
386
 
387
  ### Function: Check Voted By Username
388
  function check_voted_username($poll_id) {
389
- global $wpdb, $user_ID;
390
- // Check IP If User Is Guest
391
- if (!is_user_logged_in()) {
392
- return 1;
393
- }
394
- $pollsip_userid = intval($user_ID);
395
- $log_expiry = intval(get_option('poll_cookielog_expiry'));
396
- $log_expiry_sql = '';
397
- if($log_expiry > 0) {
398
- $log_expiry_sql = 'AND ('.current_time('timestamp').'-(pollip_timestamp+0)) < '.$log_expiry;
399
- }
400
- // Check User ID From IP Logging Database
401
- $get_voted_aids = $wpdb->get_col("SELECT pollip_aid FROM $wpdb->pollsip WHERE pollip_qid = $poll_id AND pollip_userid = $pollsip_userid $log_expiry_sql");
402
- if($get_voted_aids) {
403
- return $get_voted_aids;
404
- } else {
405
- return 0;
406
- }
407
  }
408
 
409
  add_filter('poll_template_voteheader_markup', 'poll_template_vote_markup', 10, 3);
@@ -412,867 +412,870 @@ 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
 
423
  ### Function: Display Voting Form
424
  function display_pollvote($poll_id, $display_loading = true) {
425
- do_action('wp_polls_display_pollvote');
426
- global $wpdb;
427
- // Temp Poll Result
428
- $temp_pollvote = '';
429
- // Get Poll Question Data
430
- $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes, pollq_timestamp, pollq_expiry, pollq_multiple, pollq_totalvoters FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
431
-
432
- // Poll Question Variables
433
- $poll_question_text = wp_kses_post( stripslashes( $poll_question->pollq_question ) );
434
- $poll_question_id = intval($poll_question->pollq_id);
435
- $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
436
- $poll_question_totalvoters = intval($poll_question->pollq_totalvoters);
437
- $poll_start_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_question->pollq_timestamp));
438
- $poll_expiry = trim($poll_question->pollq_expiry);
439
- if(empty($poll_expiry)) {
440
- $poll_end_date = __('No Expiry', 'wp-polls');
441
- } else {
442
- $poll_end_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_expiry));
443
- }
444
- $poll_multiple_ans = intval($poll_question->pollq_multiple);
445
-
446
- $template_question = stripslashes(get_option('poll_template_voteheader'));
447
-
448
- $template_question = apply_filters('poll_template_voteheader_markup', $template_question, $poll_question, array(
449
- '%POLL_QUESTION%' => $poll_question_text,
450
- '%POLL_ID%' => $poll_question_id,
451
- '%POLL_TOTALVOTES%' => $poll_question_totalvotes,
452
- '%POLL_TOTALVOTERS%' => $poll_question_totalvoters,
453
- '%POLL_START_DATE%' => $poll_start_date,
454
- '%POLL_END_DATE%' => $poll_end_date,
455
- '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
456
- ));
457
-
458
- // Get Poll Answers Data
459
- $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_qid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = $poll_question_id ORDER BY ".get_option('poll_ans_sortby').' '.get_option('poll_ans_sortorder'));
460
- // If There Is Poll Question With Answers
461
- if($poll_question && $poll_answers) {
462
- // Display Poll Voting Form
463
- $temp_pollvote .= "<div id=\"polls-$poll_question_id\" class=\"wp-polls\">\n";
464
- $temp_pollvote .= "\t<form id=\"polls_form_$poll_question_id\" class=\"wp-polls-form\" action=\"".esc_attr($_SERVER['SCRIPT_NAME'])."\" method=\"post\">\n";
465
- $temp_pollvote .= "\t\t<p style=\"display: none;\"><input type=\"hidden\" id=\"poll_{$poll_question_id}_nonce\" name=\"wp-polls-nonce\" value=\"".wp_create_nonce('poll_'.$poll_question_id.'-nonce')."\" /></p>\n";
466
- $temp_pollvote .= "\t\t<p style=\"display: none;\"><input type=\"hidden\" name=\"poll_id\" value=\"$poll_question_id\" /></p>\n";
467
- if($poll_multiple_ans > 0) {
468
- $temp_pollvote .= "\t\t<p style=\"display: none;\"><input type=\"hidden\" id=\"poll_multiple_ans_$poll_question_id\" name=\"poll_multiple_ans_$poll_question_id\" value=\"$poll_multiple_ans\" /></p>\n";
469
- }
470
- // Print Out Voting Form Header Template
471
- $temp_pollvote .= "\t\t$template_question\n";
472
- foreach($poll_answers as $poll_answer) {
473
- // Poll Answer Variables
474
- $poll_answer_id = intval($poll_answer->polla_aid);
475
- $poll_answer_text = wp_kses_post( stripslashes( $poll_answer->polla_answers ) );
476
- $poll_answer_votes = intval($poll_answer->polla_votes);
477
- $poll_answer_percentage = $poll_question_totalvoters > 0 ? round((($poll_answer_votes/$poll_question_totalvoters)*100)) : 0;
478
- $template_answer = stripslashes(get_option('poll_template_votebody'));
479
-
480
- $template_answer = apply_filters('poll_template_votebody_markup', $template_answer, $poll_answer, array(
481
- '%POLL_ID%' => $poll_question_id,
482
- '%POLL_ANSWER_ID%' => $poll_answer_id,
483
- '%POLL_ANSWER%' => $poll_answer_text,
484
- '%POLL_ANSWER_VOTES%' => number_format_i18n($poll_answer_votes),
485
- '%POLL_ANSWER_PERCENTAGE%' => $poll_answer_percentage,
486
- "%POLL_CHECKBOX_RADIO%" => $poll_multiple_ans > 0 ? 'checkbox' : 'radio'
487
- ));
488
-
489
- // Print Out Voting Form Body Template
490
- $temp_pollvote .= "\t\t$template_answer\n";
491
- }
492
- // Determine Poll Result URL
493
- $poll_result_url = $_SERVER['REQUEST_URI'];
494
- $poll_result_url = preg_replace('/pollresult=(\d+)/i', 'pollresult='.$poll_question_id, $poll_result_url);
495
- if(isset($_GET['pollresult']) && intval($_GET['pollresult']) == 0) {
496
- if(strpos($poll_result_url, '?') !== false) {
497
- $poll_result_url = "$poll_result_url&amp;pollresult=$poll_question_id";
498
- } else {
499
- $poll_result_url = "$poll_result_url?pollresult=$poll_question_id";
500
- }
501
- }
502
- // Voting Form Footer Variables
503
- $template_footer = stripslashes(get_option('poll_template_votefooter'));
504
-
505
- $template_footer = apply_filters('poll_template_votefooter_markup', $template_footer, $poll_question, array(
506
- '%POLL_ID%' => $poll_question_id,
507
- '%POLL_RESULT_URL%' => $poll_result_url,
508
- '%POLL_START_DATE%' => $poll_start_date,
509
- '%POLL_END_DATE%' => $poll_end_date,
510
- '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
511
- ));
512
-
513
- // Print Out Voting Form Footer Template
514
- $temp_pollvote .= "\t\t$template_footer\n";
515
- $temp_pollvote .= "\t</form>\n";
516
- $temp_pollvote .= "</div>\n";
517
- if($display_loading) {
518
- $poll_ajax_style = get_option('poll_ajax_style');
519
- if(intval($poll_ajax_style['loading']) == 1) {
520
- $temp_pollvote .= "<div id=\"polls-$poll_question_id-loading\" class=\"wp-polls-loading\"><img src=\"".plugins_url('wp-polls/images/loading.gif')."\" width=\"16\" height=\"16\" alt=\"".__('Loading', 'wp-polls')." ...\" title=\"".__('Loading', 'wp-polls')." ...\" class=\"wp-polls-image\" />&nbsp;".__('Loading', 'wp-polls')." ...</div>\n";
521
- }
522
- }
523
- } else {
524
- $temp_pollvote .= stripslashes(get_option('poll_template_disable'));
525
- }
526
- // Return Poll Vote Template
527
- return $temp_pollvote;
 
528
  }
529
 
530
 
531
  ### Function: Display Results Form
532
  function display_pollresult($poll_id, $user_voted = '', $display_loading = true) {
533
- do_action('wp_polls_display_pollresult');
534
- global $wpdb;
535
- $poll_id = intval($poll_id);
536
- // User Voted
537
- if(!is_array($user_voted)) {
538
- $user_voted = array();
539
- }
540
- // Temp Poll Result
541
- $temp_pollresult = '';
542
- // Most/Least Variables
543
- $poll_most_answer = '';
544
- $poll_most_votes = 0;
545
- $poll_most_percentage = 0;
546
- $poll_least_answer = '';
547
- $poll_least_votes = 0;
548
- $poll_least_percentage = 0;
549
- // Get Poll Question Data
550
- $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes, pollq_active, pollq_timestamp, pollq_expiry, pollq_multiple, pollq_totalvoters FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
551
- // No poll could be loaded from the database
552
- if (!$poll_question) {
553
- return stripslashes(get_option('poll_template_disable'));
554
- }
555
- // Poll Question Variables
556
- $poll_question_text = wp_kses_post( stripslashes( $poll_question->pollq_question ) );
557
- $poll_question_id = intval($poll_question->pollq_id);
558
- $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
559
- $poll_question_totalvoters = intval($poll_question->pollq_totalvoters);
560
- $poll_question_active = intval($poll_question->pollq_active);
561
- $poll_start_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_question->pollq_timestamp));
562
- $poll_expiry = trim($poll_question->pollq_expiry);
563
- if(empty($poll_expiry)) {
564
- $poll_end_date = __('No Expiry', 'wp-polls');
565
- } else {
566
- $poll_end_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_expiry));
567
- }
568
- $poll_multiple_ans = intval($poll_question->pollq_multiple);
569
- $template_question = stripslashes(get_option('poll_template_resultheader'));
570
- $template_question = str_replace("%POLL_QUESTION%", $poll_question_text, $template_question);
571
- $template_question = str_replace("%POLL_ID%", $poll_question_id, $template_question);
572
- $template_question = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_question);
573
- $template_question = str_replace("%POLL_TOTALVOTERS%", $poll_question_totalvoters, $template_question);
574
- $template_question = str_replace("%POLL_START_DATE%", $poll_start_date, $template_question);
575
- $template_question = str_replace("%POLL_END_DATE%", $poll_end_date, $template_question);
576
- if($poll_multiple_ans > 0) {
577
- $template_question = str_replace("%POLL_MULTIPLE_ANS_MAX%", $poll_multiple_ans, $template_question);
578
- } else {
579
- $template_question = str_replace("%POLL_MULTIPLE_ANS_MAX%", '1', $template_question);
580
- }
581
- // Get Poll Answers Data
582
- $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = $poll_question_id ORDER BY ".get_option('poll_ans_result_sortby').' '.get_option('poll_ans_result_sortorder'));
583
- // If There Is Poll Question With Answers
584
- if($poll_question && $poll_answers) {
585
- // Store The Percentage Of The Poll
586
- $poll_answer_percentage_array = array();
587
- // Is The Poll Total Votes 0?
588
- $poll_totalvotes_zero = true;
589
- if($poll_question_totalvotes > 0) {
590
- $poll_totalvotes_zero = false;
591
- }
592
- // Print Out Result Header Template
593
- $temp_pollresult .= "<div id=\"polls-$poll_question_id\" class=\"wp-polls\">\n";
594
- $temp_pollresult .= "\t\t$template_question\n";
595
- foreach($poll_answers as $poll_answer) {
596
- // Poll Answer Variables
597
- $poll_answer_id = intval($poll_answer->polla_aid);
598
- $poll_answer_text = wp_kses_post( stripslashes($poll_answer->polla_answers) );
599
- $poll_answer_votes = intval($poll_answer->polla_votes);
600
- // Calculate Percentage And Image Bar Width
601
- if(!$poll_totalvotes_zero) {
602
- if($poll_answer_votes > 0) {
603
- $poll_answer_percentage = round((($poll_answer_votes/$poll_question_totalvoters)*100));
604
- $poll_answer_imagewidth = round($poll_answer_percentage);
605
- if($poll_answer_imagewidth == 100) {
606
- $poll_answer_imagewidth = 99;
607
- }
608
- } else {
609
- $poll_answer_percentage = 0;
610
- $poll_answer_imagewidth = 1;
611
- }
612
- } else {
613
- $poll_answer_percentage = 0;
614
- $poll_answer_imagewidth = 1;
615
- }
616
- // Make Sure That Total Percentage Is 100% By Adding A Buffer To The Last Poll Answer
617
- $round_percentage = apply_filters( 'wp_polls_round_percentage', false );
618
- if( $round_percentage ) {
619
- if ( $poll_multiple_ans === 0 ) {
620
- $poll_answer_percentage_array[] = $poll_answer_percentage;
621
- if ( sizeof( $poll_answer_percentage_array ) === sizeof( $poll_answers ) ) {
622
- $percentage_error_buffer = 100 - array_sum( $poll_answer_percentage_array );
623
- $poll_answer_percentage = $poll_answer_percentage + $percentage_error_buffer;
624
- if ( $poll_answer_percentage < 0 ) {
625
- $poll_answer_percentage = 0;
626
- }
627
- }
628
- }
629
- }
630
-
631
- // Let User See What Options They Voted
632
- if(in_array($poll_answer_id, $user_voted)) {
633
- // Results Body Variables
634
- $template_answer = stripslashes(get_option('poll_template_resultbody2'));
635
- $template_answer = str_replace("%POLL_ID%", $poll_question_id, $template_answer);
636
- $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
637
- $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
638
- $template_answer = str_replace("%POLL_ANSWER_TEXT%", htmlspecialchars(strip_tags($poll_answer_text)), $template_answer);
639
- $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format_i18n($poll_answer_votes), $template_answer);
640
- $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
641
- $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
642
- // Print Out Results Body Template
643
- $temp_pollresult .= "\t\t$template_answer\n";
644
- } else {
645
- // Results Body Variables
646
- $template_answer = stripslashes(get_option('poll_template_resultbody'));
647
- $template_answer = str_replace("%POLL_ID%", $poll_question_id, $template_answer);
648
- $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
649
- $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
650
- $template_answer = str_replace("%POLL_ANSWER_TEXT%", htmlspecialchars(strip_tags($poll_answer_text)), $template_answer);
651
- $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format_i18n($poll_answer_votes), $template_answer);
652
- $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
653
- $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
654
- // Print Out Results Body Template
655
- $temp_pollresult .= "\t\t$template_answer\n";
656
- }
657
- // Get Most Voted Data
658
- if($poll_answer_votes > $poll_most_votes) {
659
- $poll_most_answer = $poll_answer_text;
660
- $poll_most_votes = $poll_answer_votes;
661
- $poll_most_percentage = $poll_answer_percentage;
662
- }
663
- // Get Least Voted Data
664
- if($poll_least_votes == 0) {
665
- $poll_least_votes = $poll_answer_votes;
666
- }
667
- if($poll_answer_votes <= $poll_least_votes) {
668
- $poll_least_answer = $poll_answer_text;
669
- $poll_least_votes = $poll_answer_votes;
670
- $poll_least_percentage = $poll_answer_percentage;
671
- }
672
- }
673
- // Results Footer Variables
674
- if(!empty($user_voted) || $poll_question_active == 0 || !check_allowtovote()) {
675
- $template_footer = stripslashes(get_option('poll_template_resultfooter'));
676
- } else {
677
- $template_footer = stripslashes(get_option('poll_template_resultfooter2'));
678
- }
679
- $template_footer = str_replace("%POLL_START_DATE%", $poll_start_date, $template_footer);
680
- $template_footer = str_replace("%POLL_END_DATE%", $poll_end_date, $template_footer);
681
- $template_footer = str_replace("%POLL_ID%", $poll_question_id, $template_footer);
682
- $template_footer = str_replace("%POLL_TOTALVOTES%", number_format_i18n($poll_question_totalvotes), $template_footer);
683
- $template_footer = str_replace("%POLL_TOTALVOTERS%", number_format_i18n($poll_question_totalvoters), $template_footer);
684
- $template_footer = str_replace("%POLL_MOST_ANSWER%", $poll_most_answer, $template_footer);
685
- $template_footer = str_replace("%POLL_MOST_VOTES%", number_format_i18n($poll_most_votes), $template_footer);
686
- $template_footer = str_replace("%POLL_MOST_PERCENTAGE%", $poll_most_percentage, $template_footer);
687
- $template_footer = str_replace("%POLL_LEAST_ANSWER%", $poll_least_answer, $template_footer);
688
- $template_footer = str_replace("%POLL_LEAST_VOTES%", number_format_i18n($poll_least_votes), $template_footer);
689
- $template_footer = str_replace("%POLL_LEAST_PERCENTAGE%", $poll_least_percentage, $template_footer);
690
- if($poll_multiple_ans > 0) {
691
- $template_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", $poll_multiple_ans, $template_footer);
692
- } else {
693
- $template_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", '1', $template_footer);
694
- }
695
- // Print Out Results Footer Template
696
- $temp_pollresult .= "\t\t$template_footer\n";
697
- $temp_pollresult .= "\t\t<input type=\"hidden\" id=\"poll_{$poll_question_id}_nonce\" name=\"wp-polls-nonce\" value=\"".wp_create_nonce('poll_'.$poll_question_id.'-nonce')."\" />\n";
698
- $temp_pollresult .= "</div>\n";
699
- if($display_loading) {
700
- $poll_ajax_style = get_option('poll_ajax_style');
701
- if(intval($poll_ajax_style['loading']) == 1) {
702
- $temp_pollresult .= "<div id=\"polls-$poll_question_id-loading\" class=\"wp-polls-loading\"><img src=\"".plugins_url('wp-polls/images/loading.gif')."\" width=\"16\" height=\"16\" alt=\"".__('Loading', 'wp-polls')." ...\" title=\"".__('Loading', 'wp-polls')." ...\" class=\"wp-polls-image\" />&nbsp;".__('Loading', 'wp-polls')." ...</div>\n";
703
- }
704
- }
705
- } else {
706
- $temp_pollresult .= stripslashes(get_option('poll_template_disable'));
707
- }
708
- // Return Poll Result
709
- return $temp_pollresult;
 
710
  }
711
 
712
 
713
  ### Function: Get IP Address
714
  if(!function_exists('get_ipaddress')) {
715
- function get_ipaddress() {
716
- foreach ( array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
717
- if ( array_key_exists( $key, $_SERVER ) === true ) {
718
- foreach ( explode( ',', $_SERVER[$key] ) as $ip ) {
719
- $ip = trim( $ip );
720
- if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
721
- return esc_attr( $ip );
722
- }
723
- }
724
- }
725
- }
726
- }
727
  }
728
 
729
 
730
  ### Function: Short Code For Inserting Polls Archive Into Page
731
  add_shortcode('page_polls', 'poll_page_shortcode');
732
  function poll_page_shortcode($atts) {
733
- return polls_archive();
734
  }
735
 
736
 
737
  ### Function: Short Code For Inserting Polls Into Posts
738
  add_shortcode( 'poll', 'poll_shortcode' );
739
  function poll_shortcode( $atts ) {
740
- $attributes = shortcode_atts( array( 'id' => 0, 'type' => 'vote' ), $atts );
741
- if( ! is_feed() ) {
742
- $id = intval( $attributes['id'] );
743
-
744
- // To maintain backward compatibility with [poll=1]. Props @tz-ua
745
- if( ! $id && isset( $atts[0] ) ) {
746
- $id = intval( trim( $atts[0], '="\'' ) );
747
- }
748
-
749
- if( $attributes['type'] === 'vote' ) {
750
- return get_poll( $id, false );
751
- } elseif( $attributes['type'] === 'result' ) {
752
- return display_pollresult( $id );
753
- }
754
- } else {
755
- return __( 'Note: There is a poll embedded within this post, please visit the site to participate in this post\'s poll.', 'wp-polls' );
756
- }
757
  }
758
 
759
 
760
  ### Function: Get Poll Question Based On Poll ID
761
  if(!function_exists('get_poll_question')) {
762
- function get_poll_question($poll_id) {
763
- global $wpdb;
764
- $poll_id = intval($poll_id);
765
- $poll_question = $wpdb->get_var("SELECT pollq_question FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
766
- return wp_kses_post( stripslashes( $poll_question ) );
767
- }
768
  }
769
 
770
 
771
  ### Function: Get Poll Total Questions
772
  if(!function_exists('get_pollquestions')) {
773
- function get_pollquestions($display = true) {
774
- global $wpdb;
775
- $totalpollq = intval($wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq"));
776
- if($display) {
777
- echo $totalpollq;
778
- } else {
779
- return $totalpollq;
780
- }
781
- }
782
  }
783
 
784
 
785
  ### Function: Get Poll Total Answers
786
  if(!function_exists('get_pollanswers')) {
787
- function get_pollanswers($display = true) {
788
- global $wpdb;
789
- $totalpolla = intval($wpdb->get_var("SELECT COUNT(polla_aid) FROM $wpdb->pollsa"));
790
- if($display) {
791
- echo $totalpolla;
792
- } else {
793
- return $totalpolla;
794
- }
795
- }
796
  }
797
 
798
 
799
  ### Function: Get Poll Total Votes
800
  if(!function_exists('get_pollvotes')) {
801
- function get_pollvotes($display = true) {
802
- global $wpdb;
803
- $totalvotes = intval($wpdb->get_var("SELECT SUM(pollq_totalvotes) FROM $wpdb->pollsq"));
804
- if($display) {
805
- echo $totalvotes;
806
- } else {
807
- return $totalvotes;
808
- }
809
- }
810
  }
811
 
812
 
813
  ### Function: Get Poll Total Voters
814
  if(!function_exists('get_pollvoters')) {
815
- function get_pollvoters($display = true) {
816
- global $wpdb;
817
- $totalvoters = intval($wpdb->get_var("SELECT SUM(pollq_totalvoters) FROM $wpdb->pollsq"));
818
- if($display) {
819
- echo $totalvoters;
820
- } else {
821
- return $totalvoters;
822
- }
823
- }
824
  }
825
 
826
 
827
  ### Function: Check Voted To Get Voted Answer
828
  function check_voted_multiple($poll_id, $polls_ips) {
829
- if(!empty($_COOKIE["voted_$poll_id"])) {
830
- return explode(',', $_COOKIE["voted_$poll_id"]);
831
- } else {
832
- if($polls_ips) {
833
- return $polls_ips;
834
- } else {
835
- return array();
836
- }
837
- }
838
  }
839
 
840
 
841
  ### Function: Polls Archive Link
842
  function polls_archive_link($page) {
843
- $polls_archive_url = get_option('poll_archive_url');
844
- if($page > 0) {
845
- if(strpos($polls_archive_url, '?') !== false) {
846
- $polls_archive_url = "$polls_archive_url&amp;poll_page=$page";
847
- } else {
848
- $polls_archive_url = "$polls_archive_url?poll_page=$page";
849
- }
850
- }
851
- return $polls_archive_url;
852
  }
853
 
854
 
855
  ### Function: Displays Polls Archive Link
856
  function display_polls_archive_link($display = true) {
857
- $template_pollarchivelink = stripslashes(get_option('poll_template_pollarchivelink'));
858
- $template_pollarchivelink = str_replace("%POLL_ARCHIVE_URL%", get_option('poll_archive_url'), $template_pollarchivelink);
859
- if($display) {
860
- echo $template_pollarchivelink;
861
- } else{
862
- return $template_pollarchivelink;
863
- }
864
  }
865
 
866
 
867
  ### Function: Display Polls Archive
868
  function polls_archive() {
869
- do_action('wp_polls_polls_archive');
870
- global $wpdb, $in_pollsarchive;
871
- // Polls Variables
872
- $in_pollsarchive = true;
873
- $page = isset($_GET['poll_page']) ? intval($_GET['poll_page']) : 0;
874
- $polls_questions = array();
875
- $polls_answers = array();
876
- $polls_ips = array();
877
- $polls_perpage = intval(get_option('poll_archive_perpage'));
878
- $poll_questions_ids = '0';
879
- $poll_voted = false;
880
- $poll_voted_aid = 0;
881
- $poll_id = 0;
882
- $pollsarchive_output_archive = '';
883
- $polls_type = intval(get_option('poll_archive_displaypoll'));
884
- $polls_type_sql = '';
885
- // Determine What Type Of Polls To Show
886
- switch($polls_type) {
887
- case 1:
888
- $polls_type_sql = 'pollq_active = 0';
889
- break;
890
- case 2:
891
- $polls_type_sql = 'pollq_active = 1';
892
- break;
893
- case 3:
894
- $polls_type_sql = 'pollq_active IN (0,1)';
895
- break;
896
- }
897
- // Get Total Polls
898
- $total_polls = $wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq WHERE $polls_type_sql AND pollq_active != -1");
899
-
900
- // Calculate Paging
901
- $numposts = $total_polls;
902
- $perpage = $polls_perpage;
903
- $max_page = ceil($numposts/$perpage);
904
- if(empty($page) || $page == 0) {
905
- $page = 1;
906
- }
907
- $offset = ($page-1) * $perpage;
908
- $pages_to_show = 10;
909
- $pages_to_show_minus_1 = $pages_to_show-1;
910
- $half_page_start = floor($pages_to_show_minus_1/2);
911
- $half_page_end = ceil($pages_to_show_minus_1/2);
912
- $start_page = $page - $half_page_start;
913
- if($start_page <= 0) {
914
- $start_page = 1;
915
- }
916
- $end_page = $page + $half_page_end;
917
- if(($end_page - $start_page) != $pages_to_show_minus_1) {
918
- $end_page = $start_page + $pages_to_show_minus_1;
919
- }
920
- if($end_page > $max_page) {
921
- $start_page = $max_page - $pages_to_show_minus_1;
922
- $end_page = $max_page;
923
- }
924
- if($start_page <= 0) {
925
- $start_page = 1;
926
- }
927
- if(($offset + $perpage) > $numposts) {
928
- $max_on_page = $numposts;
929
- } else {
930
- $max_on_page = ($offset + $perpage);
931
- }
932
- if (($offset + 1) > ($numposts)) {
933
- $display_on_page = $numposts;
934
- } else {
935
- $display_on_page = ($offset + 1);
936
- }
937
-
938
- // Get Poll Questions
939
- $questions = $wpdb->get_results("SELECT * FROM $wpdb->pollsq WHERE $polls_type_sql ORDER BY pollq_id DESC LIMIT $offset, $polls_perpage");
940
- if($questions) {
941
- foreach($questions as $question) {
942
- $polls_questions[] = array('id' => intval($question->pollq_id), 'question' => wp_kses_post( stripslashes( $question->pollq_question ) ), 'timestamp' => $question->pollq_timestamp, 'totalvotes' => intval($question->pollq_totalvotes), 'start' => $question->pollq_timestamp, 'end' => trim($question->pollq_expiry), 'multiple' => intval($question->pollq_multiple), 'totalvoters' => intval($question->pollq_totalvoters));
943
- $poll_questions_ids .= intval($question->pollq_id).', ';
944
- }
945
- $poll_questions_ids = substr($poll_questions_ids, 0, -2);
946
- }
947
-
948
- // Get Poll Answers
949
- $answers = $wpdb->get_results("SELECT polla_aid, polla_qid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid IN ($poll_questions_ids) ORDER BY ".get_option('poll_ans_result_sortby').' '.get_option('poll_ans_result_sortorder'));
950
- if($answers) {
951
- foreach($answers as $answer) {
952
- $polls_answers[intval($answer->polla_qid)][] = array('aid' => intval($answer->polla_aid), 'qid' => intval($answer->polla_qid), 'answers' => wp_kses_post( stripslashes( $answer->polla_answers ) ), 'votes' => intval($answer->polla_votes));
953
- }
954
- }
955
-
956
- // Get Poll IPs
957
- $ips = $wpdb->get_results("SELECT pollip_qid, pollip_aid FROM $wpdb->pollsip WHERE pollip_qid IN ($poll_questions_ids) AND pollip_ip = '".get_ipaddress()."' ORDER BY pollip_qid ASC");
958
- if($ips) {
959
- foreach($ips as $ip) {
960
- $polls_ips[intval($ip->pollip_qid)][] = intval($ip->pollip_aid);
961
- }
962
- }
963
- // Poll Archives
964
- $pollsarchive_output_archive .= "<div class=\"wp-polls wp-polls-archive\">\n";
965
- foreach($polls_questions as $polls_question) {
966
- // Most/Least Variables
967
- $poll_most_answer = '';
968
- $poll_most_votes = 0;
969
- $poll_most_percentage = 0;
970
- $poll_least_answer = '';
971
- $poll_least_votes = 0;
972
- $poll_least_percentage = 0;
973
- // Is The Poll Total Votes 0?
974
- $poll_totalvotes_zero = true;
975
- if($polls_question['totalvotes'] > 0) {
976
- $poll_totalvotes_zero = false;
977
- }
978
- $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']));
979
- if(empty($polls_question['end'])) {
980
- $poll_end_date = __('No Expiry', 'wp-polls');
981
- } else {
982
- $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']));
983
- }
984
- // Archive Poll Header
985
- $template_archive_header = stripslashes(get_option('poll_template_pollarchiveheader'));
986
- // Poll Question Variables
987
- $template_question = stripslashes(get_option('poll_template_resultheader'));
988
- $template_question = str_replace("%POLL_QUESTION%", $polls_question['question'], $template_question);
989
- $template_question = str_replace("%POLL_ID%", $polls_question['id'], $template_question);
990
- $template_question = str_replace("%POLL_TOTALVOTES%", number_format_i18n($polls_question['totalvotes']), $template_question);
991
- $template_question = str_replace("%POLL_TOTALVOTERS%", number_format_i18n($polls_question['totalvoters']), $template_question);
992
- $template_question = str_replace("%POLL_START_DATE%", $poll_start_date, $template_question);
993
- $template_question = str_replace("%POLL_END_DATE%", $poll_end_date, $template_question);
994
- if($polls_question['multiple'] > 0) {
995
- $template_question = str_replace("%POLL_MULTIPLE_ANS_MAX%", $polls_question['multiple'], $template_question);
996
- } else {
997
- $template_question = str_replace("%POLL_MULTIPLE_ANS_MAX%", '1', $template_question);
998
- }
999
- // Print Out Result Header Template
1000
- $pollsarchive_output_archive .= $template_archive_header;
1001
- $pollsarchive_output_archive .= $template_question;
1002
- // Store The Percentage Of The Poll
1003
- $poll_answer_percentage_array = array();
1004
- foreach($polls_answers[$polls_question['id']] as $polls_answer) {
1005
- // Calculate Percentage And Image Bar Width
1006
- if(!$poll_totalvotes_zero) {
1007
- if($polls_answer['votes'] > 0) {
1008
- $poll_answer_percentage = round((($polls_answer['votes']/$polls_question['totalvoters'])*100));
1009
- $poll_answer_imagewidth = round($poll_answer_percentage*0.9);
1010
- } else {
1011
- $poll_answer_percentage = 0;
1012
- $poll_answer_imagewidth = 1;
1013
- }
1014
- } else {
1015
- $poll_answer_percentage = 0;
1016
- $poll_answer_imagewidth = 1;
1017
- }
1018
- // Make Sure That Total Percentage Is 100% By Adding A Buffer To The Last Poll Answer
1019
- if($polls_question['multiple'] == 0) {
1020
- $poll_answer_percentage_array[] = $poll_answer_percentage;
1021
- if(sizeof($poll_answer_percentage_array) == sizeof($polls_answers[$polls_question['id']])) {
1022
- $percentage_error_buffer = 100 - array_sum($poll_answer_percentage_array);
1023
- $poll_answer_percentage = $poll_answer_percentage + $percentage_error_buffer;
1024
- if($poll_answer_percentage < 0) {
1025
- $poll_answer_percentage = 0;
1026
- }
1027
- }
1028
- }
1029
- $polls_answer['answers'] = wp_kses_post( $polls_answer['answers'] );
1030
- // Let User See What Options They Voted
1031
- if(isset($polls_ips[$polls_question['id']]) && in_array($polls_answer['aid'], check_voted_multiple($polls_question['id'], $polls_ips[$polls_question['id']]))) {
1032
- // Results Body Variables
1033
- $template_answer = stripslashes(get_option('poll_template_resultbody2'));
1034
- $template_answer = str_replace("%POLL_ID%", $polls_question['id'], $template_answer);
1035
- $template_answer = str_replace("%POLL_ANSWER_ID%", $polls_answer['aid'], $template_answer);
1036
- $template_answer = str_replace("%POLL_ANSWER%", $polls_answer['answers'], $template_answer);
1037
- $template_answer = str_replace("%POLL_ANSWER_TEXT%", htmlspecialchars(strip_tags($polls_answer['answers'])), $template_answer);
1038
- $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format_i18n($polls_answer['votes']), $template_answer);
1039
- $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
1040
- $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
1041
- // Print Out Results Body Template
1042
- $pollsarchive_output_archive .= $template_answer;
1043
- } else {
1044
- // Results Body Variables
1045
- $template_answer = stripslashes(get_option('poll_template_resultbody'));
1046
- $template_answer = str_replace("%POLL_ID%", $polls_question['id'], $template_answer);
1047
- $template_answer = str_replace("%POLL_ANSWER_ID%", $polls_answer['aid'], $template_answer);
1048
- $template_answer = str_replace("%POLL_ANSWER%", $polls_answer['answers'], $template_answer);
1049
- $template_answer = str_replace("%POLL_ANSWER_TEXT%", htmlspecialchars(strip_tags($polls_answer['answers'])), $template_answer);
1050
- $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format_i18n($polls_answer['votes']), $template_answer);
1051
- $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
1052
- $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
1053
- // Print Out Results Body Template
1054
- $pollsarchive_output_archive .= $template_answer;
1055
- }
1056
- // Get Most Voted Data
1057
- if($polls_answer['votes'] > $poll_most_votes) {
1058
- $poll_most_answer = $polls_answer['answers'];
1059
- $poll_most_votes = $polls_answer['votes'];
1060
- $poll_most_percentage = $poll_answer_percentage;
1061
- }
1062
- // Get Least Voted Data
1063
- if($poll_least_votes == 0) {
1064
- $poll_least_votes = $polls_answer['votes'];
1065
- }
1066
- if($polls_answer['votes'] <= $poll_least_votes) {
1067
- $poll_least_answer = $polls_answer['answers'];
1068
- $poll_least_votes = $polls_answer['votes'];
1069
- $poll_least_percentage = $poll_answer_percentage;
1070
- }
1071
- }
1072
- // Results Footer Variables
1073
- $template_footer = stripslashes(get_option('poll_template_resultfooter'));
1074
- $template_footer = str_replace("%POLL_ID%", $polls_question['id'], $template_footer);
1075
- $template_footer = str_replace("%POLL_START_DATE%", $poll_start_date, $template_footer);
1076
- $template_footer = str_replace("%POLL_END_DATE%", $poll_end_date, $template_footer);
1077
- $template_footer = str_replace("%POLL_TOTALVOTES%", number_format_i18n($polls_question['totalvotes']), $template_footer);
1078
- $template_footer = str_replace("%POLL_TOTALVOTERS%", number_format_i18n($polls_question['totalvoters']), $template_footer);
1079
- $template_footer = str_replace("%POLL_MOST_ANSWER%", $poll_most_answer, $template_footer);
1080
- $template_footer = str_replace("%POLL_MOST_VOTES%", number_format_i18n($poll_most_votes), $template_footer);
1081
- $template_footer = str_replace("%POLL_MOST_PERCENTAGE%", $poll_most_percentage, $template_footer);
1082
- $template_footer = str_replace("%POLL_LEAST_ANSWER%", $poll_least_answer, $template_footer);
1083
- $template_footer = str_replace("%POLL_LEAST_VOTES%", number_format_i18n($poll_least_votes), $template_footer);
1084
- $template_footer = str_replace("%POLL_LEAST_PERCENTAGE%", $poll_least_percentage, $template_footer);
1085
- if($polls_question['multiple'] > 0) {
1086
- $template_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", $polls_question['multiple'], $template_footer);
1087
- } else {
1088
- $template_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", '1', $template_footer);
1089
- }
1090
- // Archive Poll Footer
1091
- $template_archive_footer = stripslashes(get_option('poll_template_pollarchivefooter'));
1092
- $template_archive_footer = str_replace("%POLL_START_DATE%", $poll_start_date, $template_archive_footer);
1093
- $template_archive_footer = str_replace("%POLL_END_DATE%", $poll_end_date, $template_archive_footer);
1094
- $template_archive_footer = str_replace("%POLL_TOTALVOTES%", number_format_i18n($polls_question['totalvotes']), $template_archive_footer);
1095
- $template_archive_footer = str_replace("%POLL_TOTALVOTERS%", number_format_i18n($polls_question['totalvoters']), $template_archive_footer);
1096
- $template_archive_footer = str_replace("%POLL_MOST_ANSWER%", $poll_most_answer, $template_archive_footer);
1097
- $template_archive_footer = str_replace("%POLL_MOST_VOTES%", number_format_i18n($poll_most_votes), $template_archive_footer);
1098
- $template_archive_footer = str_replace("%POLL_MOST_PERCENTAGE%", $poll_most_percentage, $template_archive_footer);
1099
- $template_archive_footer = str_replace("%POLL_LEAST_ANSWER%", $poll_least_answer, $template_archive_footer);
1100
- $template_archive_footer = str_replace("%POLL_LEAST_VOTES%", number_format_i18n($poll_least_votes), $template_archive_footer);
1101
- $template_archive_footer = str_replace("%POLL_LEAST_PERCENTAGE%", $poll_least_percentage, $template_archive_footer);
1102
- if($polls_question['multiple'] > 0) {
1103
- $template_archive_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", $polls_question['multiple'], $template_archive_footer);
1104
- } else {
1105
- $template_archive_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", '1', $template_archive_footer);
1106
- }
1107
- // Print Out Results Footer Template
1108
- $pollsarchive_output_archive .= $template_footer;
1109
- // Print Out Archive Poll Footer Template
1110
- $pollsarchive_output_archive .= $template_archive_footer;
1111
- }
1112
- $pollsarchive_output_archive .= "</div>\n";
1113
-
1114
- // Polls Archive Paging
1115
- if($max_page > 1) {
1116
- $pollsarchive_output_archive .= stripslashes(get_option('poll_template_pollarchivepagingheader'));
1117
- if(function_exists('wp_pagenavi')) {
1118
- $pollsarchive_output_archive .= '<div class="wp-pagenavi">'."\n";
1119
- } else {
1120
- $pollsarchive_output_archive .= '<div class="wp-polls-paging">'."\n";
1121
- }
1122
- $pollsarchive_output_archive .= '<span class="pages">&#8201;'.sprintf(__('Page %s of %s', 'wp-polls'), number_format_i18n($page), number_format_i18n($max_page)).'&#8201;</span>';
1123
- if ($start_page >= 2 && $pages_to_show < $max_page) {
1124
- $pollsarchive_output_archive .= '<a href="'.polls_archive_link(1).'" title="'.__('&laquo; First', 'wp-polls').'">&#8201;'.__('&laquo; First', 'wp-polls').'&#8201;</a>';
1125
- $pollsarchive_output_archive .= '<span class="extend">...</span>';
1126
- }
1127
- if($page > 1) {
1128
- $pollsarchive_output_archive .= '<a href="'.polls_archive_link(($page-1)).'" title="'.__('&laquo;', 'wp-polls').'">&#8201;'.__('&laquo;', 'wp-polls').'&#8201;</a>';
1129
- }
1130
- for($i = $start_page; $i <= $end_page; $i++) {
1131
- if($i == $page) {
1132
- $pollsarchive_output_archive .= '<span class="current">&#8201;'.number_format_i18n($i).'&#8201;</span>';
1133
- } else {
1134
- $pollsarchive_output_archive .= '<a href="'.polls_archive_link($i).'" title="'.number_format_i18n($i).'">&#8201;'.number_format_i18n($i).'&#8201;</a>';
1135
- }
1136
- }
1137
- if(empty($page) || ($page+1) <= $max_page) {
1138
- $pollsarchive_output_archive .= '<a href="'.polls_archive_link(($page+1)).'" title="'.__('&raquo;', 'wp-polls').'">&#8201;'.__('&raquo;', 'wp-polls').'&#8201;</a>';
1139
- }
1140
- if ($end_page < $max_page) {
1141
- $pollsarchive_output_archive .= '<span class="extend">...</span>';
1142
- $pollsarchive_output_archive .= '<a href="'.polls_archive_link($max_page).'" title="'.__('Last &raquo;', 'wp-polls').'">&#8201;'.__('Last &raquo;', 'wp-polls').'&#8201;</a>';
1143
- }
1144
- $pollsarchive_output_archive .= '</div>';
1145
- $pollsarchive_output_archive .= stripslashes(get_option('poll_template_pollarchivepagingfooter'));
1146
- }
1147
-
1148
- // Output Polls Archive Page
1149
- return apply_filters('polls_archive', $pollsarchive_output_archive);
 
1150
  }
1151
 
1152
 
1153
  // Edit Timestamp Options
1154
  function poll_timestamp($poll_timestamp, $fieldname = 'pollq_timestamp', $display = 'block') {
1155
- global $month;
1156
- echo '<div id="'.$fieldname.'" style="display: '.$display.'">'."\n";
1157
- $day = gmdate('j', $poll_timestamp);
1158
- echo '<select name="'.$fieldname.'_day" size="1">'."\n";
1159
- for($i = 1; $i <=31; $i++) {
1160
- if($day == $i) {
1161
- echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
1162
- } else {
1163
- echo "<option value=\"$i\">$i</option>\n";
1164
- }
1165
- }
1166
- echo '</select>&nbsp;&nbsp;'."\n";
1167
- $month2 = gmdate('n', $poll_timestamp);
1168
- echo '<select name="'.$fieldname.'_month" size="1">'."\n";
1169
- for($i = 1; $i <= 12; $i++) {
1170
- if ($i < 10) {
1171
- $ii = '0'.$i;
1172
- } else {
1173
- $ii = $i;
1174
- }
1175
- if($month2 == $i) {
1176
- echo "<option value=\"$i\" selected=\"selected\">$month[$ii]</option>\n";
1177
- } else {
1178
- echo "<option value=\"$i\">$month[$ii]</option>\n";
1179
- }
1180
- }
1181
- echo '</select>&nbsp;&nbsp;'."\n";
1182
- $year = gmdate('Y', $poll_timestamp);
1183
- echo '<select name="'.$fieldname.'_year" size="1">'."\n";
1184
- for($i = 2000; $i <= ($year+10); $i++) {
1185
- if($year == $i) {
1186
- echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
1187
- } else {
1188
- echo "<option value=\"$i\">$i</option>\n";
1189
- }
1190
- }
1191
- echo '</select>&nbsp;@'."\n";
1192
- echo '<span dir="ltr">'."\n";
1193
- $hour = gmdate('H', $poll_timestamp);
1194
- echo '<select name="'.$fieldname.'_hour" size="1">'."\n";
1195
- for($i = 0; $i < 24; $i++) {
1196
- if($hour == $i) {
1197
- echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
1198
- } else {
1199
- echo "<option value=\"$i\">$i</option>\n";
1200
- }
1201
- }
1202
- echo '</select>&nbsp;:'."\n";
1203
- $minute = gmdate('i', $poll_timestamp);
1204
- echo '<select name="'.$fieldname.'_minute" size="1">'."\n";
1205
- for($i = 0; $i < 60; $i++) {
1206
- if($minute == $i) {
1207
- echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
1208
- } else {
1209
- echo "<option value=\"$i\">$i</option>\n";
1210
- }
1211
- }
1212
-
1213
- echo '</select>&nbsp;:'."\n";
1214
- $second = gmdate('s', $poll_timestamp);
1215
- echo '<select name="'.$fieldname.'_second" size="1">'."\n";
1216
- for($i = 0; $i <= 60; $i++) {
1217
- if($second == $i) {
1218
- echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
1219
- } else {
1220
- echo "<option value=\"$i\">$i</option>\n";
1221
- }
1222
- }
1223
- echo '</select>'."\n";
1224
- echo '</span>'."\n";
1225
- echo '</div>'."\n";
1226
  }
1227
 
1228
 
1229
  ### Function: Place Cron
1230
  function cron_polls_place() {
1231
- wp_clear_scheduled_hook('polls_cron');
1232
- if (!wp_next_scheduled('polls_cron')) {
1233
- wp_schedule_event(time(), 'twicedaily', 'polls_cron');
1234
- }
1235
  }
1236
 
1237
 
1238
  ### Funcion: Check All Polls Status To Check If It Expires
1239
  add_action('polls_cron', 'cron_polls_status');
1240
  function cron_polls_status() {
1241
- global $wpdb;
1242
- // Close Poll
1243
- $close_polls = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_active = 0 WHERE pollq_expiry < '".current_time('timestamp')."' AND pollq_expiry != '' AND pollq_active != 0");
1244
- // Open Future Polls
1245
- $active_polls = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_active = 1 WHERE pollq_timestamp <= '".current_time('timestamp')."' AND pollq_active = -1");
1246
- // Update Latest Poll If Future Poll Is Opened
1247
- if($active_polls) {
1248
- $update_latestpoll = update_option('poll_latestpoll', polls_latest_id());
1249
- }
1250
- return;
1251
  }
1252
 
1253
 
1254
  ### Funcion: Get Latest Poll ID
1255
  function polls_latest_id() {
1256
- global $wpdb;
1257
- $poll_id = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq WHERE pollq_active = 1 ORDER BY pollq_timestamp DESC LIMIT 1");
1258
- return intval($poll_id);
1259
  }
1260
 
1261
 
1262
  ### Check If In Poll Archive Page
1263
  function in_pollarchive() {
1264
- $poll_archive_url = get_option('poll_archive_url');
1265
- $poll_archive_url_array = explode('/', $poll_archive_url);
1266
- $poll_archive_url = $poll_archive_url_array[sizeof($poll_archive_url_array)-1];
1267
- if(empty($poll_archive_url)) {
1268
- $poll_archive_url = $poll_archive_url_array[sizeof($poll_archive_url_array)-2];
1269
- }
1270
- $current_url = $_SERVER['REQUEST_URI'];
1271
- if(strpos($current_url, $poll_archive_url) === false) {
1272
- return false;
1273
- } else {
1274
- return true;
1275
- }
1276
  }
1277
 
1278
 
@@ -1280,527 +1283,600 @@ function in_pollarchive() {
1280
  add_action('wp_ajax_polls', 'vote_poll');
1281
  add_action('wp_ajax_nopriv_polls', 'vote_poll');
1282
  function vote_poll() {
1283
- global $wpdb, $user_identity, $user_ID;
1284
-
1285
- if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'polls')
1286
- {
1287
- // Load Headers
1288
- polls_textdomain();
1289
- header('Content-Type: text/html; charset='.get_option('blog_charset').'');
1290
-
1291
- // Get Poll ID
1292
- $poll_id = (isset($_REQUEST['poll_id']) ? intval($_REQUEST['poll_id']) : 0);
1293
-
1294
- // Ensure Poll ID Is Valid
1295
- if($poll_id == 0)
1296
- {
1297
- _e('Invalid Poll ID', 'wp-polls');
1298
- exit();
1299
- }
1300
-
1301
- // Verify Referer
1302
- if(!check_ajax_referer('poll_'.$poll_id.'-nonce', 'poll_'.$poll_id.'_nonce', false))
1303
- {
1304
- _e('Failed To Verify Referrer', 'wp-polls');
1305
- exit();
1306
- }
1307
-
1308
- // Which View
1309
- switch($_REQUEST['view'])
1310
- {
1311
- // Poll Vote
1312
- case 'process':
1313
- do_action('wp_polls_vote_poll');
1314
- $poll_aid = $_POST["poll_$poll_id"];
1315
- $poll_aid_array = array_unique(array_map('intval', explode(',', $poll_aid)));
1316
- if($poll_id > 0 && !empty($poll_aid_array) && check_allowtovote()) {
1317
- $is_poll_open = intval( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->pollsq WHERE pollq_id = %d AND pollq_active = 1", $poll_id ) ) );
1318
- if ( $is_poll_open > 0 ) {
1319
- $check_voted = check_voted($poll_id);
1320
- if ($check_voted == 0) {
1321
- if (!empty($user_identity)) {
1322
- $pollip_user = htmlspecialchars(addslashes($user_identity));
1323
- } elseif (!empty($_COOKIE['comment_author_' . COOKIEHASH])) {
1324
- $pollip_user = htmlspecialchars(addslashes($_COOKIE['comment_author_' . COOKIEHASH]));
1325
- } else {
1326
- $pollip_user = __('Guest', 'wp-polls');
1327
- }
1328
- $pollip_userid = intval($user_ID);
1329
- $pollip_ip = get_ipaddress();
1330
- $pollip_host = esc_attr(@gethostbyaddr($pollip_ip));
1331
- $pollip_timestamp = current_time('timestamp');
1332
- // Only Create Cookie If User Choose Logging Method 1 Or 2
1333
- $poll_logging_method = intval(get_option('poll_logging_method'));
1334
- if ($poll_logging_method == 1 || $poll_logging_method == 3) {
1335
- $cookie_expiry = intval(get_option('poll_cookielog_expiry'));
1336
- if ($cookie_expiry == 0) {
1337
- $cookie_expiry = 30000000;
1338
- }
1339
- $vote_cookie = setcookie('voted_' . $poll_id, $poll_aid, ($pollip_timestamp + $cookie_expiry), apply_filters('wp_polls_cookiepath', SITECOOKIEPATH));
1340
- }
1341
- $i = 0;
1342
- foreach ($poll_aid_array as $polla_aid) {
1343
- $update_polla_votes = $wpdb->query("UPDATE $wpdb->pollsa SET polla_votes = (polla_votes+1) WHERE polla_qid = $poll_id AND polla_aid = $polla_aid");
1344
- if (!$update_polla_votes) {
1345
- unset($poll_aid_array[$i]);
1346
- }
1347
- $i++;
1348
- }
1349
- $vote_q = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes+" . sizeof($poll_aid_array) . "), pollq_totalvoters = (pollq_totalvoters+1) WHERE pollq_id = $poll_id AND pollq_active = 1");
1350
- if ($vote_q) {
1351
- foreach ($poll_aid_array as $polla_aid) {
1352
- $wpdb->query("INSERT INTO $wpdb->pollsip VALUES (0, $poll_id, $polla_aid, '$pollip_ip', '$pollip_host', '$pollip_timestamp', '$pollip_user', $pollip_userid)");
1353
- }
1354
- echo display_pollresult($poll_id, $poll_aid_array, false);
1355
- do_action( 'wp_polls_vote_poll_success' );
1356
- } else {
1357
- printf(__('Unable To Update Poll Total Votes And Poll Total Voters. Poll ID #%s', 'wp-polls'), $poll_id);
1358
- } // End if($vote_a)
1359
- } else {
1360
- printf(__('You Had Already Voted For This Poll. Poll ID #%s', 'wp-polls'), $poll_id);
1361
- } // End if($check_voted)
1362
- } else {
1363
- printf( __( 'Poll ID #%s is closed', 'wp-polls' ), $poll_id );
1364
- } // End if($is_poll_open > 0)
1365
- } else {
1366
- printf(__('Invalid Poll ID. Poll ID #%s', 'wp-polls'), $poll_id);
1367
- } // End if($poll_id > 0 && !empty($poll_aid_array) && check_allowtovote())
1368
- break;
1369
- // Poll Result
1370
- case 'result':
1371
- echo display_pollresult($poll_id, 0, false);
1372
- break;
1373
- // Poll Booth Aka Poll Voting Form
1374
- case 'booth':
1375
- echo display_pollvote($poll_id, false);
1376
- break;
1377
- } // End switch($_REQUEST['view'])
1378
- } // End if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'polls')
1379
- exit();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1380
  }
1381
 
1382
 
1383
  ### Function: Manage Polls
1384
  add_action('wp_ajax_polls-admin', 'manage_poll');
1385
  function manage_poll() {
1386
- global $wpdb;
1387
- ### Form Processing
1388
- if(isset($_POST['action']) && $_POST['action'] == 'polls-admin')
1389
- {
1390
- if(!empty($_POST['do'])) {
1391
- // Set Header
1392
- header('Content-Type: text/html; charset='.get_option('blog_charset').'');
1393
-
1394
- // Decide What To Do
1395
- switch($_POST['do']) {
1396
- // Delete Polls Logs
1397
- case __('Delete All Logs', 'wp-polls'):
1398
- check_ajax_referer('wp-polls_delete-polls-logs');
1399
- if(trim($_POST['delete_logs_yes']) == 'yes') {
1400
- $delete_logs = $wpdb->query("DELETE FROM $wpdb->pollsip");
1401
- if($delete_logs) {
1402
- echo '<p style="color: green;">'.__('All Polls Logs Have Been Deleted.', 'wp-polls').'</p>';
1403
- } else {
1404
- echo '<p style="color: red;">'.__('An Error Has Occurred While Deleting All Polls Logs.', 'wp-polls').'</p>';
1405
- }
1406
- }
1407
- break;
1408
- // Delete Poll Logs For Individual Poll
1409
- case __('Delete Logs For This Poll Only', 'wp-polls'):
1410
- check_ajax_referer('wp-polls_delete-poll-logs');
1411
- $pollq_id = intval($_POST['pollq_id']);
1412
- $pollq_question = $wpdb->get_var("SELECT pollq_question FROM $wpdb->pollsq WHERE pollq_id = $pollq_id");
1413
- if(trim($_POST['delete_logs_yes']) == 'yes') {
1414
- $delete_logs = $wpdb->query("DELETE FROM $wpdb->pollsip WHERE pollip_qid = $pollq_id");
1415
- if($delete_logs) {
1416
- echo '<p style="color: green;">'.sprintf(__('All Logs For \'%s\' Has Been Deleted.', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1417
- } else {
1418
- echo '<p style="color: red;">'.sprintf(__('An Error Has Occurred While Deleting All Logs For \'%s\'', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1419
- }
1420
- }
1421
- break;
1422
- // Delete Poll's Answer
1423
- case __('Delete Poll Answer', 'wp-polls'):
1424
- check_ajax_referer('wp-polls_delete-poll-answer');
1425
- $pollq_id = intval($_POST['pollq_id']);
1426
- $polla_aid = intval($_POST['polla_aid']);
1427
- $poll_answers = $wpdb->get_row("SELECT polla_votes, polla_answers FROM $wpdb->pollsa WHERE polla_aid = $polla_aid AND polla_qid = $pollq_id");
1428
- $polla_votes = intval($poll_answers->polla_votes);
1429
- $polla_answers = wp_kses_post( stripslashes( trim( $poll_answers->polla_answers ) ) );
1430
- $delete_polla_answers = $wpdb->query("DELETE FROM $wpdb->pollsa WHERE polla_aid = $polla_aid AND polla_qid = $pollq_id");
1431
- $delete_pollip = $wpdb->query("DELETE FROM $wpdb->pollsip WHERE pollip_qid = $pollq_id AND pollip_aid = $polla_aid");
1432
- $update_pollq_totalvotes = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes-$polla_votes) WHERE pollq_id = $pollq_id");
1433
- if($delete_polla_answers) {
1434
- echo '<p style="color: green;">'.sprintf(__('Poll Answer \'%s\' Deleted Successfully.', 'wp-polls'), $polla_answers).'</p>';
1435
- } else {
1436
- echo '<p style="color: red;">'.sprintf(__('Error In Deleting Poll Answer \'%s\'.', 'wp-polls'), $polla_answers).'</p>';
1437
- }
1438
- break;
1439
- // Open Poll
1440
- case __('Open Poll', 'wp-polls'):
1441
- check_ajax_referer('wp-polls_open-poll');
1442
- $pollq_id = intval($_POST['pollq_id']);
1443
- $pollq_question = $wpdb->get_var("SELECT pollq_question FROM $wpdb->pollsq WHERE pollq_id = $pollq_id");
1444
- $open_poll = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_active = 1 WHERE pollq_id = $pollq_id;");
1445
- if($open_poll) {
1446
- echo '<p style="color: green;">'.sprintf(__('Poll \'%s\' Is Now Opened', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1447
- } else {
1448
- echo '<p style="color: red;">'.sprintf(__('Error Opening Poll \'%s\'', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1449
- }
1450
- break;
1451
- // Close Poll
1452
- case __('Close Poll', 'wp-polls'):
1453
- check_ajax_referer('wp-polls_close-poll');
1454
- $pollq_id = intval($_POST['pollq_id']);
1455
- $pollq_question = $wpdb->get_var("SELECT pollq_question FROM $wpdb->pollsq WHERE pollq_id = $pollq_id");
1456
- $close_poll = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_active = 0 WHERE pollq_id = $pollq_id;");
1457
- if($close_poll) {
1458
- echo '<p style="color: green;">'.sprintf(__('Poll \'%s\' Is Now Closed', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1459
- } else {
1460
- echo '<p style="color: red;">'.sprintf(__('Error Closing Poll \'%s\'', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1461
- }
1462
- break;
1463
- // Delete Poll
1464
- case __('Delete Poll', 'wp-polls'):
1465
- check_ajax_referer('wp-polls_delete-poll');
1466
- $pollq_id = intval($_POST['pollq_id']);
1467
- $pollq_question = $wpdb->get_var("SELECT pollq_question FROM $wpdb->pollsq WHERE pollq_id = $pollq_id");
1468
- $delete_poll_question = $wpdb->query("DELETE FROM $wpdb->pollsq WHERE pollq_id = $pollq_id");
1469
- $delete_poll_answers = $wpdb->query("DELETE FROM $wpdb->pollsa WHERE polla_qid = $pollq_id");
1470
- $delete_poll_ip = $wpdb->query("DELETE FROM $wpdb->pollsip WHERE pollip_qid = $pollq_id");
1471
- $poll_option_lastestpoll = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'poll_latestpoll'");
1472
- if(!$delete_poll_question) {
1473
- echo '<p style="color: red;">'.sprintf(__('Error In Deleting Poll \'%s\' Question', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1474
- }
1475
- if(empty($text)) {
1476
- echo '<p style="color: green;">'.sprintf(__('Poll \'%s\' Deleted Successfully', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1477
- }
1478
- // Update Lastest Poll ID To Poll Options
1479
- $latest_pollid = polls_latest_id();
1480
- $update_latestpoll = update_option('poll_latestpoll', $latest_pollid);
1481
- do_action( 'wp_polls_delete_poll', $pollq_id );
1482
- break;
1483
- }
1484
- exit();
1485
- }
1486
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1487
  }
1488
 
1489
 
1490
  ### Function: Plug Into WP-Stats
1491
  add_action( 'plugins_loaded','polls_wp_stats' );
1492
  function polls_wp_stats() {
1493
- add_filter( 'wp_stats_page_admin_plugins', 'polls_page_admin_general_stats' );
1494
- add_filter( 'wp_stats_page_plugins', 'polls_page_general_stats' );
1495
  }
1496
 
1497
 
1498
  ### Function: Add WP-Polls General Stats To WP-Stats Page Options
1499
  function polls_page_admin_general_stats($content) {
1500
- $stats_display = get_option('stats_display');
1501
- if($stats_display['polls'] == 1) {
1502
- $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_polls" value="polls" checked="checked" />&nbsp;&nbsp;<label for="wpstats_polls">'.__('WP-Polls', 'wp-polls').'</label><br />'."\n";
1503
- } else {
1504
- $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_polls" value="polls" />&nbsp;&nbsp;<label for="wpstats_polls">'.__('WP-Polls', 'wp-polls').'</label><br />'."\n";
1505
- }
1506
- return $content;
1507
  }
1508
 
1509
 
1510
  ### Function: Add WP-Polls General Stats To WP-Stats Page
1511
  function polls_page_general_stats($content) {
1512
- $stats_display = get_option('stats_display');
1513
- if($stats_display['polls'] == 1) {
1514
- $content .= '<p><strong>'.__('WP-Polls', 'wp-polls').'</strong></p>'."\n";
1515
- $content .= '<ul>'."\n";
1516
- $content .= '<li>'.sprintf(_n('<strong>%s</strong> poll was created.', '<strong>%s</strong> polls were created.', get_pollquestions(false), 'wp-polls'), number_format_i18n(get_pollquestions(false))).'</li>'."\n";
1517
- $content .= '<li>'.sprintf(_n('<strong>%s</strong> polls\' answer was given.', '<strong>%s</strong> polls\' answers were given.', get_pollanswers(false), 'wp-polls'), number_format_i18n(get_pollanswers(false))).'</li>'."\n";
1518
- $content .= '<li>'.sprintf(_n('<strong>%s</strong> vote was cast.', '<strong>%s</strong> votes were cast.', get_pollvotes(false), 'wp-polls'), number_format_i18n(get_pollvotes(false))).'</li>'."\n";
1519
- $content .= '</ul>'."\n";
1520
- }
1521
- return $content;
1522
  }
1523
 
1524
 
1525
  ### Class: WP-Polls Widget
1526
  class WP_Widget_Polls extends WP_Widget {
1527
- // Constructor
1528
- function __construct() {
1529
- $widget_ops = array('description' => __('WP-Polls polls', 'wp-polls'));
1530
- parent::__construct('polls-widget', __('Polls', 'wp-polls'), $widget_ops);
1531
- }
1532
-
1533
- // Display Widget
1534
- function widget($args, $instance) {
1535
- extract($args);
1536
- $title = apply_filters('widget_title', esc_attr($instance['title']));
1537
- $poll_id = intval($instance['poll_id']);
1538
- $display_pollarchive = intval($instance['display_pollarchive']);
1539
- echo $before_widget;
1540
- if(!empty($title)) {
1541
- echo $before_title.$title.$after_title;
1542
- }
1543
- get_poll($poll_id);
1544
- if($display_pollarchive) {
1545
- display_polls_archive_link();
1546
- }
1547
- echo $after_widget;
1548
- }
1549
-
1550
- // When Widget Control Form Is Posted
1551
- function update($new_instance, $old_instance) {
1552
- if (!isset($new_instance['submit'])) {
1553
- return false;
1554
- }
1555
- $instance = $old_instance;
1556
- $instance['title'] = strip_tags($new_instance['title']);
1557
- $instance['poll_id'] = intval($new_instance['poll_id']);
1558
- $instance['display_pollarchive'] = intval($new_instance['display_pollarchive']);
1559
- return $instance;
1560
- }
1561
-
1562
- // DIsplay Widget Control Form
1563
- function form($instance) {
1564
- global $wpdb;
1565
- $instance = wp_parse_args((array) $instance, array('title' => __('Polls', 'wp-polls'), 'poll_id' => 0, 'display_pollarchive' => 1));
1566
- $title = esc_attr($instance['title']);
1567
- $poll_id = intval($instance['poll_id']);
1568
- $display_pollarchive = intval($instance['display_pollarchive']);
1569
  ?>
1570
- <p>
1571
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'wp-polls'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label>
1572
- </p>
1573
- <p>
1574
- <label for="<?php echo $this->get_field_id('display_pollarchive'); ?>"><?php _e('Display Polls Archive Link Below Poll?', 'wp-polls'); ?>
1575
- <select name="<?php echo $this->get_field_name('display_pollarchive'); ?>" id="<?php echo $this->get_field_id('display_pollarchive'); ?>" class="widefat">
1576
- <option value="0"<?php selected(0, $display_pollarchive); ?>><?php _e('No', 'wp-polls'); ?></option>
1577
- <option value="1"<?php selected(1, $display_pollarchive); ?>><?php _e('Yes', 'wp-polls'); ?></option>
1578
- </select>
1579
- </label>
1580
- </p>
1581
- <p>
1582
- <label for="<?php echo $this->get_field_id('poll_id'); ?>"><?php _e('Poll To Display:', 'wp-polls'); ?>
1583
- <select name="<?php echo $this->get_field_name('poll_id'); ?>" id="<?php echo $this->get_field_id('poll_id'); ?>" class="widefat">
1584
- <option value="-1"<?php selected(-1, $poll_id); ?>><?php _e('Do NOT Display Poll (Disable)', 'wp-polls'); ?></option>
1585
- <option value="-2"<?php selected(-2, $poll_id); ?>><?php _e('Display Random Poll', 'wp-polls'); ?></option>
1586
- <option value="0"<?php selected(0, $poll_id); ?>><?php _e('Display Latest Poll', 'wp-polls'); ?></option>
1587
- <optgroup>&nbsp;</optgroup>
1588
- <?php
1589
- $polls = $wpdb->get_results("SELECT pollq_id, pollq_question FROM $wpdb->pollsq ORDER BY pollq_id DESC");
1590
- if($polls) {
1591
- foreach($polls as $poll) {
1592
- $pollq_question = wp_kses_post( stripslashes( $poll->pollq_question ) );
1593
- $pollq_id = intval($poll->pollq_id);
1594
- if($pollq_id == $poll_id) {
1595
- echo "<option value=\"$pollq_id\" selected=\"selected\">$pollq_question</option>\n";
1596
- } else {
1597
- echo "<option value=\"$pollq_id\">$pollq_question</option>\n";
1598
- }
1599
- }
1600
- }
1601
- ?>
1602
- </select>
1603
- </label>
1604
- </p>
1605
- <input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
1606
  <?php
1607
- }
1608
  }
1609
 
1610
 
1611
  ### Function: Init WP-Polls Widget
1612
  add_action('widgets_init', 'widget_polls_init');
1613
  function widget_polls_init() {
1614
- polls_textdomain();
1615
- register_widget('WP_Widget_Polls');
1616
  }
1617
 
1618
 
1619
  ### Function: Activate Plugin
1620
  register_activation_hook( __FILE__, 'polls_activation' );
1621
- function polls_activation( $network_wide )
1622
- {
1623
- if ( is_multisite() && $network_wide )
1624
- {
1625
- $ms_sites = wp_get_sites();
1626
-
1627
- if( 0 < sizeof( $ms_sites ) )
1628
- {
1629
- foreach ( $ms_sites as $ms_site )
1630
- {
1631
- switch_to_blog( $ms_site['blog_id'] );
1632
- polls_activate();
1633
- restore_current_blog();
1634
- }
1635
- }
1636
- }
1637
- else
1638
- {
1639
- polls_activate();
1640
- }
1641
  }
1642
 
1643
  function polls_activate() {
1644
- global $wpdb;
1645
-
1646
- if(@is_file(ABSPATH.'/wp-admin/includes/upgrade.php')) {
1647
- include_once(ABSPATH.'/wp-admin/includes/upgrade.php');
1648
- } elseif(@is_file(ABSPATH.'/wp-admin/upgrade-functions.php')) {
1649
- include_once(ABSPATH.'/wp-admin/upgrade-functions.php');
1650
- } else {
1651
- die('We have problem finding your \'/wp-admin/upgrade-functions.php\' and \'/wp-admin/includes/upgrade.php\'');
1652
- }
1653
-
1654
- // Create Poll Tables (3 Tables)
1655
- $charset_collate = '';
1656
- if( $wpdb->has_cap( 'collation' ) ) {
1657
- if(!empty($wpdb->charset)) {
1658
- $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
1659
- }
1660
- if(!empty($wpdb->collate)) {
1661
- $charset_collate .= " COLLATE $wpdb->collate";
1662
- }
1663
- }
1664
- $create_table = array();
1665
- $create_table['pollsq'] = "CREATE TABLE $wpdb->pollsq (".
1666
- "pollq_id int(10) NOT NULL auto_increment,".
1667
- "pollq_question varchar(200) character set utf8 NOT NULL default '',".
1668
- "pollq_timestamp varchar(20) NOT NULL default '',".
1669
- "pollq_totalvotes int(10) NOT NULL default '0',".
1670
- "pollq_active tinyint(1) NOT NULL default '1',".
1671
- "pollq_expiry varchar(20) NOT NULL default '',".
1672
- "pollq_multiple tinyint(3) NOT NULL default '0',".
1673
- "pollq_totalvoters int(10) NOT NULL default '0',".
1674
- "PRIMARY KEY (pollq_id)) $charset_collate;";
1675
- $create_table['pollsa'] = "CREATE TABLE $wpdb->pollsa (".
1676
- "polla_aid int(10) NOT NULL auto_increment,".
1677
- "polla_qid int(10) NOT NULL default '0',".
1678
- "polla_answers varchar(200) character set utf8 NOT NULL default '',".
1679
- "polla_votes int(10) NOT NULL default '0',".
1680
- "PRIMARY KEY (polla_aid)) $charset_collate;";
1681
- $create_table['pollsip'] = "CREATE TABLE $wpdb->pollsip (".
1682
- "pollip_id int(10) NOT NULL auto_increment,".
1683
- "pollip_qid varchar(10) NOT NULL default '',".
1684
- "pollip_aid varchar(10) NOT NULL default '',".
1685
- "pollip_ip varchar(100) NOT NULL default '',".
1686
- "pollip_host VARCHAR(200) NOT NULL default '',".
1687
- "pollip_timestamp varchar(20) NOT NULL default '0000-00-00 00:00:00',".
1688
- "pollip_user tinytext NOT NULL,".
1689
- "pollip_userid int(10) NOT NULL default '0',".
1690
- "PRIMARY KEY (pollip_id),".
1691
- "KEY pollip_ip (pollip_ip),".
1692
- "KEY pollip_qid (pollip_qid),".
1693
- "KEY pollip_ip_qid (pollip_ip, pollip_qid)".
1694
- ") $charset_collate;";
1695
- maybe_create_table($wpdb->pollsq, $create_table['pollsq']);
1696
- maybe_create_table($wpdb->pollsa, $create_table['pollsa']);
1697
- maybe_create_table($wpdb->pollsip, $create_table['pollsip']);
1698
- // Check Whether It is Install Or Upgrade
1699
- $first_poll = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq LIMIT 1");
1700
- // If Install, Insert 1st Poll Question With 5 Poll Answers
1701
- if(empty($first_poll)) {
1702
- // Insert Poll Question (1 Record)
1703
- $insert_pollq = $wpdb->query("INSERT INTO $wpdb->pollsq VALUES (1, '".__('How Is My Site?', 'wp-polls')."', '".current_time('timestamp')."', 0, 1, '', 0, 0);");
1704
- if($insert_pollq) {
1705
- // Insert Poll Answers (5 Records)
1706
- $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (1, 1, '".__('Good', 'wp-polls')."', 0);");
1707
- $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (2, 1, '".__('Excellent', 'wp-polls')."', 0);");
1708
- $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (3, 1, '".__('Bad', 'wp-polls')."', 0);");
1709
- $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (4, 1, '".__('Can Be Improved', 'wp-polls')."', 0);");
1710
- $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (5, 1, '".__('No Comments', 'wp-polls')."', 0);");
1711
- }
1712
- }
1713
- // Add In Options (16 Records)
1714
- add_option('poll_template_voteheader', '<p style="text-align: center;"><strong>%POLL_QUESTION%</strong></p>'.
1715
- '<div id="polls-%POLL_ID%-ans" class="wp-polls-ans">'.
1716
- '<ul class="wp-polls-ul">');
1717
- add_option('poll_template_votebody', '<li><input type="%POLL_CHECKBOX_RADIO%" id="poll-answer-%POLL_ANSWER_ID%" name="poll_%POLL_ID%" value="%POLL_ANSWER_ID%" /> <label for="poll-answer-%POLL_ANSWER_ID%">%POLL_ANSWER%</label></li>');
1718
- add_option('poll_template_votefooter', '</ul>'.
1719
- '<p style="text-align: center;"><input type="button" name="vote" value=" '.__('Vote', 'wp-polls').' " class="Buttons" onclick="poll_vote(%POLL_ID%);" /></p>'.
1720
- '<p style="text-align: center;"><a href="#ViewPollResults" onclick="poll_result(%POLL_ID%); return false;" title="'.__('View Results Of This Poll', 'wp-polls').'">'.__('View Results', 'wp-polls').'</a></p>'.
1721
- '</div>');
1722
- add_option('poll_template_resultheader', '<p style="text-align: center;"><strong>%POLL_QUESTION%</strong></p>'.
1723
- '<div id="polls-%POLL_ID%-ans" class="wp-polls-ans">'.
1724
- '<ul class="wp-polls-ul">');
1725
- add_option('poll_template_resultbody', '<li>%POLL_ANSWER% <small>(%POLL_ANSWER_PERCENTAGE%%'.__(',', 'wp-polls').' %POLL_ANSWER_VOTES% '.__('Votes', 'wp-polls').')</small><div class="pollbar" style="width: %POLL_ANSWER_IMAGEWIDTH%%;" title="%POLL_ANSWER_TEXT% (%POLL_ANSWER_PERCENTAGE%% | %POLL_ANSWER_VOTES% '.__('Votes', 'wp-polls').')"></div></li>');
1726
- add_option('poll_template_resultbody2', '<li><strong><i>%POLL_ANSWER% <small>(%POLL_ANSWER_PERCENTAGE%%'.__(',', 'wp-polls').' %POLL_ANSWER_VOTES% '.__('Votes', 'wp-polls').')</small></i></strong><div class="pollbar" style="width: %POLL_ANSWER_IMAGEWIDTH%%;" title="'.__('You Have Voted For This Choice', 'wp-polls').' - %POLL_ANSWER_TEXT% (%POLL_ANSWER_PERCENTAGE%% | %POLL_ANSWER_VOTES% '.__('Votes', 'wp-polls').')"></div></li>');
1727
- add_option('poll_template_resultfooter', '</ul>'.
1728
- '<p style="text-align: center;">'.__('Total Voters', 'wp-polls').': <strong>%POLL_TOTALVOTERS%</strong></p>'.
1729
- '</div>');
1730
- add_option('poll_template_resultfooter2', '</ul>'.
1731
- '<p style="text-align: center;">'.__('Total Voters', 'wp-polls').': <strong>%POLL_TOTALVOTERS%</strong></p>'.
1732
- '<p style="text-align: center;"><a href="#VotePoll" onclick="poll_booth(%POLL_ID%); return false;" title="'.__('Vote For This Poll', 'wp-polls').'">'.__('Vote', 'wp-polls').'</a></p>'.
1733
- '</div>');
1734
- add_option('poll_template_disable', __('Sorry, there are no polls available at the moment.', 'wp-polls'));
1735
- add_option('poll_template_error', __('An error has occurred when processing your poll.', 'wp-polls'));
1736
- add_option('poll_currentpoll', 0);
1737
- add_option('poll_latestpoll', 1);
1738
- add_option('poll_archive_perpage', 5);
1739
- add_option('poll_ans_sortby', 'polla_aid');
1740
- add_option('poll_ans_sortorder', 'asc');
1741
- add_option('poll_ans_result_sortby', 'polla_votes');
1742
- add_option('poll_ans_result_sortorder', 'desc');
1743
- // Database Upgrade For WP-Polls 2.1
1744
- add_option('poll_logging_method', '3');
1745
- add_option('poll_allowtovote', '2');
1746
- maybe_add_column($wpdb->pollsq, 'pollq_active', "ALTER TABLE $wpdb->pollsq ADD pollq_active TINYINT( 1 ) NOT NULL DEFAULT '1';");
1747
- // Database Upgrade For WP-Polls 2.12
1748
- maybe_add_column($wpdb->pollsip, 'pollip_userid', "ALTER TABLE $wpdb->pollsip ADD pollip_userid INT( 10 ) NOT NULL DEFAULT '0';");
1749
- add_option('poll_archive_url', site_url('pollsarchive'));
1750
- // Database Upgrade For WP-Polls 2.13
1751
- add_option('poll_bar', array('style' => 'default', 'background' => 'd8e1eb', 'border' => 'c8c8c8', 'height' => 8));
1752
- // Database Upgrade For WP-Polls 2.14
1753
- maybe_add_column($wpdb->pollsq, 'pollq_expiry', "ALTER TABLE $wpdb->pollsq ADD pollq_expiry varchar(20) NOT NULL default '';");
1754
- add_option('poll_close', 1);
1755
- // Database Upgrade For WP-Polls 2.20
1756
- add_option('poll_ajax_style', array('loading' => 1, 'fading' => 1));
1757
- add_option('poll_template_pollarchivelink', '<ul>'.
1758
- '<li><a href="%POLL_ARCHIVE_URL%">'.__('Polls Archive', 'wp-polls').'</a></li>'.
1759
- '</ul>');
1760
- add_option('poll_archive_displaypoll', 2);
1761
- add_option('poll_template_pollarchiveheader', '');
1762
- add_option('poll_template_pollarchivefooter', '<p>'.__('Start Date:', 'wp-polls').' %POLL_START_DATE%<br />'.__('End Date:', 'wp-polls').' %POLL_END_DATE%</p>');
1763
- maybe_add_column($wpdb->pollsq, 'pollq_multiple', "ALTER TABLE $wpdb->pollsq ADD pollq_multiple TINYINT( 3 ) NOT NULL DEFAULT '0';");
1764
- $pollq_totalvoters = maybe_add_column($wpdb->pollsq, 'pollq_totalvoters', "ALTER TABLE $wpdb->pollsq ADD pollq_totalvoters INT( 10 ) NOT NULL DEFAULT '0';");
1765
- if($pollq_totalvoters) {
1766
- $pollq_totalvoters = intval($wpdb->get_var("SELECT SUM(pollq_totalvoters) FROM $wpdb->pollsq"));
1767
- if($pollq_totalvoters == 0) {
1768
- $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvoters = pollq_totalvotes");
1769
- }
1770
- }
1771
- // Database Upgrade For WP-Polls 2.30
1772
- add_option('poll_cookielog_expiry', 0);
1773
- add_option('poll_template_pollarchivepagingheader', '');
1774
- add_option('poll_template_pollarchivepagingfooter', '');
1775
- // Database Upgrade For WP-Polls 2.50
1776
- delete_option('poll_archive_show');
1777
-
1778
- // Index
1779
- $index = $wpdb->get_results( "SHOW INDEX FROM $wpdb->pollsip;" );
1780
- $key_name = array();
1781
- if( sizeof( $index ) > 0 ) {
1782
- foreach( $index as $i ) {
1783
- $key_name[]= $i->Key_name;
1784
- }
1785
- }
1786
- if ( ! in_array( 'pollip_ip', $key_name ) ) {
1787
- $wpdb->query( "ALTER TABLE $wpdb->pollsip ADD INDEX pollip_ip (pollip_ip);" );
1788
- }
1789
- if ( ! in_array( 'pollip_qid', $key_name ) ) {
1790
- $wpdb->query( "ALTER TABLE $wpdb->pollsip ADD INDEX pollip_qid (pollip_qid);" );
1791
- }
1792
- if ( ! in_array( 'pollip_ip_qid_aid', $key_name ) ) {
1793
- $wpdb->query( "ALTER TABLE $wpdb->pollsip ADD INDEX pollip_ip_qid_aid (pollip_ip, pollip_qid, pollip_aid);" );
1794
- }
1795
- // No longer needed index
1796
- if ( in_array( 'pollip_ip_qid', $key_name ) ) {
1797
- $wpdb->query( "ALTER TABLE $wpdb->pollsip DROP INDEX pollip_ip_qid;" );
1798
- }
1799
-
1800
- // Set 'manage_polls' Capabilities To Administrator
1801
- $role = get_role( 'administrator' );
1802
- if( ! $role->has_cap( 'manage_polls' ) ) {
1803
- $role->add_cap( 'manage_polls' );
1804
- }
1805
- cron_polls_place();
1806
- }
1
  <?php
2
  /*
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.72
7
  Author: Lester 'GaMerZ' Chan
8
+ Author URI: https://lesterchan.net
9
  Text Domain: wp-polls
10
  */
11
 
12
 
13
  /*
14
+ Copyright 2015 Lester Chan (email : lesterchan@gmail.com)
15
 
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License as published by
18
+ the Free Software Foundation; either version 2 of the License, or
19
+ (at your option) any later version.
20
 
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
 
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
  */
30
 
31
 
32
  ### Version
33
+ define( 'WP_POLLS_VERSION', 2.72 );
34
 
35
 
36
  ### Create Text Domain For Translations
37
  add_action( 'plugins_loaded', 'polls_textdomain' );
38
  function polls_textdomain() {
39
+ load_plugin_textdomain( 'wp-polls' );
40
  }
41
 
42
 
50
  ### Function: Poll Administration Menu
51
  add_action( 'admin_menu', 'poll_menu' );
52
  function poll_menu() {
53
+ add_menu_page( __( 'Polls', 'wp-polls' ), __( 'Polls', 'wp-polls' ), 'manage_polls', 'wp-polls/polls-manager.php', '', 'dashicons-chart-bar' );
54
 
55
+ add_submenu_page( 'wp-polls/polls-manager.php', __( 'Manage Polls', 'wp-polls'), __( 'Manage Polls', 'wp-polls' ), 'manage_polls', 'wp-polls/polls-manager.php' );
56
+ add_submenu_page( 'wp-polls/polls-manager.php', __( 'Add Poll', 'wp-polls'), __( 'Add Poll', 'wp-polls' ), 'manage_polls', 'wp-polls/polls-add.php' );
57
+ add_submenu_page( 'wp-polls/polls-manager.php', __( 'Poll Options', 'wp-polls'), __( 'Poll Options', 'wp-polls' ), 'manage_polls', 'wp-polls/polls-options.php' );
58
+ add_submenu_page( 'wp-polls/polls-manager.php', __( 'Poll Templates', 'wp-polls'), __( 'Poll Templates', 'wp-polls' ), 'manage_polls', 'wp-polls/polls-templates.php' );
59
  }
60
 
61
 
62
  ### Function: Get Poll
63
  function get_poll($temp_poll_id = 0, $display = true) {
64
+ global $wpdb, $polls_loaded;
65
+ // Poll Result Link
66
+ if(isset($_GET['pollresult'])) {
67
+ $pollresult_id = intval($_GET['pollresult']);
68
+ } else {
69
+ $pollresult_id = 0;
70
+ }
71
+ $temp_poll_id = intval($temp_poll_id);
72
+ // Check Whether Poll Is Disabled
73
+ if(intval(get_option('poll_currentpoll')) == -1) {
74
+ if($display) {
75
+ echo stripslashes(get_option('poll_template_disable'));
76
+ return;
77
+ } else {
78
+ return stripslashes(get_option('poll_template_disable'));
79
+ }
80
+ // Poll Is Enabled
81
+ } else {
82
+ do_action('wp_polls_get_poll');
83
+ // Hardcoded Poll ID Is Not Specified
84
+ switch($temp_poll_id) {
85
+ // Random Poll
86
+ case -2:
87
+ $poll_id = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq WHERE pollq_active = 1 ORDER BY RAND() LIMIT 1");
88
+ break;
89
+ // Latest Poll
90
+ case 0:
91
+ // Random Poll
92
+ if(intval(get_option('poll_currentpoll')) == -2) {
93
+ $random_poll_id = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq WHERE pollq_active = 1 ORDER BY RAND() LIMIT 1");
94
+ $poll_id = intval($random_poll_id);
95
+ if($pollresult_id > 0) {
96
+ $poll_id = $pollresult_id;
97
+ } elseif(intval($_POST['poll_id']) > 0) {
98
+ $poll_id = intval($_POST['poll_id']);
99
+ }
100
+ // Current Poll ID Is Not Specified
101
+ } elseif(intval(get_option('poll_currentpoll')) == 0) {
102
+ // Get Lastest Poll ID
103
+ $poll_id = intval(get_option('poll_latestpoll'));
104
+ } else {
105
+ // Get Current Poll ID
106
+ $poll_id = intval(get_option('poll_currentpoll'));
107
+ }
108
+ break;
109
+ // Take Poll ID From Arguments
110
+ default:
111
+ $poll_id = $temp_poll_id;
112
+ }
113
+ }
114
+
115
+ // Assign All Loaded Poll To $polls_loaded
116
+ if(empty($polls_loaded)) {
117
+ $polls_loaded = array();
118
+ }
119
+ if(!in_array($poll_id, $polls_loaded)) {
120
+ $polls_loaded[] = $poll_id;
121
+ }
122
+
123
+ // User Click on View Results Link
124
+ if($pollresult_id == $poll_id) {
125
+ if($display) {
126
+ echo display_pollresult($poll_id);
127
+ return;
128
+ } else {
129
+ return display_pollresult($poll_id);
130
+ }
131
+ // Check Whether User Has Voted
132
+ } else {
133
+ $poll_active = $wpdb->get_var( $wpdb->prepare( "SELECT pollq_active FROM $wpdb->pollsq WHERE pollq_id = %d", $poll_id ) );
134
+ $poll_active = intval($poll_active);
135
+ $check_voted = check_voted($poll_id);
136
+ if($poll_active == 0) {
137
+ $poll_close = intval(get_option('poll_close'));
138
+ } else {
139
+ $poll_close = 0;
140
+ }
141
+ if(intval($check_voted) > 0 || (is_array($check_voted) && sizeof($check_voted) > 0) || ($poll_active == 0 && $poll_close == 1)) {
142
+ if($display) {
143
+ echo display_pollresult($poll_id, $check_voted);
144
+ return;
145
+ } else {
146
+ return display_pollresult($poll_id, $check_voted);
147
+ }
148
+ } elseif(!check_allowtovote() || ($poll_active == 0 && $poll_close == 3)) {
149
+ $disable_poll_js = '<script type="text/javascript">jQuery("#polls_form_'.$poll_id.' :input").each(function (i){jQuery(this).attr("disabled","disabled")});</script>';
150
+ if($display) {
151
+ echo display_pollvote($poll_id).$disable_poll_js;
152
+ return;
153
+ } else {
154
+ return display_pollvote($poll_id).$disable_poll_js;
155
+ }
156
+ } elseif($poll_active == 1) {
157
+ if($display) {
158
+ echo display_pollvote($poll_id);
159
+ return;
160
+ } else {
161
+ return display_pollvote($poll_id);
162
+ }
163
+ }
164
+ }
165
  }
166
 
167
 
168
  ### Function: Enqueue Polls JavaScripts/CSS
169
  add_action('wp_enqueue_scripts', 'poll_scripts');
170
  function poll_scripts() {
171
+ if(@file_exists(get_stylesheet_directory().'/polls-css.css')) {
172
+ wp_enqueue_style('wp-polls', get_stylesheet_directory_uri().'/polls-css.css', false, WP_POLLS_VERSION, 'all');
173
+ } else {
174
+ wp_enqueue_style('wp-polls', plugins_url('wp-polls/polls-css.css'), false, WP_POLLS_VERSION, 'all');
175
+ }
176
+ if( is_rtl() ) {
177
+ if(@file_exists(get_stylesheet_directory().'/polls-css-rtl.css')) {
178
+ wp_enqueue_style('wp-polls-rtl', get_stylesheet_directory_uri().'/polls-css-rtl.css', false, WP_POLLS_VERSION, 'all');
179
+ } else {
180
+ wp_enqueue_style('wp-polls-rtl', plugins_url('wp-polls/polls-css-rtl.css'), false, WP_POLLS_VERSION, 'all');
181
+ }
182
+ }
183
+ $pollbar = get_option( 'poll_bar' );
184
+ if( $pollbar['style'] === 'use_css' ) {
185
+ $pollbar_css = '.wp-polls .pollbar {'."\n";
186
+ $pollbar_css .= "\t".'margin: 1px;'."\n";
187
+ $pollbar_css .= "\t".'font-size: '.($pollbar['height']-2).'px;'."\n";
188
+ $pollbar_css .= "\t".'line-height: '.$pollbar['height'].'px;'."\n";
189
+ $pollbar_css .= "\t".'height: '.$pollbar['height'].'px;'."\n";
190
+ $pollbar_css .= "\t".'background: #'.$pollbar['background'].';'."\n";
191
+ $pollbar_css .= "\t".'border: 1px solid #'.$pollbar['border'].';'."\n";
192
+ $pollbar_css .= '}'."\n";
193
+ } else {
194
+ $pollbar_css = '.wp-polls .pollbar {'."\n";
195
+ $pollbar_css .= "\t".'margin: 1px;'."\n";
196
+ $pollbar_css .= "\t".'font-size: '.($pollbar['height']-2).'px;'."\n";
197
+ $pollbar_css .= "\t".'line-height: '.$pollbar['height'].'px;'."\n";
198
+ $pollbar_css .= "\t".'height: '.$pollbar['height'].'px;'."\n";
199
+ $pollbar_css .= "\t".'background-image: url(\''.plugins_url('wp-polls/images/'.$pollbar['style'].'/pollbg.gif').'\');'."\n";
200
+ $pollbar_css .= "\t".'border: 1px solid #'.$pollbar['border'].';'."\n";
201
+ $pollbar_css .= '}'."\n";
202
+ }
203
+ wp_add_inline_style( 'wp-polls', $pollbar_css );
204
+ $poll_ajax_style = get_option('poll_ajax_style');
205
+ wp_enqueue_script('wp-polls', plugins_url('wp-polls/polls-js.js'), array('jquery'), WP_POLLS_VERSION, true);
206
+ wp_localize_script('wp-polls', 'pollsL10n', array(
207
+ 'ajax_url' => admin_url('admin-ajax.php'),
208
+ 'text_wait' => __('Your last request is still being processed. Please wait a while ...', 'wp-polls'),
209
+ 'text_valid' => __('Please choose a valid poll answer.', 'wp-polls'),
210
+ 'text_multiple' => __('Maximum number of choices allowed: ', 'wp-polls'),
211
+ 'show_loading' => intval($poll_ajax_style['loading']),
212
+ 'show_fading' => intval($poll_ajax_style['fading'])
213
+ ));
214
  }
215
 
216
 
217
  ### Function: Enqueue Polls Stylesheets/JavaScripts In WP-Admin
218
  add_action('admin_enqueue_scripts', 'poll_scripts_admin');
219
  function poll_scripts_admin($hook_suffix) {
220
+ $poll_admin_pages = array('wp-polls/polls-manager.php', 'wp-polls/polls-add.php', 'wp-polls/polls-options.php', 'wp-polls/polls-templates.php', 'wp-polls/polls-uninstall.php');
221
+ if(in_array($hook_suffix, $poll_admin_pages)) {
222
+ wp_enqueue_style('wp-polls-admin', plugins_url('wp-polls/polls-admin-css.css'), false, WP_POLLS_VERSION, 'all');
223
+ wp_enqueue_script('wp-polls-admin', plugins_url('wp-polls/polls-admin-js.js'), array('jquery'), WP_POLLS_VERSION, true);
224
+ wp_localize_script('wp-polls-admin', 'pollsAdminL10n', array(
225
+ 'admin_ajax_url' => admin_url('admin-ajax.php'),
226
+ 'text_direction' => is_rtl() ? 'right' : 'left',
227
+ 'text_delete_poll' => __('Delete Poll', 'wp-polls'),
228
+ 'text_no_poll_logs' => __('No poll logs available.', 'wp-polls'),
229
+ 'text_delete_all_logs' => __('Delete All Logs', 'wp-polls'),
230
+ 'text_checkbox_delete_all_logs' => __('Please check the \\\'Yes\\\' checkbox if you want to delete all logs.', 'wp-polls'),
231
+ 'text_delete_poll_logs' => __('Delete Logs For This Poll Only', 'wp-polls'),
232
+ 'text_checkbox_delete_poll_logs' => __('Please check the \\\'Yes\\\' checkbox if you want to delete all logs for this poll ONLY.', 'wp-polls'),
233
+ 'text_delete_poll_ans' => __('Delete Poll Answer', 'wp-polls'),
234
+ 'text_open_poll' => __('Open Poll', 'wp-polls'),
235
+ 'text_close_poll' => __('Close Poll', 'wp-polls'),
236
+ 'text_answer' => __('Answer', 'wp-polls'),
237
+ 'text_remove_poll_answer' => __('Remove', 'wp-polls')
238
+ ));
239
+ }
240
  }
241
 
242
 
247
  add_action('admin_footer-page.php', 'poll_footer_admin');
248
  function poll_footer_admin() {
249
  ?>
250
+ <script type="text/javascript">
251
+ QTags.addButton('ed_wp_polls', '<?php echo esc_js(__('Poll', 'wp-polls')); ?>', function() {
252
+ var poll_id = jQuery.trim(prompt('<?php echo esc_js(__('Enter Poll ID', 'wp-polls')); ?>'));
253
+ while(isNaN(poll_id)) {
254
+ poll_id = jQuery.trim(prompt("<?php echo esc_js(__('Error: Poll ID must be numeric', 'wp-polls')); ?>\n\n<?php echo esc_js(__('Please enter Poll ID again', 'wp-polls')); ?>"));
255
+ }
256
+ if (poll_id >= -1 && poll_id != null && poll_id != "") {
257
+ QTags.insertContent('[poll id="' + poll_id + '"]');
258
+ }
259
+ });
260
+ </script>
261
  <?php
262
  }
263
 
264
  ### Function: Add Quick Tag For Poll In TinyMCE >= WordPress 2.5
265
  add_action('init', 'poll_tinymce_addbuttons');
266
  function poll_tinymce_addbuttons() {
267
+ if(!current_user_can('edit_posts') && ! current_user_can('edit_pages')) {
268
+ return;
269
+ }
270
+ if(get_user_option('rich_editing') == 'true') {
271
+ add_filter('mce_external_plugins', 'poll_tinymce_addplugin');
272
+ add_filter('mce_buttons', 'poll_tinymce_registerbutton');
273
+ add_filter('wp_mce_translation', 'poll_tinymce_translation');
274
+ }
275
  }
276
  function poll_tinymce_registerbutton($buttons) {
277
+ array_push($buttons, 'separator', 'polls');
278
+ return $buttons;
279
  }
280
  function poll_tinymce_addplugin($plugin_array) {
281
+ if(WP_DEBUG) {
282
+ $plugin_array['polls'] = plugins_url( 'wp-polls/tinymce/plugins/polls/plugin.js?v=' . WP_POLLS_VERSION );
283
+ } else {
284
+ $plugin_array['polls'] = plugins_url( 'wp-polls/tinymce/plugins/polls/plugin.min.js?v=' . WP_POLLS_VERSION );
285
+ }
286
+ return $plugin_array;
287
  }
288
  function poll_tinymce_translation($mce_translation) {
289
+ $mce_translation['Enter Poll ID'] = esc_js(__('Enter Poll ID', 'wp-polls'));
290
+ $mce_translation['Error: Poll ID must be numeric'] = esc_js(__('Error: Poll ID must be numeric', 'wp-polls'));
291
+ $mce_translation['Please enter Poll ID again'] = esc_js(__('Please enter Poll ID again', 'wp-polls'));
292
+ $mce_translation['Insert Poll'] = esc_js(__('Insert Poll', 'wp-polls'));
293
+ return $mce_translation;
294
  }
295
 
296
 
297
  ### Function: Check Who Is Allow To Vote
298
  function check_allowtovote() {
299
+ global $user_ID;
300
+ $user_ID = intval($user_ID);
301
+ $allow_to_vote = intval(get_option('poll_allowtovote'));
302
+ switch($allow_to_vote) {
303
+ // Guests Only
304
+ case 0:
305
+ if($user_ID > 0) {
306
+ return false;
307
+ }
308
+ return true;
309
+ break;
310
+ // Registered Users Only
311
+ case 1:
312
+ if($user_ID == 0) {
313
+ return false;
314
+ }
315
+ return true;
316
+ break;
317
+ // Registered Users And Guests
318
+ case 2:
319
+ default:
320
+ return true;
321
+ }
322
  }
323
 
324
 
325
  ### Funcrion: Check Voted By Cookie Or IP
326
  function check_voted($poll_id) {
327
+ $poll_logging_method = intval(get_option('poll_logging_method'));
328
+ switch($poll_logging_method) {
329
+ // Do Not Log
330
+ case 0:
331
+ return 0;
332
+ break;
333
+ // Logged By Cookie
334
+ case 1:
335
+ return check_voted_cookie($poll_id);
336
+ break;
337
+ // Logged By IP
338
+ case 2:
339
+ return check_voted_ip($poll_id);
340
+ break;
341
+ // Logged By Cookie And IP
342
+ case 3:
343
+ $check_voted_cookie = check_voted_cookie($poll_id);
344
+ if(!empty($check_voted_cookie)) {
345
+ return $check_voted_cookie;
346
+ } else {
347
+ return check_voted_ip($poll_id);
348
+ }
349
+ break;
350
+ // Logged By Username
351
+ case 4:
352
+ return check_voted_username($poll_id);
353
+ break;
354
+ }
355
  }
356
 
357
 
358
  ### Function: Check Voted By Cookie
359
  function check_voted_cookie($poll_id) {
360
+ if(!empty($_COOKIE["voted_$poll_id"])) {
361
+ $get_voted_aids = explode(',', $_COOKIE["voted_$poll_id"]);
362
+ } else {
363
+ $get_voted_aids = 0;
364
+ }
365
+ return $get_voted_aids;
366
  }
367
 
368
 
369
  ### Function: Check Voted By IP
370
+ function check_voted_ip( $poll_id ) {
371
+ global $wpdb;
372
+ $log_expiry = intval( get_option( 'poll_cookielog_expiry' ) );
373
+ $log_expiry_sql = '';
374
+ if( $log_expiry > 0 ) {
375
+ $log_expiry_sql = 'AND (' . current_time('timestamp') . '-(pollip_timestamp+0)) < ' . $log_expiry;
376
+ }
377
+ // Check IP From IP Logging Database
378
+ $get_voted_aids = $wpdb->get_col( $wpdb->prepare( "SELECT pollip_aid FROM $wpdb->pollsip WHERE pollip_qid = %d AND pollip_ip = %s", $poll_id, get_ipaddress() ) . $log_expiry_sql );
379
+ if( $get_voted_aids ) {
380
+ return $get_voted_aids;
381
+ } else {
382
+ return 0;
383
+ }
384
  }
385
 
386
 
387
  ### Function: Check Voted By Username
388
  function check_voted_username($poll_id) {
389
+ global $wpdb, $user_ID;
390
+ // Check IP If User Is Guest
391
+ if ( ! is_user_logged_in() ) {
392
+ return 1;
393
+ }
394
+ $pollsip_userid = intval( $user_ID );
395
+ $log_expiry = intval( get_option( 'poll_cookielog_expiry' ) );
396
+ $log_expiry_sql = '';
397
+ if( $log_expiry > 0 ) {
398
+ $log_expiry_sql = 'AND (' . current_time('timestamp') . '-(pollip_timestamp+0)) < ' . $log_expiry;
399
+ }
400
+ // Check User ID From IP Logging Database
401
+ $get_voted_aids = $wpdb->get_col( $wpdb->prepare( "SELECT pollip_aid FROM $wpdb->pollsip WHERE pollip_qid = %d AND pollip_userid = %d", $poll_id, $pollsip_userid ) . $log_expiry_sql );
402
+ if($get_voted_aids) {
403
+ return $get_voted_aids;
404
+ } else {
405
+ return 0;
406
+ }
407
  }
408
 
409
  add_filter('poll_template_voteheader_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
 
423
  ### Function: Display Voting Form
424
  function display_pollvote($poll_id, $display_loading = true) {
425
+ do_action('wp_polls_display_pollvote');
426
+ global $wpdb;
427
+ // Temp Poll Result
428
+ $temp_pollvote = '';
429
+ // Get Poll Question Data
430
+ $poll_question = $wpdb->get_row( $wpdb->prepare( "SELECT pollq_id, pollq_question, pollq_totalvotes, pollq_timestamp, pollq_expiry, pollq_multiple, pollq_totalvoters FROM $wpdb->pollsq WHERE pollq_id = %d LIMIT 1", $poll_id ) );
431
+
432
+ // Poll Question Variables
433
+ $poll_question_text = wp_kses_post( stripslashes( $poll_question->pollq_question ) );
434
+ $poll_question_id = intval($poll_question->pollq_id);
435
+ $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
436
+ $poll_question_totalvoters = intval($poll_question->pollq_totalvoters);
437
+ $poll_start_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_question->pollq_timestamp));
438
+ $poll_expiry = trim($poll_question->pollq_expiry);
439
+ if(empty($poll_expiry)) {
440
+ $poll_end_date = __('No Expiry', 'wp-polls');
441
+ } else {
442
+ $poll_end_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_expiry));
443
+ }
444
+ $poll_multiple_ans = intval($poll_question->pollq_multiple);
445
+
446
+ $template_question = stripslashes(get_option('poll_template_voteheader'));
447
+
448
+ $template_question = apply_filters('poll_template_voteheader_markup', $template_question, $poll_question, array(
449
+ '%POLL_QUESTION%' => $poll_question_text,
450
+ '%POLL_ID%' => $poll_question_id,
451
+ '%POLL_TOTALVOTES%' => $poll_question_totalvotes,
452
+ '%POLL_TOTALVOTERS%' => $poll_question_totalvoters,
453
+ '%POLL_START_DATE%' => $poll_start_date,
454
+ '%POLL_END_DATE%' => $poll_end_date,
455
+ '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
456
+ ));
457
+
458
+ // Get Poll Answers Data
459
+ list($order_by, $sort_order) = _polls_get_ans_sort();
460
+ $poll_answers = $wpdb->get_results( $wpdb->prepare( "SELECT polla_aid, polla_qid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = %d ORDER BY $order_by $sort_order", $poll_question_id ) );
461
+ // If There Is Poll Question With Answers
462
+ if($poll_question && $poll_answers) {
463
+ // Display Poll Voting Form
464
+ $temp_pollvote .= "<div id=\"polls-$poll_question_id\" class=\"wp-polls\">\n";
465
+ $temp_pollvote .= "\t<form id=\"polls_form_$poll_question_id\" class=\"wp-polls-form\" action=\"".esc_attr($_SERVER['SCRIPT_NAME'])."\" method=\"post\">\n";
466
+ $temp_pollvote .= "\t\t<p style=\"display: none;\"><input type=\"hidden\" id=\"poll_{$poll_question_id}_nonce\" name=\"wp-polls-nonce\" value=\"".wp_create_nonce('poll_'.$poll_question_id.'-nonce')."\" /></p>\n";
467
+ $temp_pollvote .= "\t\t<p style=\"display: none;\"><input type=\"hidden\" name=\"poll_id\" value=\"$poll_question_id\" /></p>\n";
468
+ if($poll_multiple_ans > 0) {
469
+ $temp_pollvote .= "\t\t<p style=\"display: none;\"><input type=\"hidden\" id=\"poll_multiple_ans_$poll_question_id\" name=\"poll_multiple_ans_$poll_question_id\" value=\"$poll_multiple_ans\" /></p>\n";
470
+ }
471
+ // Print Out Voting Form Header Template
472
+ $temp_pollvote .= "\t\t$template_question\n";
473
+ foreach($poll_answers as $poll_answer) {
474
+ // Poll Answer Variables
475
+ $poll_answer_id = intval($poll_answer->polla_aid);
476
+ $poll_answer_text = wp_kses_post( stripslashes( $poll_answer->polla_answers ) );
477
+ $poll_answer_votes = intval($poll_answer->polla_votes);
478
+ $poll_answer_percentage = $poll_question_totalvoters > 0 ? round((($poll_answer_votes/$poll_question_totalvoters)*100)) : 0;
479
+ $template_answer = stripslashes(get_option('poll_template_votebody'));
480
+
481
+ $template_answer = apply_filters('poll_template_votebody_markup', $template_answer, $poll_answer, array(
482
+ '%POLL_ID%' => $poll_question_id,
483
+ '%POLL_ANSWER_ID%' => $poll_answer_id,
484
+ '%POLL_ANSWER%' => $poll_answer_text,
485
+ '%POLL_ANSWER_VOTES%' => number_format_i18n($poll_answer_votes),
486
+ '%POLL_ANSWER_PERCENTAGE%' => $poll_answer_percentage,
487
+ "%POLL_CHECKBOX_RADIO%" => $poll_multiple_ans > 0 ? 'checkbox' : 'radio'
488
+ ));
489
+
490
+ // Print Out Voting Form Body Template
491
+ $temp_pollvote .= "\t\t$template_answer\n";
492
+ }
493
+ // Determine Poll Result URL
494
+ $poll_result_url = $_SERVER['REQUEST_URI'];
495
+ $poll_result_url = preg_replace('/pollresult=(\d+)/i', 'pollresult='.$poll_question_id, $poll_result_url);
496
+ if(isset($_GET['pollresult']) && intval($_GET['pollresult']) == 0) {
497
+ if(strpos($poll_result_url, '?') !== false) {
498
+ $poll_result_url = "$poll_result_url&amp;pollresult=$poll_question_id";
499
+ } else {
500
+ $poll_result_url = "$poll_result_url?pollresult=$poll_question_id";
501
+ }
502
+ }
503
+ // Voting Form Footer Variables
504
+ $template_footer = stripslashes(get_option('poll_template_votefooter'));
505
+
506
+ $template_footer = apply_filters('poll_template_votefooter_markup', $template_footer, $poll_question, array(
507
+ '%POLL_ID%' => $poll_question_id,
508
+ '%POLL_RESULT_URL%' => $poll_result_url,
509
+ '%POLL_START_DATE%' => $poll_start_date,
510
+ '%POLL_END_DATE%' => $poll_end_date,
511
+ '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
512
+ ));
513
+
514
+ // Print Out Voting Form Footer Template
515
+ $temp_pollvote .= "\t\t$template_footer\n";
516
+ $temp_pollvote .= "\t</form>\n";
517
+ $temp_pollvote .= "</div>\n";
518
+ if($display_loading) {
519
+ $poll_ajax_style = get_option('poll_ajax_style');
520
+ if(intval($poll_ajax_style['loading']) == 1) {
521
+ $temp_pollvote .= "<div id=\"polls-$poll_question_id-loading\" class=\"wp-polls-loading\"><img src=\"".plugins_url('wp-polls/images/loading.gif')."\" width=\"16\" height=\"16\" alt=\"".__('Loading', 'wp-polls')." ...\" title=\"".__('Loading', 'wp-polls')." ...\" class=\"wp-polls-image\" />&nbsp;".__('Loading', 'wp-polls')." ...</div>\n";
522
+ }
523
+ }
524
+ } else {
525
+ $temp_pollvote .= stripslashes(get_option('poll_template_disable'));
526
+ }
527
+ // Return Poll Vote Template
528
+ return $temp_pollvote;
529
  }
530
 
531
 
532
  ### Function: Display Results Form
533
  function display_pollresult($poll_id, $user_voted = '', $display_loading = true) {
534
+ do_action('wp_polls_display_pollresult');
535
+ global $wpdb;
536
+ $poll_id = intval($poll_id);
537
+ // User Voted
538
+ if(!is_array($user_voted)) {
539
+ $user_voted = array();
540
+ }
541
+ // Temp Poll Result
542
+ $temp_pollresult = '';
543
+ // Most/Least Variables
544
+ $poll_most_answer = '';
545
+ $poll_most_votes = 0;
546
+ $poll_most_percentage = 0;
547
+ $poll_least_answer = '';
548
+ $poll_least_votes = 0;
549
+ $poll_least_percentage = 0;
550
+ // Get Poll Question Data
551
+ $poll_question = $wpdb->get_row( $wpdb->prepare( "SELECT pollq_id, pollq_question, pollq_totalvotes, pollq_active, pollq_timestamp, pollq_expiry, pollq_multiple, pollq_totalvoters FROM $wpdb->pollsq WHERE pollq_id = %d LIMIT 1", $poll_id ) );
552
+ // No poll could be loaded from the database
553
+ if (!$poll_question) {
554
+ return stripslashes(get_option('poll_template_disable'));
555
+ }
556
+ // Poll Question Variables
557
+ $poll_question_text = wp_kses_post( stripslashes( $poll_question->pollq_question ) );
558
+ $poll_question_id = intval($poll_question->pollq_id);
559
+ $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
560
+ $poll_question_totalvoters = intval($poll_question->pollq_totalvoters);
561
+ $poll_question_active = intval($poll_question->pollq_active);
562
+ $poll_start_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_question->pollq_timestamp));
563
+ $poll_expiry = trim($poll_question->pollq_expiry);
564
+ if(empty($poll_expiry)) {
565
+ $poll_end_date = __('No Expiry', 'wp-polls');
566
+ } else {
567
+ $poll_end_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_expiry));
568
+ }
569
+ $poll_multiple_ans = intval($poll_question->pollq_multiple);
570
+ $template_question = stripslashes(get_option('poll_template_resultheader'));
571
+ $template_question = str_replace("%POLL_QUESTION%", $poll_question_text, $template_question);
572
+ $template_question = str_replace("%POLL_ID%", $poll_question_id, $template_question);
573
+ $template_question = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_question);
574
+ $template_question = str_replace("%POLL_TOTALVOTERS%", $poll_question_totalvoters, $template_question);
575
+ $template_question = str_replace("%POLL_START_DATE%", $poll_start_date, $template_question);
576
+ $template_question = str_replace("%POLL_END_DATE%", $poll_end_date, $template_question);
577
+ if($poll_multiple_ans > 0) {
578
+ $template_question = str_replace("%POLL_MULTIPLE_ANS_MAX%", $poll_multiple_ans, $template_question);
579
+ } else {
580
+ $template_question = str_replace("%POLL_MULTIPLE_ANS_MAX%", '1', $template_question);
581
+ }
582
+ // Get Poll Answers Data
583
+ list($order_by, $sort_order) = _polls_get_ans_result_sort();
584
+ $poll_answers = $wpdb->get_results( $wpdb->prepare( "SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = %d ORDER BY $order_by $sort_order", $poll_question_id ) );
585
+ // If There Is Poll Question With Answers
586
+ if($poll_question && $poll_answers) {
587
+ // Store The Percentage Of The Poll
588
+ $poll_answer_percentage_array = array();
589
+ // Is The Poll Total Votes 0?
590
+ $poll_totalvotes_zero = true;
591
+ if($poll_question_totalvotes > 0) {
592
+ $poll_totalvotes_zero = false;
593
+ }
594
+ // Print Out Result Header Template
595
+ $temp_pollresult .= "<div id=\"polls-$poll_question_id\" class=\"wp-polls\">\n";
596
+ $temp_pollresult .= "\t\t$template_question\n";
597
+ foreach($poll_answers as $poll_answer) {
598
+ // Poll Answer Variables
599
+ $poll_answer_id = intval($poll_answer->polla_aid);
600
+ $poll_answer_text = wp_kses_post( stripslashes($poll_answer->polla_answers) );
601
+ $poll_answer_votes = intval($poll_answer->polla_votes);
602
+ // Calculate Percentage And Image Bar Width
603
+ if(!$poll_totalvotes_zero) {
604
+ if($poll_answer_votes > 0) {
605
+ $poll_answer_percentage = round((($poll_answer_votes/$poll_question_totalvoters)*100));
606
+ $poll_answer_imagewidth = round($poll_answer_percentage);
607
+ if($poll_answer_imagewidth == 100) {
608
+ $poll_answer_imagewidth = 99;
609
+ }
610
+ } else {
611
+ $poll_answer_percentage = 0;
612
+ $poll_answer_imagewidth = 1;
613
+ }
614
+ } else {
615
+ $poll_answer_percentage = 0;
616
+ $poll_answer_imagewidth = 1;
617
+ }
618
+ // Make Sure That Total Percentage Is 100% By Adding A Buffer To The Last Poll Answer
619
+ $round_percentage = apply_filters( 'wp_polls_round_percentage', false );
620
+ if( $round_percentage ) {
621
+ if ( $poll_multiple_ans === 0 ) {
622
+ $poll_answer_percentage_array[] = $poll_answer_percentage;
623
+ if ( sizeof( $poll_answer_percentage_array ) === sizeof( $poll_answers ) ) {
624
+ $percentage_error_buffer = 100 - array_sum( $poll_answer_percentage_array );
625
+ $poll_answer_percentage = $poll_answer_percentage + $percentage_error_buffer;
626
+ if ( $poll_answer_percentage < 0 ) {
627
+ $poll_answer_percentage = 0;
628
+ }
629
+ }
630
+ }
631
+ }
632
+
633
+ // Let User See What Options They Voted
634
+ if(in_array($poll_answer_id, $user_voted)) {
635
+ // Results Body Variables
636
+ $template_answer = stripslashes(get_option('poll_template_resultbody2'));
637
+ $template_answer = str_replace("%POLL_ID%", $poll_question_id, $template_answer);
638
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
639
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
640
+ $template_answer = str_replace("%POLL_ANSWER_TEXT%", htmlspecialchars(strip_tags($poll_answer_text)), $template_answer);
641
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format_i18n($poll_answer_votes), $template_answer);
642
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
643
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
644
+ // Print Out Results Body Template
645
+ $temp_pollresult .= "\t\t$template_answer\n";
646
+ } else {
647
+ // Results Body Variables
648
+ $template_answer = stripslashes(get_option('poll_template_resultbody'));
649
+ $template_answer = str_replace("%POLL_ID%", $poll_question_id, $template_answer);
650
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
651
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
652
+ $template_answer = str_replace("%POLL_ANSWER_TEXT%", htmlspecialchars(strip_tags($poll_answer_text)), $template_answer);
653
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format_i18n($poll_answer_votes), $template_answer);
654
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
655
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
656
+ // Print Out Results Body Template
657
+ $temp_pollresult .= "\t\t$template_answer\n";
658
+ }
659
+ // Get Most Voted Data
660
+ if($poll_answer_votes > $poll_most_votes) {
661
+ $poll_most_answer = $poll_answer_text;
662
+ $poll_most_votes = $poll_answer_votes;
663
+ $poll_most_percentage = $poll_answer_percentage;
664
+ }
665
+ // Get Least Voted Data
666
+ if($poll_least_votes == 0) {
667
+ $poll_least_votes = $poll_answer_votes;
668
+ }
669
+ if($poll_answer_votes <= $poll_least_votes) {
670
+ $poll_least_answer = $poll_answer_text;
671
+ $poll_least_votes = $poll_answer_votes;
672
+ $poll_least_percentage = $poll_answer_percentage;
673
+ }
674
+ }
675
+ // Results Footer Variables
676
+ if(!empty($user_voted) || $poll_question_active == 0 || !check_allowtovote()) {
677
+ $template_footer = stripslashes(get_option('poll_template_resultfooter'));
678
+ } else {
679
+ $template_footer = stripslashes(get_option('poll_template_resultfooter2'));
680
+ }
681
+ $template_footer = str_replace("%POLL_START_DATE%", $poll_start_date, $template_footer);
682
+ $template_footer = str_replace("%POLL_END_DATE%", $poll_end_date, $template_footer);
683
+ $template_footer = str_replace("%POLL_ID%", $poll_question_id, $template_footer);
684
+ $template_footer = str_replace("%POLL_TOTALVOTES%", number_format_i18n($poll_question_totalvotes), $template_footer);
685
+ $template_footer = str_replace("%POLL_TOTALVOTERS%", number_format_i18n($poll_question_totalvoters), $template_footer);
686
+ $template_footer = str_replace("%POLL_MOST_ANSWER%", $poll_most_answer, $template_footer);
687
+ $template_footer = str_replace("%POLL_MOST_VOTES%", number_format_i18n($poll_most_votes), $template_footer);
688
+ $template_footer = str_replace("%POLL_MOST_PERCENTAGE%", $poll_most_percentage, $template_footer);
689
+ $template_footer = str_replace("%POLL_LEAST_ANSWER%", $poll_least_answer, $template_footer);
690
+ $template_footer = str_replace("%POLL_LEAST_VOTES%", number_format_i18n($poll_least_votes), $template_footer);
691
+ $template_footer = str_replace("%POLL_LEAST_PERCENTAGE%", $poll_least_percentage, $template_footer);
692
+ if($poll_multiple_ans > 0) {
693
+ $template_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", $poll_multiple_ans, $template_footer);
694
+ } else {
695
+ $template_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", '1', $template_footer);
696
+ }
697
+ // Print Out Results Footer Template
698
+ $temp_pollresult .= "\t\t$template_footer\n";
699
+ $temp_pollresult .= "\t\t<input type=\"hidden\" id=\"poll_{$poll_question_id}_nonce\" name=\"wp-polls-nonce\" value=\"".wp_create_nonce('poll_'.$poll_question_id.'-nonce')."\" />\n";
700
+ $temp_pollresult .= "</div>\n";
701
+ if($display_loading) {
702
+ $poll_ajax_style = get_option('poll_ajax_style');
703
+ if(intval($poll_ajax_style['loading']) == 1) {
704
+ $temp_pollresult .= "<div id=\"polls-$poll_question_id-loading\" class=\"wp-polls-loading\"><img src=\"".plugins_url('wp-polls/images/loading.gif')."\" width=\"16\" height=\"16\" alt=\"".__('Loading', 'wp-polls')." ...\" title=\"".__('Loading', 'wp-polls')." ...\" class=\"wp-polls-image\" />&nbsp;".__('Loading', 'wp-polls')." ...</div>\n";
705
+ }
706
+ }
707
+ } else {
708
+ $temp_pollresult .= stripslashes(get_option('poll_template_disable'));
709
+ }
710
+ // Return Poll Result
711
+ return $temp_pollresult;
712
  }
713
 
714
 
715
  ### Function: Get IP Address
716
  if(!function_exists('get_ipaddress')) {
717
+ function get_ipaddress() {
718
+ foreach ( array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
719
+ if ( array_key_exists( $key, $_SERVER ) === true ) {
720
+ foreach ( explode( ',', $_SERVER[$key] ) as $ip ) {
721
+ $ip = trim( $ip );
722
+ if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
723
+ return esc_attr( $ip );
724
+ }
725
+ }
726
+ }
727
+ }
728
+ }
729
  }
730
 
731
 
732
  ### Function: Short Code For Inserting Polls Archive Into Page
733
  add_shortcode('page_polls', 'poll_page_shortcode');
734
  function poll_page_shortcode($atts) {
735
+ return polls_archive();
736
  }
737
 
738
 
739
  ### Function: Short Code For Inserting Polls Into Posts
740
  add_shortcode( 'poll', 'poll_shortcode' );
741
  function poll_shortcode( $atts ) {
742
+ $attributes = shortcode_atts( array( 'id' => 0, 'type' => 'vote' ), $atts );
743
+ if( ! is_feed() ) {
744
+ $id = intval( $attributes['id'] );
745
+
746
+ // To maintain backward compatibility with [poll=1]. Props @tz-ua
747
+ if( ! $id && isset( $atts[0] ) ) {
748
+ $id = intval( trim( $atts[0], '="\'' ) );
749
+ }
750
+
751
+ if( $attributes['type'] === 'vote' ) {
752
+ return get_poll( $id, false );
753
+ } elseif( $attributes['type'] === 'result' ) {
754
+ return display_pollresult( $id );
755
+ }
756
+ } else {
757
+ return __( 'Note: There is a poll embedded within this post, please visit the site to participate in this post\'s poll.', 'wp-polls' );
758
+ }
759
  }
760
 
761
 
762
  ### Function: Get Poll Question Based On Poll ID
763
  if(!function_exists('get_poll_question')) {
764
+ function get_poll_question($poll_id) {
765
+ global $wpdb;
766
+ $poll_id = intval( $poll_id );
767
+ $poll_question = $wpdb->get_var( $wpdb->prepare( "SELECT pollq_question FROM $wpdb->pollsq WHERE pollq_id = %d LIMIT 1", $poll_id ) );
768
+ return wp_kses_post( stripslashes( $poll_question ) );
769
+ }
770
  }
771
 
772
 
773
  ### Function: Get Poll Total Questions
774
  if(!function_exists('get_pollquestions')) {
775
+ function get_pollquestions($display = true) {
776
+ global $wpdb;
777
+ $totalpollq = intval($wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq"));
778
+ if($display) {
779
+ echo $totalpollq;
780
+ } else {
781
+ return $totalpollq;
782
+ }
783
+ }
784
  }
785
 
786
 
787
  ### Function: Get Poll Total Answers
788
  if(!function_exists('get_pollanswers')) {
789
+ function get_pollanswers($display = true) {
790
+ global $wpdb;
791
+ $totalpolla = intval($wpdb->get_var("SELECT COUNT(polla_aid) FROM $wpdb->pollsa"));
792
+ if($display) {
793
+ echo $totalpolla;
794
+ } else {
795
+ return $totalpolla;
796
+ }
797
+ }
798
  }
799
 
800
 
801
  ### Function: Get Poll Total Votes
802
  if(!function_exists('get_pollvotes')) {
803
+ function get_pollvotes($display = true) {
804
+ global $wpdb;
805
+ $totalvotes = intval($wpdb->get_var("SELECT SUM(pollq_totalvotes) FROM $wpdb->pollsq"));
806
+ if($display) {
807
+ echo $totalvotes;
808
+ } else {
809
+ return $totalvotes;
810
+ }
811
+ }
812
  }
813
 
814
 
815
  ### Function: Get Poll Total Voters
816
  if(!function_exists('get_pollvoters')) {
817
+ function get_pollvoters($display = true) {
818
+ global $wpdb;
819
+ $totalvoters = intval($wpdb->get_var("SELECT SUM(pollq_totalvoters) FROM $wpdb->pollsq"));
820
+ if($display) {
821
+ echo $totalvoters;
822
+ } else {
823
+ return $totalvoters;
824
+ }
825
+ }
826
  }
827
 
828
 
829
  ### Function: Check Voted To Get Voted Answer
830
  function check_voted_multiple($poll_id, $polls_ips) {
831
+ if(!empty($_COOKIE["voted_$poll_id"])) {
832
+ return explode(',', $_COOKIE["voted_$poll_id"]);
833
+ } else {
834
+ if($polls_ips) {
835
+ return $polls_ips;
836
+ } else {
837
+ return array();
838
+ }
839
+ }
840
  }
841
 
842
 
843
  ### Function: Polls Archive Link
844
  function polls_archive_link($page) {
845
+ $polls_archive_url = get_option('poll_archive_url');
846
+ if($page > 0) {
847
+ if(strpos($polls_archive_url, '?') !== false) {
848
+ $polls_archive_url = "$polls_archive_url&amp;poll_page=$page";
849
+ } else {
850
+ $polls_archive_url = "$polls_archive_url?poll_page=$page";
851
+ }
852
+ }
853
+ return $polls_archive_url;
854
  }
855
 
856
 
857
  ### Function: Displays Polls Archive Link
858
  function display_polls_archive_link($display = true) {
859
+ $template_pollarchivelink = stripslashes(get_option('poll_template_pollarchivelink'));
860
+ $template_pollarchivelink = str_replace("%POLL_ARCHIVE_URL%", get_option('poll_archive_url'), $template_pollarchivelink);
861
+ if($display) {
862
+ echo $template_pollarchivelink;
863
+ } else{
864
+ return $template_pollarchivelink;
865
+ }
866
  }
867
 
868
 
869
  ### Function: Display Polls Archive
870
  function polls_archive() {
871
+ do_action('wp_polls_polls_archive');
872
+ global $wpdb, $in_pollsarchive;
873
+ // Polls Variables
874
+ $in_pollsarchive = true;
875
+ $page = isset($_GET['poll_page']) ? intval($_GET['poll_page']) : 0;
876
+ $polls_questions = array();
877
+ $polls_answers = array();
878
+ $polls_ips = array();
879
+ $polls_perpage = intval(get_option('poll_archive_perpage'));
880
+ $poll_questions_ids = '0';
881
+ $poll_voted = false;
882
+ $poll_voted_aid = 0;
883
+ $poll_id = 0;
884
+ $pollsarchive_output_archive = '';
885
+ $polls_type = intval(get_option('poll_archive_displaypoll'));
886
+ $polls_type_sql = '';
887
+ // Determine What Type Of Polls To Show
888
+ switch($polls_type) {
889
+ case 1:
890
+ $polls_type_sql = 'pollq_active = 0';
891
+ break;
892
+ case 2:
893
+ $polls_type_sql = 'pollq_active = 1';
894
+ break;
895
+ case 3:
896
+ $polls_type_sql = 'pollq_active IN (0,1)';
897
+ break;
898
+ }
899
+ // Get Total Polls
900
+ $total_polls = $wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq WHERE $polls_type_sql AND pollq_active != -1");
901
+
902
+ // Calculate Paging
903
+ $numposts = $total_polls;
904
+ $perpage = $polls_perpage;
905
+ $max_page = ceil($numposts/$perpage);
906
+ if(empty($page) || $page == 0) {
907
+ $page = 1;
908
+ }
909
+ $offset = ($page-1) * $perpage;
910
+ $pages_to_show = 10;
911
+ $pages_to_show_minus_1 = $pages_to_show-1;
912
+ $half_page_start = floor($pages_to_show_minus_1/2);
913
+ $half_page_end = ceil($pages_to_show_minus_1/2);
914
+ $start_page = $page - $half_page_start;
915
+ if($start_page <= 0) {
916
+ $start_page = 1;
917
+ }
918
+ $end_page = $page + $half_page_end;
919
+ if(($end_page - $start_page) != $pages_to_show_minus_1) {
920
+ $end_page = $start_page + $pages_to_show_minus_1;
921
+ }
922
+ if($end_page > $max_page) {
923
+ $start_page = $max_page - $pages_to_show_minus_1;
924
+ $end_page = $max_page;
925
+ }
926
+ if($start_page <= 0) {
927
+ $start_page = 1;
928
+ }
929
+ if(($offset + $perpage) > $numposts) {
930
+ $max_on_page = $numposts;
931
+ } else {
932
+ $max_on_page = ($offset + $perpage);
933
+ }
934
+ if (($offset + 1) > ($numposts)) {
935
+ $display_on_page = $numposts;
936
+ } else {
937
+ $display_on_page = ($offset + 1);
938
+ }
939
+
940
+ // Get Poll Questions
941
+ $questions = $wpdb->get_results("SELECT * FROM $wpdb->pollsq WHERE $polls_type_sql ORDER BY pollq_id DESC LIMIT $offset, $polls_perpage");
942
+ if($questions) {
943
+ foreach($questions as $question) {
944
+ $polls_questions[] = array('id' => intval($question->pollq_id), 'question' => wp_kses_post( stripslashes( $question->pollq_question ) ), 'timestamp' => $question->pollq_timestamp, 'totalvotes' => intval($question->pollq_totalvotes), 'start' => $question->pollq_timestamp, 'end' => trim($question->pollq_expiry), 'multiple' => intval($question->pollq_multiple), 'totalvoters' => intval($question->pollq_totalvoters));
945
+ $poll_questions_ids .= intval($question->pollq_id).', ';
946
+ }
947
+ $poll_questions_ids = substr($poll_questions_ids, 0, -2);
948
+ }
949
+
950
+ // Get Poll Answers
951
+ list($order_by, $sort_order) = _polls_get_ans_result_sort();
952
+ $answers = $wpdb->get_results("SELECT polla_aid, polla_qid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid IN ($poll_questions_ids) ORDER BY $order_by $sort_order");
953
+ if($answers) {
954
+ foreach($answers as $answer) {
955
+ $polls_answers[intval($answer->polla_qid)][] = array('aid' => intval($answer->polla_aid), 'qid' => intval($answer->polla_qid), 'answers' => wp_kses_post( stripslashes( $answer->polla_answers ) ), 'votes' => intval($answer->polla_votes));
956
+ }
957
+ }
958
+
959
+ // Get Poll IPs
960
+ $ips = $wpdb->get_results("SELECT pollip_qid, pollip_aid FROM $wpdb->pollsip WHERE pollip_qid IN ($poll_questions_ids) AND pollip_ip = '".get_ipaddress()."' ORDER BY pollip_qid ASC");
961
+ if($ips) {
962
+ foreach($ips as $ip) {
963
+ $polls_ips[intval($ip->pollip_qid)][] = intval($ip->pollip_aid);
964
+ }
965
+ }
966
+ // Poll Archives
967
+ $pollsarchive_output_archive .= "<div class=\"wp-polls wp-polls-archive\">\n";
968
+ foreach($polls_questions as $polls_question) {
969
+ // Most/Least Variables
970
+ $poll_most_answer = '';
971
+ $poll_most_votes = 0;
972
+ $poll_most_percentage = 0;
973
+ $poll_least_answer = '';
974
+ $poll_least_votes = 0;
975
+ $poll_least_percentage = 0;
976
+ // Is The Poll Total Votes 0?
977
+ $poll_totalvotes_zero = true;
978
+ if($polls_question['totalvotes'] > 0) {
979
+ $poll_totalvotes_zero = false;
980
+ }
981
+ $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']));
982
+ if(empty($polls_question['end'])) {
983
+ $poll_end_date = __('No Expiry', 'wp-polls');
984
+ } else {
985
+ $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']));
986
+ }
987
+ // Archive Poll Header
988
+ $template_archive_header = stripslashes(get_option('poll_template_pollarchiveheader'));
989
+ // Poll Question Variables
990
+ $template_question = stripslashes(get_option('poll_template_resultheader'));
991
+ $template_question = str_replace("%POLL_QUESTION%", $polls_question['question'], $template_question);
992
+ $template_question = str_replace("%POLL_ID%", $polls_question['id'], $template_question);
993
+ $template_question = str_replace("%POLL_TOTALVOTES%", number_format_i18n($polls_question['totalvotes']), $template_question);
994
+ $template_question = str_replace("%POLL_TOTALVOTERS%", number_format_i18n($polls_question['totalvoters']), $template_question);
995
+ $template_question = str_replace("%POLL_START_DATE%", $poll_start_date, $template_question);
996
+ $template_question = str_replace("%POLL_END_DATE%", $poll_end_date, $template_question);
997
+ if($polls_question['multiple'] > 0) {
998
+ $template_question = str_replace("%POLL_MULTIPLE_ANS_MAX%", $polls_question['multiple'], $template_question);
999
+ } else {
1000
+ $template_question = str_replace("%POLL_MULTIPLE_ANS_MAX%", '1', $template_question);
1001
+ }
1002
+ // Print Out Result Header Template
1003
+ $pollsarchive_output_archive .= $template_archive_header;
1004
+ $pollsarchive_output_archive .= $template_question;
1005
+ // Store The Percentage Of The Poll
1006
+ $poll_answer_percentage_array = array();
1007
+ foreach($polls_answers[$polls_question['id']] as $polls_answer) {
1008
+ // Calculate Percentage And Image Bar Width
1009
+ if(!$poll_totalvotes_zero) {
1010
+ if($polls_answer['votes'] > 0) {
1011
+ $poll_answer_percentage = round((($polls_answer['votes']/$polls_question['totalvoters'])*100));
1012
+ $poll_answer_imagewidth = round($poll_answer_percentage*0.9);
1013
+ } else {
1014
+ $poll_answer_percentage = 0;
1015
+ $poll_answer_imagewidth = 1;
1016
+ }
1017
+ } else {
1018
+ $poll_answer_percentage = 0;
1019
+ $poll_answer_imagewidth = 1;
1020
+ }
1021
+ // Make Sure That Total Percentage Is 100% By Adding A Buffer To The Last Poll Answer
1022
+ if($polls_question['multiple'] == 0) {
1023
+ $poll_answer_percentage_array[] = $poll_answer_percentage;
1024
+ if(sizeof($poll_answer_percentage_array) == sizeof($polls_answers[$polls_question['id']])) {
1025
+ $percentage_error_buffer = 100 - array_sum($poll_answer_percentage_array);
1026
+ $poll_answer_percentage = $poll_answer_percentage + $percentage_error_buffer;
1027
+ if($poll_answer_percentage < 0) {
1028
+ $poll_answer_percentage = 0;
1029
+ }
1030
+ }
1031
+ }
1032
+ $polls_answer['answers'] = wp_kses_post( $polls_answer['answers'] );
1033
+ // Let User See What Options They Voted
1034
+ if(isset($polls_ips[$polls_question['id']]) && in_array($polls_answer['aid'], check_voted_multiple($polls_question['id'], $polls_ips[$polls_question['id']]))) {
1035
+ // Results Body Variables
1036
+ $template_answer = stripslashes(get_option('poll_template_resultbody2'));
1037
+ $template_answer = str_replace("%POLL_ID%", $polls_question['id'], $template_answer);
1038
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $polls_answer['aid'], $template_answer);
1039
+ $template_answer = str_replace("%POLL_ANSWER%", $polls_answer['answers'], $template_answer);
1040
+ $template_answer = str_replace("%POLL_ANSWER_TEXT%", htmlspecialchars(strip_tags($polls_answer['answers'])), $template_answer);
1041
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format_i18n($polls_answer['votes']), $template_answer);
1042
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
1043
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
1044
+ // Print Out Results Body Template
1045
+ $pollsarchive_output_archive .= $template_answer;
1046
+ } else {
1047
+ // Results Body Variables
1048
+ $template_answer = stripslashes(get_option('poll_template_resultbody'));
1049
+ $template_answer = str_replace("%POLL_ID%", $polls_question['id'], $template_answer);
1050
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $polls_answer['aid'], $template_answer);
1051
+ $template_answer = str_replace("%POLL_ANSWER%", $polls_answer['answers'], $template_answer);
1052
+ $template_answer = str_replace("%POLL_ANSWER_TEXT%", htmlspecialchars(strip_tags($polls_answer['answers'])), $template_answer);
1053
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format_i18n($polls_answer['votes']), $template_answer);
1054
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
1055
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
1056
+ // Print Out Results Body Template
1057
+ $pollsarchive_output_archive .= $template_answer;
1058
+ }
1059
+ // Get Most Voted Data
1060
+ if($polls_answer['votes'] > $poll_most_votes) {
1061
+ $poll_most_answer = $polls_answer['answers'];
1062
+ $poll_most_votes = $polls_answer['votes'];
1063
+ $poll_most_percentage = $poll_answer_percentage;
1064
+ }
1065
+ // Get Least Voted Data
1066
+ if($poll_least_votes == 0) {
1067
+ $poll_least_votes = $polls_answer['votes'];
1068
+ }
1069
+ if($polls_answer['votes'] <= $poll_least_votes) {
1070
+ $poll_least_answer = $polls_answer['answers'];
1071
+ $poll_least_votes = $polls_answer['votes'];
1072
+ $poll_least_percentage = $poll_answer_percentage;
1073
+ }
1074
+ }
1075
+ // Results Footer Variables
1076
+ $template_footer = stripslashes(get_option('poll_template_resultfooter'));
1077
+ $template_footer = str_replace("%POLL_ID%", $polls_question['id'], $template_footer);
1078
+ $template_footer = str_replace("%POLL_START_DATE%", $poll_start_date, $template_footer);
1079
+ $template_footer = str_replace("%POLL_END_DATE%", $poll_end_date, $template_footer);
1080
+ $template_footer = str_replace("%POLL_TOTALVOTES%", number_format_i18n($polls_question['totalvotes']), $template_footer);
1081
+ $template_footer = str_replace("%POLL_TOTALVOTERS%", number_format_i18n($polls_question['totalvoters']), $template_footer);
1082
+ $template_footer = str_replace("%POLL_MOST_ANSWER%", $poll_most_answer, $template_footer);
1083
+ $template_footer = str_replace("%POLL_MOST_VOTES%", number_format_i18n($poll_most_votes), $template_footer);
1084
+ $template_footer = str_replace("%POLL_MOST_PERCENTAGE%", $poll_most_percentage, $template_footer);
1085
+ $template_footer = str_replace("%POLL_LEAST_ANSWER%", $poll_least_answer, $template_footer);
1086
+ $template_footer = str_replace("%POLL_LEAST_VOTES%", number_format_i18n($poll_least_votes), $template_footer);
1087
+ $template_footer = str_replace("%POLL_LEAST_PERCENTAGE%", $poll_least_percentage, $template_footer);
1088
+ if($polls_question['multiple'] > 0) {
1089
+ $template_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", $polls_question['multiple'], $template_footer);
1090
+ } else {
1091
+ $template_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", '1', $template_footer);
1092
+ }
1093
+ // Archive Poll Footer
1094
+ $template_archive_footer = stripslashes(get_option('poll_template_pollarchivefooter'));
1095
+ $template_archive_footer = str_replace("%POLL_START_DATE%", $poll_start_date, $template_archive_footer);
1096
+ $template_archive_footer = str_replace("%POLL_END_DATE%", $poll_end_date, $template_archive_footer);
1097
+ $template_archive_footer = str_replace("%POLL_TOTALVOTES%", number_format_i18n($polls_question['totalvotes']), $template_archive_footer);
1098
+ $template_archive_footer = str_replace("%POLL_TOTALVOTERS%", number_format_i18n($polls_question['totalvoters']), $template_archive_footer);
1099
+ $template_archive_footer = str_replace("%POLL_MOST_ANSWER%", $poll_most_answer, $template_archive_footer);
1100
+ $template_archive_footer = str_replace("%POLL_MOST_VOTES%", number_format_i18n($poll_most_votes), $template_archive_footer);
1101
+ $template_archive_footer = str_replace("%POLL_MOST_PERCENTAGE%", $poll_most_percentage, $template_archive_footer);
1102
+ $template_archive_footer = str_replace("%POLL_LEAST_ANSWER%", $poll_least_answer, $template_archive_footer);
1103
+ $template_archive_footer = str_replace("%POLL_LEAST_VOTES%", number_format_i18n($poll_least_votes), $template_archive_footer);
1104
+ $template_archive_footer = str_replace("%POLL_LEAST_PERCENTAGE%", $poll_least_percentage, $template_archive_footer);
1105
+ if($polls_question['multiple'] > 0) {
1106
+ $template_archive_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", $polls_question['multiple'], $template_archive_footer);
1107
+ } else {
1108
+ $template_archive_footer = str_replace("%POLL_MULTIPLE_ANS_MAX%", '1', $template_archive_footer);
1109
+ }
1110
+ // Print Out Results Footer Template
1111
+ $pollsarchive_output_archive .= $template_footer;
1112
+ // Print Out Archive Poll Footer Template
1113
+ $pollsarchive_output_archive .= $template_archive_footer;
1114
+ }
1115
+ $pollsarchive_output_archive .= "</div>\n";
1116
+
1117
+ // Polls Archive Paging
1118
+ if($max_page > 1) {
1119
+ $pollsarchive_output_archive .= stripslashes(get_option('poll_template_pollarchivepagingheader'));
1120
+ if(function_exists('wp_pagenavi')) {
1121
+ $pollsarchive_output_archive .= '<div class="wp-pagenavi">'."\n";
1122
+ } else {
1123
+ $pollsarchive_output_archive .= '<div class="wp-polls-paging">'."\n";
1124
+ }
1125
+ $pollsarchive_output_archive .= '<span class="pages">&#8201;'.sprintf(__('Page %s of %s', 'wp-polls'), number_format_i18n($page), number_format_i18n($max_page)).'&#8201;</span>';
1126
+ if ($start_page >= 2 && $pages_to_show < $max_page) {
1127
+ $pollsarchive_output_archive .= '<a href="'.polls_archive_link(1).'" title="'.__('&laquo; First', 'wp-polls').'">&#8201;'.__('&laquo; First', 'wp-polls').'&#8201;</a>';
1128
+ $pollsarchive_output_archive .= '<span class="extend">...</span>';
1129
+ }
1130
+ if($page > 1) {
1131
+ $pollsarchive_output_archive .= '<a href="'.polls_archive_link(($page-1)).'" title="'.__('&laquo;', 'wp-polls').'">&#8201;'.__('&laquo;', 'wp-polls').'&#8201;</a>';
1132
+ }
1133
+ for($i = $start_page; $i <= $end_page; $i++) {
1134
+ if($i == $page) {
1135
+ $pollsarchive_output_archive .= '<span class="current">&#8201;'.number_format_i18n($i).'&#8201;</span>';
1136
+ } else {
1137
+ $pollsarchive_output_archive .= '<a href="'.polls_archive_link($i).'" title="'.number_format_i18n($i).'">&#8201;'.number_format_i18n($i).'&#8201;</a>';
1138
+ }
1139
+ }
1140
+ if(empty($page) || ($page+1) <= $max_page) {
1141
+ $pollsarchive_output_archive .= '<a href="'.polls_archive_link(($page+1)).'" title="'.__('&raquo;', 'wp-polls').'">&#8201;'.__('&raquo;', 'wp-polls').'&#8201;</a>';
1142
+ }
1143
+ if ($end_page < $max_page) {
1144
+ $pollsarchive_output_archive .= '<span class="extend">...</span>';
1145
+ $pollsarchive_output_archive .= '<a href="'.polls_archive_link($max_page).'" title="'.__('Last &raquo;', 'wp-polls').'">&#8201;'.__('Last &raquo;', 'wp-polls').'&#8201;</a>';
1146
+ }
1147
+ $pollsarchive_output_archive .= '</div>';
1148
+ $pollsarchive_output_archive .= stripslashes(get_option('poll_template_pollarchivepagingfooter'));
1149
+ }
1150
+
1151
+ // Output Polls Archive Page
1152
+ return apply_filters('polls_archive', $pollsarchive_output_archive);
1153
  }
1154
 
1155
 
1156
  // Edit Timestamp Options
1157
  function poll_timestamp($poll_timestamp, $fieldname = 'pollq_timestamp', $display = 'block') {
1158
+ global $month;
1159
+ echo '<div id="'.$fieldname.'" style="display: '.$display.'">'."\n";
1160
+ $day = gmdate('j', $poll_timestamp);
1161
+ echo '<select name="'.$fieldname.'_day" size="1">'."\n";
1162
+ for($i = 1; $i <=31; $i++) {
1163
+ if($day == $i) {
1164
+ echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
1165
+ } else {
1166
+ echo "<option value=\"$i\">$i</option>\n";
1167
+ }
1168
+ }
1169
+ echo '</select>&nbsp;&nbsp;'."\n";
1170
+ $month2 = gmdate('n', $poll_timestamp);
1171
+ echo '<select name="'.$fieldname.'_month" size="1">'."\n";
1172
+ for($i = 1; $i <= 12; $i++) {
1173
+ if ($i < 10) {
1174
+ $ii = '0'.$i;
1175
+ } else {
1176
+ $ii = $i;
1177
+ }
1178
+ if($month2 == $i) {
1179
+ echo "<option value=\"$i\" selected=\"selected\">$month[$ii]</option>\n";
1180
+ } else {
1181
+ echo "<option value=\"$i\">$month[$ii]</option>\n";
1182
+ }
1183
+ }
1184
+ echo '</select>&nbsp;&nbsp;'."\n";
1185
+ $year = gmdate('Y', $poll_timestamp);
1186
+ echo '<select name="'.$fieldname.'_year" size="1">'."\n";
1187
+ for($i = 2000; $i <= ($year+10); $i++) {
1188
+ if($year == $i) {
1189
+ echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
1190
+ } else {
1191
+ echo "<option value=\"$i\">$i</option>\n";
1192
+ }
1193
+ }
1194
+ echo '</select>&nbsp;@'."\n";
1195
+ echo '<span dir="ltr">'."\n";
1196
+ $hour = gmdate('H', $poll_timestamp);
1197
+ echo '<select name="'.$fieldname.'_hour" size="1">'."\n";
1198
+ for($i = 0; $i < 24; $i++) {
1199
+ if($hour == $i) {
1200
+ echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
1201
+ } else {
1202
+ echo "<option value=\"$i\">$i</option>\n";
1203
+ }
1204
+ }
1205
+ echo '</select>&nbsp;:'."\n";
1206
+ $minute = gmdate('i', $poll_timestamp);
1207
+ echo '<select name="'.$fieldname.'_minute" size="1">'."\n";
1208
+ for($i = 0; $i < 60; $i++) {
1209
+ if($minute == $i) {
1210
+ echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
1211
+ } else {
1212
+ echo "<option value=\"$i\">$i</option>\n";
1213
+ }
1214
+ }
1215
+
1216
+ echo '</select>&nbsp;:'."\n";
1217
+ $second = gmdate('s', $poll_timestamp);
1218
+ echo '<select name="'.$fieldname.'_second" size="1">'."\n";
1219
+ for($i = 0; $i <= 60; $i++) {
1220
+ if($second == $i) {
1221
+ echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
1222
+ } else {
1223
+ echo "<option value=\"$i\">$i</option>\n";
1224
+ }
1225
+ }
1226
+ echo '</select>'."\n";
1227
+ echo '</span>'."\n";
1228
+ echo '</div>'."\n";
1229
  }
1230
 
1231
 
1232
  ### Function: Place Cron
1233
  function cron_polls_place() {
1234
+ wp_clear_scheduled_hook('polls_cron');
1235
+ if (!wp_next_scheduled('polls_cron')) {
1236
+ wp_schedule_event(time(), 'twicedaily', 'polls_cron');
1237
+ }
1238
  }
1239
 
1240
 
1241
  ### Funcion: Check All Polls Status To Check If It Expires
1242
  add_action('polls_cron', 'cron_polls_status');
1243
  function cron_polls_status() {
1244
+ global $wpdb;
1245
+ // Close Poll
1246
+ $close_polls = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_active = 0 WHERE pollq_expiry < '".current_time('timestamp')."' AND pollq_expiry != '' AND pollq_active != 0");
1247
+ // Open Future Polls
1248
+ $active_polls = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_active = 1 WHERE pollq_timestamp <= '".current_time('timestamp')."' AND pollq_active = -1");
1249
+ // Update Latest Poll If Future Poll Is Opened
1250
+ if($active_polls) {
1251
+ $update_latestpoll = update_option('poll_latestpoll', polls_latest_id());
1252
+ }
1253
+ return;
1254
  }
1255
 
1256
 
1257
  ### Funcion: Get Latest Poll ID
1258
  function polls_latest_id() {
1259
+ global $wpdb;
1260
+ $poll_id = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq WHERE pollq_active = 1 ORDER BY pollq_timestamp DESC LIMIT 1");
1261
+ return intval($poll_id);
1262
  }
1263
 
1264
 
1265
  ### Check If In Poll Archive Page
1266
  function in_pollarchive() {
1267
+ $poll_archive_url = get_option('poll_archive_url');
1268
+ $poll_archive_url_array = explode('/', $poll_archive_url);
1269
+ $poll_archive_url = $poll_archive_url_array[sizeof($poll_archive_url_array)-1];
1270
+ if(empty($poll_archive_url)) {
1271
+ $poll_archive_url = $poll_archive_url_array[sizeof($poll_archive_url_array)-2];
1272
+ }
1273
+ $current_url = $_SERVER['REQUEST_URI'];
1274
+ if(strpos($current_url, $poll_archive_url) === false) {
1275
+ return false;
1276
+ } else {
1277
+ return true;
1278
+ }
1279
  }
1280
 
1281
 
1283
  add_action('wp_ajax_polls', 'vote_poll');
1284
  add_action('wp_ajax_nopriv_polls', 'vote_poll');
1285
  function vote_poll() {
1286
+ global $wpdb, $user_identity, $user_ID;
1287
+
1288
+ if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'polls')
1289
+ {
1290
+ // Load Headers
1291
+ polls_textdomain();
1292
+ header('Content-Type: text/html; charset='.get_option('blog_charset').'');
1293
+
1294
+ // Get Poll ID
1295
+ $poll_id = (isset($_REQUEST['poll_id']) ? intval($_REQUEST['poll_id']) : 0);
1296
+
1297
+ // Ensure Poll ID Is Valid
1298
+ if($poll_id == 0)
1299
+ {
1300
+ _e('Invalid Poll ID', 'wp-polls');
1301
+ exit();
1302
+ }
1303
+
1304
+ // Verify Referer
1305
+ if(!check_ajax_referer('poll_'.$poll_id.'-nonce', 'poll_'.$poll_id.'_nonce', false))
1306
+ {
1307
+ _e('Failed To Verify Referrer', 'wp-polls');
1308
+ exit();
1309
+ }
1310
+
1311
+ // Which View
1312
+ switch($_REQUEST['view'])
1313
+ {
1314
+ // Poll Vote
1315
+ case 'process':
1316
+ do_action('wp_polls_vote_poll');
1317
+ $poll_aid = $_POST["poll_$poll_id"];
1318
+ $poll_aid_array = array_unique(array_map('intval', explode(',', $poll_aid)));
1319
+ if($poll_id > 0 && !empty($poll_aid_array) && check_allowtovote()) {
1320
+ $is_poll_open = intval( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->pollsq WHERE pollq_id = %d AND pollq_active = 1", $poll_id ) ) );
1321
+ if ( $is_poll_open > 0 ) {
1322
+ $check_voted = check_voted($poll_id);
1323
+ if ($check_voted == 0) {
1324
+ if (!empty($user_identity)) {
1325
+ $pollip_user = htmlspecialchars(addslashes($user_identity));
1326
+ } elseif (!empty($_COOKIE['comment_author_' . COOKIEHASH])) {
1327
+ $pollip_user = htmlspecialchars(addslashes($_COOKIE['comment_author_' . COOKIEHASH]));
1328
+ } else {
1329
+ $pollip_user = __('Guest', 'wp-polls');
1330
+ }
1331
+ $pollip_userid = intval($user_ID);
1332
+ $pollip_ip = get_ipaddress();
1333
+ $pollip_host = @gethostbyaddr($pollip_ip);
1334
+ $pollip_timestamp = current_time('timestamp');
1335
+ // Only Create Cookie If User Choose Logging Method 1 Or 2
1336
+ $poll_logging_method = intval(get_option('poll_logging_method'));
1337
+ if ($poll_logging_method == 1 || $poll_logging_method == 3) {
1338
+ $cookie_expiry = intval(get_option('poll_cookielog_expiry'));
1339
+ if ($cookie_expiry == 0) {
1340
+ $cookie_expiry = 30000000;
1341
+ }
1342
+ $vote_cookie = setcookie('voted_' . $poll_id, $poll_aid, ($pollip_timestamp + $cookie_expiry), apply_filters('wp_polls_cookiepath', SITECOOKIEPATH));
1343
+ }
1344
+ $i = 0;
1345
+ foreach ($poll_aid_array as $polla_aid) {
1346
+ $update_polla_votes = $wpdb->query( "UPDATE $wpdb->pollsa SET polla_votes = (polla_votes + 1) WHERE polla_qid = $poll_id AND polla_aid = $polla_aid" );
1347
+ if (!$update_polla_votes) {
1348
+ unset($poll_aid_array[$i]);
1349
+ }
1350
+ $i++;
1351
+ }
1352
+ $vote_q = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes+" . sizeof( $poll_aid_array ) . "), pollq_totalvoters = (pollq_totalvoters + 1) WHERE pollq_id = $poll_id AND pollq_active = 1");
1353
+ if ($vote_q) {
1354
+ foreach ($poll_aid_array as $polla_aid) {
1355
+ $wpdb->insert(
1356
+ $wpdb->pollsip,
1357
+ array(
1358
+ 'pollip_qid' => $poll_id,
1359
+ 'pollip_aid' => $polla_aid,
1360
+ 'pollip_ip' => $pollip_ip,
1361
+ 'pollip_host' => $pollip_host,
1362
+ 'pollip_timestamp' => $pollip_timestamp,
1363
+ 'pollip_user' => $pollip_user,
1364
+ 'pollip_userid' => $pollip_userid
1365
+ ),
1366
+ array(
1367
+ '%s',
1368
+ '%s',
1369
+ '%s',
1370
+ '%s',
1371
+ '%s',
1372
+ '%s',
1373
+ '%d'
1374
+ )
1375
+ );
1376
+ }
1377
+ echo display_pollresult($poll_id, $poll_aid_array, false);
1378
+ do_action( 'wp_polls_vote_poll_success' );
1379
+ } else {
1380
+ printf(__('Unable To Update Poll Total Votes And Poll Total Voters. Poll ID #%s', 'wp-polls'), $poll_id);
1381
+ } // End if($vote_a)
1382
+ } else {
1383
+ printf(__('You Had Already Voted For This Poll. Poll ID #%s', 'wp-polls'), $poll_id);
1384
+ } // End if($check_voted)
1385
+ } else {
1386
+ printf( __( 'Poll ID #%s is closed', 'wp-polls' ), $poll_id );
1387
+ } // End if($is_poll_open > 0)
1388
+ } else {
1389
+ printf(__('Invalid Poll ID. Poll ID #%s', 'wp-polls'), $poll_id);
1390
+ } // End if($poll_id > 0 && !empty($poll_aid_array) && check_allowtovote())
1391
+ break;
1392
+ // Poll Result
1393
+ case 'result':
1394
+ echo display_pollresult($poll_id, 0, false);
1395
+ break;
1396
+ // Poll Booth Aka Poll Voting Form
1397
+ case 'booth':
1398
+ echo display_pollvote($poll_id, false);
1399
+ break;
1400
+ } // End switch($_REQUEST['view'])
1401
+ } // End if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'polls')
1402
+ exit();
1403
  }
1404
 
1405
 
1406
  ### Function: Manage Polls
1407
  add_action('wp_ajax_polls-admin', 'manage_poll');
1408
  function manage_poll() {
1409
+ global $wpdb;
1410
+ ### Form Processing
1411
+ if(isset($_POST['action']) && $_POST['action'] == 'polls-admin')
1412
+ {
1413
+ if(!empty($_POST['do'])) {
1414
+ // Set Header
1415
+ header('Content-Type: text/html; charset='.get_option('blog_charset').'');
1416
+
1417
+ // Decide What To Do
1418
+ switch($_POST['do']) {
1419
+ // Delete Polls Logs
1420
+ case __('Delete All Logs', 'wp-polls'):
1421
+ check_ajax_referer('wp-polls_delete-polls-logs');
1422
+ if(trim($_POST['delete_logs_yes']) == 'yes') {
1423
+ $delete_logs = $wpdb->query("DELETE FROM $wpdb->pollsip");
1424
+ if($delete_logs) {
1425
+ echo '<p style="color: green;">'.__('All Polls Logs Have Been Deleted.', 'wp-polls').'</p>';
1426
+ } else {
1427
+ echo '<p style="color: red;">'.__('An Error Has Occurred While Deleting All Polls Logs.', 'wp-polls').'</p>';
1428
+ }
1429
+ }
1430
+ break;
1431
+ // Delete Poll Logs For Individual Poll
1432
+ case __('Delete Logs For This Poll Only', 'wp-polls'):
1433
+ check_ajax_referer('wp-polls_delete-poll-logs');
1434
+ $pollq_id = intval($_POST['pollq_id']);
1435
+ $pollq_question = $wpdb->get_var( $wpdb->prepare( "SELECT pollq_question FROM $wpdb->pollsq WHERE pollq_id = %d", $pollq_id ) );
1436
+ if(trim($_POST['delete_logs_yes']) == 'yes') {
1437
+ $delete_logs = $wpdb->delete( $wpdb->pollsip, array( 'pollip_qid' => $pollq_id ), array( '%d' ) );
1438
+ if( $delete_logs ) {
1439
+ echo '<p style="color: green;">'.sprintf(__('All Logs For \'%s\' Has Been Deleted.', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1440
+ } else {
1441
+ echo '<p style="color: red;">'.sprintf(__('An Error Has Occurred While Deleting All Logs For \'%s\'', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1442
+ }
1443
+ }
1444
+ break;
1445
+ // Delete Poll's Answer
1446
+ case __('Delete Poll Answer', 'wp-polls'):
1447
+ check_ajax_referer('wp-polls_delete-poll-answer');
1448
+ $pollq_id = intval($_POST['pollq_id']);
1449
+ $polla_aid = intval($_POST['polla_aid']);
1450
+ $poll_answers = $wpdb->get_row( $wpdb->prepare( "SELECT polla_votes, polla_answers FROM $wpdb->pollsa WHERE polla_aid = %d AND polla_qid = %d", $polla_aid, $pollq_id ) );
1451
+ $polla_votes = intval($poll_answers->polla_votes);
1452
+ $polla_answers = wp_kses_post( stripslashes( trim( $poll_answers->polla_answers ) ) );
1453
+ $delete_polla_answers = $wpdb->delete( $wpdb->pollsa, array( 'polla_aid' => $polla_aid, 'polla_qid' => $pollq_id ), array( '%d', '%d' ) );
1454
+ $delete_pollip = $wpdb->delete( $wpdb->pollsip, array( 'pollip_qid' => $pollq_id, 'pollip_aid' => $polla_aid ), array( '%d', '%d' ) );
1455
+ $update_pollq_totalvotes = $wpdb->query( "UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes - $polla_votes) WHERE pollq_id = $pollq_id" );
1456
+ if($delete_polla_answers) {
1457
+ echo '<p style="color: green;">'.sprintf(__('Poll Answer \'%s\' Deleted Successfully.', 'wp-polls'), $polla_answers).'</p>';
1458
+ } else {
1459
+ echo '<p style="color: red;">'.sprintf(__('Error In Deleting Poll Answer \'%s\'.', 'wp-polls'), $polla_answers).'</p>';
1460
+ }
1461
+ break;
1462
+ // Open Poll
1463
+ case __('Open Poll', 'wp-polls'):
1464
+ check_ajax_referer('wp-polls_open-poll');
1465
+ $pollq_id = intval($_POST['pollq_id']);
1466
+ $pollq_question = $wpdb->get_var( $wpdb->prepare( "SELECT pollq_question FROM $wpdb->pollsq WHERE pollq_id = %d", $pollq_id ) );
1467
+ $open_poll = $wpdb->update(
1468
+ $wpdb->pollsq,
1469
+ array(
1470
+ 'pollq_active' => 1
1471
+ ),
1472
+ array(
1473
+ 'pollq_id' => $pollq_id
1474
+ ),
1475
+ array(
1476
+ '%d'
1477
+ ),
1478
+ array(
1479
+ '%d'
1480
+ )
1481
+ );
1482
+ if( $open_poll ) {
1483
+ echo '<p style="color: green;">'.sprintf(__('Poll \'%s\' Is Now Opened', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1484
+ } else {
1485
+ echo '<p style="color: red;">'.sprintf(__('Error Opening Poll \'%s\'', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1486
+ }
1487
+ break;
1488
+ // Close Poll
1489
+ case __('Close Poll', 'wp-polls'):
1490
+ check_ajax_referer('wp-polls_close-poll');
1491
+ $pollq_id = intval($_POST['pollq_id']);
1492
+ $pollq_question = $wpdb->get_var( $wpdb->prepare( "SELECT pollq_question FROM $wpdb->pollsq WHERE pollq_id = %d", $pollq_id ) );
1493
+ $close_poll = $wpdb->update(
1494
+ $wpdb->pollsq,
1495
+ array(
1496
+ 'pollq_active' => 0
1497
+ ),
1498
+ array(
1499
+ 'pollq_id' => $pollq_id
1500
+ ),
1501
+ array(
1502
+ '%d'
1503
+ ),
1504
+ array(
1505
+ '%d'
1506
+ )
1507
+ );
1508
+ if( $close_poll ) {
1509
+ echo '<p style="color: green;">'.sprintf(__('Poll \'%s\' Is Now Closed', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1510
+ } else {
1511
+ echo '<p style="color: red;">'.sprintf(__('Error Closing Poll \'%s\'', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1512
+ }
1513
+ break;
1514
+ // Delete Poll
1515
+ case __('Delete Poll', 'wp-polls'):
1516
+ check_ajax_referer('wp-polls_delete-poll');
1517
+ $pollq_id = intval($_POST['pollq_id']);
1518
+ $pollq_question = $wpdb->get_var( $wpdb->prepare( "SELECT pollq_question FROM $wpdb->pollsq WHERE pollq_id = %d", $pollq_id ) );
1519
+ $delete_poll_question = $wpdb->delete( $wpdb->pollsq, array( 'pollq_id' => $pollq_id ), array( '%d' ) );
1520
+ $delete_poll_answers = $wpdb->delete( $wpdb->pollsa, array( 'polla_qid' => $pollq_id ), array( '%d' ) );
1521
+ $delete_poll_ip = $wpdb->delete( $wpdb->pollsip, array( 'pollip_qid' => $pollq_id ), array( '%d' ) );
1522
+ $poll_option_lastestpoll = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'poll_latestpoll'");
1523
+ if(!$delete_poll_question) {
1524
+ echo '<p style="color: red;">'.sprintf(__('Error In Deleting Poll \'%s\' Question', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1525
+ }
1526
+ if(empty($text)) {
1527
+ echo '<p style="color: green;">'.sprintf(__('Poll \'%s\' Deleted Successfully', 'wp-polls'), wp_kses_post( stripslashes( $pollq_question ) ) ).'</p>';
1528
+ }
1529
+ // Update Lastest Poll ID To Poll Options
1530
+ $latest_pollid = polls_latest_id();
1531
+ $update_latestpoll = update_option('poll_latestpoll', $latest_pollid);
1532
+ do_action( 'wp_polls_delete_poll', $pollq_id );
1533
+ break;
1534
+ }
1535
+ exit();
1536
+ }
1537
+ }
1538
+ }
1539
+
1540
+
1541
+ function _polls_get_ans_sort() {
1542
+ $order_by = get_option( 'poll_ans_sortby' );
1543
+ switch( $order_by ) {
1544
+ case 'polla_aid':
1545
+ case 'polla_answers':
1546
+ case 'RAND()':
1547
+ break;
1548
+ default:
1549
+ $order_by = 'polla_aid';
1550
+ break;
1551
+ }
1552
+ $sort_order = get_option( 'poll_ans_sortorder' ) === 'desc' ? 'desc' : 'asc';
1553
+ return array( $order_by, $sort_order );
1554
+ }
1555
+
1556
+ function _polls_get_ans_result_sort() {
1557
+ $order_by = get_option( 'poll_ans_result_sortby' );
1558
+ switch( $order_by ) {
1559
+ case 'polla_votes':
1560
+ case 'polla_aid':
1561
+ case 'polla_answers':
1562
+ case 'RAND()':
1563
+ break;
1564
+ default:
1565
+ $order_by = 'polla_aid';
1566
+ break;
1567
+ }
1568
+ $sort_order = get_option( 'poll_ans_result_sortorder' ) === 'desc' ? 'desc' : 'asc';
1569
+ return array( $order_by, $sort_order );
1570
  }
1571
 
1572
 
1573
  ### Function: Plug Into WP-Stats
1574
  add_action( 'plugins_loaded','polls_wp_stats' );
1575
  function polls_wp_stats() {
1576
+ add_filter( 'wp_stats_page_admin_plugins', 'polls_page_admin_general_stats' );
1577
+ add_filter( 'wp_stats_page_plugins', 'polls_page_general_stats' );
1578
  }
1579
 
1580
 
1581
  ### Function: Add WP-Polls General Stats To WP-Stats Page Options
1582
  function polls_page_admin_general_stats($content) {
1583
+ $stats_display = get_option('stats_display');
1584
+ if($stats_display['polls'] == 1) {
1585
+ $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_polls" value="polls" checked="checked" />&nbsp;&nbsp;<label for="wpstats_polls">'.__('WP-Polls', 'wp-polls').'</label><br />'."\n";
1586
+ } else {
1587
+ $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_polls" value="polls" />&nbsp;&nbsp;<label for="wpstats_polls">'.__('WP-Polls', 'wp-polls').'</label><br />'."\n";
1588
+ }
1589
+ return $content;
1590
  }
1591
 
1592
 
1593
  ### Function: Add WP-Polls General Stats To WP-Stats Page
1594
  function polls_page_general_stats($content) {
1595
+ $stats_display = get_option('stats_display');
1596
+ if($stats_display['polls'] == 1) {
1597
+ $content .= '<p><strong>'.__('WP-Polls', 'wp-polls').'</strong></p>'."\n";
1598
+ $content .= '<ul>'."\n";
1599
+ $content .= '<li>'.sprintf(_n('<strong>%s</strong> poll was created.', '<strong>%s</strong> polls were created.', get_pollquestions(false), 'wp-polls'), number_format_i18n(get_pollquestions(false))).'</li>'."\n";
1600
+ $content .= '<li>'.sprintf(_n('<strong>%s</strong> polls\' answer was given.', '<strong>%s</strong> polls\' answers were given.', get_pollanswers(false), 'wp-polls'), number_format_i18n(get_pollanswers(false))).'</li>'."\n";
1601
+ $content .= '<li>'.sprintf(_n('<strong>%s</strong> vote was cast.', '<strong>%s</strong> votes were cast.', get_pollvotes(false), 'wp-polls'), number_format_i18n(get_pollvotes(false))).'</li>'."\n";
1602
+ $content .= '</ul>'."\n";
1603
+ }
1604
+ return $content;
1605
  }
1606
 
1607
 
1608
  ### Class: WP-Polls Widget
1609
  class WP_Widget_Polls extends WP_Widget {
1610
+ // Constructor
1611
+ function __construct() {
1612
+ $widget_ops = array('description' => __('WP-Polls polls', 'wp-polls'));
1613
+ parent::__construct('polls-widget', __('Polls', 'wp-polls'), $widget_ops);
1614
+ }
1615
+
1616
+ // Display Widget
1617
+ function widget( $args, $instance ) {
1618
+ $title = apply_filters( 'widget_title', esc_attr( $instance['title'] ) );
1619
+ $poll_id = intval( $instance['poll_id'] );
1620
+ $display_pollarchive = intval( $instance['display_pollarchive'] );
1621
+ echo $args['before_widget'];
1622
+ if( ! empty( $title ) ) {
1623
+ echo $args['before_title'] . $title . $args['after_title'];
1624
+ }
1625
+ get_poll( $poll_id );
1626
+ if( $display_pollarchive ) {
1627
+ display_polls_archive_link();
1628
+ }
1629
+ echo $args['after_widget'];
1630
+ }
1631
+
1632
+ // When Widget Control Form Is Posted
1633
+ function update($new_instance, $old_instance) {
1634
+ if (!isset($new_instance['submit'])) {
1635
+ return false;
1636
+ }
1637
+ $instance = $old_instance;
1638
+ $instance['title'] = strip_tags($new_instance['title']);
1639
+ $instance['poll_id'] = intval($new_instance['poll_id']);
1640
+ $instance['display_pollarchive'] = intval($new_instance['display_pollarchive']);
1641
+ return $instance;
1642
+ }
1643
+
1644
+ // DIsplay Widget Control Form
1645
+ function form($instance) {
1646
+ global $wpdb;
1647
+ $instance = wp_parse_args((array) $instance, array('title' => __('Polls', 'wp-polls'), 'poll_id' => 0, 'display_pollarchive' => 1));
1648
+ $title = esc_attr($instance['title']);
1649
+ $poll_id = intval($instance['poll_id']);
1650
+ $display_pollarchive = intval($instance['display_pollarchive']);
 
1651
  ?>
1652
+ <p>
1653
+ <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'wp-polls'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label>
1654
+ </p>
1655
+ <p>
1656
+ <label for="<?php echo $this->get_field_id('display_pollarchive'); ?>"><?php _e('Display Polls Archive Link Below Poll?', 'wp-polls'); ?>
1657
+ <select name="<?php echo $this->get_field_name('display_pollarchive'); ?>" id="<?php echo $this->get_field_id('display_pollarchive'); ?>" class="widefat">
1658
+ <option value="0"<?php selected(0, $display_pollarchive); ?>><?php _e('No', 'wp-polls'); ?></option>
1659
+ <option value="1"<?php selected(1, $display_pollarchive); ?>><?php _e('Yes', 'wp-polls'); ?></option>
1660
+ </select>
1661
+ </label>
1662
+ </p>
1663
+ <p>
1664
+ <label for="<?php echo $this->get_field_id('poll_id'); ?>"><?php _e('Poll To Display:', 'wp-polls'); ?>
1665
+ <select name="<?php echo $this->get_field_name('poll_id'); ?>" id="<?php echo $this->get_field_id('poll_id'); ?>" class="widefat">
1666
+ <option value="-1"<?php selected(-1, $poll_id); ?>><?php _e('Do NOT Display Poll (Disable)', 'wp-polls'); ?></option>
1667
+ <option value="-2"<?php selected(-2, $poll_id); ?>><?php _e('Display Random Poll', 'wp-polls'); ?></option>
1668
+ <option value="0"<?php selected(0, $poll_id); ?>><?php _e('Display Latest Poll', 'wp-polls'); ?></option>
1669
+ <optgroup>&nbsp;</optgroup>
1670
+ <?php
1671
+ $polls = $wpdb->get_results("SELECT pollq_id, pollq_question FROM $wpdb->pollsq ORDER BY pollq_id DESC");
1672
+ if($polls) {
1673
+ foreach($polls as $poll) {
1674
+ $pollq_question = wp_kses_post( stripslashes( $poll->pollq_question ) );
1675
+ $pollq_id = intval($poll->pollq_id);
1676
+ if($pollq_id == $poll_id) {
1677
+ echo "<option value=\"$pollq_id\" selected=\"selected\">$pollq_question</option>\n";
1678
+ } else {
1679
+ echo "<option value=\"$pollq_id\">$pollq_question</option>\n";
1680
+ }
1681
+ }
1682
+ }
1683
+ ?>
1684
+ </select>
1685
+ </label>
1686
+ </p>
1687
+ <input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
1688
  <?php
1689
+ }
1690
  }
1691
 
1692
 
1693
  ### Function: Init WP-Polls Widget
1694
  add_action('widgets_init', 'widget_polls_init');
1695
  function widget_polls_init() {
1696
+ polls_textdomain();
1697
+ register_widget('WP_Widget_Polls');
1698
  }
1699
 
1700
 
1701
  ### Function: Activate Plugin
1702
  register_activation_hook( __FILE__, 'polls_activation' );
1703
+ function polls_activation( $network_wide ) {
1704
+ if ( is_multisite() && $network_wide ) {
1705
+ $ms_sites = wp_get_sites();
1706
+
1707
+ if( 0 < sizeof( $ms_sites ) ) {
1708
+ foreach ( $ms_sites as $ms_site ) {
1709
+ switch_to_blog( $ms_site['blog_id'] );
1710
+ polls_activate();
1711
+ restore_current_blog();
1712
+ }
1713
+ }
1714
+ } else {
1715
+ polls_activate();
1716
+ }
 
 
 
 
 
 
1717
  }
1718
 
1719
  function polls_activate() {
1720
+ global $wpdb;
1721
+
1722
+ if(@is_file(ABSPATH.'/wp-admin/includes/upgrade.php')) {
1723
+ include_once(ABSPATH.'/wp-admin/includes/upgrade.php');
1724
+ } elseif(@is_file(ABSPATH.'/wp-admin/upgrade-functions.php')) {
1725
+ include_once(ABSPATH.'/wp-admin/upgrade-functions.php');
1726
+ } else {
1727
+ die('We have problem finding your \'/wp-admin/upgrade-functions.php\' and \'/wp-admin/includes/upgrade.php\'');
1728
+ }
1729
+
1730
+ // Create Poll Tables (3 Tables)
1731
+ $charset_collate = '';
1732
+ if( $wpdb->has_cap( 'collation' ) ) {
1733
+ if(!empty($wpdb->charset)) {
1734
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
1735
+ }
1736
+ if(!empty($wpdb->collate)) {
1737
+ $charset_collate .= " COLLATE $wpdb->collate";
1738
+ }
1739
+ }
1740
+ $create_table = array();
1741
+ $create_table['pollsq'] = "CREATE TABLE $wpdb->pollsq (".
1742
+ "pollq_id int(10) NOT NULL auto_increment,".
1743
+ "pollq_question varchar(200) character set utf8 NOT NULL default '',".
1744
+ "pollq_timestamp varchar(20) NOT NULL default '',".
1745
+ "pollq_totalvotes int(10) NOT NULL default '0',".
1746
+ "pollq_active tinyint(1) NOT NULL default '1',".
1747
+ "pollq_expiry varchar(20) NOT NULL default '',".
1748
+ "pollq_multiple tinyint(3) NOT NULL default '0',".
1749
+ "pollq_totalvoters int(10) NOT NULL default '0',".
1750
+ "PRIMARY KEY (pollq_id)) $charset_collate;";
1751
+ $create_table['pollsa'] = "CREATE TABLE $wpdb->pollsa (".
1752
+ "polla_aid int(10) NOT NULL auto_increment,".
1753
+ "polla_qid int(10) NOT NULL default '0',".
1754
+ "polla_answers varchar(200) character set utf8 NOT NULL default '',".
1755
+ "polla_votes int(10) NOT NULL default '0',".
1756
+ "PRIMARY KEY (polla_aid)) $charset_collate;";
1757
+ $create_table['pollsip'] = "CREATE TABLE $wpdb->pollsip (".
1758
+ "pollip_id int(10) NOT NULL auto_increment,".
1759
+ "pollip_qid varchar(10) NOT NULL default '',".
1760
+ "pollip_aid varchar(10) NOT NULL default '',".
1761
+ "pollip_ip varchar(100) NOT NULL default '',".
1762
+ "pollip_host VARCHAR(200) NOT NULL default '',".
1763
+ "pollip_timestamp varchar(20) NOT NULL default '0000-00-00 00:00:00',".
1764
+ "pollip_user tinytext NOT NULL,".
1765
+ "pollip_userid int(10) NOT NULL default '0',".
1766
+ "PRIMARY KEY (pollip_id),".
1767
+ "KEY pollip_ip (pollip_ip),".
1768
+ "KEY pollip_qid (pollip_qid),".
1769
+ "KEY pollip_ip_qid (pollip_ip, pollip_qid)".
1770
+ ") $charset_collate;";
1771
+ maybe_create_table($wpdb->pollsq, $create_table['pollsq']);
1772
+ maybe_create_table($wpdb->pollsa, $create_table['pollsa']);
1773
+ maybe_create_table($wpdb->pollsip, $create_table['pollsip']);
1774
+ // Check Whether It is Install Or Upgrade
1775
+ $first_poll = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq LIMIT 1");
1776
+ // If Install, Insert 1st Poll Question With 5 Poll Answers
1777
+ if(empty($first_poll)) {
1778
+ // Insert Poll Question (1 Record)
1779
+ $insert_pollq = $wpdb->query("INSERT INTO $wpdb->pollsq VALUES (1, '".__('How Is My Site?', 'wp-polls')."', '".current_time('timestamp')."', 0, 1, '', 0, 0);");
1780
+ if($insert_pollq) {
1781
+ // Insert Poll Answers (5 Records)
1782
+ $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (1, 1, '".__('Good', 'wp-polls')."', 0);");
1783
+ $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (2, 1, '".__('Excellent', 'wp-polls')."', 0);");
1784
+ $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (3, 1, '".__('Bad', 'wp-polls')."', 0);");
1785
+ $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (4, 1, '".__('Can Be Improved', 'wp-polls')."', 0);");
1786
+ $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (5, 1, '".__('No Comments', 'wp-polls')."', 0);");
1787
+ }
1788
+ }
1789
+ // Add In Options (16 Records)
1790
+ add_option('poll_template_voteheader', '<p style="text-align: center;"><strong>%POLL_QUESTION%</strong></p>'.
1791
+ '<div id="polls-%POLL_ID%-ans" class="wp-polls-ans">'.
1792
+ '<ul class="wp-polls-ul">');
1793
+ add_option('poll_template_votebody', '<li><input type="%POLL_CHECKBOX_RADIO%" id="poll-answer-%POLL_ANSWER_ID%" name="poll_%POLL_ID%" value="%POLL_ANSWER_ID%" /> <label for="poll-answer-%POLL_ANSWER_ID%">%POLL_ANSWER%</label></li>');
1794
+ add_option('poll_template_votefooter', '</ul>'.
1795
+ '<p style="text-align: center;"><input type="button" name="vote" value=" '.__('Vote', 'wp-polls').' " class="Buttons" onclick="poll_vote(%POLL_ID%);" /></p>'.
1796
+ '<p style="text-align: center;"><a href="#ViewPollResults" onclick="poll_result(%POLL_ID%); return false;" title="'.__('View Results Of This Poll', 'wp-polls').'">'.__('View Results', 'wp-polls').'</a></p>'.
1797
+ '</div>');
1798
+ add_option('poll_template_resultheader', '<p style="text-align: center;"><strong>%POLL_QUESTION%</strong></p>'.
1799
+ '<div id="polls-%POLL_ID%-ans" class="wp-polls-ans">'.
1800
+ '<ul class="wp-polls-ul">');
1801
+ add_option('poll_template_resultbody', '<li>%POLL_ANSWER% <small>(%POLL_ANSWER_PERCENTAGE%%'.__(',', 'wp-polls').' %POLL_ANSWER_VOTES% '.__('Votes', 'wp-polls').')</small><div class="pollbar" style="width: %POLL_ANSWER_IMAGEWIDTH%%;" title="%POLL_ANSWER_TEXT% (%POLL_ANSWER_PERCENTAGE%% | %POLL_ANSWER_VOTES% '.__('Votes', 'wp-polls').')"></div></li>');
1802
+ add_option('poll_template_resultbody2', '<li><strong><i>%POLL_ANSWER% <small>(%POLL_ANSWER_PERCENTAGE%%'.__(',', 'wp-polls').' %POLL_ANSWER_VOTES% '.__('Votes', 'wp-polls').')</small></i></strong><div class="pollbar" style="width: %POLL_ANSWER_IMAGEWIDTH%%;" title="'.__('You Have Voted For This Choice', 'wp-polls').' - %POLL_ANSWER_TEXT% (%POLL_ANSWER_PERCENTAGE%% | %POLL_ANSWER_VOTES% '.__('Votes', 'wp-polls').')"></div></li>');
1803
+ add_option('poll_template_resultfooter', '</ul>'.
1804
+ '<p style="text-align: center;">'.__('Total Voters', 'wp-polls').': <strong>%POLL_TOTALVOTERS%</strong></p>'.
1805
+ '</div>');
1806
+ add_option('poll_template_resultfooter2', '</ul>'.
1807
+ '<p style="text-align: center;">'.__('Total Voters', 'wp-polls').': <strong>%POLL_TOTALVOTERS%</strong></p>'.
1808
+ '<p style="text-align: center;"><a href="#VotePoll" onclick="poll_booth(%POLL_ID%); return false;" title="'.__('Vote For This Poll', 'wp-polls').'">'.__('Vote', 'wp-polls').'</a></p>'.
1809
+ '</div>');
1810
+ add_option('poll_template_disable', __('Sorry, there are no polls available at the moment.', 'wp-polls'));
1811
+ add_option('poll_template_error', __('An error has occurred when processing your poll.', 'wp-polls'));
1812
+ add_option('poll_currentpoll', 0);
1813
+ add_option('poll_latestpoll', 1);
1814
+ add_option('poll_archive_perpage', 5);
1815
+ add_option('poll_ans_sortby', 'polla_aid');
1816
+ add_option('poll_ans_sortorder', 'asc');
1817
+ add_option('poll_ans_result_sortby', 'polla_votes');
1818
+ add_option('poll_ans_result_sortorder', 'desc');
1819
+ // Database Upgrade For WP-Polls 2.1
1820
+ add_option('poll_logging_method', '3');
1821
+ add_option('poll_allowtovote', '2');
1822
+ maybe_add_column($wpdb->pollsq, 'pollq_active', "ALTER TABLE $wpdb->pollsq ADD pollq_active TINYINT( 1 ) NOT NULL DEFAULT '1';");
1823
+ // Database Upgrade For WP-Polls 2.12
1824
+ maybe_add_column($wpdb->pollsip, 'pollip_userid', "ALTER TABLE $wpdb->pollsip ADD pollip_userid INT( 10 ) NOT NULL DEFAULT '0';");
1825
+ add_option('poll_archive_url', site_url('pollsarchive'));
1826
+ // Database Upgrade For WP-Polls 2.13
1827
+ add_option('poll_bar', array('style' => 'default', 'background' => 'd8e1eb', 'border' => 'c8c8c8', 'height' => 8));
1828
+ // Database Upgrade For WP-Polls 2.14
1829
+ maybe_add_column($wpdb->pollsq, 'pollq_expiry', "ALTER TABLE $wpdb->pollsq ADD pollq_expiry varchar(20) NOT NULL default '';");
1830
+ add_option('poll_close', 1);
1831
+ // Database Upgrade For WP-Polls 2.20
1832
+ add_option('poll_ajax_style', array('loading' => 1, 'fading' => 1));
1833
+ add_option('poll_template_pollarchivelink', '<ul>'.
1834
+ '<li><a href="%POLL_ARCHIVE_URL%">'.__('Polls Archive', 'wp-polls').'</a></li>'.
1835
+ '</ul>');
1836
+ add_option('poll_archive_displaypoll', 2);
1837
+ add_option('poll_template_pollarchiveheader', '');
1838
+ add_option('poll_template_pollarchivefooter', '<p>'.__('Start Date:', 'wp-polls').' %POLL_START_DATE%<br />'.__('End Date:', 'wp-polls').' %POLL_END_DATE%</p>');
1839
+ maybe_add_column($wpdb->pollsq, 'pollq_multiple', "ALTER TABLE $wpdb->pollsq ADD pollq_multiple TINYINT( 3 ) NOT NULL DEFAULT '0';");
1840
+ $pollq_totalvoters = maybe_add_column($wpdb->pollsq, 'pollq_totalvoters', "ALTER TABLE $wpdb->pollsq ADD pollq_totalvoters INT( 10 ) NOT NULL DEFAULT '0';");
1841
+ if($pollq_totalvoters) {
1842
+ $pollq_totalvoters = intval($wpdb->get_var("SELECT SUM(pollq_totalvoters) FROM $wpdb->pollsq"));
1843
+ if($pollq_totalvoters == 0) {
1844
+ $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvoters = pollq_totalvotes");
1845
+ }
1846
+ }
1847
+ // Database Upgrade For WP-Polls 2.30
1848
+ add_option('poll_cookielog_expiry', 0);
1849
+ add_option('poll_template_pollarchivepagingheader', '');
1850
+ add_option('poll_template_pollarchivepagingfooter', '');
1851
+ // Database Upgrade For WP-Polls 2.50
1852
+ delete_option('poll_archive_show');
1853
+
1854
+ // Index
1855
+ $index = $wpdb->get_results( "SHOW INDEX FROM $wpdb->pollsip;" );
1856
+ $key_name = array();
1857
+ if( sizeof( $index ) > 0 ) {
1858
+ foreach( $index as $i ) {
1859
+ $key_name[]= $i->Key_name;
1860
+ }
1861
+ }
1862
+ if ( ! in_array( 'pollip_ip', $key_name ) ) {
1863
+ $wpdb->query( "ALTER TABLE $wpdb->pollsip ADD INDEX pollip_ip (pollip_ip);" );
1864
+ }
1865
+ if ( ! in_array( 'pollip_qid', $key_name ) ) {
1866
+ $wpdb->query( "ALTER TABLE $wpdb->pollsip ADD INDEX pollip_qid (pollip_qid);" );
1867
+ }
1868
+ if ( ! in_array( 'pollip_ip_qid_aid', $key_name ) ) {
1869
+ $wpdb->query( "ALTER TABLE $wpdb->pollsip ADD INDEX pollip_ip_qid_aid (pollip_ip, pollip_qid, pollip_aid);" );
1870
+ }
1871
+ // No longer needed index
1872
+ if ( in_array( 'pollip_ip_qid', $key_name ) ) {
1873
+ $wpdb->query( "ALTER TABLE $wpdb->pollsip DROP INDEX pollip_ip_qid;" );
1874
+ }
1875
+
1876
+ // Set 'manage_polls' Capabilities To Administrator
1877
+ $role = get_role( 'administrator' );
1878
+ if( ! $role->has_cap( 'manage_polls' ) ) {
1879
+ $role->add_cap( 'manage_polls' );
1880
+ }
1881
+ cron_polls_place();
1882
+ }