PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.0
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.0
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / admin / views / sp-framework / fields / spacing / spacing.php

spacing.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.4.0, at admin/views/sp-framework/fields/spacing/spacing.php

175 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) {
2 die; } // Cannot access directly.
3 /**
4 *
5 * Field: spacing
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 */
10 if ( ! class_exists( 'SP_PC_Field_spacing' ) ) {
11 class SP_PC_Field_spacing extends SP_PC_Fields {
12
13 /**
14 * Spacing field constructor.
15 *
16 * @param array $field The field type.
17 * @param string $value The values of the field.
18 * @param string $unique The unique ID for the field.
19 * @param string $where To where show the output CSS.
20 * @param string $parent The parent args.
21 */
22 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
23 parent::__construct( $field, $value, $unique, $where, $parent );
24 }
25
26 /**
27 * Function to render the field.
28 *
29 * @return void
30 */
31 public function render() {
32
33 $args = wp_parse_args(
34 $this->field,
35 array(
36 'top_icon' => '<i class="fa fa-long-arrow-up"></i>',
37 'right_icon' => '<i class="fa fa-long-arrow-right"></i>',
38 'bottom_icon' => '<i class="fa fa-long-arrow-down"></i>',
39 'left_icon' => '<i class="fa fa-long-arrow-left"></i>',
40 'all_icon' => '<i class="fa fa-arrows"></i>',
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' ),
46 'top' => true,
47 'left' => true,
48 'bottom' => true,
49 'right' => true,
50 'unit' => true,
51 'min' => '0',
52 'show_units' => true,
53 'all' => false,
54 'units' => array( 'px', '%', 'em' ),
55 )
56 );
57
58 $default_values = array(
59 'top' => '',
60 'right' => '',
61 'bottom' => '',
62 'left' => '',
63 'all' => '',
64 'unit' => 'px',
65 'min' => '',
66 );
67
68 $value = wp_parse_args( $this->value, $default_values );
69 $unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : '';
70 $is_unit = ( ! empty( $unit ) ) ? ' spf--is-unit' : '';
71
72 echo wp_kses_post( $this->field_before() );
73
74 $min = ( isset( $args['min'] ) ) ? ' min="' . $args['min'] . '"' : '';
75
76 echo '<div class="spf--inputs">';
77
78 if ( ! empty( $args['all'] ) ) {
79
80 $placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="' . $args['all_placeholder'] . '"' : '';
81
82 echo '<div class="spf--input">';
83 echo ( ! empty( $args['all_icon'] ) ) ? '<span class="spf--label spf--icon">' . wp_kses_post( $args['all_icon'] ) . '</span>' : '';
84 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 ) . '" />';
85 echo ( $unit ) ? '<span class="spf--label spf--unit">' . wp_kses_post( $args['units'][0] ) . '</span>' : '';
86 echo '</div>';
87
88 } else {
89
90 $properties = array();
91
92 foreach ( array( 'top', 'right', 'bottom', 'left' ) as $prop ) {
93 if ( ! empty( $args[ $prop ] ) ) {
94 $properties[] = $prop;
95 }
96 }
97
98 $properties = ( array( 'right', 'left' ) === $properties ) ? array_reverse( $properties ) : $properties;
99
100 foreach ( $properties as $property ) {
101
102 $placeholder = ( ! empty( $args[ $property . '_placeholder' ] ) ) ? ' placeholder="' . $args[ $property . '_placeholder' ] . '"' : '';
103
104 echo '<div class="spf--input">';
105 echo ( ! empty( $args[ $property . '_icon' ] ) ) ? '<span class="spf--label spf--icon">' . wp_kses_post( $args[ $property . '_icon' ] ) . '</span>' : '';
106 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 ) . '" />';
107 echo ( $unit ) ? '<span class="spf--label spf--unit">' . wp_kses_post( $args['units'][0] ) . '</span>' : '';
108 echo '</div>';
109
110 }
111 }
112
113 if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) {
114 echo '<div class="spf--input">';
115 echo '<select name="' . esc_attr( $this->field_name( '[unit]' ) ) . '">';
116 foreach ( $args['units'] as $unit ) {
117 $selected = ( $value['unit'] === $unit ) ? ' selected' : '';
118 echo '<option value="' . esc_attr( $unit ) . '"' . esc_attr( $selected ) . '>' . esc_html( $unit ) . '</option>';
119 }
120 echo '</select>';
121 echo '</div>';
122 }
123
124 echo '</div>';
125
126 echo wp_kses_post( $this->field_after() );
127
128 }
129
130 /**
131 * The output.
132 *
133 * @return mixed
134 */
135 public function output() {
136
137 $output = '';
138 $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
139 $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
140 $unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
141
142 $mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'padding';
143 $mode = ( 'relative' === $mode || 'absolute' === $mode || 'none' === $mode ) ? '' : $mode;
144 $mode = ( ! empty( $mode ) ) ? $mode . '-' : '';
145
146 if ( ! empty( $this->field['all'] ) && isset( $this->value['all'] ) && '' !== $this->value['all'] ) {
147
148 $output = $element . '{';
149 $output .= $mode . 'top:' . $this->value['all'] . $unit . $important . ';';
150 $output .= $mode . 'right:' . $this->value['all'] . $unit . $important . ';';
151 $output .= $mode . 'bottom:' . $this->value['all'] . $unit . $important . ';';
152 $output .= $mode . 'left:' . $this->value['all'] . $unit . $important . ';';
153 $output .= '}';
154
155 } else {
156
157 $top = ( isset( $this->value['top'] ) && '' !== $this->value['top'] ) ? $mode . 'top:' . $this->value['top'] . $unit . $important . ';' : '';
158 $right = ( isset( $this->value['right'] ) && '' !== $this->value['right'] ) ? $mode . 'right:' . $this->value['right'] . $unit . $important . ';' : '';
159 $bottom = ( isset( $this->value['bottom'] ) && '' !== $this->value['bottom'] ) ? $mode . 'bottom:' . $this->value['bottom'] . $unit . $important . ';' : '';
160 $left = ( isset( $this->value['left'] ) && '' !== $this->value['left'] ) ? $mode . 'left:' . $this->value['left'] . $unit . $important . ';' : '';
161
162 if ( '' !== $top || '' !== $right || '' !== $bottom || '' !== $left ) {
163 $output = $element . '{' . $top . $right . $bottom . $left . '}';
164 }
165 }
166
167 $this->parent->output_css .= $output;
168
169 return $output;
170
171 }
172
173 }
174 }
175