forked from rickard2/utcw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utcw-widget.php
127 lines (109 loc) · 3.53 KB
/
utcw-widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* Ultimate Tag Cloud Widget
* @author Rickard Andersson <[email protected]>
* @version 2.0
* @license GPLv2
* @package utcw
* @subpackage main
* @since 2.0
*/
if ( ! defined( 'ABSPATH' ) ) die();
/**
* Widget class for WordPress integration
*
* @since 1.0
* @package utcw
* @subpackage main
*/
class UTCW extends WP_Widget {
/**
* Reference to the main plugin instance
*
* @var UTCW_Plugin
* @since 2.0
*/
private $plugin;
/**
* Constructor
*
* @param UTCW_Plugin $plugin Optional. Plugin instance for dependency injection
*
* @return UTCW
* @since 1.0
*/
function __construct( UTCW_Plugin $plugin = null ) {
$options = array( 'description' => __( 'Highly configurable tag cloud', 'utcw' ) );
parent::WP_Widget( false, __( 'Ultimate Tag Cloud', 'utcw' ), $options );
$this->plugin = $plugin ? $plugin : UTCW_Plugin::get_instance();
}
/**
* Action handler for the form in the admin panel
*
* @param array $new_instance
* @param array $old_instance
*
* @return array
* @since 1.0
*/
function update( array $new_instance, array $old_instance ) {
// Overwrite the form values with the saved configuration
if ( isset( $new_instance[ 'load_config' ] ) && isset( $new_instance[ 'load_config_name' ] ) && $new_instance[ 'load_config_name' ] ) {
$loaded_configuration = $this->plugin->load_configuration( $new_instance[ 'load_config_name' ] );
if ( $loaded_configuration ) {
$new_instance = $loaded_configuration;
}
}
// Checkbox inputs which are unchecked, will not be set in $new_instance. Set them manually to false
$checkbox_settings = array( 'show_title_text', 'show_title', 'debug', 'reverse', 'case_sensitive' );
foreach ( $checkbox_settings as $checkbox_setting ) {
if ( ! isset( $new_instance[ $checkbox_setting ] ) ) {
$new_instance[ $checkbox_setting ] = false;
}
}
$config = new UTCW_Config( $new_instance, $this->plugin );
if ( isset( $new_instance[ 'save_config' ] ) && isset( $new_instance[ 'save_config_name' ] ) && $new_instance[ 'save_config_name' ] ) {
$this->plugin->save_configuration( $new_instance[ 'save_config_name' ], $config->get_instance() );
}
return $config->get_instance();
}
/**
* Function for handling the widget control in admin panel
*
* @param array $instance
*
* @return void|string
* @since 1.0
*/
function form( array $instance ) {
/** @noinspection PhpUnusedLocalVariableInspection */
$config = new UTCW_Config( $instance, $this->plugin );
/** @noinspection PhpUnusedLocalVariableInspection */
$configurations = $this->plugin->get_configurations();
/** @noinspection PhpUnusedLocalVariableInspection */
$available_post_types = $this->plugin->get_allowed_post_types();
/** @noinspection PhpUnusedLocalVariableInspection */
$available_taxonomies = $this->plugin->get_allowed_taxonomies_objects();
/** @noinspection PhpUnusedLocalVariableInspection */
$users = $this->plugin->get_users();
/** @noinspection PhpUnusedLocalVariableInspection */
$terms = $this->plugin->get_terms();
// Content of the widget settings form
require 'pages/settings.php';
}
/**
* Function for rendering the widget
*
* @param array $args
*
* @param array $instance
*/
function widget( array $args, array $instance ) {
global $wpdb;
$input = array_merge( $instance, $args );
$config = new UTCW_Config( $input, $this->plugin );
$data = new UTCW_Data( $config, $this->plugin, $wpdb );
$render = new UTCW_Render( $config, $data, $this->plugin );
$render->render();
}
}