ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-kirki-output-property-background-position.php (1969B)


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