| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. |
| 2 |
/** |
| 3 |
* |
| 4 |
* Field: border |
| 5 |
* |
| 6 |
* @since 1.0.0 |
| 7 |
* @version 1.0.0 |
| 8 |
* |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'ADMINIFY_Field_border' ) ) { |
| 11 |
class ADMINIFY_Field_border extends ADMINIFY_Fields { |
| 12 |
|
| 13 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 14 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 15 |
} |
| 16 |
|
| 17 |
public function render() { |
| 18 |
|
| 19 |
$args = wp_parse_args( $this->field, array( |
| 20 |
'top_icon' => '<i class="fas fa-long-arrow-alt-up"></i>', |
| 21 |
'left_icon' => '<i class="fas fa-long-arrow-alt-left"></i>', |
| 22 |
'bottom_icon' => '<i class="fas fa-long-arrow-alt-down"></i>', |
| 23 |
'right_icon' => '<i class="fas fa-long-arrow-alt-right"></i>', |
| 24 |
'all_icon' => '<i class="fas fa-arrows-alt"></i>', |
| 25 |
'top_placeholder' => esc_html__( 'top', 'adminify' ), |
| 26 |
'right_placeholder' => esc_html__( 'right', 'adminify' ), |
| 27 |
'bottom_placeholder' => esc_html__( 'bottom', 'adminify' ), |
| 28 |
'left_placeholder' => esc_html__( 'left', 'adminify' ), |
| 29 |
'all_placeholder' => esc_html__( 'all', 'adminify' ), |
| 30 |
'top' => true, |
| 31 |
'left' => true, |
| 32 |
'bottom' => true, |
| 33 |
'right' => true, |
| 34 |
'all' => false, |
| 35 |
'color' => true, |
| 36 |
'style' => true, |
| 37 |
'unit' => 'px', |
| 38 |
) ); |
| 39 |
|
| 40 |
$default_value = array( |
| 41 |
'top' => '', |
| 42 |
'right' => '', |
| 43 |
'bottom' => '', |
| 44 |
'left' => '', |
| 45 |
'color' => '', |
| 46 |
'style' => 'solid', |
| 47 |
'all' => '', |
| 48 |
); |
| 49 |
|
| 50 |
$border_props = array( |
| 51 |
'solid' => esc_html__( 'Solid', 'adminify' ), |
| 52 |
'dashed' => esc_html__( 'Dashed', 'adminify' ), |
| 53 |
'dotted' => esc_html__( 'Dotted', 'adminify' ), |
| 54 |
'double' => esc_html__( 'Double', 'adminify' ), |
| 55 |
'inset' => esc_html__( 'Inset', 'adminify' ), |
| 56 |
'outset' => esc_html__( 'Outset', 'adminify' ), |
| 57 |
'groove' => esc_html__( 'Groove', 'adminify' ), |
| 58 |
'ridge' => esc_html__( 'ridge', 'adminify' ), |
| 59 |
'none' => esc_html__( 'None', 'adminify' ) |
| 60 |
); |
| 61 |
|
| 62 |
$default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value; |
| 63 |
|
| 64 |
$value = wp_parse_args( $this->value, $default_value ); |
| 65 |
|
| 66 |
echo $this->field_before(); |
| 67 |
|
| 68 |
echo '<div class="adminify--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">'; |
| 69 |
|
| 70 |
if ( ! empty( $args['all'] ) ) { |
| 71 |
|
| 72 |
$placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['all_placeholder'] ) .'"' : ''; |
| 73 |
|
| 74 |
echo '<div class="adminify--input">'; |
| 75 |
echo ( ! empty( $args['all_icon'] ) ) ? '<span class="adminify--label adminify--icon">'. $args['all_icon'] .'</span>' : ''; |
| 76 |
echo '<input type="number" name="'. esc_attr( $this->field_name( '[all]' ) ) .'" value="'. esc_attr( $value['all'] ) .'"'. $placeholder .' class="adminify-input-number adminify--is-unit" step="any" />'; |
| 77 |
echo ( ! empty( $args['unit'] ) ) ? '<span class="adminify--label adminify--unit">'. esc_attr( $args['unit'] ) .'</span>' : ''; |
| 78 |
echo '</div>'; |
| 79 |
|
| 80 |
} else { |
| 81 |
|
| 82 |
$properties = array(); |
| 83 |
|
| 84 |
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $prop ) { |
| 85 |
if ( ! empty( $args[$prop] ) ) { |
| 86 |
$properties[] = $prop; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
$properties = ( $properties === array( 'right', 'left' ) ) ? array_reverse( $properties ) : $properties; |
| 91 |
|
| 92 |
foreach ( $properties as $property ) { |
| 93 |
|
| 94 |
$placeholder = ( ! empty( $args[$property.'_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args[$property.'_placeholder'] ) .'"' : ''; |
| 95 |
|
| 96 |
echo '<div class="adminify--input">'; |
| 97 |
echo ( ! empty( $args[$property.'_icon'] ) ) ? '<span class="adminify--label adminify--icon">'. $args[$property.'_icon'] .'</span>' : ''; |
| 98 |
echo '<input type="number" name="'. esc_attr( $this->field_name( '['. $property .']' ) ) .'" value="'. esc_attr( $value[$property] ) .'"'. $placeholder .' class="adminify-input-number adminify--is-unit" step="any" />'; |
| 99 |
echo ( ! empty( $args['unit'] ) ) ? '<span class="adminify--label adminify--unit">'. esc_attr( $args['unit'] ) .'</span>' : ''; |
| 100 |
echo '</div>'; |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
if ( ! empty( $args['style'] ) ) { |
| 107 |
echo '<div class="adminify--input">'; |
| 108 |
echo '<select name="'. esc_attr( $this->field_name( '[style]' ) ) .'">'; |
| 109 |
foreach ( $border_props as $border_prop_key => $border_prop_value ) { |
| 110 |
$selected = ( $value['style'] === $border_prop_key ) ? ' selected' : ''; |
| 111 |
echo '<option value="'. esc_attr( $border_prop_key ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $border_prop_value ) .'</option>'; |
| 112 |
} |
| 113 |
echo '</select>'; |
| 114 |
echo '</div>'; |
| 115 |
} |
| 116 |
|
| 117 |
echo '</div>'; |
| 118 |
|
| 119 |
if ( ! empty( $args['color'] ) ) { |
| 120 |
$default_color_attr = ( ! empty( $default_value['color'] ) ) ? ' data-default-color="'. esc_attr( $default_value['color'] ) .'"' : ''; |
| 121 |
echo '<div class="adminify--color">'; |
| 122 |
echo '<div class="adminify-field-color">'; |
| 123 |
echo '<input type="text" name="'. esc_attr( $this->field_name( '[color]' ) ) .'" value="'. esc_attr( $value['color'] ) .'" class="adminify-color"'. $default_color_attr .' />'; |
| 124 |
echo '</div>'; |
| 125 |
echo '</div>'; |
| 126 |
} |
| 127 |
|
| 128 |
echo $this->field_after(); |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
public function output() { |
| 133 |
|
| 134 |
$output = ''; |
| 135 |
$unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px'; |
| 136 |
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; |
| 137 |
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; |
| 138 |
|
| 139 |
// properties |
| 140 |
$top = ( isset( $this->value['top'] ) && $this->value['top'] !== '' ) ? $this->value['top'] : ''; |
| 141 |
$right = ( isset( $this->value['right'] ) && $this->value['right'] !== '' ) ? $this->value['right'] : ''; |
| 142 |
$bottom = ( isset( $this->value['bottom'] ) && $this->value['bottom'] !== '' ) ? $this->value['bottom'] : ''; |
| 143 |
$left = ( isset( $this->value['left'] ) && $this->value['left'] !== '' ) ? $this->value['left'] : ''; |
| 144 |
$style = ( isset( $this->value['style'] ) && $this->value['style'] !== '' ) ? $this->value['style'] : ''; |
| 145 |
$color = ( isset( $this->value['color'] ) && $this->value['color'] !== '' ) ? $this->value['color'] : ''; |
| 146 |
$all = ( isset( $this->value['all'] ) && $this->value['all'] !== '' ) ? $this->value['all'] : ''; |
| 147 |
|
| 148 |
if ( ! empty( $this->field['all'] ) && ( $all !== '' || $color !== '' ) ) { |
| 149 |
|
| 150 |
$output = $element .'{'; |
| 151 |
$output .= ( $all !== '' ) ? 'border-width:'. $all . $unit . $important .';' : ''; |
| 152 |
$output .= ( $color !== '' ) ? 'border-color:'. $color . $important .';' : ''; |
| 153 |
$output .= ( $style !== '' ) ? 'border-style:'. $style . $important .';' : ''; |
| 154 |
$output .= '}'; |
| 155 |
|
| 156 |
} else if ( $top !== '' || $right !== '' || $bottom !== '' || $left !== '' || $color !== '' ) { |
| 157 |
|
| 158 |
$output = $element .'{'; |
| 159 |
$output .= ( $top !== '' ) ? 'border-top-width:'. $top . $unit . $important .';' : ''; |
| 160 |
$output .= ( $right !== '' ) ? 'border-right-width:'. $right . $unit . $important .';' : ''; |
| 161 |
$output .= ( $bottom !== '' ) ? 'border-bottom-width:'. $bottom . $unit . $important .';' : ''; |
| 162 |
$output .= ( $left !== '' ) ? 'border-left-width:'. $left . $unit . $important .';' : ''; |
| 163 |
$output .= ( $color !== '' ) ? 'border-color:'. $color . $important .';' : ''; |
| 164 |
$output .= ( $style !== '' ) ? 'border-style:'. $style . $important .';' : ''; |
| 165 |
$output .= '}'; |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
$this->parent->output_css .= $output; |
| 170 |
|
| 171 |
return $output; |
| 172 |
|
| 173 |
} |
| 174 |
|
| 175 |
} |
| 176 |
} |
| 177 |
|