Initial commit

This commit is contained in:
Alexander Agnarson 2019-02-10 20:21:07 +01:00
commit ee50200fe7
353 changed files with 78977 additions and 0 deletions

View file

@ -0,0 +1,47 @@
<?php
/**
* Handles CSS output for background fields.
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 3.0.0
*/
/**
* Output overrides.
*/
class Kirki_Output_Field_Background extends Kirki_Output {
/**
* Processes a single item from the `output` array.
*
* @access protected
* @param array $output The `output` item.
* @param array $value The field's value.
*/
protected function process_output( $output, $value ) {
$output = wp_parse_args(
$output,
array(
'media_query' => 'global',
'element' => 'body',
'prefix' => '',
'suffix' => '',
)
);
foreach ( array( 'background-image', 'background-color', 'background-repeat', 'background-position', 'background-size', 'background-attachment' ) as $property ) {
// See https://github.com/aristath/kirki/issues/1808.
if ( 'background-color' === $property && isset( $value['background-color'] ) && $value['background-color'] && ( ! isset( $value['background-image'] ) || empty( $value['background-image'] ) ) ) {
$this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix'];
}
if ( isset( $value[ $property ] ) && ! empty( $value[ $property ] ) ) {
$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix'];
}
}
}
}

View file

@ -0,0 +1,55 @@
<?php
/**
* Handles CSS output for dimensions fields.
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.0
*/
/**
* Output overrides.
*/
class Kirki_Output_Field_Dimensions extends Kirki_Output {
/**
* Processes a single item from the `output` array.
*
* @access protected
* @param array $output The `output` item.
* @param array $value The field's value.
*/
protected function process_output( $output, $value ) {
$output = wp_parse_args(
$output, array(
'element' => '',
'property' => '',
'media_query' => 'global',
'prefix' => '',
'suffix' => '',
)
);
if ( ! is_array( $value ) ) {
return;
}
foreach ( array_keys( $value ) as $key ) {
$property = ( empty( $output['property'] ) ) ? $key : $output['property'] . '-' . $key;
if ( isset( $output['choice'] ) && $output['property'] ) {
if ( $key === $output['choice'] ) {
$property = $output['property'];
} else {
continue;
}
}
if ( false !== strpos( $output['property'], '%%' ) ) {
$property = str_replace( '%%', $key, $output['property'] );
}
$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $key ] ) . $output['suffix'];
}
}
}

View file

@ -0,0 +1,49 @@
<?php
/**
* Handles CSS output for image fields.
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 3.0.10
*/
/**
* Output overrides.
*/
class Kirki_Output_Field_Image extends Kirki_Output {
/**
* Processes a single item from the `output` array.
*
* @access protected
* @param array $output The `output` item.
* @param array $value The field's value.
*/
protected function process_output( $output, $value ) {
if ( ! isset( $output['element'] ) || ! isset( $output['property'] ) ) {
return;
}
$output = wp_parse_args(
$output, array(
'media_query' => 'global',
'prefix' => '',
'units' => '',
'suffix' => '',
)
);
if ( is_array( $value ) ) {
if ( isset( $output['choice'] ) && $output['choice'] ) {
$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value[ $output['choice'] ] ) . $output['units'] . $output['suffix'];
return;
}
if ( isset( $value['url'] ) ) {
$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value['url'] ) . $output['units'] . $output['suffix'];
return;
}
return;
}
$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['units'] . $output['suffix'];
}
}

View file

@ -0,0 +1,53 @@
<?php
/**
* Handles CSS output for multicolor fields.
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.0
*/
/**
* Output overrides.
*/
class Kirki_Output_Field_Multicolor extends Kirki_Output {
/**
* Processes a single item from the `output` array.
*
* @access protected
* @param array $output The `output` item.
* @param array $value The field's value.
*/
protected function process_output( $output, $value ) {
foreach ( $value as $key => $sub_value ) {
// If "element" is not defined, there's no reason to continue.
if ( ! isset( $output['element'] ) ) {
continue;
}
// If the "choice" is not the same as the $key in our loop, there's no reason to proceed.
if ( isset( $output['choice'] ) && $key !== $output['choice'] ) {
continue;
}
// If "property" is not defined, fallback to the $key.
$property = ( ! isset( $output['property'] ) || empty( $output['property'] ) ) ? $key : $output['property'];
// If "media_query" is not defined, use "global".
if ( ! isset( $output['media_query'] ) || empty( $output['media_query'] ) ) {
$output['media_query'] = 'global';
}
// If "suffix" is defined, add it to the value.
$output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
// Create the styles.
$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $sub_value . $output['suffix'];
}
}
}

View file

@ -0,0 +1,95 @@
<?php
/**
* Handles CSS output for typography fields.
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2017, Aristeides Stathopoulos
* @license https://opensource.org/licenses/MIT
* @since 2.2.0
*/
/**
* Output overrides.
*/
class Kirki_Output_Field_Typography extends Kirki_Output {
/**
* Processes a single item from the `output` array.
*
* @access protected
* @param array $output The `output` item.
* @param array $value The field's value.
*/
protected function process_output( $output, $value ) {
$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
$output['element'] = ( isset( $output['element'] ) ) ? $output['element'] : 'body';
$output['prefix'] = ( isset( $output['prefix'] ) ) ? $output['prefix'] : '';
$output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
$value = Kirki_Field_Typography::sanitize( $value );
$properties = array(
'font-family',
'font-size',
'variant',
'font-weight',
'font-style',
'letter-spacing',
'word-spacing',
'line-height',
'text-align',
'text-transform',
'text-decoration',
'color',
);
foreach ( $properties as $property ) {
// Early exit if the value is not in the defaults.
if ( ! isset( $this->field['default'][ $property ] ) ) {
continue;
}
// Early exit if the value is not saved in the values.
if ( ! isset( $value[ $property ] ) || ! $value[ $property ] ) {
continue;
}
// Early exit if we use "choice" but not for this property.
if ( isset( $output['choice'] ) && $output['choice'] !== $property ) {
continue;
}
// Take care of variants.
if ( 'variant' === $property && isset( $value['variant'] ) && ! empty( $value['variant'] ) ) {
// Get the font_weight.
$font_weight = str_replace( 'italic', '', $value['variant'] );
$font_weight = ( in_array( $font_weight, array( '', 'regular' ), true ) ) ? '400' : $font_weight;
// Is this italic?
$is_italic = ( false !== strpos( $value['variant'], 'italic' ) );
$this->styles[ $output['media_query'] ][ $output['element'] ]['font-weight'] = $font_weight;
if ( $is_italic ) {
$this->styles[ $output['media_query'] ][ $output['element'] ]['font-style'] = 'italic';
}
continue;
}
$property_value = $this->process_property_value( $property, $value[ $property ] );
if ( 'font-family' === $property ) {
$value['font-backup'] = ( isset( $value['font-backup'] ) ) ? $value['font-backup'] : '';
$property_value = $this->process_property_value(
$property, array(
$value['font-family'],
$value['font-backup'],
)
);
}
$property = ( isset( $output['choice'] ) && isset( $output['property'] ) ) ? $output['property'] : $property;
$property_value = ( is_array( $property_value ) && isset( $property_value[0] ) ) ? $property_value[0] : $property_value;
$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $property_value . $output['suffix'];
}
}
}