ru-se.com

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

class-kirki-output-field-typography.php (4551B)


      1 <?php
      2 /**
      3  * Handles CSS output for typography fields.
      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_Field_Typography' ) ) {
     13 
     14 	/**
     15 	 * Output overrides.
     16 	 */
     17 	class Kirki_Output_Field_Typography extends Kirki_Output {
     18 
     19 		/**
     20 		 * Processes a single item from the `output` array.
     21 		 *
     22 		 * @access protected
     23 		 * @param array $output The `output` item.
     24 		 * @param array $value  The field's value.
     25 		 */
     26 		protected function process_output( $output, $value ) {
     27 			$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
     28 			$output['mobile_media_query'] = 'global';
     29 			$output['element']     = ( isset( $output['element'] ) ) ? $output['element'] : 'body';
     30 
     31 			// Take care of font-families.
     32 			if ( isset( $value['font-family'] ) && ! empty( $value['font-family'] ) ) {
     33 				$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
     34 				$this->styles[ $output['media_query'] ][ $output['element'] ]['font-family'] = $this->process_property_value( 'font-family', $value['font-family'] );
     35 			}
     36 
     37 			// Add support for the older font-weight parameter.
     38 			// This has been deprecated so the code below is just to add some backwards-compatibility.
     39 			// Once a user visits their customizer and make changes to their typography,
     40 			// new values are saved and this one is no longer used.
     41 			if ( isset( $value['font-weight'] ) && ! empty( $value['font-weight'] ) ) {
     42 				$this->styles[ $output['media_query'] ][ $output['element'] ]['font-weight'] = $value['font-weight'];
     43 			}
     44 
     45 			// Take care of variants.
     46 			if ( isset( $value['variant'] ) && ! empty( $value['variant'] ) ) {
     47 
     48 				// Get the font_weight.
     49 				$font_weight = str_replace( 'italic', '', $value['variant'] );
     50 				$font_weight = ( in_array( $font_weight, array( '', 'regular' ) ) ) ? '400' : $font_weight;
     51 
     52 				// Is this italic?
     53 				$is_italic = ( false !== strpos( $value['variant'], 'italic' ) );
     54 				$this->styles[ $output['media_query'] ][ $output['element'] ]['font-weight'] = $font_weight;
     55 				$font_style = $is_italic ? 'italic' : 'normal' ;
     56 				$this->styles[ $output['media_query'] ][ $output['element'] ]['font-style'] = $font_style;
     57 			}
     58 
     59 			$fontSizeMedia = $output['media_query'];
     60 			if ( isset( $value['mobile-font-size'] ) && ! empty( $value['mobile-font-size'] ) ) {
     61 				$this->styles[ $output['mobile_media_query'] ][ $output['element'] ]['font-size'] = $value['mobile-font-size'];
     62 				$fontSizeMedia = "@media only screen and (min-width: 768px)";
     63 			}
     64 			// Take care of font-size.
     65 			if ( isset( $value['font-size'] ) && ! empty( $value['font-size'] ) ) {
     66 				$this->styles[ $fontSizeMedia ][ $output['element'] ]['font-size'] = $value['font-size'];
     67 
     68 			}
     69 
     70 			// Take care of line-height.
     71 			if ( isset( $value['line-height'] ) && ! empty( $value['line-height'] ) ) {
     72 				$this->styles[ $output['media_query'] ][ $output['element'] ]['line-height'] = $value['line-height'];
     73 			}
     74 
     75 			// Take care of letter-spacing.
     76 			if ( isset( $value['letter-spacing'] ) && ( ! empty( $value['letter-spacing'] ) || '0' == $value['letter-spacing'] ) ) {
     77 				$this->styles[ $output['media_query'] ][ $output['element'] ]['letter-spacing'] = $value['letter-spacing'];
     78 			}
     79 
     80 			// Take care of text-align.
     81 			if ( isset( $value['text-align'] ) && ! empty( $value['text-align'] ) ) {
     82 				$this->styles[ $output['media_query'] ][ $output['element'] ]['text-align'] = $value['text-align'];
     83 			}
     84 
     85 			// Take care of text-transform.
     86 			if ( isset( $value['text-transform'] ) && ! empty( $value['text-transform'] ) ) {
     87 				$this->styles[ $output['media_query'] ][ $output['element'] ]['text-transform'] = $value['text-transform'];
     88 			}
     89 
     90 			// Take care of color.
     91 			if ( isset( $value['color'] ) && ! empty( $value['color'] ) ) {
     92 				$this->styles[ $output['media_query'] ][ $output['element'] ]['color'] = $value['color'];
     93             }
     94 
     95             foreach ($this->output as $index => $o) {
     96 					if(!isset($o['property']) || !is_array($value)){
     97 						continue;
     98 					}
     99 
    100 					$v = parent::apply_value_pattern($o, $value);
    101 					if(!is_array($v)){
    102 						$o['media_query'] = (isset($o['media_query'])) ? $o['media_query'] : 'global';
    103 						$o['element']     = (isset($o['element'])) ? $o['element'] : 'body';
    104 						$this->styles[ $o['media_query'] ][$o['element']][ $o['property'] ] = $v;
    105 					}
    106 
    107 			}
    108 		}
    109 	}
    110 }