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