WP-Polls - Version 2.04

Version Description

Download this release

Release Info

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

Version 2.04

pollbar.gif ADDED
Binary file
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-install.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.04 |
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
+ | - Install WP-Polls 2.04 |
14
+ | - wp-admin/polls-install.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Config
21
+ require('../wp-config.php');
22
+
23
+ ### Variables, Variables, Variables
24
+ $current_timestamp = current_time('timestamp');
25
+ $create_table = array();
26
+ $insert_pollq = array();
27
+ $insert_polla = array();
28
+ $insert_options = array();
29
+ $error = '';
30
+
31
+ ### Create Tables (3 Tables)
32
+ $create_table[] = "CREATE TABLE $wpdb->pollsq (".
33
+ "pollq_id int(10) NOT NULL auto_increment,".
34
+ "pollq_question varchar(200) NOT NULL default '',".
35
+ "pollq_timestamp varchar(20) NOT NULL default '',".
36
+ "pollq_totalvotes int(10) NOT NULL default '0',".
37
+ "PRIMARY KEY (pollq_id))";
38
+ $create_table[] = "CREATE TABLE $wpdb->pollsa (".
39
+ "polla_aid int(10) NOT NULL auto_increment,".
40
+ "polla_qid int(10) NOT NULL default '0',".
41
+ "polla_answers varchar(200) NOT NULL default '',".
42
+ "polla_votes int(10) NOT NULL default '0',".
43
+ "PRIMARY KEY (polla_aid))";
44
+ $create_table[] = "CREATE TABLE $wpdb->pollsip (".
45
+ "pollip_id int(10) NOT NULL auto_increment,".
46
+ "pollip_qid varchar(10) NOT NULL default '',".
47
+ "pollip_aid varchar(10) NOT NULL default '',".
48
+ "pollip_ip varchar(100) NOT NULL default '',".
49
+ "pollip_host VARCHAR(200) NOT NULL default '',".
50
+ "pollip_timestamp varchar(20) NOT NULL default '0000-00-00 00:00:00',".
51
+ "pollip_user tinytext NOT NULL,".
52
+ "PRIMARY KEY (pollip_id))";
53
+
54
+ ### Insert Poll Question (1 Row)
55
+ $insert_pollq[] = "INSERT INTO $wpdb->pollsq VALUES (1, 'How Is My Site?', '$current_timestamp', 0);";
56
+
57
+ ### Insert Poll Answers (5 Rows)
58
+ $insert_polla[] = "INSERT INTO $wpdb->pollsa VALUES (1, 1, 'Good', 0);";
59
+ $insert_polla[] = "INSERT INTO $wpdb->pollsa VALUES (2, 1, 'Excellent', 0);";
60
+ $insert_polla[] = "INSERT INTO $wpdb->pollsa VALUES (3, 1, 'Bad', 0);";
61
+ $insert_polla[] = "INSERT INTO $wpdb->pollsa VALUES (4, 1, 'Can Be Improved', 0);";
62
+ $insert_polla[] = "INSERT INTO $wpdb->pollsa VALUES (5, 1, 'No Comments', 0);";
63
+
64
+ ### Insert Options (16 Rows)
65
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_voteheader', 'Y', 1, '<table width=\\\"100%\\\" border=\\\"0\\\" cellspacing=\\\"3\\\" cellpadding=\\\"3\\\">\r\n<tr>\r\n<td align=\\\"center\\\"><b>%POLL_QUESTION%</b></td>\r\n</tr>', 20, 8, 'Template For Poll''s Question', 1, 'yes');";
66
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_votebody', 'Y', 1, '<tr>\r\n<td align=\\\"left\\\"><input type=\\\"radio\\\" name=\\\"poll-%POLL_ID%\\\" value=\\\"%POLL_ANSWER_ID%\\\" /> %POLL_ANSWER%</td>\r\n</tr>', 20, 8, 'Template For Poll''s Answers', 1, 'yes');";
67
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_votefooter', 'Y', 1, '<tr>\r\n<td align=\\\"center\\\"><input type=\\\"submit\\\" name=\\\"vote\\\" value=\\\" Vote \\\" class=\\\"Buttons\\\" /><br /><a href=\\\"%POLL_RESULT_URL%\\\">View Results</a></td>\r\n</tr>\r\n</table>', 20, 8, 'Template For Poll''s Voting Footer', 1, 'yes');";
68
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_resultheader', 'Y', 1, '<table width=\\\"100%\\\" border=\\\"0\\\" cellspacing=\\\"3\\\" cellpadding=\\\"3\\\">\r\n<tr>\r\n<td colspan=\\\"2\\\" align=\\\"center\\\"><b>%POLL_QUESTION%</b></td>\r\n</tr>', 20, 8, '', 1, 'yes');";
69
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_resultbody', 'Y', 1, '<tr>\r\n<td align=\\\"left\\\" width=\\\"70%\\\">%POLL_ANSWER%<br /><img src=\\\"".get_settings('home')."/wp-includes/images/pollbar.gif\\\" height=\\\"5\\\" width=\\\"%POLL_ANSWER_IMAGEWIDTH%\\\" alt=\\\"%POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)\\\" /></td>\r\n<td align=\\\"right\\\" width=\\\"30%\\\"><b>%POLL_ANSWER_PERCENTAGE%%</b></td>\r\n</tr>', 20, 8, '', 1, 'yes');";
70
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_resultbody2', 'Y', 1, '<tr>\r\n<td align=\\\"left\\\" width=\\\"70%\\\"><i>%POLL_ANSWER%</i><br /><img src=\\\"".get_settings('home')."/wp-includes/images/pollbar.gif\\\" height=\\\"5\\\" width=\\\"%POLL_ANSWER_IMAGEWIDTH%\\\" alt=\\\"You Have Voted For This Choice - %POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)\\\" /></td>\r\n<td align=\\\"right\\\" width=\\\"30%\\\"><i><b>%POLL_ANSWER_PERCENTAGE%%</b></i></td>\r\n</tr>', 20, 8, '', 1, 'yes');";
71
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_resultfooter', 'Y', 1, '<tr>\r\n<td colspan=\\\"2\\\" align=\\\"center\\\">Total Votes: <b>%POLL_TOTALVOTES%</b><td>\r\n</tr>\r\n</table>', 20, 8, '', 1, 'yes');";
72
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_disable', 'Y', 1, 'Sorry, there are no polls available at the moment.', 20, 8, 'Template For Poll When It Is Disabled', 1, 'yes');";
73
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_error', 'Y', 1, 'An error has occurred when processing your poll.', '20', '8', 'Template For Poll When An Error Has Occured', 1, 'yes');";
74
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_currentpoll', 'Y', 1, '0', 20, 8, 'Current Displayed Poll', 1, 'yes');";
75
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_latestpoll', 'Y', 1, '1', 20, 8, 'The Lastest Poll', 1, 'yes');";
76
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_archive_perpage', 'Y', 1, '5', 2, 8, 'Number Of Polls To Display Per Page On The Poll''s Archive', 1, 'no');";
77
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_ans_sortby', 'Y', 1, 'polla_aid', 20, 8, 'Sorting Of Poll''s Answers', 1, 'yes');";
78
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_ans_sortorder', 'Y', 1, 'asc', 20, 8, 'Sort Order Of Poll''s Answers', 1, 'yes');";
79
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_ans_result_sortby', 'Y', 1, 'polla_votes', 20, 8, 'Sorting Of Poll''s Answers Result', 1, 'yes');";
80
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_ans_result_sortorder', 'Y', 1, 'desc', 20, 8, 'Sorting Order Of Poll''s Answers Result', 1, 'yes');";
81
+
82
+ ### Check Whether There Is Any Pre Errors
83
+ $wpdb->show_errors = false;
84
+ $check_install = $wpdb->query("SHOW COLUMNS FROM $wpdb->pollsq");
85
+ if($check_install) {
86
+ $error = __('You Had Already Installed WP-Polls.');
87
+ }
88
+ if(empty($wpdb->pollsq) || empty($wpdb->pollsa) || empty($wpdb->pollsip)) {
89
+ $error = __('Please Define The pollsq, pollsa and pollsip tables in wp-settings.php.');
90
+ }
91
+ ?>
92
+
93
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
94
+ <html xmlns="http://www.w3.org/1999/xhtml">
95
+ <head>
96
+ <title>WordPress &rsaquo; <?php _e('Installing'); ?> &rsaquo; <?php _e('WP-Polls 2.04'); ?></title>
97
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
98
+ <style type="text/css" media="screen">
99
+ @import url( wp-admin.css );
100
+ </style>
101
+ </head>
102
+ <body>
103
+ <div class="wrap">
104
+ <h2><?php _e('Install WP-Polls 2.04'); ?></h2>
105
+ <p><?php _e('This install script will install WP-Polls 2.04 for your Wordpress'); ?>.</p>
106
+ <p>
107
+ <?php _e('This install script will be doing the following:'); ?><br />
108
+ <b>&raquo;</b> <b>3</b> <?php _e('tables will be created namely <b>pollsq</b>, <b>pollsa</b> and <b>pollsip</b>.'); ?><br />
109
+ <b>&raquo;</b> <b>1</b> <?php _e('poll question (<b>How Is My Site?</b>) will be inserted into <b>pollsq</b> table.'); ?><br />
110
+ <b>&raquo;</b> <b>5</b> <?php _e('poll answers(<b>Good</b>, <b>Excellent</b>, <b>Bad</b>, <b>Can Be Improved</b>, <b>No Comments</b>) will be inserted into <b>pollsa</b> table.'); ?><br />
111
+ <b>&raquo;</b> <b>15</b> <?php _e('options will be inserted into the <b>options</b> table.'); ?><br />
112
+ <b>&raquo;</b> <b>4</b> <?php _e('tables will be optimized namely <b>pollsq</b>, <b>pollsa</b>, <b>pollsip</b> and <b>options</b>.'); ?><br />
113
+ </p>
114
+ <?php
115
+ if(empty($error)) {
116
+ if(!empty($_POST['install'])) {
117
+ // Create Tables
118
+ $create_table_count = 0;
119
+ echo "<p><b>".__('Creating Tables:')."</b>";
120
+ foreach($create_table as $createtable) {
121
+ $wpdb->query($createtable);
122
+ }
123
+ $check_pollsq = $wpdb->query("SHOW COLUMNS FROM $wpdb->pollsq");
124
+ $check_pollsa = $wpdb->query("SHOW COLUMNS FROM $wpdb->pollsa");
125
+ $check_pollsip = $wpdb->query("SHOW COLUMNS FROM $wpdb->pollsip");
126
+ if($check_pollsq) {
127
+ echo "<br /><b>&raquo;</b> Table (<b>$wpdb->pollsq</b>) created.";
128
+ $create_table_count++;
129
+ } else {
130
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Table (<b>$wpdb->pollsq</b>) table NOT created.</font>";
131
+ }
132
+ if($check_pollsa) {
133
+ echo "<br /><b>&raquo;</b> Table (<b>$wpdb->pollsa</b>) created.";
134
+ $create_table_count++;
135
+ } else {
136
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Table (<b>$wpdb->pollsa</b>) table NOT created.</font>";
137
+ }
138
+ if($check_pollsip) {
139
+ echo "<br /><b>&raquo;</b> Table (<b>$wpdb->pollsip</b>) created.";
140
+ $create_table_count++;
141
+ } else {
142
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Table (<b>$wpdb->pollsip</b>) table NOT created.</font>";
143
+ }
144
+ echo "<br /><b>&raquo;</b> <b>$create_table_count / 3</b> Tables Created.</p>";
145
+ // Insert Poll Questions
146
+ $insert_pollq_count = 0;
147
+ echo "<p><b>".__('Inserting Poll Questions:')."</b>";
148
+ foreach($insert_pollq as $insertpollq) {
149
+ $temp_pollq = $wpdb->query($insertpollq);
150
+ $temp_poll_question = explode("VALUES ", $insertpollq);
151
+ $temp_poll_question = $temp_poll_question[1];
152
+ $temp_poll_question = substr($temp_poll_question, 5, -20);
153
+ if($temp_pollq) {
154
+ echo "<br /><b>&raquo;</b> Poll question (<b>$temp_poll_question</b>) inserted.";
155
+ $insert_pollq_count ++;
156
+ } else {
157
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Poll question (<b>$temp_poll_question</b>) NOT inserted.</font>";
158
+ }
159
+ }
160
+ echo "<br /><b>&raquo;</b> <b>$insert_pollq_count / 1</b> Poll Questions Inserted.</p>";
161
+ // Insert Poll Answers
162
+ $insert_polla_count = 0;
163
+ echo "<p><b>".__('Inserting Poll Answers:')."</b>";
164
+ foreach($insert_polla as $insertpolla) {
165
+ $temp_polla = $wpdb->query($insertpolla);
166
+ $temp_poll_answer = explode("VALUES ", $insertpolla);
167
+ $temp_poll_answer = $temp_poll_answer[1];
168
+ $temp_poll_answer = substr($temp_poll_answer, 8, -6);
169
+ if($temp_polla) {
170
+ echo "<br /><b>&raquo;</b> Poll answer (<b>$temp_poll_answer</b>) inserted.";
171
+ $insert_polla_count ++;
172
+ } else {
173
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Poll answer (<b>$temp_poll_answer</b>) NOT inserted.</font>";
174
+ }
175
+ }
176
+ echo "<br /><b>&raquo;</b> <b>$insert_polla_count / 5</b> Poll Answers Inserted.</p>";
177
+ // Insert Options
178
+ $insert_options_count = 0;
179
+ echo "<p><b>".__('Inserting Options:')."</b>";
180
+ foreach($insert_options as $insertoptions) {
181
+ $temp_options = $wpdb->query($insertoptions);
182
+ $temp_option = explode(" ", $insertoptions);
183
+ $temp_option = $temp_option[6];
184
+ $temp_option = substr($temp_option, 1, -2);
185
+ if($temp_options) {
186
+ echo "<br /><b>&raquo;</b> Option (<b>$temp_option</b>) inserted.";
187
+ $insert_options_count ++;
188
+ } else {
189
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Option (<b>$temp_option</b>) NOT inserted.</font>";
190
+ }
191
+ }
192
+ echo "<br /><b>&raquo;</b> <b>$insert_options_count / 16</b> Options Inserted.</p>";
193
+ // Optimize Tables
194
+ $optimize_table_count = 0;
195
+ echo "<p><b>".__('Optimizing Tables:')."</b>";
196
+ $optimize_tables = $wpdb->query("OPTIMIZE TABLE $wpdb->pollsq, $wpdb->pollsa, $wpdb->pollsip, $wpdb->options");
197
+ if($optimize_tables) {
198
+ echo "<br /><b>&raquo;</b> Tables (<b>$wpdb->pollsq</b>, <b>$wpdb->pollsa</b>, <b>$wpdb->pollsip</b>, <b>$wpdb->options</b>) optimized.";
199
+ $optimize_table_count = 4;
200
+ } else {
201
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Tables (<b>$wpdb->pollsq</b>, <b>$wpdb->pollsa</b>, <b>$wpdb->pollsip</b>, <b>$wpdb->options</b>) NOT optimized.</font>";
202
+ }
203
+ echo "<br /><b>&raquo;</b> <b>$optimize_table_count / 4</b> Tables Optimized.</p>";
204
+ // Check Whether Install Is Successful
205
+ if($create_table_count == 3 && $insert_pollq_count == 1 && $insert_polla_count == 5 && $insert_options_count == 16) {
206
+ echo '<p align="center"><b>'.__('WP-Polls 2.04 Installed Successfully.').'</b><br />'.__('Please remember to delete this file before proceeding on.').'</p>';
207
+ }
208
+ } else {
209
+ ?>
210
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
211
+ <div align="center"><input type="submit" name="install" value="<?php _e('Click Here To Install WP-Polls 2.04'); ?>" class="button"></div>
212
+ </form>
213
+ <?php
214
+ }
215
+ } else {
216
+ echo "<p align=\"center\"><font color=\"red\"><b>$error</b></font></p>\n";
217
+ }
218
+ ?>
219
+ </div>
220
+ </body>
221
+ </html>
polls-manager.php ADDED
@@ -0,0 +1,648 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.04 |
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-admin/polls-manager.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Admin
21
+ require_once('admin.php');
22
+
23
+
24
+ ### Check Whether User Can Manage Polls
25
+ if(!current_user_can('manage_polls')) {
26
+ die('Access Denied');
27
+ }
28
+
29
+
30
+ ### Variables Variables Variables
31
+ $title = __('Manage Polls');
32
+ $this_file = 'polls-manager.php';
33
+ $parent_file = 'polls-manager.php';
34
+ $mode = trim($_GET['mode']);
35
+ $poll_id = intval($_GET['id']);
36
+ $poll_aid = intval($_GET['aid']);
37
+
38
+
39
+ ### Cancel
40
+ if(isset($_POST['cancel'])) {
41
+ Header('Location: polls-manager.php');
42
+ exit();
43
+ }
44
+
45
+
46
+ ### Form Processing
47
+ if(!empty($_POST['do'])) {
48
+ // Decide What To Do
49
+ switch($_POST['do']) {
50
+ // Add Poll
51
+ case 'Add Poll':
52
+ // Add Poll Question
53
+ $pollq_question = addslashes(trim($_POST['pollq_question']));
54
+ $pollq_timestamp = current_time('timestamp');
55
+ $add_poll_question = $wpdb->query("INSERT INTO $wpdb->pollsq VALUES (0, '$pollq_question', '$pollq_timestamp', 0)");
56
+ if(!$add_poll_question) {
57
+ $text .= '<font color="red">Error In Adding Poll \''.stripslashes($pollq_question).'\'</font>';
58
+ }
59
+ // Add Poll Answers
60
+ $polla_answers = $_POST['polla_answers'];
61
+ $polla_qid = intval($wpdb->insert_id);
62
+ foreach($polla_answers as $polla_answer) {
63
+ $polla_answer = addslashes(trim($polla_answer));
64
+ $add_poll_answers = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answer', 0)");
65
+ if(!$add_poll_answers) {
66
+ $text .= '<font color="red">Error In Adding Poll\'s Answer \''.stripslashes($polla_answer).'\'</font>';
67
+ }
68
+ }
69
+ // Update Lastest Poll ID To Poll Options
70
+ $update_latestpoll = $wpdb->query("UPDATE $wpdb->options SET option_value = $polla_qid WHERE option_name = 'poll_latestpoll'");
71
+ if(!$update_latestpoll) {
72
+ $text .= "<font color=\"red\">There Is An Error Updating The Lastest Poll ID ($polla_qid) To The Poll Option</font>";
73
+ }
74
+ if(empty($text)) {
75
+ $text = '<font color="green">Poll \''.stripslashes($pollq_question).'\' Added Successfully</font>';
76
+ wp_cache_flush();
77
+ }
78
+ break;
79
+ // Edit Poll
80
+ case 'Edit Poll':
81
+ // Update Poll's Question
82
+ $pollq_id = intval($_POST['pollq_id']);
83
+ $pollq_totalvotes = intval($_POST['pollq_totalvotes']);
84
+ $pollq_question = addslashes(trim($_POST['pollq_question']));
85
+ $edit_polltimestamp = intval($_POST['edit_polltimestamp']);
86
+ $timestamp_sql = '';
87
+ if($edit_polltimestamp == 1) {
88
+ $pollq_timestamp_day = intval($_POST['pollq_timestamp_day']);
89
+ $pollq_timestamp_month = intval($_POST['pollq_timestamp_month']);
90
+ $pollq_timestamp_year = intval($_POST['pollq_timestamp_year']);
91
+ $pollq_timestamp_hour = intval($_POST['pollq_timestamp_hour']);
92
+ $pollq_timestamp_minute = intval($_POST['pollq_timestamp_minute']);
93
+ $pollq_timestamp_second = intval($_POST['pollq_timestamp_second']);
94
+ $timestamp_sql = ", pollq_timestamp = '".gmmktime($pollq_timestamp_hour, $pollq_timestamp_minute, $pollq_timestamp_second, $pollq_timestamp_month, $pollq_timestamp_day, $pollq_timestamp_year)."'";
95
+ }
96
+
97
+ $edit_poll_question = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_question = '$pollq_question', pollq_totalvotes = $pollq_totalvotes $timestamp_sql WHERE pollq_id = $pollq_id");
98
+ if(!$edit_poll_question) {
99
+ $text = '<font color="blue">No Changes Had Been Made To \''.stripslashes($pollq_question).'\'</font>';
100
+ }
101
+ // Update Polls' Answers
102
+ $polla_aids = array();
103
+ $get_polla_aids = $wpdb->get_results("SELECT polla_aid FROM $wpdb->pollsa WHERE polla_qid = $pollq_id ORDER BY polla_aid ASC");
104
+ if($get_polla_aids) {
105
+ foreach($get_polla_aids as $get_polla_aid) {
106
+ $polla_aids[] = intval($get_polla_aid->polla_aid);
107
+ }
108
+ foreach($polla_aids as $polla_aid) {
109
+ $polla_answers = addslashes(trim($_POST['polla_aid-'.$polla_aid]));
110
+ $polla_votes = intval($_POST['polla_votes-'.$polla_aid]);
111
+ $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");
112
+ if(!$edit_poll_answer) {
113
+ $text .= '<br /><font color="blue">No Changes Had Been Made To Poll\'s Answer \''.stripslashes($polla_answers).'\'</font>';
114
+ }
115
+ }
116
+ } else {
117
+ $text .= '<br /><font color="red">Invalid Poll \''.stripslashes($pollq_question).'\'</font>';
118
+ }
119
+ if(empty($text)) {
120
+ $text = '<font color="green">Poll \''.stripslashes($pollq_question).'\' Edited Successfully</font>';
121
+ }
122
+ break;
123
+ // Delete Poll
124
+ case 'Delete Poll':
125
+ $pollq_id = intval($_POST['pollq_id']);
126
+ $pollq_question = trim($_POST['pollq_question']);
127
+ $delete_poll_question = $wpdb->query("DELETE FROM $wpdb->pollsq WHERE pollq_id = $pollq_id");
128
+ $delete_poll_answers = $wpdb->query("DELETE FROM $wpdb->pollsa WHERE polla_qid = $pollq_id");
129
+ $delete_poll_ip = $wpdb->query("DELETE FROM $wpdb->pollsip WHERE pollip_qid = $pollq_id");
130
+ $poll_option_lastestpoll = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'poll_latestpoll'");
131
+ if(!$delete_poll_question) {
132
+ $text = '<font color="red">Error In Deleting Poll \''.stripslashes($pollq_question).'\' Question</font>';
133
+ }
134
+ if(!$delete_poll_answers) {
135
+ $text .= '<br /><font color="red">Error In Deleting Poll Answers For \''.stripslashes($pollq_question).'\'</font>';
136
+ }
137
+ if(!$delete_poll_ip) {
138
+ $text .= '<br /><font color="red">Error In Deleting Voted IPs For \''.stripslashes($pollq_question).'\'</font>';
139
+ }
140
+ if(empty($text)) {
141
+ if($poll_option_lastestpoll == $pollq_id) {
142
+ $poll_lastestpoll = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq ORDER BY pollq_id DESC LIMIT 1");
143
+ if($poll_lastestpoll) {
144
+ $poll_lastestpoll = intval($poll_lastestpoll);
145
+ $update_latestpoll = $wpdb->query("UPDATE $wpdb->options SET option_value = $poll_lastestpoll WHERE option_name = 'poll_latestpoll'");
146
+ }
147
+ }
148
+ $text = '<font color="green">Poll \''.stripslashes($pollq_question).'\' Deleted Successfully</font>';
149
+ }
150
+ break;
151
+ // Add Poll's Answer
152
+ case 'Add Answer':
153
+ $polla_qid = intval($_POST['polla_qid']);
154
+ $polla_answers = addslashes(trim($_POST['polla_answers']));
155
+ $add_poll_question = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answers', 0)");
156
+ if(!$add_poll_question) {
157
+ $text = '<font color="red">Error In Adding Poll Answer \''.stripslashes($polla_answers).'\'</font>';
158
+ } else {
159
+ $text = '<font color="green">Poll Answer \''.stripslashes($polla_answers).'\' Added Successfully</font>';
160
+ }
161
+ break;
162
+ }
163
+ }
164
+
165
+
166
+ ### Determines Which Mode It Is
167
+ switch($mode) {
168
+ // Add A Poll
169
+ case 'add':
170
+ $title = __('Add Poll');
171
+ require("./admin-header.php");
172
+ ?>
173
+ <div class="wrap">
174
+ <h2>Add Poll</h2>
175
+ <?php
176
+ if(isset($_POST['addpollquestion'])) {
177
+ $poll_noquestion = intval($_POST['poll_noquestion']);
178
+ $pollq_question = stripslashes(trim($_POST['pollq_question']));
179
+ ?>
180
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
181
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
182
+ <tr>
183
+ <th align="left" scope="row"><?php _e('Question') ?></th>
184
+ <td><input type="text" size="50" maxlength="200" name="pollq_question" value="<?php echo $pollq_question; ?>"></td>
185
+ <?php
186
+ for($i=1; $i<=$poll_noquestion; $i++) {
187
+ echo "<tr>\n";
188
+ echo "<th align=\"left\" scope=\"row\">Answers $i:</th>\n";
189
+ echo "<td><input type=\"text\" size=\"30\" maxlength=\"200\" name=\"polla_answers[]\"></td>\n";
190
+ echo "</tr>\n";
191
+ }
192
+ ?>
193
+ </tr>
194
+ <tr>
195
+ <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Add Poll'); ?>" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="<?php _e('Cancel'); ?>" class="button"></td>
196
+ </tr>
197
+ </table>
198
+ </form>
199
+ <?php } else {?>
200
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=add" method="post">
201
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
202
+ <tr>
203
+ <th align="left" scope="row"><?php _e('Question') ?></th>
204
+ <td><input type="text" size="50" maxlength="200" name="pollq_question"></td>
205
+ </tr>
206
+ <th align="left" scope="row"><?php _e('No. Of Answers:') ?></th>
207
+ <td>
208
+ <select size="1" name="poll_noquestion">
209
+ <?php
210
+ for($i=2; $i <= 20; $i++) {
211
+ echo "<option value=\"$i\">$i</option>";
212
+ }
213
+ ?>
214
+ </select>
215
+ </td>
216
+ </tr>
217
+ <tr>
218
+ <td colspan="2" align="center"><input type="submit" name="addpollquestion" value="<?php _e('Add Question'); ?>" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="<?php _e('Cancel'); ?>" class="button"></td>
219
+ </tr>
220
+ </table>
221
+ </form>
222
+ <?php } ?>
223
+ </div>
224
+ <?php
225
+ break;
226
+ // Edit A Poll
227
+ case 'edit':
228
+ $title = __('Edit Poll');
229
+ require("./admin-header.php");
230
+ $poll_question = $wpdb->get_row("SELECT pollq_question, pollq_timestamp, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id");
231
+ $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");
232
+ $poll_question_text = stripslashes($poll_question->pollq_question);
233
+ $poll_totalvotes = intval($poll_question->pollq_totalvote);
234
+ $poll_timestamp = $poll_question->pollq_timestamp;
235
+
236
+ // Edit Timestamp Options
237
+ function poll_timestamp($poll_timestamp) {
238
+ global $month;
239
+ $day = gmdate('j', $poll_timestamp);
240
+ echo '<select name="pollq_timestamp_day" size="1">"'."\n";
241
+ for($i = 1; $i <=31; $i++) {
242
+ if($day == $i) {
243
+ echo "<option value=\"$i\" selected=\"true\">$i</option>\n";
244
+ } else {
245
+ echo "<option value=\"$i\">$i</option>\n";
246
+ }
247
+ }
248
+ echo '</select>&nbsp;&nbsp;'."\n";
249
+ $month2 = gmdate('n', $poll_timestamp);
250
+ echo '<select name="pollq_timestamp_month" size="1">"'."\n";
251
+ for($i = 1; $i <= 12; $i++) {
252
+ if ($i < 10) {
253
+ $ii = '0'.$i;
254
+ } else {
255
+ $ii = $i;
256
+ }
257
+ if($month2 == $i) {
258
+ echo "<option value=\"$i\" selected=\"true\">$month[$ii]</option>\n";
259
+ } else {
260
+ echo "<option value=\"$i\">$month[$ii]</option>\n";
261
+ }
262
+ }
263
+ echo '</select>&nbsp;&nbsp;'."\n";
264
+ $year = gmdate('Y', $poll_timestamp);
265
+ echo '<select name="pollq_timestamp_year" size="1">"'."\n";
266
+ for($i = 2000; $i <= gmdate('Y'); $i++) {
267
+ if($year == $i) {
268
+ echo "<option value=\"$i\" selected=\"true\">$i</option>\n";
269
+ } else {
270
+ echo "<option value=\"$i\">$i</option>\n";
271
+ }
272
+ }
273
+ echo '</select>&nbsp;@'."\n";
274
+ $hour = gmdate('H', $poll_timestamp);
275
+ echo '<select name="pollq_timestamp_hour" size="1">"'."\n";
276
+ for($i = 0; $i < 24; $i++) {
277
+ if($hour == $i) {
278
+ echo "<option value=\"$i\" selected=\"true\">$i</option>\n";
279
+ } else {
280
+ echo "<option value=\"$i\">$i</option>\n";
281
+ }
282
+ }
283
+ echo '</select>&nbsp;:'."\n";
284
+ $minute = gmdate('i', $poll_timestamp);
285
+ echo '<select name="pollq_timestamp_minute" size="1">"'."\n";
286
+ for($i = 0; $i < 60; $i++) {
287
+ if($minute == $i) {
288
+ echo "<option value=\"$i\" selected=\"true\">$i</option>\n";
289
+ } else {
290
+ echo "<option value=\"$i\">$i</option>\n";
291
+ }
292
+ }
293
+
294
+ echo '</select>&nbsp;:'."\n";
295
+ $second = gmdate('s', $poll_timestamp);
296
+ echo '<select name="pollq_timestamp_second" size="1">"'."\n";
297
+ for($i = 0; $i <= 60; $i++) {
298
+ if($second == $i) {
299
+ echo "<option value=\"$i\" selected=\"true\">$i</option>\n";
300
+ } else {
301
+ echo "<option value=\"$i\">$i</option>\n";
302
+ }
303
+ }
304
+ echo '</select>'."\n";
305
+ }
306
+ ?>
307
+ <script language="Javascript" type="text/javascript">
308
+ function check_totalvotes() {
309
+ var total_votes = 0;
310
+ var temp_vote = 0;
311
+ <?php
312
+ foreach($poll_answers as $poll_answer) {
313
+ $polla_aid = intval($poll_answer->polla_aid);
314
+ echo "\t\t\t\ttemp_vote = parseInt(document.getElementById('polla_votes-$polla_aid').value);\n";
315
+ echo "\t\t\t\tif(isNaN(temp_vote)) {\n";
316
+ echo "\t\t\t\tdocument.getElementById('polla_votes-$polla_aid').value = 0;\n";
317
+ echo "\t\t\t\ttemp_vote = 0;\n";
318
+ echo "\t\t\t\t}\n";
319
+ echo "\t\t\t\ttotal_votes += temp_vote;\n";
320
+ }
321
+ ?>
322
+ document.getElementById('pollq_totalvotes').value = parseInt(total_votes);
323
+ }
324
+ </script>
325
+ <!-- Edit Poll -->
326
+ <div class="wrap">
327
+ <h2><?php _e('Edit Poll'); ?></h2>
328
+ <form name="edit_poll" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
329
+ <input type="hidden" name="pollq_id" value="<?php echo $poll_id; ?>">
330
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
331
+ <tr>
332
+ <th scope="row" colspan="2"><?php _e('Question') ?></th>
333
+ </tr>
334
+ <tr>
335
+ <td align="center" colspan="2"><input type="text" size="70" maxlength="200" name="pollq_question" value="<?php echo $poll_question_text; ?>" /></td>
336
+ </tr>
337
+ <tr>
338
+ <th align="left" scope="row"><?php _e('Answers:') ?></th>
339
+ <th align="right" scope="row"><?php _e('No. Of Votes') ?></th>
340
+ </tr>
341
+ <?php
342
+ $i=1;
343
+ $poll_actual_totalvotes = 0;
344
+ if($poll_answers) {
345
+ $pollip_answers = array();
346
+ $pollip_answers[0] = __('Null Votes');
347
+ foreach($poll_answers as $poll_answer) {
348
+ $polla_aid = intval($poll_answer->polla_aid);
349
+ $polla_answers = stripslashes($poll_answer->polla_answers);
350
+ $polla_votes = intval($poll_answer->polla_votes);
351
+ $pollip_answers[$polla_aid] = $polla_answers;
352
+ echo "<tr>\n";
353
+ 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;";
354
+ echo "<a href=\"polls-manager.php?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";
355
+ 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";
356
+ $poll_actual_totalvotes += $polla_votes;
357
+ $i++;
358
+ }
359
+ }
360
+ ?>
361
+ </tr>
362
+ <tr>
363
+ <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>
364
+ </tr>
365
+ <tr>
366
+ <td colspan="2"><b><?php _e('Timestamp'); ?></b>:</td>
367
+ </tr>
368
+ <tr>
369
+ <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>
370
+ </tr>
371
+ <tr>
372
+ <td align="center" colspan="2"><input type="submit" name="do" value="<?php _e('Edit Poll'); ?>" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="<?php _e('Cancel'); ?>" class="button"></td>
373
+ </tr>
374
+ </table>
375
+ </form>
376
+ </div>
377
+ <!-- Add Poll's Answer -->
378
+ <div class="wrap">
379
+ <h2><?php _e('Add Answer') ?></h2>
380
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=edit&id=<?php echo $poll_id; ?>" method="post">
381
+ <input type="hidden" name="polla_qid" value="<?php echo $poll_id; ?>">
382
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
383
+ <tr>
384
+ <td><b><?php _e('Add Answer') ?></b></td>
385
+ <td><input type="text" size="50" maxlength="200" name="polla_answers"></td>
386
+ </tr>
387
+ <tr>
388
+ <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Add Answer'); ?>" class="button"></td>
389
+ </tr>
390
+ </table>
391
+ </form>
392
+ </div>
393
+ <!-- Users Voted For This Poll -->
394
+ <?php
395
+ $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");
396
+ ?>
397
+ <div class="wrap">
398
+ <h2><?php _e('Users Voted For This Poll') ?></h2>
399
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
400
+ <?php
401
+ if($poll_ips) {
402
+ $k = 1;
403
+ $poll_last_aid = -1;
404
+ foreach($poll_ips as $poll_ip) {
405
+ $pollip_aid = intval($poll_ip->pollip_aid);
406
+ $pollip_user = stripslashes($poll_ip->pollip_user);
407
+ $pollip_ip = $poll_ip->pollip_ip;
408
+ $pollip_host = $poll_ip->pollip_host;
409
+ $pollip_date = gmdate("jS F Y @ H:i", $poll_ip->pollip_timestamp);
410
+ if($pollip_aid != $poll_last_aid) {
411
+ if($pollip_aid == 0) {
412
+ echo "<tr style='background-color: #b8d4ff'>\n<td colspan=\"4\"><b>$pollip_answers[$pollip_aid]</b></td>\n</tr>\n";
413
+ } else {
414
+ echo "<tr style='background-color: #b8d4ff'>\n<td colspan=\"4\"><b>".__('Answer')." $k: $pollip_answers[$pollip_aid]</b></td>\n</tr>\n";
415
+ $k++;
416
+ }
417
+ echo "<tr>\n";
418
+ echo "<th scope=\"row\">".__('No.')."</th>\n";
419
+ echo "<th scope=\"row\">".__('User')."</th>\n";
420
+ echo "<th scope=\"row\">".__('IP/Host')."</th>\n";
421
+ echo "<th scope=\"row\">".__('Date')."</th>\n";
422
+ echo "</tr>\n";
423
+ $i = 1;
424
+ }
425
+ if($i%2 == 0) {
426
+ $style = 'style=\'background-color: none\'';
427
+ } else {
428
+ $style = 'style=\'background-color: #eee\'';
429
+ }
430
+ echo "<tr $style>\n";
431
+ echo "<td>$i</td>\n";
432
+ echo "<td>$pollip_user</td>\n";
433
+ echo "<td>$pollip_ip / $pollip_host</td>\n";
434
+ echo "<td>$pollip_date</td>\n";
435
+ echo "</tr>\n";
436
+ $poll_last_aid = $pollip_aid;
437
+ $i++;
438
+ }
439
+ } else {
440
+ echo "<tr>\n<td colspan=\"4\" align=\"center\">".__('No IP Has Been Logged Yet.')."</td>\n</tr>\n";
441
+ }
442
+ ?>
443
+ </table>
444
+ </div>
445
+ <?php
446
+ break;
447
+ // Delete A Poll
448
+ case 'delete':
449
+ $title = __('Delete Poll');
450
+ require("./admin-header.php");
451
+ $poll_question = $wpdb->get_row("SELECT pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id");
452
+ $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = $poll_id ORDER BY polla_answers");
453
+ $poll_question_text = stripslashes($poll_question->pollq_question);
454
+ $poll_totalvotes = intval($poll_question->pollq_totalvotes);
455
+ ?>
456
+ <!-- Delete Poll -->
457
+ <div class="wrap">
458
+ <h2><?php _e('Delete Poll') ?></h2>
459
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
460
+ <input type="hidden" name="pollq_id" value="<?php echo $poll_id; ?>">
461
+ <input type="hidden" name="pollq_question" value="<?php echo $poll_question_text; ?>">
462
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
463
+ <tr>
464
+ <th colspan="2" scope="row"><?php _e('Question') ?></th>
465
+ </tr>
466
+ <tr>
467
+ <td colspan="2" align="center"><?php echo $poll_question_text; ?></td>
468
+ </tr>
469
+ <tr>
470
+ <th align="left" scope="row"><?php _e('Answers') ?></th>
471
+ <th scope="row"><?php _e('No. Of Votes') ?></th>
472
+ </tr>
473
+ <?php
474
+ $i=1;
475
+ if($poll_answers) {
476
+ foreach($poll_answers as $poll_answer) {
477
+ $polla_answers = stripslashes($poll_answer->polla_answers);
478
+ $polla_votes = intval($poll_answer->polla_votes);
479
+ echo "<tr>\n";
480
+ echo "<td>".__('Answer')." $i:&nbsp;&nbsp;&nbsp;$polla_answers</td>\n";
481
+ echo "<td align=\"center\">$polla_votes</td>\n</tr>\n";
482
+ $i++;
483
+ }
484
+ }
485
+ ?>
486
+ </tr>
487
+ <tr>
488
+ <th colspan="2" scope="row"><?php _e('Total Votes'); ?>: <?php echo $poll_totalvotes; ?></th>
489
+ </tr>
490
+ <tr>
491
+ <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="submit" name="cancel" Value="<?php _e('Cancel'); ?>" class="button"></td>
492
+ </tr>
493
+ </table>
494
+ </form>
495
+ </div>
496
+ <?php
497
+ break;
498
+ // Delete A Poll Answer
499
+ case 'deleteans':
500
+ $title = __('Delete Poll\'s Answer');
501
+ require("./admin-header.php");
502
+ $poll_answers = $wpdb->get_row("SELECT polla_votes, polla_answers FROM $wpdb->pollsa WHERE polla_aid = $poll_aid AND polla_qid = $poll_id");
503
+ $polla_votes = intval($poll_answers->polla_votes);
504
+ $polla_answers = stripslashes(trim($poll_answers->polla_answers));
505
+ $delete_polla_answers = $wpdb->query("DELETE FROM $wpdb->pollsa WHERE polla_aid = $poll_aid AND polla_qid = $poll_id");
506
+ $update_pollq_totalvotes = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes-$polla_votes) WHERE pollq_id=$poll_id");
507
+ ?>
508
+ <!-- Delete Poll's Answer -->
509
+ <div class="wrap">
510
+ <h2><?php _e('Delete Poll\'s Answer') ?></h2>
511
+ <?php
512
+ if($delete_polla_answers) {
513
+ $text = "<font color=\"green\">Poll Answer '$polla_answers' Deleted Successfully</font>";
514
+ } else {
515
+ $text = "<font color=\"red\">Error In Deleting Poll Answer '$polla_answers'</font>";
516
+ }
517
+ if($update_pollq_totalvotes) {
518
+ $text .= "<br /><font color=\"green\">Poll Question's Total Votes Updated Successfully</font>";
519
+ } else {
520
+ $text .= "<br /><font color=\"blue\">No Changes Had Been Made To The Poll's Total Votes</font>";
521
+ }
522
+ _e($text);
523
+ ?>
524
+ <p><b><a href="polls-manager.php?mode=edit&id=<?php echo $poll_id; ?>"><?php _e('Click here To Go Back To The Poll Edit Page'); ?></a>.</b></p>
525
+ </div>
526
+ <?php
527
+ break;
528
+ // Main Page
529
+ default:
530
+ $title = __('Manage Polls');
531
+ require("./admin-header.php");
532
+ $polls = $wpdb->get_results("SELECT * FROM $wpdb->pollsq ORDER BY pollq_id DESC");
533
+ $total_ans = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->pollsa");
534
+ $total_votes = 0;
535
+ ?>
536
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
537
+ <!-- Manage Polls -->
538
+ <div class="wrap">
539
+ <h2><?php _e('Manage Polls'); ?></h2>
540
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
541
+ <tr>
542
+ <th scope="col"><?php _e('ID'); ?></b></th>
543
+ <th scope="col"><?php _e('Question'); ?></b></th>
544
+ <th scope="col"><?php _e('Total Votes'); ?></b></th>
545
+ <th scope="col"><?php _e('Date Added'); ?></b></th>
546
+ <th scope="col" colspan="2"><?php _e('Action'); ?></th>
547
+ </tr>
548
+ <?php
549
+ if($polls) {
550
+ $i = 0;
551
+ $current_poll = intval(get_settings('poll_currentpoll'));
552
+ foreach($polls as $poll) {
553
+ $poll_id = intval($poll->pollq_id);
554
+ $poll_question = stripslashes($poll->pollq_question);
555
+ $poll_date = gmdate("jS F Y @ H:i", $poll->pollq_timestamp);
556
+ $poll_totalvotes = intval($poll->pollq_totalvotes);
557
+ if($i%2 == 0) {
558
+ $style = 'style=\'background-color: #eee\'';
559
+ } else {
560
+ $style = 'style=\'background-color: none\'';
561
+ }
562
+ if($current_poll > 0) {
563
+ if($current_poll == $poll_id) {
564
+ $style = 'style=\'background-color: #b8d4ff\'';
565
+ }
566
+ } else {
567
+ if($i == 0) {
568
+ $style = 'style=\'background-color: #b8d4ff\'';
569
+ }
570
+ }
571
+ echo "<tr $style>\n";
572
+ echo "<td><b>$poll_id</b></td>\n";
573
+ echo '<td>';
574
+ if($current_poll > 0) {
575
+ if($current_poll == $poll_id) {
576
+ echo '<b>'.__('Displayed:').'</b> ';
577
+ }
578
+ } elseif($current_poll != -1) {
579
+ if($i == 0) {
580
+ echo '<b>'.__('Displayed:').'</b> ';
581
+ }
582
+ }
583
+ echo "$poll_question</td>\n";
584
+ echo "<td>$poll_totalvotes</td>\n";
585
+ echo "<td>$poll_date</td>\n";
586
+ echo "<td><a href=\"polls-manager.php?mode=edit&id=$poll_id\" class=\"edit\">".__('Edit')."</a></td>\n";
587
+ echo "<td><a href=\"polls-manager.php?mode=delete&id=$poll_id\" class=\"delete\">".__('Delete')."</a></td>\n";
588
+ echo '</tr>';
589
+ $i++;
590
+ $total_votes+= $poll_totalvotes;
591
+
592
+ }
593
+ } else {
594
+ echo '<tr><td colspan="6" align="center"><b>'.__('No Polls Found').'</b></td></tr>';
595
+ }
596
+ ?>
597
+ </table>
598
+ </div>
599
+ <!-- Add A Poll -->
600
+ <div class="wrap">
601
+ <h2><?php _e('Add A Poll'); ?></h2>
602
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=add" method="post">
603
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
604
+ <tr>
605
+ <th align="left" scope="row"><?php _e('Question') ?></th>
606
+ <td><input type="text" size="50" maxlength="200" name="pollq_question"></td>
607
+ </tr>
608
+ <th align="left" scope="row"><?php _e('No. Of Answers:') ?></th>
609
+ <td>
610
+ <select size="1" name="poll_noquestion">
611
+ <?php
612
+ for($i=2; $i <= 20; $i++) {
613
+ echo "<option value=\"$i\">$i</option>";
614
+ }
615
+ ?>
616
+ </select>
617
+ </td>
618
+ </tr>
619
+ <tr>
620
+ <td colspan="2" align="center"><input type="submit" name="addpollquestion" value="<?php _e('Add Question'); ?>" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="<?php _e('Cancel'); ?>" class="button"></td>
621
+ </tr>
622
+ </table>
623
+ </form>
624
+ </div>
625
+ <!-- Polls Stats -->
626
+ <div class="wrap">
627
+ <h2><?php _e('Polls Stats'); ?></h2>
628
+ <table border="0" cellspacing="3" cellpadding="3">
629
+ <tr>
630
+ <th align="left" scope="row"><?php _e('Total Polls:'); ?></th>
631
+ <td align="left"><?php echo $i; ?></td>
632
+ </tr>
633
+ <tr>
634
+ <th align="left" scope="row"><?php _e('Total Polls\' Answers:'); ?></th>
635
+ <td align="left"><?php echo number_format($total_ans); ?></td>
636
+ </tr>
637
+ <tr>
638
+ <th align="left" scope="row"><?php _e('Total Votes Casted:'); ?></th>
639
+ <td align="left"><?php echo number_format($total_votes); ?></td>
640
+ </tr>
641
+ </table>
642
+ </div>
643
+ <?php
644
+ } // End switch($mode)
645
+
646
+ ### Require Admin Footer
647
+ require_once 'admin-footer.php';
648
+ ?>
polls-options.php ADDED
@@ -0,0 +1,372 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.04 |
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-admin/polls-options.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Admin
21
+ require_once('admin.php');
22
+
23
+
24
+ ### Check Whether User Can Manage Polls
25
+ if(!current_user_can('manage_polls')) {
26
+ die('Access Denied');
27
+ }
28
+
29
+
30
+ ### Variables Variables Variables
31
+ $title = __('Poll Options');
32
+ $this_file = 'polls-options.php';
33
+ $parent_file = 'polls-manager.php';
34
+ $id = intval($_GET['id']);
35
+
36
+
37
+ ### Require Admin Header
38
+ require("./admin-header.php");
39
+
40
+
41
+ ### If Form Is Submitted
42
+ if($_POST['Submit']) {
43
+ $poll_ans_sortby = addslashes(strip_tags(trim($_POST['poll_ans_sortby'])));
44
+ $poll_ans_sortorder = addslashes(strip_tags(trim($_POST['poll_ans_sortorder'])));
45
+ $poll_ans_result_sortby = addslashes(strip_tags(trim($_POST['poll_ans_result_sortby'])));
46
+ $poll_ans_result_sortorder = addslashes(strip_tags(trim($_POST['poll_ans_result_sortorder'])));
47
+ $poll_template_voteheader =addslashes(trim($_POST['poll_template_voteheader']));
48
+ $poll_template_votebody = addslashes(trim($_POST['poll_template_votebody']));
49
+ $poll_template_votefooter = addslashes(trim($_POST['poll_template_votefooter']));
50
+ $poll_template_resultheader = addslashes(trim($_POST['poll_template_resultheader']));
51
+ $poll_template_resultbody = addslashes(trim($_POST['poll_template_resultbody']));
52
+ $poll_template_resultbody2 = addslashes(trim($_POST['poll_template_resultbody2']));
53
+ $poll_template_resultfooter = addslashes(trim($_POST['poll_template_resultfooter']));
54
+ $poll_template_disable =addslashes( trim($_POST['poll_template_disable']));
55
+ $poll_template_error =addslashes( trim($_POST['poll_template_error']));
56
+ $poll_archive_perpage = intval($_POST['poll_archive_perpage']);
57
+ $poll_currentpoll = intval($_POST['poll_currentpoll']);
58
+ $update_poll_queries = array();
59
+ $update_poll_text = array();
60
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_ans_sortby' WHERE option_name = 'poll_ans_sortby'";
61
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_ans_sortorder' WHERE option_name = 'poll_ans_sortorder'";
62
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_ans_result_sortby' WHERE option_name = 'poll_ans_result_sortby'";
63
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_ans_result_sortorder' WHERE option_name = 'poll_ans_result_sortorder'";
64
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_voteheader' WHERE option_name = 'poll_template_voteheader'";
65
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_votebody' WHERE option_name = 'poll_template_votebody'";
66
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_votefooter' WHERE option_name = 'poll_template_votefooter'";
67
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_resultheader' WHERE option_name = 'poll_template_resultheader'";
68
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_resultbody' WHERE option_name = 'poll_template_resultbody'";
69
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_resultbody2' WHERE option_name = 'poll_template_resultbody2'";
70
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_resultfooter' WHERE option_name = 'poll_template_resultfooter'";
71
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_disable' WHERE option_name = 'poll_template_disable'";
72
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_error' WHERE option_name = 'poll_template_error'";
73
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_archive_perpage' WHERE option_name = 'poll_archive_perpage'";
74
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_currentpoll' WHERE option_name = 'poll_currentpoll'";
75
+ $update_poll_text[] = __('Sort Poll Answers By Option');
76
+ $update_poll_text[] = __('Sort Order Of Poll Answers Option');
77
+ $update_poll_text[] = __('Sort Poll Results By Option');
78
+ $update_poll_text[] = __('Sort Order Of Poll Results Option');
79
+ $update_poll_text[] = __('Voting Form Header Template');
80
+ $update_poll_text[] = __('Voting Form Body Template');
81
+ $update_poll_text[] = __('Voting Form Footer Template');
82
+ $update_poll_text[] = __('Result Header Template');
83
+ $update_poll_text[] = __('Result Body Template');
84
+ $update_poll_text[] = __('Result Body2 Template');
85
+ $update_poll_text[] = __('Result Footer Template');
86
+ $update_poll_text[] = __('Poll Disabled Template');
87
+ $update_poll_text[] = __('Poll Error Template');
88
+ $update_poll_text[] = __('Archive Polls Per Page Option');
89
+ $update_poll_text[] = __('Current Active Poll Option');
90
+ $i=0;
91
+ $text = '';
92
+ foreach($update_poll_queries as $update_poll_query) {
93
+ $updating = $wpdb->query($update_poll_query);
94
+ if($updating) {
95
+ $text .= '<font color="green">'.$update_poll_text[$i].' '.__('Updated').'</font><br />';
96
+ wp_cache_flush();
97
+ }
98
+ $i++;
99
+ }
100
+ if(empty($text)) {
101
+ $text = '<font color="red">'.__('No Poll Option Updated').'</font>';
102
+ }
103
+ }
104
+
105
+ ?>
106
+ <script language="JavaScript" type="text/javascript">
107
+ function poll_default_templates(template) {
108
+ var default_template;
109
+ switch(template) {
110
+ case "voteheader":
111
+ default_template = "<table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n<tr>\n<td align=\"center\"><b>%POLL_QUESTION%</b></td>\n</tr>";
112
+ break;
113
+ case "votebody":
114
+ default_template = "<tr>\n<td align=\"left\"><input type=\"radio\" name=\"poll-%POLL_ID%\" value=\"%POLL_ANSWER_ID%\" />&nbsp;%POLL_ANSWER%</td>\n</tr>";
115
+ break;
116
+ case "votefooter":
117
+ default_template = "<tr>\n<td align=\"center\"><input type=\"submit\" name=\"vote\" value=\" Vote \" class=\"Buttons\" /><br /><a href=\"%POLL_RESULT_URL%\">View Results</a></td>\n</tr>\n</table>";
118
+ break;
119
+ case "resultheader":
120
+ default_template = "<table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n<tr>\n<td colspan=\"2\" align=\"center\"><b>%POLL_QUESTION%</b></td>\n</tr>";
121
+ break;
122
+ case "resultbody":
123
+ default_template = "<tr>\n<td align=\"left\" width=\"70%\">%POLL_ANSWER%<br /><img src=\"<?php echo get_settings('home'); ?>/wp-includes/images/pollbar.gif\" height=\"5\" width=\"%POLL_ANSWER_IMAGEWIDTH%\" alt=\"%POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)\" /></td>\n<td align=\"right\" width=\"30%\"><b>%POLL_ANSWER_PERCENTAGE%%</b></td>\n</tr>";
124
+ break;
125
+ case "resultbody2":
126
+ default_template = "<tr>\n<td align=\"left\" width=\"70%\"><i>%POLL_ANSWER%</i><br /><img src=\"<?php echo get_settings('home'); ?>/wp-includes/images/pollbar.gif\" height=\"5\" width=\"%POLL_ANSWER_IMAGEWIDTH%\" alt=\"You Have Voted For This Choice - %POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)\" /></td>\n<td align=\"right\" width=\"30%\"><i><b>%POLL_ANSWER_PERCENTAGE%%</b></i></td>\n</tr>";
127
+ break;
128
+ case "resultfooter":
129
+ default_template = "<tr>\n<td colspan=\"2\" align=\"center\">Total Votes: <b>%POLL_TOTALVOTES%</b><td>\n</tr>\n</table>";
130
+ break;
131
+ case "disable":
132
+ default_template = 'Sorry, there are no polls available at the moment.';
133
+ break;
134
+ case "error":
135
+ default_template = 'An error has occurred when processing your poll.';
136
+ break;
137
+ }
138
+ document.getElementById("poll_template_" + template).value = default_template;
139
+ }
140
+
141
+ </script>
142
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
143
+ <div class="wrap">
144
+ <h2><?php echo $title; ?></h2>
145
+ <form name="polls_options" method="post" action="polls-options.php">
146
+ <fieldset class="options">
147
+ <legend><?php _e('Sorting Of Poll Answers'); ?></legend>
148
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
149
+ <tr valign="top">
150
+ <th scope="row" width="40%"><?php _e('Sort Poll Answers By:'); ?></th>
151
+ <td>
152
+ <select name="poll_ans_sortby" size="1">
153
+ <option value="polla_aid"<?php selected('polla_aid', get_settings('poll_ans_sortby')); ?>><?php _e('Exact Order'); ?></option>
154
+ <option value="polla_answers"<?php selected('polla_answers', get_settings('poll_ans_sortby')); ?>><?php _e('Alphabetical Order'); ?></option>
155
+ </select>
156
+ </td>
157
+ </tr>
158
+ <tr valign="top">
159
+ <th scope="row" width="40%"><?php _e('Sort Order Of Poll Answers:'); ?></th>
160
+ <td>
161
+ <select name="poll_ans_sortorder" size="1">
162
+ <option value="asc"<?php selected('asc', get_settings('poll_ans_sortorder')); ?>><?php _e('Ascending'); ?></option>
163
+ <option value="desc"<?php selected('desc', get_settings('poll_ans_sortorder')); ?>><?php _e('Descending'); ?></option>
164
+ </select>
165
+ </td>
166
+ </tr>
167
+ </table>
168
+ </fieldset>
169
+ <fieldset class="options">
170
+ <legend><?php _e('Sorting Of Poll Results'); ?></legend>
171
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
172
+ <tr valign="top">
173
+ <th scope="row" width="40%"><?php _e('Sort Poll Results By:'); ?></th>
174
+ <td>
175
+ <select name="poll_ans_result_sortby" size="1">
176
+ <option value="polla_votes"<?php selected('polla_votes', get_settings('poll_ans_result_sortby')); ?>><?php _e('Votes'); ?></option>
177
+ <option value="polla_aid"<?php selected('polla_aid', get_settings('poll_ans_result_sortby')); ?>><?php _e('Exact Order'); ?></option>
178
+ <option value="polla_answers"<?php selected('polla_answers', get_settings('poll_ans_result_sortby')); ?>><?php _e('Alphabetical Order'); ?></option>
179
+ </select>
180
+ </td>
181
+ </tr>
182
+ <tr valign="top">
183
+ <th scope="row" width="40%"><?php _e('Sort Order Of Poll Results:'); ?></th>
184
+ <td>
185
+ <select name="poll_ans_result_sortorder" size="1">
186
+ <option value="asc"<?php selected('asc', get_settings('poll_ans_result_sortorder')); ?>><?php _e('Ascending'); ?></option>
187
+ <option value="desc"<?php selected('desc', get_settings('poll_ans_result_sortorder')); ?>><?php _e('Descending'); ?></option>
188
+ </select>
189
+ </td>
190
+ </tr>
191
+ </table>
192
+ </fieldset>
193
+ <fieldset class="options">
194
+ <legend><?php _e('Poll Archive'); ?></legend>
195
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
196
+ <tr valign="top">
197
+ <th scope="row" width="40%"><?php _e('Polls Per Page:'); ?></th>
198
+ <td><input type="text" name="poll_archive_perpage" value="<?php form_option('poll_archive_perpage'); ?>" size="2" /></td>
199
+ </tr>
200
+ </table>
201
+ </fieldset>
202
+ <fieldset class="options">
203
+ <legend><?php _e('Current Active Poll'); ?></legend>
204
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
205
+ <tr valign="top">
206
+ <th scope="row" width="40%"><?php _e('Current Active Poll:'); ?></th>
207
+ <td>
208
+ <select name="poll_currentpoll" size="1">
209
+ <option value="-1"<?php selected('-1', get_settings('poll_currentpoll')); ?>><?php _e('Do NOT Display Poll (Disable)'); ?></option>
210
+ <option value="0"<?php selected('0', get_settings('poll_currentpoll')); ?>><?php _e('Display Latest Poll'); ?></option>
211
+ <option value="0"></option>
212
+ <?php
213
+ $polls = $wpdb->get_results("SELECT pollq_id, pollq_question FROM $wpdb->pollsq ORDER BY pollq_id DESC");
214
+ if($polls) {
215
+ foreach($polls as $poll) {
216
+ $poll_question = stripslashes($poll->pollq_question);
217
+ $poll_id = intval($poll->pollq_id);
218
+ if($poll_id == intval(get_settings('poll_currentpoll'))) {
219
+ echo "<option value=\"$poll_id\" selected=\"selected\">$poll_question</option>\n";
220
+ } else {
221
+ echo "<option value=\"$poll_id\">$poll_question</option>\n";
222
+ }
223
+ }
224
+ }
225
+ ?>
226
+ </select>
227
+ </td>
228
+ </tr>
229
+ </table>
230
+ </fieldset>
231
+ <fieldset class="options">
232
+ <legend><?php _e('Template Variables'); ?></legend>
233
+ <table width="100%" cellspacing="2" cellpadding="5" align="center">
234
+ <tr>
235
+ <td><b>%POLL_ID%</b> - <?php _e('Display the poll\'s ID'); ?></td>
236
+ <td><b>%POLL_ANSWER_ID%</b> - <?php _e('Display the poll\'s answer ID'); ?></td>
237
+ </tr>
238
+ <tr>
239
+ <td><b>%POLL_QUESTION%</b> - <?php _e('Display the poll\'s question'); ?></td>
240
+ <td><b>%POLL_ANSWER%</b> - <?php _e('Display the poll\'s answer'); ?></td>
241
+ </tr>
242
+ <tr>
243
+ <td><b>%POLL_TOTALVOTES%</b> - <?php _e('Display the poll\'s total votes'); ?></td>
244
+ <td><b>%POLL_ANSWER_VOTES%</b> - <?php _e('Display the poll\'s answer votes'); ?></td>
245
+ </tr>
246
+ <tr>
247
+ <td><b>%POLL_RESULT_URL%</b> - <?php _e('Displays URL to poll\'s result'); ?></td>
248
+ <td><b>%POLL_ANSWER_PERCENTAGE%</b> - <?php _e('Display the poll\'s answer percentage'); ?></td>
249
+ </tr>
250
+ <tr>
251
+ <td>&nbsp;</td>
252
+ <td><b>"%POLL_ANSWER_IMAGEWIDTH%</b> - <?php _e('Display the poll\'s answer image width'); ?></td>
253
+ </tr>
254
+ </table>
255
+ </fieldset>
256
+ <fieldset class="options">
257
+ <legend><?php _e('Poll Voting Form Templates'); ?></legend>
258
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
259
+ <tr valign="top">
260
+ <td width="30%" align="left">
261
+ <b><?php _e('Voting Form Header:'); ?></b><br /><br /><br />
262
+ <?php _e('Allowed Variables:'); ?><br />
263
+ - %POLL_ID%<br />
264
+ - %POLL_QUESTION%<br />
265
+ - %POLL_TOTALVOTES%<br /><br />
266
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('voteheader');" class="button" />
267
+ </td>
268
+ <td width="70%" align="right"><textarea cols="60" rows="10" id="poll_template_voteheader" name="poll_template_voteheader"><?php echo stripslashes(get_settings('poll_template_voteheader')); ?></textarea></td>
269
+ </tr>
270
+ <tr valign="top">
271
+ <td width="30%" align="left">
272
+ <b><?php _e('Voting Form Body:'); ?></b><br /><br /><br />
273
+ <?php _e('Allowed Variables:'); ?><br />
274
+ - %POLL_ID%<br />
275
+ - %POLL_ANSWER_ID%<br />
276
+ - %POLL_ANSWER%<br />
277
+ - %POLL_ANSWER_VOTES%<br /><br />
278
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('votebody');" class="button" />
279
+ </td>
280
+ <td width="70%" align="right"><textarea cols="60" rows="10" id="poll_template_votebody" name="poll_template_votebody"><?php echo stripslashes(get_settings('poll_template_votebody')); ?></textarea></td>
281
+ </tr>
282
+ <tr valign="top">
283
+ <td width="30%" align="left">
284
+ <b><?php _e('Voting Form Footer:'); ?></b><br /><br /><br />
285
+ <?php _e('Allowed Variables:'); ?><br />
286
+ - %POLL_RESULT_URL%<br /><br />
287
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('votefooter');" class="button" />
288
+ </td>
289
+ <td width="70%" align="right"><textarea cols="60" rows="10" id="poll_template_votefooter" name="poll_template_votefooter"><?php echo stripslashes(get_settings('poll_template_votefooter')); ?></textarea></td>
290
+ </tr>
291
+ </table>
292
+ </fieldset>
293
+ <fieldset class="options">
294
+ <legend><?php _e('Poll Result Templates'); ?></legend>
295
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
296
+ <tr valign="top">
297
+ <td width="30%" align="left">
298
+ <b><?php _e('Result Header:'); ?></b><br /><br /><br />
299
+ <?php _e('Allowed Variables:'); ?><br />
300
+ - %POLL_ID%<br />
301
+ - %POLL_QUESTION%<br />
302
+ - %POLL_TOTALVOTES%<br /><br />
303
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultheader');" class="button" />
304
+ </td>
305
+ <td width="70%" align="right"><textarea cols="60" rows="10" id="poll_template_resultheader" name="poll_template_resultheader"><?php echo stripslashes(get_settings('poll_template_resultheader')); ?></textarea></td>
306
+ </tr>
307
+ <tr valign="top">
308
+ <td width="30%" align="left">
309
+ <b><?php _e('Result Body:'); ?></b><br /><?php _e('Normal'); ?><br /><br />
310
+ <?php _e('Allowed Variables:'); ?><br />
311
+ - %POLL_ANSWER_ID%<br />
312
+ - %POLL_ANSWER%<br />
313
+ - %POLL_ANSWER_VOTES%<br />
314
+ - %POLL_ANSWER_PERCENTAGE%<br />
315
+ - %POLL_ANSWER_IMAGEWIDTH%<br /><br />
316
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultbody');" class="button" />
317
+ </td>
318
+ <td width="70%" align="right"><textarea cols="60" rows="10" id="poll_template_resultbody" name="poll_template_resultbody"><?php echo stripslashes(get_settings('poll_template_resultbody')); ?></textarea></td>
319
+ </tr>
320
+ <tr valign="top">
321
+ <td width="30%" align="left">
322
+ <b><?php _e('Result Body:'); ?></b><br /><?php _e('Displaying Of User\'s Voted Answer'); ?><br /><br />
323
+ <?php _e('Allowed Variables:'); ?><br />
324
+ - %POLL_ANSWER_ID%<br />
325
+ - %POLL_ANSWER%<br />
326
+ - %POLL_ANSWER_VOTES%<br />
327
+ - %POLL_ANSWER_PERCENTAGE%<br />
328
+ - %POLL_ANSWER_IMAGEWIDTH%<br /><br />
329
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultbody2');" class="button" />
330
+ </td>
331
+ <td width="70%" align="right"><textarea cols="60" rows="10" id="poll_template_resultbody2" name="poll_template_resultbody2"><?php echo stripslashes(get_settings('poll_template_resultbody2')); ?></textarea></td>
332
+ </tr>
333
+ <tr valign="top">
334
+ <td width="30%" align="left">
335
+ <b><?php _e('Result Footer:'); ?></b><br /><br /><br />
336
+ <?php _e('Allowed Variables:'); ?><br />
337
+ - %POLL_TOTALVOTES%<br /><br />
338
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultfooter');" class="button" />
339
+ </td>
340
+ <td width="70%" align="right"><textarea cols="60" rows="10" id="poll_template_resultfooter" name="poll_template_resultfooter"><?php echo stripslashes(get_settings('poll_template_resultfooter')); ?></textarea></td>
341
+ </tr>
342
+ </table>
343
+ </fieldset>
344
+ <fieldset class="options">
345
+ <legend><?php _e('Poll Misc Templates'); ?></legend>
346
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
347
+ <tr valign="top">
348
+ <td width="30%" align="left">
349
+ <b><?php _e('Poll Disabled'); ?></b><br /><br /><br />
350
+ <?php _e('Allowed Variables:'); ?><br />
351
+ - N/A<br /><br />
352
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('disable');" class="button" />
353
+ </td>
354
+ <td width="70%" align="right"><textarea cols="60" rows="10" id="poll_template_disable" name="poll_template_disable"><?php echo stripslashes(get_settings('poll_template_disable')); ?></textarea></td>
355
+ </tr>
356
+ <tr valign="top">
357
+ <td width="30%" align="left">
358
+ <b><?php _e('Poll Error'); ?></b><br /><br /><br />
359
+ <?php _e('Allowed Variables:'); ?><br />
360
+ - N/A<br /><br />
361
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('error');" class="button" />
362
+ </td>
363
+ <td width="70%" align="right"><textarea cols="60" rows="10" id="poll_template_error" name="poll_template_error"><?php echo stripslashes(get_settings('poll_template_error')); ?></textarea></td>
364
+ </tr>
365
+ </table>
366
+ </fieldset>
367
+ <p class="submit">
368
+ <input type="submit" name="Submit" value="<?php _e('Update Options'); ?> &raquo;" />
369
+ </p>
370
+ </form>
371
+ </div>
372
+ <?php include('./admin-footer.php') ?>
polls-upgrade-202.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.04 |
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
+ | - Upgrade WP-Polls From 2.0x To 2.04 |
14
+ | - wp-admin/polls-upgrade-202.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Config
21
+ require('../wp-config.php');
22
+
23
+ ### Variables, Variables, Variables
24
+ $alter_table = array();
25
+ $insert_options = array();
26
+ $update_options = array();
27
+ $error = '';
28
+
29
+ ### Alter Tables (1 Table)
30
+ $alter_table[] = "ALTER TABLE $wpdb->pollsip ADD pollip_host VARCHAR(200) NOT NULL AFTER pollip_ip;";
31
+
32
+ ### Insert Options (1 Row)
33
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_error', 'Y', '1', 'An error has occurred when processing your poll.', '20', '8', 'Template For Poll When An Error Has Occured', '1', 'yes');";
34
+
35
+ ### Update Options (1 Row)
36
+ $update_options[] = "UPDATE $wpdb->options SET autoload = 'no' WHERE option_name = 'poll_archive_perpage'";
37
+
38
+ ### Total IPs Needed To Be Resolved
39
+ $ip_totalcount = $wpdb->get_var("SELECT COUNT(pollip_id) FROM $wpdb->pollsip WHERE pollip_ip != ''");
40
+
41
+ ### Check Whether There Is Any Pre Errors
42
+ $wpdb->show_errors = false;
43
+ $check_upgrade = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'poll_template_error'");
44
+ if($check_upgrade) {
45
+ $error = __('You Had Already Installed WP-Polls.');
46
+ }
47
+ if(empty($wpdb->pollsq) || empty($wpdb->pollsa) || empty($wpdb->pollsip)) {
48
+ $error = __('Please Define The pollsq, pollsa and pollsip tables in wp-settings.php.');
49
+ }
50
+ ?>
51
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
52
+ <html xmlns="http://www.w3.org/1999/xhtml">
53
+ <head>
54
+ <title>WordPress &rsaquo; <?php _e('Upgrading'); ?> &rsaquo; <?php _e('WP-Polls 2.04'); ?></title>
55
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
56
+ <style type="text/css" media="screen">
57
+ @import url( wp-admin.css );
58
+ </style>
59
+ </head>
60
+ <body>
61
+ <div class="wrap">
62
+ <h2><?php _e('Upgrading WP-Polls 2.04'); ?></h2>
63
+ <p><?php _e('This upgrade script will upgrade WP-Polls from version 2.00 or 2.01 to version 2.04 for your Wordpress.'); ?></p>
64
+ <p>
65
+ <?php _e('This upgrade script will be doing the following:'); ?><br />
66
+ <b>&raquo;</b> <b>1</b> <?php _e('table will be altered namely <b>pollsip</b>.'); ?><br />
67
+ <b>&raquo;</b> <b>1</b> <?php _e('option will be inserted into the <b>options</b> table.'); ?><br />
68
+ <b>&raquo;</b> <b>1</b> <?php _e('option will be updated from <b>options</b> table.'); ?><br />
69
+ <b>&raquo;</b> <b><?php echo $ip_totalcount; ?></b> <?php _e('IPs will be resolved and updated.'); ?><br />
70
+ <b>&raquo;</b> <b>4</b> <?php _e('tables will be optimized namely <b>pollsq</b>, <b>pollsa</b>, <b>pollsip</b> and <b>options</b>.'); ?><br />
71
+ </p>
72
+ <?php
73
+ if(empty($error)) {
74
+ if(!empty($_POST['upgrade'])) {
75
+ // Alter Table
76
+ $alter_table_count = 0;
77
+ echo "<p><b>".__('Altering Tables:')."</b>";
78
+ foreach($alter_table as $altertable) {
79
+ $wpdb->query($altertable);
80
+ }
81
+ $check_pollsip = $wpdb->get_var("SELECT pollip_id FROM $wpdb->pollsip WHERE pollip_host = '' LIMIT 1");
82
+ if($check_pollsip) {
83
+ echo "<br /><b>&raquo;</b> Table (<b>$wpdb->pollsa</b>) altered.";
84
+ $alter_table_count++;
85
+ } else {
86
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Table (<b>$wpdb->pollsip</b>) table NOT altered.</font>";
87
+ }
88
+ echo "<br /><b>&raquo;</b> <b>$alter_table_count / 1</b> Table Altered.</p>";
89
+ // Insert Options
90
+ $insert_options_count = 0;
91
+ echo "<p><b>".__('Inserting Options:')."</b>";
92
+ foreach($insert_options as $insertoptions) {
93
+ $temp_options = $wpdb->query($insertoptions);
94
+ $temp_option = explode(" ", $insertoptions);
95
+ $temp_option = $temp_option[6];
96
+ $temp_option = substr($temp_option, 1, -2);
97
+ if($temp_options) {
98
+ echo "<br /><b>&raquo;</b> Option (<b>$temp_option</b>) inserted.";
99
+ $insert_options_count++;
100
+ } else {
101
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Option (<b>$temp_option</b>) NOT inserted.</font>";
102
+ }
103
+ }
104
+ echo "<br /><b>&raquo;</b> <b>$insert_options_count / 1</b> Option Inserted.</p>";
105
+ // Update Options
106
+ $update_options_count = 0;
107
+ echo "<p><b>".__('Updating Options:')."</b>";
108
+ foreach($update_options as $updateoptions) {
109
+ $temp_options = $wpdb->query($updateoptions);
110
+ $temp_option = explode("=", $updateoptions);
111
+ $temp_option = $temp_option[2];
112
+ $temp_option = substr($temp_option, 2, -1);
113
+ if($temp_options) {
114
+ echo "<br /><b>&raquo;</b> Option (<b>$temp_option</b>) updated.";
115
+ $update_options_count++;
116
+ } else {
117
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Option (<b>$temp_option</b>) NOT updated.</font>";
118
+ }
119
+ }
120
+ echo "<br /><b>&raquo;</b> <b>$update_options_count / 1</b> Option Updated.</p>";
121
+ // Resolve IPs
122
+ $ip_count = 0;
123
+ echo "<p><b>".__('Resolving IPs:')."</b>";
124
+ $ips_data = $wpdb->get_results("SELECT pollip_id, pollip_ip FROM $wpdb->pollsip WHERE pollip_ip != ''");
125
+ if($ips_data) {
126
+ foreach($ips_data as $ip_data) {
127
+ $pollip_id = intval($ip_data->pollip_id);
128
+ $pollip_host = gethostbyaddr($ip_data->pollip_ip);
129
+ $update_ip = $wpdb->query("UPDATE $wpdb->pollsip SET pollip_host = '$pollip_host' WHERE pollip_id = $pollip_id");
130
+ if($update_ip) {
131
+ echo "<br /><b>&raquo;</b> IP (<b>$ip_data->pollip_ip</b>) resolved.";
132
+ $ip_count++;
133
+ } else {
134
+ echo "<br /><b>&raquo;</b> <font color=\"red\">IP (<b>$ip_data->pollip_ip</b>) NOT resolved.</font>";
135
+ }
136
+ }
137
+ } else {
138
+ echo "<br /><b>&raquo;</b> There are no IP to be resolved.";
139
+ }
140
+ echo "<br /><b>&raquo;</b> <b>$ip_count / $ip_totalcount</b> IPs Resolved.</p>";
141
+ // Optimize Tables
142
+ $optimize_table_count = 0;
143
+ echo "<p><b>".__('Optimizing Tables:')."</b>";
144
+ $optimize_tables = $wpdb->query("OPTIMIZE TABLE $wpdb->pollsq, $wpdb->pollsa, $wpdb->pollsip, $wpdb->options");
145
+ if($optimize_tables) {
146
+ echo "<br /><b>&raquo;</b> Tables (<b>$wpdb->pollsq</b>, <b>$wpdb->pollsa</b>, <b>$wpdb->pollsip</b>, <b>$wpdb->options</b>) optimized.";
147
+ $optimize_table_count = 4;
148
+ } else {
149
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Tables (<b>$wpdb->pollsq</b>, <b>$wpdb->pollsa</b>, <b>$wpdb->pollsip</b>, <b>$wpdb->options</b>) NOT optimized.</font>";
150
+ }
151
+ echo "<br /><b>&raquo;</b> <b>$optimize_table_count / 4</b> Tables Optimized.</p>";
152
+ // Check Whether Install Is Successful
153
+ if($alter_table_count == 1 && $insert_options_count == 1) {
154
+ echo '<p align="center"><b>'.__('WP-Polls Upgraded Successfully To Version 2.04.').'</b><br />'.__('Please remember to delete this file before proceeding on.').'</p>';
155
+ }
156
+ } else {
157
+ ?>
158
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
159
+ <div align="center"><?php _e('It may take some time for all the ips to be resolved.'); ?><br /><input type="submit" name="upgrade" value="<?php _e('Click Here To Upgrade WP-Polls 2.04'); ?>" class="button"></div>
160
+ </form>
161
+ <?php
162
+ }
163
+ } else {
164
+ echo "<p align=\"center\"><font color=\"red\"><b>$error</b></font></p>\n";
165
+ }
166
+ ?>
167
+ </div>
168
+ </body>
169
+ </html>
polls-upgrade.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.04 |
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
+ | - Upgrade WP-Polls From 1.0x To 2.04 |
14
+ | - wp-admin/polls-upgrade.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Config
21
+ require('../wp-config.php');
22
+
23
+ ### Variables, Variables, Variables
24
+ $create_table = array();
25
+ $alter_table = array();
26
+ $insert_options = array();
27
+ $error = '';
28
+
29
+ ### Create Tables (1 Table)
30
+ $create_table[] = "CREATE TABLE $wpdb->pollsip (".
31
+ "pollip_id int(10) NOT NULL auto_increment,".
32
+ "pollip_qid varchar(10) NOT NULL default '',".
33
+ "pollip_aid varchar(10) NOT NULL default '',".
34
+ "pollip_ip varchar(100) NOT NULL default '',".
35
+ "pollip_host VARCHAR(200) NOT NULL default '',".
36
+ "pollip_timestamp varchar(20) NOT NULL default '0000-00-00 00:00:00',".
37
+ "pollip_user tinytext NOT NULL,".
38
+ "PRIMARY KEY (pollip_id))";
39
+
40
+ ### Alter Tables (2 Tables)
41
+ $alter_table[] = "ALTER TABLE $wpdb->pollsq CHANGE id pollq_id INT(10) NULL AUTO_INCREMENT ,".
42
+ "CHANGE question pollq_question VARCHAR(200) NOT NULL ,".
43
+ "CHANGE timestamp pollq_timestamp VARCHAR(20) NOT NULL ,".
44
+ "CHANGE total_votes pollq_totalvotes INT(10) DEFAULT '0' NOT NULL";
45
+ $alter_table[] = "ALTER TABLE $wpdb->pollsa CHANGE aid polla_aid INT(10) NOT NULL AUTO_INCREMENT ,".
46
+ "CHANGE qid polla_qid INT(10) DEFAULT '0' NOT NULL ,".
47
+ "CHANGE answers polla_answers VARCHAR( 200 ) NOT NULL ,".
48
+ "CHANGE votes polla_votes INT(10) DEFAULT '0' NOT NULL";
49
+
50
+ ### Get Lastest Poll ID
51
+ $poll_latest_id = $wpdb->get_var("SELECT id FROM $wpdb->pollsq ORDER BY id DESC LIMIT 1");
52
+ if(intval($poll_latest_id) < 1) { $poll_latest_id = 1; }
53
+
54
+ ### Insert Options (16 Rows)
55
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_voteheader', 'Y', 1, '<table width=\\\"100%\\\" border=\\\"0\\\" cellspacing=\\\"3\\\" cellpadding=\\\"3\\\">\r\n<tr>\r\n<td align=\\\"center\\\"><b>%POLL_QUESTION%</b></td>\r\n</tr>', 20, 8, 'Template For Poll''s Question', 1, 'yes');";
56
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_votebody', 'Y', 1, '<tr>\r\n<td align=\\\"left\\\"><input type=\\\"radio\\\" name=\\\"poll-%POLL_ID%\\\" value=\\\"%POLL_ANSWER_ID%\\\" /> %POLL_ANSWER%</td>\r\n</tr>', 20, 8, 'Template For Poll''s Answers', 1, 'yes');";
57
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_votefooter', 'Y', 1, '<tr>\r\n<td align=\\\"center\\\"><input type=\\\"submit\\\" name=\\\"vote\\\" value=\\\" Vote \\\" class=\\\"Buttons\\\" /><br /><a href=\\\"%POLL_RESULT_URL%\\\">View Results</a></td>\r\n</tr>\r\n</table>', 20, 8, 'Template For Poll''s Voting Footer', 1, 'yes');";
58
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_resultheader', 'Y', 1, '<table width=\\\"100%\\\" border=\\\"0\\\" cellspacing=\\\"3\\\" cellpadding=\\\"3\\\">\r\n<tr>\r\n<td colspan=\\\"2\\\" align=\\\"center\\\"><b>%POLL_QUESTION%</b></td>\r\n</tr>', 20, 8, '', 1, 'yes');";
59
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_resultbody', 'Y', 1, '<tr>\r\n<td align=\\\"left\\\" width=\\\"70%\\\">%POLL_ANSWER%<br /><img src=\\\"".get_settings('home')."/wp-includes/images/pollbar.gif\\\" height=\\\"5\\\" width=\\\"%POLL_ANSWER_IMAGEWIDTH%\\\" alt=\\\"%POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)\\\" /></td>\r\n<td align=\\\"right\\\" width=\\\"30%\\\"><b>%POLL_ANSWER_PERCENTAGE%%</b></td>\r\n</tr>', 20, 8, '', 1, 'yes');";
60
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_resultbody2', 'Y', 1, '<tr>\r\n<td align=\\\"left\\\" width=\\\"70%\\\"><i>%POLL_ANSWER%</i><br /><img src=\\\"".get_settings('home')."/wp-includes/images/pollbar.gif\\\" height=\\\"5\\\" width=\\\"%POLL_ANSWER_IMAGEWIDTH%\\\" alt=\\\"You Have Voted For This Choice - %POLL_ANSWER% -> %POLL_ANSWER_PERCENTAGE%% (%POLL_ANSWER_VOTES% Votes)\\\" /></td>\r\n<td align=\\\"right\\\" width=\\\"30%\\\"><i><b>%POLL_ANSWER_PERCENTAGE%%</b></i></td>\r\n</tr>', 20, 8, '', 1, 'yes');";
61
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_resultfooter', 'Y', 1, '<tr>\r\n<td colspan=\\\"2\\\" align=\\\"center\\\">Total Votes: <b>%POLL_TOTALVOTES%</b><td>\r\n</tr>\r\n</table>', 20, 8, '', 1, 'yes');";
62
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_disable', 'Y', 1, 'Sorry, there are no polls available at the moment.', 20, 8, 'Template For Poll When It Is Disabled', 1, 'yes');";
63
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_template_error', 'Y', 1, 'An error has occurred when processing your poll.', '20', '8', 'Template For Poll When An Error Has Occured', 1, 'yes');";
64
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_currentpoll', 'Y', 1, '0', 20, 8, 'Current Displayed Poll', 1, 'yes');";
65
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_latestpoll', 'Y', 1, '$poll_latest_id', 20, 8, 'The Lastest Poll', 1, 'yes');";
66
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_archive_perpage', 'Y', 1, '10', 2, 8, 'Number Of Polls To Display Per Page On The Poll''s Archive', 1, 'no');";
67
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_ans_sortby', 'Y', 1, 'polla_aid', 20, 8, 'Sorting Of Poll''s Answers', 1, 'yes');";
68
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_ans_sortorder', 'Y', 1, 'asc', 20, 8, 'Sort Order Of Poll''s Answers', 1, 'yes');";
69
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_ans_result_sortby', 'Y', 1, 'polla_votes', 20, 8, 'Sorting Of Poll''s Answers Result', 1, 'yes');";
70
+ $insert_options[] ="INSERT INTO $wpdb->options VALUES (0, 0, 'poll_ans_result_sortorder', 'Y', 1, 'desc', 20, 8, 'Sorting Order Of Poll''s Answers Result', 1, 'yes');";
71
+
72
+ ### Check Whether There Is Any Pre Errors
73
+ $wpdb->show_errors = false;
74
+ $check_upgrade = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'poll_latestpoll'");
75
+ if($check_upgrade) {
76
+ $error = __('You Had Already Installed WP-Polls.');
77
+ }
78
+ if(empty($wpdb->pollsq) || empty($wpdb->pollsa) || empty($wpdb->pollsip)) {
79
+ $error = __('Please Define The pollsq, pollsa and pollsip tables in wp-settings.php.');
80
+ }
81
+ ?>
82
+
83
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
84
+ <html xmlns="http://www.w3.org/1999/xhtml">
85
+ <head>
86
+ <title>WordPress &rsaquo; <?php _e('Upgrading'); ?> &rsaquo; <?php _e('WP-Polls 2.04'); ?></title>
87
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
88
+ <style type="text/css" media="screen">
89
+ @import url( wp-admin.css );
90
+ </style>
91
+ </head>
92
+ <body>
93
+ <div class="wrap">
94
+ <h2><?php _e('Upgrading WP-Polls 2.04'); ?></h2>
95
+ <p><?php _e('This upgrade script will upgrade WP-Polls to version 2.04 for your Wordpress.'); ?></p>
96
+ <p>
97
+ <?php _e('This upgrade script will be doing the following:'); ?><br />
98
+ <b>&raquo;</b> <b>1</b> <?php _e('table will be created namely <b>pollsip</b>.'); ?><br />
99
+ <b>&raquo;</b> <b>2</b> <?php _e('tables will be altered namely <b>pollsq</b> and <b>pollsa</b>.'); ?><br />
100
+ <b>&raquo;</b> <b>15</b> <?php _e('options will be inserted into the <b>options</b> table.'); ?><br />
101
+ <b>&raquo;</b> <b>4</b> <?php _e('tables will be optimized namely <b>pollsq</b>, <b>pollsa</b>, <b>pollsip</b> and <b>options</b>.'); ?><br />
102
+ </p>
103
+ <?php
104
+ if(empty($error)) {
105
+ if(!empty($_POST['upgrade'])) {
106
+ // Create Tables
107
+ $create_table_count = 0;
108
+ echo "<p><b>".__('Creating Tables:')."</b>";
109
+ foreach($create_table as $createtable) {
110
+ $wpdb->query($createtable);
111
+ }
112
+ $check_pollsip = $wpdb->query("SHOW COLUMNS FROM $wpdb->pollsip");
113
+ if($check_pollsip) {
114
+ echo "<br /><b>&raquo;</b> Table (<b>$wpdb->pollsip</b>) created.";
115
+ $create_table_count++;
116
+ } else {
117
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Table (<b>$wpdb->pollsip</b>) table NOT created.</font>";
118
+ }
119
+ echo "<br /><b>&raquo;</b> <b>$create_table_count / 1</b> Table Created.</p>";
120
+ // Alter Table
121
+ $alter_table_count = 0;
122
+ echo "<p><b>".__('Altering Tables:')."</b>";
123
+ foreach($alter_table as $altertable) {
124
+ $wpdb->query($altertable);
125
+ }
126
+ $check_pollsq = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq LIMIT 1");
127
+ $check_pollsa = $wpdb->get_var("SELECT polla_aid FROM $wpdb->pollsa LIMIT 1");
128
+ if($check_pollsq) {
129
+ echo "<br /><b>&raquo;</b> Table (<b>$wpdb->pollsq</b>) altered.";
130
+ $alter_table_count++;
131
+ } else {
132
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Table (<b>$wpdb->pollsip</b>) table NOT altered.</font>";
133
+ }
134
+ if($check_pollsa) {
135
+ echo "<br /><b>&raquo;</b> Table (<b>$wpdb->pollsa</b>) altered.";
136
+ $alter_table_count++;
137
+ } else {
138
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Table (<b>$wpdb->pollsip</b>) table NOT altered.</font>";
139
+ }
140
+ echo "<br /><b>&raquo;</b> <b>$alter_table_count / 2</b> Tables Altered.</p>";
141
+ // Insert Options
142
+ $insert_options_count = 0;
143
+ echo "<p><b>".__('Inserting Options:')."</b>";
144
+ foreach($insert_options as $insertoptions) {
145
+ $temp_options = $wpdb->query($insertoptions);
146
+ $temp_option = explode(" ", $insertoptions);
147
+ $temp_option = $temp_option[6];
148
+ $temp_option = substr($temp_option, 1, -2);
149
+ if($temp_options) {
150
+ echo "<br /><b>&raquo;</b> Option (<b>$temp_option</b>) inserted.";
151
+ $insert_options_count ++;
152
+ } else {
153
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Option (<b>$temp_option</b>) NOT inserted.</font>";
154
+ }
155
+ }
156
+ echo "<br /><b>&raquo;</b> <b>$insert_options_count / 16</b> Options Inserted.</p>";
157
+ // Optimize Tables
158
+ $optimize_table_count = 0;
159
+ echo "<p><b>".__('Optimizing Tables:')."</b>";
160
+ $optimize_tables = $wpdb->query("OPTIMIZE TABLE $wpdb->pollsq, $wpdb->pollsa, $wpdb->pollsip, $wpdb->options");
161
+ if($optimize_tables) {
162
+ echo "<br /><b>&raquo;</b> Tables (<b>$wpdb->pollsq</b>, <b>$wpdb->pollsa</b>, <b>$wpdb->pollsip</b>, <b>$wpdb->options</b>) optimized.";
163
+ $optimize_table_count = 4;
164
+ } else {
165
+ echo "<br /><b>&raquo;</b> <font color=\"red\">Tables (<b>$wpdb->pollsq</b>, <b>$wpdb->pollsa</b>, <b>$wpdb->pollsip</b>, <b>$wpdb->options</b>) NOT optimized.</font>";
166
+ }
167
+ echo "<br /><b>&raquo;</b> <b>$optimize_table_count / 4</b> Tables Optimized.</p>";
168
+ // Check Whether Install Is Successful
169
+ if($create_table_count == 1 && $alter_table_count == 2 && $insert_options_count == 16) {
170
+ echo '<p align="center"><b>'.__('WP-Polls Upgraded Successfully To Version 2.04.').'</b><br />'.__('Please remember to delete this file before proceeding on.').'</p>';
171
+ }
172
+ } else {
173
+ ?>
174
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
175
+ <div align="center"><input type="submit" name="upgrade" value="<?php _e('Click Here To Upgrade WP-Polls 2.04'); ?>" class="button"></div>
176
+ </form>
177
+ <?php
178
+ }
179
+ } else {
180
+ echo "<p align=\"center\"><font color=\"red\"><b>$error</b></font></p>\n";
181
+ }
182
+ ?>
183
+ </div>
184
+ </body>
185
+ </html>
polls.php ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.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
+ } // End if($vote_a)
286
+ } // End if($vote_ip)
287
+ } // End if($vote_cookie)
288
+ }// End if($voted_ip == 0 && $voted_cookie == 0)
289
+ } // End if(!empty($_POST['vote']))
290
+ } // End if($poll_id > 0 && $poll_aid > 0)
291
+ }
292
+
293
+
294
+ ### Function: Get IP Address
295
+ function get_ipaddress() {
296
+ if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
297
+ $ip_address = $_SERVER["REMOTE_ADDR"];
298
+ } else {
299
+ $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
300
+ }
301
+ if(strpos($ip_address, ',') !== false) {
302
+ $ip_address = explode(',', $ip_address);
303
+ $ip_address = $ip_address[0];
304
+ }
305
+ return $ip_address;
306
+ }
307
+
308
+
309
+ ### Function: Place Poll In Content (By: Robert Accettura Of http://robert.accettura.com/)
310
+ add_filter('the_content', 'place_poll', '12');
311
+ function place_poll($content){
312
+ $content = preg_replace( "/\[poll=(\d+)\]/ise", "display_poll('\\1')", $content);
313
+ return $content;
314
+ }
315
+
316
+
317
+ ### Function: Display The Poll In Content (By: Robert Accettura Of http://robert.accettura.com/)
318
+ function display_poll($poll_id, $display_pollarchive = true){
319
+ if (function_exists('vote_poll')){
320
+ if($display_pollarchive) {
321
+ return get_poll($poll_id)."\n".'<p><a href="'.get_settings('home').'/wp-polls.php">Polls Archive</a></p>';
322
+ } else {
323
+ return get_poll($poll_id);
324
+ }
325
+ }
326
+ }
327
+ ?>
readme-install.txt ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Installation Instructions
2
+ ------------------------------------------------------------------
3
+ // Open wp-admin folder
4
+
5
+ Put:
6
+ ------------------------------------------------------------------
7
+ polls-install.php
8
+ polls-manager.php
9
+ polls-options.php
10
+ ------------------------------------------------------------------
11
+
12
+
13
+ // Open wp-content/plugins folder
14
+
15
+ Put:
16
+ ------------------------------------------------------------------
17
+ polls.php
18
+ ------------------------------------------------------------------
19
+
20
+ // Open Wordpress root folder
21
+
22
+ Put:
23
+ ------------------------------------------------------------------
24
+ wp-polls.php
25
+ ------------------------------------------------------------------
26
+
27
+
28
+ // Open wp-includes/images folder
29
+
30
+ Put:
31
+ ------------------------------------------------------------------
32
+ pollbar.gif
33
+ ------------------------------------------------------------------
34
+
35
+
36
+ // Activate the polls plugin
37
+
38
+
39
+ // Run wp-admin/polls-install.php
40
+
41
+ Note:
42
+ ------------------------------------------------------------------
43
+ Please remember to remove polls-install.php after installation.
44
+ ------------------------------------------------------------------
45
+
46
+
47
+ // Open wp-content/themes/<YOUR THEME NAME>/sidebar.php
48
+
49
+ Add:
50
+ ------------------------------------------------------------------
51
+ <?php if (function_exists('vote_poll')): ?>
52
+ <li>
53
+ <h2>Polls</h2>
54
+ <ul>
55
+ <?php get_poll();?>
56
+ <li><a href="<?php echo get_settings('home'); ?>/wp-polls.php">Polls Archive</a></li>
57
+ </ul>
58
+ </li>
59
+ <?php endif; ?>
60
+ ------------------------------------------------------------------
61
+
62
+ Note:
63
+ ------------------------------------------------------------------
64
+ To show specific poll, use <?php get_poll(<ID>);?> where <ID> is your poll id.
65
+ To embed a specific poll in your post, use [poll=<ID>] where <ID> is your poll id.
66
+ ------------------------------------------------------------------
readme-upgrade.txt ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Upgrade Instructions For Version 2.03 To Version 2.04
2
+ ------------------------------------------------------------------
3
+ // Open wp-admin folder
4
+
5
+ Overwrite:
6
+ ------------------------------------------------------------------
7
+ polls-manager.php
8
+ polls-options.php
9
+ ------------------------------------------------------------------
10
+
11
+
12
+ // Open wp-content/plugins folder
13
+
14
+ Overwrite:
15
+ ------------------------------------------------------------------
16
+ polls.php
17
+ ------------------------------------------------------------------
18
+
19
+
20
+ // Open Wordpress root folder
21
+
22
+ Overwrite:
23
+ ------------------------------------------------------------------
24
+ wp-polls.php
25
+ ------------------------------------------------------------------
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+ -> Upgrade Instructions For Version 2.02 To Version 2.03
37
+ ------------------------------------------------------------------
38
+ // Open wp-admin folder
39
+
40
+ Overwrite:
41
+ ------------------------------------------------------------------
42
+ polls-manager.php
43
+ polls-options.php
44
+ ------------------------------------------------------------------
45
+
46
+
47
+ // Open wp-content/plugins folder
48
+
49
+ Overwrite:
50
+ ------------------------------------------------------------------
51
+ polls.php
52
+ ------------------------------------------------------------------
53
+
54
+
55
+ // Open Wordpress root folder
56
+
57
+ Overwrite:
58
+ ------------------------------------------------------------------
59
+ wp-polls.php
60
+ ------------------------------------------------------------------
61
+
62
+
63
+ // Open wp-includes/images folder
64
+
65
+ Put:
66
+ ------------------------------------------------------------------
67
+ pollbar.gif
68
+ ------------------------------------------------------------------
69
+
70
+
71
+ // Remove Previous Traces Of Poll Code In Your Theme
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ -> Upgrade Instructions FOr Version 2.01 To Version 2.02
80
+ ------------------------------------------------------------------
81
+ // Open wp-admin folder
82
+
83
+ Put:
84
+ ------------------------------------------------------------------
85
+ polls-upgrade-202.php
86
+ ------------------------------------------------------------------
87
+
88
+ // Run wp-admin/polls-upgrade-202.php
89
+
90
+ Note:
91
+ ------------------------------------------------------------------
92
+ Please remember to remove polls-upgrade-202.php after installation.
93
+ ------------------------------------------------------------------
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+ -> Upgrade Instructions For Version 1.0x To Version 2.01
105
+ ------------------------------------------------------------------
106
+ // Open wp-admin folder
107
+
108
+ Put/Overwrite:
109
+ ------------------------------------------------------------------
110
+ polls-upgrade.php
111
+ polls-manager.php
112
+ polls-options.php
113
+ ------------------------------------------------------------------
114
+
115
+
116
+ // Open wp-content/plugins folder
117
+
118
+ Put/Overwrite:
119
+ ------------------------------------------------------------------
120
+ polls.php
121
+ ------------------------------------------------------------------
122
+
123
+
124
+ // Open Wordpress root folder
125
+
126
+ Put/Overwrite:
127
+ ------------------------------------------------------------------
128
+ wp-polls.php
129
+ ------------------------------------------------------------------
130
+
131
+
132
+ // Open wp-includes/images folder
133
+
134
+ Put:
135
+ ------------------------------------------------------------------
136
+ pollbar.gif
137
+ ------------------------------------------------------------------
138
+
139
+
140
+ // Run wp-admin/polls-upgrade.php
141
+
142
+ Note:
143
+ ------------------------------------------------------------------
144
+ Please remember to remove polls-upgrade.php after installation.
145
+ ------------------------------------------------------------------
readme.txt ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 February 2006
10
+ --------------------------------------------------
11
+
12
+
13
+ // Version 2.04 (01-02-2006)
14
+ - NEW: Added 'manage_polls' Capabilities To Administrator Role
15
+ - NEW: [poll=POLL_ID] Tag To Insert Poll Into A Post
16
+ - NEW: Ability To Edit Poll's Timestamp
17
+ - NEW: Ability To Edit Individual Poll's Answer Votes
18
+ - NEW: %POLL_RESULT_URL% To Display Poll's Result URL
19
+ - FIXED: Cannot Sent Header Error
20
+
21
+ // Version 2.03 (01-01-2006)
22
+ - NEW: Compatible With WordPress 2.0 Only
23
+ - NEW: Poll Administration Menu Added Automatically Upon Activating The Plugin
24
+ - NEW: Removed Add Poll Link From The Administration Menu
25
+ - NEW: GPL License Added
26
+ - NEW: Page Title Added To wp-polls.php
27
+
28
+ // Version 2.02a (17-11-2005)
29
+ - FIXED: poll-install.php And poll-upgrade.php will Now Be Installed/Upgraded To 2.02 Instead Of 2.01
30
+
31
+ // Version 2.02 (05-11-2005)
32
+ - FIXED: Showing 0 Vote On Poll Edit Page
33
+ - FIXED: Null Vote Being Counted As A Vote
34
+ - FIXED: Auto Loading Of Poll Option: Polls Per Page In Poll Archive Page Is Now "No"
35
+ - NEW: Host Column In Poll IP Table To Prevent Network Lagging When Resolving IP
36
+ - NEW: New Poll Error Template
37
+
38
+ // Version 2.01 (25-10-2005)
39
+ - FIXED: Upgrade Script To Insert Lastest Poll ID Of User's Current Polls, Instead Of Poll ID 1
40
+ - FIXED: Replace All <?= With <?php
41
+ - FIXED: Added addalshes() To $pollip_user
42
+ - FIXED: Better Localization Support (80% Done, Will Leave It In The Mean Time)
43
+
44
+ // Version 2.0 (20-10-2005)
45
+ - NEW: IP Logging
46
+ - NEW: Poll Options: Sorting Of Answers In Voting Form
47
+ - NEW: Poll Options: Sorting Of Answers In Results View
48
+ - NEW: Poll Options: Number Of Polls Per Page In Poll Archive
49
+ - NEW: Poll Options: Choose Poll To Display On Index Page
50
+ - NEW: Poll Options: Able To Disable Poll With Custom Message
51
+ - NEW: Poll Options: Poll Templates
52
+ - NEW: Display User's Voted Choice
53
+ - FIXED: Better Install/Upgrade Script
wp-polls.php ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.04 |
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
+ // Current Poll ID Is Not Specified
72
+ if(intval(get_settings('poll_currentpoll')) == 0) {
73
+ // Get Lastest Poll ID
74
+ $poll_id = intval(get_settings('poll_latestpoll'));
75
+ } else {
76
+ // Get Current Poll ID
77
+ $poll_id = intval(get_settings('poll_currentpoll'));
78
+ }
79
+ // Get Hardcoded Poll ID
80
+ } else {
81
+ $poll_id = intval($temp_poll_id);
82
+ }
83
+ }
84
+
85
+ ### Get Poll Questions
86
+ $questions = $wpdb->get_results("SELECT * FROM $wpdb->pollsq WHERE pollq_id != $poll_id ORDER BY pollq_id DESC LIMIT $offset, $polls_perpage");
87
+ if($questions) {
88
+ foreach($questions as $question) {
89
+ $polls_questions[] = array('id' => intval($question->pollq_id), 'question' => stripslashes($question->pollq_question), 'timestamp' => $question->pollq_timestamp, 'totalvotes' => intval($question->pollq_totalvotes));
90
+ $poll_questions_ids .= intval($question->pollq_id).', ';
91
+ }
92
+ $poll_questions_ids = substr($poll_questions_ids, 0, -2);
93
+ }
94
+
95
+ ### Get Poll Answers
96
+ $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'));
97
+ if($answers) {
98
+ foreach($answers as $answer) {
99
+ $polls_answers[] = array('aid' => intval($answer->polla_aid), 'qid' => intval($answer->polla_qid), 'answers' => stripslashes($answer->polla_answers), 'votes' => intval($answer->polla_votes));
100
+ }
101
+ }
102
+
103
+ ### Get Poll IPs
104
+ $ips = $wpdb->get_results("SELECT pollip_qid, pollip_aid FROM $wpdb->pollsip WHERE pollip_qid IN ($poll_questions_ids) AND pollip_ip = '".get_ipaddress()."'");
105
+ if($ips) {
106
+ foreach($ips as $ip) {
107
+ $polls_ips[] = array('qid' => intval($ip->pollip_qid), 'aid' => intval($ip->pollip_aid));
108
+ }
109
+ }
110
+ ### Function: Check Voted To Get Voted Answer
111
+ function check_voted($poll_id) {
112
+ global $polls_ips;
113
+ $temp_voted_aid = 0;
114
+ if(intval($_COOKIE["voted_$poll_id"]) > 0) {
115
+ $temp_voted_aid = intval($_COOKIE["voted_$poll_id"]);
116
+ } else {
117
+ if($polls_ips) {
118
+ foreach($polls_ips as $polls_ip) {
119
+ if($polls_ip['qid'] == $poll_id) {
120
+ $temp_voted_aid = $polls_ip['aid'];
121
+ }
122
+ }
123
+ }
124
+ }
125
+ return $temp_voted_aid;
126
+ }
127
+ ?>
128
+ <?php get_header(); ?>
129
+ <div id="content" class="narrowcolumn">
130
+ <?php
131
+ if($page < 2) {
132
+ echo "<!-- <Currrent Poll> -->\n";
133
+ echo '<h2 class="pagetitle">'.__('Current Poll').'</h2>'."\n";
134
+ // Current Poll
135
+ if(intval(get_settings('poll_currentpoll')) == -1) {
136
+ echo get_settings('poll_template_disable');
137
+ } else {
138
+ // User Click on View Results Link
139
+ if(intval($_GET['pollresult']) == 1) {
140
+ display_pollresult($poll_id);
141
+ // Check Whether User Has Voted
142
+ } else {
143
+ // Check Cookie First
144
+ $voted_cookie = check_voted_cookie($poll_id);
145
+ if($voted_cookie > 0) {
146
+ display_pollresult($poll_id, $voted_cookie);
147
+ // Check IP If Cookie Cannot Be Found
148
+ } else {
149
+ $voted_ip = check_voted_ip($poll_id);
150
+ if($voted_ip > 0) {
151
+ display_pollresult($poll_id, $voted_ip);
152
+ // User Never Vote. Display Poll Voting Form
153
+ } else {
154
+ display_pollvote($poll_id);
155
+ }
156
+ }
157
+ }
158
+ }
159
+ echo "<!-- </Currrent Poll> -->\n";
160
+ }
161
+ ?>
162
+ <!-- <Poll Archives> -->
163
+ <h2 class="pagetitle"><?php _e('Polls Archive'); ?></h2>
164
+ <?php
165
+ foreach($polls_questions as $polls_question) {
166
+ // Is The Poll Total Votes 0?
167
+ $poll_totalvotes_zero = true;
168
+ if($polls_question['totalvotes'] > 0) {
169
+ $poll_totalvotes_zero = false;
170
+ }
171
+ // Poll Question Variables
172
+ $template_question = stripslashes(get_settings('poll_template_resultheader'));
173
+ $template_question = str_replace("%POLL_QUESTION%", $polls_question['question'], $template_question);
174
+ $template_question = str_replace("%POLL_ID%", $polls_question['id'], $template_question);
175
+ $template_question = str_replace("%POLL_TOTALVOTES%", $polls_question['totalvotes'], $template_question);
176
+ // Print Out Result Header Template
177
+ echo $template_question;
178
+ foreach($polls_answers as $polls_answer) {
179
+ if($polls_question['id'] == $polls_answer['qid']) {
180
+ // Calculate Percentage And Image Bar Width
181
+ if(!$poll_totalvotes_zero) {
182
+ if($polls_answer['votes'] > 0) {
183
+ $poll_answer_percentage = round((($polls_answer['votes']/$polls_question['totalvotes'])*100));
184
+ $poll_answer_imagewidth = round($poll_answer_percentage*0.9);
185
+ } else {
186
+ $poll_answer_percentage = 0;
187
+ $poll_answer_imagewidth = 1;
188
+ }
189
+ } else {
190
+ $poll_answer_percentage = 0;
191
+ $poll_answer_imagewidth = 1;
192
+ }
193
+ // Let User See What Options They Voted
194
+ if(check_voted($polls_question['id']) == $polls_answer['aid']) {
195
+ // Results Body Variables
196
+ $template_answer = stripslashes(get_settings('poll_template_resultbody2'));
197
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $polls_answer['aid'], $template_answer);
198
+ $template_answer = str_replace("%POLL_ANSWER%", $polls_answer['answers'], $template_answer);
199
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $polls_answer['votes'], $template_answer);
200
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
201
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
202
+ // Print Out Results Body Template
203
+ echo $template_answer;
204
+ } else {
205
+ // Results Body Variables
206
+ $template_answer = stripslashes(get_settings('poll_template_resultbody'));
207
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $polls_answer['aid'], $template_answer);
208
+ $template_answer = str_replace("%POLL_ANSWER%", $polls_answer['answers'], $template_answer);
209
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $polls_answer['votes'], $template_answer);
210
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
211
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
212
+ // Print Out Results Body Template
213
+ echo $template_answer;
214
+ }
215
+ // Delete Away From Array
216
+ unset($polls_answer['answers']);
217
+ }
218
+ }
219
+ // Results Footer Variables
220
+ $template_footer = stripslashes(get_settings('poll_template_resultfooter'));
221
+ $template_footer = str_replace("%POLL_TOTALVOTES%", $polls_question['totalvotes'], $template_footer);
222
+ // Print Out Results Footer Template
223
+ echo $template_footer;
224
+ echo "<br /><hr class=\"Divider\" />\n";
225
+ }
226
+ ?>
227
+ <!-- </Poll Archives> -->
228
+
229
+ <!-- <Paging> -->
230
+ <?php
231
+ if($total_polls > 0) {
232
+ ?>
233
+ <br />
234
+ <table width="100%" cellspacing="0" cellpadding="0" border="0">
235
+ <tr>
236
+ <td align="left" width="50%">
237
+ <?php
238
+ if($page > 1 && ((($page*$polls_perpage)-($polls_perpage-1)) <= $total_polls)) {
239
+ echo '<b>&laquo;</b> <a href="wp-polls.php?page='.($page-1).'" title="&laquo; '.__('Previous Page').'">'.__('Previous Page').'</a>';
240
+ } else {
241
+ echo '&nbsp;';
242
+ }
243
+ ?>
244
+ </td>
245
+ <td align="right" width="50%">
246
+ <?php
247
+ if($page >= 1 && ((($page*$polls_perpage)+1) <= $total_polls)) {
248
+ echo '<a href="wp-polls.php?page='.($page+1).'" title="'.__('Next Page').' &raquo;">'.__('Next Page').'</a> <b>&raquo;</b>';
249
+ } else {
250
+ echo '&nbsp;';
251
+ }
252
+ ?>
253
+ </td>
254
+ </tr>
255
+ <tr>
256
+ <td colspan="2" align="center">
257
+ <?php _e('Pages'); ?> (<?echo $total_pages; ?>) :
258
+ <?php
259
+ if ($page >= 4) {
260
+ echo '<b><a href="wp-polls.php?page=1" title="'.__('Go to First Page').'">&laquo; '.__('First').'</a></b> ... ';
261
+ }
262
+ if($page > 1) {
263
+ echo ' <b><a href="wp-polls.php?page='.($page-1).'" title="&laquo; '.__('Go to Page').' '.($page-1).'">&laquo;</a></b> ';
264
+ }
265
+ for($i = $page - 2 ; $i <= $page +2; $i++) {
266
+ if ($i >= 1 && $i <= $total_pages) {
267
+ if($i == $page) {
268
+ echo "<b>[$i]</b> ";
269
+ } else {
270
+ echo '<a href="wp-polls.php?page='.($i).'" title="'.__('Page').' '.$i.'">'.$i.'</a> ';
271
+ }
272
+ }
273
+ }
274
+ if($page < $total_pages) {
275
+ echo ' <b><a href="wp-polls.php?page='.($page+1).'" title="'.__('Go to Page').' '.($page+1).' &raquo;">&raquo;</a></b> ';
276
+ }
277
+ if (($page+2) < $total_pages) {
278
+ echo ' ... <b><a href="wp-polls.php?page='.($total_pages).'" title="'.__('Go to Last Page').'">'.__('Last').' &raquo;</a></b>';
279
+ }
280
+ ?>
281
+ </td>
282
+ </tr>
283
+ </table>
284
+ <!-- </Paging> -->
285
+ <?php
286
+ }
287
+ ?>
288
+ </div>
289
+ <?php
290
+ get_sidebar();
291
+ get_footer();
292
+ ?>