Completed
Push — develop ( fe9689...674c42 )
by Aristeides
02:41
created

Kirki_Output_Field_Gradient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B process_output() 0 28 4
1
<?php
2
/**
3
 * Handles CSS output for dimensions fields.
4
 *
5
 * @package     Kirki
6
 * @subpackage  Controls
7
 * @copyright   Copyright (c) 2017, Aristeides Stathopoulos
8
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
9
 * @since       2.2.0
10
 */
11
12
/**
13
 * Output overrides.
14
 */
15
class Kirki_Output_Field_Gradient extends Kirki_Output {
16
17
	/**
18
	 * Processes a single item from the `output` array.
19
	 *
20
	 * @access protected
21
	 * @param array $output The `output` item.
22
	 * @param array $value  The field's value.
23
	 */
24
	protected function process_output( $output, $value ) {
25
		// Make sure we've got everything by defining some defaults.
26
		$value = wp_parse_args( $value, array(
27
			'angle' => 0,
28
			'start' => array(
29
				'color'    => 'rgba(0,0,0,0)',
30
				'position' => 0,
31
			),
32
			'end' => array(
33
				'color'    => 'rgba(0,0,0,0)',
34
				'position' => 100,
35
			),
36
			'mode' => 'linear',
37
		) );
38
39
		$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
40
41
		$this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = $value['start']['color'];
42
		switch ( $value['mode'] ) {
43
44
			case 'linear':
45
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = 'linear-gradient(' . intval( $value['angle'] ) . 'deg, ' . $value['start']['color'] . ' ' . $value['start']['position'] . '%,' . $value['end']['color'] . ' ' . $value['end']['position'] . '%)';
46
				break;
47
			case 'radial':
48
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = 'radial-gradient(ellipse at center,' . $value['start']['color'] . ' ' . $value['start']['position'] . '%,' . $value['end']['color'] . ' ' . $value['end']['position'] . '%)';
49
				break;
50
		}
51
	}
52
}
53