PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.50.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.50.0
3.54.0 3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 All 178 releases
simple-tags / inc / class.widgets.php

class.widgets.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.50.0, at inc/class.widgets.php

420 lines 15.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * TaxoPress widget class
5 *
6 */
7 class SimpleTags_Widget extends WP_Widget
8 {
9 /**
10 * Constructor widget
11 *
12 * @return void
13 * @author WebFactory Ltd
14 */
15 public function __construct()
16 {
17 parent::__construct(
18 'simpletags',
19 esc_html__('Tag Cloud (TaxoPress Legacy)', 'simple-tags'),
20 array(
21 'classname' => 'widget-simpletags',
22 'description' => esc_html__('[DEPRECATED] - Your most used tags in cloud format with dynamic color and many options', 'simple-tags')
23 )
24 );
25 }
26
27 /**
28 * Check if taxonomy exist and return it, otherwise return default post tags.
29 *
30 * @param array $instance
31 *
32 * @return string
33 * @author WebFactory Ltd
34 */
35 public static function _get_current_taxonomy($instance)
36 {
37 if (! empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy'])) {
38 return $instance['taxonomy'];
39 }
40
41 return 'post_tag';
42 }
43
44 /**
45 * Default settings for widget
46 *
47 * @return array
48 * @author WebFactory Ltd
49 */
50 public static function get_fields()
51 {
52 return array(
53 'taxonomy' => 'post_tag',
54 'title' => esc_html__('Tag cloud', 'simple-tags'),
55 'max' => 45,
56 'selectionby' => 'count',
57 'selection' => 'desc',
58 'orderby' => 'random',
59 'order' => 'asc',
60 'smini' => 8,
61 'smax' => 22,
62 'unit' => 'pt',
63 'format' => 'flat',
64 'color' => 1,
65 'cmini' => '#CCCCCC',
66 'cmax' => '#000000',
67 'xformat' => '',
68 'adv_usage' => ''
69 );
70 }
71
72 /**
73 * Method for theme render
74 *
75 * @param array $args
76 * @param array $instance
77 *
78 * @return void
79 * @author WebFactory Ltd
80 */
81 public function widget($args, $instance)
82 {
83 extract($args);
84
85 $current_taxonomy = self::_get_current_taxonomy($instance);
86
87 // Build or not the name of the widget
88 if (! empty($instance['title'])) {
89 $title = $instance['title'];
90 } else {
91 if ('post_tag' == $current_taxonomy) {
92 $title = esc_html__('Tags', 'simple-tags');
93 } else {
94 $tax = get_taxonomy($current_taxonomy);
95 if (isset($tax->labels)) {
96 $title = $tax->labels->name;
97 } else {
98 $title = $tax->name;
99 }
100 }
101 }
102 $title = apply_filters('widget_title', $title, $instance, $this->id_base);
103 $title = esc_html($title);
104
105 // Set values and clean it
106 foreach ((array) self::get_fields() as $field => $field_value) {
107 ${$field} = isset($instance[$field]) ? esc_html(trim($instance[$field])) : '';
108 }
109
110 $param = '';
111
112 // Selection
113 $param .= (! empty($selectionby)) ? '&selectionby=' . $selectionby : '&selectionby=count';
114 $param .= (! empty($selection)) ? '&selection=' . $selection : '&selection=desc';
115
116 // Order
117 $param .= (! empty($orderby)) ? '&orderby=' . $orderby : '&orderby=random';
118 $param .= (! empty($order)) ? '&order=' . $order : '&order=asc';
119
120 // Max tags
121 if ((int) $max != 0) {
122 $param .= '&number=' . $max;
123 }
124
125 // Size Mini
126 if ((int) $smini != 0) {
127 $param .= '&smallest=' . $smini;
128 }
129
130 // Size Maxi
131 if ((int) $smax != 0) {
132 $param .= '&largest=' . $smax;
133 }
134
135 // Unit
136 if (! empty($unit)) {
137 $param .= '&unit=' . $unit;
138 }
139
140 // Format
141 if (! empty($format)) {
142 $param .= '&format=' . $format;
143 }
144
145 // Use color ?
146 if ((int) $color == 0) {
147 $param .= '&color=false';
148 }
149
150 // Color mini
151 if (! empty($cmini)) {
152 $param .= '&mincolor=' . $cmini;
153 }
154
155 // Color Max
156 if (! empty($cmax)) {
157 $param .= '&maxcolor=' . $cmax;
158 }
159
160 // Xformat
161 if (! empty($xformat)) {
162 $param .= '&xformat=' . $xformat;
163 }
164
165 // Advanced usage
166 if (! empty($adv_usage)) {
167 if (substr($adv_usage, 0, 1) != '&') {
168 $param .= '&';
169 }
170
171 $param .= $adv_usage;
172 }
173
174
175 // Taxonomy
176 $param .= '&taxonomy=' . $current_taxonomy;
177
178 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
179 echo $before_widget;
180 if (! empty($title)) {
181 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
182 echo $before_title . $title . $after_title;
183 }
184 st_tag_cloud(apply_filters('simple-tags-widget', 'title=' . $param, $instance)); // Use Widgets title and no ST title !!
185 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
186 echo $after_widget;
187 }
188
189 /**
190 * Update widget settings
191 *
192 * @param array $new_instance
193 * @param array $old_instance
194 *
195 * @return array
196 * @author WebFactory Ltd
197 */
198 public function update($new_instance, $old_instance)
199 {
200 $instance = $old_instance;
201
202 foreach ((array) self::get_fields() as $field => $field_value) {
203 $instance[ $field ] = sanitize_text_field($new_instance[ $field ]);
204 }
205
206 return $instance;
207 }
208
209 /**
210 * Admin form for widgets
211 *
212 * @param array $instance
213 *
214 * @return void
215 * @author WebFactory Ltd
216 */
217 public function form($instance)
218 {
219 //Defaults
220 $instance = wp_parse_args((array) $instance, self::get_fields());
221 ?>
222 <p style="color:red;"><?php esc_html_e('This widget is no longer being updated. Please use the "Terms Display (TaxoPress Shortcode)" widget instead.', 'simple-tags'); ?></p>
223
224 <p>
225 <label for="<?php echo esc_attr($this->get_field_id('title')); ?>">
226 <?php esc_html_e('Title:', 'simple-tags'); ?>
227 <input class="widefat" type="text" id="<?php echo esc_attr($this->get_field_id('title')); ?>"
228 name="<?php echo esc_attr($this->get_field_name('title')); ?>"
229 value="<?php echo esc_attr($instance['title']); ?>"/>
230 </label>
231 </p>
232
233 <p>
234 <label for="<?php echo esc_attr($this->get_field_id('max')); ?>">
235 <?php esc_html_e('Max tags to display: (default: 45)', 'simple-tags'); ?>
236 <input class="widefat" size="20" type="text" id="<?php echo esc_attr($this->get_field_id('max')); ?>"
237 name="<?php echo esc_attr($this->get_field_name('max')); ?>"
238 value="<?php echo esc_attr($instance['max']); ?>"/>
239 </label>
240 </p>
241
242 <p>
243 <label for="<?php echo esc_attr($this->get_field_id('selectionby')); ?>">
244 <?php esc_html_e('Order by for DB selection tags:', 'simple-tags'); ?>
245 <select id="<?php echo esc_attr($this->get_field_id('selectionby')); ?>"
246 name="<?php echo esc_attr($this->get_field_name('selectionby')); ?>">
247 <option <?php selected(esc_attr($instance['selectionby']), 'name'); ?>
248 value="name"><?php esc_html_e('Name', 'simple-tags'); ?></option>
249 <option <?php selected($instance['selectionby'], 'slug'); ?>
250 value="slug"><?php esc_html_e('Slug', 'simple-tags'); ?></option>
251 <option <?php selected($instance['selectionby'], 'term_group'); ?>
252 value="term_group"><?php esc_html_e('Term group', 'simple-tags'); ?></option>
253 <option <?php selected($instance['selectionby'], 'count'); ?>
254 value="count"><?php esc_html_e('Counter (default)', 'simple-tags'); ?></option>
255 <option <?php selected($instance['selectionby'], 'random'); ?>
256 value="random"><?php esc_html_e('Random', 'simple-tags'); ?></option>
257 </select>
258 </label>
259 </p>
260
261 <p>
262 <label for="<?php echo esc_attr($this->get_field_id('selection')); ?>">
263 <?php esc_html_e('Order for DB selection tags:', 'simple-tags'); ?>
264 <select id="<?php echo esc_attr($this->get_field_id('selection')); ?>"
265 name="<?php echo esc_attr($this->get_field_name('selection')); ?>">
266 <option <?php selected($instance['selection'], 'asc'); ?>
267 value="asc"><?php esc_html_e('ASC', 'simple-tags'); ?></option>
268 <option <?php selected($instance['selection'], 'desc'); ?>
269 value="desc"><?php esc_html_e('DESC (default)', 'simple-tags'); ?></option>
270 </select>
271 </label>
272 </p>
273
274 <p>
275 <label for="<?php echo esc_attr($this->get_field_id('orderby')); ?>">
276 <?php esc_html_e('Order by for display tags:', 'simple-tags'); ?>
277 <select id="<?php echo esc_attr($this->get_field_id('orderby')); ?>"
278 name="<?php echo esc_attr($this->get_field_name('orderby')); ?>">
279 <option <?php selected(esc_attr($instance['orderby']), 'name'); ?>
280 value="name"><?php esc_html_e('Name', 'simple-tags'); ?></option>
281 <option <?php selected(esc_attr($instance['orderby']), 'count'); ?>
282 value="count"><?php esc_html_e('Counter', 'simple-tags'); ?></option>
283 <option <?php selected(esc_attr($instance['orderby']), 'random'); ?>
284 value="random"><?php esc_html_e('Random (default)', 'simple-tags'); ?></option>
285 </select>
286 </label>
287 </p>
288
289 <p>
290 <label for="<?php echo esc_attr($this->get_field_id('order')); ?>">
291 <?php esc_html_e('Order for display tags:', 'simple-tags'); ?>
292 <select id="<?php echo esc_attr($this->get_field_id('order')); ?>"
293 name="<?php echo esc_attr($this->get_field_name('order')); ?>">
294 <option <?php selected(esc_attr($instance['order']), 'asc'); ?>
295 value="asc"><?php esc_html_e('ASC', 'simple-tags'); ?></option>
296 <option <?php selected(esc_attr($instance['order']), 'desc'); ?>
297 value="desc"><?php esc_html_e('DESC (default)', 'simple-tags'); ?></option>
298 </select>
299 </label>
300 </p>
301
302 <p>
303 <label for="<?php echo esc_attr($this->get_field_id('smini')); ?>">
304 <?php esc_html_e('Font size mini: (default: 8)', 'simple-tags'); ?>
305 <input class="widefat" size="20" type="text" id="<?php echo esc_attr($this->get_field_id('smini')); ?>"
306 name="<?php echo esc_attr($this->get_field_name('smini')); ?>"
307 value="<?php echo esc_attr($instance['smini']); ?>"/>
308 </label>
309 </p>
310
311 <p>
312 <label for="<?php echo esc_attr($this->get_field_id('smax')); ?>">
313 <?php esc_html_e('Font size max: (default: 22)', 'simple-tags'); ?>
314 <input class="widefat" size="20" type="text" id="<?php echo esc_attr($this->get_field_id('smax')); ?>"
315 name="<?php echo esc_attr($this->get_field_name('smax')); ?>"
316 value="<?php echo esc_attr($instance['smax']); ?>"/>
317 </label>
318 </p>
319
320 <p>
321 <label for="<?php echo esc_attr($this->get_field_id('unit')); ?>">
322 <?php esc_html_e('Unit font size:', 'simple-tags'); ?>
323 <select id="<?php echo esc_attr($this->get_field_id('unit')); ?>"
324 name="<?php echo esc_attr($this->get_field_name('unit')); ?>">
325 <option <?php selected(esc_attr($instance['unit']), 'pt'); ?>
326 value="pt"><?php esc_html_e('Point (default)', 'simple-tags'); ?></option>
327 <option <?php selected(esc_attr($instance['unit']), 'px'); ?>
328 value="px"><?php esc_html_e('Pixel', 'simple-tags'); ?></option>
329 <option <?php selected(esc_attr($instance['unit']), 'em'); ?>
330 value="em"><?php esc_html_e('Em', 'simple-tags'); ?></option>
331 <option <?php selected(esc_attr($instance['unit']), '%'); ?>
332 value="%"><?php esc_html_e('Pourcent', 'simple-tags'); ?></option>
333 </select>
334 </label>
335 </p>
336
337 <p>
338 <label for="<?php echo esc_attr($this->get_field_id('format')); ?>">
339 <?php esc_html_e('Format:', 'simple-tags'); ?>
340 <select id="<?php echo esc_attr($this->get_field_id('format')); ?>"
341 name="<?php echo esc_attr($this->get_field_name('format')); ?>">
342 <option <?php selected(esc_attr($instance['format']), 'flat'); ?>
343 value="flat"><?php esc_html_e('Flat (default)', 'simple-tags'); ?></option>
344 <option <?php selected(esc_attr($instance['format']), 'list'); ?>
345 value="list"><?php esc_html_e('List (UL/LI)', 'simple-tags'); ?></option>
346 <option <?php selected(esc_attr($instance['format']), 'ol'); ?>
347 value="list"><?php esc_html_e('Ordinary List (OL/LI)', 'simple-tags'); ?></option>
348 </select>
349 </label>
350 </p>
351
352 <p>
353 <label for="<?php echo esc_attr($this->get_field_id('color')); ?>">
354 <input class="checkbox" type="checkbox" id="<?php echo esc_attr($this->get_field_id('color')); ?>"
355 name="<?php echo esc_attr($this->get_field_name('color')); ?>" <?php checked((int) $instance['color'], 1); ?>
356 value="1"/>
357 <?php esc_html_e('Use auto color cloud:', 'simple-tags'); ?>
358 </label>
359 </p>
360
361 <p>
362 <label for="<?php echo esc_attr($this->get_field_id('cmini')); ?>">
363 <?php esc_html_e('Font color mini: (default: #CCCCCC)', 'simple-tags'); ?>
364 <input class="widefat" type="text" id="<?php echo esc_attr($this->get_field_id('cmini')); ?>"
365 name="<?php echo esc_attr($this->get_field_name('cmini')); ?>"
366 value="<?php echo esc_attr($instance['cmini']); ?>"/>
367 </label>
368 </p>
369
370 <p>
371 <label for="<?php echo esc_attr($this->get_field_id('cmax')); ?>">
372 <?php esc_html_e('Font color max: (default: #000000)', 'simple-tags'); ?>
373 <input class="widefat" type="text" id="<?php echo esc_attr($this->get_field_id('cmax')); ?>"
374 name="<?php echo esc_attr($this->get_field_name('cmax')); ?>"
375 value="<?php echo esc_attr($instance['cmax']); ?>"/>
376 </label>
377 </p>
378
379 <p>
380 <label for="<?php echo esc_attr($this->get_field_id('xformat')); ?>">
381 <?php esc_html_e('Tag link format:', 'simple-tags'); ?><br/>
382 <input class="widefat" style="width: 100% !important;" type="text"
383 id="<?php echo esc_attr($this->get_field_id('xformat')); ?>"
384 name="<?php echo esc_attr($this->get_field_name('xformat')); ?>"
385 value="<?php echo esc_attr($instance['xformat']); ?>"/>
386 </label>
387 </p>
388
389 <p>
390 <label for="<?php echo esc_attr($this->get_field_id('adv_usage')); ?>">
391 <?php esc_html_e('Advanced usage:', 'simple-tags'); ?><br/>
392 <input class="adv_usage" style="width: 100% !important;" type="text"
393 id="<?php echo esc_attr($this->get_field_id('adv_usage')); ?>"
394 name="<?php echo esc_attr($this->get_field_name('adv_usage')); ?>"
395 value="<?php echo esc_attr($instance['adv_usage']); ?>"/>
396 </label>
397 </p>
398
399 <p>
400 <label for="<?php echo esc_attr($this->get_field_id('taxonomy')); ?>">
401 <?php esc_html_e("What to show", 'simple-tags'); ?><br/>
402 <select id="<?php echo esc_attr($this->get_field_id('taxonomy')); ?>"
403 name="<?php echo esc_attr($this->get_field_name('taxonomy')); ?>" style="width:100%;">
404 <?php
405 foreach (get_object_taxonomies('post') as $_taxonomy) {
406 $tax = get_taxonomy($_taxonomy);
407 if (! $tax->show_tagcloud || empty($tax->labels->name)) {
408 continue;
409 }
410
411 echo '<option ' . selected(esc_attr($instance['taxonomy']), esc_attr($tax->name), false) . ' value="' . esc_attr($tax->name) . '">' . esc_html($tax->labels->name) . '</option>';
412 }
413 ?>
414 </select>
415 </label>
416 </p>
417 <?php
418 }
419 }
420