Issues (36)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

classes/uix/ui/panel.php (3 issues)

Upgrade to new PHP Analysis Engine

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 Panel
4
 *
5
 * @package   ui
6
 * @author    David Cramer
7
 * @license   GPL-2.0+
8
 * @link
9
 * @copyright 2016 David Cramer
10
 */
11
namespace uix\ui;
12
13
/**
14
 * UIX panel. a holder to contain sections. a panel with multiple sections creates a tabbed interface to switch between sections areas.
15
 *
16
 * @package uix\ui
17
 * @author  David Cramer
18
 */
19
class panel extends \uix\data\data {
20
21
	/**
22
	 * The type of object
23
	 *
24
	 * @since 1.0.0
25
	 * @access public
26
	 * @var      string
27
	 */
28
	public $type = 'panel';
29
30
	/**
31
	 * Define core panel styles ans scripts
32
	 *
33
	 * @since 1.0.0
34
	 * @access public
35
	 */
36 14
	public function set_assets() {
37
38 14
		$this->assets['script'][ $this->type ] = $this->url . 'assets/js/' . $this->type . UIX_ASSET_DEBUG . '.js';
39 14
		$this->assets['style'][ $this->type ]  = $this->url . 'assets/css/' . $this->type . UIX_ASSET_DEBUG . '.css';
40
41 14
		parent::set_assets();
42
43 14
	}
44
45
	/**
46
	 * Get Data from all controls of this section
47
	 *
48
	 * @since 1.0.0
49
	 * @see \uix\load
50
	 * @return array|null Array of sections data structured by the controls or null if none.
51
	 */
52 4
	public function get_data() {
53
54 4
		if ( empty( $this->data ) ) {
55 4
			$this->data = array(
56 4
				$this->slug => $this->get_child_data(),
57
			);
58
		}
59
60 4
		return $this->data;
61
	}
62
63
	/**
64
	 * Sets the data for all children
65
	 *
66
	 * @since 1.0.0
67
	 * @access protected
68
	 * @return array data of the child objects.
69
	 */
70 4
	protected function get_child_data() {
71
72 4
		$data = array();
73 4
		foreach ( $this->child as $child ) {
74 4
			if ( null !== $child->get_data() ) {
75 4
				$data += $child->get_data();
76
			}
77
		}
78 4
		if ( ! empty( $this->struct['data'] ) ) {
79
			$data = array_merge( $this->struct['data'], $data );
80
		}
81
82 4
		return $data;
83
	}
84
85
86
	/**
87
	 * Sets the data for all children
88
	 *
89
	 * @since 1.0.0
90
	 * @access public
91
	 */
92 4
	public function set_data( $data ) {
93
94 4
		if ( ! empty( $data[ $this->slug ] ) ) {
95 3
			foreach ( $this->child as $child ) {
96 3
				if ( method_exists( $child, 'set_data' ) ) {
97 3
					$child->set_data( $data[ $this->slug ] );
98
				}
99
			}
100 3
			$this->data = $data[ $this->slug ];
101
		}
102
103 4
	}
104
105
	/**
106
	 * Render the panel
107
	 *
108
	 * @since 1.0.0
109
	 * @access public
110
	 */
111 6
	public function render() {
112 6
		$output = null;
113
114 6
		if ( $this->child_count() > 0 ) {
115
116 1
			$output .= '<div id="panel-' . esc_attr( $this->id() ) . '" class="uix-' . esc_attr( $this->type ) . '-inside ' . esc_attr( $this->wrapper_class_names() ) . '">';
117
			// render a lable
118 1
			$output .= $this->label();
119
			// render a desciption
120 1
			$output .= $this->description();
121
			// render navigation tabs
122 1
			$output .= $this->navigation();
123
			// sections
124 1
			$output .= $this->panel_section();
125
126 1
			$output .= '</div>';
127
		} else {
128
			// sections
129 5
			$output .= $this->panel_section();
130
		}
131
132 6
		$output .= $this->render_template();
133
134 6
		return $output;
135
	}
136
137
	/**
138
	 * Determines the number of useable children for tab display
139
	 *
140
	 * @since 1.0.0
141
	 * @access public
142
	 * @return int Number of tabable children
143
	 */
144 7
	public function child_count() {
145
146 7
		$count = 0;
147 7
		if ( ! empty( $this->child ) ) {
148 6
			foreach ( $this->child as $child ) {
149 6
				if ( $this->is_section_object( $child ) ) {
150 6
					$count ++;
151
				}
152
			}
153
		}
154
155 7
		return $count;
156
	}
157
158
	/**
159
	 * Check if child is a section object
160
	 *
161
	 * @since 1.0.0
162
	 * @access public
163
	 *
164
	 * @param uix Object to test if it is to be rendered in a section
165
	 *
166
	 * @return string|null HTML of rendered description
167
	 */
168 6
	public function is_section_object( $section ) {
169 6
		$types = explode( '\\', get_class( $section ) );
170 6
		$excl = array( 'help', 'header', 'footer', 'control' );
171 6
		$merge = array_merge( $types, $excl );
172 6
		$unique = array_unique( $merge );
173 6
		return count( $merge ) === count( $unique );
174
	}
175
176
	/**
177
	 * Check if child is a control object
178
	 *
179
	 * @since 1.0.0
180
	 * @access public
181
	 *
182
	 * @param uix Object to test if it is to be rendered in a section
183
	 *
184
	 * @return string|null HTML of rendered description
185
	 */
186 4
	public function is_control_object( $object ) {
187
188 4
		return (bool) strpos( get_class( $object ), 'control' );
189
	}
190
191
	/**
192
	 * Returns the class names for the tab wrapper
193
	 *
194
	 * @since 1.0.0
195
	 * @access public
196
	 */
197 1
	public function wrapper_class_names() {
198
199
		$wrapper_class_names = array(
200 1
			'uix-panel-inside',
201
		);
202
203 1
		if ( $this->child_count() > 1 ) {
204
			$wrapper_class_names[] = 'uix-has-tabs';
205
206
			if ( ! empty( $this->struct['top_tabs'] ) ) {
207
				$wrapper_class_names[] = 'uix-top-tabs';
208
			}
209
		}
210
211 1
		return implode( ' ', $wrapper_class_names );
212
	}
213
214
	/**
215
	 * Render the panels label
216
	 *
217
	 * @since 1.0.0
218
	 * @access public
219
	 * @return string|null rendered html of label
220
	 */
221 1 View Code Duplication
	public function label() {
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.

Loading history...
222 1
		$output = null;
223 1
		if ( ! empty( $this->struct['label'] ) ) {
224
			$output .= '<div class="uix-' . esc_attr( $this->type ) . '-heading"><h3 class="uix-' . esc_attr( $this->type ) . '-title">' . esc_html( $this->struct['label'] ) . '</h3></div>';
225
		}
226
227 1
		return $output;
228
	}
229
230
	/**
231
	 * Render the panels Description
232
	 *
233
	 * @since 1.0.0
234
	 * @access public
235
	 * @return string|null HTML of rendered description
236
	 */
237 1 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.

Loading history...
238 1
		$output = null;
239 1
		if ( ! empty( $this->struct['description'] ) ) {
240 1
			$output .= '<div class="uix-' . esc_attr( $this->type ) . '-heading"><p class="uix-' . esc_attr( $this->type ) . '-subtitle description">' . esc_html( $this->struct['description'] ) . '</p></div>';
241
		}
242
243 1
		return $output;
244
	}
