PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.14
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.14
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / views / styles / components / FrmSliderStyleComponent.php

FrmSliderStyleComponent.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.14, at classes/views/styles/components/FrmSliderStyleComponent.php

190 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5 class FrmSliderStyleComponent extends FrmStyleComponent {
6
7 /**
8 * The view file name.
9 *
10 * @since 6.14
11 *
12 * @var string
13 */
14 protected $view_name = 'slider';
15
16 /**
17 * The FrmStyleComponent data.
18 *
19 * @since 6.14
20 *
21 * @var array
22 */
23 protected $data;
24
25 public function __construct( $field_name, $field_value, $data ) {
26
27 $this->init_field_data( $data, $field_name, $field_value );
28
29 if ( true === $this->hide_component() ) {
30 return;
31 }
32
33 $this->data['unit_measurement'] = $this->detect_unit_measurement();
34 $this->data['has-multiple-values'] = count( $this->get_values() ) > 1;
35 $this->data['units'] = $this->get_units_list( $data );
36
37 $this->init_defaults();
38 $this->init_icon();
39 $this->init_multiple_values();
40
41 parent::get_instance();
42 $this->load_view();
43 }
44
45 /**
46 * Retrieves the list of units for the slider style component.
47 *
48 * If the units array is empty in the provided data, it returns an array containing the default units: 'px', 'em', and '%'.
49 * Otherwise, it merges the units array from the provided data with the default units array and returns the result.
50 *
51 * @param array $data The data containing the units array.
52 * @return array The list of units for the slider style component.
53 */
54 private function get_units_list( $data ) {
55 if ( empty( $data['units'] ) ) {
56 return array( 'px', 'em', '%' );
57 }
58 return $data['units'];
59 }
60
61 /**
62 * Init components default values
63 *
64 * @since 6.14
65 *
66 * @return void
67 */
68 private function init_defaults() {
69 $this->data['max_value'] = empty( $this->data['max_value'] ) ? 100 : $this->data['max_value'];
70 }
71
72 /**
73 * Init the slider multiple values data. It works with sliders which has multiple values only: top&bottom and left&right.
74 * This is used for cases when there are 4 sliders in the same field.
75 *
76 * @since 6.14
77 *
78 * @return array
79 */
80 private function init_multiple_values() {
81 if ( ! $this->data['has-multiple-values'] ) {
82 return;
83 }
84
85 $values = $this->get_values();
86 $top = $values[0];
87 $bottom = empty( $values[2] ) ? $values[0] : $values[2];
88 $left = empty( $values[3] ) ? $values[1] : $values[3];
89 $right = $values[1];
90
91 $this->data['vertical'] = array(
92 'value' => $top,
93 'unit' => $this->detect_unit_measurement( $top ),
94 );
95
96 $this->data['horizontal'] = array(
97 'value' => $right,
98 'unit' => $this->detect_unit_measurement( $right ),
99 );
100
101 $this->data['top'] = array(
102 'value' => $top,
103 'unit' => $this->detect_unit_measurement( $top ),
104 );
105
106 $this->data['bottom'] = array(
107 'value' => $bottom,
108 'unit' => $this->detect_unit_measurement( $bottom ),
109 );
110
111 $this->data['left'] = array(
112 'value' => $left,
113 'unit' => $this->detect_unit_measurement( $left ),
114 );
115
116 $this->data['right'] = array(
117 'value' => $right,
118 'unit' => $this->detect_unit_measurement( $right ),
119 );
120 }
121
122 /**
123 * Split the field value by space from string to an array.
124 * For instance: '10px 20px 30px 40px' will be converted to array( '10px', '20px', '30px', '40px' ).
125 *
126 * @since 6.14
127 *
128 * @return array
129 */
130 private function get_values() {
131 return explode( ' ', $this->field_value );
132 }
133
134 /**
135 * Detect the unit measurement from the value.
136 * Possible values are: px, %, em.
137 *
138 * @since 6.14
139 *
140 * @return string
141 */
142 private function detect_unit_measurement( $value = null ) {
143 if ( null === $value ) {
144 $value = $this->field_value;
145 }
146
147 if ( preg_match( '/%$/', $value ) ) {
148 return '%';
149 }
150 if ( preg_match( '/em$/', $value ) ) {
151 return 'em';
152 }
153
154 return 'px';
155 }
156
157 /**
158 * Init the field icon
159 *
160 * @since 6.14
161 *
162 * @return array
163 */
164 private function init_icon() {
165
166 if ( ! empty( $this->data['icon'] ) ) {
167 return;
168 }
169
170 if ( empty( $this->data['type'] ) ) {
171 $this->data['icon'] = '';
172 return;
173 }
174
175 switch ( $this->data['type'] ) {
176 case 'vertical-margin':
177 $this->data['icon'] = 'frm_icon_font frm-margin-top-bottom';
178 return;
179
180 case 'horizontal-margin':
181 $this->data['icon'] = 'frm_icon_font frm-margin-left-right';
182 return;
183
184 default:
185 $this->data['icon'] = '';
186 return;
187 }
188 }
189 }
190