PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.4.2
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.4.2
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.4.2, at inc/class.widgets.php

404 lines 13.0 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', __( 'Tag Cloud (TaxoPress Legacy)', 'simple-tags' ),
16 array(
17 'classname' => 'widget-simpletags',
18 'description' => __( '[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' => __( '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 = __( '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
97 // Set values and clean it
98 foreach ( (array) self::get_fields() as $field => $field_value ) {
99 ${$field} = isset($instance[$field]) ? trim($instance[$field]) : '';
100 }
101
102 $param = '';
103
104 // Selection
105 $param .= ( ! empty( $selectionby ) ) ? '&selectionby=' . $selectionby : '&selectionby=count';
106 $param .= ( ! empty( $selection ) ) ? '&selection=' . $selection : '&selection=desc';
107
108 // Order
109 $param .= ( ! empty( $orderby ) ) ? '&orderby=' . $orderby : '&orderby=random';
110 $param .= ( ! empty( $order ) ) ? '&order=' . $order : '&order=asc';
111
112 // Max tags
113 if ( (int) $max != 0 ) {
114 $param .= '&number=' . $max;
115 }
116
117 // Size Mini
118 if ( (int) $smini != 0 ) {
119 $param .= '&smallest=' . $smini;
120 }
121
122 // Size Maxi
123 if ( (int) $smax != 0 ) {
124 $param .= '&largest=' . $smax;
125 }
126
127 // Unit
128 if ( ! empty( $unit ) ) {
129 $param .= '&unit=' . $unit;
130 }
131
132 // Format
133 if ( ! empty( $format ) ) {
134 $param .= '&format=' . $format;
135 }
136
137 // Use color ?
138 if ( (int) $color == 0 ) {
139 $param .= '&color=false';
140 }
141
142 // Color mini
143 if ( ! empty( $cmini ) ) {
144 $param .= '&mincolor=' . $cmini;
145 }
146
147 // Color Max
148 if ( ! empty( $cmax ) ) {
149 $param .= '&maxcolor=' . $cmax;
150 }
151
152 // Xformat
153 if ( ! empty( $xformat ) ) {
154 $param .= '&xformat=' . $xformat;
155 }
156
157 // Advanced usage
158 if ( ! empty( $adv_usage ) ) {
159 if ( substr( $adv_usage, 0, 1 ) != '&' ) {
160 $param .= '&';
161 }
162
163 $param .= $adv_usage;
164 }
165
166
167 // Taxonomy
168 $param .= '&taxonomy=' . $current_taxonomy;
169
170 echo $before_widget;
171 if ( ! empty( $title ) ) {
172 echo $before_title . $title . $after_title;
173 }
174 st_tag_cloud( apply_filters( 'simple-tags-widget', 'title=' . $param, $instance ) ); // Use Widgets title and no ST title !!
175 echo $after_widget;
176 }
177
178 /**
179 * Update widget settings
180 *
181 * @param array $new_instance
182 * @param array $old_instance
183 *
184 * @return array
185 * @author WebFactory Ltd
186 */
187 public function update( $new_instance, $old_instance ) {
188 $instance = $old_instance;
189
190 foreach ( (array) self::get_fields() as $field => $field_value ) {
191 $instance[ $field ] = $new_instance[ $field ];
192 }
193
194 return $instance;
195 }
196
197 /**
198 * Admin form for widgets
199 *
200 * @param array $instance
201 *
202 * @return void
203 * @author WebFactory Ltd
204 */
205 public function form( $instance ) {
206 //Defaults
207 $instance = wp_parse_args( (array) $instance, self::get_fields() );
208 ?>
209 <p style="color:red;"><?php _e( 'This widget is no longer being updated. Please use the "Tag Cloud (TaxoPress Shortcode)" widget instead.', 'simple-tags' ); ?></p>
210
211 <p>
212 <label for="<?php echo $this->get_field_id( 'title' ); ?>">
213 <?php _e( 'Title:', 'simple-tags' ); ?>
214 <input class="widefat" type="text" id="<?php echo $this->get_field_id( 'title' ); ?>"
215 name="<?php echo $this->get_field_name( 'title' ); ?>"
216 value="<?php echo esc_attr( $instance['title'] ); ?>"/>
217 </label>
218 </p>
219
220 <p>
221 <label for="<?php echo $this->get_field_id( 'max' ); ?>">
222 <?php _e( 'Max tags to display: (default: 45)', 'simple-tags' ); ?>
223 <input class="widefat" size="20" type="text" id="<?php echo $this->get_field_id( 'max' ); ?>"
224 name="<?php echo $this->get_field_name( 'max' ); ?>"
225 value="<?php echo esc_attr( $instance['max'] ); ?>"/>
226 </label>
227 </p>
228
229 <p>
230 <label for="<?php echo $this->get_field_id( 'selectionby' ); ?>">
231 <?php _e( 'Order by for DB selection tags:', 'simple-tags' ); ?>
232 <select id="<?php echo $this->get_field_id( 'selectionby' ); ?>"
233 name="<?php echo $this->get_field_name( 'selectionby' ); ?>">
234 <option <?php selected( $instance['selectionby'], 'name' ); ?>
235 value="name"><?php _e( 'Name', 'simple-tags' ); ?></option>
236 <option <?php selected( $instance['selectionby'], 'slug' ); ?>
237 value="slug"><?php _e( 'Slug', 'simple-tags' ); ?></option>
238 <option <?php selected( $instance['selectionby'], 'term_group' ); ?>
239 value="term_group"><?php _e( 'Term group', 'simple-tags' ); ?></option>
240 <option <?php selected( $instance['selectionby'], 'count' ); ?>
241 value="count"><?php _e( 'Counter (default)', 'simple-tags' ); ?></option>
242 <option <?php selected( $instance['selectionby'], 'random' ); ?>
243 value="random"><?php _e( 'Random', 'simple-tags' ); ?></option>
244 </select>
245 </label>
246 </p>
247
248 <p>
249 <label for="<?php echo $this->get_field_id( 'selection' ); ?>">
250 <?php _e( 'Order for DB selection tags:', 'simple-tags' ); ?>
251 <select id="<?php echo $this->get_field_id( 'selection' ); ?>"
252 name="<?php echo $this->get_field_name( 'selection' ); ?>">
253 <option <?php selected( $instance['selection'], 'asc' ); ?>
254 value="asc"><?php _e( 'ASC', 'simple-tags' ); ?></option>
255 <option <?php selected( $instance['selection'], 'desc' ); ?>
256 value="desc"><?php _e( 'DESC (default)', 'simple-tags' ); ?></option>
257 </select>
258 </label>
259 </p>
260
261 <p>
262 <label for="<?php echo $this->get_field_id( 'orderby' ); ?>">
263 <?php _e( 'Order by for display tags:', 'simple-tags' ); ?>
264 <select id="<?php echo $this->get_field_id( 'orderby' ); ?>"
265 name="<?php echo $this->get_field_name( 'orderby' ); ?>">
266 <option <?php selected( $instance['orderby'], 'name' ); ?>
267 value="name"><?php _e( 'Name', 'simple-tags' ); ?></option>
268 <option <?php selected( $instance['orderby'], 'count' ); ?>
269 value="count"><?php _e( 'Counter', 'simple-tags' ); ?></option>
270 <option <?php selected( $instance['orderby'], 'random' ); ?>
271 value="random"><?php _e( 'Random (default)', 'simple-tags' ); ?></option>
272 </select>
273 </label>
274 </p>
275
276 <p>
277 <label for="<?php echo $this->get_field_id( 'order' ); ?>">
278 <?php _e( 'Order for display tags:', 'simple-tags' ); ?>
279 <select id="<?php echo $this->get_field_id( 'order' ); ?>"
280 name="<?php echo $this->get_field_name( 'order' ); ?>">
281 <option <?php selected( $instance['order'], 'asc' ); ?>
282 value="asc"><?php _e( 'ASC', 'simple-tags' ); ?></option>
283 <option <?php selected( $instance['order'], 'desc' ); ?>
284 value="desc"><?php _e( 'DESC (default)', 'simple-tags' ); ?></option>
285 </select>
286 </label>
287 </p>
288
289 <p>
290 <label for="<?php echo $this->get_field_id( 'smini' ); ?>">
291 <?php _e( 'Font size mini: (default: 8)', 'simple-tags' ); ?>
292 <input class="widefat" size="20" type="text" id="<?php echo $this->get_field_id( 'smini' ); ?>"
293 name="<?php echo $this->get_field_name( 'smini' ); ?>"
294 value="<?php echo esc_attr( $instance['smini'] ); ?>"/>
295 </label>
296 </p>
297
298 <p>
299 <label for="<?php echo $this->get_field_id( 'smax' ); ?>">
300 <?php _e( 'Font size max: (default: 22)', 'simple-tags' ); ?>
301 <input class="widefat" size="20" type="text" id="<?php echo $this->get_field_id( 'smax' ); ?>"
302 name="<?php echo $this->get_field_name( 'smax' ); ?>"
303 value="<?php echo esc_attr( $instance['smax'] ); ?>"/>
304 </label>
305 </p>
306
307 <p>
308 <label for="<?php echo $this->get_field_id( 'unit' ); ?>">
309 <?php _e( 'Unit font size:', 'simple-tags' ); ?>
310 <select id="<?php echo $this->get_field_id( 'unit' ); ?>"
311 name="<?php echo $this->get_field_name( 'unit' ); ?>">
312 <option <?php selected( $instance['unit'], 'pt' ); ?>
313 value="pt"><?php _e( 'Point (default)', 'simple-tags' ); ?></option>
314 <option <?php selected( $instance['unit'], 'px' ); ?>
315 value="px"><?php _e( 'Pixel', 'simple-tags' ); ?></option>
316 <option <?php selected( $instance['unit'], 'em' ); ?>
317 value="em"><?php _e( 'Em', 'simple-tags' ); ?></option>
318 <option <?php selected( $instance['unit'], '%' ); ?>
319 value="%"><?php _e( 'Pourcent', 'simple-tags' ); ?></option>
320 </select>
321 </label>
322 </p>
323
324 <p>
325 <label for="<?php echo $this->get_field_id( 'format' ); ?>">
326 <?php _e( 'Format:', 'simple-tags' ); ?>
327 <select id="<?php echo $this->get_field_id( 'format' ); ?>"
328 name="<?php echo $this->get_field_name( 'format' ); ?>">
329 <option <?php selected( $instance['format'], 'flat' ); ?>
330 value="flat"><?php _e( 'Flat (default)', 'simple-tags' ); ?></option>
331 <option <?php selected( $instance['format'], 'list' ); ?>
332 value="list"><?php _e( 'List (UL/LI)', 'simple-tags' ); ?></option>
333 </select>
334 </label>
335 </p>
336
337 <p>
338 <label for="<?php echo $this->get_field_id( 'color' ); ?>">
339 <input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id( 'color' ); ?>"
340 name="<?php echo $this->get_field_name( 'color' ); ?>" <?php checked( (int) $instance['color'], 1 ); ?>
341 value="1"/>
342 <?php _e( 'Use auto color cloud:', 'simple-tags' ); ?>
343 </label>
344 </p>
345
346 <p>
347 <label for="<?php echo $this->get_field_id( 'cmini' ); ?>">
348 <?php _e( 'Font color mini: (default: #CCCCCC)', 'simple-tags' ); ?>
349 <input class="widefat" type="text" id="<?php echo $this->get_field_id( 'cmini' ); ?>"
350 name="<?php echo $this->get_field_name( 'cmini' ); ?>"
351 value="<?php echo esc_attr( $instance['cmini'] ); ?>"/>
352 </label>
353 </p>
354
355 <p>
356 <label for="<?php echo $this->get_field_id( 'cmax' ); ?>">
357 <?php _e( 'Font color max: (default: #000000)', 'simple-tags' ); ?>
358 <input class="widefat" type="text" id="<?php echo $this->get_field_id( 'cmax' ); ?>"
359 name="<?php echo $this->get_field_name( 'cmax' ); ?>"
360 value="<?php echo esc_attr( $instance['cmax'] ); ?>"/>
361 </label>
362 </p>
363
364 <p>
365 <label for="<?php echo $this->get_field_id( 'xformat' ); ?>">
366 <?php _e( 'Tag link format:', 'simple-tags' ); ?><br/>
367 <input class="widefat" style="width: 100% !important;" type="text"
368 id="<?php echo $this->get_field_id( 'xformat' ); ?>"
369 name="<?php echo $this->get_field_name( 'xformat' ); ?>"
370 value="<?php echo esc_attr( $instance['xformat'] ); ?>"/>
371 </label>
372 </p>
373
374 <p>
375 <label for="<?php echo $this->get_field_id( 'adv_usage' ); ?>">
376 <?php _e( 'Advanced usage:', 'simple-tags' ); ?><br/>
377 <input class="adv_usage" style="width: 100% !important;" type="text"
378 id="<?php echo $this->get_field_id( 'adv_usage' ); ?>"
379 name="<?php echo $this->get_field_name( 'adv_usage' ); ?>"
380 value="<?php echo esc_attr( $instance['adv_usage'] ); ?>"/>
381 </label>
382 </p>
383
384 <p>
385 <label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>">
386 <?php _e( "What to show", 'simple-tags' ); ?><br/>
387 <select id="<?php echo $this->get_field_id( 'taxonomy' ); ?>"
388 name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" style="width:100%;">
389 <?php
390 foreach ( get_object_taxonomies( 'post' ) as $_taxonomy ) {
391 $tax = get_taxonomy( $_taxonomy );
392 if ( ! $tax->show_tagcloud || empty( $tax->labels->name ) ) {
393 continue;
394 }
395
396 echo '<option ' . selected( $instance['taxonomy'], $tax->name, false ) . ' value="' . esc_attr( $tax->name ) . '">' . esc_html( $tax->labels->name ) . '</option>';
397 }
398 ?>
399 </select>
400 </label>
401 </p>
402 <?php
403 }
404 }