← All changes
|
admin/views/sp-framework/fields/spacing/spacing.php
+61
-33
2.4.17
→
2.2.10
View file →
| @@ -1,24 +1,14 @@ | ||
| 1 | -<?php | |
| 1 | +<?php if ( ! defined( 'ABSPATH' ) ) { | |
| 2 | + die; } // Cannot access directly. | |
| 2 | 3 | /** |
| 3 | - * The framework spacing fields file. | |
| 4 | 4 | * |
| 5 | - * @package Smart_Post_Show | |
| 6 | - * @subpackage Smart_Post_Show/admin | |
| 5 | + * Field: spacing | |
| 6 | + * | |
| 7 | + * @since 1.0.0 | |
| 8 | + * @version 1.0.0 | |
| 7 | 9 | */ |
| 8 | - | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | - die; } // Cannot access directly. | |
| 11 | - | |
| 12 | 10 | if ( ! class_exists( 'SP_PC_Field_spacing' ) ) { |
| 13 | - | |
| 14 | - /** | |
| 15 | - * | |
| 16 | - * Field: spacing | |
| 17 | - * | |
| 18 | - * @since 1.0.0 | |
| 19 | - * @version 1.0.0 | |
| 20 | - */ | |
| 21 | 11 | class SP_PC_Field_spacing extends SP_PC_Fields { |
| 22 | 12 | |
| 23 | 13 | /** |
| 24 | 14 | * Spacing field constructor. |
| @@ -47,19 +37,19 @@ | ||
| 47 | 37 | 'right_icon' => '<i class="fa fa-long-arrow-right"></i>', |
| 48 | 38 | 'bottom_icon' => '<i class="fa fa-long-arrow-down"></i>', |
| 49 | 39 | 'left_icon' => '<i class="fa fa-long-arrow-left"></i>', |
| 50 | 40 | 'all_icon' => '<i class="fa fa-arrows"></i>', |
| 51 | - 'top_placeholder' => esc_html__( 'top', 'post-carousel' ), | |
| 52 | - 'right_placeholder' => esc_html__( 'right', 'post-carousel' ), | |
| 53 | - 'bottom_placeholder' => esc_html__( 'bottom', 'post-carousel' ), | |
| 54 | - 'left_placeholder' => esc_html__( 'left', 'post-carousel' ), | |
| 55 | - 'all_placeholder' => esc_html__( 'all', 'post-carousel' ), | |
| 41 | + 'top_placeholder' => esc_html__( 'top', 'smart-post-show' ), | |
| 42 | + 'right_placeholder' => esc_html__( 'right', 'smart-post-show' ), | |
| 43 | + 'bottom_placeholder' => esc_html__( 'bottom', 'smart-post-show' ), | |
| 44 | + 'left_placeholder' => esc_html__( 'left', 'smart-post-show' ), | |
| 45 | + 'all_placeholder' => esc_html__( 'all', 'smart-post-show' ), | |
| 56 | 46 | 'top' => true, |
| 57 | 47 | 'left' => true, |
| 58 | 48 | 'bottom' => true, |
| 59 | 49 | 'right' => true, |
| 60 | 50 | 'unit' => true, |
| 61 | - 'min' => '-50', | |
| 51 | + 'min' => '0', | |
| 62 | 52 | 'show_units' => true, |
| 63 | 53 | 'all' => false, |
| 64 | 54 | 'units' => array( 'px', '%', 'em' ), |
| 65 | 55 | ) |
| @@ -78,9 +68,9 @@ | ||
| 78 | 68 | $value = wp_parse_args( $this->value, $default_values ); |
| 79 | 69 | $unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : ''; |
| 80 | 70 | $is_unit = ( ! empty( $unit ) ) ? ' spf--is-unit' : ''; |
| 81 | 71 | |
| 82 | - echo wp_kses_post( $this->field_before() ); | |
| 72 | + echo $this->field_before(); | |
| 83 | 73 | |
| 84 | 74 | $min = ( isset( $args['min'] ) ) ? ' min="' . $args['min'] . '"' : ''; |
| 85 | 75 | |
| 86 | 76 | echo '<div class="spf--inputs">'; |
| @@ -89,11 +79,11 @@ | ||
| 89 | 79 | |
| 90 | 80 | $placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="' . $args['all_placeholder'] . '"' : ''; |
| 91 | 81 | |
| 92 | 82 | echo '<div class="spf--input">'; |
| 93 | - echo ( ! empty( $args['all_icon'] ) ) ? '<span class="spf--label spf--icon">' . wp_kses_post( $args['all_icon'] ) . '</span>' : ''; | |
| 94 | - echo '<input type="number" name="' . esc_attr( $this->field_name( '[all]' ) ) . '" value="' . esc_attr( $value['all'] ) . '"' . wp_kses_post( $placeholder . $min ) . ' class="spf-input-number' . esc_attr( $is_unit ) . '" />'; | |
| 95 | - echo ( $unit ) ? '<span class="spf--label spf--unit">' . wp_kses_post( $args['units'][0] ) . '</span>' : ''; | |
| 83 | + echo ( ! empty( $args['all_icon'] ) ) ? '<span class="spf--label spf--icon">' . $args['all_icon'] . '</span>' : ''; | |
| 84 | + echo '<input type="number" name="' . $this->field_name( '[all]' ) . '" value="' . $value['all'] . '"' . $placeholder . $min . ' class="spf-input-number' . $is_unit . '" />'; | |
| 85 | + echo ( $unit ) ? '<span class="spf--label spf--unit">' . $args['units'][0] . '</span>' : ''; | |
| 96 | 86 | echo '</div>'; |
| 97 | 87 | |
| 98 | 88 | } else { |
| 99 | 89 | |
| @@ -104,9 +94,9 @@ | ||
| 104 | 94 | $properties[] = $prop; |
| 105 | 95 | } |
| 106 | 96 | } |
| 107 | 97 | |
| 108 | - $properties = ( array( 'right', 'left' ) === $properties ) ? array_reverse( $properties ) : $properties; | |
| 98 | + $properties = ( $properties === array( 'right', 'left' ) ) ? array_reverse( $properties ) : $properties; | |
| 109 | 99 | |
| 110 | 100 | foreach ( $properties as $property ) { |
| 111 | 101 | |
| 112 | 102 | $placeholder = ( ! empty( $args[ $property . '_placeholder' ] ) ) ? ' placeholder="' . $args[ $property . '_placeholder' ] . '"' : ''; |
| @@ -111,11 +101,11 @@ | ||
| 111 | 101 | |
| 112 | 102 | $placeholder = ( ! empty( $args[ $property . '_placeholder' ] ) ) ? ' placeholder="' . $args[ $property . '_placeholder' ] . '"' : ''; |
| 113 | 103 | |
| 114 | 104 | echo '<div class="spf--input">'; |
| 115 | - echo ( ! empty( $args[ $property . '_icon' ] ) ) ? '<span class="spf--label spf--icon">' . wp_kses_post( $args[ $property . '_icon' ] ) . '</span>' : ''; | |
| 116 | - echo '<input type="number" name="' . esc_attr( $this->field_name( '[' . $property . ']' ) ) . '" value="' . esc_attr( $value[ $property ] ) . '"' . wp_kses_post( $placeholder . $min ) . ' class="spf-input-number' . esc_attr( $is_unit ) . '" />'; | |
| 117 | - echo ( $unit ) ? '<span class="spf--label spf--unit">' . wp_kses_post( $args['units'][0] ) . '</span>' : ''; | |
| 105 | + echo ( ! empty( $args[ $property . '_icon' ] ) ) ? '<span class="spf--label spf--icon">' . $args[ $property . '_icon' ] . '</span>' : ''; | |
| 106 | + echo '<input type="number" name="' . $this->field_name( '[' . $property . ']' ) . '" value="' . $value[ $property ] . '"' . $placeholder . $min . ' class="spf-input-number' . $is_unit . '" />'; | |
| 107 | + echo ( $unit ) ? '<span class="spf--label spf--unit">' . $args['units'][0] . '</span>' : ''; | |
| 118 | 108 | echo '</div>'; |
| 119 | 109 | |
| 120 | 110 | } |
| 121 | 111 | } |
| @@ -121,12 +111,12 @@ | ||
| 121 | 111 | } |
| 122 | 112 | |
| 123 | 113 | if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) { |
| 124 | 114 | echo '<div class="spf--input">'; |
| 125 | - echo '<select name="' . esc_attr( $this->field_name( '[unit]' ) ) . '">'; | |
| 115 | + echo '<select name="' . $this->field_name( '[unit]' ) . '">'; | |
| 126 | 116 | foreach ( $args['units'] as $unit ) { |
| 127 | 117 | $selected = ( $value['unit'] === $unit ) ? ' selected' : ''; |
| 128 | - echo '<option value="' . esc_attr( $unit ) . '"' . esc_attr( $selected ) . '>' . esc_html( $unit ) . '</option>'; | |
| 118 | + echo '<option value="' . $unit . '"' . $selected . '>' . $unit . '</option>'; | |
| 129 | 119 | } |
| 130 | 120 | echo '</select>'; |
| 131 | 121 | echo '</div>'; |
| 132 | 122 | } |
| @@ -132,9 +122,47 @@ | ||
| 132 | 122 | } |
| 133 | 123 | |
| 134 | 124 | echo '</div>'; |
| 135 | 125 | |
| 136 | - echo wp_kses_post( $this->field_after() ); | |
| 126 | + echo $this->field_after(); | |
| 127 | + | |
| 128 | + } | |
| 129 | + | |
| 130 | + public function output() { | |
| 131 | + | |
| 132 | + $output = ''; | |
| 133 | + $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; | |
| 134 | + $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; | |
| 135 | + $unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px'; | |
| 136 | + | |
| 137 | + $mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'padding'; | |
| 138 | + $mode = ( $mode === 'relative' || $mode === 'absolute' || $mode === 'none' ) ? '' : $mode; | |
| 139 | + $mode = ( ! empty( $mode ) ) ? $mode . '-' : ''; | |
| 140 | + | |
| 141 | + if ( ! empty( $this->field['all'] ) && isset( $this->value['all'] ) && $this->value['all'] !== '' ) { | |
| 142 | + | |
| 143 | + $output = $element . '{'; | |
| 144 | + $output .= $mode . 'top:' . $this->value['all'] . $unit . $important . ';'; | |
| 145 | + $output .= $mode . 'right:' . $this->value['all'] . $unit . $important . ';'; | |
| 146 | + $output .= $mode . 'bottom:' . $this->value['all'] . $unit . $important . ';'; | |
| 147 | + $output .= $mode . 'left:' . $this->value['all'] . $unit . $important . ';'; | |
| 148 | + $output .= '}'; | |
| 149 | + | |
| 150 | + } else { | |
| 151 | + | |
| 152 | + $top = ( isset( $this->value['top'] ) && $this->value['top'] !== '' ) ? $mode . 'top:' . $this->value['top'] . $unit . $important . ';' : ''; | |
| 153 | + $right = ( isset( $this->value['right'] ) && $this->value['right'] !== '' ) ? $mode . 'right:' . $this->value['right'] . $unit . $important . ';' : ''; | |
| 154 | + $bottom = ( isset( $this->value['bottom'] ) && $this->value['bottom'] !== '' ) ? $mode . 'bottom:' . $this->value['bottom'] . $unit . $important . ';' : ''; | |
| 155 | + $left = ( isset( $this->value['left'] ) && $this->value['left'] !== '' ) ? $mode . 'left:' . $this->value['left'] . $unit . $important . ';' : ''; | |
| 156 | + | |
| 157 | + if ( $top !== '' || $right !== '' || $bottom !== '' || $left !== '' ) { | |
| 158 | + $output = $element . '{' . $top . $right . $bottom . $left . '}'; | |
| 159 | + } | |
| 160 | + } | |
| 161 | + | |
| 162 | + $this->parent->output_css .= $output; | |
| 163 | + | |
| 164 | + return $output; | |
| 137 | 165 | |
| 138 | 166 | } |
| 139 | 167 | |
| 140 | 168 | } |