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