| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: WP-Polls Widget |
| 4 |
Plugin URI: http://www.lesterchan.net/portfolio/programming.php |
| 5 |
Description: Adds a Sidebar Widget To Display Poll From WP-Polls Plugin |
| 6 |
Version: 2.11 |
| 7 |
Author: GaMerZ |
| 8 |
Author URI: http://www.lesterchan.net |
| 9 |
*/ |
| 10 |
|
| 11 |
|
| 12 |
/* Copyright 2006 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 |
### Function: Init WP-Polls Widget |
| 31 |
function widget_polls_init() { |
| 32 |
if (!function_exists('register_sidebar_widget')) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
### Function: WP-Polls Widget |
| 37 |
function widget_polls($args) { |
| 38 |
extract($args); |
| 39 |
$options = get_option('widget_polls'); |
| 40 |
$title = __('Polls'); |
| 41 |
if (function_exists('vote_poll') && basename($_SERVER['PHP_SELF']) != 'wp-polls.php') { |
| 42 |
echo $before_widget.$before_title.$title.$after_title; |
| 43 |
get_poll(); |
| 44 |
if(intval($options['display_archive']) == 1) { |
| 45 |
echo "<ul>\n<li><a href=\"".get_settings('siteurl')."/wp-content/plugins/polls/wp-polls.php\">Polls Archive</a></li></ul>\n"; |
| 46 |
} |
| 47 |
echo $after_widget; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
### Function: WP-Polls Widget Options |
| 52 |
function widget_polls_options() { |
| 53 |
global $wpdb; |
| 54 |
$options = get_option('widget_polls'); |
| 55 |
$current_poll = get_settings('poll_currentpoll'); |
| 56 |
if (!is_array($options)) { |
| 57 |
$options = array('display_archive' => '1'); |
| 58 |
} |
| 59 |
if ($_POST['polls-submit']) { |
| 60 |
$poll_currentpoll = intval($_POST['poll_currentpoll']); |
| 61 |
$options['display_archive'] = intval($_POST['polls-displayarchive']); |
| 62 |
update_option('widget_polls', $options); |
| 63 |
update_option('poll_currentpoll', $poll_currentpoll); |
| 64 |
} |
| 65 |
echo '<p style="text-align: left;"><label for="polls-displayarchive">Display Polls Archive Link?</label> '."\n"; |
| 66 |
echo '<input type="radio" id="polls-displayarchive" name="polls-displayarchive" value="1"'; |
| 67 |
checked(1, intval($options['display_archive'])); |
| 68 |
echo ' /> Yes <input type="radio" id="polls-displayarchive" name="polls-displayarchive" value="0"'; |
| 69 |
checked(0, intval($options['display_archive'])); |
| 70 |
echo ' /> No</p>'."\n"; |
| 71 |
echo '<p style="text-align: left;"><label for="poll_currentpoll">Current Active Poll:</label> '."\n"; |
| 72 |
echo '<select id="poll_currentpoll" name="poll_currentpoll" size="1">'."\n"; |
| 73 |
echo '<option value="-1"'; |
| 74 |
selected(-1, $current_poll); |
| 75 |
echo '>'; |
| 76 |
_e('Do NOT Display Poll (Disable)'); |
| 77 |
echo '</option>'."\n"; |
| 78 |
echo '<option value="-2"'; |
| 79 |
selected(-2, $current_poll); |
| 80 |
echo '>'; |
| 81 |
_e('Display Random Poll'); |
| 82 |
echo '</option>'."\n"; |
| 83 |
echo '<option value="0"'; |
| 84 |
selected(0, $current_poll); |
| 85 |
echo '>'; |
| 86 |
_e('Display Latest Poll'); |
| 87 |
echo '</option>'."\n"; |
| 88 |
echo '<option value="0"> </option>'."\n"; |
| 89 |
$polls = $wpdb->get_results("SELECT pollq_id, pollq_question FROM $wpdb->pollsq ORDER BY pollq_id DESC"); |
| 90 |
if($polls) { |
| 91 |
foreach($polls as $poll) { |
| 92 |
$poll_question = stripslashes($poll->pollq_question); |
| 93 |
$poll_id = intval($poll->pollq_id); |
| 94 |
if($poll_id == intval($current_poll)) { |
| 95 |
echo "<option value=\"$poll_id\" selected=\"selected\">$poll_question</option>\n"; |
| 96 |
} else { |
| 97 |
echo "<option value=\"$poll_id\">$poll_question</option>\n"; |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
echo '</select>'."\n"; |
| 102 |
echo '</p>'."\n"; |
| 103 |
echo '<input type="hidden" id="polls-submit" name="polls-submit" value="1" />'."\n"; |
| 104 |
} |
| 105 |
|
| 106 |
// Register Widgets |
| 107 |
register_sidebar_widget('Polls', 'widget_polls'); |
| 108 |
register_widget_control('Polls', 'widget_polls_options', 400, 120); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
### Function: Load The WP-Polls Widget |
| 113 |
add_action('plugins_loaded', 'widget_polls_init'); |
| 114 |
?> |