PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.44.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.44.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 3.6.2 All 177 releases
simple-tags / inc / class.widgets.php

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

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