WP-Polls - Version 2.06

Version Description

Download this release

Release Info

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

Version 2.06

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