| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
|
| 5 |
+----------------------------------------------------------------+ |
| 6 |
|
| 7 |
| | |
| 8 |
|
| 9 |
| WordPress 2.0 Plugin: WP-Polls 2.06 | |
| 10 |
|
| 11 |
| Copyright (c) 2005 Lester "GaMerZ" Chan | |
| 12 |
|
| 13 |
| | |
| 14 |
|
| 15 |
| File Written By: | |
| 16 |
|
| 17 |
| - Lester "GaMerZ" Chan | |
| 18 |
|
| 19 |
| - http://www.lesterchan.net | |
| 20 |
|
| 21 |
| | |
| 22 |
|
| 23 |
| File Information: | |
| 24 |
|
| 25 |
| - Poll Archive | |
| 26 |
|
| 27 |
| - wp-polls.php | |
| 28 |
|
| 29 |
| | |
| 30 |
|
| 31 |
+----------------------------------------------------------------+ |
| 32 |
|
| 33 |
*/ |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
### Wordpress Header |
| 40 |
|
| 41 |
require(dirname(__FILE__).'/wp-blog-header.php'); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
### Function: Poll Page Title |
| 46 |
|
| 47 |
add_filter('wp_title', 'poll_pagetitle'); |
| 48 |
|
| 49 |
function poll_pagetitle($poll_pagetitle) { |
| 50 |
|
| 51 |
return $poll_pagetitle.' » Polls'; |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
### Polls Variables |
| 58 |
|
| 59 |
$page = intval($_GET['page']); |
| 60 |
|
| 61 |
$polls_questions = array(); |
| 62 |
|
| 63 |
$polls_answers = array(); |
| 64 |
|
| 65 |
$polls_ip = array(); |
| 66 |
|
| 67 |
$polls_perpage = intval(get_settings('poll_archive_perpage')); |
| 68 |
|
| 69 |
$poll_questions_ids = '0'; |
| 70 |
|
| 71 |
$poll_voted = false; |
| 72 |
|
| 73 |
$poll_voted_aid = 0; |
| 74 |
|
| 75 |
$poll_id = 0; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
### Get Total Polls |
| 80 |
|
| 81 |
$total_polls = $wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq"); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
### Checking $page and $offset |
| 86 |
|
| 87 |
if (empty($page) || $page == 0) { $page = 1; } |
| 88 |
|
| 89 |
if (empty($offset)) { $offset = 0; } |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
### Determin $offset |
| 94 |
|
| 95 |
$offset = ($page-1) * $polls_perpage; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
### Determine Max Number Of Polls To Display On Page |
| 100 |
|
| 101 |
if(($offset + $polls_perpage) > $total_polls) { |
| 102 |
|
| 103 |
$max_on_page = $total_polls; |
| 104 |
|
| 105 |
} else { |
| 106 |
|
| 107 |
$max_on_page = ($offset + $polls_perpage); |
| 108 |
|
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
### Determine Number Of Polls To Display On Page |
| 114 |
|
| 115 |
if (($offset + 1) > ($total_polls)) { |
| 116 |
|
| 117 |
$display_on_page = $total_polls; |
| 118 |
|
| 119 |
} else { |
| 120 |
|
| 121 |
$display_on_page = ($offset + 1); |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
### Determing Total Amount Of Pages |
| 128 |
|
| 129 |
$total_pages = ceil($total_polls / $polls_perpage); |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
### Make Sure Poll Is Not Disabled |
| 134 |
|
| 135 |
if(intval(get_settings('poll_currentpoll')) != -1 && $page < 2) { |
| 136 |
|
| 137 |
// Hardcoded Poll ID Is Not Specified |
| 138 |
|
| 139 |
if(intval($temp_poll_id) == 0) { |
| 140 |
|
| 141 |
// Random Poll |
| 142 |
if(intval(get_settings('poll_currentpoll')) == -2) { |
| 143 |
$random_poll_id = $wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq ORDER BY RAND() LIMIT 1"); |
| 144 |
$poll_id = intval($random_poll_id); |
| 145 |
// Current Poll ID Is Not Specified |
| 146 |
|
| 147 |
} else if(intval(get_settings('poll_currentpoll')) == 0) { |
| 148 |
|
| 149 |
// Get Lastest Poll ID |
| 150 |
|
| 151 |
$poll_id = intval(get_settings('poll_latestpoll')); |
| 152 |
|
| 153 |
} else { |
| 154 |
|
| 155 |
// Get Current Poll ID |
| 156 |
|
| 157 |
$poll_id = intval(get_settings('poll_currentpoll')); |
| 158 |
|
| 159 |
} |
| 160 |
|
| 161 |
// Get Hardcoded Poll ID |
| 162 |
|
| 163 |
} else { |
| 164 |
|
| 165 |
$poll_id = intval($temp_poll_id); |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
### Get Poll Questions |
| 174 |
|
| 175 |
$questions = $wpdb->get_results("SELECT * FROM $wpdb->pollsq WHERE pollq_id != $poll_id ORDER BY pollq_id DESC LIMIT $offset, $polls_perpage"); |
| 176 |
|
| 177 |
if($questions) { |
| 178 |
|
| 179 |
foreach($questions as $question) { |
| 180 |
|
| 181 |
$polls_questions[] = array('id' => intval($question->pollq_id), 'question' => stripslashes($question->pollq_question), 'timestamp' => $question->pollq_timestamp, 'totalvotes' => intval($question->pollq_totalvotes)); |
| 182 |
|
| 183 |
$poll_questions_ids .= intval($question->pollq_id).', '; |
| 184 |
|
| 185 |
} |
| 186 |
|
| 187 |
$poll_questions_ids = substr($poll_questions_ids, 0, -2); |
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
### Get Poll Answers |
| 194 |
|
| 195 |
$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')); |
| 196 |
|
| 197 |
if($answers) { |
| 198 |
|
| 199 |
foreach($answers as $answer) { |
| 200 |
|
| 201 |
$polls_answers[] = array('aid' => intval($answer->polla_aid), 'qid' => intval($answer->polla_qid), 'answers' => stripslashes($answer->polla_answers), 'votes' => intval($answer->polla_votes)); |
| 202 |
|
| 203 |
} |
| 204 |
|
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
### Get Poll IPs |
| 210 |
|
| 211 |
$ips = $wpdb->get_results("SELECT pollip_qid, pollip_aid FROM $wpdb->pollsip WHERE pollip_qid IN ($poll_questions_ids) AND pollip_ip = '".get_ipaddress()."'"); |
| 212 |
|
| 213 |
if($ips) { |
| 214 |
|
| 215 |
foreach($ips as $ip) { |
| 216 |
|
| 217 |
$polls_ips[] = array('qid' => intval($ip->pollip_qid), 'aid' => intval($ip->pollip_aid)); |
| 218 |
|
| 219 |
} |
| 220 |
|
| 221 |
} |
| 222 |
|
| 223 |
### Function: Check Voted To Get Voted Answer |
| 224 |
|
| 225 |
function check_voted($poll_id) { |
| 226 |
|
| 227 |
global $polls_ips; |
| 228 |
|
| 229 |
$temp_voted_aid = 0; |
| 230 |
|
| 231 |
if(intval($_COOKIE["voted_$poll_id"]) > 0) { |
| 232 |
|
| 233 |
$temp_voted_aid = intval($_COOKIE["voted_$poll_id"]); |
| 234 |
|
| 235 |
} else { |
| 236 |
|
| 237 |
if($polls_ips) { |
| 238 |
|
| 239 |
foreach($polls_ips as $polls_ip) { |
| 240 |
|
| 241 |
if($polls_ip['qid'] == $poll_id) { |
| 242 |
|
| 243 |
$temp_voted_aid = $polls_ip['aid']; |
| 244 |
|
| 245 |
} |
| 246 |
|
| 247 |
} |
| 248 |
|
| 249 |
} |
| 250 |
|
| 251 |
} |
| 252 |
|
| 253 |
return $temp_voted_aid; |
| 254 |
|
| 255 |
} |
| 256 |
|
| 257 |
?> |
| 258 |
|
| 259 |
<?php get_header(); ?> |
| 260 |
|
| 261 |
<div id="content" class="narrowcolumn"> |
| 262 |
|
| 263 |
<?php |
| 264 |
|
| 265 |
if($page < 2) { |
| 266 |
|
| 267 |
echo "<!-- <Currrent Poll> -->\n"; |
| 268 |
|
| 269 |
echo '<h2 class="pagetitle">'.__('Current Poll').'</h2>'."\n"; |
| 270 |
|
| 271 |
// Current Poll |
| 272 |
|
| 273 |
if(intval(get_settings('poll_currentpoll')) == -1) { |
| 274 |
|
| 275 |
echo get_settings('poll_template_disable'); |
| 276 |
|
| 277 |
} else { |
| 278 |
|
| 279 |
// User Click on View Results Link |
| 280 |
|
| 281 |
if(intval($_GET['pollresult']) == $poll_id) { |
| 282 |
|
| 283 |
echo display_pollresult($poll_id); |
| 284 |
|
| 285 |
// Check Whether User Has Voted |
| 286 |
|
| 287 |
} else { |
| 288 |
|
| 289 |
// Check Cookie First |
| 290 |
|
| 291 |
$voted_cookie = check_voted_cookie($poll_id); |
| 292 |
|
| 293 |
if($voted_cookie > 0) { |
| 294 |
|
| 295 |
echo display_pollresult($poll_id, $voted_cookie); |
| 296 |
|
| 297 |
// Check IP If Cookie Cannot Be Found |
| 298 |
|
| 299 |
} else { |
| 300 |
|
| 301 |
$voted_ip = check_voted_ip($poll_id); |
| 302 |
|
| 303 |
if($voted_ip > 0) { |
| 304 |
|
| 305 |
echo display_pollresult($poll_id, $voted_ip); |
| 306 |
|
| 307 |
// User Never Vote. Display Poll Voting Form |
| 308 |
|
| 309 |
} else { |
| 310 |
|
| 311 |
echo display_pollvote($poll_id); |
| 312 |
|
| 313 |
} |
| 314 |
|
| 315 |
} |
| 316 |
|
| 317 |
} |
| 318 |
|
| 319 |
} |
| 320 |
|
| 321 |
echo "<!-- </Currrent Poll> -->\n"; |
| 322 |
|
| 323 |
} |
| 324 |
|
| 325 |
?> |
| 326 |
|
| 327 |
<!-- <Poll Archives> --> |
| 328 |
|
| 329 |
<h2 class="pagetitle"><?php _e('Polls Archive'); ?></h2> |
| 330 |
|
| 331 |
<?php |
| 332 |
|
| 333 |
foreach($polls_questions as $polls_question) { |
| 334 |
|
| 335 |
// Most/Least Variables |
| 336 |
|
| 337 |
$poll_most_answer = ''; |
| 338 |
|
| 339 |
$poll_most_votes = 0; |
| 340 |
|
| 341 |
$poll_most_percentage = 0; |
| 342 |
|
| 343 |
$poll_least_answer = ''; |
| 344 |
|
| 345 |
$poll_least_votes = 0; |
| 346 |
|
| 347 |
$poll_least_percentage = 0; |
| 348 |
|
| 349 |
// Is The Poll Total Votes 0? |
| 350 |
|
| 351 |
$poll_totalvotes_zero = true; |
| 352 |
|
| 353 |
if($polls_question['totalvotes'] > 0) { |
| 354 |
|
| 355 |
$poll_totalvotes_zero = false; |
| 356 |
|
| 357 |
} |
| 358 |
|
| 359 |
// Poll Question Variables |
| 360 |
|
| 361 |
$template_question = stripslashes(get_settings('poll_template_resultheader')); |
| 362 |
|
| 363 |
$template_question = str_replace("%POLL_QUESTION%", $polls_question['question'], $template_question); |
| 364 |
|
| 365 |
$template_question = str_replace("%POLL_ID%", $polls_question['id'], $template_question); |
| 366 |
|
| 367 |
$template_question = str_replace("%POLL_TOTALVOTES%", $polls_question['totalvotes'], $template_question); |
| 368 |
|
| 369 |
// Print Out Result Header Template |
| 370 |
|
| 371 |
echo $template_question; |
| 372 |
|
| 373 |
foreach($polls_answers as $polls_answer) { |
| 374 |
|
| 375 |
if($polls_question['id'] == $polls_answer['qid']) { |
| 376 |
|
| 377 |
// Calculate Percentage And Image Bar Width |
| 378 |
|
| 379 |
if(!$poll_totalvotes_zero) { |
| 380 |
|
| 381 |
if($polls_answer['votes'] > 0) { |
| 382 |
|
| 383 |
$poll_answer_percentage = round((($polls_answer['votes']/$polls_question['totalvotes'])*100)); |
| 384 |
|
| 385 |
$poll_answer_imagewidth = round($poll_answer_percentage*0.9); |
| 386 |
|
| 387 |
} else { |
| 388 |
|
| 389 |
$poll_answer_percentage = 0; |
| 390 |
|
| 391 |
$poll_answer_imagewidth = 1; |
| 392 |
|
| 393 |
} |
| 394 |
|
| 395 |
} else { |
| 396 |
|
| 397 |
$poll_answer_percentage = 0; |
| 398 |
|
| 399 |
$poll_answer_imagewidth = 1; |
| 400 |
|
| 401 |
} |
| 402 |
|
| 403 |
// Let User See What Options They Voted |
| 404 |
|
| 405 |
if(check_voted($polls_question['id']) == $polls_answer['aid']) { |
| 406 |
|
| 407 |
// Results Body Variables |
| 408 |
|
| 409 |
$template_answer = stripslashes(get_settings('poll_template_resultbody2')); |
| 410 |
|
| 411 |
$template_answer = str_replace("%POLL_ANSWER_ID%", $polls_answer['aid'], $template_answer); |
| 412 |
|
| 413 |
$template_answer = str_replace("%POLL_ANSWER%", $polls_answer['answers'], $template_answer); |
| 414 |
|
| 415 |
$template_answer = str_replace("%POLL_ANSWER_VOTES%", $polls_answer['votes'], $template_answer); |
| 416 |
|
| 417 |
$template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer); |
| 418 |
|
| 419 |
$template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer); |
| 420 |
|
| 421 |
// Print Out Results Body Template |
| 422 |
|
| 423 |
echo $template_answer; |
| 424 |
|
| 425 |
} else { |
| 426 |
|
| 427 |
// Results Body Variables |
| 428 |
|
| 429 |
$template_answer = stripslashes(get_settings('poll_template_resultbody')); |
| 430 |
|
| 431 |
$template_answer = str_replace("%POLL_ANSWER_ID%", $polls_answer['aid'], $template_answer); |
| 432 |
|
| 433 |
$template_answer = str_replace("%POLL_ANSWER%", $polls_answer['answers'], $template_answer); |
| 434 |
|
| 435 |
$template_answer = str_replace("%POLL_ANSWER_VOTES%", $polls_answer['votes'], $template_answer); |
| 436 |
|
| 437 |
$template_answer = str_replace("%POLL_ANSWER_PERCENTAGE%", $poll_answer_percentage, $template_answer); |
| 438 |
|
| 439 |
$template_answer = str_replace("%POLL_ANSWER_IMAGEWIDTH%", $poll_answer_imagewidth, $template_answer); |
| 440 |
|
| 441 |
// Print Out Results Body Template |
| 442 |
|
| 443 |
echo $template_answer; |
| 444 |
|
| 445 |
} |
| 446 |
|
| 447 |
// Get Most Voted Data |
| 448 |
|
| 449 |
if($polls_answer['votes'] > $poll_most_votes) { |
| 450 |
|
| 451 |
$poll_most_answer = $polls_answer['answers']; |
| 452 |
|
| 453 |
$poll_most_votes = $polls_answer['votes']; |
| 454 |
|
| 455 |
$poll_most_percentage = $poll_answer_percentage; |
| 456 |
|
| 457 |
} |
| 458 |
|
| 459 |
// Get Least Voted Data |
| 460 |
|
| 461 |
if($poll_least_votes == 0) { |
| 462 |
|
| 463 |
$poll_least_votes = $polls_answer['votes']; |
| 464 |
|
| 465 |
} |
| 466 |
|
| 467 |
if($polls_answer['votes'] <= $poll_least_votes) { |
| 468 |
|
| 469 |
$poll_least_answer = $polls_answer['answers']; |
| 470 |
|
| 471 |
$poll_least_votes = $polls_answer['votes']; |
| 472 |
|
| 473 |
$poll_least_percentage = $poll_answer_percentage; |
| 474 |
|
| 475 |
} |
| 476 |
|
| 477 |
// Delete Away From Array |
| 478 |
|
| 479 |
unset($polls_answer['answers']); |
| 480 |
|
| 481 |
} |
| 482 |
|
| 483 |
} |
| 484 |
|
| 485 |
// Results Footer Variables |
| 486 |
|
| 487 |
$template_footer = stripslashes(get_settings('poll_template_resultfooter')); |
| 488 |
|
| 489 |
$template_footer = str_replace("%POLL_TOTALVOTES%", $polls_question['totalvotes'], $template_footer); |
| 490 |
|
| 491 |
$template_footer = str_replace("%POLL_MOST_ANSWER%", $poll_most_answer, $template_footer); |
| 492 |
|
| 493 |
$template_footer = str_replace("%POLL_MOST_VOTES%", number_format($poll_most_votes), $template_footer); |
| 494 |
|
| 495 |
$template_footer = str_replace("%POLL_MOST_PERCENTAGE%", $poll_most_percentage, $template_footer); |
| 496 |
|
| 497 |
$template_footer = str_replace("%POLL_LEAST_ANSWER%", $poll_least_answer, $template_footer); |
| 498 |
|
| 499 |
$template_footer = str_replace("%POLL_LEAST_VOTES%", number_format($poll_least_votes), $template_footer); |
| 500 |
|
| 501 |
$template_footer = str_replace("%POLL_LEAST_PERCENTAGE%", $poll_least_percentage, $template_footer); |
| 502 |
|
| 503 |
// Print Out Results Footer Template |
| 504 |
|
| 505 |
echo $template_footer; |
| 506 |
|
| 507 |
echo "<br />\n"; |
| 508 |
|
| 509 |
} |
| 510 |
|
| 511 |
?> |
| 512 |
|
| 513 |
<!-- </Poll Archives> --> |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
<!-- <Paging> --> |
| 518 |
|
| 519 |
<?php |
| 520 |
|
| 521 |
if($total_pages > 1) { |
| 522 |
|
| 523 |
?> |
| 524 |
|
| 525 |
<br /> |
| 526 |
|
| 527 |
<p> |
| 528 |
|
| 529 |
<span style="float: left;"> |
| 530 |
|
| 531 |
<?php |
| 532 |
|
| 533 |
if($page > 1 && ((($page*$polls_perpage)-($polls_perpage-1)) <= $total_polls)) { |
| 534 |
|
| 535 |
echo '<b>«</b> <a href="wp-polls.php?page='.($page-1).'" title="« '.__('Previous Page').'">'.__('Previous Page').'</a>'; |
| 536 |
|
| 537 |
} else { |
| 538 |
|
| 539 |
echo ' '; |
| 540 |
|
| 541 |
} |
| 542 |
|
| 543 |
?> |
| 544 |
|
| 545 |
</span> |
| 546 |
|
| 547 |
<span style="float: right;"> |
| 548 |
|
| 549 |
<?php |
| 550 |
|
| 551 |
if($page >= 1 && ((($page*$polls_perpage)+1) <= $total_polls)) { |
| 552 |
|
| 553 |
echo '<a href="wp-polls.php?page='.($page+1).'" title="'.__('Next Page').' »">'.__('Next Page').'</a> <b>»</b>'; |
| 554 |
|
| 555 |
} else { |
| 556 |
|
| 557 |
echo ' '; |
| 558 |
|
| 559 |
} |
| 560 |
|
| 561 |
?> |
| 562 |
|
| 563 |
</span> |
| 564 |
|
| 565 |
</p> |
| 566 |
|
| 567 |
<br style="clear: both;" /> |
| 568 |
|
| 569 |
<p> |
| 570 |
|
| 571 |
<?php _e('Pages'); ?> (<?php echo $total_pages; ?>) : |
| 572 |
|
| 573 |
<?php |
| 574 |
|
| 575 |
if ($page >= 4) { |
| 576 |
|
| 577 |
echo '<b><a href="wp-polls.php?page=1" title="'.__('Go to First Page').'">« '.__('First').'</a></b> ... '; |
| 578 |
|
| 579 |
} |
| 580 |
|
| 581 |
if($page > 1) { |
| 582 |
|
| 583 |
echo ' <b><a href="wp-polls.php?page='.($page-1).'" title="« '.__('Go to Page').' '.($page-1).'">«</a></b> '; |
| 584 |
|
| 585 |
} |
| 586 |
|
| 587 |
for($i = $page - 2 ; $i <= $page +2; $i++) { |
| 588 |
|
| 589 |
if ($i >= 1 && $i <= $total_pages) { |
| 590 |
|
| 591 |
if($i == $page) { |
| 592 |
|
| 593 |
echo "<b>[$i]</b> "; |
| 594 |
|
| 595 |
} else { |
| 596 |
|
| 597 |
echo '<a href="wp-polls.php?page='.($i).'" title="'.__('Page').' '.$i.'">'.$i.'</a> '; |
| 598 |
|
| 599 |
} |
| 600 |
|
| 601 |
} |
| 602 |
|
| 603 |
} |
| 604 |
|
| 605 |
if($page < $total_pages) { |
| 606 |
|
| 607 |
echo ' <b><a href="wp-polls.php?page='.($page+1).'" title="'.__('Go to Page').' '.($page+1).' »">»</a></b> '; |
| 608 |
|
| 609 |
} |
| 610 |
|
| 611 |
if (($page+2) < $total_pages) { |
| 612 |
|
| 613 |
echo ' ... <b><a href="wp-polls.php?page='.($total_pages).'" title="'.__('Go to Last Page').'">'.__('Last').' »</a></b>'; |
| 614 |
|
| 615 |
} |
| 616 |
|
| 617 |
?> |
| 618 |
|
| 619 |
</p> |
| 620 |
|
| 621 |
<!-- </Paging> --> |
| 622 |
|
| 623 |
<?php |
| 624 |
|
| 625 |
} |
| 626 |
|
| 627 |
?> |
| 628 |
|
| 629 |
</div> |
| 630 |
|
| 631 |
<?php get_sidebar(); ?> |
| 632 |
|
| 633 |
<?php get_footer(); ?> |