WP-Polls - Version 2.68

Version Description

N/A

Download this release

Release Info

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

Code changes from version 2.67 to 2.68

polls-add.php CHANGED
@@ -1,22 +1,4 @@
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
- | - Add Poll |
14
- | - wp-content/plugins/wp-polls/polls-add.php |
15
- | |
16
- +----------------------------------------------------------------+
17
- */
18
-
19
-
20
  ### Check Whether User Can Manage Polls
21
  if(!current_user_can('manage_polls')) {
22
  die('Access Denied');
@@ -35,66 +17,78 @@ if(!empty($_POST['do'])) {
35
  check_admin_referer('wp-polls_add-poll');
36
  // Poll Question
37
  $pollq_question = addslashes(trim($_POST['pollq_question']));
38
- // Poll Start Date
39
- $timestamp_sql = '';
40
- $pollq_timestamp_day = intval($_POST['pollq_timestamp_day']);
41
- $pollq_timestamp_month = intval($_POST['pollq_timestamp_month']);
42
- $pollq_timestamp_year = intval($_POST['pollq_timestamp_year']);
43
- $pollq_timestamp_hour = intval($_POST['pollq_timestamp_hour']);
44
- $pollq_timestamp_minute = intval($_POST['pollq_timestamp_minute']);
45
- $pollq_timestamp_second = intval($_POST['pollq_timestamp_second']);
46
- $pollq_timestamp = gmmktime($pollq_timestamp_hour, $pollq_timestamp_minute, $pollq_timestamp_second, $pollq_timestamp_month, $pollq_timestamp_day, $pollq_timestamp_year);
47
- if($pollq_timestamp > current_time('timestamp')) {
48
- $pollq_active = -1;
49
- } else {
50
- $pollq_active = 1;
51
- }
52
- // Poll End Date
53
- $pollq_expiry_no = intval($_POST['pollq_expiry_no']);
54
- if($pollq_expiry_no == 1) {
55
- $pollq_expiry = '';
56
- } else {
57
- $pollq_expiry_day = intval($_POST['pollq_expiry_day']);
58
- $pollq_expiry_month = intval($_POST['pollq_expiry_month']);
59
- $pollq_expiry_year = intval($_POST['pollq_expiry_year']);
60
- $pollq_expiry_hour = intval($_POST['pollq_expiry_hour']);
61
- $pollq_expiry_minute = intval($_POST['pollq_expiry_minute']);
62
- $pollq_expiry_second = intval($_POST['pollq_expiry_second']);
63
- $pollq_expiry = gmmktime($pollq_expiry_hour, $pollq_expiry_minute, $pollq_expiry_second, $pollq_expiry_month, $pollq_expiry_day, $pollq_expiry_year);
64
- if($pollq_expiry <= current_time('timestamp')) {
65
- $pollq_active = 0;
66
  }
67
- }
68
- // Mutilple Poll
69
- $pollq_multiple_yes = intval($_POST['pollq_multiple_yes']);
70
- $pollq_multiple = 0;
71
- if($pollq_multiple_yes == 1) {
72
- $pollq_multiple = intval($_POST['pollq_multiple']);
73
- } else {
 
 
 
 
 
 
 
 
 
 
 
74
  $pollq_multiple = 0;
75
- }
76
- // Insert Poll
77
- $add_poll_question = $wpdb->query("INSERT INTO $wpdb->pollsq VALUES (0, '$pollq_question', '$pollq_timestamp', 0, $pollq_active, '$pollq_expiry', $pollq_multiple, 0)");
78
- if(!$add_poll_question) {
79
- $text .= '<p style="color: red;">'.sprintf(__('Error In Adding Poll \'%s\'.', 'wp-polls'), stripslashes($pollq_question)).'</p>';
80
- }
81
- // Add Poll Answers
82
- $polla_answers = $_POST['polla_answers'];
83
- $polla_qid = intval($wpdb->insert_id);
84
- foreach($polla_answers as $polla_answer) {
85
- $polla_answer = addslashes(trim($polla_answer));
86
- $add_poll_answers = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answer', 0)");
87
- if(!$add_poll_answers) {
88
- $text .= '<p style="color: red;">'.sprintf(__('Error In Adding Poll\'s Answer \'%s\'.', 'wp-polls'), stripslashes($polla_answer)).'</p>';
89
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  }
91
- // Update Lastest Poll ID To Poll Options
92
- $latest_pollid = polls_latest_id();
93
- $update_latestpoll = update_option('poll_latestpoll', $latest_pollid);
94
- if(empty($text)) {
95
- $text = '<p style="color: green;">'.sprintf(__('Poll \'%s\' (ID: %s) Added Successfully.', 'wp-polls'), stripslashes($pollq_question), $latest_pollid).' <a href="'.$base_page.'">'.__('Manage Polls', 'wp-polls').'</a></p>';
96
- }
97
- cron_polls_place();
98
  break;
99
  }
100
  }
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  ### Check Whether User Can Manage Polls
3
  if(!current_user_can('manage_polls')) {
4
  die('Access Denied');
17
  check_admin_referer('wp-polls_add-poll');
18
  // Poll Question
19
  $pollq_question = addslashes(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(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
+ cron_polls_place();
89
+ } else {
90
+ $text .= '<p style="color: red;">' . __( 'Poll Question is empty.', 'wp-polls' ) . '</p>';
91
  }
 
 
 
 
 
 
 
92
  break;
93
  }
94
  }
polls-logs.php CHANGED
@@ -129,9 +129,9 @@ if(!empty($_POST['do'])) {
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 casted by registered users', '<strong>&raquo;</strong> <strong>%s</strong> votes are casted 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 casted by comment authors', '<strong>&raquo;</strong> <strong>%s</strong> votes are casted 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 casted by guests', '<strong>&raquo;</strong> <strong>%s</strong> votes are casted by guests', $poll_guest, 'wp-polls'), number_format_i18n($poll_guest)); ?>
135
  </p>
136
  </div>
137
  <?php if($poll_totalrecorded > 0) { ?>
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) { ?>
polls-manager.php CHANGED
@@ -153,7 +153,7 @@ switch($mode) {
153
  break;
154
  // Edit A Poll
155
  case 'edit':
156
- $last_col_align = ('rtl' == $text_direction) ? 'left' : 'right';
157
  $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");
158
  $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");
159
  $poll_noquestion = $wpdb->get_var("SELECT COUNT(polla_aid) FROM $wpdb->pollsa WHERE polla_qid = $poll_id");
@@ -437,7 +437,7 @@ switch($mode) {
437
  <td><?php echo number_format_i18n($total_ans); ?></td>
438
  </tr>
439
  <tr>
440
- <th><?php _e('Total Votes Casted:', 'wp-polls'); ?></th>
441
  <td><?php echo number_format_i18n($total_votes); ?></td>
442
  </tr>
443
  <tr class="alternate">
153
  break;
154
  // Edit A Poll
155
  case 'edit':
156
+ $last_col_align = is_rtl() ? 'right' : 'left';
157
  $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");
158
  $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");
159
  $poll_noquestion = $wpdb->get_var("SELECT COUNT(polla_aid) FROM $wpdb->pollsa WHERE polla_qid = $poll_id");
437
  <td><?php echo number_format_i18n($total_ans); ?></td>
438
  </tr>
439
  <tr>
440
+ <th><?php _e('Total Votes Cast:', 'wp-polls'); ?></th>
441
  <td><?php echo number_format_i18n($total_votes); ?></td>
442
  </tr>
443
  <tr class="alternate">
polls-options.php CHANGED
@@ -86,12 +86,12 @@ if( isset($_POST['Submit']) && $_POST['Submit'] ) {
86
  $text = '';
87
  foreach($update_poll_queries as $update_poll_query) {
88
  if($update_poll_query) {
89
- $text .= '<font color="green">'.$update_poll_text[$i].' '.__('Updated', 'wp-polls').'</font><br />';
90
  }
91
  $i++;
92
  }
93
  if(empty($text)) {
94
- $text = '<font color="red">'.__('No Poll Option Updated', 'wp-polls').'</font>';
95
  }
96
  cron_polls_place();
97
  }
86
  $text = '';
87
  foreach($update_poll_queries as $update_poll_query) {
88
  if($update_poll_query) {
89
+ $text .= '<p style="color: green;">'.$update_poll_text[$i].' '.__('Updated', 'wp-polls').'</p>';
90
  }
91
  $i++;
92
  }
93
  if(empty($text)) {
94
+ $text = '<p style="color: red;">'.__('No Poll Option Updated', 'wp-polls').'</p>';
95
  }
96
  cron_polls_place();
97
  }
polls-templates.php CHANGED
@@ -81,12 +81,12 @@ if( isset($_POST['Submit']) && $_POST['Submit'] ) {
81
  $text = '';
82
  foreach($update_poll_queries as $update_poll_query) {
83
  if($update_poll_query) {
84
- $text .= '<font color="green">'.$update_poll_text[$i].' '.__('Updated', 'wp-polls').'</font><br />';
85
  }
86
  $i++;
87
  }
88
  if(empty($text)) {
89
- $text = '<font color="red">'.__('No Poll Option Updated', 'wp-polls').'</font>';
90
  }
91
  wp_clear_scheduled_hook('polls_cron');
92
  if (!wp_next_scheduled('polls_cron')) {
81
  $text = '';
82
  foreach($update_poll_queries as $update_poll_query) {
83
  if($update_poll_query) {
84
+ $text .= '<p style="color: green;">'.$update_poll_text[$i].' '.__('Updated', 'wp-polls').'</p>';
85
  }
86
  $i++;
87
  }
88
  if(empty($text)) {
89
+ $text = '<p style="color: red;">'.__('No Poll Option Updated', 'wp-polls').'</p>';
90
  }
91
  wp_clear_scheduled_hook('polls_cron');
92
  if (!wp_next_scheduled('polls_cron')) {
polls-uninstall.php DELETED
@@ -1,133 +0,0 @@
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
- | - Uninstall WP-Polls |
14
- | - wp-content/plugins/wp-polls/polls-uninstall.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 Variables Variables
27
- $base_name = plugin_basename('wp-polls/polls-manager.php');
28
- $base_page = 'admin.php?page='.$base_name;
29
- $mode = (isset($_GET['mode']) ? trim($_GET['mode']) : '');
30
- $polls_tables = array($wpdb->pollsq, $wpdb->pollsa, $wpdb->pollsip);
31
- $polls_settings = array('poll_template_voteheader', 'poll_template_votebody', 'poll_template_votefooter', 'poll_template_resultheader', 'poll_template_resultbody', 'poll_template_resultbody2', 'poll_template_resultfooter', 'poll_template_resultfooter2', 'poll_template_disable', 'poll_template_error', 'poll_currentpoll', 'poll_latestpoll', 'poll_archive_perpage', 'poll_ans_sortby', 'poll_ans_sortorder', 'poll_ans_result_sortby', 'poll_ans_result_sortorder', 'poll_logging_method', 'poll_allowtovote', 'poll_archive_show', 'poll_archive_url', 'poll_bar', 'poll_close', 'poll_ajax_style', 'poll_template_pollarchivelink', 'widget_polls', 'poll_archive_displaypoll', 'poll_template_pollarchiveheader', 'poll_template_pollarchivefooter', 'poll_cookielog_expiry', 'widget_polls-widget');
32
-
33
-
34
- ### Form Processing
35
- if(!empty($_POST['do'])) {
36
- // Decide What To Do
37
- switch($_POST['do']) {
38
- // Uninstall WP-Polls (By: Philippe Corbes)
39
- case __('UNINSTALL WP-Polls', 'wp-polls') :
40
- check_admin_referer('wp-polls_uninstall');
41
- if(trim($_POST['uninstall_poll_yes']) == 'yes') {
42
- echo '<div id="message" class="updated fade">';
43
- echo '<p>';
44
- foreach($polls_tables as $table) {
45
- $wpdb->query("DROP TABLE {$table}");
46
- echo '<font style="color: green;">';
47
- printf(__('Table \'%s\' has been deleted.', 'wp-polls'), "<strong><em>{$table}</em></strong>");
48
- echo '</font><br />';
49
- }
50
- echo '</p>';
51
- echo '<p>';
52
- foreach($polls_settings as $setting) {
53
- $delete_setting = delete_option($setting);
54
- if($delete_setting) {
55
- echo '<font color="green">';
56
- printf(__('Setting Key \'%s\' has been deleted.', 'wp-polls'), "<strong><em>{$setting}</em></strong>");
57
- echo '</font><br />';
58
- }
59
- }
60
- echo '</p>';
61
- echo '</div>';
62
- $mode = 'end-UNINSTALL';
63
- }
64
- break;
65
- }
66
- }
67
-
68
-
69
- ### Determines Which Mode It Is
70
- switch($mode) {
71
- // Deactivating WP-Polls (By: Philippe Corbes)
72
- case 'end-UNINSTALL':
73
- $deactivate_url = wp_nonce_url('plugins.php?action=deactivate&amp;plugin=wp-polls/wp-polls.php', 'deactivate-plugin_wp-polls/wp-polls.php');
74
- echo '<div class="wrap">';
75
- echo '<h2>'.__('Uninstall WP-Polls', 'wp-polls').'</h2>';
76
- echo '<p><strong>'.sprintf(__('<a href="%s">Click Here</a> To Finish The Uninstallation And WP-Polls Will Be Deactivated Automatically.', 'wp-polls'), $deactivate_url).'</strong></p>';
77
- echo '</div>';
78
- break;
79
- // Main Page
80
- default:
81
- ?>
82
- <!-- Uninstall WP-Polls (By: Philippe Corbes) -->
83
- <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
84
- <?php wp_nonce_field('wp-polls_uninstall'); ?>
85
- <div class="wrap">
86
- <h2><?php _e('Uninstall WP-Polls', 'wp-polls'); ?></h2>
87
- <p>
88
- <?php _e('Deactivating WP-Polls plugin does not remove any data that may have been created, such as the poll data and the poll\'s voting logs. To completely remove this plugin, you can uninstall it here.', 'wp-polls'); ?>
89
- </p>
90
- <p style="color: red">
91
- <strong><?php _e('WARNING:', 'wp-polls'); ?></strong><br />
92
- <?php _e('Once uninstalled, this cannot be undone. You should use a Database Backup plugin of WordPress to back up all the data first.', 'wp-polls'); ?>
93
- </p>
94
- <p style="color: red">
95
- <strong><?php _e('The following WordPress Options/Tables will be DELETED:', 'wp-polls'); ?></strong><br />
96
- </p>
97
- <table class="widefat">
98
- <thead>
99
- <tr>
100
- <th><?php _e('WordPress Options', 'wp-polls'); ?></th>
101
- <th><?php _e('WordPress Tables', 'wp-polls'); ?></th>
102
- </tr>
103
- </thead>
104
- <tr>
105
- <td valign="top">
106
- <ol>
107
- <?php
108
- foreach($polls_settings as $settings) {
109
- echo '<li>'.$settings.'</li>'."\n";
110
- }
111
- ?>
112
- </ol>
113
- </td>
114
- <td valign="top" class="alternate">
115
- <ol>
116
- <?php
117
- foreach($polls_tables as $tables) {
118
- echo '<li>'.$tables.'</li>'."\n";
119
- }
120
- ?>
121
- </ol>
122
- </td>
123
- </tr>
124
- </table>
125
- <p style="text-align: center;">
126
- <?php _e('Do you really want to uninstall WP-Polls?', 'wp-polls'); ?><br /><br />
127
- <input type="checkbox" name="uninstall_poll_yes" value="yes" />&nbsp;<?php _e('Yes', 'wp-polls'); ?><br /><br />
128
- <input type="submit" name="do" value="<?php _e('UNINSTALL WP-Polls', 'wp-polls'); ?>" class="button-primary" onclick="return confirm('<?php _e('You Are About To Uninstall WP-Polls From WordPress.\nThis Action Is Not Reversible.\n\n Choose [Cancel] To Stop, [OK] To Uninstall.', 'wp-polls'); ?>')" />
129
- </p>
130
- </div>
131
- </form>
132
- <?php
133
- } // End switch($mode)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: GamerZ
3
  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.0
7
- Stable tag: 2.67
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,14 @@ 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 appericiate it. If not feel free to use it without any obligations.
28
 
29
  == Changelog ==
 
 
 
 
 
 
 
 
30
 
31
  = Version 2.67 =
32
  * NEW: Use POST for View Results and Vote link
@@ -341,6 +349,9 @@ N/A
341
 
342
  * If you ARE NOT using nice permalinks, you need to go to `WP-Admin -> Polls -> Poll Options` and under `Poll Archive -> Polls Archive URL`, you need to fill in the URL to the Polls Archive Page you created above.
343
 
 
 
 
344
  = How Does WP-Polls Load CSS? =
345
  * WP-Polls will load `polls-css.css` from your theme's directory if it exists.
346
  * If it doesn't exists, it will just load the default `polls-css.css` that comes with WP-Polls.
3
  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.1
7
+ Stable tag: 2.68
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 appericiate it. If not feel free to use it without any obligations.
28
 
29
  == Changelog ==
30
+ = Version 2.68 =
31
+ * NEW: Poll answer percentage are now not rounded off, previously it was always rounded to add up to 100%
32
+ * NEW: Support WordPress MultiSite Network Activation
33
+ * NEW: Uses native WordPress uninstall.php
34
+ * NEW: Show shortcode in success message after creating a poll
35
+ * NEW: Checks and ensure that Poll Question and Poll Answers are not empty
36
+ * NEW: Checks whether Poll is closed before checking whether user has voted
37
+
38
 
39
  = Version 2.67 =
40
  * NEW: Use POST for View Results and Vote link
349
 
350
  * If you ARE NOT using nice permalinks, you need to go to `WP-Admin -> Polls -> Poll Options` and under `Poll Archive -> Polls Archive URL`, you need to fill in the URL to the Polls Archive Page you created above.
351
 
352
+ = Why doesn't my poll's answers add up to 100%? =
353
+ * It is because of rounding issues. To make it always round up to 100%, the last poll's answer will get the remainding percentage added to it. To enable this feature, add this to your theme's functions.php: `add_filter( 'wp_polls_round_percentage', '__return_true' );`
354
+
355
  = How Does WP-Polls Load CSS? =
356
  * WP-Polls will load `polls-css.css` from your theme's directory if it exists.
357
  * If it doesn't exists, it will just load the default `polls-css.css` that comes with WP-Polls.
uninstall.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Uninstall plugin
4
+ */
5
+ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
6
+ exit ();
7
+
8
+ $option_names = array(
9
+ 'poll_template_voteheader'
10
+ , 'poll_template_votebody'
11
+ , 'poll_template_votefooter'
12
+ , 'poll_template_resultheader'
13
+ , 'poll_template_resultbody'
14
+ , 'poll_template_resultbody2'
15
+ , 'poll_template_resultfooter'
16
+ , 'poll_template_resultfooter2'
17
+ , 'poll_template_disable'
18
+ , 'poll_template_error'
19
+ , 'poll_currentpoll'
20
+ , 'poll_latestpoll'
21
+ , 'poll_archive_perpage'
22
+ , 'poll_ans_sortby'
23
+ , 'poll_ans_sortorder'
24
+ , 'poll_ans_result_sortby'
25
+ , 'poll_ans_result_sortorder'
26
+ , 'poll_logging_method'
27
+ , 'poll_allowtovote'
28
+ , 'poll_archive_show'
29
+ , 'poll_archive_url'
30
+ , 'poll_bar'
31
+ , 'poll_close'
32
+ , 'poll_ajax_style'
33
+ , 'poll_template_pollarchivelink'
34
+ , 'widget_polls'
35
+ , 'poll_archive_displaypoll'
36
+ , 'poll_template_pollarchiveheader'
37
+ , 'poll_template_pollarchivefooter'
38
+ , 'poll_cookielog_expiry'
39
+ , 'widget_polls-widget'
40
+ );
41
+
42
+
43
+ if ( is_multisite() ) {
44
+ $ms_sites = wp_get_sites();
45
+
46
+ if( 0 < sizeof( $ms_sites ) ) {
47
+ foreach ( $ms_sites as $ms_site ) {
48
+ switch_to_blog( $ms_site['blog_id'] );
49
+ if( sizeof( $option_names ) > 0 ) {
50
+ foreach( $option_names as $option_name ) {
51
+ delete_option( $option_name );
52
+ plugin_uninstalled();
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ restore_current_blog();
59
+ } else {
60
+ if( sizeof( $option_names ) > 0 ) {
61
+ foreach( $option_names as $option_name ) {
62
+ delete_option( $option_name );
63
+ plugin_uninstalled();
64
+ }
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Delete plugin table when uninstalled
70
+ *
71
+ * @access public
72
+ * @return void
73
+ */
74
+ function plugin_uninstalled() {
75
+ global $wpdb;
76
+
77
+ $table_names = array( 'pollsq', 'pollsa', 'pollsip' );
78
+ if( sizeof( $table_names ) > 0 ) {
79
+ foreach( $table_names as $table_name ) {
80
+ $table = $wpdb->prefix . $table_name;
81
+ $wpdb->query( "DROP TABLE IF EXISTS $table" );
82
+ }
83
+ }
84
+ }
wp-polls.php CHANGED
@@ -3,7 +3,7 @@
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.67
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-polls
@@ -13,24 +13,24 @@ Text Domain: wp-polls
13
  /*
14
  Copyright 2014 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.67 );
34
 
35
 
36
  ### Create Text Domain For Translations
@@ -48,15 +48,14 @@ $wpdb->pollsip = $wpdb->prefix.'pollsip';
48
 
49
 
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
- add_submenu_page('wp-polls/polls-manager.php', __('Uninstall WP-Polls', 'wp-polls'), __('Uninstall WP-Polls', 'wp-polls'), 'manage_polls', 'wp-polls/polls-uninstall.php');
60
  }
61
 
62
 
@@ -198,13 +197,12 @@ function poll_head_scripts() {
198
  ### Function: Enqueue Polls JavaScripts/CSS
199
  add_action('wp_enqueue_scripts', 'poll_scripts');
200
  function poll_scripts() {
201
- global $text_direction;
202
  if(@file_exists(get_stylesheet_directory().'/polls-css.css')) {
203
  wp_enqueue_style('wp-polls', get_stylesheet_directory_uri().'/polls-css.css', false, WP_POLLS_VERSION, 'all');
204
  } else {
205
  wp_enqueue_style('wp-polls', plugins_url('wp-polls/polls-css.css'), false, WP_POLLS_VERSION, 'all');
206
  }
207
- if('rtl' == $text_direction) {
208
  if(@file_exists(get_stylesheet_directory().'/polls-css-rtl.css')) {
209
  wp_enqueue_style('wp-polls-rtl', get_stylesheet_directory_uri().'/polls-css-rtl.css', false, WP_POLLS_VERSION, 'all');
210
  } else {
@@ -228,14 +226,13 @@ function poll_scripts() {
228
  ### Function: Enqueue Polls Stylesheets/JavaScripts In WP-Admin
229
  add_action('admin_enqueue_scripts', 'poll_scripts_admin');
230
  function poll_scripts_admin($hook_suffix) {
231
- global $text_direction;
232
  $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');
233
  if(in_array($hook_suffix, $poll_admin_pages)) {
234
  wp_enqueue_style('wp-polls-admin', plugins_url('wp-polls/polls-admin-css.css'), false, WP_POLLS_VERSION, 'all');
235
  wp_enqueue_script('wp-polls-admin', plugins_url('wp-polls/polls-admin-js.js'), array('jquery'), WP_POLLS_VERSION, true);
236
  wp_localize_script('wp-polls-admin', 'pollsAdminL10n', array(
237
  'admin_ajax_url' => admin_url('admin-ajax.php'),
238
- 'text_direction' => ('rtl' == $text_direction) ? 'left' : 'right',
239
  'text_delete_poll' => __('Delete Poll', 'wp-polls'),
240
  'text_no_poll_logs' => __('No poll logs available.', 'wp-polls'),
241
  'text_delete_all_logs' => __('Delete All Logs', 'wp-polls'),
@@ -424,11 +421,11 @@ add_filter('poll_template_votefooter_markup', 'poll_template_vote_markup', 10, 3
424
 
425
  function poll_template_vote_markup($template, $poll_db_object, $variables) {
426
 
427
- foreach($variables as $placeholder => $value) {
428
- $template = str_replace($placeholder, $value, $template);
429
- }
430
 
431
- return $template;
432
  }
433
 
434
 
@@ -457,15 +454,15 @@ function display_pollvote($poll_id, $display_loading = true) {
457
 
458
  $template_question = stripslashes(get_option('poll_template_voteheader'));
459
 
460
- $template_question = apply_filters('poll_template_voteheader_markup', $template_question, $poll_question, array(
461
- '%POLL_QUESTION%' => $poll_question_text,
462
- '%POLL_ID%' => $poll_question_id,
463
- '%POLL_TOTALVOTES%' => $poll_question_totalvotes,
464
- '%POLL_TOTALVOTERS%' => $poll_question_totalvoters,
465
- '%POLL_START_DATE%' => $poll_start_date,
466
- '%POLL_END_DATE%' => $poll_end_date,
467
- '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
468
- ));
469
 
470
  // Get Poll Answers Data
471
  $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'));
@@ -488,13 +485,13 @@ function display_pollvote($poll_id, $display_loading = true) {
488
  $poll_answer_votes = intval($poll_answer->polla_votes);
489
  $template_answer = stripslashes(get_option('poll_template_votebody'));
490
 
491
- $template_answer = apply_filters('poll_template_votebody_markup', $template_answer, $poll_answer, array(
492
- '%POLL_ID%' => $poll_question_id,
493
- '%POLL_ANSWER_ID%' => $poll_answer_id,
494
- '%POLL_ANSWER%' => $poll_answer_text,
495
- '%POLL_ANSWER_VOTES%' => number_format_i18n($poll_answer_votes),
496
- "%POLL_CHECKBOX_RADIO%" => $poll_multiple_ans > 0 ? 'checkbox' : 'radio'
497
- ));
498
 
499
  // Print Out Voting Form Body Template
500
  $temp_pollvote .= "\t\t$template_answer\n";
@@ -512,13 +509,13 @@ function display_pollvote($poll_id, $display_loading = true) {
512
  // Voting Form Footer Variables
513
  $template_footer = stripslashes(get_option('poll_template_votefooter'));
514
 
515
- $template_footer = apply_filters('poll_template_votefooter_markup', $template_footer, $poll_question, array(
516
- '%POLL_ID%' => $poll_question_id,
517
- '%POLL_RESULT_URL%' => $poll_result_url,
518
- '%POLL_START_DATE%' => $poll_start_date,
519
- '%POLL_END_DATE%' => $poll_end_date,
520
- '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
521
- ));
522
 
523
  // Print Out Voting Form Footer Template
524
  $temp_pollvote .= "\t\t$template_footer\n";
@@ -558,6 +555,11 @@ function display_pollresult($poll_id, $user_voted = '', $display_loading = true)
558
  $poll_least_percentage = 0;
559
  // Get Poll Question Data
560
  $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");
 
 
 
 
 
561
  // Poll Question Variables
562
  $poll_question_text = stripslashes($poll_question->pollq_question);
563
  $poll_question_id = intval($poll_question->pollq_id);
@@ -622,16 +624,20 @@ function display_pollresult($poll_id, $user_voted = '', $display_loading = true)
622
  $poll_answer_imagewidth = 1;
623
  }
624
  // Make Sure That Total Percentage Is 100% By Adding A Buffer To The Last Poll Answer
625
- if($poll_multiple_ans == 0) {
626
- $poll_answer_percentage_array[] = $poll_answer_percentage;
627
- if(sizeof($poll_answer_percentage_array) == sizeof($poll_answers)) {
628
- $percentage_error_buffer = 100 - array_sum($poll_answer_percentage_array);
629
- $poll_answer_percentage = $poll_answer_percentage + $percentage_error_buffer;
630
- if($poll_answer_percentage < 0) {
631
- $poll_answer_percentage = 0;
 
 
 
632
  }
633
  }
634
  }
 
635
  // Let User See What Options They Voted
636
  if(in_array($poll_answer_id, $user_voted)) {
637
  // Results Body Variables
@@ -1317,48 +1323,53 @@ function 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
- $check_voted = check_voted($poll_id);
1321
- if($check_voted == 0) {
1322
- if(!empty($user_identity)) {
1323
- $pollip_user = htmlspecialchars(addslashes($user_identity));
1324
- } elseif(!empty($_COOKIE['comment_author_'.COOKIEHASH])) {
1325
- $pollip_user = htmlspecialchars(addslashes($_COOKIE['comment_author_'.COOKIEHASH]));
1326
- } else {
1327
- $pollip_user = __('Guest', 'wp-polls');
1328
- }
1329
- $pollip_userid = intval($user_ID);
1330
- $pollip_ip = get_ipaddress();
1331
- $pollip_host = esc_attr(@gethostbyaddr($pollip_ip));
1332
- $pollip_timestamp = current_time('timestamp');
1333
- // Only Create Cookie If User Choose Logging Method 1 Or 2
1334
- $poll_logging_method = intval(get_option('poll_logging_method'));
1335
- if($poll_logging_method == 1 || $poll_logging_method == 3) {
1336
- $cookie_expiry = intval(get_option('poll_cookielog_expiry'));
1337
- if($cookie_expiry == 0) {
1338
- $cookie_expiry = 30000000;
1339
  }
1340
- $vote_cookie = setcookie('voted_'.$poll_id, $poll_aid, ($pollip_timestamp + $cookie_expiry), apply_filters('wp_polls_cookiepath', SITECOOKIEPATH));
1341
- }
1342
- $i = 0;
1343
- foreach($poll_aid_array as $polla_aid) {
1344
- $update_polla_votes = $wpdb->query("UPDATE $wpdb->pollsa SET polla_votes = (polla_votes+1) WHERE polla_qid = $poll_id AND polla_aid = $polla_aid");
1345
- if(!$update_polla_votes) {
1346
- unset($poll_aid_array[$i]);
 
 
 
 
 
1347
  }
1348
- $i++;
1349
- }
1350
- $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");
1351
- if($vote_q) {
1352
- foreach($poll_aid_array as $polla_aid) {
1353
- $wpdb->query("INSERT INTO $wpdb->pollsip VALUES (0, $poll_id, $polla_aid, '$pollip_ip', '$pollip_host', '$pollip_timestamp', '$pollip_user', $pollip_userid)");
 
1354
  }
1355
- echo display_pollresult($poll_id,$poll_aid_array, false);
 
 
 
 
 
 
 
 
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(__('Invalid Poll ID. Poll ID #%s', 'wp-polls'), $poll_id);
1364
  } // End if($poll_id > 0 && !empty($poll_aid_array) && check_allowtovote())
@@ -1515,7 +1526,7 @@ function polls_page_general_stats($content) {
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 casted.', '<strong>%s</strong> votes were casted.', get_pollvotes(false), 'wp-polls'), number_format_i18n(get_pollvotes(false))).'</li>'."\n";
1519
  $content .= '</ul>'."\n";
1520
  }
1521
  return $content;
@@ -1616,20 +1627,42 @@ function widget_polls_init() {
1616
  }
1617
 
1618
 
1619
- ### Function: Create Poll Tables
1620
- add_action('activate_wp-polls/wp-polls.php', 'create_poll_table');
1621
- function create_poll_table() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1622
  global $wpdb;
1623
- polls_textdomain();
1624
- if(@is_file(ABSPATH.'/wp-admin/includes/upgrade.php')) {
1625
- include_once(ABSPATH.'/wp-admin/includes/upgrade.php');
1626
- }elseif(@is_file(ABSPATH.'/wp-admin/upgrade-functions.php')) {
1627
  include_once(ABSPATH.'/wp-admin/upgrade-functions.php');
1628
  } elseif(@is_file(ABSPATH.'/wp-admin/includes/upgrade.php')) {
1629
  include_once(ABSPATH.'/wp-admin/includes/upgrade.php');
1630
  } else {
1631
  die('We have problem finding your \'/wp-admin/upgrade-functions.php\' and \'/wp-admin/includes/upgrade.php\'');
1632
  }
 
1633
  // Create Poll Tables (3 Tables)
1634
  $charset_collate = '';
1635
  if( $wpdb->has_cap( 'collation' ) ) {
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.68
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-polls
13
  /*
14
  Copyright 2014 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.68 );
34
 
35
 
36
  ### Create Text Domain For Translations
48
 
49
 
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
 
197
  ### Function: Enqueue Polls JavaScripts/CSS
198
  add_action('wp_enqueue_scripts', 'poll_scripts');
199
  function poll_scripts() {
 
200
  if(@file_exists(get_stylesheet_directory().'/polls-css.css')) {
201
  wp_enqueue_style('wp-polls', get_stylesheet_directory_uri().'/polls-css.css', false, WP_POLLS_VERSION, 'all');
202
  } else {
203
  wp_enqueue_style('wp-polls', plugins_url('wp-polls/polls-css.css'), false, WP_POLLS_VERSION, 'all');
204
  }
205
+ if( is_rtl() ) {
206
  if(@file_exists(get_stylesheet_directory().'/polls-css-rtl.css')) {
207
  wp_enqueue_style('wp-polls-rtl', get_stylesheet_directory_uri().'/polls-css-rtl.css', false, WP_POLLS_VERSION, 'all');
208
  } else {
226
  ### Function: Enqueue Polls Stylesheets/JavaScripts In WP-Admin
227
  add_action('admin_enqueue_scripts', 'poll_scripts_admin');
228
  function poll_scripts_admin($hook_suffix) {
 
229
  $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');
230
  if(in_array($hook_suffix, $poll_admin_pages)) {
231
  wp_enqueue_style('wp-polls-admin', plugins_url('wp-polls/polls-admin-css.css'), false, WP_POLLS_VERSION, 'all');
232
  wp_enqueue_script('wp-polls-admin', plugins_url('wp-polls/polls-admin-js.js'), array('jquery'), WP_POLLS_VERSION, true);
233
  wp_localize_script('wp-polls-admin', 'pollsAdminL10n', array(
234
  'admin_ajax_url' => admin_url('admin-ajax.php'),
235
+ 'text_direction' => is_rtl() ? 'right' : 'left',
236
  'text_delete_poll' => __('Delete Poll', 'wp-polls'),
237
  'text_no_poll_logs' => __('No poll logs available.', 'wp-polls'),
238
  'text_delete_all_logs' => __('Delete All Logs', 'wp-polls'),
421
 
422
  function poll_template_vote_markup($template, $poll_db_object, $variables) {
423
 
424
+ foreach($variables as $placeholder => $value) {
425
+ $template = str_replace($placeholder, $value, $template);
426
+ }
427
 
428
+ return $template;
429
  }
430
 
431
 
454
 
455
  $template_question = stripslashes(get_option('poll_template_voteheader'));
456
 
457
+ $template_question = apply_filters('poll_template_voteheader_markup', $template_question, $poll_question, array(
458
+ '%POLL_QUESTION%' => $poll_question_text,
459
+ '%POLL_ID%' => $poll_question_id,
460
+ '%POLL_TOTALVOTES%' => $poll_question_totalvotes,
461
+ '%POLL_TOTALVOTERS%' => $poll_question_totalvoters,
462
+ '%POLL_START_DATE%' => $poll_start_date,
463
+ '%POLL_END_DATE%' => $poll_end_date,
464
+ '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
465
+ ));
466
 
467
  // Get Poll Answers Data
468
  $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'));
485
  $poll_answer_votes = intval($poll_answer->polla_votes);
486
  $template_answer = stripslashes(get_option('poll_template_votebody'));
487
 
488
+ $template_answer = apply_filters('poll_template_votebody_markup', $template_answer, $poll_answer, array(
489
+ '%POLL_ID%' => $poll_question_id,
490
+ '%POLL_ANSWER_ID%' => $poll_answer_id,
491
+ '%POLL_ANSWER%' => $poll_answer_text,
492
+ '%POLL_ANSWER_VOTES%' => number_format_i18n($poll_answer_votes),
493
+ "%POLL_CHECKBOX_RADIO%" => $poll_multiple_ans > 0 ? 'checkbox' : 'radio'
494
+ ));
495
 
496
  // Print Out Voting Form Body Template
497
  $temp_pollvote .= "\t\t$template_answer\n";
509
  // Voting Form Footer Variables
510
  $template_footer = stripslashes(get_option('poll_template_votefooter'));
511
 
512
+ $template_footer = apply_filters('poll_template_votefooter_markup', $template_footer, $poll_question, array(
513
+ '%POLL_ID%' => $poll_question_id,
514
+ '%POLL_RESULT_URL%' => $poll_result_url,
515
+ '%POLL_START_DATE%' => $poll_start_date,
516
+ '%POLL_END_DATE%' => $poll_end_date,
517
+ '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1
518
+ ));
519
 
520
  // Print Out Voting Form Footer Template
521
  $temp_pollvote .= "\t\t$template_footer\n";
555
  $poll_least_percentage = 0;
556
  // Get Poll Question Data
557
  $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");
558
+ // No poll could be loaded from the database
559
+ if (!$poll_question) {
560
+ echo stripslashes(get_option('poll_template_disable'));
561
+ return;
562
+ }
563
  // Poll Question Variables
564
  $poll_question_text = stripslashes($poll_question->pollq_question);
565
  $poll_question_id = intval($poll_question->pollq_id);
624
  $poll_answer_imagewidth = 1;
625
  }
626
  // Make Sure That Total Percentage Is 100% By Adding A Buffer To The Last Poll Answer
627
+ $round_percentage = apply_filters( 'wp_polls_round_percentage', false );
628
+ if( $round_percentage ) {
629
+ if ( $poll_multiple_ans === 0 ) {
630
+ $poll_answer_percentage_array[] = $poll_answer_percentage;
631
+ if ( sizeof( $poll_answer_percentage_array ) === sizeof( $poll_answers ) ) {
632
+ $percentage_error_buffer = 100 - array_sum( $poll_answer_percentage_array );
633
+ $poll_answer_percentage = $poll_answer_percentage + $percentage_error_buffer;
634
+ if ( $poll_answer_percentage < 0 ) {
635
+ $poll_answer_percentage = 0;
636
+ }
637
  }
638
  }
639
  }
640
+
641
  // Let User See What Options They Voted
642
  if(in_array($poll_answer_id, $user_voted)) {
643
  // Results Body Variables
1323
  $poll_aid = $_POST["poll_$poll_id"];
1324
  $poll_aid_array = array_unique(array_map('intval', explode(',', $poll_aid)));
1325
  if($poll_id > 0 && !empty($poll_aid_array) && check_allowtovote()) {
1326
+ $is_poll_open = intval( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->pollsq WHERE pollq_id = %d AND pollq_active = 1", $poll_id ) ) );
1327
+ if ( $is_poll_open > 0 ) {
1328
+ $check_voted = check_voted($poll_id);
1329
+ if ($check_voted == 0) {
1330
+ if (!empty($user_identity)) {
1331
+ $pollip_user = htmlspecialchars(addslashes($user_identity));
1332
+ } elseif (!empty($_COOKIE['comment_author_' . COOKIEHASH])) {
1333
+ $pollip_user = htmlspecialchars(addslashes($_COOKIE['comment_author_' . COOKIEHASH]));
1334
+ } else {
1335
+ $pollip_user = __('Guest', 'wp-polls');
 
 
 
 
 
 
 
 
 
1336
  }
1337
+ $pollip_userid = intval($user_ID);
1338
+ $pollip_ip = get_ipaddress();
1339
+ $pollip_host = esc_attr(@gethostbyaddr($pollip_ip));
1340
+ $pollip_timestamp = current_time('timestamp');
1341
+ // Only Create Cookie If User Choose Logging Method 1 Or 2
1342
+ $poll_logging_method = intval(get_option('poll_logging_method'));
1343
+ if ($poll_logging_method == 1 || $poll_logging_method == 3) {
1344
+ $cookie_expiry = intval(get_option('poll_cookielog_expiry'));
1345
+ if ($cookie_expiry == 0) {
1346
+ $cookie_expiry = 30000000;
1347
+ }
1348
+ $vote_cookie = setcookie('voted_' . $poll_id, $poll_aid, ($pollip_timestamp + $cookie_expiry), apply_filters('wp_polls_cookiepath', SITECOOKIEPATH));
1349
  }
1350
+ $i = 0;
1351
+ foreach ($poll_aid_array as $polla_aid) {
1352
+ $update_polla_votes = $wpdb->query("UPDATE $wpdb->pollsa SET polla_votes = (polla_votes+1) WHERE polla_qid = $poll_id AND polla_aid = $polla_aid");
1353
+ if (!$update_polla_votes) {
1354
+ unset($poll_aid_array[$i]);
1355
+ }
1356
+ $i++;
1357
  }
1358
+ $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");
1359
+ if ($vote_q) {
1360
+ foreach ($poll_aid_array as $polla_aid) {
1361
+ $wpdb->query("INSERT INTO $wpdb->pollsip VALUES (0, $poll_id, $polla_aid, '$pollip_ip', '$pollip_host', '$pollip_timestamp', '$pollip_user', $pollip_userid)");
1362
+ }
1363
+ echo display_pollresult($poll_id, $poll_aid_array, false);
1364
+ } else {
1365
+ printf(__('Unable To Update Poll Total Votes And Poll Total Voters. Poll ID #%s', 'wp-polls'), $poll_id);
1366
+ } // End if($vote_a)
1367
  } else {
1368
+ printf(__('You Had Already Voted For This Poll. Poll ID #%s', 'wp-polls'), $poll_id);
1369
+ } // End if($check_voted)
1370
  } else {
1371
+ printf( __( 'Poll ID #%s is closed', 'wp-polls' ), $poll_id );
1372
+ } // End if($is_poll_open > 0)
1373
  } else {
1374
  printf(__('Invalid Poll ID. Poll ID #%s', 'wp-polls'), $poll_id);
1375
  } // End if($poll_id > 0 && !empty($poll_aid_array) && check_allowtovote())
1526
  $content .= '<ul>'."\n";
1527
  $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";
1528
  $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";
1529
+ $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";
1530
  $content .= '</ul>'."\n";
1531
  }
1532
  return $content;
1627
  }
1628
 
1629
 
1630
+ ### Function: Activate Plugin
1631
+ register_activation_hook( __FILE__, 'polls_activation' );
1632
+ function polls_activation( $network_wide )
1633
+ {
1634
+ if ( is_multisite() && $network_wide )
1635
+ {
1636
+ $ms_sites = wp_get_sites();
1637
+
1638
+ if( 0 < sizeof( $ms_sites ) )
1639
+ {
1640
+ foreach ( $ms_sites as $ms_site )
1641
+ {
1642
+ switch_to_blog( $ms_site['blog_id'] );
1643
+ polls_activate();
1644
+ }
1645
+ }
1646
+
1647
+ restore_current_blog();
1648
+ }
1649
+ else
1650
+ {
1651
+ polls_activate();
1652
+ }
1653
+ }
1654
+
1655
+ function polls_activate() {
1656
  global $wpdb;
1657
+
1658
+ if(@is_file(ABSPATH.'/wp-admin/upgrade-functions.php')) {
 
 
1659
  include_once(ABSPATH.'/wp-admin/upgrade-functions.php');
1660
  } elseif(@is_file(ABSPATH.'/wp-admin/includes/upgrade.php')) {
1661
  include_once(ABSPATH.'/wp-admin/includes/upgrade.php');
1662
  } else {
1663
  die('We have problem finding your \'/wp-admin/upgrade-functions.php\' and \'/wp-admin/includes/upgrade.php\'');
1664
  }
1665
+
1666
  // Create Poll Tables (3 Tables)
1667
  $charset_collate = '';
1668
  if( $wpdb->has_cap( 'collation' ) ) {
wp-polls.pot CHANGED
@@ -118,28 +118,28 @@ msgstr[1] ""
118
 
119
  #: polls-logs.php:130
120
  msgid ""
121
- "<strong>&raquo;</strong> <strong>%s</strong> vote is casted by registered "
122
  "users"
123
  msgid_plural ""
124
- "<strong>&raquo;</strong> <strong>%s</strong> votes are casted by registered "
125
  "users"
126
  msgstr[0] ""
127
  msgstr[1] ""
128
 
129
  #: polls-logs.php:131
130
  msgid ""
131
- "<strong>&raquo;</strong> <strong>%s</strong> vote is casted by comment "
132
  "authors"
133
  msgid_plural ""
134
- "<strong>&raquo;</strong> <strong>%s</strong> votes are casted by comment "
135
  "authors"
136
  msgstr[0] ""
137
  msgstr[1] ""
138
 
139
  #: polls-logs.php:132
140
- msgid "<strong>&raquo;</strong> <strong>%s</strong> vote is casted by guests"
141
  msgid_plural ""
142
- "<strong>&raquo;</strong> <strong>%s</strong> votes are casted by guests"
143
  msgstr[0] ""
144
  msgstr[1] ""
145
 
@@ -452,7 +452,7 @@ msgid "Total Polls' Answers:"
452
  msgstr ""
453
 
454
  #: polls-manager.php:449
455
- msgid "Total Votes Casted:"
456
  msgstr ""
457
 
458
  #: polls-manager.php:462
@@ -1337,8 +1337,8 @@ msgstr[0] ""
1337
  msgstr[1] ""
1338
 
1339
  #: wp-polls.php:1504
1340
- msgid "<strong>%s</strong> vote was casted."
1341
- msgid_plural "<strong>%s</strong> votes were casted."
1342
  msgstr[0] ""
1343
  msgstr[1] ""
1344
 
118
 
119
  #: polls-logs.php:130
120
  msgid ""
121
+ "<strong>&raquo;</strong> <strong>%s</strong> vote is cast by registered "
122
  "users"
123
  msgid_plural ""
124
+ "<strong>&raquo;</strong> <strong>%s</strong> votes are cast by registered "
125
  "users"
126
  msgstr[0] ""
127
  msgstr[1] ""
128
 
129
  #: polls-logs.php:131
130
  msgid ""
131
+ "<strong>&raquo;</strong> <strong>%s</strong> vote is cast by comment "
132
  "authors"
133
  msgid_plural ""
134
+ "<strong>&raquo;</strong> <strong>%s</strong> votes are cast by comment "
135
  "authors"
136
  msgstr[0] ""
137
  msgstr[1] ""
138
 
139
  #: polls-logs.php:132
140
+ msgid "<strong>&raquo;</strong> <strong>%s</strong> vote is cast by guests"
141
  msgid_plural ""
142
+ "<strong>&raquo;</strong> <strong>%s</strong> votes are cast by guests"
143
  msgstr[0] ""
144
  msgstr[1] ""
145
 
452
  msgstr ""
453
 
454
  #: polls-manager.php:449
455
+ msgid "Total Votes Cast:"
456
  msgstr ""
457
 
458
  #: polls-manager.php:462
1337
  msgstr[1] ""
1338
 
1339
  #: wp-polls.php:1504
1340
+ msgid "<strong>%s</strong> vote was cast."
1341
+ msgid_plural "<strong>%s</strong> votes were cast."
1342
  msgstr[0] ""
1343
  msgstr[1] ""
1344