root/wp-polls/trunk/wp-polls-widget.php

Revision 49932, 7.0 kB (checked in by GamerZ, 4 weeks ago)

Fixed MYSQL Charset Issue

Line 
1 <?php
2 /*
3 Plugin Name: WP-Polls Widget
4 Plugin URI: http://lesterchan.net/portfolio/programming/php/
5 Description: Adds a Poll Widget to display single or multiple polls from WP-Polls Plugin. You will need to activate WP-Polls first.
6 Version: 2.31
7 Author: Lester 'GaMerZ' Chan
8 Author URI: http://lesterchan.net
9 */
10
11
12 /* 
13     Copyright 2008  Lester Chan  (email : lesterchan@gmail.com)
14
15     This program is free software; you can redistribute it and/or modify
16     it under the terms of the GNU General Public License as published by
17     the Free Software Foundation; either version 2 of the License, or
18     (at your option) any later version.
19
20     This program is distributed in the hope that it will be useful,
21     but WITHOUT ANY WARRANTY; without even the implied warranty of
22     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     GNU General Public License for more details.
24
25     You should have received a copy of the GNU General Public License
26     along with this program; if not, write to the Free Software
27     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28 */
29
30
31 ### Function: Init WP-Polls Widget
32 function widget_polls_init() {
33     if (!function_exists('register_sidebar_widget')) {
34         return;
35     }
36
37     ### Function: WP-Polls Widget
38     function widget_polls($args) {
39         global $in_pollsarchive;
40         extract($args);
41         $options = get_option('widget_polls');
42         $title = htmlspecialchars(stripslashes($options['title']));       
43         if (function_exists('vote_poll') && !in_pollarchive()) {
44             echo $before_widget.$before_title.$title.$after_title;
45             if(intval(get_option('poll_currentpoll')) == -3) {
46                 $multiple_polls = explode(',', $options['multiple_polls']);
47                 foreach($multiple_polls as $multiple_poll) {
48                     get_poll($multiple_poll);
49                 }
50             } else {
51                 get_poll();               
52             }
53             display_polls_archive_link();
54             echo $after_widget;
55         }       
56     }
57
58     ### Function: WP-Polls Widget Options
59     function widget_polls_options() {
60         global $wpdb;
61         $options = get_option('widget_polls');
62         $current_poll = get_option('poll_currentpoll');
63         if (!is_array($options)) {
64             $options = array('title' => __('Polls', 'wp-polls'), 'poll_multiplepolls' => '');
65         }
66         if ($_POST['polls-submit']) {
67             $poll_currentpoll = intval($_POST['poll_currentpoll']);
68             $poll_archive_show = intval($_POST['poll_archive_show']);       
69             $options['title'] = strip_tags($_POST['polls-title']);
70             if(is_array($_POST['poll_multiplepolls'])) {
71                 $options['multiple_polls'] = implode(',', $_POST['poll_multiplepolls']);
72             } else {
73                 $options['multiple_polls'] = $_POST['poll_multiplepolls'];
74             }
75             update_option('widget_polls', $options);
76             update_option('poll_currentpoll', $poll_currentpoll);
77             update_option('poll_archive_show', $poll_archive_show);
78         }
79         ?>
80         <script type="text/javascript">
81             /* <![CDATA[*/
82                 function show_multiple_polls() {
83                     if(document.getElementById('poll_currentpoll').value == -3) {
84                         document.getElementById('poll_multiplepolls').disabled = false;
85                         document.getElementById('poll_multiplepolls_text').style.display = 'block';
86                     } else {                       
87                         document.getElementById('poll_multiplepolls').selectedIndex = -1;
88                         document.getElementById('poll_multiplepolls').disabled = true;
89                         document.getElementById('poll_multiplepolls_text').style.display = 'none';
90                     }
91                 }
92             /* ]]> */
93         </script>
94         <?php
95         echo '<p style="text-align: left;"><label for="polls-title">';
96         _e('Title', 'wp-polls');
97         echo ': </label><input type="text" id="polls-title" name="polls-title" value="'.htmlspecialchars(stripslashes($options['title'])).'" /></p>'."\n";
98         echo '<p style="text-align: left;"><label for="polls-displayarchive">';
99         _e('Display Polls Archive Link Below Poll?', 'wp-polls');
100         echo ' </label>'."\n";
101         echo '<select id="polls-displayarchive" name="poll_archive_show" size="1">'."\n";
102         echo '<option value="0"';
103         selected('0', get_option('poll_archive_show'));
104         echo '>';
105         _e('No', 'wp-polls');
106         echo '</option>'."\n";
107         echo '<option value="1"';
108         selected('1', get_option('poll_archive_show'));
109         echo '>';
110         _e('Yes', 'wp-polls');
111         echo '</option>'."\n";
112         echo '</select></p>'."\n";
113         echo '<p style="text-align: left;"><label for="poll_currentpoll">';
114         _e('Current Active Poll', 'wp-polls');
115         echo ': </label>'."\n";
116         echo '<select id="poll_currentpoll" name="poll_currentpoll" size="1" onchange="show_multiple_polls()">'."\n";
117         echo '<option value="-1"';
118         selected(-1, $current_poll);
119         echo '>';
120         _e('Do NOT Display Poll (Disable)', 'wp-polls');
121         echo '</option>'."\n";
122         echo '<option value="-2"';
123         selected(-2, $current_poll);
124         echo '>';
125         _e('Display Random Poll', 'wp-polls');
126         echo '</option>'."\n";
127         echo '<option value="0"';
128         selected(0, $current_poll);
129         echo '>';
130         _e('Display Latest Poll', 'wp-polls');
131         echo '</option>'."\n";
132         echo '<option value="-3"';
133         selected(-3, $current_poll);
134         echo '>';
135         _e('Display Multiple Polls', 'wp-polls');
136         echo '</option>'."\n";
137         echo '<option value="0">&nbsp;</option>'."\n";
138         $polls = $wpdb->get_results("SELECT pollq_id, pollq_question FROM $wpdb->pollsq ORDER BY pollq_id DESC");
139         if($polls) {
140             foreach($polls as $poll) {
141                 $poll_question = stripslashes($poll->pollq_question);
142                 $poll_id = intval($poll->pollq_id);
143                 if($poll_id == intval($current_poll)) {
144                     echo "<option value=\"$poll_id\" selected=\"selected\">$poll_question</option>\n";
145                 } else {
146                     echo "<option value=\"$poll_id\">$poll_question</option>\n";
147                 }
148             }
149         }
150         echo '</select></p>'."\n";
151         if($current_poll == -3) {
152             $display = 'display: block;';
153             $disabled = '';
154         } else {
155             $display = 'display: none;';
156             $disabled = 'disabled="disabled"';
157         }
158         echo '<p id="poll_multiplepolls_text" style="text-align: left; '.$display.'"><label for="poll_multiplepolls">';
159         _e('Select Multiple Polls', 'wp-polls');
160         echo ': </label>'."\n";
161         echo '<select id="poll_multiplepolls" name="poll_multiplepolls[]" size="5" multiple="true" style="vertical-align: text-top;" $disabled>'."\n";
162         $multiple_polls = explode(',', $options['multiple_polls']);
163         $polls = $wpdb->get_results("SELECT pollq_id, pollq_question FROM $wpdb->pollsq ORDER BY pollq_id DESC");
164         if($polls) {
165             foreach($polls as $poll) {
166                 $poll_question = stripslashes($poll->pollq_question);
167                 $poll_id = intval($poll->pollq_id);
168                 if(in_array($poll_id, $multiple_polls)) {
169                     echo "<option value=\"$poll_id\" selected=\"selected\">$poll_question</option>\n";
170                 } else {
171                     echo "<option value=\"$poll_id\">$poll_question</option>\n";
172                 }
173             }
174         }
175         echo '</select>'."\n";
176         echo '</p>'."\n";
177         echo '<input type="hidden" id="polls-submit" name="polls-submit" value="1" />'."\n";
178     }
179
180     // Register Widgets
181     register_sidebar_widget(array('Polls', 'wp-polls'), 'widget_polls');
182     register_widget_control(array('Polls', 'wp-polls'), 'widget_polls_options', 400, 300);
183 }
184
185
186 ### Function: Load The WP-Polls Widget
187 add_action('plugins_loaded', 'widget_polls_init');
188 ?>
Note: See TracBrowser for help on using the browser.