WP-Polls - Version 2.06b

Version Description

Download this release

Release Info

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

Version 2.06b

polls/images/pollbar.gif ADDED
Binary file
polls/images/pollend.gif ADDED
Binary file
polls/images/pollstart.gif ADDED
Binary file
polls/polls-debug.php ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-Polls Debug
4
+ Plugin URI: http://www.lesterchan.net/portfolio/programming.php
5
+ Description: Adds A Poll Feature To WordPress
6
+ Version: 2.04
7
+ Author: GaMerZ
8
+ Author URI: http://www.lesterchan.net
9
+ */
10
+
11
+
12
+ /* Copyright 2005 Lester Chan (email : gamerz84@hotmail.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ */
28
+
29
+
30
+ ### Polls Table Name
31
+ $wpdb->pollsq = $table_prefix . 'pollsq';
32
+ $wpdb->pollsa = $table_prefix . 'pollsa';
33
+ $wpdb->pollsip = $table_prefix . 'pollsip';
34
+
35
+
36
+ ### Function: Poll Administration Menu
37
+ add_action('admin_menu', 'poll_menu');
38
+ function poll_menu() {
39
+ if (function_exists('add_menu_page')) {
40
+ add_menu_page(__('Polls'), __('Polls'), 'manage_polls', 'polls-manager.php');
41
+ }
42
+ if (function_exists('add_submenu_page')) {
43
+ add_submenu_page('polls-manager.php', __('Manage Polls'), __('Manage Polls'), 'manage_polls', 'polls-manager.php');
44
+ add_submenu_page('polls-manager.php', __('Poll Option'), __('Poll Option'), 'manage_polls', 'polls-options.php');
45
+ }
46
+ }
47
+
48
+
49
+ ### Function: Poll Administration Role
50
+ add_action('admin_head', 'poll_role');
51
+ function poll_role() {
52
+ if(function_exists('get_role')) {
53
+ $role = get_role('administrator');
54
+ $role->add_cap('manage_polls');
55
+ }
56
+ }
57
+
58
+
59
+ ### Function: Get Poll
60
+ function get_poll($temp_poll_id = 0) {
61
+ global $wpdb;
62
+ // Check Whether Poll Is Disabled
63
+ if(intval(get_settings('poll_currentpoll')) == -1) {
64
+ echo stripslashes(get_settings('poll_template_disable'));
65
+ return;
66
+ // Poll Is Enabled
67
+ } else {
68
+ // Hardcoded Poll ID Is Not Specified
69
+ if(intval($temp_poll_id) == 0) {
70
+ // Current Poll ID Is Not Specified
71
+ if(intval(get_settings('poll_currentpoll')) == 0) {
72
+ // Get Lastest Poll ID
73
+ $poll_id = intval(get_settings('poll_latestpoll'));
74
+ } else {
75
+ // Get Current Poll ID
76
+ $poll_id = intval(get_settings('poll_currentpoll'));
77
+ }
78
+ // Get Hardcoded Poll ID
79
+ } else {
80
+ $poll_id = intval($temp_poll_id);
81
+ }
82
+ }
83
+
84
+ // User Click on View Results Link
85
+ if(intval($_GET['pollresult']) == 1) {
86
+ display_pollresult($poll_id);
87
+ // Check Whether User Has Voted
88
+ } else {
89
+ // Check Cookie First
90
+ $voted_cookie = check_voted_cookie($poll_id);
91
+ if($voted_cookie > 0) {
92
+ display_pollresult($poll_id, $voted_cookie);
93
+ // Check IP If Cookie Cannot Be Found
94
+ } else {
95
+ $voted_ip = check_voted_ip($poll_id);
96
+ if($voted_ip > 0) {
97
+ display_pollresult($poll_id, $voted_ip);
98
+ // User Never Vote. Display Poll Voting Form
99
+ } else {
100
+ display_pollvote($poll_id);
101
+ }
102
+ }
103
+ }
104
+ }
105
+
106
+
107
+ ### Function: Check Voted By Cookie
108
+ function check_voted_cookie($poll_id) {
109
+ // 0: False | > 0: True
110
+ return intval($_COOKIE["voted_$poll_id"]);
111
+ }
112
+
113
+
114
+ ### Function: Check Voted By IP
115
+ function check_voted_ip($poll_id) {
116
+ global $wpdb;
117
+ // Check IP From IP Logging Database
118
+ $get_voted_aid = $wpdb->get_var("SELECT pollip_aid FROM $wpdb->pollsip WHERE pollip_qid = $poll_id AND pollip_ip = '".get_ipaddress()."'");
119
+ // 0: False | > 0: True
120
+ return intval($get_voted_aid);
121
+ }
122
+
123
+
124
+ ### Function: Display Voting Form
125
+ function display_pollvote($poll_id) {
126
+ global $wpdb;
127
+ // Get Poll Question Data
128
+ $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
129
+ // Poll Question Variables
130
+ $poll_question_text = stripslashes($poll_question->pollq_question);
131
+ $poll_question_id = intval($poll_question->pollq_id);
132
+ $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
133
+ $template_question = stripslashes(get_settings('poll_template_voteheader'));
134
+ $template_question = str_replace("%POLL_QUESTION%", $poll_question_text, $template_question);
135
+ $template_question = str_replace("%POLL_ID%", $poll_question_id, $template_question);
136
+ $template_question = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_question);
137
+ // Get Poll Answers Data
138
+ $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = $poll_question_id ORDER BY ".get_settings('poll_ans_sortby').' '.get_settings('poll_ans_sortorder'));
139
+ // If There Is Poll Question With Answers
140
+ if($poll_question && $poll_answers) {
141
+ // Display Poll Voting Form
142
+ echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">'."\n";
143
+ echo "<input type=\"hidden\" name=\"poll_id\" value=\"$poll_question_id\" />\n";
144
+ // Print Out Voting Form Header Template
145
+ echo $template_question;
146
+ foreach($poll_answers as $poll_answer) {
147
+ // Poll Answer Variables
148
+ $poll_answer_id = intval($poll_answer->polla_aid);
149
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
150
+ $poll_answer_votes = intval($poll_answer->polla_votes);
151
+ $template_answer = stripslashes(get_settings('poll_template_votebody'));
152
+ $template_answer = str_replace("%POLL_ID%", $poll_question_id, $template_answer);
153
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
154
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
155
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $poll_answer_votes, $template_answer);
156
+ // Print Out Voting Form Body Template
157
+ echo $template_answer;
158
+ }
159
+ // Determine Poll Result URL
160
+ $poll_result_url = $_SERVER['REQUEST_URI'];
161
+ if(strpos($poll_result_url, '?') !== false) {
162
+ $poll_result_url = $poll_result_url.'&pollresult=1';
163
+ } else {
164
+ $poll_result_url = $poll_result_url.'?pollresult=1';
165
+ }
166
+ // Voting Form Footer Variables
167
+ $template_footer = stripslashes(get_settings('poll_template_votefooter'));
168
+ $template_footer = str_replace("%POLL_RESULT_URL%", $poll_result_url, $template_footer);
169
+ // Print Out Voting Form Footer Template
170
+ echo $template_footer;
171
+ echo "</form>\n";
172
+ } else {
173
+ echo stripslashes(get_settings('poll_template_disable'));
174
+ }
175
+ }
176
+
177
+
178
+ ### Function: Display Results Form
179
+ function display_pollresult($poll_id, $user_voted = 0) {
180
+ global $wpdb;
181
+ // Get Poll Question Data
182
+ $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
183
+ // Poll Question Variables
184
+ $poll_question_text = stripslashes($poll_question->pollq_question);
185
+ $poll_question_id = intval($poll_question->pollq_id);
186
+ $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
187
+ $template_question = stripslashes(get_settings('poll_template_resultheader'));
188
+ $template_question = str_replace("%POLL_QUESTION%", $poll_question_text, $template_question);
189
+ $template_question = str_replace("%POLL_ID%", $poll_question_id, $template_question);
190
+ $template_question = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_question);
191
+ // Get Poll Answers Data
192
+ $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = $poll_question_id ORDER BY ".get_settings('poll_ans_result_sortby').' '.get_settings('poll_ans_result_sortorder'));
193
+ // If There Is Poll Question With Answers
194
+ if($poll_question && $poll_answers) {
195
+ // Is The Poll Total Votes 0?
196
+ $poll_totalvotes_zero = true;
197
+ if($poll_question_totalvotes > 0) {
198
+ $poll_totalvotes_zero = false;
199
+ }
200
+ // Print Out Result Header Template
201
+ echo $template_question;
202
+ foreach($poll_answers as $poll_answer) {
203
+ // Poll Answer Variables
204
+ $poll_answer_id = intval($poll_answer->polla_aid);
205
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
206
+ $poll_answer_votes = intval($poll_answer->polla_votes);
207
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
208
+ $poll_answer_percentage = 0;
209
+ $poll_answer_imagewidth = 0;
210
+ // Calculate Percentage And Image Bar Width
211
+ if(!$poll_totalvotes_zero) {
212
+ if($poll_answer_votes > 0) {
213
+ $poll_answer_percentage = round((($poll_answer_votes/$poll_question_totalvotes)*100));
214
+ $poll_answer_imagewidth = round($poll_answer_percentage*0.9);
215
+ } else {
216
+ $poll_answer_percentage = 0;
217
+ $poll_answer_imagewidth = 1;
218
+ }
219
+ } else {
220
+ $poll_answer_percentage = 0;
221
+ $poll_answer_imagewidth = 1;
222
+ }
223
+ // Let User See What Options They Voted
224
+ if($user_voted == $poll_answer_id) {
225
+ // Results Body Variables
226
+ $template_answer = stripslashes(get_settings('poll_template_resultbody2'));
227
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
228
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
229
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $poll_answer_votes, $template_answer);
230
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
231
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
232
+ // Print Out Results Body Template
233
+ echo $template_answer;
234
+ } else {
235
+ // Results Body Variables
236
+ $template_answer = stripslashes(get_settings('poll_template_resultbody'));
237
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
238
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
239
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $poll_answer_votes, $template_answer);
240
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
241
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
242
+ // Print Out Results Body Template
243
+ echo $template_answer;
244
+ }
245
+ }
246
+ // Results Footer Variables
247
+ $template_footer = stripslashes(get_settings('poll_template_resultfooter'));
248
+ $template_footer = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_footer);
249
+ // Print Out Results Footer Template
250
+ echo $template_footer;
251
+ } else {
252
+ echo stripslashes(get_settings('poll_template_disable'));
253
+ }
254
+ }
255
+
256
+
257
+ ### Function: Vote Poll
258
+ add_action('init', 'vote_poll');
259
+ function vote_poll() {
260
+ global $wpdb, $user_identity;
261
+ if(!empty($_POST['vote'])) {
262
+ $poll_id = intval($_POST['poll_id']);
263
+ $poll_aid = intval($_POST["poll-$poll_id"]);
264
+ if($poll_id > 0 && $poll_aid > 0) {
265
+ $voted_ip = check_voted_ip($poll_id);
266
+ $voted_cookie = check_voted_cookie($poll_ip);
267
+ if($voted_ip == 0 && $voted_cookie == 0) {
268
+ if(!empty($user_identity)) {
269
+ $pollip_user = addslashes($user_identity);
270
+ } elseif(!empty($_COOKIE['comment_author_'.COOKIEHASH])) {
271
+ $pollip_user = addslashes($_COOKIE['comment_author_'.COOKIEHASH]);
272
+ } else {
273
+ $pollip_user = 'Guest';
274
+ }
275
+ $vote_cookie = setcookie("voted_".$poll_id, $poll_aid, time() + 30000000, COOKIEPATH);
276
+ if($vote_cookie) {
277
+ $pollip_ip = get_ipaddress();
278
+ $pollip_host = gethostbyaddr($pollip_ip);
279
+ $pollip_timestamp = current_time('timestamp');
280
+ $vote_ip = $wpdb->query("INSERT INTO $wpdb->pollsip VALUES(0,$poll_id,$poll_aid,'$pollip_ip','$pollip_host','$pollip_timestamp','$pollip_user')");
281
+ if($vote_ip) {
282
+ $vote_a = $wpdb->query("UPDATE $wpdb->pollsa SET polla_votes = (polla_votes+1) WHERE polla_qid = $poll_id AND polla_aid = $poll_aid");
283
+ if($vote_a) {
284
+ $vote_q = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes+1) WHERE pollq_id = $poll_id");
285
+ if(!$vote_q) {
286
+ echo "Error Updating Poll Total Votes:- UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes+1) WHERE pollq_id = $poll_id";
287
+ }
288
+ } else {
289
+ echo "Error Updating Poll Answer Vote:- UPDATE $wpdb->pollsa SET polla_votes = (polla_votes+1) WHERE polla_qid = $poll_id AND polla_aid = $poll_aid";
290
+ }
291
+ } else {
292
+ echo "Error Inserting Poll IP:- INSERT INTO $wpdb->pollsip VALUES(0, $poll_id, $poll_aid, '$pollip_ip', '$pollip_host', '$pollip_timestamp', '$pollip_user')";
293
+ }
294
+ } else {
295
+ echo "Error Setting Poll Cookie:- (voted_$poll_id, $poll_aid, ".(time() + 30000000).", ".COOKIEPATH.")";
296
+ }
297
+ } else {
298
+ echo "You Have Already Voted:- voted_ip: $voted_ip | voted_cookie: $voted_cookie";
299
+ }
300
+ } else {
301
+ echo "Invalid Poll ID And Poll Answer ID:- poll_id: $poll_id | poll_aid: $poll_aid";
302
+ }
303
+ } else {
304
+ echo "Empty Poll Vote Button:- $_POST[vote]";
305
+ }
306
+ }
307
+
308
+
309
+ ### Function: Get IP Address
310
+ function get_ipaddress() {
311
+ if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
312
+ $ip_address = $_SERVER["REMOTE_ADDR"];
313
+ } else {
314
+ $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
315
+ }
316
+ if(strpos($ip_address, ',') !== false) {
317
+ $ip_address = explode(',', $ip_address);
318
+ $ip_address = $ip_address[0];
319
+ }
320
+ return $ip_address;
321
+ }
322
+
323
+
324
+ ### Function: Place Poll In Content (By: Robert Accettura Of http://robert.accettura.com/)
325
+ add_filter('the_content', 'place_poll', '12');
326
+ function place_poll($content){
327
+ $content = preg_replace( "/\[poll=(\d+)\]/ise", "display_poll('\\1')", $content);
328
+ return $content;
329
+ }
330
+
331
+
332
+ ### Function: Display The Poll In Content (By: Robert Accettura Of http://robert.accettura.com/)
333
+ function display_poll($poll_id, $display_pollarchive = true){
334
+ if (function_exists('vote_poll')){
335
+ if($display_pollarchive) {
336
+ return get_poll($poll_id)."\n".'<p><a href="'.get_settings('home').'/wp-polls.php">Polls Archive</a></p>';
337
+ } else {
338
+ return get_poll($poll_id);
339
+ }
340
+ }
341
+ }
342
+ ?>
polls/polls-manager.php ADDED
@@ -0,0 +1,622 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.06 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Manage Your Polls |
14
+ | - wp-content/plugins/polls/polls-manager.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('polls/polls-manager.php');
28
+ $base_page = 'admin.php?page='.$base_name;
29
+ $mode = trim($_GET['mode']);
30
+ $poll_id = intval($_GET['id']);
31
+ $poll_aid = intval($_GET['aid']);
32
+
33
+
34
+ ### Form Processing
35
+ if(!empty($_POST['do'])) {
36
+ // Decide What To Do
37
+ switch($_POST['do']) {
38
+ // Add Poll
39
+ case 'Add Poll':
40
+ // Add Poll Question
41
+ $pollq_question = addslashes(trim($_POST['pollq_question']));
42
+ $pollq_timestamp = current_time('timestamp');
43
+ $add_poll_question = $wpdb->query("INSERT INTO $wpdb->pollsq VALUES (0, '$pollq_question', '$pollq_timestamp', 0)");
44
+ if(!$add_poll_question) {
45
+ $text .= '<font color="red">Error In Adding Poll \''.stripslashes($pollq_question).'\'</font>';
46
+ }
47
+ // Add Poll Answers
48
+ $polla_answers = $_POST['polla_answers'];
49
+ $polla_qid = intval($wpdb->insert_id);
50
+ foreach($polla_answers as $polla_answer) {
51
+ $polla_answer = addslashes(trim($polla_answer));
52
+ $add_poll_answers = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answer', 0)");
53
+ if(!$add_poll_answers) {
54
+ $text .= '<font color="red">Error In Adding Poll\'s Answer \''.stripslashes($polla_answer).'\'</font>';
55
+ }
56
+ }
57
+ // Update Lastest Poll ID To Poll Options
58
+ $update_latestpoll = update_option('poll_latestpoll', $polla_qid);
59
+ if(!$update_latestpoll) {
60
+ $text .= "<font color=\"red\">There Is An Error Updating The Lastest Poll ID ($polla_qid) To The Poll Option</font>";
61
+ }
62
+ if(empty($text)) {
63
+ $text = '<font color="green">Poll \''.stripslashes($pollq_question).'\' Added Successfully</font>';
64
+ }
65
+ break;
66
+ // Edit Poll
67
+ case 'Edit Poll':
68
+ // Update Poll's Question
69
+ $pollq_id = intval($_POST['pollq_id']);
70
+ $pollq_totalvotes = intval($_POST['pollq_totalvotes']);
71
+ $pollq_question = addslashes(trim($_POST['pollq_question']));
72
+ $edit_polltimestamp = intval($_POST['edit_polltimestamp']);
73
+ $timestamp_sql = '';
74
+ if($edit_polltimestamp == 1) {
75
+ $pollq_timestamp_day = intval($_POST['pollq_timestamp_day']);
76
+ $pollq_timestamp_month = intval($_POST['pollq_timestamp_month']);
77
+ $pollq_timestamp_year = intval($_POST['pollq_timestamp_year']);
78
+ $pollq_timestamp_hour = intval($_POST['pollq_timestamp_hour']);
79
+ $pollq_timestamp_minute = intval($_POST['pollq_timestamp_minute']);
80
+ $pollq_timestamp_second = intval($_POST['pollq_timestamp_second']);
81
+ $timestamp_sql = ", pollq_timestamp = '".gmmktime($pollq_timestamp_hour, $pollq_timestamp_minute, $pollq_timestamp_second, $pollq_timestamp_month, $pollq_timestamp_day, $pollq_timestamp_year)."'";
82
+ }
83
+
84
+ $edit_poll_question = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_question = '$pollq_question', pollq_totalvotes = $pollq_totalvotes $timestamp_sql WHERE pollq_id = $pollq_id");
85
+ if(!$edit_poll_question) {
86
+ $text = '<font color="blue">No Changes Had Been Made To \''.stripslashes($pollq_question).'\'</font>';
87
+ }
88
+ // Update Polls' Answers
89
+ $polla_aids = array();
90
+ $get_polla_aids = $wpdb->get_results("SELECT polla_aid FROM $wpdb->pollsa WHERE polla_qid = $pollq_id ORDER BY polla_aid ASC");
91
+ if($get_polla_aids) {
92
+ foreach($get_polla_aids as $get_polla_aid) {
93
+ $polla_aids[] = intval($get_polla_aid->polla_aid);
94
+ }
95
+ foreach($polla_aids as $polla_aid) {
96
+ $polla_answers = addslashes(trim($_POST['polla_aid-'.$polla_aid]));
97
+ $polla_votes = intval($_POST['polla_votes-'.$polla_aid]);
98
+ $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");
99
+ if(!$edit_poll_answer) {
100
+ $text .= '<br /><font color="blue">No Changes Had Been Made To Poll\'s Answer \''.stripslashes($polla_answers).'\'</font>';
101
+ }
102
+ }
103
+ } else {
104
+ $text .= '<br /><font color="red">Invalid Poll \''.stripslashes($pollq_question).'\'</font>';
105
+ }
106
+ if(empty($text)) {
107
+ $text = '<font color="green">Poll \''.stripslashes($pollq_question).'\' Edited Successfully</font>';
108
+ }
109
+ break;
110
+ // Delete Poll
111
+ case 'Delete Poll':
112
+ $pollq_id = intval($_POST['pollq_id']);
113
+ $pollq_question = trim($_POST['pollq_question']);
114
+ $delete_poll_question = $wpdb->query("DELETE FROM $wpdb->pollsq WHERE pollq_id = $pollq_id");
115
+ $delete_poll_answers = $wpdb->query("DELETE FROM $wpdb->pollsa WHERE polla_qid = $pollq_id");
116
+ $delete_poll_ip = $wpdb->query("DELETE FROM $wpdb->pollsip WHERE pollip_qid = $pollq_id");
117
+ $poll_option_lastestpoll = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'poll_latestpoll'");
118
+ if(!$delete_poll_question) {
119
+ $text = '<font color="red">Error In Deleting Poll \''.stripslashes($pollq_question).'\' Question</font>';
120
+ }
121
+ if(!$delete_poll_answers) {
122
+ $text .= '<br /><font color="red">Error In Deleting Poll Answers For \''.stripslashes($pollq_question).'\'</font>';
123
+ }
124
+ if(!$delete_poll_ip) {
125
+ $text .= '<br /><font color="red">Error In Deleting Voted IPs For \''.stripslashes($pollq_question).'\'</font>';
126
+ }
127
+ if(empty($text)) {
128
+ if($poll_option_lastestpoll == $pollq_id) {
129
+ $poll_lastestpoll = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq ORDER BY pollq_id DESC LIMIT 1");
130
+ if($poll_lastestpoll) {
131
+ $poll_lastestpoll = intval($poll_lastestpoll);
132
+ update_option('poll_latestpoll', $poll_lastestpoll);
133
+ }
134
+ }
135
+ $text = '<font color="green">Poll \''.stripslashes($pollq_question).'\' Deleted Successfully</font>';
136
+ }
137
+ break;
138
+ // Add Poll's Answer
139
+ case 'Add Answer':
140
+ $polla_qid = intval($_POST['polla_qid']);
141
+ $polla_answers = addslashes(trim($_POST['polla_answers']));
142
+ $add_poll_question = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answers', 0)");
143
+ if(!$add_poll_question) {
144
+ $text = '<font color="red">Error In Adding Poll Answer \''.stripslashes($polla_answers).'\'</font>';
145
+ } else {
146
+ $text = '<font color="green">Poll Answer \''.stripslashes($polla_answers).'\' Added Successfully</font>';
147
+ }
148
+ break;
149
+ }
150
+ }
151
+
152
+
153
+ ### Determines Which Mode It Is
154
+ switch($mode) {
155
+ // Add A Poll
156
+ case 'add':
157
+ ?>
158
+ <div class="wrap">
159
+ <h2><?php _e('Add Poll'); ?></h2>
160
+ <?php
161
+ if(isset($_POST['addpollquestion'])) {
162
+ $poll_noquestion = intval($_POST['poll_noquestion']);
163
+ $pollq_question = stripslashes(trim($_POST['pollq_question']));
164
+ ?>
165
+ <form action="<?php echo $base_page; ?>" method="post">
166
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
167
+ <tr>
168
+ <th align="left"><?php _e('Question') ?></th>
169
+ <td><input type="text" size="50" maxlength="200" name="pollq_question" value="<?php echo $pollq_question; ?>"></td>
170
+ <?php
171
+ for($i=1; $i<=$poll_noquestion; $i++) {
172
+ echo "<tr>\n";
173
+ echo "<th align=\"left\" scope=\"row\">Answers $i:</th>\n";
174
+ echo "<td><input type=\"text\" size=\"30\" maxlength=\"200\" name=\"polla_answers[]\"></td>\n";
175
+ echo "</tr>\n";
176
+ }
177
+ ?>
178
+ </tr>
179
+ <tr>
180
+ <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Add Poll'); ?>" class="button">&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
181
+ </tr>
182
+ </table>
183
+ </form>
184
+ <?php } else {?>
185
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>&amp;mode=add" method="post">
186
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
187
+ <tr>
188
+ <th align="left"><?php _e('Question') ?></th>
189
+ <td><input type="text" size="50" maxlength="200" name="pollq_question"></td>
190
+ </tr>
191
+ <th align="left"><?php _e('No. Of Answers:') ?></th>
192
+ <td>
193
+ <select size="1" name="poll_noquestion">
194
+ <?php
195
+ for($i=2; $i <= 20; $i++) {
196
+ echo "<option value=\"$i\">$i</option>";
197
+ }
198
+ ?>
199
+ </select>
200
+ </td>
201
+ </tr>
202
+ <tr>
203
+ <td colspan="2" align="center"><input type="submit" name="addpollquestion" value="<?php _e('Add Question'); ?>" class="button">&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
204
+ </tr>
205
+ </table>
206
+ </form>
207
+ <?php } ?>
208
+ </div>
209
+ <?php
210
+ break;
211
+ // Edit A Poll
212
+ case 'edit':
213
+ $poll_question = $wpdb->get_row("SELECT pollq_question, pollq_timestamp, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id");
214
+ $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");
215
+ $poll_question_text = stripslashes($poll_question->pollq_question);
216
+ $poll_totalvotes = intval($poll_question->pollq_totalvote);
217
+ $poll_timestamp = $poll_question->pollq_timestamp;
218
+
219
+ // Edit Timestamp Options
220
+ function poll_timestamp($poll_timestamp) {
221
+ global $month;
222
+ $day = gmdate('j', $poll_timestamp);
223
+ echo '<select name="pollq_timestamp_day" size="1">"'."\n";
224
+ for($i = 1; $i <=31; $i++) {
225
+ if($day == $i) {
226
+ echo "<option value=\"$i\" selected=\"true\">$i</option>\n";
227
+ } else {
228
+ echo "<option value=\"$i\">$i</option>\n";
229
+ }
230
+ }
231
+ echo '</select>&nbsp;&nbsp;'."\n";
232
+ $month2 = gmdate('n', $poll_timestamp);
233
+ echo '<select name="pollq_timestamp_month" size="1">"'."\n";
234
+ for($i = 1; $i <= 12; $i++) {
235
+ if ($i < 10) {
236
+ $ii = '0'.$i;
237
+ } else {
238
+ $ii = $i;
239
+ }
240
+ if($month2 == $i) {
241
+ echo "<option value=\"$i\" selected=\"true\">$month[$ii]</option>\n";
242
+ } else {
243
+ echo "<option value=\"$i\">$month[$ii]</option>\n";
244
+ }
245
+ }
246
+ echo '</select>&nbsp;&nbsp;'."\n";
247
+ $year = gmdate('Y', $poll_timestamp);
248
+ echo '<select name="pollq_timestamp_year" size="1">"'."\n";
249
+ for($i = 2000; $i <= gmdate('Y'); $i++) {
250
+ if($year == $i) {
251
+ echo "<option value=\"$i\" selected=\"true\">$i</option>\n";
252
+ } else {
253
+ echo "<option value=\"$i\">$i</option>\n";
254
+ }
255
+ }
256
+ echo '</select>&nbsp;@'."\n";
257
+ $hour = gmdate('H', $poll_timestamp);
258
+ echo '<select name="pollq_timestamp_hour" size="1">"'."\n";
259
+ for($i = 0; $i < 24; $i++) {
260
+ if($hour == $i) {
261
+ echo "<option value=\"$i\" selected=\"true\">$i</option>\n";
262
+ } else {
263
+ echo "<option value=\"$i\">$i</option>\n";
264
+ }
265
+ }
266
+ echo '</select>&nbsp;:'."\n";
267
+ $minute = gmdate('i', $poll_timestamp);
268
+ echo '<select name="pollq_timestamp_minute" size="1">"'."\n";
269
+ for($i = 0; $i < 60; $i++) {
270
+ if($minute == $i) {
271
+ echo "<option value=\"$i\" selected=\"true\">$i</option>\n";
272
+ } else {
273
+ echo "<option value=\"$i\">$i</option>\n";
274
+ }
275
+ }
276
+
277
+ echo '</select>&nbsp;:'."\n";
278
+ $second = gmdate('s', $poll_timestamp);
279
+ echo '<select name="pollq_timestamp_second" size="1">"'."\n";
280
+ for($i = 0; $i <= 60; $i++) {
281
+ if($second == $i) {
282
+ echo "<option value=\"$i\" selected=\"true\">$i</option>\n";
283
+ } else {
284
+ echo "<option value=\"$i\">$i</option>\n";
285
+ }
286
+ }
287
+ echo '</select>'."\n";
288
+ }
289
+ ?>
290
+ <script language="Javascript" type="text/javascript">
291
+ function check_totalvotes() {
292
+ var total_votes = 0;
293
+ var temp_vote = 0;
294
+ <?php
295
+ foreach($poll_answers as $poll_answer) {
296
+ $polla_aid = intval($poll_answer->polla_aid);
297
+ echo "\t\t\t\ttemp_vote = parseInt(document.getElementById('polla_votes-$polla_aid').value);\n";
298
+ echo "\t\t\t\tif(isNaN(temp_vote)) {\n";
299
+ echo "\t\t\t\tdocument.getElementById('polla_votes-$polla_aid').value = 0;\n";
300
+ echo "\t\t\t\ttemp_vote = 0;\n";
301
+ echo "\t\t\t\t}\n";
302
+ echo "\t\t\t\ttotal_votes += temp_vote;\n";
303
+ }
304
+ ?>
305
+ document.getElementById('pollq_totalvotes').value = parseInt(total_votes);
306
+ }
307
+ </script>
308
+ <!-- Edit Poll -->
309
+ <div class="wrap">
310
+ <h2><?php _e('Edit Poll'); ?></h2>
311
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
312
+ <input type="hidden" name="pollq_id" value="<?php echo $poll_id; ?>">
313
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
314
+ <tr>
315
+ <th colspan="2"><?php _e('Question') ?></th>
316
+ </tr>
317
+ <tr>
318
+ <td align="center" colspan="2"><input type="text" size="70" maxlength="200" name="pollq_question" value="<?php echo $poll_question_text; ?>" /></td>
319
+ </tr>
320
+ <tr>
321
+ <th align="left"><?php _e('Answers:') ?></th>
322
+ <th align="right"><?php _e('No. Of Votes') ?></th>
323
+ </tr>
324
+ <?php
325
+ $i=1;
326
+ $poll_actual_totalvotes = 0;
327
+ if($poll_answers) {
328
+ $pollip_answers = array();
329
+ $pollip_answers[0] = __('Null Votes');
330
+ foreach($poll_answers as $poll_answer) {
331
+ $polla_aid = intval($poll_answer->polla_aid);
332
+ $polla_answers = stripslashes($poll_answer->polla_answers);
333
+ $polla_votes = intval($poll_answer->polla_votes);
334
+ $pollip_answers[$polla_aid] = $polla_answers;
335
+ echo "<tr>\n";
336
+ echo "<td align=\"left\">".__('Answer')." $i:&nbsp;&nbsp;&nbsp;<input type=\"text\" size=\"50\" maxlength=\"200\" name=\"polla_aid-$polla_aid\" value=\"$polla_answers\" />&nbsp;&nbsp;&nbsp;";
337
+ echo "<a href=\"$base_page&amp;mode=deleteans&id=$poll_id&aid=$polla_aid\" onclick=\"return confirm('You Are About To Delete This Poll Answer \'$polla_answers\'\\n \'Cancel\' to stop, \'OK\' to delete.')\">Delete</a></td>\n";
338
+ echo "<td align=\"right\">$polla_votes&nbsp;&nbsp;&nbsp;<input type=\"text\" size=\"4\" maxlength=\"6\" id=\"polla_votes-$polla_aid\" name=\"polla_votes-$polla_aid\" value=\"$polla_votes\" onblur=\"check_totalvotes();\" /></td>\n</tr>\n";
339
+ $poll_actual_totalvotes += $polla_votes;
340
+ $i++;
341
+ }
342
+ }
343
+ ?>
344
+ </tr>
345
+ <tr>
346
+ <td align="right" colspan="2"><b><?php _e('Total Votes'); ?>: <?php echo $poll_actual_totalvotes; ?></b>&nbsp;&nbsp;&nbsp;<input type="text" size="4" maxlength="4" id="pollq_totalvotes" name="pollq_totalvotes" value="<?php echo $poll_actual_totalvotes; ?>" onblur="check_totalvotes();" /></td>
347
+ </tr>
348
+ <tr>
349
+ <td colspan="2"><b><?php _e('Timestamp'); ?></b>:</td>
350
+ </tr>
351
+ <tr>
352
+ <td colspan="2"><input type="checkbox" name="edit_polltimestamp" value="1" />Edit Timestamp<br /><?php poll_timestamp($poll_timestamp); ?><br />Existing Timestamp: <?php echo gmdate('jS F Y @ H:i:s', $poll_timestamp); ?></td>
353
+ </tr>
354
+ <tr>
355
+ <td align="center" colspan="2"><input type="submit" name="do" value="<?php _e('Edit Poll'); ?>" class="button">&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
356
+ </tr>
357
+ </table>
358
+ </form>
359
+ </div>
360
+ <!-- Add Poll's Answer -->
361
+ <div class="wrap">
362
+ <h2><?php _e('Add Answer') ?></h2>
363
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>&amp;mode=edit&amp;id=<?php echo $poll_id; ?>" method="post">
364
+ <input type="hidden" name="polla_qid" value="<?php echo $poll_id; ?>">
365
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
366
+ <tr>
367
+ <td><b><?php _e('Add Answer') ?></b></td>
368
+ <td><input type="text" size="50" maxlength="200" name="polla_answers"></td>
369
+ </tr>
370
+ <tr>
371
+ <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Add Answer'); ?>" class="button"></td>
372
+ </tr>
373
+ </table>
374
+ </form>
375
+ </div>
376
+ <!-- Users Voted For This Poll -->
377
+ <?php
378
+ $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");
379
+ ?>
380
+ <div class="wrap">
381
+ <h2><?php _e('Users Voted For This Poll') ?></h2>
382
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
383
+ <?php
384
+ if($poll_ips) {
385
+ $k = 1;
386
+ $poll_last_aid = -1;
387
+ foreach($poll_ips as $poll_ip) {
388
+ $pollip_aid = intval($poll_ip->pollip_aid);
389
+ $pollip_user = stripslashes($poll_ip->pollip_user);
390
+ $pollip_ip = $poll_ip->pollip_ip;
391
+ $pollip_host = $poll_ip->pollip_host;
392
+ $pollip_date = gmdate("jS F Y @ H:i", $poll_ip->pollip_timestamp);
393
+ if($pollip_aid != $poll_last_aid) {
394
+ if($pollip_aid == 0) {
395
+ echo "<tr style='background-color: #b8d4ff'>\n<td colspan=\"4\"><b>$pollip_answers[$pollip_aid]</b></td>\n</tr>\n";
396
+ } else {
397
+ echo "<tr style='background-color: #b8d4ff'>\n<td colspan=\"4\"><b>".__('Answer')." $k: $pollip_answers[$pollip_aid]</b></td>\n</tr>\n";
398
+ $k++;
399
+ }
400
+ echo "<tr>\n";
401
+ echo "<th scope=\"row\">".__('No.')."</th>\n";
402
+ echo "<th scope=\"row\">".__('User')."</th>\n";
403
+ echo "<th scope=\"row\">".__('IP/Host')."</th>\n";
404
+ echo "<th scope=\"row\">".__('Date')."</th>\n";
405
+ echo "</tr>\n";
406
+ $i = 1;
407
+ }
408
+ if($i%2 == 0) {
409
+ $style = 'style=\'background-color: none\'';
410
+ } else {
411
+ $style = 'style=\'background-color: #eee\'';
412
+ }
413
+ echo "<tr $style>\n";
414
+ echo "<td>$i</td>\n";
415
+ echo "<td>$pollip_user</td>\n";
416
+ echo "<td>$pollip_ip / $pollip_host</td>\n";
417
+ echo "<td>$pollip_date</td>\n";
418
+ echo "</tr>\n";
419
+ $poll_last_aid = $pollip_aid;
420
+ $i++;
421
+ }
422
+ } else {
423
+ echo "<tr>\n<td colspan=\"4\" align=\"center\">".__('No IP Has Been Logged Yet.')."</td>\n</tr>\n";
424
+ }
425
+ ?>
426
+ </table>
427
+ </div>
428
+ <?php
429
+ break;
430
+ // Delete A Poll
431
+ case 'delete':
432
+ $poll_question = $wpdb->get_row("SELECT pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id");
433
+ $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = $poll_id ORDER BY polla_answers");
434
+ $poll_question_text = stripslashes($poll_question->pollq_question);
435
+ $poll_totalvotes = intval($poll_question->pollq_totalvotes);
436
+ ?>
437
+ <!-- Delete Poll -->
438
+ <div class="wrap">
439
+ <h2><?php _e('Delete Poll') ?></h2>
440
+ <form action="<?php echo $base_page; ?>" method="post">
441
+ <input type="hidden" name="pollq_id" value="<?php echo $poll_id; ?>">
442
+ <input type="hidden" name="pollq_question" value="<?php echo $poll_question_text; ?>">
443
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
444
+ <tr>
445
+ <th colspan="2"><?php _e('Question') ?></th>
446
+ </tr>
447
+ <tr>
448
+ <td colspan="2" align="center"><?php echo $poll_question_text; ?></td>
449
+ </tr>
450
+ <tr>
451
+ <th align="left"><?php _e('Answers') ?></th>
452
+ <th><?php _e('No. Of Votes') ?></th>
453
+ </tr>
454
+ <?php
455
+ $i=1;
456
+ if($poll_answers) {
457
+ foreach($poll_answers as $poll_answer) {
458
+ $polla_answers = stripslashes($poll_answer->polla_answers);
459
+ $polla_votes = intval($poll_answer->polla_votes);
460
+ echo "<tr>\n";
461
+ echo "<td>".__('Answer')." $i:&nbsp;&nbsp;&nbsp;$polla_answers</td>\n";
462
+ echo "<td align=\"center\">$polla_votes</td>\n</tr>\n";
463
+ $i++;
464
+ }
465
+ }
466
+ ?>
467
+ </tr>
468
+ <tr>
469
+ <th colspan="2"><?php _e('Total Votes'); ?>: <?php echo $poll_totalvotes; ?></th>
470
+ </tr>
471
+ <tr>
472
+ <td align="center" colspan="2"><br /><p><b><?php _e('You Are About To Delete This Poll'); ?> '<?php echo $poll_question_text; ?>'</b></p><input type="submit" class="button" name="do" value="<?php _e('Delete Poll'); ?>" onclick="return confirm('You Are About To The Delete This Poll \'<?php echo $poll_question_text; ?>\'.\nThis Action Is Not Reversible.\n\n Choose \'Cancel\' to stop, \'OK\' to delete.')">&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
473
+ </tr>
474
+ </table>
475
+ </form>
476
+ </div>
477
+ <?php
478
+ break;
479
+ // Delete A Poll Answer
480
+ case 'deleteans':
481
+ $poll_answers = $wpdb->get_row("SELECT polla_votes, polla_answers FROM $wpdb->pollsa WHERE polla_aid = $poll_aid AND polla_qid = $poll_id");
482
+ $polla_votes = intval($poll_answers->polla_votes);
483
+ $polla_answers = stripslashes(trim($poll_answers->polla_answers));
484
+ $delete_polla_answers = $wpdb->query("DELETE FROM $wpdb->pollsa WHERE polla_aid = $poll_aid AND polla_qid = $poll_id");
485
+ $update_pollq_totalvotes = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes-$polla_votes) WHERE pollq_id=$poll_id");
486
+ ?>
487
+ <!-- Delete Poll's Answer -->
488
+ <div class="wrap">
489
+ <h2><?php _e('Delete Poll\'s Answer') ?></h2>
490
+ <?php
491
+ if($delete_polla_answers) {
492
+ $text = "<font color=\"green\">Poll Answer '$polla_answers' Deleted Successfully</font>";
493
+ } else {
494
+ $text = "<font color=\"red\">Error In Deleting Poll Answer '$polla_answers'</font>";
495
+ }
496
+ if($update_pollq_totalvotes) {
497
+ $text .= "<br /><font color=\"green\">Poll Question's Total Votes Updated Successfully</font>";
498
+ } else {
499
+ $text .= "<br /><font color=\"blue\">No Changes Had Been Made To The Poll's Total Votes</font>";
500
+ }
501
+ _e($text);
502
+ ?>
503
+ <p><b><a href="<?php echo $base_page; ?>&amp;mode=edit&amp;id=<?php echo $poll_id; ?>"><?php _e('Click here To Go Back To The Poll Edit Page'); ?></a>.</b></p>
504
+ </div>
505
+ <?php
506
+ break;
507
+ // Main Page
508
+ default:
509
+ $polls = $wpdb->get_results("SELECT * FROM $wpdb->pollsq ORDER BY pollq_id DESC");
510
+ $total_ans = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->pollsa");
511
+ $total_votes = 0;
512
+ ?>
513
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
514
+ <!-- Manage Polls -->
515
+ <div class="wrap">
516
+ <h2><?php _e('Manage Polls'); ?></h2>
517
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
518
+ <tr>
519
+ <th scope="col"><?php _e('ID'); ?></b></th>
520
+ <th scope="col"><?php _e('Question'); ?></b></th>
521
+ <th scope="col"><?php _e('Total Votes'); ?></b></th>
522
+ <th scope="col"><?php _e('Date Added'); ?></b></th>
523
+ <th scope="col" colspan="2"><?php _e('Action'); ?></th>
524
+ </tr>
525
+ <?php
526
+ if($polls) {
527
+ $i = 0;
528
+ $current_poll = intval(get_settings('poll_currentpoll'));
529
+ foreach($polls as $poll) {
530
+ $poll_id = intval($poll->pollq_id);
531
+ $poll_question = stripslashes($poll->pollq_question);
532
+ $poll_date = gmdate("jS F Y @ H:i", $poll->pollq_timestamp);
533
+ $poll_totalvotes = intval($poll->pollq_totalvotes);
534
+ if($i%2 == 0) {
535
+ $style = 'style=\'background-color: #eee\'';
536
+ } else {
537
+ $style = 'style=\'background-color: none\'';
538
+ }
539
+ if($current_poll > 0) {
540
+ if($current_poll == $poll_id) {
541
+ $style = 'style=\'background-color: #b8d4ff\'';
542
+ }
543
+ } else {
544
+ if($i == 0) {
545
+ $style = 'style=\'background-color: #b8d4ff\'';
546
+ }
547
+ }
548
+ echo "<tr $style>\n";
549
+ echo "<td><b>$poll_id</b></td>\n";
550
+ echo '<td>';
551
+ if($current_poll > 0) {
552
+ if($current_poll == $poll_id) {
553
+ echo '<b>'.__('Displayed:').'</b> ';
554
+ }
555
+ } elseif($current_poll != -1) {
556
+ if($i == 0) {
557
+ echo '<b>'.__('Displayed:').'</b> ';
558
+ }
559
+ }
560
+ echo "$poll_question</td>\n";
561
+ echo "<td>$poll_totalvotes</td>\n";
562
+ echo "<td>$poll_date</td>\n";
563
+ echo "<td><a href=\"$base_page&amp;mode=edit&amp;id=$poll_id\" class=\"edit\">".__('Edit')."</a></td>\n";
564
+ echo "<td><a href=\"$base_page&amp;mode=delete&amp;id=$poll_id\" class=\"delete\">".__('Delete')."</a></td>\n";
565
+ echo '</tr>';
566
+ $i++;
567
+ $total_votes+= $poll_totalvotes;
568
+
569
+ }
570
+ } else {
571
+ echo '<tr><td colspan="6" align="center"><b>'.__('No Polls Found').'</b></td></tr>';
572
+ }
573
+ ?>
574
+ </table>
575
+ </div>
576
+ <!-- Add A Poll -->
577
+ <div class="wrap">
578
+ <h2><?php _e('Add A Poll'); ?></h2>
579
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>&amp;mode=add" method="post">
580
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
581
+ <tr>
582
+ <th align="left"><?php _e('Question') ?></th>
583
+ <td><input type="text" size="50" maxlength="200" name="pollq_question"></td>
584
+ </tr>
585
+ <th align="left"><?php _e('No. Of Answers:') ?></th>
586
+ <td>
587
+ <select size="1" name="poll_noquestion">
588
+ <?php
589
+ for($k=2; $k <= 20; $k++) {
590
+ echo "<option value=\"$k\">$k</option>";
591
+ }
592
+ ?>
593
+ </select>
594
+ </td>
595
+ </tr>
596
+ <tr>
597
+ <td colspan="2" align="center"><input type="submit" name="addpollquestion" value="<?php _e('Add Question'); ?>" class="button" /></td>
598
+ </tr>
599
+ </table>
600
+ </form>
601
+ </div>
602
+ <!-- Polls Stats -->
603
+ <div class="wrap">
604
+ <h2><?php _e('Polls Stats'); ?></h2>
605
+ <table border="0" cellspacing="3" cellpadding="3">
606
+ <tr>
607
+ <th align="left"><?php _e('Total Polls:'); ?></th>
608
+ <td align="left"><?php echo $i; ?></td>
609
+ </tr>
610
+ <tr>
611
+ <th align="left"><?php _e('Total Polls\' Answers:'); ?></th>
612
+ <td align="left"><?php echo number_format($total_ans); ?></td>
613
+ </tr>
614
+ <tr>
615
+ <th align="left"><?php _e('Total Votes Casted:'); ?></th>
616
+ <td align="left"><?php echo number_format($total_votes); ?></td>
617
+ </tr>
618
+ </table>
619
+ </div>
620
+ <?php
621
+ } // End switch($mode)
622
+ ?>
polls/polls-options.php ADDED
@@ -0,0 +1,379 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.06 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Configure Poll Options |
14
+ | - wp-content/plugins/polls/polls-options.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('polls/polls-options.php');
28
+ $base_page = 'admin.php?page='.$base_name;
29
+ $id = intval($_GET['id']);
30
+
31
+
32
+ ### If Form Is Submitted
33
+ if($_POST['Submit']) {
34
+ $poll_ans_sortby = strip_tags(trim($_POST['poll_ans_sortby']));
35
+ $poll_ans_sortorder = strip_tags(trim($_POST['poll_ans_sortorder']));
36
+ $poll_ans_result_sortby = strip_tags(trim($_POST['poll_ans_result_sortby']));
37
+ $poll_ans_result_sortorder = strip_tags(trim($_POST['poll_ans_result_sortorder']));
38
+ $poll_template_voteheader =trim($_POST['poll_template_voteheader']);
39
+ $poll_template_votebody = trim($_POST['poll_template_votebody']);
40
+ $poll_template_votefooter = trim($_POST['poll_template_votefooter']);
41
+ $poll_template_resultheader = trim($_POST['poll_template_resultheader']);
42
+ $poll_template_resultbody = trim($_POST['poll_template_resultbody']);
43
+ $poll_template_resultbody2 = trim($_POST['poll_template_resultbody2']);
44
+ $poll_template_resultfooter = trim($_POST['poll_template_resultfooter']);
45
+ $poll_template_disable = trim($_POST['poll_template_disable']);
46
+ $poll_template_error = trim($_POST['poll_template_error']);
47
+ $poll_archive_perpage = intval($_POST['poll_archive_perpage']);
48
+ $poll_currentpoll = intval($_POST['poll_currentpoll']);
49
+ $update_poll_queries = array();
50
+ $update_poll_text = array();
51
+ $update_poll_queries[] = update_option('poll_ans_sortby', $poll_ans_sortby);
52
+ $update_poll_queries[] = update_option('poll_ans_sortorder', $poll_ans_sortorder);
53
+ $update_poll_queries[] = update_option('poll_ans_result_sortby', $poll_ans_result_sortby);
54
+ $update_poll_queries[] = update_option('poll_ans_result_sortorder', $poll_ans_result_sortorder);
55
+ $update_poll_queries[] = update_option('poll_template_voteheader', $poll_template_voteheader);
56
+ $update_poll_queries[] = update_option('poll_template_votebody', $poll_template_votebody);
57
+ $update_poll_queries[] = update_option('poll_template_votefooter', $poll_template_votefooter);
58
+ $update_poll_queries[] = update_option('poll_template_resultheader', $poll_template_resultheader);
59
+ $update_poll_queries[] = update_option('poll_template_resultbody', $poll_template_resultbody);
60
+ $update_poll_queries[] = update_option('poll_template_resultbody2', $poll_template_resultbody2);
61
+ $update_poll_queries[] = update_option('poll_template_resultfooter', $poll_template_resultfooter);
62
+ $update_poll_queries[] = update_option('poll_template_disable', $poll_template_disable);
63
+ $update_poll_queries[] = update_option('poll_template_error', $poll_template_error);
64
+ $update_poll_queries[] = update_option('poll_archive_perpage', $poll_archive_perpage);
65
+ $update_poll_queries[] = update_option('poll_currentpoll', $poll_currentpoll);
66
+ $update_poll_text[] = __('Sort Poll Answers By Option');
67
+ $update_poll_text[] = __('Sort Order Of Poll Answers Option');
68
+ $update_poll_text[] = __('Sort Poll Results By Option');
69
+ $update_poll_text[] = __('Sort Order Of Poll Results Option');
70
+ $update_poll_text[] = __('Voting Form Header Template');
71
+ $update_poll_text[] = __('Voting Form Body Template');
72
+ $update_poll_text[] = __('Voting Form Footer Template');
73
+ $update_poll_text[] = __('Result Header Template');
74
+ $update_poll_text[] = __('Result Body Template');
75
+ $update_poll_text[] = __('Result Body2 Template');
76
+ $update_poll_text[] = __('Result Footer Template');
77
+ $update_poll_text[] = __('Poll Disabled Template');
78
+ $update_poll_text[] = __('Poll Error Template');
79
+ $update_poll_text[] = __('Archive Polls Per Page Option');
80
+ $update_poll_text[] = __('Current Active Poll Option');
81
+ $i=0;
82
+ $text = '';
83
+ foreach($update_poll_queries as $update_poll_query) {
84
+ if($update_poll_query) {
85
+ $text .= '<font color="green">'.$update_poll_text[$i].' '.__('Updated').'</font><br />';
86
+ }
87
+ $i++;
88
+ }
89
+ if(empty($text)) {
90
+ $text = '<font color="red">'.__('No Poll Option Updated').'</font>';
91
+ }
92
+ }
93
+
94
+ ?>
95
+ <script language="JavaScript" type="text/javascript">
96
+ function poll_default_templates(template) {
97
+ var default_template;
98
+ switch(template) {
99
+ case "voteheader":
100
+ default_template = "<p align=\"center\"><b>%POLL_QUESTION%</b></p>\n<ul>";
101
+ break;
102
+ case "votebody":
103
+ default_template = "<li><label for=\"poll-answer-%POLL_ANSWER_ID%\"><input type=\"radio\" id=\"poll-answer-%POLL_ANSWER_ID%\" name=\"poll-%POLL_ID%\" value=\"%POLL_ANSWER_ID%\" /> %POLL_ANSWER%</label></li>";
104
+ break;
105
+ case "votefooter":
106
+ default_template = "</ul>\n<p align=\"center\"><input type=\"submit\" name=\"vote\" value=\" Vote \" class=\"Buttons\" /><br /><a href=\"%POLL_RESULT_URL%\">View Results</a></p>";
107
+ break;
108
+ case "resultheader":
109
+ default_template = "<p align=\"center\"><b>%POLL_QUESTION%</b></p>\n<ul>";
110
+ break;
111
+ case "resultbody":
112
+ default_template = "<li>%POLL_ANSWER% <small>(%POLL_ANSWER_PERCENTAGE%%)</small><br /><img src=\"<?php echo get_settings('siteurl'); ?>/wp-content/plugins/polls/images/pollstart.gif\" height=\"10\" width=\"2\" /><img src=\"<?php echo get_settings('siteurl'); ?>/wp-content/plugins/polls/images/pollbar.gif\" height=\"10\" width=\"%POLL_ANSWER_IMAGEWIDTH%\" alt=\"%POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)\" title=\"%POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)\" /><img src=\"<?php echo get_settings('siteurl'); ?>/wp-content/plugins/polls/images/pollend.gif\" height=\"10\" width=\"2\" /></li>";
113
+ break;
114
+ case "resultbody2":
115
+ default_template = "<li><b><i>%POLL_ANSWER% <small>(%POLL_ANSWER_PERCENTAGE%%)</small></i></b><br /><img src=\"<?php echo get_settings('siteurl'); ?>/wp-content/plugins/polls/images/pollstart.gif\" height=\"10\" width=\"2\" /><img src=\"<?php echo get_settings('siteurl'); ?>/wp-content/plugins/polls/images/pollbar.gif\" height=\"10\" width=\"%POLL_ANSWER_IMAGEWIDTH%\" alt=\"You Have Voted For This Choice - %POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)\" title=\"You Have Voted For This Choice - %POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)\" /><img src=\"<?php echo get_settings('siteurl'); ?>/wp-content/plugins/polls/images/pollend.gif\" height=\"10\" width=\"2\" /></li>";
116
+ break;
117
+ case "resultfooter":
118
+ default_template = "</ul>\n<p align=\"center\">Total Votes: <b>%POLL_TOTALVOTES%</b></p>";
119
+ break;
120
+ case "disable":
121
+ default_template = 'Sorry, there are no polls available at the moment.';
122
+ break;
123
+ case "error":
124
+ default_template = 'An error has occurred when processing your poll.';
125
+ break;
126
+ }
127
+ document.getElementById("poll_template_" + template).value = default_template;
128
+ }
129
+
130
+ </script>
131
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
132
+ <div class="wrap">
133
+ <h2><?php _e('Poll Options'); ?></h2>
134
+ <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
135
+ <fieldset class="options">
136
+ <legend><?php _e('Sorting Of Poll Answers'); ?></legend>
137
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
138
+ <tr valign="top">
139
+ <th align="left" width="30%"><?php _e('Sort Poll Answers By:'); ?></th>
140
+ <td align="left">
141
+ <select name="poll_ans_sortby" size="1">
142
+ <option value="polla_aid"<?php selected('polla_aid', get_settings('poll_ans_sortby')); ?>><?php _e('Exact Order'); ?></option>
143
+ <option value="polla_answers"<?php selected('polla_answers', get_settings('poll_ans_sortby')); ?>><?php _e('Alphabetical Order'); ?></option>
144
+ </select>
145
+ </td>
146
+ </tr>
147
+ <tr valign="top">
148
+ <th align="left" width="30%"><?php _e('Sort Order Of Poll Answers:'); ?></th>
149
+ <td align="left">
150
+ <select name="poll_ans_sortorder" size="1">
151
+ <option value="asc"<?php selected('asc', get_settings('poll_ans_sortorder')); ?>><?php _e('Ascending'); ?></option>
152
+ <option value="desc"<?php selected('desc', get_settings('poll_ans_sortorder')); ?>><?php _e('Descending'); ?></option>
153
+ </select>
154
+ </td>
155
+ </tr>
156
+ </table>
157
+ </fieldset>
158
+ <fieldset class="options">
159
+ <legend><?php _e('Sorting Of Poll Results'); ?></legend>
160
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
161
+ <tr valign="top">
162
+ <th align="left" width="30%"><?php _e('Sort Poll Results By:'); ?></th>
163
+ <td align="left">
164
+ <select name="poll_ans_result_sortby" size="1">
165
+ <option value="polla_votes"<?php selected('polla_votes', get_settings('poll_ans_result_sortby')); ?>><?php _e('Votes'); ?></option>
166
+ <option value="polla_aid"<?php selected('polla_aid', get_settings('poll_ans_result_sortby')); ?>><?php _e('Exact Order'); ?></option>
167
+ <option value="polla_answers"<?php selected('polla_answers', get_settings('poll_ans_result_sortby')); ?>><?php _e('Alphabetical Order'); ?></option>
168
+ </select>
169
+ </td>
170
+ </tr>
171
+ <tr valign="top">
172
+ <th align="left" width="30%"><?php _e('Sort Order Of Poll Results:'); ?></th>
173
+ <td align="left">
174
+ <select name="poll_ans_result_sortorder" size="1">
175
+ <option value="asc"<?php selected('asc', get_settings('poll_ans_result_sortorder')); ?>><?php _e('Ascending'); ?></option>
176
+ <option value="desc"<?php selected('desc', get_settings('poll_ans_result_sortorder')); ?>><?php _e('Descending'); ?></option>
177
+ </select>
178
+ </td>
179
+ </tr>
180
+ </table>
181
+ </fieldset>
182
+ <fieldset class="options">
183
+ <legend><?php _e('Poll Archive'); ?></legend>
184
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
185
+ <tr valign="top">
186
+ <th align="left" width="30%"><?php _e('Polls Per Page:'); ?></th>
187
+ <td align="left"><input type="text" name="poll_archive_perpage" value="<?php echo intval(get_settings('poll_archive_perpage')); ?>" size="2" /></td>
188
+ </tr>
189
+ </table>
190
+ </fieldset>
191
+ <fieldset class="options">
192
+ <legend><?php _e('Current Active Poll'); ?></legend>
193
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
194
+ <tr valign="top">
195
+ <th align="left" width="30%"><?php _e('Current Active Poll:'); ?></th>
196
+ <td align="left">
197
+ <select name="poll_currentpoll" size="1">
198
+ <option value="-1"<?php selected(-1, get_settings('poll_currentpoll')); ?>><?php _e('Do NOT Display Poll (Disable)'); ?></option>
199
+ <option value="-2"<?php selected(-2, get_settings('poll_currentpoll')); ?>><?php _e('Display Random Poll'); ?></option>
200
+ <option value="0"<?php selected(0, get_settings('poll_currentpoll')); ?>><?php _e('Display Latest Poll'); ?></option>
201
+ <option value="0"></option>
202
+ <?php
203
+ $polls = $wpdb->get_results("SELECT pollq_id, pollq_question FROM $wpdb->pollsq ORDER BY pollq_id DESC");
204
+ if($polls) {
205
+ foreach($polls as $poll) {
206
+ $poll_question = stripslashes($poll->pollq_question);
207
+ $poll_id = intval($poll->pollq_id);
208
+ if($poll_id == intval(get_settings('poll_currentpoll'))) {
209
+ echo "<option value=\"$poll_id\" selected=\"selected\">$poll_question</option>\n";
210
+ } else {
211
+ echo "<option value=\"$poll_id\">$poll_question</option>\n";
212
+ }
213
+ }
214
+ }
215
+ ?>
216
+ </select>
217
+ </td>
218
+ </tr>
219
+ </table>
220
+ </fieldset>
221
+ <fieldset class="options">
222
+ <legend><?php _e('Template Variables'); ?></legend>
223
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
224
+ <tr>
225
+ <td><b>%POLL_ID%</b> - <?php _e('Display the poll\'s ID'); ?></td>
226
+ <td><b>%POLL_ANSWER_ID%</b> - <?php _e('Display the poll\'s answer ID'); ?></td>
227
+ </tr>
228
+ <tr>
229
+ <td><b>%POLL_QUESTION%</b> - <?php _e('Display the poll\'s question'); ?></td>
230
+ <td><b>%POLL_ANSWER%</b> - <?php _e('Display the poll\'s answer'); ?></td>
231
+ </tr>
232
+ <tr>
233
+ <td><b>%POLL_TOTALVOTES%</b> - <?php _e('Display the poll\'s total votes'); ?></td>
234
+ <td><b>%POLL_ANSWER_VOTES%</b> - <?php _e('Display the poll\'s answer votes'); ?></td>
235
+ </tr>
236
+ <tr>
237
+ <td><b>%POLL_RESULT_URL%</b> - <?php _e('Displays URL to poll\'s result'); ?></td>
238
+ <td><b>%POLL_ANSWER_PERCENTAGE%</b> - <?php _e('Display the poll\'s answer percentage'); ?></td>
239
+ </tr>
240
+ <tr>
241
+ <td><b>%POLL_MOST_ANSWER%</b> - <?php _e('Display the poll\'s most voted answer'); ?></td>
242
+ <td><b>%POLL_ANSWER_IMAGEWIDTH%</b> - <?php _e('Display the poll\'s answer image width'); ?></td>
243
+ </tr>
244
+ <tr>
245
+ <td><b>%POLL_MOST_VOTES%</b> - <?php _e('Display the poll\'s answer votes for the most voted answer'); ?></td>
246
+ <td><b>%POLL_LEAST_ANSWER%</b> - <?php _e('Display the poll\'s least voted answer'); ?></td>
247
+ </tr>
248
+ <tr>
249
+ <td><b>%POLL_MOST_PERCENTAGE%</b> - <?php _e('Display the poll\'s answer percentage for the most voted answer'); ?></td>
250
+ <td><b>%POLL_LEAST_VOTES%</b> - <?php _e('Display the poll\'s answer votes for the least voted answer'); ?></td>
251
+ </tr>
252
+ <tr>
253
+ <td>&nbsp;</td>
254
+ <td><b>%POLL_LEAST_PERCENTAGE%</b> - <?php _e('Display the poll\'s answer percentage for the least voted answer'); ?></td>
255
+ </tr>
256
+ </table>
257
+ </fieldset>
258
+ <fieldset class="options">
259
+ <legend><?php _e('Poll Voting Form Templates'); ?></legend>
260
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
261
+ <tr valign="top">
262
+ <td width="30%" align="left">
263
+ <b><?php _e('Voting Form Header:'); ?></b><br /><br /><br />
264
+ <?php _e('Allowed Variables:'); ?><br />
265
+ - %POLL_ID%<br />
266
+ - %POLL_QUESTION%<br />
267
+ - %POLL_TOTALVOTES%<br /><br />
268
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('voteheader');" class="button" />
269
+ </td>
270
+ <td align="left"><textarea cols="80" rows="10" id="poll_template_voteheader" name="poll_template_voteheader"><?php echo stripslashes(get_settings('poll_template_voteheader')); ?></textarea></td>
271
+ </tr>
272
+ <tr valign="top">
273
+ <td width="30%" align="left">
274
+ <b><?php _e('Voting Form Body:'); ?></b><br /><br /><br />
275
+ <?php _e('Allowed Variables:'); ?><br />
276
+ - %POLL_ID%<br />
277
+ - %POLL_ANSWER_ID%<br />
278
+ - %POLL_ANSWER%<br />
279
+ - %POLL_ANSWER_VOTES%<br /><br />
280
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('votebody');" class="button" />
281
+ </td>
282
+ <td align="left"><textarea cols="80" rows="10" id="poll_template_votebody" name="poll_template_votebody"><?php echo stripslashes(get_settings('poll_template_votebody')); ?></textarea></td>
283
+ </tr>
284
+ <tr valign="top">
285
+ <td width="30%" align="left">
286
+ <b><?php _e('Voting Form Footer:'); ?></b><br /><br /><br />
287
+ <?php _e('Allowed Variables:'); ?><br />
288
+ - %POLL_RESULT_URL%<br /><br />
289
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('votefooter');" class="button" />
290
+ </td>
291
+ <td align="left"><textarea cols="80" rows="10" id="poll_template_votefooter" name="poll_template_votefooter"><?php echo stripslashes(get_settings('poll_template_votefooter')); ?></textarea></td>
292
+ </tr>
293
+ </table>
294
+ </fieldset>
295
+ <fieldset class="options">
296
+ <legend><?php _e('Poll Result Templates'); ?></legend>
297
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
298
+ <tr valign="top">
299
+ <td width="30%" align="left">
300
+ <b><?php _e('Result Header:'); ?></b><br /><br /><br />
301
+ <?php _e('Allowed Variables:'); ?><br />
302
+ - %POLL_ID%<br />
303
+ - %POLL_QUESTION%<br />
304
+ - %POLL_TOTALVOTES%<br /><br />
305
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultheader');" class="button" />
306
+ </td>
307
+ <td align="left"><textarea cols="80" rows="10" id="poll_template_resultheader" name="poll_template_resultheader"><?php echo stripslashes(get_settings('poll_template_resultheader')); ?></textarea></td>
308
+ </tr>
309
+ <tr valign="top">
310
+ <td width="30%" align="left">
311
+ <b><?php _e('Result Body:'); ?></b><br /><?php _e('Normal'); ?><br /><br />
312
+ <?php _e('Allowed Variables:'); ?><br />
313
+ - %POLL_ANSWER_ID%<br />
314
+ - %POLL_ANSWER%<br />
315
+ - %POLL_ANSWER_VOTES%<br />
316
+ - %POLL_ANSWER_PERCENTAGE%<br />
317
+ - %POLL_ANSWER_IMAGEWIDTH%<br /><br />
318
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultbody');" class="button" />
319
+ </td>
320
+ <td align="left"><textarea cols="80" rows="10" id="poll_template_resultbody" name="poll_template_resultbody"><?php echo stripslashes(get_settings('poll_template_resultbody')); ?></textarea></td>
321
+ </tr>
322
+ <tr valign="top">
323
+ <td width="30%" align="left">
324
+ <b><?php _e('Result Body:'); ?></b><br /><?php _e('Displaying Of User\'s Voted Answer'); ?><br /><br />
325
+ <?php _e('Allowed Variables:'); ?><br />
326
+ - %POLL_ANSWER_ID%<br />
327
+ - %POLL_ANSWER%<br />
328
+ - %POLL_ANSWER_VOTES%<br />
329
+ - %POLL_ANSWER_PERCENTAGE%<br />
330
+ - %POLL_ANSWER_IMAGEWIDTH%<br /><br />
331
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultbody2');" class="button" />
332
+ </td>
333
+ <td align="left"><textarea cols="80" rows="10" id="poll_template_resultbody2" name="poll_template_resultbody2"><?php echo stripslashes(get_settings('poll_template_resultbody2')); ?></textarea></td>
334
+ </tr>
335
+ <tr valign="top">
336
+ <td width="30%" align="left">
337
+ <b><?php _e('Result Footer:'); ?></b><br /><br /><br />
338
+ <?php _e('Allowed Variables:'); ?><br />
339
+ - %POLL_TOTALVOTES%<br />
340
+ - %POLL_MOST_ANSWER%<br />
341
+ - %POLL_MOST_VOTES%<br />
342
+ - %POLL_MOST_PERCENTAGE%<br />
343
+ - %POLL_LEAST_ANSWER%<br />
344
+ - %POLL_LEAST_VOTES%<br />
345
+ - %POLL_LEAST_PERCENTAGE%<br /><br />
346
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultfooter');" class="button" />
347
+ </td>
348
+ <td align="left"><textarea cols="80" rows="10" id="poll_template_resultfooter" name="poll_template_resultfooter"><?php echo stripslashes(get_settings('poll_template_resultfooter')); ?></textarea></td>
349
+ </tr>
350
+ </table>
351
+ </fieldset>
352
+ <fieldset class="options">
353
+ <legend><?php _e('Poll Misc Templates'); ?></legend>
354
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
355
+ <tr valign="top">
356
+ <td width="30%" align="left">
357
+ <b><?php _e('Poll Disabled'); ?></b><br /><br /><br />
358
+ <?php _e('Allowed Variables:'); ?><br />
359
+ - N/A<br /><br />
360
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('disable');" class="button" />
361
+ </td>
362
+ <td align="left"><textarea cols="80" rows="10" id="poll_template_disable" name="poll_template_disable"><?php echo stripslashes(get_settings('poll_template_disable')); ?></textarea></td>
363
+ </tr>
364
+ <tr valign="top">
365
+ <td width="30%" align="left">
366
+ <b><?php _e('Poll Error'); ?></b><br /><br /><br />
367
+ <?php _e('Allowed Variables:'); ?><br />
368
+ - N/A<br /><br />
369
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('error');" class="button" />
370
+ </td>
371
+ <td align="left"><textarea cols="80" rows="10" id="poll_template_error" name="poll_template_error"><?php echo stripslashes(get_settings('poll_template_error')); ?></textarea></td>
372
+ </tr>
373
+ </table>
374
+ </fieldset>
375
+ <div align="center">
376
+ <input type="submit" name="Submit" class="button" value="<?php _e('Update Options'); ?>" />&nbsp;&nbsp;<input type="button" name="cancel" Value="Cancel" class="button" onclick="javascript:history.go(-1)" />
377
+ </div>
378
+ </form>
379
+ </div>
polls/polls.php ADDED
@@ -0,0 +1,517 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-Polls
4
+ Plugin URI: http://www.lesterchan.net/portfolio/programming.php
5
+ Description: Adds A Poll Feature To WordPress
6
+ Version: 2.06
7
+ Author: GaMerZ
8
+ Author URI: http://www.lesterchan.net
9
+ */
10
+
11
+
12
+ /* Copyright 2005 Lester Chan (email : gamerz84@hotmail.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ */
28
+
29
+
30
+ ### Polls Table Name
31
+ $wpdb->pollsq = $table_prefix . 'pollsq';
32
+ $wpdb->pollsa = $table_prefix . 'pollsa';
33
+ $wpdb->pollsip = $table_prefix . 'pollsip';
34
+
35
+
36
+ ### Function: Poll Administration Menu
37
+ add_action('admin_menu', 'poll_menu');
38
+ function poll_menu() {
39
+ if (function_exists('add_menu_page')) {
40
+ add_menu_page(__('Polls'), __('Polls'), 'manage_polls', 'polls/polls-manager.php');
41
+ }
42
+ if (function_exists('add_submenu_page')) {
43
+ add_submenu_page('polls/polls-manager.php', __('Manage Polls'), __('Manage Polls'), 'manage_polls', 'polls/polls-manager.php');
44
+ add_submenu_page('polls/polls-manager.php', __('Poll Options'), __('Poll Options'), 'manage_polls', 'polls/polls-options.php');
45
+ }
46
+ }
47
+
48
+
49
+ ### Function: Get Poll
50
+ function get_poll($temp_poll_id = 0, $display = true) {
51
+ global $wpdb;
52
+ // Poll Result Link
53
+ $pollresult_id = intval($_GET['pollresult']);
54
+ // Check Whether Poll Is Disabled
55
+ if(intval(get_settings('poll_currentpoll')) == -1) {
56
+ if($display) {
57
+ echo stripslashes(get_settings('poll_template_disable'));
58
+ return;
59
+ } else {
60
+ return stripslashes(get_settings('poll_template_disable'));
61
+ }
62
+ // Poll Is Enabled
63
+ } else {
64
+ // Hardcoded Poll ID Is Not Specified
65
+ if(intval($temp_poll_id) == 0) {
66
+ // Random Poll
67
+ if(intval(get_settings('poll_currentpoll')) == -2) {
68
+ $random_poll_id = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq ORDER BY RAND() LIMIT 1");
69
+ $poll_id = intval($random_poll_id);
70
+ if($pollresult_id > 0) {
71
+ $poll_id = $pollresult_id;
72
+ } elseif(intval($_POST['poll_id']) > 0) {
73
+ $poll_id = intval($_POST['poll_id']);
74
+ }
75
+ // Current Poll ID Is Not Specified
76
+ } elseif(intval(get_settings('poll_currentpoll')) == 0) {
77
+ // Get Lastest Poll ID
78
+ $poll_id = intval(get_settings('poll_latestpoll'));
79
+ } else {
80
+ // Get Current Poll ID
81
+ $poll_id = intval(get_settings('poll_currentpoll'));
82
+ }
83
+ // Get Hardcoded Poll ID
84
+ } else {
85
+ $poll_id = intval($temp_poll_id);
86
+ }
87
+ }
88
+
89
+ // User Click on View Results Link
90
+ if($pollresult_id == $poll_id) {
91
+ if($display) {
92
+ echo display_pollresult($poll_id);
93
+ return;
94
+ } else {
95
+ return display_pollresult($poll_id);
96
+ }
97
+ // Check Whether User Has Voted
98
+ } else {
99
+ // Check Cookie First
100
+ $voted_cookie = check_voted_cookie($poll_id);
101
+ if($voted_cookie > 0) {
102
+ if($display) {
103
+ echo display_pollresult($poll_id, $voted_cookie);
104
+ return;
105
+ } else {
106
+ return display_pollresult($poll_id, $voted_cookie);
107
+ }
108
+ // Check IP If Cookie Cannot Be Found
109
+ } else {
110
+ $voted_ip = check_voted_ip($poll_id);
111
+ if($voted_ip > 0) {
112
+ if($display) {
113
+ echo display_pollresult($poll_id, $voted_ip);
114
+ return;
115
+ } else {
116
+ return display_pollresult($poll_id, $voted_ip);
117
+ }
118
+ // User Never Vote. Display Poll Voting Form
119
+ } else {
120
+ if($display) {
121
+ echo display_pollvote($poll_id);
122
+ return;
123
+ } else {
124
+ return display_pollvote($poll_id);
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
130
+
131
+
132
+ ### Function: Displays Polls CSS
133
+ add_action('wp_head', 'poll_css');
134
+ function poll_css() {
135
+ echo '<style type="text/css" media="screen">'."\n";
136
+ echo "\t".'.wp-polls ul li {'."\n";
137
+ echo "\t\t".'text-align: left;'."\n";
138
+ echo "\t\t".'list-style: none;'."\n";
139
+ echo "\t".'}'."\n";
140
+ echo "\t".'.wp-polls ul li:before, #sidebar ul ul ul li:before {'."\n";
141
+ echo "\t\t".'content: \'\';'."\n";
142
+ echo "\t".'}'."\n";
143
+ echo '</style>'."\n";
144
+ }
145
+
146
+
147
+ ### Function: Check Voted By Cookie
148
+ function check_voted_cookie($poll_id) {
149
+ // 0: False | > 0: True
150
+ return intval($_COOKIE["voted_$poll_id"]);
151
+ }
152
+
153
+
154
+ ### Function: Check Voted By IP
155
+ function check_voted_ip($poll_id) {
156
+ global $wpdb;
157
+ // Check IP From IP Logging Database
158
+ $get_voted_aid = $wpdb->get_var("SELECT pollip_aid FROM $wpdb->pollsip WHERE pollip_qid = $poll_id AND pollip_ip = '".get_ipaddress()."'");
159
+ // 0: False | > 0: True
160
+ return intval($get_voted_aid);
161
+ }
162
+
163
+
164
+ ### Function: Display Voting Form
165
+ function display_pollvote($poll_id) {
166
+ global $wpdb;
167
+ // Temp Poll Result
168
+ $temp_pollvote = '';
169
+ // Get Poll Question Data
170
+ $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
171
+ // Poll Question Variables
172
+ $poll_question_text = stripslashes($poll_question->pollq_question);
173
+ $poll_question_id = intval($poll_question->pollq_id);
174
+ $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
175
+ $template_question = stripslashes(get_settings('poll_template_voteheader'));
176
+ $template_question = str_replace("%POLL_QUESTION%", $poll_question_text, $template_question);
177
+ $template_question = str_replace("%POLL_ID%", $poll_question_id, $template_question);
178
+ $template_question = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_question);
179
+ // Get Poll Answers Data
180
+ $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = $poll_question_id ORDER BY ".get_settings('poll_ans_sortby').' '.get_settings('poll_ans_sortorder'));
181
+ // If There Is Poll Question With Answers
182
+ if($poll_question && $poll_answers) {
183
+ // Display Poll Voting Form
184
+ $temp_pollvote .= "<div id=\"wp-polls-$poll_question_id\" class=\"wp-polls\">\n";
185
+ $temp_pollvote .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">'."\n";
186
+ $temp_pollvote .= "<input type=\"hidden\" name=\"poll_id\" value=\"$poll_question_id\" />\n";
187
+ // Print Out Voting Form Header Template
188
+ $temp_pollvote .= $template_question;
189
+ foreach($poll_answers as $poll_answer) {
190
+ // Poll Answer Variables
191
+ $poll_answer_id = intval($poll_answer->polla_aid);
192
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
193
+ $poll_answer_votes = intval($poll_answer->polla_votes);
194
+ $template_answer = stripslashes(get_settings('poll_template_votebody'));
195
+ $template_answer = str_replace("%POLL_ID%", $poll_question_id, $template_answer);
196
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
197
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
198
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format($poll_answer_votes), $template_answer);
199
+ // Print Out Voting Form Body Template
200
+ $temp_pollvote .= $template_answer;
201
+ }
202
+ // Determine Poll Result URL
203
+ $poll_result_url = $_SERVER['REQUEST_URI'];
204
+ $poll_result_url = preg_replace('/pollresult=(\d+)/i', 'pollresult='.$poll_question_id, $poll_result_url);
205
+ if(intval($_GET['pollresult']) == 0) {
206
+ if(strpos($poll_result_url, '?') !== false) {
207
+ $poll_result_url = "$poll_result_url&amp;pollresult=$poll_question_id";
208
+ } else {
209
+ $poll_result_url = "$poll_result_url?pollresult=$poll_question_id";
210
+ }
211
+ }
212
+ // Voting Form Footer Variables
213
+ $template_footer = stripslashes(get_settings('poll_template_votefooter'));
214
+ $template_footer = str_replace("%POLL_RESULT_URL%", $poll_result_url, $template_footer);
215
+ // Print Out Voting Form Footer Template
216
+ $temp_pollvote .= $template_footer;
217
+ $temp_pollvote .= "</form>\n";
218
+ $temp_pollvote .= "</div>\n";
219
+ } else {
220
+ $temp_pollvote .= stripslashes(get_settings('poll_template_disable'));
221
+ }
222
+ // Return Poll Vote Template
223
+ return $temp_pollvote;
224
+ }
225
+
226
+
227
+ ### Function: Display Results Form
228
+ function display_pollresult($poll_id, $user_voted = 0) {
229
+ global $wpdb;
230
+ // Temp Poll Result
231
+ $temp_pollresult = '';
232
+ // Most/Least Variables
233
+ $poll_most_answer = '';
234
+ $poll_most_votes = 0;
235
+ $poll_most_percentage = 0;
236
+ $poll_least_answer = '';
237
+ $poll_least_votes = 0;
238
+ $poll_least_percentage = 0;
239
+ // Get Poll Question Data
240
+ $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
241
+ // Poll Question Variables
242
+ $poll_question_text = stripslashes($poll_question->pollq_question);
243
+ $poll_question_id = intval($poll_question->pollq_id);
244
+ $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
245
+ $template_question = stripslashes(get_settings('poll_template_resultheader'));
246
+ $template_question = str_replace("%POLL_QUESTION%", $poll_question_text, $template_question);
247
+ $template_question = str_replace("%POLL_ID%", $poll_question_id, $template_question);
248
+ $template_question = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_question);
249
+ // Get Poll Answers Data
250
+ $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = $poll_question_id ORDER BY ".get_settings('poll_ans_result_sortby').' '.get_settings('poll_ans_result_sortorder'));
251
+ // If There Is Poll Question With Answers
252
+ if($poll_question && $poll_answers) {
253
+ // Is The Poll Total Votes 0?
254
+ $poll_totalvotes_zero = true;
255
+ if($poll_question_totalvotes > 0) {
256
+ $poll_totalvotes_zero = false;
257
+ }
258
+ // Print Out Result Header Template
259
+ $temp_pollresult .= "<div id=\"wp-polls-$poll_question_id\" class=\"wp-polls\">\n";
260
+ $temp_pollresult .= $template_question;
261
+ foreach($poll_answers as $poll_answer) {
262
+ // Poll Answer Variables
263
+ $poll_answer_id = intval($poll_answer->polla_aid);
264
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
265
+ $poll_answer_votes = intval($poll_answer->polla_votes);
266
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
267
+ $poll_answer_percentage = 0;
268
+ $poll_answer_imagewidth = 0;
269
+ // Calculate Percentage And Image Bar Width
270
+ if(!$poll_totalvotes_zero) {
271
+ if($poll_answer_votes > 0) {
272
+ $poll_answer_percentage = round((($poll_answer_votes/$poll_question_totalvotes)*100));
273
+ $poll_answer_imagewidth = round($poll_answer_percentage);
274
+ } else {
275
+ $poll_answer_percentage = 0;
276
+ $poll_answer_imagewidth = 1;
277
+ }
278
+ } else {
279
+ $poll_answer_percentage = 0;
280
+ $poll_answer_imagewidth = 1;
281
+ }
282
+ // Let User See What Options They Voted
283
+ if($user_voted == $poll_answer_id) {
284
+ // Results Body Variables
285
+ $template_answer = stripslashes(get_settings('poll_template_resultbody2'));
286
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
287
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
288
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format($poll_answer_votes), $template_answer);
289
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
290
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
291
+ // Print Out Results Body Template
292
+ $temp_pollresult .= $template_answer;
293
+ } else {
294
+ // Results Body Variables
295
+ $template_answer = stripslashes(get_settings('poll_template_resultbody'));
296
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
297
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
298
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", number_format($poll_answer_votes), $template_answer);
299
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
300
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
301
+ // Print Out Results Body Template
302
+ $temp_pollresult .= $template_answer;
303
+ }
304
+ // Get Most Voted Data
305
+ if($poll_answer_votes > $poll_most_votes) {
306
+ $poll_most_answer = $poll_answer_text;
307
+ $poll_most_votes = $poll_answer_votes;
308
+ $poll_most_percentage = $poll_answer_percentage;
309
+ }
310
+ // Get Least Voted Data
311
+ if($poll_least_votes == 0) {
312
+ $poll_least_votes = $poll_answer_votes;
313
+ }
314
+ if($poll_answer_votes <= $poll_least_votes) {
315
+ $poll_least_answer = $poll_answer_text;
316
+ $poll_least_votes = $poll_answer_votes;
317
+ $poll_least_percentage = $poll_answer_percentage;
318
+ }
319
+ }
320
+ // Results Footer Variables
321
+ $template_footer = stripslashes(get_settings('poll_template_resultfooter'));
322
+ $template_footer = str_replace("%POLL_TOTALVOTES%", number_format($poll_question_totalvotes), $template_footer);
323
+ $template_footer = str_replace("%POLL_MOST_ANSWER%", $poll_most_answer, $template_footer);
324
+ $template_footer = str_replace("%POLL_MOST_VOTES%", number_format($poll_most_votes), $template_footer);
325
+ $template_footer = str_replace("%POLL_MOST_PERCENTAGE%", $poll_most_percentage, $template_footer);
326
+ $template_footer = str_replace("%POLL_LEAST_ANSWER%", $poll_least_answer, $template_footer);
327
+ $template_footer = str_replace("%POLL_LEAST_VOTES%", number_format($poll_least_votes), $template_footer);
328
+ $template_footer = str_replace("%POLL_LEAST_PERCENTAGE%", $poll_least_percentage, $template_footer);
329
+ // Print Out Results Footer Template
330
+ $temp_pollresult .= $template_footer;
331
+ $temp_pollresult .= "</div>\n";
332
+ } else {
333
+ $temp_pollresult .= stripslashes(get_settings('poll_template_disable'));
334
+ }
335
+ // Return Poll Result
336
+ return $temp_pollresult;
337
+ }
338
+
339
+
340
+ ### Function: Vote Poll
341
+ add_action('init', 'vote_poll');
342
+ function vote_poll() {
343
+ global $wpdb, $user_identity;
344
+ if(!empty($_POST['vote'])) {
345
+ $poll_id = intval($_POST['poll_id']);
346
+ $poll_aid = intval($_POST["poll-$poll_id"]);
347
+ if($poll_id > 0 && $poll_aid > 0) {
348
+ $voted_ip = check_voted_ip($poll_id);
349
+ $voted_cookie = check_voted_cookie($poll_id);
350
+ if($voted_ip == 0 && $voted_cookie == 0) {
351
+ if(!empty($user_identity)) {
352
+ $pollip_user = addslashes($user_identity);
353
+ } elseif(!empty($_COOKIE['comment_author_'.COOKIEHASH])) {
354
+ $pollip_user = addslashes($_COOKIE['comment_author_'.COOKIEHASH]);
355
+ } else {
356
+ $pollip_user = 'Guest';
357
+ }
358
+ $vote_cookie = setcookie("voted_".$poll_id, $poll_aid, time() + 30000000, COOKIEPATH);
359
+ if($vote_cookie) {
360
+ $pollip_ip = get_ipaddress();
361
+ $pollip_host = gethostbyaddr($pollip_ip);
362
+ $pollip_timestamp = current_time('timestamp');
363
+ $vote_ip = $wpdb->query("INSERT INTO $wpdb->pollsip VALUES(0,$poll_id,$poll_aid,'$pollip_ip','$pollip_host','$pollip_timestamp','$pollip_user')");
364
+ if($vote_ip) {
365
+ $vote_a = $wpdb->query("UPDATE $wpdb->pollsa SET polla_votes = (polla_votes+1) WHERE polla_qid = $poll_id AND polla_aid = $poll_aid");
366
+ if($vote_a) {
367
+ $vote_q = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes+1) WHERE pollq_id = $poll_id");
368
+ } // End if($vote_a)
369
+ } // End if($vote_ip)
370
+ } // End if($vote_cookie)
371
+ }// End if($voted_ip == 0 && $voted_cookie == 0)
372
+ } // End if(!empty($_POST['vote']))
373
+ } // End if($poll_id > 0 && $poll_aid > 0)
374
+ }
375
+
376
+
377
+ ### Function: Get IP Address
378
+ if(!function_exists('get_ipaddress')) {
379
+ function get_ipaddress() {
380
+ if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
381
+ $ip_address = $_SERVER["REMOTE_ADDR"];
382
+ } else {
383
+ $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
384
+ }
385
+ if(strpos($ip_address, ',') !== false) {
386
+ $ip_address = explode(',', $ip_address);
387
+ $ip_address = $ip_address[0];
388
+ }
389
+ return $ip_address;
390
+ }
391
+ }
392
+
393
+
394
+ ### Function: Place Poll In Content (By: Robert Accettura Of http://robert.accettura.com/)
395
+ add_filter('the_content', 'place_poll', '12');
396
+ function place_poll($content){
397
+ $content = preg_replace( "/\[poll=(\d+)\]/ise", "display_poll('\\1')", $content);
398
+ return $content;
399
+ }
400
+
401
+
402
+ ### Function: Display The Poll In Content (By: Robert Accettura Of http://robert.accettura.com/)
403
+ function display_poll($poll_id, $display_pollarchive = false){
404
+ if (function_exists('vote_poll')){
405
+ if($display_pollarchive) {
406
+ return get_poll($poll_id, false)."\n".'<p><a href="'.get_settings('home').'/wp-polls.php">Polls Archive</a></p>';
407
+ } else {
408
+ return get_poll($poll_id, false);
409
+ }
410
+ }
411
+ }
412
+
413
+
414
+ ### Function: Get Poll Total Questions
415
+ if(!function_exists('get_pollquestions')) {
416
+ function get_pollquestions() {
417
+ global $wpdb;
418
+ $totalpollq = $wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq");
419
+ echo $totalpollq;
420
+ }
421
+ }
422
+
423
+
424
+ ### Function: Get Poll Total Answers
425
+ if(!function_exists('get_pollanswers')) {
426
+ function get_pollanswers() {
427
+ global $wpdb;
428
+ $totalpolla = $wpdb->get_var("SELECT COUNT(polla_aid) FROM $wpdb->pollsa");
429
+ echo $totalpolla;
430
+ }
431
+ }
432
+
433
+
434
+ ### Function: Get Poll Total Votes
435
+ if(!function_exists('get_pollvotes')) {
436
+ function get_pollvotes() {
437
+ global $wpdb;
438
+ $totalpollip = $wpdb->get_var("SELECT COUNT(pollip_id) FROM $wpdb->pollsip");
439
+ echo $totalpollip;
440
+ }
441
+ }
442
+
443
+
444
+ ### Function: Create Poll Tables
445
+ add_action('activate_polls/polls.php', 'create_poll_table');
446
+ function create_poll_table() {
447
+ global $wpdb;
448
+ include_once(ABSPATH.'/wp-admin/upgrade-functions.php');
449
+ // Create Poll Tables (3 Tables)
450
+ $create_table = array();
451
+ $create_table['pollsq'] = "CREATE TABLE $wpdb->pollsq (".
452
+ "pollq_id int(10) NOT NULL auto_increment,".
453
+ "pollq_question varchar(200) NOT NULL default '',".
454
+ "pollq_timestamp varchar(20) NOT NULL default '',".
455
+ "pollq_totalvotes int(10) NOT NULL default '0',".
456
+ "PRIMARY KEY (pollq_id))";
457
+ $create_table['pollsa'] = "CREATE TABLE $wpdb->pollsa (".
458
+ "polla_aid int(10) NOT NULL auto_increment,".
459
+ "polla_qid int(10) NOT NULL default '0',".
460
+ "polla_answers varchar(200) NOT NULL default '',".
461
+ "polla_votes int(10) NOT NULL default '0',".
462
+ "PRIMARY KEY (polla_aid))";
463
+ $create_table['pollsip'] = "CREATE TABLE $wpdb->pollsip (".
464
+ "pollip_id int(10) NOT NULL auto_increment,".
465
+ "pollip_qid varchar(10) NOT NULL default '',".
466
+ "pollip_aid varchar(10) NOT NULL default '',".
467
+ "pollip_ip varchar(100) NOT NULL default '',".
468
+ "pollip_host VARCHAR(200) NOT NULL default '',".
469
+ "pollip_timestamp varchar(20) NOT NULL default '0000-00-00 00:00:00',".
470
+ "pollip_user tinytext NOT NULL,".
471
+ "PRIMARY KEY (pollip_id))";
472
+ maybe_create_table($wpdb->pollsq, $create_table['pollsq']);
473
+ maybe_create_table($wpdb->pollsa, $create_table['pollsa']);
474
+ maybe_create_table($wpdb->pollsip, $create_table['pollsip']);
475
+ // Check Whether It is Install Or Upgrade
476
+ $first_poll = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq LIMIT 1");
477
+ // If Install, Insert 1st Poll Question With 5 Poll Answers
478
+ if(empty($first_poll)) {
479
+ // Insert Poll Question (1 Record)
480
+ $insert_pollq = $wpdb->query("INSERT INTO $wpdb->pollsq VALUES (1, 'How Is My Site?', '".current_time('timestamp')."', 0);");
481
+ if($insert_pollq) {
482
+ // Insert Poll Answers (5 Records)
483
+ $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (1, 1, 'Good', 0);");
484
+ $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (2, 1, 'Excellent', 0);");
485
+ $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (3, 1, 'Bad', 0);");
486
+ $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (4, 1, 'Can Be Improved', 0);");
487
+ $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (5, 1, 'No Comments', 0);");
488
+ }
489
+ }
490
+ // Add In Options (16 Records)
491
+ add_option('poll_template_voteheader', '<p align="center"><b>%POLL_QUESTION%</b></p>'.
492
+ '<ul>', 'Template For Poll\'s Question');
493
+ add_option('poll_template_votebody', '<li><label for="poll-answer-%POLL_ANSWER_ID%"><input type="radio" id="poll-answer-%POLL_ANSWER_ID%" name="poll-%POLL_ID%" value="%POLL_ANSWER_ID%" /> %POLL_ANSWER%</label></li>', 'Template For Poll\'s Answers');
494
+ add_option('poll_template_votefooter', '</ul>'.
495
+ '<p align="center"><input type="submit" name="vote" value=" Vote " class="Buttons" /><br /><a href="%POLL_RESULT_URL%">View Results</a></p>', 'Template For Poll\'s Voting Footer');
496
+ add_option('poll_template_resultheader', '<p align="center"><b>%POLL_QUESTION%</b></p>'.
497
+ '<ul>', 'Template For Poll Header');
498
+ add_option('poll_template_resultbody', '<li>%POLL_ANSWER% <small>(%POLL_ANSWER_PERCENTAGE%%)</small><br /><img src="'.get_settings('siteurl').'/wp-content/plugins/polls/images/pollstart.gif" height="10" width="2" /><img src="'.get_settings('siteurl').'/wp-content/plugins/polls/images/pollbar.gif" height="10" width="%POLL_ANSWER_IMAGEWIDTH%" alt="%POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)" title="%POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)" /><img src="'.get_settings('siteurl').'/wp-content/plugins/polls/images/pollend.gif" height="10" width="2" /></li>', 'Template For Poll Results');
499
+ add_option('poll_template_resultbody2', '<li><b><i>%POLL_ANSWER% <small>(%POLL_ANSWER_PERCENTAGE%%)</small></i></b><br /><img src="'.get_settings('siteurl').'/wp-content/plugins/polls/images/pollstart.gif" height="10" width="2" /><img src="'.get_settings('siteurl').'/wp-content/plugins/polls/images/pollbar.gif" height="10" width="%POLL_ANSWER_IMAGEWIDTH%" alt="You Have Voted For This Choice - %POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)" title="You Have Voted For This Choice - %POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)" /><img src="'.get_settings('siteurl').'/wp-content/plugins/polls/images/pollend.gif" height="10" width="2" /></li>', 'Template For Poll Results (User Voted)');
500
+ add_option('poll_template_resultfooter', '</ul>'.
501
+ '<p align="center">Total Votes: <b>%POLL_TOTALVOTES%</b></p>', 'Template For Poll Result Footer');
502
+ add_option('poll_template_disable', 'Sorry, there are no polls available at the moment.', 'Template For Poll When It Is Disabled');
503
+ add_option('poll_template_error', 'An error has occurred when processing your poll.', 'Template For Poll When An Error Has Occured');
504
+ add_option('poll_currentpoll', 0, 'Current Displayed Poll');
505
+ add_option('poll_latestpoll', 1, 'The Lastest Poll');
506
+ add_option('poll_archive_perpage', 5, 'Number Of Polls To Display Per Page On The Poll\'s Archive', 'no');
507
+ add_option('poll_ans_sortby', 'polla_aid', 'Sorting Of Poll\'s Answers');
508
+ add_option('poll_ans_sortorder', 'asc', 'Sort Order Of Poll\'s Answers');
509
+ add_option('poll_ans_result_sortby', 'polla_votes', 'Sorting Of Poll\'s Answers Result');
510
+ add_option('poll_ans_result_sortorder', 'desc', 'Sorting Order Of Poll\'s Answers Result');
511
+ // Set 'manage_polls' Capabilities To Administrator
512
+ $role = get_role('administrator');
513
+ if(!$role->has_cap('manage_polls')) {
514
+ $role->add_cap('manage_polls');
515
+ }
516
+ }
517
+ ?>
readme-install.txt ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Installation Instructions
2
+ ------------------------------------------------------------------
3
+ // Open wp-content/plugins folder
4
+
5
+ Put:
6
+ ------------------------------------------------------------------
7
+ Folder: polls
8
+ ------------------------------------------------------------------
9
+
10
+ // Open Wordpress root folder
11
+
12
+ Put:
13
+ ------------------------------------------------------------------
14
+ wp-polls.php
15
+ ------------------------------------------------------------------
16
+
17
+
18
+ // Activate WP-Polls plugin
19
+
20
+
21
+ // Tutorial On How To Integrate wp-polls.php With Your Theme
22
+
23
+ Go To:
24
+ ------------------------------------------------------------------
25
+ http://www.lesterchan.net/wordpress/tutorials/integrating/
26
+ ------------------------------------------------------------------
27
+
28
+
29
+
30
+
31
+
32
+ -> Usage Instructions
33
+ ------------------------------------------------------------------
34
+ // Open wp-content/themes/<YOUR THEME NAME>/sidebar.php
35
+
36
+ Add:
37
+ ------------------------------------------------------------------
38
+ <?php if (function_exists('vote_poll')): ?>
39
+ <li>
40
+ <h2>Polls</h2>
41
+ <ul>
42
+ <?php get_poll();?>
43
+ <li><a href="<?php echo get_settings('home'); ?>/wp-polls.php">Polls Archive</a></li>
44
+ </ul>
45
+ </li>
46
+ <?php endif; ?>
47
+ ------------------------------------------------------------------
48
+ Note:
49
+ ------------------------------------------------------------------
50
+ To show specific poll, use <?php get_poll(<ID>);?> where <ID> is your poll id.
51
+ To embed a specific poll in your post, use [poll=<ID>] where <ID> is your poll id.
52
+ ------------------------------------------------------------------
53
+
54
+
55
+ // Polls Stats (You can place it anywhere outside the WP Loop)
56
+
57
+ // To Display Total Polls
58
+
59
+ Use:
60
+ ------------------------------------------------------------------
61
+ <?php if (function_exists('get_pollquestions')): ?>
62
+ <?php get_pollquestions(); ?>
63
+ <?php endif; ?>
64
+ ------------------------------------------------------------------
65
+
66
+
67
+ // To Display Total Poll Answers
68
+
69
+ Use:
70
+ ------------------------------------------------------------------
71
+ <?php if (function_exists('get_pollanswers')): ?>
72
+ <?php get_pollanswers(); ?>
73
+ <?php endif; ?>
74
+ ------------------------------------------------------------------
75
+
76
+
77
+ // To Display Total Poll Votes
78
+
79
+ Use:
80
+ ------------------------------------------------------------------
81
+ <?php if (function_exists('get_pollvotes')): ?>
82
+ <?php get_pollvotes(); ?>
83
+ <?php endif; ?>
84
+ ------------------------------------------------------------------
readme-upgrade.txt ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Upgrade Instructions For Version 2.05 To Version 2.06
2
+ ------------------------------------------------------------------
3
+ // Open wp-content/plugins folder
4
+
5
+ Overwrite:
6
+ ------------------------------------------------------------------
7
+ Folder: polls
8
+ ------------------------------------------------------------------
9
+
10
+
11
+ // Open Wordpress root folder
12
+
13
+ Overwrite:
14
+ ------------------------------------------------------------------
15
+ wp-polls.php
16
+ ------------------------------------------------------------------
17
+
18
+
19
+ // Go to 'WP-Admin -> Polls -> Polls Options' and restore all the template variables to Default
20
+
21
+
22
+
23
+
24
+
25
+ -> Upgrade Instructions For Version 1.0x To Version 2.06
26
+ ------------------------------------------------------------------
27
+ // Deactivate WP-Polls plugin
28
+
29
+
30
+ // Delete these file if exists
31
+
32
+ Delete:
33
+ ------------------------------------------------------------------
34
+ wp-content/plugins/polls.php
35
+ wp-admin/polls-options.php
36
+ wp-admin/polls-manager.php
37
+ wp-includes/images/pollbar.gif
38
+ ------------------------------------------------------------------
39
+
40
+
41
+ // Open wp-content/plugins folder
42
+
43
+ Put:
44
+ ------------------------------------------------------------------
45
+ Folder: polls
46
+ ------------------------------------------------------------------
47
+
48
+
49
+ // Open Wordpress root folder
50
+
51
+ Overwrite:
52
+ ------------------------------------------------------------------
53
+ wp-polls.php
54
+ ------------------------------------------------------------------
55
+
56
+
57
+ // Activate WP-Polls plugin
58
+
59
+
60
+ // Go to 'WP-Admin -> EMail -> EMail Options' and restore all the template variables to Default
61
+
62
+
63
+ // Refer to readme-install.txt for further usage instructions
readme.txt ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Polls Plugin For WordPress 2.0
2
+ --------------------------------------------------
3
+ Author -> Lester 'GaMerZ' Chan
4
+ Email -> gamerz84@hotmail.com
5
+ Website -> http://www.lesterchan.net/
6
+ Demo -> http://www.lesterchan.net/blogs
7
+ Documentation -> http://dev.wp-plugins.org/wiki/wp-polls
8
+ Development -> http://dev.wp-plugins.org/browser/wp-polls/
9
+ Updated -> 1st April 2006
10
+ --------------------------------------------------
11
+ Note: I have changed almost the whole structure of WP-Polls, So if there is any bug,
12
+ please contact me immediately.
13
+ --------------------------------------------------
14
+
15
+
16
+ // Version 2.06b (26-04-2006)
17
+ - FIXED: Bug In vote_poll();
18
+
19
+ // Version 2.06a (02-04-2006)
20
+ - FIXED: Random Poll Not Working Correctly
21
+
22
+ // Version 2.06 (01-04-2006)
23
+ - NEW: Poll Bar Is Slightly Nicer
24
+ - NEW: Got Rid Of Tables, Now Using List <li>
25
+ - NEW: Added In Most Voted And Least Voted Answer/Votes/Percentage For Individual Poll As Template Variables
26
+ - NEW: Display Random Poll Option Under Poll -> Poll Options -> Current Poll
27
+ - FIXED: Totally Removed Tables In wp-polls.php
28
+
29
+ // Version 2.05 (01-03-2006)
30
+ - NEW: Improved On 'manage_polls' Capabilities
31
+ - NEW: Neater Structure
32
+ - NEW: No More Install/Upgrade File, It Will Install/Upgrade When You Activate The Plugin
33
+ - NEW: Added Poll Stats Function
34
+
35
+ // Version 2.04 (01-02-2006)
36
+ - NEW: Added 'manage_polls' Capabilities To Administrator Role
37
+ - NEW: [poll=POLL_ID] Tag To Insert Poll Into A Post
38
+ - NEW: Ability To Edit Poll's Timestamp
39
+ - NEW: Ability To Edit Individual Poll's Answer Votes
40
+ - NEW: %POLL_RESULT_URL% To Display Poll's Result URL
41
+ - FIXED: Cannot Sent Header Error
42
+
43
+ // Version 2.03 (01-01-2006)
44
+ - NEW: Compatible With WordPress 2.0 Only
45
+ - NEW: Poll Administration Menu Added Automatically Upon Activating The Plugin
46
+ - NEW: Removed Add Poll Link From The Administration Menu
47
+ - NEW: GPL License Added
48
+ - NEW: Page Title Added To wp-polls.php
49
+
50
+ // Version 2.02a (17-11-2005)
51
+ - FIXED: poll-install.php And poll-upgrade.php will Now Be Installed/Upgraded To 2.02 Instead Of 2.01
52
+
53
+ // Version 2.02 (05-11-2005)
54
+ - FIXED: Showing 0 Vote On Poll Edit Page
55
+ - FIXED: Null Vote Being Counted As A Vote
56
+ - FIXED: Auto Loading Of Poll Option: Polls Per Page In Poll Archive Page Is Now "No"
57
+ - NEW: Host Column In Poll IP Table To Prevent Network Lagging When Resolving IP
58
+ - NEW: New Poll Error Template
59
+
60
+ // Version 2.01 (25-10-2005)
61
+ - FIXED: Upgrade Script To Insert Lastest Poll ID Of User's Current Polls, Instead Of Poll ID 1
62
+ - FIXED: Replace All <?= With <?php
63
+ - FIXED: Added addalshes() To $pollip_user
64
+ - FIXED: Better Localization Support (80% Done, Will Leave It In The Mean Time)
65
+
66
+ // Version 2.0 (20-10-2005)
67
+ - NEW: IP Logging
68
+ - NEW: Poll Options: Sorting Of Answers In Voting Form
69
+ - NEW: Poll Options: Sorting Of Answers In Results View
70
+ - NEW: Poll Options: Number Of Polls Per Page In Poll Archive
71
+ - NEW: Poll Options: Choose Poll To Display On Index Page
72
+ - NEW: Poll Options: Able To Disable Poll With Custom Message
73
+ - NEW: Poll Options: Poll Templates
74
+ - NEW: Display User's Voted Choice
75
+ - FIXED: Better Install/Upgrade Script
wp-polls.php ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.06 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Poll Archive |
14
+ | - wp-polls.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Wordpress Header
21
+ require(dirname(__FILE__).'/wp-blog-header.php');
22
+
23
+ ### Function: Poll Page Title
24
+ add_filter('wp_title', 'poll_pagetitle');
25
+ function poll_pagetitle($poll_pagetitle) {
26
+ return $poll_pagetitle.' &raquo; Polls';
27
+ }
28
+
29
+ ### Polls Variables
30
+ $page = intval($_GET['page']);
31
+ $polls_questions = array();
32
+ $polls_answers = array();
33
+ $polls_ip = array();
34
+ $polls_perpage = intval(get_settings('poll_archive_perpage'));
35
+ $poll_questions_ids = '0';
36
+ $poll_voted = false;
37
+ $poll_voted_aid = 0;
38
+ $poll_id = 0;
39
+
40
+ ### Get Total Polls
41
+ $total_polls = $wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq");
42
+
43
+ ### Checking $page and $offset
44
+ if (empty($page) || $page == 0) { $page = 1; }
45
+ if (empty($offset)) { $offset = 0; }
46
+
47
+ ### Determin $offset
48
+ $offset = ($page-1) * $polls_perpage;
49
+
50
+ ### Determine Max Number Of Polls To Display On Page
51
+ if(($offset + $polls_perpage) > $total_polls) {
52
+ $max_on_page = $total_polls;
53
+ } else {
54
+ $max_on_page = ($offset + $polls_perpage);
55
+ }
56
+
57
+ ### Determine Number Of Polls To Display On Page
58
+ if (($offset + 1) > ($total_polls)) {
59
+ $display_on_page = $total_polls;
60
+ } else {
61
+ $display_on_page = ($offset + 1);
62
+ }
63
+
64
+ ### Determing Total Amount Of Pages
65
+ $total_pages = ceil($total_polls / $polls_perpage);
66
+
67
+ ### Make Sure Poll Is Not Disabled
68
+ if(intval(get_settings('poll_currentpoll')) != -1 && $page < 2) {
69
+ // Hardcoded Poll ID Is Not Specified
70
+ if(intval($temp_poll_id) == 0) {
71
+ // Random Poll
72
+ if(intval(get_settings('poll_currentpoll')) == -2) {
73
+ $random_poll_id = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq ORDER BY RAND() LIMIT 1");
74
+ $poll_id = intval($random_poll_id);
75
+ // Current Poll ID Is Not Specified
76
+ } else if(intval(get_settings('poll_currentpoll')) == 0) {
77
+ // Get Lastest Poll ID
78
+ $poll_id = intval(get_settings('poll_latestpoll'));
79
+ } else {
80
+ // Get Current Poll ID
81
+ $poll_id = intval(get_settings('poll_currentpoll'));
82
+ }
83
+ // Get Hardcoded Poll ID
84
+ } else {
85
+ $poll_id = intval($temp_poll_id);
86
+ }
87
+ }
88
+
89
+ ### Get Poll Questions
90
+ $questions = $wpdb->get_results("SELECT * FROM $wpdb->pollsq WHERE pollq_id != $poll_id ORDER BY pollq_id DESC LIMIT $offset, $polls_perpage");
91
+ if($questions) {
92
+ foreach($questions as $question) {
93
+ $polls_questions[] = array('id' => intval($question->pollq_id), 'question' => stripslashes($question->pollq_question), 'timestamp' => $question->pollq_timestamp, 'totalvotes' => intval($question->pollq_totalvotes));
94
+ $poll_questions_ids .= intval($question->pollq_id).', ';
95
+ }
96
+ $poll_questions_ids = substr($poll_questions_ids, 0, -2);
97
+ }
98
+
99
+ ### Get Poll Answers
100
+ $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_settings('poll_ans_result_sortby').' '.get_settings('poll_ans_result_sortorder'));
101
+ if($answers) {
102
+ foreach($answers as $answer) {
103
+ $polls_answers[] = array('aid' => intval($answer->polla_aid), 'qid' => intval($answer->polla_qid), 'answers' => stripslashes($answer->polla_answers), 'votes' => intval($answer->polla_votes));
104
+ }
105
+ }
106
+
107
+ ### Get Poll IPs
108
+ $ips = $wpdb->get_results("SELECT pollip_qid, pollip_aid FROM $wpdb->pollsip WHERE pollip_qid IN ($poll_questions_ids) AND pollip_ip = '".get_ipaddress()."'");
109
+ if($ips) {
110
+ foreach($ips as $ip) {
111
+ $polls_ips[] = array('qid' => intval($ip->pollip_qid), 'aid' => intval($ip->pollip_aid));
112
+ }
113
+ }
114
+ ### Function: Check Voted To Get Voted Answer
115
+ function check_voted($poll_id) {
116
+ global $polls_ips;
117
+ $temp_voted_aid = 0;
118
+ if(intval($_COOKIE["voted_$poll_id"]) > 0) {
119
+ $temp_voted_aid = intval($_COOKIE["voted_$poll_id"]);
120
+ } else {
121
+ if($polls_ips) {
122
+ foreach($polls_ips as $polls_ip) {
123
+ if($polls_ip['qid'] == $poll_id) {
124
+ $temp_voted_aid = $polls_ip['aid'];
125
+ }
126
+ }
127
+ }
128
+ }
129
+ return $temp_voted_aid;
130
+ }
131
+ ?>
132
+ <?php get_header(); ?>
133
+ <div id="content" class="narrowcolumn">
134
+ <?php
135
+ if($page < 2) {
136
+ echo "<!-- <Currrent Poll> -->\n";
137
+ echo '<h2 class="pagetitle">'.__('Current Poll').'</h2>'."\n";
138
+ // Current Poll
139
+ if(intval(get_settings('poll_currentpoll')) == -1) {
140
+ echo get_settings('poll_template_disable');
141
+ } else {
142
+ // User Click on View Results Link
143
+ if(intval($_GET['pollresult']) == $poll_id) {
144
+ echo display_pollresult($poll_id);
145
+ // Check Whether User Has Voted
146
+ } else {
147
+ // Check Cookie First
148
+ $voted_cookie = check_voted_cookie($poll_id);
149
+ if($voted_cookie > 0) {
150
+ echo display_pollresult($poll_id, $voted_cookie);
151
+ // Check IP If Cookie Cannot Be Found
152
+ } else {
153
+ $voted_ip = check_voted_ip($poll_id);
154
+ if($voted_ip > 0) {
155
+ echo display_pollresult($poll_id, $voted_ip);
156
+ // User Never Vote. Display Poll Voting Form
157
+ } else {
158
+ echo display_pollvote($poll_id);
159
+ }
160
+ }
161
+ }
162
+ }
163
+ echo "<!-- </Currrent Poll> -->\n";
164
+ }
165
+ ?>
166
+ <!-- <Poll Archives> -->
167
+ <h2 class="pagetitle"><?php _e('Polls Archive'); ?></h2>
168
+ <?php
169
+ foreach($polls_questions as $polls_question) {
170
+ // Most/Least Variables
171
+ $poll_most_answer = '';
172
+ $poll_most_votes = 0;
173
+ $poll_most_percentage = 0;
174
+ $poll_least_answer = '';
175
+ $poll_least_votes = 0;
176
+ $poll_least_percentage = 0;
177
+ // Is The Poll Total Votes 0?
178
+ $poll_totalvotes_zero = true;
179
+ if($polls_question['totalvotes'] > 0) {
180
+ $poll_totalvotes_zero = false;
181
+ }
182
+ // Poll Question Variables
183
+ $template_question = stripslashes(get_settings('poll_template_resultheader'));
184
+ $template_question = str_replace("%POLL_QUESTION%", $polls_question['question'], $template_question);
185
+ $template_question = str_replace("%POLL_ID%", $polls_question['id'], $template_question);
186
+ $template_question = str_replace("%POLL_TOTALVOTES%", $polls_question['totalvotes'], $template_question);
187
+ // Print Out Result Header Template
188
+ echo $template_question;
189
+ foreach($polls_answers as $polls_answer) {
190
+ if($polls_question['id'] == $polls_answer['qid']) {
191
+ // Calculate Percentage And Image Bar Width
192
+ if(!$poll_totalvotes_zero) {
193
+ if($polls_answer['votes'] > 0) {
194
+ $poll_answer_percentage = round((($polls_answer['votes']/$polls_question['totalvotes'])*100));
195
+ $poll_answer_imagewidth = round($poll_answer_percentage*0.9);
196
+ } else {
197
+ $poll_answer_percentage = 0;
198
+ $poll_answer_imagewidth = 1;
199
+ }
200
+ } else {
201
+ $poll_answer_percentage = 0;
202
+ $poll_answer_imagewidth = 1;
203
+ }
204
+ // Let User See What Options They Voted
205
+ if(check_voted($polls_question['id']) == $polls_answer['aid']) {
206
+ // Results Body Variables
207
+ $template_answer = stripslashes(get_settings('poll_template_resultbody2'));
208
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $polls_answer['aid'], $template_answer);
209
+ $template_answer = str_replace("%POLL_ANSWER%", $polls_answer['answers'], $template_answer);
210
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $polls_answer['votes'], $template_answer);
211
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
212
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
213
+ // Print Out Results Body Template
214
+ echo $template_answer;
215
+ } else {
216
+ // Results Body Variables
217
+ $template_answer = stripslashes(get_settings('poll_template_resultbody'));
218
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $polls_answer['aid'], $template_answer);
219
+ $template_answer = str_replace("%POLL_ANSWER%", $polls_answer['answers'], $template_answer);
220
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $polls_answer['votes'], $template_answer);
221
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
222
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
223
+ // Print Out Results Body Template
224
+ echo $template_answer;
225
+ }
226
+ // Get Most Voted Data
227
+ if($polls_answer['votes'] > $poll_most_votes) {
228
+ $poll_most_answer = $polls_answer['answers'];
229
+ $poll_most_votes = $polls_answer['votes'];
230
+ $poll_most_percentage = $poll_answer_percentage;
231
+ }
232
+ // Get Least Voted Data
233
+ if($poll_least_votes == 0) {
234
+ $poll_least_votes = $polls_answer['votes'];
235
+ }
236
+ if($polls_answer['votes'] <= $poll_least_votes) {
237
+ $poll_least_answer = $polls_answer['answers'];
238
+ $poll_least_votes = $polls_answer['votes'];
239
+ $poll_least_percentage = $poll_answer_percentage;
240
+ }
241
+ // Delete Away From Array
242
+ unset($polls_answer['answers']);
243
+ }
244
+ }
245
+ // Results Footer Variables
246
+ $template_footer = stripslashes(get_settings('poll_template_resultfooter'));
247
+ $template_footer = str_replace("%POLL_TOTALVOTES%", $polls_question['totalvotes'], $template_footer);
248
+ $template_footer = str_replace("%POLL_MOST_ANSWER%", $poll_most_answer, $template_footer);
249
+ $template_footer = str_replace("%POLL_MOST_VOTES%", number_format($poll_most_votes), $template_footer);
250
+ $template_footer = str_replace("%POLL_MOST_PERCENTAGE%", $poll_most_percentage, $template_footer);
251
+ $template_footer = str_replace("%POLL_LEAST_ANSWER%", $poll_least_answer, $template_footer);
252
+ $template_footer = str_replace("%POLL_LEAST_VOTES%", number_format($poll_least_votes), $template_footer);
253
+ $template_footer = str_replace("%POLL_LEAST_PERCENTAGE%", $poll_least_percentage, $template_footer);
254
+ // Print Out Results Footer Template
255
+ echo $template_footer;
256
+ echo "<br />\n";
257
+ }
258
+ ?>
259
+ <!-- </Poll Archives> -->
260
+
261
+ <!-- <Paging> -->
262
+ <?php
263
+ if($total_pages > 1) {
264
+ ?>
265
+ <br />
266
+ <p>
267
+ <span style="float: left;">
268
+ <?php
269
+ if($page > 1 && ((($page*$polls_perpage)-($polls_perpage-1)) <= $total_polls)) {
270
+ echo '<b>&laquo;</b> <a href="wp-polls.php?page='.($page-1).'" title="&laquo; '.__('Previous Page').'">'.__('Previous Page').'</a>';
271
+ } else {
272
+ echo '&nbsp;';
273
+ }
274
+ ?>
275
+ </span>
276
+ <span style="float: right;">
277
+ <?php
278
+ if($page >= 1 && ((($page*$polls_perpage)+1) <= $total_polls)) {
279
+ echo '<a href="wp-polls.php?page='.($page+1).'" title="'.__('Next Page').' &raquo;">'.__('Next Page').'</a> <b>&raquo;</b>';
280
+ } else {
281
+ echo '&nbsp;';
282
+ }
283
+ ?>
284
+ </span>
285
+ </p>
286
+ <br style="clear: both;" />
287
+ <p>
288
+ <?php _e('Pages'); ?> (<?php echo $total_pages; ?>) :
289
+ <?php
290
+ if ($page >= 4) {
291
+ echo '<b><a href="wp-polls.php?page=1" title="'.__('Go to First Page').'">&laquo; '.__('First').'</a></b> ... ';
292
+ }
293
+ if($page > 1) {
294
+ echo ' <b><a href="wp-polls.php?page='.($page-1).'" title="&laquo; '.__('Go to Page').' '.($page-1).'">&laquo;</a></b> ';
295
+ }
296
+ for($i = $page - 2 ; $i <= $page +2; $i++) {
297
+ if ($i >= 1 && $i <= $total_pages) {
298
+ if($i == $page) {
299
+ echo "<b>[$i]</b> ";
300
+ } else {
301
+ echo '<a href="wp-polls.php?page='.($i).'" title="'.__('Page').' '.$i.'">'.$i.'</a> ';
302
+ }
303
+ }
304
+ }
305
+ if($page < $total_pages) {
306
+ echo ' <b><a href="wp-polls.php?page='.($page+1).'" title="'.__('Go to Page').' '.($page+1).' &raquo;">&raquo;</a></b> ';
307
+ }
308
+ if (($page+2) < $total_pages) {
309
+ echo ' ... <b><a href="wp-polls.php?page='.($total_pages).'" title="'.__('Go to Last Page').'">'.__('Last').' &raquo;</a></b>';
310
+ }
311
+ ?>
312
+ </p>
313
+ <!-- </Paging> -->
314
+ <?php
315
+ }
316
+ ?>
317
+ </div>
318
+ <?php get_sidebar(); ?>
319
+ <?php get_footer(); ?>