1 | <?php
|
---|
2 | function widget_st_tag_cloud_init() {
|
---|
3 | // Widgets exists ?
|
---|
4 | if ( !function_exists('wp_register_sidebar_widget') || !function_exists('wp_register_widget_control') ) {
|
---|
5 | return;
|
---|
6 | }
|
---|
7 |
|
---|
8 | // Simple Tags exists ?
|
---|
9 | if ( !class_exists('SimpleTags') ) {
|
---|
10 | return;
|
---|
11 | }
|
---|
12 |
|
---|
13 | function widget_st_tag_cloud( $widget_args, $number = 1 ) {
|
---|
14 | extract($widget_args);
|
---|
15 | $options = get_option('widget_stags_cloud');
|
---|
16 |
|
---|
17 | // Use Widgets title and no ST title !!
|
---|
18 | $args = 'title=';
|
---|
19 |
|
---|
20 | // Selection
|
---|
21 | $selection = trim(strtolower($options[$number]['selection']));
|
---|
22 | if ( !empty($selection) ) {
|
---|
23 | $args .= '&cloud_selection='.$selection;
|
---|
24 | } else {
|
---|
25 | $args .= '&cloud_selection=count-desc';
|
---|
26 | }
|
---|
27 |
|
---|
28 | // Order
|
---|
29 | $order = trim(strtolower($options[$number]['order']));
|
---|
30 | if ( !empty($order) ) {
|
---|
31 | $args .= '&cloud_sort='.$order;
|
---|
32 | } else {
|
---|
33 | $args .= '&cloud_sort=random';
|
---|
34 | }
|
---|
35 |
|
---|
36 | // Max tags
|
---|
37 | $max = (int) $options[$number]['max'];
|
---|
38 | if ( $max != 0 ) {
|
---|
39 | $args .= '&number='.$max;
|
---|
40 | }
|
---|
41 |
|
---|
42 | // Size Mini
|
---|
43 | $smini = (int) $options[$number]['smini'];
|
---|
44 | if ( $smini != 0 ) {
|
---|
45 | $args .= '&smallest='.$smini;
|
---|
46 | }
|
---|
47 |
|
---|
48 | // Size Maxi
|
---|
49 | $smax = (int) $options[$number]['smax'];
|
---|
50 | if ( $smax != 0 ) {
|
---|
51 | $args .= '&largest='.$smax;
|
---|
52 | }
|
---|
53 |
|
---|
54 | // Unit
|
---|
55 | $unity = trim($options[$number]['unit']);
|
---|
56 | if ( !empty($unity) ) {
|
---|
57 | $args .= '&unit='.$unity;
|
---|
58 | }
|
---|
59 |
|
---|
60 | // Format
|
---|
61 | $format = trim($options[$number]['format']);
|
---|
62 | if ( !empty($format) ) {
|
---|
63 | $args .= '&format='.$format;
|
---|
64 | }
|
---|
65 |
|
---|
66 | // Use color ?
|
---|
67 | $color = (int) $options[$number]['color'];
|
---|
68 | if ( $color == 0 ) {
|
---|
69 | $args .= '&color=false';
|
---|
70 | }
|
---|
71 |
|
---|
72 | // Color mini
|
---|
73 | $cmini = trim($options[$number]['cmini']);
|
---|
74 | if ( !empty($cmini) ) {
|
---|
75 | $args .= '&mincolor='.$cmini;
|
---|
76 | }
|
---|
77 |
|
---|
78 | // Color Max
|
---|
79 | $cmax = trim($options[$number]['cmax']);
|
---|
80 | if ( !empty($cmax) ) {
|
---|
81 | $args .= '&maxcolor='.$cmax;
|
---|
82 | }
|
---|
83 |
|
---|
84 | // Xformat
|
---|
85 | $xformat = trim($options[$number]['xformat']);
|
---|
86 | if ( !empty($xformat) ) {
|
---|
87 | $args .= '&xformat='.$xformat;
|
---|
88 | }
|
---|
89 |
|
---|
90 | // Use custom title with Widgets Title
|
---|
91 | $title = trim($options[$number]['title']);
|
---|
92 |
|
---|
93 | echo $before_widget;
|
---|
94 | echo $before_title . $title . $after_title;
|
---|
95 | st_tag_cloud($args);
|
---|
96 | echo $after_widget;
|
---|
97 | }
|
---|
98 |
|
---|
99 | function widget_st_tag_cloud_control( $number ) {
|
---|
100 | // Get actual options
|
---|
101 | $options = $newoptions = get_option('widget_stags_cloud');
|
---|
102 | if ( !is_array($options) ) {
|
---|
103 | $options = $newoptions = array();
|
---|
104 | }
|
---|
105 |
|
---|
106 | // Post to new options array
|
---|
107 | if ( isset($_POST['widget-stags-submit-'.$number]) ) {
|
---|
108 | $newoptions[$number]['title'] = strip_tags(stripslashes($_POST['widget-stags-title-'.$number]));
|
---|
109 | $newoptions[$number]['max'] = (int) stripslashes($_POST['widget-stags-max-'.$number]);
|
---|
110 | $newoptions[$number]['selection'] = stripslashes($_POST['widget-stags-selection-'.$number]);
|
---|
111 | $newoptions[$number]['order'] = stripslashes($_POST['widget-stags-order-'.$number]);
|
---|
112 | $newoptions[$number]['smini'] = (int) stripslashes($_POST['widget-stags-smini-'.$number]);
|
---|
113 | $newoptions[$number]['smax'] = (int) stripslashes($_POST['widget-stags-smax-'.$number]);
|
---|
114 | $newoptions[$number]['unit'] = stripslashes($_POST['widget-stags-unit-'.$number]);
|
---|
115 | $newoptions[$number]['format'] = stripslashes($_POST['widget-stags-format-'.$number]);
|
---|
116 | $newoptions[$number]['color'] = (int) stripslashes($_POST['widget-stags-color-'.$number]);
|
---|
117 | $newoptions[$number]['cmini'] = stripslashes($_POST['widget-stags-cmini-'.$number]);
|
---|
118 | $newoptions[$number]['cmax'] = stripslashes($_POST['widget-stags-cmax-'.$number]);
|
---|
119 | $newoptions[$number]['xformat'] = stripslashes($_POST['widget-stags-xformat-'.$number]);
|
---|
120 | }
|
---|
121 |
|
---|
122 | // Update if new options
|
---|
123 | if ( $options != $newoptions ) {
|
---|
124 | $options = $newoptions;
|
---|
125 | update_option('widget_stags_cloud', $options);
|
---|
126 | }
|
---|
127 |
|
---|
128 | // Prepare data for display
|
---|
129 | $title = htmlspecialchars($options[$number]['title'], ENT_QUOTES);
|
---|
130 | $max = htmlspecialchars($options[$number]['max'], ENT_QUOTES);
|
---|
131 | $selection = htmlspecialchars($options[$number]['selection'], ENT_QUOTES);
|
---|
132 | $order = htmlspecialchars($options[$number]['order'], ENT_QUOTES);
|
---|
133 | $smini = htmlspecialchars($options[$number]['smini'], ENT_QUOTES);
|
---|
134 | $smax = htmlspecialchars($options[$number]['smax'], ENT_QUOTES);
|
---|
135 | $unit = htmlspecialchars($options[$number]['unit'], ENT_QUOTES);
|
---|
136 | $format = htmlspecialchars($options[$number]['format'], ENT_QUOTES);
|
---|
137 | $color = htmlspecialchars($options[$number]['color'], ENT_QUOTES);
|
---|
138 | $cmini = htmlspecialchars($options[$number]['cmini'], ENT_QUOTES);
|
---|
139 | $cmax = htmlspecialchars($options[$number]['cmax'], ENT_QUOTES);
|
---|
140 | $xformat= htmlspecialchars($options[$number]['xformat'], ENT_QUOTES);
|
---|
141 | ?>
|
---|
142 | <div>
|
---|
143 | <p><?php _e('Empty field will use default value.', 'simpletags'); ?></p>
|
---|
144 |
|
---|
145 | <label for="widget-stags-title-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
146 | <?php _e('Title:', 'simpletags'); ?><br />
|
---|
147 | <input style="width: 100% !important;" type="text" id="widget-stags-title-<?php echo $number; ?>" name="widget-stags-title-<?php echo $number; ?>" value="<?php echo $title; ?>" />
|
---|
148 | </label>
|
---|
149 |
|
---|
150 | <label for="widget-stags-max-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
151 | <?php _e('Max tags to display: (default: 45)', 'simpletags'); ?>
|
---|
152 | <input size="20" type="text" id="widget-stags-max-<?php echo $number; ?>" name="widget-stags-max-<?php echo $number; ?>" value="<?php echo $max; ?>" />
|
---|
153 | </label>
|
---|
154 |
|
---|
155 | <label for="widget-stags-selection-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
156 | <?php _e('Tags selection:', 'simpletags'); ?>
|
---|
157 | <select id="widget-stags-selection-<?php echo $number; ?>" name="widget-stags-selection-<?php echo $number; ?>">
|
---|
158 | <option <?php if ( $selection == 'name-asc' ) echo 'selected="selected"'; ?> value="name-asc"><?php _e('Alphabetical', 'simpletags'); ?></option>
|
---|
159 | <option <?php if ( $selection == 'name-desc' ) echo 'selected="selected"'; ?> value="name-desc"><?php _e('Inverse Alphabetical', 'simpletags'); ?></option>
|
---|
160 | <option <?php if ( $selection == 'count-desc' ) echo 'selected="selected"'; ?> value="count-desc"><?php _e('Most popular (default)', 'simpletags'); ?></option>
|
---|
161 | <option <?php if ( $selection == 'count-asc' ) echo 'selected="selected"'; ?> value="count-asc"><?php _e('Least used', 'simpletags'); ?></option>
|
---|
162 | <option <?php if ( $selection == 'random' ) echo 'selected="selected"'; ?> value="random"><?php _e('Random', 'simpletags'); ?></option>
|
---|
163 | </select>
|
---|
164 | </label>
|
---|
165 |
|
---|
166 | <label for="widget-stags-order-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
167 | <?php _e('Order tags display:', 'simpletags'); ?>
|
---|
168 | <select id="widget-stags-order-<?php echo $number; ?>" name="widget-stags-order-<?php echo $number; ?>">
|
---|
169 | <option <?php if ( $order == 'name-asc' ) echo 'selected="selected"'; ?> value="name-asc"><?php _e('Alphabetical', 'simpletags'); ?></option>
|
---|
170 | <option <?php if ( $order == 'name-desc' ) echo 'selected="selected"'; ?> value="name-desc"><?php _e('Inverse Alphabetical', 'simpletags'); ?></option>
|
---|
171 | <option <?php if ( $order == 'count-desc' ) echo 'selected="selected"'; ?> value="count-desc"><?php _e('Most popular', 'simpletags'); ?></option>
|
---|
172 | <option <?php if ( $order == 'count-asc' ) echo 'selected="selected"'; ?> value="count-asc"><?php _e('Least used', 'simpletags'); ?></option>
|
---|
173 | <option <?php if ( $order == 'random' ) echo 'selected="selected"'; ?> value="random"><?php _e('Random (default)', 'simpletags'); ?></option>
|
---|
174 | </select>
|
---|
175 | </label>
|
---|
176 |
|
---|
177 | <label for="widget-stags-smini-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
178 | <?php _e('Font size mini: (default: 8)', 'simpletags'); ?>
|
---|
179 | <input size="20" type="text" id="widget-stags-smini-<?php echo $number; ?>" name="widget-stags-smini-<?php echo $number; ?>" value="<?php echo $smini; ?>" />
|
---|
180 | </label>
|
---|
181 |
|
---|
182 | <label for="widget-stags-smax-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
183 | <?php _e('Font size max: (default: 22)', 'simpletags'); ?>
|
---|
184 | <input size="20" type="text" id="widget-stags-smax-<?php echo $number; ?>" name="widget-stags-smax-<?php echo $number; ?>" value="<?php echo $smax; ?>" />
|
---|
185 | </label>
|
---|
186 |
|
---|
187 | <label for="widget-stags-unit-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
188 | <?php _e('Unit font size:', 'simpletags'); ?>
|
---|
189 | <select id="widget-stags-unit-<?php echo $number; ?>" name="widget-stags-unit-<?php echo $number; ?>">
|
---|
190 | <option <?php if ( $unit == 'pt' ) echo 'selected="selected"'; ?> value="pt"><?php _e('Point (default)', 'simpletags'); ?></option>
|
---|
191 | <option <?php if ( $unit == 'px' ) echo 'selected="selected"'; ?> value="px"><?php _e('Pixel', 'simpletags'); ?></option>
|
---|
192 | <option <?php if ( $unit == 'em' ) echo 'selected="selected"'; ?> value="em"><?php _e('Em', 'simpletags'); ?></option>
|
---|
193 | <option <?php if ( $unit == '%' ) echo 'selected="selected"'; ?> value="%"><?php _e('Pourcent', 'simpletags'); ?></option>
|
---|
194 | </select>
|
---|
195 | </label>
|
---|
196 |
|
---|
197 | <label for="widget-stags-format-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
198 | <?php _e('Format:', 'simpletags'); ?>
|
---|
199 | <select id="widget-stags-format-<?php echo $number; ?>" name="widget-stags-format-<?php echo $number; ?>">
|
---|
200 | <option <?php if ( $format == 'flat' ) echo 'selected="selected"'; ?> value="flat"><?php _e('Flat (default)', 'simpletags'); ?></option>
|
---|
201 | <option <?php if ( $format == 'list' ) echo 'selected="selected"'; ?> value="list"><?php _e('List (UL/LI)', 'simpletags'); ?></option>
|
---|
202 | </select>
|
---|
203 | </label>
|
---|
204 |
|
---|
205 | <label for="widget-stags-color-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
206 | <input type="checkbox" id="widget-stags-color-<?php echo $number; ?>" name="widget-stags-color-<?php echo $number; ?>" <?php if ( $color == 1 ) echo 'checked="checked"'; ?> value="1" />
|
---|
207 | <?php _e('Use auto color cloud:', 'simpletags'); ?>
|
---|
208 | </label>
|
---|
209 |
|
---|
210 | <label for="widget-stags-cmini-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
211 | <?php _e('Font color mini: (default: #CCCCCC)', 'simpletags'); ?>
|
---|
212 | <input type="text" id="widget-stags-cmini-<?php echo $number; ?>" name="widget-stags-cmini-<?php echo $number; ?>" value="<?php echo $cmini; ?>" />
|
---|
213 | </label>
|
---|
214 |
|
---|
215 | <label for="widget-stags-cmax-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
216 | <?php _e('Font color max: (default: #000000)', 'simpletags'); ?>
|
---|
217 | <input type="text" id="widget-stags-cmax-<?php echo $number; ?>" name="widget-stags-cmax-<?php echo $number; ?>" value="<?php echo $cmax; ?>" />
|
---|
218 | </label>
|
---|
219 |
|
---|
220 | <label for="widget-stags-xformat-<?php echo $number; ?>" style="line-height:35px;display:block;">
|
---|
221 | <?php _e('Extended format: (advanced usage)', 'simpletags'); ?><br />
|
---|
222 | <input style="width: 100% !important;" type="text" id="widget-stags-xformat-<?php echo $number; ?>" name="widget-stags-xformat-<?php echo $number; ?>" value="<?php echo $xformat; ?>" />
|
---|
223 | </label>
|
---|
224 |
|
---|
225 | <input type="hidden" name="widget-stags-submit-<?php echo $number; ?>" id="widget-stags-submit-<?php echo $number; ?>" value="1" />
|
---|
226 | </div>
|
---|
227 | <?php
|
---|
228 | }
|
---|
229 |
|
---|
230 | function st_tag_cloud_setup() {
|
---|
231 | $options = $newoptions = get_option('widget_stags_cloud');
|
---|
232 | if ( isset($_POST['stags_cloud-number-submit']) ) {
|
---|
233 | $newoptions['number'] = (int) $_POST['stags_cloud-number'];
|
---|
234 | if ( $newoptions['number'] > 9 ) {
|
---|
235 | $newoptions['number'] = 9;
|
---|
236 | } elseif ( $newoptions['number'] < 1 ) {
|
---|
237 | $newoptions['number'] = 1;
|
---|
238 | }
|
---|
239 | }
|
---|
240 | if ( $options != $newoptions ) {
|
---|
241 | $options = $newoptions;
|
---|
242 | update_option('widget_stags_cloud', $options);
|
---|
243 | widget_st_tag_cloud_register($options['number']);
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | function st_tag_cloud_page() {
|
---|
248 | $options = get_option('widget_stags_cloud');
|
---|
249 | ?>
|
---|
250 | <div class="wrap">
|
---|
251 | <form method="post">
|
---|
252 | <h2><?php _e('Tag Cloud Widgets', 'simpletags'); ?></h2>
|
---|
253 | <p style="line-height: 30px;"><?php _e('How many tag cloud widgets would you like?', 'simpletags'); ?>
|
---|
254 | <select id="stags_cloud-number" name="stags_cloud-number" value="<?php echo $options['number']; ?>">
|
---|
255 | <?php for ( $i = 1; $i < 10; ++$i ) echo "<option value='$i' ".($options['number']==$i ? "selected='selected'" : '').">$i</option>"; ?>
|
---|
256 | </select>
|
---|
257 | <span class="submit"><input type="submit" name="stags_cloud-number-submit" id="stags_cloud-number-submit" value="<?php echo attribute_escape(__('Save', 'simpletags')); ?>" /></span></p>
|
---|
258 | </form>
|
---|
259 | </div>
|
---|
260 | <?php
|
---|
261 | }
|
---|
262 |
|
---|
263 | function widget_st_tag_cloud_register() {
|
---|
264 | $options = get_option('widget_stags_cloud');
|
---|
265 |
|
---|
266 | $number = (int) $options['number'];
|
---|
267 | if ( $number < 1 ) {
|
---|
268 | $number = 1;
|
---|
269 | } elseif ( $number > 9 ) {
|
---|
270 | $number = 9;
|
---|
271 | }
|
---|
272 |
|
---|
273 | for ( $i = 1; $i <= 9; $i++ ) {
|
---|
274 | wp_register_sidebar_widget('widget_stags-'.$i, sprintf(__('Extended Tag Cloud %d', 'simpletags'), $i), $i <= $number ? 'widget_st_tag_cloud' : '', array('classname' => 'widget_stags_cloud'), $i);
|
---|
275 | wp_register_widget_control('widget_stags-'.$i, sprintf(__('Extended Tag Cloud %d', 'simpletags'), $i), $i <= $number ? 'widget_st_tag_cloud_control' : '', array('width' => 460, 'height' => 520), $i);
|
---|
276 | }
|
---|
277 |
|
---|
278 | add_action('sidebar_admin_setup', 'st_tag_cloud_setup');
|
---|
279 | add_action('sidebar_admin_page', 'st_tag_cloud_page');
|
---|
280 | }
|
---|
281 |
|
---|
282 | // Launch Widgets
|
---|
283 | widget_st_tag_cloud_register();
|
---|
284 | }
|
---|
285 |
|
---|
286 | // Initialize !
|
---|
287 | widget_st_tag_cloud_init();
|
---|
288 | ?> |
---|