| 1 |
<?php if (! defined('ABSPATH')) { |
| 2 |
die; |
| 3 |
} // Cannot access directly. |
| 4 |
/** |
| 5 |
* |
| 6 |
* Field: dimensions |
| 7 |
* |
| 8 |
* @since 1.0.0 |
| 9 |
* @version 1.0.0 |
| 10 |
* |
| 11 |
*/ |
| 12 |
if (! class_exists('DarkifyField_dimensions')) { |
| 13 |
class DarkifyField_dimensions extends DarkifyFields |
| 14 |
{ |
| 15 |
|
| 16 |
public function __construct($field, $value = '', $unique = '', $where = '', $parent = '') |
| 17 |
{ |
| 18 |
parent::__construct($field, $value, $unique, $where, $parent); |
| 19 |
} |
| 20 |
|
| 21 |
public function render() |
| 22 |
{ |
| 23 |
|
| 24 |
$args = wp_parse_args($this->field, array( |
| 25 |
'width_icon' => '<i class="icofont-long-arrow-left"></i><i class="icofont-long-arrow-right"></i>', |
| 26 |
'height_icon' => '<i class="icofont-long-arrow-up"></i><i class="icofont-long-arrow-down"></i>', |
| 27 |
'width_placeholder' => esc_html__('width', 'darkify'), |
| 28 |
'height_placeholder' => esc_html__('height', 'darkify'), |
| 29 |
'width' => true, |
| 30 |
'height' => true, |
| 31 |
'unit' => true, |
| 32 |
'show_units' => true, |
| 33 |
'units' => array('px', '%', 'em') |
| 34 |
)); |
| 35 |
|
| 36 |
$default_values = array( |
| 37 |
'width' => '', |
| 38 |
'height' => '', |
| 39 |
'unit' => 'px', |
| 40 |
); |
| 41 |
|
| 42 |
$value = wp_parse_args($this->value, $default_values); |
| 43 |
$unit = (count($args['units']) === 1 && ! empty($args['unit'])) ? $args['units'][0] : ''; |
| 44 |
$is_unit = (! empty($unit)) ? ' darkify--is-unit' : ''; |
| 45 |
|
| 46 |
echo wp_kses_post($this->field_before()); |
| 47 |
|
| 48 |
echo '<div class="darkify--inputs" data-depend-id="' . esc_attr($this->field['id']) . '">'; |
| 49 |
|
| 50 |
if (! empty($args['width'])) { |
| 51 |
$placeholder = (! empty($args['width_placeholder'])) ? ' placeholder="' . esc_attr($args['width_placeholder']) . '"' : ''; |
| 52 |
echo '<div class="darkify--input">'; |
| 53 |
echo ! empty( $args['width_text'] ) ? '<div class="darkify--title">' . wp_kses_post( $args['width_text'] ) . '</div>' : ''; |
| 54 |
echo (! empty($args['width_icon'])) ? '<span class="darkify--label darkify--icon">' . wp_kses_post($args['width_icon']) . '</span>' : ''; |
| 55 |
echo '<input type="number" name="' . esc_attr($this->field_name('[width]')) . '" value="' . esc_attr($value['width']) . '"' . wp_kses_post($placeholder) . ' class="darkify-input-number' . esc_attr($is_unit) . '" step="any" />'; |
| 56 |
echo (! empty($unit)) ? '<span class="darkify--label darkify--unit">' . esc_attr($args['units'][0]) . '</span>' : ''; |
| 57 |
echo '</div>'; |
| 58 |
} |
| 59 |
|
| 60 |
if (! empty($args['height'])) { |
| 61 |
$placeholder = (! empty($args['height_placeholder'])) ? ' placeholder="' . esc_attr($args['height_placeholder']) . '"' : ''; |
| 62 |
echo '<div class="darkify--input">'; |
| 63 |
echo ( ! empty( $args['height_text'] ) ) ? '<div class="darkify--title">' . wp_kses_post( $args['height_text'] ) . '</div>' : ''; |
| 64 |
echo (! empty($args['height_icon'])) ? '<span class="darkify--label darkify--icon">' . wp_kses_post($args['height_icon']) . '</span>' : ''; |
| 65 |
echo '<input type="number" name="' . esc_attr($this->field_name('[height]')) . '" value="' . esc_attr($value['height']) . '"' . wp_kses_post($placeholder) . ' class="darkify-input-number' . esc_attr($is_unit) . '" />'; |
| 66 |
echo (! empty($unit)) ? '<span class="darkify--label darkify--unit">' . esc_attr($args['units'][0]) . '</span>' : ''; |
| 67 |
echo '</div>'; |
| 68 |
} |
| 69 |
|
| 70 |
if (! empty($args['unit']) && ! empty($args['show_units']) && count($args['units']) > 1) { |
| 71 |
echo '<div class="darkify--input">'; |
| 72 |
echo '<select name="' . esc_attr($this->field_name('[unit]')) . '">'; |
| 73 |
foreach ($args['units'] as $unit) { |
| 74 |
$selected = ($value['unit'] === $unit) ? ' selected' : ''; |
| 75 |
echo '<option value="' . esc_attr($unit) . '"' . esc_attr($selected) . '>' . esc_attr($unit) . '</option>'; |
| 76 |
} |
| 77 |
echo '</select>'; |
| 78 |
echo '</div>'; |
| 79 |
} |
| 80 |
|
| 81 |
echo '</div>'; |
| 82 |
|
| 83 |
echo wp_kses_post($this->field_after()); |
| 84 |
} |
| 85 |
|
| 86 |
public function output() |
| 87 |
{ |
| 88 |
|
| 89 |
$output = ''; |
| 90 |
$element = (is_array($this->field['output'])) ? join(',', $this->field['output']) : $this->field['output']; |
| 91 |
$prefix = (! empty($this->field['output_prefix'])) ? $this->field['output_prefix'] . '-' : ''; |
| 92 |
$important = (! empty($this->field['output_important'])) ? '!important' : ''; |
| 93 |
$unit = (! empty($this->value['unit'])) ? $this->value['unit'] : 'px'; |
| 94 |
$width = (isset($this->value['width']) && $this->value['width'] !== '') ? $prefix . 'width:' . $this->value['width'] . $unit . $important . ';' : ''; |
| 95 |
$height = (isset($this->value['height']) && $this->value['height'] !== '') ? $prefix . 'height:' . $this->value['height'] . $unit . $important . ';' : ''; |
| 96 |
|
| 97 |
if ($width !== '' || $height !== '') { |
| 98 |
$output = $element . '{' . $width . $height . '}'; |
| 99 |
} |
| 100 |
|
| 101 |
$this->parent->output_css .= $output; |
| 102 |
|
| 103 |
return $output; |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|