1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Handles CSS output for background-position. |
4
|
|
|
* |
5
|
|
|
* @package Kirki |
6
|
|
|
* @subpackage Controls |
7
|
|
|
* @copyright Copyright (c) 2017, Aristeides Stathopoulos |
8
|
|
|
* @license https://opensource.org/licenses/MIT |
9
|
|
|
* @since 2.2.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Output overrides. |
14
|
|
|
*/ |
15
|
|
|
class Kirki_Output_Property_Background_Position extends Kirki_Output_Property { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Modifies the value. |
19
|
|
|
* |
20
|
|
|
* @access protected |
21
|
|
|
*/ |
22
|
|
|
protected function process_value() { |
23
|
|
|
$this->value = trim( $this->value ); |
|
|
|
|
24
|
|
|
|
25
|
|
|
// If you use calc() there, I suppose you know what you're doing. |
26
|
|
|
// No need to process this any further, just exit. |
27
|
|
|
if ( false !== strpos( $this->value, 'calc' ) ) { |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
// If the value is initial or inherit, we don't need to do anything. |
32
|
|
|
// Just exit. |
33
|
|
|
if ( 'initial' === $this->value || 'inherit' === $this->value ) { |
34
|
|
|
return; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$x_dimensions = array( 'left', 'center', 'right' ); |
38
|
|
|
$y_dimensions = array( 'top', 'center', 'bottom' ); |
39
|
|
|
|
40
|
|
|
// If there's a space, we have an X and a Y value. |
41
|
|
|
if ( false !== strpos( $this->value, ' ' ) ) { |
42
|
|
|
$xy = explode( ' ', $this->value ); |
43
|
|
|
|
44
|
|
|
$x = trim( $xy[0] ); |
45
|
|
|
$y = trim( $xy[1] ); |
46
|
|
|
|
47
|
|
|
// If x is not left/center/right, we need to sanitize it. |
48
|
|
|
if ( ! in_array( $x, $x_dimensions, true ) ) { |
49
|
|
|
$x = sanitize_text_field( $x ); |
50
|
|
|
} |
51
|
|
|
if ( ! in_array( $y, $y_dimensions, true ) ) { |
52
|
|
|
$y = sanitize_text_field( $y ); |
53
|
|
|
} |
54
|
|
|
$this->value = $x . ' ' . $y; |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
$x = 'center'; |
58
|
|
|
foreach ( $x_dimensions as $x_dimension ) { |
59
|
|
|
if ( false !== strpos( $this->value, $x_dimension ) ) { |
60
|
|
|
$x = $x_dimension; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
$y = 'center'; |
64
|
|
|
foreach ( $y_dimensions as $y_dimension ) { |
65
|
|
|
if ( false !== strpos( $this->value, $y_dimension ) ) { |
66
|
|
|
$y = $y_dimension; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
$this->value = $x . ' ' . $y; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|