WP-Polls - Version 2.03

Version Description

Download this release

Release Info

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

Version 2.03

pollbar.gif ADDED
Binary file
polls-debug.php ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.02
7
+ Author: GaMerZ
8
+ Author URI: http://www.lesterchan.net
9
+ */
10
+
11
+
12
+ ### Function: Get Poll
13
+ function get_poll($temp_poll_id = 0) {
14
+ global $wpdb;
15
+ // Check Whether Poll Is Disabled
16
+ if(intval(get_settings('poll_currentpoll')) == -1) {
17
+ echo stripslashes(get_settings('poll_template_disable'));
18
+ return;
19
+ // Poll Is Enabled
20
+ } else {
21
+ // Hardcoded Poll ID Is Not Specified
22
+ if(intval($temp_poll_id) == 0) {
23
+ // Current Poll ID Is Not Specified
24
+ if(intval(get_settings('poll_currentpoll')) == 0) {
25
+ // Get Lastest Poll ID
26
+ $poll_id = intval(get_settings('poll_latestpoll'));
27
+ } else {
28
+ // Get Current Poll ID
29
+ $poll_id = intval(get_settings('poll_currentpoll'));
30
+ }
31
+ // Get Hardcoded Poll ID
32
+ } else {
33
+ $poll_id = intval($temp_poll_id);
34
+ }
35
+ }
36
+
37
+ // User Click on View Results Link
38
+ if(intval($_GET['pollresult']) == 1) {
39
+ display_pollresult($poll_id);
40
+ // Check Whether User Has Voted
41
+ } else {
42
+ // Check Cookie First
43
+ $voted_cookie = check_voted_cookie($poll_id);
44
+ if($voted_cookie > 0) {
45
+ display_pollresult($poll_id, $voted_cookie);
46
+ // Check IP If Cookie Cannot Be Found
47
+ } else {
48
+ $voted_ip = check_voted_ip($poll_id);
49
+ if($voted_ip > 0) {
50
+ display_pollresult($poll_id, $voted_ip);
51
+ // User Never Vote. Display Poll Voting Form
52
+ } else {
53
+ display_pollvote($poll_id);
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+
60
+ ### Function: Check Voted By Cookie
61
+ function check_voted_cookie($poll_id) {
62
+ // 0: False | > 0: True
63
+ return intval($_COOKIE["voted_$poll_id"]);
64
+ }
65
+
66
+
67
+ ### Function: Check Voted By IP
68
+ function check_voted_ip($poll_id) {
69
+ global $wpdb;
70
+ // Check IP From IP Logging Database
71
+ $get_voted_aid = $wpdb->get_var("SELECT pollip_aid FROM $wpdb->pollsip WHERE pollip_qid = $poll_id AND pollip_ip = '".get_ipaddress()."'");
72
+ // 0: False | > 0: True
73
+ return intval($get_voted_aid);
74
+ }
75
+
76
+
77
+ ### Function: Display Voting Form
78
+ function display_pollvote($poll_id) {
79
+ global $wpdb;
80
+ // Get Poll Question Data
81
+ $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
82
+ // Poll Question Variables
83
+ $poll_question_text = stripslashes($poll_question->pollq_question);
84
+ $poll_question_id = intval($poll_question->pollq_id);
85
+ $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
86
+ $template_question = stripslashes(get_settings('poll_template_voteheader'));
87
+ $template_question = str_replace("%POLL_QUESTION%", $poll_question_text, $template_question);
88
+ $template_question = str_replace("%POLL_ID%", $poll_question_id, $template_question);
89
+ $template_question = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_question);
90
+ // Get Poll Answers Data
91
+ $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'));
92
+ // If There Is Poll Question With Answers
93
+ if($poll_question && $poll_answers) {
94
+ // Display Poll Voting Form
95
+ echo '<form action="'.$_SERVER['REQUEST_URI'].'" name="polls" method="post">'."\n";
96
+ echo "<input type=\"hidden\" name=\"poll_id\" value=\"$poll_question_id\" />\n";
97
+ // Print Out Voting Form Header Template
98
+ echo $template_question;
99
+ foreach($poll_answers as $poll_answer) {
100
+ // Poll Answer Variables
101
+ $poll_answer_id = intval($poll_answer->polla_aid);
102
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
103
+ $poll_answer_votes = intval($poll_answer->polla_votes);
104
+ $template_answer = stripslashes(get_settings('poll_template_votebody'));
105
+ $template_answer = str_replace("%POLL_ID%", $poll_question_id, $template_answer);
106
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
107
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
108
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $poll_answer_votes, $template_answer);
109
+ // Print Out Voting Form Body Template
110
+ echo $template_answer;
111
+ }
112
+ // Voting Form Footer Variables
113
+ $template_footer = stripslashes(get_settings('poll_template_votefooter'));
114
+ // Print Out Voting Form Footer Template
115
+ echo $template_footer;
116
+ echo "</form>\n";
117
+ } else {
118
+ echo stripslashes(get_settings('poll_template_disable'));
119
+ }
120
+ }
121
+
122
+
123
+ ### Function: Display Results Form
124
+ function display_pollresult($poll_id, $user_voted = 0) {
125
+ global $wpdb;
126
+ // Get Poll Question Data
127
+ $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
128
+ // Poll Question Variables
129
+ $poll_question_text = stripslashes($poll_question->pollq_question);
130
+ $poll_question_id = intval($poll_question->pollq_id);
131
+ $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
132
+ $template_question = stripslashes(get_settings('poll_template_resultheader'));
133
+ $template_question = str_replace("%POLL_QUESTION%", $poll_question_text, $template_question);
134
+ $template_question = str_replace("%POLL_ID%", $poll_question_id, $template_question);
135
+ $template_question = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_question);
136
+ // Get Poll Answers Data
137
+ $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'));
138
+ // If There Is Poll Question With Answers
139
+ if($poll_question && $poll_answers) {
140
+ // Is The Poll Total Votes 0?
141
+ $poll_totalvotes_zero = true;
142
+ if($poll_question_totalvotes > 0) {
143
+ $poll_totalvotes_zero = false;
144
+ }
145
+ // Print Out Result Header Template
146
+ echo $template_question;
147
+ foreach($poll_answers as $poll_answer) {
148
+ // Poll Answer Variables
149
+ $poll_answer_id = intval($poll_answer->polla_aid);
150
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
151
+ $poll_answer_votes = intval($poll_answer->polla_votes);
152
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
153
+ $poll_answer_percentage = 0;
154
+ $poll_answer_imagewidth = 0;
155
+ // Calculate Percentage And Image Bar Width
156
+ if(!$poll_totalvotes_zero) {
157
+ if($poll_answer_votes > 0) {
158
+ $poll_answer_percentage = round((($poll_answer_votes/$poll_question_totalvotes)*100));
159
+ $poll_answer_imagewidth = round($poll_answer_percentage*0.9);
160
+ } else {
161
+ $poll_answer_percentage = 0;
162
+ $poll_answer_imagewidth = 1;
163
+ }
164
+ } else {
165
+ $poll_answer_percentage = 0;
166
+ $poll_answer_imagewidth = 1;
167
+ }
168
+ // Let User See What Options They Voted
169
+ if($user_voted == $poll_answer_id) {
170
+ // Results Body Variables
171
+ $template_answer = stripslashes(get_settings('poll_template_resultbody2'));
172
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
173
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
174
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $poll_answer_votes, $template_answer);
175
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
176
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
177
+ // Print Out Results Body Template
178
+ echo $template_answer;
179
+ } else {
180
+ // Results Body Variables
181
+ $template_answer = stripslashes(get_settings('poll_template_resultbody'));
182
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
183
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
184
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $poll_answer_votes, $template_answer);
185
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
186
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
187
+ // Print Out Results Body Template
188
+ echo $template_answer;
189
+ }
190
+ }
191
+ // Results Footer Variables
192
+ $template_footer = stripslashes(get_settings('poll_template_resultfooter'));
193
+ $template_footer = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_footer);
194
+ // Print Out Results Footer Template
195
+ echo $template_footer;
196
+ } else {
197
+ echo stripslashes(get_settings('poll_template_disable'));
198
+ }
199
+ }
200
+
201
+
202
+ ### Function: Vote Poll
203
+ function vote_poll() {
204
+ global $wpdb, $user_identity;
205
+ if(!empty($_POST['vote'])) {
206
+ $poll_id = intval($_POST['poll_id']);
207
+ $poll_aid = intval($_POST["poll-$poll_id"]);
208
+ if($poll_id > 0 && $poll_aid > 0) {
209
+ $voted_ip = check_voted_ip($poll_id);
210
+ $voted_cookie = check_voted_cookie($poll_ip);
211
+ if($voted_ip == 0 && $voted_cookie == 0) {
212
+ if(!empty($user_identity)) {
213
+ $pollip_user = addslashes($user_identity);
214
+ } elseif(!empty($_COOKIE['comment_author_'.COOKIEHASH])) {
215
+ $pollip_user = addslashes($_COOKIE['comment_author_'.COOKIEHASH]);
216
+ } else {
217
+ $pollip_user = 'Guest';
218
+ }
219
+ $vote_cookie = setcookie("voted_".$poll_id, $poll_aid, time() + 30000000, COOKIEPATH);
220
+ if($vote_cookie) {
221
+ $pollip_ip = get_ipaddress();
222
+ $pollip_host = gethostbyaddr($pollip_ip);
223
+ $pollip_timestamp = current_time('timestamp');
224
+ $vote_ip = $wpdb->query("INSERT INTO $wpdb->pollsip VALUES(0,$poll_id,$poll_aid,'$pollip_ip','$pollip_host','$pollip_timestamp','$pollip_user')");
225
+ if($vote_ip) {
226
+ $vote_a = $wpdb->query("UPDATE $wpdb->pollsa SET polla_votes = (polla_votes+1) WHERE polla_qid = $poll_id AND polla_aid = $poll_aid");
227
+ if($vote_a) {
228
+ $vote_q = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes+1) WHERE pollq_id = $poll_id");
229
+ if(!$vote_q) {
230
+ echo "Error Updating Poll Question:- UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes+1) WHERE pollq_id = $poll_id";
231
+ }
232
+ } else {
233
+ echo "Error Updating Poll Answer:- UPDATE $wpdb->pollsa SET polla_votes = (polla_votes+1) WHERE polla_qid = $poll_id AND polla_aid = $poll_aid";
234
+ }
235
+ } else {
236
+ echo "Error Inserting Poll IP:- INSERT INTO $wpdb->pollsip VALUES(0, $poll_id, $poll_aid, '$pollip_ip', '$pollip_host', '$pollip_timestamp', '$pollip_user')";
237
+ }
238
+ } else {
239
+ echo "Error Setting Poll Cookie:- (voted_$poll_id, $poll_aid, ".(time() + 30000000).", ".COOKIEPATH.")";
240
+ }
241
+ } else {
242
+ echo "You Have Already Voted:- voted_ip: $voted_ip | voted_cookie: $voted_cookie";
243
+ }
244
+ } else {
245
+ echo "Empty Poll Vote Button:- $_POST[vote]";
246
+ }
247
+ } else {
248
+ echo "Invalid Poll ID And Poll Answer ID:- poll_id: $poll_id | poll_aid: $poll_aid";
249
+ }
250
+ }
251
+
252
+
253
+ ### Function: Get IP Address
254
+ function get_ipaddress() {
255
+ if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
256
+ $ip_address = $_SERVER["REMOTE_ADDR"];
257
+ } else {
258
+ $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
259
+ }
260
+ if(strpos($ip_address, ',') !== false) {
261
+ $ip_address = explode(',', $ip_address);
262
+ $ip_address = $ip_address[0];
263
+ }
264
+ return $ip_address;
265
+ }
266
+ ?>
polls-install.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.03 |
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.03 |
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=\\\"index.php?pollresult=1\\\">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 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.03'); ?></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.03'); ?></h2>
105
+ <p><?php _e('This install script will install WP-Polls 2.03 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.03 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.03'); ?>" 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,562 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.03 |
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
+ ### Variables Variables Variables
24
+ $title = __('Manage Polls');
25
+ $this_file = 'polls-manager.php';
26
+ $parent_file = 'polls-manager.php';
27
+ $mode = trim($_GET['mode']);
28
+ $poll_id = intval($_GET['id']);
29
+ $poll_aid = intval($_GET['aid']);
30
+
31
+ ### Magic Quotes GPC
32
+ if (get_magic_quotes_gpc()) {
33
+ function traverse(&$arr) {
34
+ if(!is_array($arr))
35
+ return;
36
+ foreach($arr as $key => $val)
37
+ is_array($arr[$key]) ? traverse($arr[$key]) : ($arr[$key] = stripslashes($arr[$key]));
38
+ }
39
+ $gpc = array(&$_GET, &$_POST, &$_COOKIE);
40
+ traverse($gpc);
41
+ }
42
+
43
+ ### Cancel
44
+ if(isset($_POST['cancel'])) {
45
+ Header('Location: polls-manager.php');
46
+ exit();
47
+ }
48
+
49
+ ### Form Processing
50
+ if(!empty($_POST['do'])) {
51
+ // Decide What To Do
52
+ switch($_POST['do']) {
53
+ // Add Poll
54
+ case 'Add Poll':
55
+ // Add Poll Question
56
+ $pollq_question = addslashes(trim($_POST['pollq_question']));
57
+ $pollq_timestamp = current_time('timestamp');
58
+ $add_poll_question = $wpdb->query("INSERT INTO $wpdb->pollsq VALUES (0, '$pollq_question', '$pollq_timestamp', 0)");
59
+ if(!$add_poll_question) {
60
+ $text .= '<font color="red">Error In Adding Poll \''.stripslashes($pollq_question).'\'</font>';
61
+ }
62
+ // Add Poll Answers
63
+ $polla_answers = $_POST['polla_answers'];
64
+ $polla_qid = intval($wpdb->insert_id);
65
+ foreach($polla_answers as $polla_answer) {
66
+ $polla_answer = addslashes(trim($polla_answer));
67
+ $add_poll_answers = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answer', 0)");
68
+ if(!$add_poll_answers) {
69
+ $text .= '<font color="red">Error In Adding Poll\'s Answer \''.stripslashes($polla_answer).'\'</font>';
70
+ }
71
+ }
72
+ // Update Lastest Poll ID To Poll Options
73
+ $update_latestpoll = $wpdb->query("UPDATE $wpdb->options SET option_value = $polla_qid WHERE option_name = 'poll_latestpoll'");
74
+ if(!$update_latestpoll) {
75
+ $text .= "<font color=\"red\">There Is An Error Updating The Lastest Poll ID ($polla_qid) To The Poll Option</font>";
76
+ }
77
+ if(empty($text)) {
78
+ $text = '<font color="green">Poll \''.stripslashes($pollq_question).'\' Added Successfully</font>';
79
+ wp_cache_flush();
80
+ }
81
+ break;
82
+ // Edit Poll
83
+ case 'Edit Poll':
84
+ // Update Poll's Question
85
+ $pollq_id = intval($_POST['pollq_id']);
86
+ $pollq_totalvotes = intval($_POST['pollq_totalvotes']);
87
+ $pollq_question = addslashes(trim($_POST['pollq_question']));
88
+ $edit_poll_question = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_question = '$pollq_question', pollq_totalvotes = $pollq_totalvotes WHERE pollq_id = $pollq_id");
89
+ if(!$edit_poll_question) {
90
+ $text = '<font color="blue">No Changes Had Been Made To \''.stripslashes($pollq_question).'\'</font>';
91
+ }
92
+ // Update Polls' Answers
93
+ $polla_aids = array();
94
+ $get_polla_aids = $wpdb->get_results("SELECT polla_aid FROM $wpdb->pollsa WHERE polla_qid = $pollq_id ORDER BY polla_aid ASC");
95
+ if($get_polla_aids) {
96
+ foreach($get_polla_aids as $get_polla_aid) {
97
+ $polla_aids[] = intval($get_polla_aid->polla_aid);
98
+ }
99
+ foreach($polla_aids as $polla_aid) {
100
+ $polla_answers = addslashes(trim($_POST['polla_aid-'.$polla_aid]));
101
+ $edit_poll_answer = $wpdb->query("UPDATE $wpdb->pollsa SET polla_answers = '$polla_answers' WHERE polla_qid = $pollq_id AND polla_aid = $polla_aid");
102
+ if(!$edit_poll_answer) {
103
+ $text .= '<br /><font color="blue">No Changes Had Been Made To Poll\'s Answer \''.stripslashes($polla_answers).'\'</font>';
104
+ }
105
+ }
106
+ } else {
107
+ $text .= '<br /><font color="red">Invalid Poll \''.stripslashes($pollq_question).'\'</font>';
108
+ }
109
+ if(empty($text)) {
110
+ $text = '<font color="green">Poll \''.stripslashes($pollq_question).'\' Edited Successfully</font>';
111
+ }
112
+ break;
113
+ // Delete Poll
114
+ case 'Delete Poll':
115
+ $pollq_id = intval($_POST['pollq_id']);
116
+ $pollq_question = trim($_POST['pollq_question']);
117
+ $delete_poll_question = $wpdb->query("DELETE FROM $wpdb->pollsq WHERE pollq_id = $pollq_id");
118
+ $delete_poll_answers = $wpdb->query("DELETE FROM $wpdb->pollsa WHERE polla_qid = $pollq_id");
119
+ $delete_poll_ip = $wpdb->query("DELETE FROM $wpdb->pollsip WHERE pollip_qid = $pollq_id");
120
+ $poll_option_lastestpoll = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'poll_latestpoll'");
121
+ if(!$delete_poll_question) {
122
+ $text = '<font color="red">Error In Deleting Poll \''.stripslashes($pollq_question).'\' Question</font>';
123
+ }
124
+ if(!$delete_poll_answers) {
125
+ $text .= '<br /><font color="red">Error In Deleting Poll Answers For \''.stripslashes($pollq_question).'\'</font>';
126
+ }
127
+ if(!$delete_poll_ip) {
128
+ $text .= '<br /><font color="red">Error In Deleting Voted IPs For \''.stripslashes($pollq_question).'\'</font>';
129
+ }
130
+ if(empty($text)) {
131
+ if($poll_option_lastestpoll == $pollq_id) {
132
+ $poll_lastestpoll = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq ORDER BY pollq_id DESC LIMIT 1");
133
+ if($poll_lastestpoll) {
134
+ $poll_lastestpoll = intval($poll_lastestpoll);
135
+ $update_latestpoll = $wpdb->query("UPDATE $wpdb->options SET option_value = $poll_lastestpoll WHERE option_name = 'poll_latestpoll'");
136
+ }
137
+ }
138
+ $text = '<font color="green">Poll \''.stripslashes($pollq_question).'\' Deleted Successfully</font>';
139
+ }
140
+ break;
141
+ // Add Poll's Answer
142
+ case 'Add Answer':
143
+ $polla_qid = intval($_POST['polla_qid']);
144
+ $polla_answers = addslashes(trim($_POST['polla_answers']));
145
+ $add_poll_question = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0, $polla_qid, '$polla_answers', 0)");
146
+ if(!$add_poll_question) {
147
+ $text = '<font color="red">Error In Adding Poll Answer \''.stripslashes($polla_answers).'\'</font>';
148
+ } else {
149
+ $text = '<font color="green">Poll Answer \''.stripslashes($polla_answers).'\' Added Successfully</font>';
150
+ }
151
+ break;
152
+ }
153
+ }
154
+
155
+
156
+ ### Determines Which Mode It Is
157
+ switch($mode) {
158
+ // Add A Poll
159
+ case 'add':
160
+ $title = __('Add Poll');
161
+ $standalone = 0;
162
+ require("./admin-header.php");
163
+ if ($user_level < 8) {
164
+ die(__('Access Denied: Insufficient Access'));
165
+ }
166
+ ?>
167
+ <div class="wrap">
168
+ <h2>Add Poll</h2>
169
+ <?php
170
+ if(isset($_POST['addpollquestion'])) {
171
+ $poll_noquestion = intval($_POST['poll_noquestion']);
172
+ $pollq_question = stripslashes(trim($_POST['pollq_question']));
173
+ ?>
174
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
175
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
176
+ <tr>
177
+ <th align="left" scope="row"><?php _e('Question') ?></th>
178
+ <td><input type="text" size="50" maxlength="200" name="pollq_question" value="<?php echo $pollq_question; ?>"></td>
179
+ <?php
180
+ for($i=1; $i<=$poll_noquestion; $i++) {
181
+ echo "<tr>\n";
182
+ echo "<th align=\"left\" scope=\"row\">Answers $i:</th>\n";
183
+ echo "<td><input type=\"text\" size=\"30\" maxlength=\"200\" name=\"polla_answers[]\"></td>\n";
184
+ echo "</tr>\n";
185
+ }
186
+ ?>
187
+ </tr>
188
+ <tr>
189
+ <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>
190
+ </tr>
191
+ </table>
192
+ </form>
193
+ <?php } else {?>
194
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=add" method="post">
195
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
196
+ <tr>
197
+ <th align="left" scope="row"><?php _e('Question') ?></th>
198
+ <td><input type="text" size="50" maxlength="200" name="pollq_question"></td>
199
+ </tr>
200
+ <th align="left" scope="row"><?php _e('No. Of Answers:') ?></th>
201
+ <td>
202
+ <select size="1" name="poll_noquestion">
203
+ <?php
204
+ for($i=2; $i <= 20; $i++) {
205
+ echo "<option value=\"$i\">$i</option>";
206
+ }
207
+ ?>
208
+ </select>
209
+ </td>
210
+ </tr>
211
+ <tr>
212
+ <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>
213
+ </tr>
214
+ </table>
215
+ </form>
216
+ <?php } ?>
217
+ </div>
218
+ <?php
219
+ break;
220
+ // Edit A Poll
221
+ case 'edit':
222
+ $title = __('Edit Poll');
223
+ $standalone = 0;
224
+ require("./admin-header.php");
225
+ if ($user_level < 8) {
226
+ die(__('Access Denied: Insufficient Access'));
227
+ }
228
+ $poll_question = $wpdb->get_row("SELECT pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id");
229
+ $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");
230
+ $poll_question_text = stripslashes($poll_question->pollq_question);
231
+ $poll_totalvotes = intval($poll_question->pollq_totalvote);
232
+ ?>
233
+ <!-- Edit Poll -->
234
+ <div class="wrap">
235
+ <h2><?php _e('Edit Poll'); ?></h2>
236
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
237
+ <input type="hidden" name="pollq_id" value="<?php echo $poll_id; ?>">
238
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
239
+ <tr>
240
+ <th scope="row" colspan="2"><?php _e('Question') ?></th>
241
+ </tr>
242
+ <tr>
243
+ <td align="center" colspan="2"><input type="text" size="70" maxlength="200" name="pollq_question" value="<?php echo $poll_question_text; ?>" /></td>
244
+ </tr>
245
+ <tr>
246
+ <th align="left" scope="row"><?php _e('Answers:') ?></th>
247
+ <th align="right" scope="row"><?php _e('No. Of Votes') ?></th>
248
+ </tr>
249
+ <?php
250
+ $i=1;
251
+ $poll_actual_totalvotes = 0;
252
+ if($poll_answers) {
253
+ $pollip_answers = array();
254
+ $pollip_answers[0] = __('Null Votes');
255
+ foreach($poll_answers as $poll_answer) {
256
+ $polla_aid = intval($poll_answer->polla_aid);
257
+ $polla_answers = stripslashes($poll_answer->polla_answers);
258
+ $polla_votes = intval($poll_answer->polla_votes);
259
+ $pollip_answers[$polla_aid] = $polla_answers;
260
+ echo "<tr>\n";
261
+ 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;";
262
+ 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";
263
+ echo "<td align=\"right\">$polla_votes</td>\n</tr>\n";
264
+ $poll_actual_totalvotes += $polla_votes;
265
+ $i++;
266
+ }
267
+ }
268
+ ?>
269
+ </tr>
270
+ <tr>
271
+ <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" name="pollq_totalvotes" value="<?php echo $poll_actual_totalvotes; ?>"></td>
272
+ </tr>
273
+ <tr>
274
+ <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>
275
+ </tr>
276
+ </table>
277
+ </form>
278
+ </div>
279
+ <!-- Add Poll's Answer -->
280
+ <div class="wrap">
281
+ <h2><?php _e('Add Answer') ?></h2>
282
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=edit&id=<?php echo $poll_id; ?>" method="post">
283
+ <input type="hidden" name="polla_qid" value="<?php echo $poll_id; ?>">
284
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
285
+ <tr>
286
+ <td><b><?php _e('Add Answer') ?></b></td>
287
+ <td><input type="text" size="50" maxlength="200" name="polla_answers"></td>
288
+ </tr>
289
+ <tr>
290
+ <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Add Answer'); ?>" class="button"></td>
291
+ </tr>
292
+ </table>
293
+ </form>
294
+ </div>
295
+ <!-- Users Voted For This Poll -->
296
+ <?php
297
+ $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");
298
+ ?>
299
+ <div class="wrap">
300
+ <h2><?php _e('Users Voted For This Poll') ?></h2>
301
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
302
+ <?php
303
+ if($poll_ips) {
304
+ $k = 1;
305
+ $poll_last_aid = -1;
306
+ foreach($poll_ips as $poll_ip) {
307
+ $pollip_aid = intval($poll_ip->pollip_aid);
308
+ $pollip_user = stripslashes($poll_ip->pollip_user);
309
+ $pollip_ip = $poll_ip->pollip_ip;
310
+ $pollip_host = $poll_ip->pollip_host;
311
+ $pollip_date = gmdate("jS F Y @ H:i", $poll_ip->pollip_timestamp);
312
+ if($pollip_aid != $poll_last_aid) {
313
+ if($pollip_aid == 0) {
314
+ echo "<tr style='background-color: #b8d4ff'>\n<td colspan=\"4\"><b>$pollip_answers[$pollip_aid]</b></td>\n</tr>\n";
315
+ } else {
316
+ echo "<tr style='background-color: #b8d4ff'>\n<td colspan=\"4\"><b>".__('Answer')." $k: $pollip_answers[$pollip_aid]</b></td>\n</tr>\n";
317
+ $k++;
318
+ }
319
+ echo "<tr>\n";
320
+ echo "<th scope=\"row\">".__('No.')."</th>\n";
321
+ echo "<th scope=\"row\">".__('User')."</th>\n";
322
+ echo "<th scope=\"row\">".__('IP/Host')."</th>\n";
323
+ echo "<th scope=\"row\">".__('Date')."</th>\n";
324
+ echo "</tr>\n";
325
+ $i = 1;
326
+ }
327
+ if($i%2 == 0) {
328
+ $style = 'style=\'background-color: none\'';
329
+ } else {
330
+ $style = 'style=\'background-color: #eee\'';
331
+ }
332
+ echo "<tr $style>\n";
333
+ echo "<td>$i</td>\n";
334
+ echo "<td>$pollip_user</td>\n";
335
+ echo "<td>$pollip_ip / $pollip_host</td>\n";
336
+ echo "<td>$pollip_date</td>\n";
337
+ echo "</tr>\n";
338
+ $poll_last_aid = $pollip_aid;
339
+ $i++;
340
+ }
341
+ } else {
342
+ echo "<tr>\n<td colspan=\"4\" align=\"center\">".__('No IP Has Been Logged Yet.')."</td>\n</tr>\n";
343
+ }
344
+ ?>
345
+ </table>
346
+ </div>
347
+ <?php
348
+ break;
349
+ // Delete A Poll
350
+ case 'delete':
351
+ $title = __('Delete Poll');
352
+ $standalone = 0;
353
+ require("./admin-header.php");
354
+ if ($user_level < 8) {
355
+ die(__('Access Denied: Insufficient Access'));
356
+ }
357
+ $poll_question = $wpdb->get_row("SELECT pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id");
358
+ $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_answers, polla_votes FROM $wpdb->pollsa WHERE polla_qid = $poll_id ORDER BY polla_answers");
359
+ $poll_question_text = stripslashes($poll_question->pollq_question);
360
+ $poll_totalvotes = intval($poll_question->pollq_totalvotes);
361
+ ?>
362
+ <!-- Delete Poll -->
363
+ <div class="wrap">
364
+ <h2><?php _e('Delete Poll') ?></h2>
365
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
366
+ <input type="hidden" name="pollq_id" value="<?php echo $poll_id; ?>">
367
+ <input type="hidden" name="pollq_question" value="<?php echo $poll_question_text; ?>">
368
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
369
+ <tr>
370
+ <th colspan="2" scope="row"><?php _e('Question') ?></th>
371
+ </tr>
372
+ <tr>
373
+ <td colspan="2" align="center"><?php echo $poll_question_text; ?></td>
374
+ </tr>
375
+ <tr>
376
+ <th align="left" scope="row"><?php _e('Answers') ?></th>
377
+ <th scope="row"><?php _e('No. Of Votes') ?></th>
378
+ </tr>
379
+ <?php
380
+ $i=1;
381
+ if($poll_answers) {
382
+ foreach($poll_answers as $poll_answer) {
383
+ $polla_answers = stripslashes($poll_answer->polla_answers);
384
+ $polla_votes = intval($poll_answer->polla_votes);
385
+ echo "<tr>\n";
386
+ echo "<td>".__('Answer')." $i:&nbsp;&nbsp;&nbsp;$polla_answers</td>\n";
387
+ echo "<td align=\"center\">$polla_votes</td>\n</tr>\n";
388
+ $i++;
389
+ }
390
+ }
391
+ ?>
392
+ </tr>
393
+ <tr>
394
+ <th colspan="2" scope="row"><?php _e('Total Votes'); ?>: <?php echo $poll_totalvotes; ?></th>
395
+ </tr>
396
+ <tr>
397
+ <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>
398
+ </tr>
399
+ </table>
400
+ </form>
401
+ </div>
402
+ <?php
403
+ break;
404
+ // Delete A Poll Answer
405
+ case 'deleteans':
406
+ $title = __('Delete Poll\'s Answer');
407
+ $standalone = 0;
408
+ require("./admin-header.php");
409
+ if ($user_level < 8) {
410
+ die(__('Access Denied: Insufficient Access'));
411
+ }
412
+ $poll_answers = $wpdb->get_row("SELECT polla_votes, polla_answers FROM $wpdb->pollsa WHERE polla_aid = $poll_aid AND polla_qid = $poll_id");
413
+ $polla_votes = intval($poll_answers->polla_votes);
414
+ $polla_answers = stripslashes(trim($poll_answers->polla_answers));
415
+ $delete_polla_answers = $wpdb->query("DELETE FROM $wpdb->pollsa WHERE polla_aid = $poll_aid AND polla_qid = $poll_id");
416
+ $update_pollq_totalvotes = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes-$polla_votes) WHERE pollq_id=$poll_id");
417
+ ?>
418
+ <!-- Delete Poll's Answer -->
419
+ <div class="wrap">
420
+ <h2><?php _e('Delete Poll\'s Answer') ?></h2>
421
+ <?php
422
+ if($delete_polla_answers) {
423
+ $text = "<font color=\"green\">Poll Answer '$polla_answers' Deleted Successfully</font>";
424
+ } else {
425
+ $text = "<font color=\"red\">Error In Deleting Poll Answer '$polla_answers'</font>";
426
+ }
427
+ if($update_pollq_totalvotes) {
428
+ $text .= "<br /><font color=\"green\">Poll Question's Total Votes Updated Successfully</font>";
429
+ } else {
430
+ $text .= "<br /><font color=\"blue\">No Changes Had Been Made To The Poll's Total Votes</font>";
431
+ }
432
+ _e($text);
433
+ ?>
434
+ <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>
435
+ </div>
436
+ <?php
437
+ break;
438
+ // Main Page
439
+ default:
440
+ $title = __('Manage Polls');
441
+ $standalone = 0;
442
+ require("./admin-header.php");
443
+ if ($user_level < 8) {
444
+ die(__('Access Denied: Insufficient Access'));
445
+ }
446
+ $polls = $wpdb->get_results("SELECT * FROM $wpdb->pollsq ORDER BY pollq_id DESC");
447
+ $total_ans = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->pollsa");
448
+ $total_votes = 0;
449
+ ?>
450
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
451
+ <!-- Manage Polls -->
452
+ <div class="wrap">
453
+ <h2><?php _e('Manage Polls'); ?></h2>
454
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
455
+ <tr>
456
+ <th scope="col"><?php _e('ID'); ?></b></th>
457
+ <th scope="col"><?php _e('Question'); ?></b></th>
458
+ <th scope="col"><?php _e('Total Votes'); ?></b></th>
459
+ <th scope="col"><?php _e('Date Added'); ?></b></th>
460
+ <th scope="col" colspan="2"><?php _e('Action'); ?></th>
461
+ </tr>
462
+ <?php
463
+ if($polls) {
464
+ $i = 0;
465
+ $current_poll = intval(get_settings('poll_currentpoll'));
466
+ foreach($polls as $poll) {
467
+ $poll_id = intval($poll->pollq_id);
468
+ $poll_question = stripslashes($poll->pollq_question);
469
+ $poll_date = gmdate("jS F Y @ H:i", $poll->pollq_timestamp);
470
+ $poll_totalvotes = intval($poll->pollq_totalvotes);
471
+ if($i%2 == 0) {
472
+ $style = 'style=\'background-color: #eee\'';
473
+ } else {
474
+ $style = 'style=\'background-color: none\'';
475
+ }
476
+ if($current_poll > 0) {
477
+ if($current_poll == $poll_id) {
478
+ $style = 'style=\'background-color: #b8d4ff\'';
479
+ }
480
+ } else {
481
+ if($i == 0) {
482
+ $style = 'style=\'background-color: #b8d4ff\'';
483
+ }
484
+ }
485
+ echo "<tr $style>\n";
486
+ echo "<td><b>$poll_id</b></td>\n";
487
+ echo '<td>';
488
+ if($current_poll > 0) {
489
+ if($current_poll == $poll_id) {
490
+ echo '<b>'.__('Displayed:').'</b> ';
491
+ }
492
+ } elseif($current_poll != -1) {
493
+ if($i == 0) {
494
+ echo '<b>'.__('Displayed:').'</b> ';
495
+ }
496
+ }
497
+ echo "$poll_question</td>\n";
498
+ echo "<td>$poll_totalvotes</td>\n";
499
+ echo "<td>$poll_date</td>\n";
500
+ echo "<td><a href=\"polls-manager.php?mode=edit&id=$poll_id\" class=\"edit\">".__('Edit')."</a></td>\n";
501
+ echo "<td><a href=\"polls-manager.php?mode=delete&id=$poll_id\" class=\"delete\">".__('Delete')."</a></td>\n";
502
+ echo '</tr>';
503
+ $i++;
504
+ $total_votes+= $poll_totalvotes;
505
+
506
+ }
507
+ } else {
508
+ echo '<tr><td colspan="6" align="center"><b>'.__('No Polls Found').'</b></td></tr>';
509
+ }
510
+ ?>
511
+ </table>
512
+ </div>
513
+ <!-- Add A Poll -->
514
+ <div class="wrap">
515
+ <h2><?php _e('Add A Poll'); ?></h2>
516
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=add" method="post">
517
+ <table width="100%" border="0" cellspacing="3" cellpadding="3">
518
+ <tr>
519
+ <th align="left" scope="row"><?php _e('Question') ?></th>
520
+ <td><input type="text" size="50" maxlength="200" name="pollq_question"></td>
521
+ </tr>
522
+ <th align="left" scope="row"><?php _e('No. Of Answers:') ?></th>
523
+ <td>
524
+ <select size="1" name="poll_noquestion">
525
+ <?php
526
+ for($i=2; $i <= 20; $i++) {
527
+ echo "<option value=\"$i\">$i</option>";
528
+ }
529
+ ?>
530
+ </select>
531
+ </td>
532
+ </tr>
533
+ <tr>
534
+ <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>
535
+ </tr>
536
+ </table>
537
+ </form>
538
+ </div>
539
+ <!-- Polls Stats -->
540
+ <div class="wrap">
541
+ <h2><?php _e('Polls Stats'); ?></h2>
542
+ <table border="0" cellspacing="3" cellpadding="3">
543
+ <tr>
544
+ <th align="left" scope="row"><?php _e('Total Polls:'); ?></th>
545
+ <td align="left"><?php echo $i; ?></td>
546
+ </tr>
547
+ <tr>
548
+ <th align="left" scope="row"><?php _e('Total Polls\' Answers:'); ?></th>
549
+ <td align="left"><?php echo number_format($total_ans); ?></td>
550
+ </tr>
551
+ <tr>
552
+ <th align="left" scope="row"><?php _e('Total Votes Casted:'); ?></th>
553
+ <td align="left"><?php echo number_format($total_votes); ?></td>
554
+ </tr>
555
+ </table>
556
+ </div>
557
+ <?php
558
+ } // End switch($mode)
559
+
560
+ ### Require Admin Footer
561
+ require_once 'admin-footer.php';
562
+ ?>
polls-options.php ADDED
@@ -0,0 +1,381 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Polls 2.03 |
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
+ ### Variables Variables Variables
24
+ $title = __('Poll Options');
25
+ $this_file = 'polls-options.php';
26
+ $parent_file = 'polls-manager.php';
27
+ $id = intval($_GET['id']);
28
+ $standalone = 0;
29
+
30
+ ### Require Admin Header
31
+ require("./admin-header.php");
32
+
33
+ ### If User Less Than 8, Don't Let Him Pass
34
+ if ($user_level < 8) {
35
+ die(__('Access Denied: Insufficient Access'));
36
+ }
37
+
38
+ ### Magic Quotes GPC
39
+ if (get_magic_quotes_gpc()) {
40
+ function traverse(&$arr) {
41
+ if(!is_array($arr))
42
+ return;
43
+ foreach($arr as $key => $val)
44
+ is_array($arr[$key]) ? traverse($arr[$key]) : ($arr[$key] = stripslashes($arr[$key]));
45
+ }
46
+ $gpc = array(&$_GET, &$_POST, &$_COOKIE);
47
+ traverse($gpc);
48
+ }
49
+
50
+ ### If Form Is Submitted
51
+ if($_POST['Submit']) {
52
+ $poll_ans_sortby = addslashes(strip_tags(trim($_POST['poll_ans_sortby'])));
53
+ $poll_ans_sortorder = addslashes(strip_tags(trim($_POST['poll_ans_sortorder'])));
54
+ $poll_ans_result_sortby = addslashes(strip_tags(trim($_POST['poll_ans_result_sortby'])));
55
+ $poll_ans_result_sortorder = addslashes(strip_tags(trim($_POST['poll_ans_result_sortorder'])));
56
+ $poll_template_voteheader =addslashes(trim($_POST['poll_template_voteheader']));
57
+ $poll_template_votebody = addslashes(trim($_POST['poll_template_votebody']));
58
+ $poll_template_votefooter = addslashes(trim($_POST['poll_template_votefooter']));
59
+ $poll_template_resultheader = addslashes(trim($_POST['poll_template_resultheader']));
60
+ $poll_template_resultbody = addslashes(trim($_POST['poll_template_resultbody']));
61
+ $poll_template_resultbody2 = addslashes(trim($_POST['poll_template_resultbody2']));
62
+ $poll_template_resultfooter = addslashes(trim($_POST['poll_template_resultfooter']));
63
+ $poll_template_disable =addslashes( trim($_POST['poll_template_disable']));
64
+ $poll_template_error =addslashes( trim($_POST['poll_template_error']));
65
+ $poll_archive_perpage = intval($_POST['poll_archive_perpage']);
66
+ $poll_currentpoll = intval($_POST['poll_currentpoll']);
67
+ $update_poll_queries = array();
68
+ $update_poll_text = array();
69
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_ans_sortby' WHERE option_name = 'poll_ans_sortby'";
70
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_ans_sortorder' WHERE option_name = 'poll_ans_sortorder'";
71
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_ans_result_sortby' WHERE option_name = 'poll_ans_result_sortby'";
72
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_ans_result_sortorder' WHERE option_name = 'poll_ans_result_sortorder'";
73
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_voteheader' WHERE option_name = 'poll_template_voteheader'";
74
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_votebody' WHERE option_name = 'poll_template_votebody'";
75
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_votefooter' WHERE option_name = 'poll_template_votefooter'";
76
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_resultheader' WHERE option_name = 'poll_template_resultheader'";
77
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_resultbody' WHERE option_name = 'poll_template_resultbody'";
78
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_resultbody2' WHERE option_name = 'poll_template_resultbody2'";
79
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_resultfooter' WHERE option_name = 'poll_template_resultfooter'";
80
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_disable' WHERE option_name = 'poll_template_disable'";
81
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_template_error' WHERE option_name = 'poll_template_error'";
82
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_archive_perpage' WHERE option_name = 'poll_archive_perpage'";
83
+ $update_poll_queries[] = "UPDATE $wpdb->options SET option_value = '$poll_currentpoll' WHERE option_name = 'poll_currentpoll'";
84
+ $update_poll_text[] = __('Sort Poll Answers By Option');
85
+ $update_poll_text[] = __('Sort Order Of Poll Answers Option');
86
+ $update_poll_text[] = __('Sort Poll Results By Option');
87
+ $update_poll_text[] = __('Sort Order Of Poll Results Option');
88
+ $update_poll_text[] = __('Voting Form Header Template');
89
+ $update_poll_text[] = __('Voting Form Body Template');
90
+ $update_poll_text[] = __('Voting Form Footer Template');
91
+ $update_poll_text[] = __('Result Header Template');
92
+ $update_poll_text[] = __('Result Body Template');
93
+ $update_poll_text[] = __('Result Body2 Template');
94
+ $update_poll_text[] = __('Result Footer Template');
95
+ $update_poll_text[] = __('Poll Disabled Template');
96
+ $update_poll_text[] = __('Poll Error Template');
97
+ $update_poll_text[] = __('Archive Polls Per Page Option');
98
+ $update_poll_text[] = __('Current Active Poll Option');
99
+ $i=0;
100
+ $text = '';
101
+ foreach($update_poll_queries as $update_poll_query) {
102
+ $updating = $wpdb->query($update_poll_query);
103
+ if($updating) {
104
+ $text .= '<font color="green">'.$update_poll_text[$i].' '.__('Updated').'</font><br />';
105
+ wp_cache_flush();
106
+ }
107
+ $i++;
108
+ }
109
+ if(empty($text)) {
110
+ $text = '<font color="red">'.__('No Poll Option Updated').'</font>';
111
+ }
112
+ }
113
+
114
+ ?>
115
+ <script language="JavaScript" type="text/javascript">
116
+ function poll_default_templates(template) {
117
+ var default_template;
118
+ switch(template) {
119
+ case "voteheader":
120
+ default_template = "<table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n<tr>\n<td align=\"center\"><b>%POLL_QUESTION%</b></td>\n</tr>";
121
+ break;
122
+ case "votebody":
123
+ default_template = "<tr>\n<td align=\"left\"><input type=\"radio\" name=\"poll-%POLL_ID%\" value=\"%POLL_ANSWER_ID%\" />&nbsp;%POLL_ANSWER%</td>\n</tr>";
124
+ break;
125
+ case "votefooter":
126
+ default_template = "<tr>\n<td align=\"center\"><input type=\"submit\" name=\"vote\" value=\" Vote \" class=\"Buttons\" /><br /><a href=\"index.php?pollresult=1\">View Results</a></td>\n</tr>\n</table>";
127
+ break;
128
+ case "resultheader":
129
+ 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>";
130
+ break;
131
+ case "resultbody":
132
+ 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>";
133
+ break;
134
+ case "resultbody2":
135
+ 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>";
136
+ break;
137
+ case "resultfooter":
138
+ default_template = "<tr>\n<td colspan=\"2\" align=\"center\">Total Votes: <b>%POLL_TOTALVOTES%</b><td>\n</tr>\n</table>";
139
+ break;
140
+ case "disable":
141
+ default_template = 'Sorry, there are no polls available at the moment.';
142
+ break;
143
+ case "error":
144
+ default_template = 'An error has occurred when processing your poll.';
145
+ break;
146
+ }
147
+ document.getElementById("poll_template_" + template).value = default_template;
148
+ }
149
+
150
+ </script>
151
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
152
+ <div class="wrap">
153
+ <h2><?php echo $title; ?></h2>
154
+ <form name="polls_options" method="post" action="polls-options.php">
155
+ <fieldset class="options">
156
+ <legend><?php _e('Sorting Of Poll Answers'); ?></legend>
157
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
158
+ <tr valign="top">
159
+ <th scope="row" width="40%"><?php _e('Sort Poll Answers By:'); ?></th>
160
+ <td>
161
+ <select name="poll_ans_sortby" size="1">
162
+ <option value="polla_aid"<?php selected('polla_aid', get_settings('poll_ans_sortby')); ?>><?php _e('Exact Order'); ?></option>
163
+ <option value="polla_answers"<?php selected('polla_answers', get_settings('poll_ans_sortby')); ?>><?php _e('Alphabetical Order'); ?></option>
164
+ </select>
165
+ </td>
166
+ </tr>
167
+ <tr valign="top">
168
+ <th scope="row" width="40%"><?php _e('Sort Order Of Poll Answers:'); ?></th>
169
+ <td>
170
+ <select name="poll_ans_sortorder" size="1">
171
+ <option value="asc"<?php selected('asc', get_settings('poll_ans_sortorder')); ?>><?php _e('Ascending'); ?></option>
172
+ <option value="desc"<?php selected('desc', get_settings('poll_ans_sortorder')); ?>><?php _e('Descending'); ?></option>
173
+ </select>
174
+ </td>
175
+ </tr>
176
+ </table>
177
+ </fieldset>
178
+ <fieldset class="options">
179
+ <legend><?php _e('Sorting Of Poll Results'); ?></legend>
180
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
181
+ <tr valign="top">
182
+ <th scope="row" width="40%"><?php _e('Sort Poll Results By:'); ?></th>
183
+ <td>
184
+ <select name="poll_ans_result_sortby" size="1">
185
+ <option value="polla_votes"<?php selected('polla_votes', get_settings('poll_ans_result_sortby')); ?>><?php _e('Votes'); ?></option>
186
+ <option value="polla_aid"<?php selected('polla_aid', get_settings('poll_ans_result_sortby')); ?>><?php _e('Exact Order'); ?></option>
187
+ <option value="polla_answers"<?php selected('polla_answers', get_settings('poll_ans_result_sortby')); ?>><?php _e('Alphabetical Order'); ?></option>
188
+ </select>
189
+ </td>
190
+ </tr>
191
+ <tr valign="top">
192
+ <th scope="row" width="40%"><?php _e('Sort Order Of Poll Results:'); ?></th>
193
+ <td>
194
+ <select name="poll_ans_result_sortorder" size="1">
195
+ <option value="asc"<?php selected('asc', get_settings('poll_ans_result_sortorder')); ?>><?php _e('Ascending'); ?></option>
196
+ <option value="desc"<?php selected('desc', get_settings('poll_ans_result_sortorder')); ?>><?php _e('Descending'); ?></option>
197
+ </select>
198
+ </td>
199
+ </tr>
200
+ </table>
201
+ </fieldset>
202
+ <fieldset class="options">
203
+ <legend><?php _e('Poll Archive'); ?></legend>
204
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
205
+ <tr valign="top">
206
+ <th scope="row" width="40%"><?php _e('Polls Per Page:'); ?></th>
207
+ <td><input type="text" name="poll_archive_perpage" value="<?php form_option('poll_archive_perpage'); ?>" size="2" /></td>
208
+ </tr>
209
+ </table>
210
+ </fieldset>
211
+ <fieldset class="options">
212
+ <legend><?php _e('Current Active Poll'); ?></legend>
213
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
214
+ <tr valign="top">
215
+ <th scope="row" width="40%"><?php _e('Current Active Poll:'); ?></th>
216
+ <td>
217
+ <select name="poll_currentpoll" size="1">
218
+ <option value="-1"<?php selected('-1', get_settings('poll_currentpoll')); ?>><?php _e('Do NOT Display Poll (Disable)'); ?></option>
219
+ <option value="0"<?php selected('0', get_settings('poll_currentpoll')); ?>><?php _e('Display Latest Poll'); ?></option>
220
+ <option value="0"></option>
221
+ <?php
222
+ $polls = $wpdb->get_results("SELECT pollq_id, pollq_question FROM $wpdb->pollsq ORDER BY pollq_id DESC");
223
+ if($polls) {
224
+ foreach($polls as $poll) {
225
+ $poll_question = stripslashes($poll->pollq_question);
226
+ $poll_id = intval($poll->pollq_id);
227
+ if($poll_id == intval(get_settings('poll_currentpoll'))) {
228
+ echo "<option value=\"$poll_id\" selected=\"selected\">$poll_question</option>\n";
229
+ } else {
230
+ echo "<option value=\"$poll_id\">$poll_question</option>\n";
231
+ }
232
+ }
233
+ }
234
+ ?>
235
+ </select>
236
+ </td>
237
+ </tr>
238
+ </table>
239
+ </fieldset>
240
+ <fieldset class="options">
241
+ <legend><?php _e('Template Variables'); ?></legend>
242
+ <table width="100%" cellspacing="2" cellpadding="5" align="center">
243
+ <tr>
244
+ <td><b>%POLL_ID%</b> - <?php _e('Display the poll\'s ID'); ?></td>
245
+ <td><b>%POLL_ANSWER_ID%</b> - <?php _e('Display the poll\'s answer ID'); ?></td>
246
+ </tr>
247
+ <tr>
248
+ <td><b>%POLL_QUESTION%</b> - <?php _e('Display the poll\'s question'); ?></td>
249
+ <td><b>%POLL_ANSWER%</b> - <?php _e('Display the poll\'s answer'); ?></td>
250
+ </tr>
251
+ <tr>
252
+ <td><b>%POLL_TOTALVOTES%</b> - <?php _e('Display the poll\'s total votes'); ?></td>
253
+ <td><b>%POLL_ANSWER_VOTES%</b> - <?php _e('Display the poll\'s answer votes'); ?></td>
254
+ </tr>
255
+ <tr>
256
+ <td>&nbsp;</td>
257
+ <td><b>%POLL_ANSWER_PERCENTAGE%</b> - <?php _e('Display the poll\'s answer percentage'); ?></td>
258
+ </tr>
259
+ <tr>
260
+ <td>&nbsp;</td>
261
+ <td><b>"%POLL_ANSWER_IMAGEWIDTH%</b> - <?php _e('Display the poll\'s answer image width'); ?></td>
262
+ </tr>
263
+ </table>
264
+ </fieldset>
265
+ <fieldset class="options">
266
+ <legend><?php _e('Poll Voting Form Templates'); ?></legend>
267
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
268
+ <tr valign="top">
269
+ <td width="30%" align="left">
270
+ <b><?php _e('Voting Form Header:'); ?></b><br /><br /><br />
271
+ <?php _e('Allowed Variables:'); ?><br />
272
+ - %POLL_ID%<br />
273
+ - %POLL_QUESTION%<br />
274
+ - %POLL_TOTALVOTES%<br /><br />
275
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('voteheader');" class="button" />
276
+ </td>
277
+ <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>
278
+ </tr>
279
+ <tr valign="top">
280
+ <td width="30%" align="left">
281
+ <b><?php _e('Voting Form Body:'); ?></b><br /><br /><br />
282
+ <?php _e('Allowed Variables:'); ?><br />
283
+ - %POLL_ID%<br />
284
+ - %POLL_ANSWER_ID%<br />
285
+ - %POLL_ANSWER%<br />
286
+ - %POLL_ANSWER_VOTES%<br /><br />
287
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('votebody');" class="button" />
288
+ </td>
289
+ <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>
290
+ </tr>
291
+ <tr valign="top">
292
+ <td width="30%" align="left">
293
+ <b><?php _e('Voting Form Footer:'); ?></b><br /><br /><br />
294
+ <?php _e('Allowed Variables:'); ?><br />
295
+ - N/A<br /><br />
296
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('votefooter');" class="button" />
297
+ </td>
298
+ <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>
299
+ </tr>
300
+ </table>
301
+ </fieldset>
302
+ <fieldset class="options">
303
+ <legend><?php _e('Poll Result Templates'); ?></legend>
304
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
305
+ <tr valign="top">
306
+ <td width="30%" align="left">
307
+ <b><?php _e('Result Header:'); ?></b><br /><br /><br />
308
+ <?php _e('Allowed Variables:'); ?><br />
309
+ - %POLL_ID%<br />
310
+ - %POLL_QUESTION%<br />
311
+ - %POLL_TOTALVOTES%<br /><br />
312
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultheader');" class="button" />
313
+ </td>
314
+ <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>
315
+ </tr>
316
+ <tr valign="top">
317
+ <td width="30%" align="left">
318
+ <b><?php _e('Result Body:'); ?></b><br /><?php _e('Normal'); ?><br /><br />
319
+ <?php _e('Allowed Variables:'); ?><br />
320
+ - %POLL_ANSWER_ID%<br />
321
+ - %POLL_ANSWER%<br />
322
+ - %POLL_ANSWER_VOTES%<br />
323
+ - %POLL_ANSWER_PERCENTAGE%<br />
324
+ - %POLL_ANSWER_IMAGEWIDTH%<br /><br />
325
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultbody');" class="button" />
326
+ </td>
327
+ <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>
328
+ </tr>
329
+ <tr valign="top">
330
+ <td width="30%" align="left">
331
+ <b><?php _e('Result Body:'); ?></b><br /><?php _e('Displaying Of User\'s Voted Answer'); ?><br /><br />
332
+ <?php _e('Allowed Variables:'); ?><br />
333
+ - %POLL_ANSWER_ID%<br />
334
+ - %POLL_ANSWER%<br />
335
+ - %POLL_ANSWER_VOTES%<br />
336
+ - %POLL_ANSWER_PERCENTAGE%<br />
337
+ - %POLL_ANSWER_IMAGEWIDTH%<br /><br />
338
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultbody2');" class="button" />
339
+ </td>
340
+ <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>
341
+ </tr>
342
+ <tr valign="top">
343
+ <td width="30%" align="left">
344
+ <b><?php _e('Result Footer:'); ?></b><br /><br /><br />
345
+ <?php _e('Allowed Variables:'); ?><br />
346
+ - %POLL_TOTALVOTES%<br /><br />
347
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('resultfooter');" class="button" />
348
+ </td>
349
+ <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>
350
+ </tr>
351
+ </table>
352
+ </fieldset>
353
+ <fieldset class="options">
354
+ <legend><?php _e('Poll Misc Templates'); ?></legend>
355
+ <table width="100%" cellspacing="2" cellpadding="5" class="editform">
356
+ <tr valign="top">
357
+ <td width="30%" align="left">
358
+ <b><?php _e('Poll Disabled'); ?></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('disable');" class="button" />
362
+ </td>
363
+ <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>
364
+ </tr>
365
+ <tr valign="top">
366
+ <td width="30%" align="left">
367
+ <b><?php _e('Poll Error'); ?></b><br /><br /><br />
368
+ <?php _e('Allowed Variables:'); ?><br />
369
+ - N/A<br /><br />
370
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template'); ?>" onclick="javascript: poll_default_templates('error');" class="button" />
371
+ </td>
372
+ <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>
373
+ </tr>
374
+ </table>
375
+ </fieldset>
376
+ <p class="submit">
377
+ <input type="submit" name="Submit" value="<?php _e('Update Options'); ?> &raquo;" />
378
+ </p>
379
+ </form>
380
+ </div>
381
+ <?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.03 |
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.03 |
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', '3', 'An error has occurred when processing your poll.', '20', '8', 'Template For Poll When An Error Has Occured', '8', '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 Version 2.03.');
46
+ }
47
+ if(empty($wpdb->pollsq) || empty($wpdb->pollsa) || empty($wpdb->pollsip)) {
48
+ $error = __('Please Define The pollsq, pollsa and pollsip 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.03</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.03'); ?></h2>
63
+ <p><?php _e('This upgrade script will upgrade WP-Polls from version 2.00 or 2.01 to version 2.03 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.03.').'</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.03'); ?>" 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.03 |
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.03 |
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=\\\"index.php?pollresult=1\\\">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 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.03'); ?></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.03'); ?></h2>
95
+ <p><?php _e('This upgrade script will upgrade WP-Polls to version 2.03 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.03.').'</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.03'); ?>" 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,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.03
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 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', 1, 'polls-manager.php');
41
+ }
42
+ if (function_exists('add_submenu_page')) {
43
+ add_submenu_page('polls-manager.php', __('Manage Polls'), __('Manage Polls'), 1, 'polls-manager.php');
44
+ add_submenu_page('polls-manager.php', __('Poll Option'), __('Poll Option'), 1, 'polls-options.php');
45
+ }
46
+ }
47
+
48
+
49
+ ### Function: Get Poll
50
+ function get_poll($temp_poll_id = 0) {
51
+ global $wpdb;
52
+ // Check Whether Poll Is Disabled
53
+ if(intval(get_settings('poll_currentpoll')) == -1) {
54
+ echo stripslashes(get_settings('poll_template_disable'));
55
+ return;
56
+ // Poll Is Enabled
57
+ } else {
58
+ // Hardcoded Poll ID Is Not Specified
59
+ if(intval($temp_poll_id) == 0) {
60
+ // Current Poll ID Is Not Specified
61
+ if(intval(get_settings('poll_currentpoll')) == 0) {
62
+ // Get Lastest Poll ID
63
+ $poll_id = intval(get_settings('poll_latestpoll'));
64
+ } else {
65
+ // Get Current Poll ID
66
+ $poll_id = intval(get_settings('poll_currentpoll'));
67
+ }
68
+ // Get Hardcoded Poll ID
69
+ } else {
70
+ $poll_id = intval($temp_poll_id);
71
+ }
72
+ }
73
+
74
+ // User Click on View Results Link
75
+ if(intval($_GET['pollresult']) == 1) {
76
+ display_pollresult($poll_id);
77
+ // Check Whether User Has Voted
78
+ } else {
79
+ // Check Cookie First
80
+ $voted_cookie = check_voted_cookie($poll_id);
81
+ if($voted_cookie > 0) {
82
+ display_pollresult($poll_id, $voted_cookie);
83
+ // Check IP If Cookie Cannot Be Found
84
+ } else {
85
+ $voted_ip = check_voted_ip($poll_id);
86
+ if($voted_ip > 0) {
87
+ display_pollresult($poll_id, $voted_ip);
88
+ // User Never Vote. Display Poll Voting Form
89
+ } else {
90
+ display_pollvote($poll_id);
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+
97
+ ### Function: Check Voted By Cookie
98
+ function check_voted_cookie($poll_id) {
99
+ // 0: False | > 0: True
100
+ return intval($_COOKIE["voted_$poll_id"]);
101
+ }
102
+
103
+
104
+ ### Function: Check Voted By IP
105
+ function check_voted_ip($poll_id) {
106
+ global $wpdb;
107
+ // Check IP From IP Logging Database
108
+ $get_voted_aid = $wpdb->get_var("SELECT pollip_aid FROM $wpdb->pollsip WHERE pollip_qid = $poll_id AND pollip_ip = '".get_ipaddress()."'");
109
+ // 0: False | > 0: True
110
+ return intval($get_voted_aid);
111
+ }
112
+
113
+
114
+ ### Function: Display Voting Form
115
+ function display_pollvote($poll_id) {
116
+ global $wpdb;
117
+ // Get Poll Question Data
118
+ $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
119
+ // Poll Question Variables
120
+ $poll_question_text = stripslashes($poll_question->pollq_question);
121
+ $poll_question_id = intval($poll_question->pollq_id);
122
+ $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
123
+ $template_question = stripslashes(get_settings('poll_template_voteheader'));
124
+ $template_question = str_replace("%POLL_QUESTION%", $poll_question_text, $template_question);
125
+ $template_question = str_replace("%POLL_ID%", $poll_question_id, $template_question);
126
+ $template_question = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_question);
127
+ // Get Poll Answers Data
128
+ $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'));
129
+ // If There Is Poll Question With Answers
130
+ if($poll_question && $poll_answers) {
131
+ // Display Poll Voting Form
132
+ echo '<form action="'.$_SERVER['REQUEST_URI'].'" name="polls" method="post">'."\n";
133
+ echo "<input type=\"hidden\" name=\"poll_id\" value=\"$poll_question_id\" />\n";
134
+ // Print Out Voting Form Header Template
135
+ echo $template_question;
136
+ foreach($poll_answers as $poll_answer) {
137
+ // Poll Answer Variables
138
+ $poll_answer_id = intval($poll_answer->polla_aid);
139
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
140
+ $poll_answer_votes = intval($poll_answer->polla_votes);
141
+ $template_answer = stripslashes(get_settings('poll_template_votebody'));
142
+ $template_answer = str_replace("%POLL_ID%", $poll_question_id, $template_answer);
143
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
144
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
145
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $poll_answer_votes, $template_answer);
146
+ // Print Out Voting Form Body Template
147
+ echo $template_answer;
148
+ }
149
+ // Voting Form Footer Variables
150
+ $template_footer = stripslashes(get_settings('poll_template_votefooter'));
151
+ // Print Out Voting Form Footer Template
152
+ echo $template_footer;
153
+ echo "</form>\n";
154
+ } else {
155
+ echo stripslashes(get_settings('poll_template_disable'));
156
+ }
157
+ }
158
+
159
+
160
+ ### Function: Display Results Form
161
+ function display_pollresult($poll_id, $user_voted = 0) {
162
+ global $wpdb;
163
+ // Get Poll Question Data
164
+ $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes FROM $wpdb->pollsq WHERE pollq_id = $poll_id LIMIT 1");
165
+ // Poll Question Variables
166
+ $poll_question_text = stripslashes($poll_question->pollq_question);
167
+ $poll_question_id = intval($poll_question->pollq_id);
168
+ $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
169
+ $template_question = stripslashes(get_settings('poll_template_resultheader'));
170
+ $template_question = str_replace("%POLL_QUESTION%", $poll_question_text, $template_question);
171
+ $template_question = str_replace("%POLL_ID%", $poll_question_id, $template_question);
172
+ $template_question = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_question);
173
+ // Get Poll Answers Data
174
+ $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'));
175
+ // If There Is Poll Question With Answers
176
+ if($poll_question && $poll_answers) {
177
+ // Is The Poll Total Votes 0?
178
+ $poll_totalvotes_zero = true;
179
+ if($poll_question_totalvotes > 0) {
180
+ $poll_totalvotes_zero = false;
181
+ }
182
+ // Print Out Result Header Template
183
+ echo $template_question;
184
+ foreach($poll_answers as $poll_answer) {
185
+ // Poll Answer Variables
186
+ $poll_answer_id = intval($poll_answer->polla_aid);
187
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
188
+ $poll_answer_votes = intval($poll_answer->polla_votes);
189
+ $poll_answer_text = stripslashes($poll_answer->polla_answers);
190
+ $poll_answer_percentage = 0;
191
+ $poll_answer_imagewidth = 0;
192
+ // Calculate Percentage And Image Bar Width
193
+ if(!$poll_totalvotes_zero) {
194
+ if($poll_answer_votes > 0) {
195
+ $poll_answer_percentage = round((($poll_answer_votes/$poll_question_totalvotes)*100));
196
+ $poll_answer_imagewidth = round($poll_answer_percentage*0.9);
197
+ } else {
198
+ $poll_answer_percentage = 0;
199
+ $poll_answer_imagewidth = 1;
200
+ }
201
+ } else {
202
+ $poll_answer_percentage = 0;
203
+ $poll_answer_imagewidth = 1;
204
+ }
205
+ // Let User See What Options They Voted
206
+ if($user_voted == $poll_answer_id) {
207
+ // Results Body Variables
208
+ $template_answer = stripslashes(get_settings('poll_template_resultbody2'));
209
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
210
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
211
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $poll_answer_votes, $template_answer);
212
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
213
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
214
+ // Print Out Results Body Template
215
+ echo $template_answer;
216
+ } else {
217
+ // Results Body Variables
218
+ $template_answer = stripslashes(get_settings('poll_template_resultbody'));
219
+ $template_answer = str_replace("%POLL_ANSWER_ID%", $poll_answer_id, $template_answer);
220
+ $template_answer = str_replace("%POLL_ANSWER%", $poll_answer_text, $template_answer);
221
+ $template_answer = str_replace("%POLL_ANSWER_VOTES%", $poll_answer_votes, $template_answer);
222
+ $template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer);
223
+ $template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer);
224
+ // Print Out Results Body Template
225
+ echo $template_answer;
226
+ }
227
+ }
228
+ // Results Footer Variables
229
+ $template_footer = stripslashes(get_settings('poll_template_resultfooter'));
230
+ $template_footer = str_replace("%POLL_TOTALVOTES%", $poll_question_totalvotes, $template_footer);
231
+ // Print Out Results Footer Template
232
+ echo $template_footer;
233
+ } else {
234
+ echo stripslashes(get_settings('poll_template_disable'));
235
+ }
236
+ }
237
+
238
+
239
+ ### Function: Vote Poll
240
+ add_action('wp_head', 'vote_poll');
241
+ function vote_poll() {
242
+ global $wpdb, $user_identity;
243
+ if(!empty($_POST['vote'])) {
244
+ $poll_id = intval($_POST['poll_id']);
245
+ $poll_aid = intval($_POST["poll-$poll_id"]);
246
+ if($poll_id > 0 && $poll_aid > 0) {
247
+ $voted_ip = check_voted_ip($poll_id);
248
+ $voted_cookie = check_voted_cookie($poll_ip);
249
+ if($voted_ip == 0 && $voted_cookie == 0) {
250
+ if(!empty($user_identity)) {
251
+ $pollip_user = addslashes($user_identity);
252
+ } elseif(!empty($_COOKIE['comment_author_'.COOKIEHASH])) {
253
+ $pollip_user = addslashes($_COOKIE['comment_author_'.COOKIEHASH]);
254
+ } else {
255
+ $pollip_user = 'Guest';
256
+ }
257
+ $vote_cookie = setcookie("voted_".$poll_id, $poll_aid, time() + 30000000, COOKIEPATH);
258
+ if($vote_cookie) {
259
+ $pollip_ip = get_ipaddress();
260
+ $pollip_host = gethostbyaddr($pollip_ip);
261
+ $pollip_timestamp = current_time('timestamp');
262
+ $vote_ip = $wpdb->query("INSERT INTO $wpdb->pollsip VALUES(0,$poll_id,$poll_aid,'$pollip_ip','$pollip_host','$pollip_timestamp','$pollip_user')");
263
+ if($vote_ip) {
264
+ $vote_a = $wpdb->query("UPDATE $wpdb->pollsa SET polla_votes = (polla_votes+1) WHERE polla_qid = $poll_id AND polla_aid = $poll_aid");
265
+ if($vote_a) {
266
+ $vote_q = $wpdb->query("UPDATE $wpdb->pollsq SET pollq_totalvotes = (pollq_totalvotes+1) WHERE pollq_id = $poll_id");
267
+ } // End if($vote_a)
268
+ } // End if($vote_ip)
269
+ } // End if($vote_cookie)
270
+ }// End if($voted_ip == 0 && $voted_cookie == 0)
271
+ } // End if(!empty($_POST['vote']))
272
+ } // End if($poll_id > 0 && $poll_aid > 0)
273
+ }
274
+
275
+
276
+ ### Function: Get IP Address
277
+ function get_ipaddress() {
278
+ if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
279
+ $ip_address = $_SERVER["REMOTE_ADDR"];
280
+ } else {
281
+ $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
282
+ }
283
+ if(strpos($ip_address, ',') !== false) {
284
+ $ip_address = explode(',', $ip_address);
285
+ $ip_address = $ip_address[0];
286
+ }
287
+ return $ip_address;
288
+ }
289
+ ?>
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
65
+ poll id.
66
+ ------------------------------------------------------------------
readme-upgrade.txt ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Upgrade Instructions For Version 2.02 To Version 2.03
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
+ // Open Wordpress root folder
20
+
21
+ Overwrite:
22
+ ------------------------------------------------------------------
23
+ wp-polls.php
24
+ ------------------------------------------------------------------
25
+
26
+
27
+ // Open wp-includes/images folder
28
+
29
+ Put:
30
+ ------------------------------------------------------------------
31
+ pollbar.gif
32
+ ------------------------------------------------------------------
33
+
34
+
35
+ // Remove Previous Traces Of Poll Code In Your Theme
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ -> Upgrade Instructions FOr Version 2.01 To Version 2.02
44
+ ------------------------------------------------------------------
45
+ // Open wp-admin folder
46
+
47
+ Put:
48
+ ------------------------------------------------------------------
49
+ polls-upgrade-202.php
50
+ ------------------------------------------------------------------
51
+
52
+ // Run wp-admin/polls-upgrade-202.php
53
+
54
+ Note:
55
+ ------------------------------------------------------------------
56
+ Please remember to remove polls-upgrade-202.php after installation.
57
+ ------------------------------------------------------------------
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+ -> Upgrade Instructions For Version 1.0x To Version 2.01
69
+ ------------------------------------------------------------------
70
+ // Open wp-admin folder
71
+
72
+ Put/Overwrite:
73
+ ------------------------------------------------------------------
74
+ polls-upgrade.php
75
+ polls-manager.php
76
+ polls-options.php
77
+ ------------------------------------------------------------------
78
+
79
+
80
+ // Open wp-content/plugins folder
81
+
82
+ Put/Overwrite:
83
+ ------------------------------------------------------------------
84
+ polls.php
85
+ ------------------------------------------------------------------
86
+
87
+
88
+ // Open Wordpress root folder
89
+
90
+ Put/Overwrite:
91
+ ------------------------------------------------------------------
92
+ wp-polls.php
93
+ ------------------------------------------------------------------
94
+
95
+
96
+ // Open wp-includes/images folder
97
+
98
+ Put:
99
+ ------------------------------------------------------------------
100
+ pollbar.gif
101
+ ------------------------------------------------------------------
102
+
103
+
104
+ // Run wp-admin/polls-upgrade.php
105
+
106
+ Note:
107
+ ------------------------------------------------------------------
108
+ Please remember to remove polls-upgrade.php after installation.
109
+ ------------------------------------------------------------------
readme.txt ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Polls Plugin For WordPress 2.0
2
+ --------------------------------------------------
3
+ Author -> Lester 'GaMerZ' Chan
4
+ Email -> lesterch@singnet.com.sg
5
+ Website -> http://www.lesterchan.net/
6
+ Demo -> http://www.lesterchan.net/blogs
7
+ Updated -> 1st January 2006
8
+ --------------------------------------------------
9
+
10
+
11
+ // Version 2.03 (01-01-2006)
12
+ - NEW: Compatible With WordPress 2.0
13
+ - NEW: Poll Administration Menu Added Automatically Upon Activating The Plugin
14
+ - NEW: Removed Add Poll Link From The Administration Menu
15
+ - NEW: GPL License Added
16
+ - NEW: Page Title Added To wp-polls.php
17
+
18
+ // Version 2.02a (17-11-2005)
19
+ - FIXED: poll-install.php And poll-upgrade.php will Now Be Installed/Upgraded To 2.02 Instead Of 2.01
20
+
21
+ // Version 2.02 (05-11-2005)
22
+ - FIXED: Showing 0 Vote On Poll Edit Page
23
+ - FIXED: Null Vote Being Counted As A Vote
24
+ - FIXED: Auto Loading Of Poll Option: Polls Per Page In Poll Archive Page Is Now "No"
25
+ - NEW: Host Column In Poll IP Table To Prevent Network Lagging When Resolving IP
26
+ - NEW: New Poll Error Template
27
+
28
+ // Version 2.01 (25-10-2005)
29
+ - FIXED: Upgrade Script To Insert Lastest Poll ID Of User's Current Polls, Instead Of Poll ID 1
30
+ - FIXED: Replace All <?= With <?php
31
+ - FIXED: Added addalshes() To $pollip_user
32
+ - FIXED: Better Localization Support (80% Done, Will Leave It In The Mean Time)
33
+
34
+ // Version 2.0 (20-10-2005)
35
+ - NEW: IP Logging
36
+ - NEW: Poll Options: Sorting Of Answers In Voting Form
37
+ - NEW: Poll Options: Sorting Of Answers In Results View
38
+ - NEW: Poll Options: Number Of Polls Per Page In Poll Archive
39
+ - NEW: Poll Options: Choose Poll To Display On Index Page
40
+ - NEW: Poll Options: Able To Disable Poll With Custom Message
41
+ - NEW: Poll Options: Poll Templates
42
+ - NEW: Display User's Voted Choice
43
+ - 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.03 |
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
+ ?>