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