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