245
246
	/**
247
	 * Render the panels navigation tabs
248
	 *
249
	 * @since 1.0.0
250
	 * @access public
251
	 * @return string|null Html of rendered navigation tabs
252
	 */
253 1
	public function navigation() {
254 1
		$output = null;
255
256 1
		if ( $this->child_count() > 1 ) {
257
258
			$output .= '<ul class="uix-' . esc_attr( $this->type ) . '-tabs uix-panel-tabs">';
259
			$active = 'true';
260
			foreach ( $this->child as $child ) {
261
				if ( $this->is_section_object( $child ) ) {
262
					$output .= $this->tab_label( $child, $active );
263
					$active = 'false';
264
				}
265
			}
266
			$output .= '</ul>';
267
		}
268
269 1
		return $output;
270
	}
271
272
	/**
273
	 * Render the tabs label
274
	 *
275
	 * @since 1.0.0
276
	 *
277
	 * @param object $child Child object to render tab for.
278
	 * @param string $active Set the tabactive or not.
279
	 *
280
	 * @access private
281
	 * @return string|null html of rendered label
282
	 */
283
	private function tab_label( $child, $active ) {
284
285
		$output = null;
286
287
		$label = esc_html( $child->struct['label'] );
288
289
		if ( ! empty( $child->struct['icon'] ) ) {
290
			$label = '<i class="dashicons ' . $child->struct['icon'] . '"></i><span class="label">' . esc_html( $child->struct['label'] ) . '</span>';
291
		}
292
293
		$output .= '<li aria-selected="' . esc_attr( $active ) . '">';
294
		$output .= '<a href="#' . esc_attr( $child->id() ) . '" data-parent="' . esc_attr( $this->id() ) . '" class="uix-tab-trigger">' . $label . '</a>';
295
		$output .= '</li>';
296
297
		return $output;
298
	}
299
300
	/**
301
	 * Render the panels Description
302
	 *
303
	 * @since 1.0.0
304
	 * @access public
305
	 * @return string|null HTML of rendered description
306
	 */
307 6
	public function panel_section() {
308 6
		$output = null;
309
310
		// render the section wrapper
311 6
		$output .= '<div class="uix-' . esc_attr( $this->type ) . '-sections uix-sections">';
312
313 6
		$hidden = 'false';
314 6
		foreach ( $this->child as $section ) {
315
316 5
			if ( ! $this->is_section_object( $section ) && ! $this->is_control_object( $section ) ) {
317 3
				continue;
318
			}
319
320 2
			$section->struct['active'] = $hidden;
321 2
			$output .= $section->render();
322 2
			$hidden = 'true';
323
		}
324
325 6
		$output .= '</div>';
326
327 6
		return $output;
328
	}
329
330
	/**
331
	 * Render a template based object
332
	 *
333
	 * @since 1.0.0
334
	 * @access public
335
	 * @return string|null HTML of rendered template
336
	 */
337 6 View Code Duplication
	public function render_template() {
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.

Loading history...
338
		// template
339 6
		$_output = null;
340
341 6
		if ( ! empty( $this->struct['template'] ) ) {
342 2
			ob_start();
343 2
			include $this->struct['template'];
344 2
			$_output .= ob_get_clean();
345
		}
346
347 6
		return $_output;
348
	}
349
350
	/**
351
	 * Enqueues specific tabs assets for the active pages
352
	 *
353
	 * @since 1.0.0
354
	 * @access protected
355
	 */
356 1
	protected function set_active_styles() {
357 1
		$style = '#panel-' . $this->id() . ' > .uix-panel-tabs > li[aria-selected="true"] a {box-shadow: 3px 0 0 ' . $this->base_color() . ' inset;}';
358 1
		$style .= '#panel-' . $this->id() . '.uix-top-tabs > .uix-panel-tabs > li[aria-selected="true"] a {	box-shadow: 0 3px 0 ' . $this->base_color() . ' inset;}';
359 1
		uix_share()->set_active_styles( $style );
360 1
	}
361
}
362