This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * UIX Controls |
||
4 | * |
||
5 | * @package controls |
||
6 | * @author David Cramer |
||
7 | * @license GPL-2.0+ |
||
8 | * @link |
||
9 | * @copyright 2016 David Cramer |
||
10 | */ |
||
11 | namespace uix\ui; |
||
12 | |||
13 | /** |
||
14 | * Base UIX Control class. |
||
15 | * |
||
16 | * @since 1.0.0 |
||
17 | */ |
||
18 | class control extends \uix\data\data { |
||
19 | |||
20 | /** |
||
21 | * The type of object |
||
22 | * |
||
23 | * @since 1.0.0 |
||
24 | * @access public |
||
25 | * @var string |
||
26 | */ |
||
27 | public $type = 'control'; |
||
28 | |||
29 | /** |
||
30 | * Register the UIX objects |
||
31 | * |
||
32 | * @since 1.0.0 |
||
33 | * @access public |
||
34 | * |
||
35 | * @param string $slug Object slug |
||
36 | * @param array $object object structure array |
||
37 | * |
||
38 | * @return object|\uix object instance |
||
39 | */ |
||
40 | 9 | public static function register( $slug, $object, $parent = null ) { |
|
41 | |||
42 | 9 | $caller = get_called_class(); |
|
43 | // get the current instance |
||
44 | 9 | if ( empty( $object['type'] ) || ! uix()->is_callable( 'control\\' . $object['type'] ) ) { |
|
45 | 1 | $object['type'] = 'text'; |
|
46 | } |
||
47 | |||
48 | 9 | $caller = $caller . '\\' . $object['type']; |
|
49 | |||
50 | 9 | return new $caller( $slug, $object, $parent ); |
|
51 | |||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Sets the controls data |
||
56 | * |
||
57 | * @since 1.0.0 |
||
58 | * @see \uix\uix |
||
59 | * @access public |
||
60 | */ |
||
61 | 9 | public function setup() { |
|
62 | |||
63 | // run parents to setup sanitization filters |
||
64 | 9 | parent::setup(); |
|
65 | 9 | $value = array( $this->slug, '' ); |
|
66 | 9 | $data = uix()->request_vars( 'post' ); |
|
67 | 9 | if ( ! empty( $this->struct['value'] ) ) { |
|
68 | 5 | $value[ $this->slug ] = $this->struct['value']; |
|
69 | } |
||
70 | 9 | if ( isset( $data[ $this->id() ] ) ) { |
|
71 | $value[ $this->slug ] = $data[ $this->id() ]; |
||
72 | } |
||
73 | 9 | $this->set_data( $value ); |
|
74 | // base attributes defined |
||
75 | 9 | $this->attributes['name'] = $this->name(); |
|
76 | 9 | $this->attributes['id'] = $this->id() . '-control'; |
|
77 | 9 | } |
|
78 | |||
79 | /** |
||
80 | * Create and Return the control's input name |
||
81 | * |
||
82 | * @since 1.0.0 |
||
83 | * @access public |
||
84 | * @return string The control name |
||
85 | */ |
||
86 | 9 | public function name() { |
|
87 | 9 | return $this->id(); |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * Sets the attributes for the control. |
||
92 | * |
||
93 | * @since 1.0.0 |
||
94 | * @access public |
||
95 | */ |
||
96 | 5 | public function set_attributes() { |
|
97 | |||
98 | 5 | if ( ! empty( $this->struct['config'] ) ) { |
|
99 | $this->set_config(); |
||
100 | } |
||
101 | |||
102 | 5 | $this->attributes['class'] = implode( ' ', $this->classes() ); |
|
103 | |||
104 | 5 | parent::set_attributes(); |
|
105 | |||
106 | 5 | } |
|
107 | |||
108 | /** |
||
109 | * Handy method for setting data-* attributes using the setup parameter |
||
110 | * @since 1.0.0 |
||
111 | * @access public |
||
112 | */ |
||
113 | public function set_config() { |
||
114 | |||
115 | foreach ( $this->struct['config'] as $key => $setting ) { |
||
116 | $this->attributes[ 'data-' . $key ] = $setting; |
||
117 | } |
||
118 | |||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Gets the classes for the control input |
||
123 | * |
||
124 | * @since 1.0.0 |
||
125 | * @access public |
||
126 | * @return array |
||
127 | */ |
||
128 | 3 | public function classes() { |
|
129 | |||
130 | return array( |
||
131 | 3 | 'widefat', |
|
132 | ); |
||
133 | |||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Define core page styles |
||
138 | * |
||
139 | * @since 1.0.0 |
||
140 | * @access public |
||
141 | */ |
||
142 | 9 | public function set_assets() { |
|
143 | 9 | $this->assets['style']['controls'] = $this->url . 'assets/css/control' . UIX_ASSET_DEBUG . '.css'; |
|
144 | 9 | parent::set_assets(); |
|
145 | 9 | } |
|
146 | |||
147 | /** |
||
148 | * Render the Control |
||
149 | * |
||
150 | * @since 1.0.0 |
||
151 | * @see \uix\ui\uix |
||
152 | * @access public |
||
153 | * @return string HTML of rendered control |
||
154 | */ |
||
155 | 5 | public function render() { |
|
156 | |||
157 | 5 | $output = '<div id="' . esc_attr( $this->id() ) . '" class="uix-control uix-control-' . esc_attr( $this->type ) . ' ' . esc_attr( $this->id() ) . '">'; |
|
158 | |||
159 | 5 | $output .= $this->label(); |
|
160 | 5 | $output .= '<div class="uix-control-input">'; |
|
161 | 5 | $output .= $this->input(); |
|
162 | 5 | $output .= '</div>'; |
|
163 | 5 | $output .= $this->description(); |
|
164 | |||
165 | 5 | $output .= '</div>'; |
|
166 | |||
167 | 5 | return $output; |
|
168 | } |
||
169 | |||
170 | /** |
||
171 | * Returns the label for the control |
||
172 | * |
||
173 | * @since 1.0.0 |
||
174 | * @access public |
||
175 | * @return string label of control |
||
176 | */ |
||
177 | 5 | View Code Duplication | public function label() { |
0 ignored issues
–
show
|
|||
178 | 5 | $output = null; |
|
179 | 5 | if ( isset( $this->struct['label'] ) ) { |
|
180 | 2 | $output .= '<label for="' . esc_attr( $this->id() ) . '-control"><span class="uix-control-label">' . esc_html( $this->struct['label'] ) . '</span></label>'; |
|
181 | } |
||
182 | |||
183 | 5 | return $output; |
|
184 | } |
||
185 | |||
186 | /** |
||
187 | * Returns the main input field for rendering |
||
188 | * |
||
189 | * @since 1.0.0 |
||
190 | * @see \uix\ui\uix |
||
191 | * @access public |
||
192 | * @return string Input field HTML striung |
||
193 | */ |
||
194 | 4 | public function input() { |
|
195 | |||
196 | 4 | return '<input type="' . esc_attr( $this->type ) . '" value="' . esc_attr( $this->get_value() ) . '" ' . $this->build_attributes() . '>'; |
|
197 | } |
||
198 | |||
199 | /** |
||
200 | * get this controls value |
||
201 | * |
||
202 | * @since 1.0.0 |
||
203 | * @access public |
||
204 | * @return mixed the controls value |
||
205 | */ |
||
206 | 5 | public function get_value() { |
|
207 | 5 | $value = null; |
|
208 | 5 | $data = $this->get_data(); |
|
209 | |||
210 | 5 | if ( null !== $data ) { |
|
211 | 5 | $value = $data[ $this->slug ]; |
|
212 | } |
||
213 | |||
214 | 5 | return $value; |
|
215 | } |
||
216 | |||
217 | /** |
||
218 | * Returns the description for the control |
||
219 | * |
||
220 | * @since 1.0.0 |
||
221 | * @access public |
||
222 | * @return string description string |
||
223 | */ |
||
224 | 5 | View Code Duplication | public function description() { |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
225 | 5 | $output = null; |
|
226 | 5 | if ( isset( $this->struct['description'] ) ) { |
|
227 | 1 | $output .= '<span class="uix-control-description">' . esc_html( $this->struct['description'] ) . '</span>'; |
|
228 | } |
||
229 | |||
230 | 5 | return $output; |
|
231 | } |
||
232 | |||
233 | /** |
||
234 | * checks if the current control is active |
||
235 | * |
||
236 | * @since 1.0.0 |
||
237 | * @access public |
||
238 | */ |
||
239 | 3 | public function is_active() { |
|
240 | 3 | if ( ! empty( $this->parent ) ) { |
|
241 | 1 | return $this->parent->is_active(); |
|
242 | } |
||
243 | |||
244 | 3 | return parent::is_active(); |
|
245 | } |
||
246 | |||
247 | } |
||
248 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.