Completed
Push — master ( de47be...91c9cd )
by Stephanie
03:24
created
classes/controllers/FrmFieldsController.php 1 patch
Indentation   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -2,129 +2,129 @@  discard block
 block discarded – undo
2 2
 
3 3
 class FrmFieldsController {
4 4
 
5
-    public static function load_field() {
5
+	public static function load_field() {
6 6
 		FrmAppHelper::permission_check('frm_edit_forms');
7
-        check_ajax_referer( 'frm_ajax', 'nonce' );
7
+		check_ajax_referer( 'frm_ajax', 'nonce' );
8 8
 
9
-        $fields = $_POST['field'];
10
-        if ( empty( $fields ) ) {
11
-            wp_die();
12
-        }
9
+		$fields = $_POST['field'];
10
+		if ( empty( $fields ) ) {
11
+			wp_die();
12
+		}
13 13
 
14
-        $_GET['page'] = 'formidable';
15
-        $fields = stripslashes_deep( $fields );
14
+		$_GET['page'] = 'formidable';
15
+		$fields = stripslashes_deep( $fields );
16 16
 
17
-        $ajax = true;
17
+		$ajax = true;
18 18
 		$values = array( 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ) );
19
-        $path = FrmAppHelper::plugin_path();
20
-        $field_html = array();
21
-
22
-        foreach ( $fields as $field ) {
23
-            $field = htmlspecialchars_decode( nl2br( $field ) );
24
-            $field = json_decode( $field, true );
25
-            if ( ! isset( $field['id'] ) ) {
26
-                // this field may have already been loaded
27
-                continue;
28
-            }
19
+		$path = FrmAppHelper::plugin_path();
20
+		$field_html = array();
21
+
22
+		foreach ( $fields as $field ) {
23
+			$field = htmlspecialchars_decode( nl2br( $field ) );
24
+			$field = json_decode( $field, true );
25
+			if ( ! isset( $field['id'] ) ) {
26
+				// this field may have already been loaded
27
+				continue;
28
+			}
29 29
 
30
-            $field_id = absint( $field['id'] );
30
+			$field_id = absint( $field['id'] );
31 31
 
32
-            if ( ! isset( $field['value'] ) ) {
33
-                $field['value'] = '';
34
-            }
32
+			if ( ! isset( $field['value'] ) ) {
33
+				$field['value'] = '';
34
+			}
35 35
 
36 36
 			$field_name = 'item_meta[' . $field_id . ']';
37
-            $html_id = FrmFieldsHelper::get_html_id($field);
37
+			$html_id = FrmFieldsHelper::get_html_id($field);
38 38
 
39
-            ob_start();
39
+			ob_start();
40 40
 			include( $path . '/classes/views/frm-forms/add_field.php' );
41
-            $field_html[ $field_id ] = ob_get_contents();
42
-            ob_end_clean();
43
-        }
41
+			$field_html[ $field_id ] = ob_get_contents();
42
+			ob_end_clean();
43
+		}
44 44
 
45
-        unset($path);
45
+		unset($path);
46 46
 
47
-        echo json_encode($field_html);
47
+		echo json_encode($field_html);
48 48
 
49
-        wp_die();
50
-    }
49
+		wp_die();
50
+	}
51 51
 
52 52
 	/**
53 53
 	 * Create a new field with ajax
54 54
 	 */
55
-    public static function create() {
55
+	public static function create() {
56 56
 		FrmAppHelper::permission_check('frm_edit_forms');
57
-        check_ajax_referer( 'frm_ajax', 'nonce' );
57
+		check_ajax_referer( 'frm_ajax', 'nonce' );
58 58
 
59 59
 		$field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
60 60
 		$form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
61 61
 
62 62
 		$field = self::include_new_field( $field_type, $form_id );
63 63
 
64
-        // this hook will allow for multiple fields to be added at once
65
-        do_action('frm_after_field_created', $field, $form_id);
64
+		// this hook will allow for multiple fields to be added at once
65
+		do_action('frm_after_field_created', $field, $form_id);
66 66
 
67
-        wp_die();
68
-    }
67
+		wp_die();
68
+	}
69 69
 
70
-    /**
71
-     * Set up and create a new field
72
-     *
73
-     * @param string $field_type
74
-     * @param integer $form_id
75
-     * @return array|bool
76
-     */
70
+	/**
71
+	 * Set up and create a new field
72
+	 *
73
+	 * @param string $field_type
74
+	 * @param integer $form_id
75
+	 * @return array|bool
76
+	 */
77 77
 	public static function include_new_field( $field_type, $form_id ) {
78
-        $values = array();
79
-        if ( FrmAppHelper::pro_is_installed() ) {
80
-            $values['post_type'] = FrmProFormsHelper::post_type($form_id);
81
-        }
78
+		$values = array();
79
+		if ( FrmAppHelper::pro_is_installed() ) {
80
+			$values['post_type'] = FrmProFormsHelper::post_type($form_id);
81
+		}
82 82
 
83 83
 		$field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
84
-        $field_values = apply_filters( 'frm_before_field_created', $field_values );
84
+		$field_values = apply_filters( 'frm_before_field_created', $field_values );
85 85
 
86
-        $field_id = FrmField::create( $field_values );
86
+		$field_id = FrmField::create( $field_values );
87 87
 
88
-        if ( ! $field_id ) {
89
-            return false;
90
-        }
88
+		if ( ! $field_id ) {
89
+			return false;
90
+		}
91 91
 
92
-        $field = self::include_single_field($field_id, $values, $form_id);
92
+		$field = self::include_single_field($field_id, $values, $form_id);
93 93
 
94
-        return $field;
95
-    }
94
+		return $field;
95
+	}
96 96
 
97 97
 	public static function edit_name( $field = 'name', $id = '' ) {
98 98
 		FrmAppHelper::permission_check('frm_edit_forms');
99
-        check_ajax_referer( 'frm_ajax', 'nonce' );
99
+		check_ajax_referer( 'frm_ajax', 'nonce' );
100 100
 
101
-        if ( empty($field) ) {
102
-            $field = 'name';
103
-        }
101
+		if ( empty($field) ) {
102
+			$field = 'name';
103
+		}
104 104
 
105
-        if ( empty($id) ) {
105
+		if ( empty($id) ) {
106 106
 			$id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' );
107 107
 			$id = str_replace( 'field_label_', '', $id );
108
-        }
108
+		}
109 109
 
110 110
 		$value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' );
111 111
 		$value = trim( $value );
112
-        if ( trim(strip_tags($value)) == '' ) {
113
-            // set blank value if there is no content
114
-            $value = '';
115
-        }
112
+		if ( trim(strip_tags($value)) == '' ) {
113
+			// set blank value if there is no content
114
+			$value = '';
115
+		}
116 116
 
117 117
 		FrmField::update( $id, array( $field => $value ) );
118 118
 
119 119
 		do_action( 'frm_after_update_field_' . $field, compact( 'id', 'value' ) );
120 120
 
121 121
 		echo stripslashes( wp_kses_post( $value ) );
122
-        wp_die();
123
-    }
122
+		wp_die();
123
+	}
124 124
 
125
-    public static function update_ajax_option() {
125
+	public static function update_ajax_option() {
126 126
 		FrmAppHelper::permission_check('frm_edit_forms');
127
-        check_ajax_referer( 'frm_ajax', 'nonce' );
127
+		check_ajax_referer( 'frm_ajax', 'nonce' );
128 128
 
129 129
 		$field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
130 130
 		if ( ! $field_id ) {
@@ -139,248 +139,248 @@  discard block
 block discarded – undo
139 139
 			unset($new_val);
140 140
 		}
141 141
 
142
-        FrmField::update( $field_id, array(
143
-            'field_options' => $field->field_options,
142
+		FrmField::update( $field_id, array(
143
+			'field_options' => $field->field_options,
144 144
 			'form_id'		=> $field->form_id,
145
-        ) );
146
-        wp_die();
147
-    }
145
+		) );
146
+		wp_die();
147
+	}
148 148
 
149
-    public static function duplicate() {
149
+	public static function duplicate() {
150 150
 		FrmAppHelper::permission_check('frm_edit_forms');
151
-        check_ajax_referer( 'frm_ajax', 'nonce' );
151
+		check_ajax_referer( 'frm_ajax', 'nonce' );
152 152
 
153
-        global $wpdb;
153
+		global $wpdb;
154 154
 
155 155
 		$field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
156 156
 		$form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
157 157
 
158 158
 		$copy_field = FrmField::getOne( $field_id );
159
-        if ( ! $copy_field ) {
160
-            wp_die();
161
-        }
159
+		if ( ! $copy_field ) {
160
+			wp_die();
161
+		}
162 162
 
163 163
 		do_action( 'frm_duplicate_field', $copy_field, $form_id );
164 164
 		do_action( 'frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id );
165 165
 
166 166
 		$values = array();
167
-        FrmFieldsHelper::fill_field( $values, $copy_field, $form_id );
167
+		FrmFieldsHelper::fill_field( $values, $copy_field, $form_id );
168 168
 
169
-	    $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values );
169
+		$values = apply_filters( 'frm_prepare_single_field_for_duplication', $values );
170 170
 
171 171
 		$field_id = FrmField::create( $values );
172 172
 		if ( ! $field_id ) {
173 173
 			wp_die();
174 174
 		}
175 175
 
176
-        self::include_single_field($field_id, $values);
176
+		self::include_single_field($field_id, $values);
177 177
 
178
-        wp_die();
179
-    }
178
+		wp_die();
179
+	}
180 180
 
181
-    /**
182
-     * Load a single field in the form builder along with all needed variables
183
-     */
184
-    public static function include_single_field( $field_id, $values, $form_id = 0 ) {
185
-        $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id));
181
+	/**
182
+	 * Load a single field in the form builder along with all needed variables
183
+	 */
184
+	public static function include_single_field( $field_id, $values, $form_id = 0 ) {
185
+		$field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id));
186 186
 		$field_name = 'item_meta[' . $field_id . ']';
187
-        $html_id = FrmFieldsHelper::get_html_id($field);
188
-        $id = $form_id ? $form_id : $field['form_id'];
189
-        if ( $field['type'] == 'html' ) {
190
-            $field['stop_filter'] = true;
191
-        }
187
+		$html_id = FrmFieldsHelper::get_html_id($field);
188
+		$id = $form_id ? $form_id : $field['form_id'];
189
+		if ( $field['type'] == 'html' ) {
190
+			$field['stop_filter'] = true;
191
+		}
192 192
 
193 193
 		require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
194 194
 
195
-        return $field;
196
-    }
195
+		return $field;
196
+	}
197 197
 
198
-    public static function destroy() {
198
+	public static function destroy() {
199 199
 		FrmAppHelper::permission_check('frm_edit_forms');
200
-        check_ajax_referer( 'frm_ajax', 'nonce' );
200
+		check_ajax_referer( 'frm_ajax', 'nonce' );
201 201
 
202 202
 		$field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
203 203
 		FrmField::destroy( $field_id );
204
-        wp_die();
205
-    }
204
+		wp_die();
205
+	}
206 206
 
207
-    /* Field Options */
207
+	/* Field Options */
208 208
 
209
-    //Add Single Option or Other Option
210
-    public static function add_option() {
209
+	//Add Single Option or Other Option
210
+	public static function add_option() {
211 211
 		FrmAppHelper::permission_check('frm_edit_forms');
212
-        check_ajax_referer( 'frm_ajax', 'nonce' );
212
+		check_ajax_referer( 'frm_ajax', 'nonce' );
213 213
 
214 214
 		$id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
215 215
 		$opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' );
216 216
 		$opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'absint' );
217 217
 
218
-        $field = FrmField::getOne($id);
218
+		$field = FrmField::getOne($id);
219 219
 
220
-        if ( 'other' == $opt_type ) {
220
+		if ( 'other' == $opt_type ) {
221 221
 			$opt = __( 'Other', 'formidable' );
222
-            $other_val = '';
223
-            $opt_key = 'other_' . $opt_key;
224
-        } else {
222
+			$other_val = '';
223
+			$opt_key = 'other_' . $opt_key;
224
+		} else {
225 225
 			$opt = __( 'New Option', 'formidable' );
226
-        }
227
-        $field_val = $opt;
226
+		}
227
+		$field_val = $opt;
228 228
 
229
-        $field_data = $field;
229
+		$field_data = $field;
230 230
 		$field = (array) $field;
231 231
 		$field['separate_value'] = isset( $field_data->field_options['separate_value'] ) ? $field_data->field_options['separate_value'] : 0;
232 232
 		unset( $field_data );
233 233
 
234 234
 		$field_name = 'item_meta[' . $id . ']';
235 235
 		$html_id = FrmFieldsHelper::get_html_id( $field );
236
-        $checked = '';
236
+		$checked = '';
237 237
 
238
-        if ( 'other' == $opt_type ) {
238
+		if ( 'other' == $opt_type ) {
239 239
 			include( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' );
240
-        } else {
240
+		} else {
241 241
 			require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
242
-        }
243
-        wp_die();
244
-    }
242
+		}
243
+		wp_die();
244
+	}
245 245
 
246
-    public static function edit_option() {
246
+	public static function edit_option() {
247 247
 		_deprecated_function( __FUNCTION__, '2.3' );
248
-    }
248
+	}
249 249
 
250
-    public static function delete_option() {
250
+	public static function delete_option() {
251 251
 		_deprecated_function( __FUNCTION__, '2.3' );
252
-    }
252
+	}
253 253
 
254
-    public static function import_choices() {
255
-        FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' );
254
+	public static function import_choices() {
255
+		FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' );
256 256
 
257 257
 		$field_id = absint( $_REQUEST['field_id'] );
258 258
 
259
-        global $current_screen, $hook_suffix;
259
+		global $current_screen, $hook_suffix;
260 260
 
261
-        // Catch plugins that include admin-header.php before admin.php completes.
262
-        if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) {
263
-            $hook_suffix = '';
264
-        	set_current_screen();
265
-        }
261
+		// Catch plugins that include admin-header.php before admin.php completes.
262
+		if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) {
263
+			$hook_suffix = '';
264
+			set_current_screen();
265
+		}
266 266
 
267
-        if ( function_exists( 'register_admin_color_schemes' ) ) {
268
-            register_admin_color_schemes();
269
-        }
267
+		if ( function_exists( 'register_admin_color_schemes' ) ) {
268
+			register_admin_color_schemes();
269
+		}
270 270
 
271 271
 		$hook_suffix = '';
272 272
 		$admin_body_class = '';
273 273
 
274
-        if ( get_user_setting( 'mfold' ) == 'f' ) {
275
-        	$admin_body_class .= ' folded';
276
-        }
274
+		if ( get_user_setting( 'mfold' ) == 'f' ) {
275
+			$admin_body_class .= ' folded';
276
+		}
277 277
 
278
-        if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
279
-        	$admin_body_class .= ' admin-bar';
280
-        }
278
+		if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
279
+			$admin_body_class .= ' admin-bar';
280
+		}
281 281
 
282
-        if ( is_rtl() ) {
283
-        	$admin_body_class .= ' rtl';
284
-        }
282
+		if ( is_rtl() ) {
283
+			$admin_body_class .= ' rtl';
284
+		}
285 285
 
286
-        $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
287
-        $prepop = array();
288
-        FrmFieldsHelper::get_bulk_prefilled_opts($prepop);
286
+		$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
287
+		$prepop = array();
288
+		FrmFieldsHelper::get_bulk_prefilled_opts($prepop);
289 289
 
290
-        $field = FrmField::getOne($field_id);
290
+		$field = FrmField::getOne($field_id);
291 291
 
292
-        wp_enqueue_script( 'utils' );
292
+		wp_enqueue_script( 'utils' );
293 293
 		wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' );
294
-        FrmAppHelper::load_admin_wide_js();
294
+		FrmAppHelper::load_admin_wide_js();
295 295
 
296 296
 		include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/import_choices.php' );
297
-        wp_die();
298
-    }
297
+		wp_die();
298
+	}
299 299
 
300
-    public static function import_options() {
300
+	public static function import_options() {
301 301
 		FrmAppHelper::permission_check('frm_edit_forms');
302
-        check_ajax_referer( 'frm_ajax', 'nonce' );
302
+		check_ajax_referer( 'frm_ajax', 'nonce' );
303 303
 
304
-        if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) {
305
-            return;
306
-        }
304
+		if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) {
305
+			return;
306
+		}
307 307
 
308 308
 		$field_id = absint( $_POST['field_id'] );
309
-        $field = FrmField::getOne($field_id);
309
+		$field = FrmField::getOne($field_id);
310 310
 
311 311
 		if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
312
-            return;
313
-        }
312
+			return;
313
+		}
314 314
 
315
-        $field = FrmFieldsHelper::setup_edit_vars($field);
315
+		$field = FrmFieldsHelper::setup_edit_vars($field);
316 316
 		$opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
317 317
 		$opts = explode( "\n", rtrim( $opts, "\n" ) );
318 318
 		$opts = array_map( 'trim', $opts );
319 319
 
320
-        if ( $field['separate_value'] ) {
321
-            foreach ( $opts as $opt_key => $opt ) {
322
-                if ( strpos($opt, '|') !== false ) {
323
-                    $vals = explode('|', $opt);
324
-                    if ( $vals[0] != $vals[1] ) {
325
-                        $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) );
326
-                    }
327
-                    unset($vals);
328
-                }
329
-                unset($opt_key, $opt);
330
-            }
331
-        }
332
-
333
-        //Keep other options after bulk update
334
-        if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
335
-            $other_array = array();
336
-            foreach ( $field['options'] as $opt_key => $opt ) {
320
+		if ( $field['separate_value'] ) {
321
+			foreach ( $opts as $opt_key => $opt ) {
322
+				if ( strpos($opt, '|') !== false ) {
323
+					$vals = explode('|', $opt);
324
+					if ( $vals[0] != $vals[1] ) {
325
+						$opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) );
326
+					}
327
+					unset($vals);
328
+				}
329
+				unset($opt_key, $opt);
330
+			}
331
+		}
332
+
333
+		//Keep other options after bulk update
334
+		if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
335
+			$other_array = array();
336
+			foreach ( $field['options'] as $opt_key => $opt ) {
337 337
 				if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
338 338
 					$other_array[ $opt_key ] = $opt;
339 339
 				}
340
-                unset($opt_key, $opt);
341
-            }
342
-            if ( ! empty($other_array) ) {
343
-                $opts = array_merge( $opts, $other_array);
344
-            }
345
-        }
340
+				unset($opt_key, $opt);
341
+			}
342
+			if ( ! empty($other_array) ) {
343
+				$opts = array_merge( $opts, $other_array);
344
+			}
345
+		}
346 346
 
347
-        $field['options'] = $opts;
347
+		$field['options'] = $opts;
348 348
 
349
-        if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
349
+		if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
350 350
 			$field_name = 'item_meta[' . $field['id'] . ']';
351 351
 
352 352
 			// Get html_id which will be used in single-option.php
353 353
 			$html_id = FrmFieldsHelper::get_html_id( $field );
354 354
 
355 355
 			require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' );
356
-        } else {
357
-            FrmFieldsHelper::show_single_option($field);
358
-        }
356
+		} else {
357
+			FrmFieldsHelper::show_single_option($field);
358
+		}
359 359
 
360
-        wp_die();
361
-    }
360
+		wp_die();
361
+	}
362 362
 
363
-    public static function update_order() {
363
+	public static function update_order() {
364 364
 		FrmAppHelper::permission_check('frm_edit_forms');
365
-        check_ajax_referer( 'frm_ajax', 'nonce' );
365
+		check_ajax_referer( 'frm_ajax', 'nonce' );
366 366
 
367 367
 		$fields = FrmAppHelper::get_post_param( 'frm_field_id' );
368 368
 		foreach ( (array) $fields as $position => $item ) {
369 369
 			FrmField::update( absint( $item ), array( 'field_order' => absint( $position ) ) );
370 370
 		}
371
-        wp_die();
372
-    }
371
+		wp_die();
372
+	}
373 373
 
374 374
 	public static function change_type( $type ) {
375
-        $type_switch = array(
376
-            'scale'     => 'radio',
377
-            '10radio'   => 'radio',
378
-            'rte'       => 'textarea',
379
-            'website'   => 'url',
380
-        );
381
-        if ( isset( $type_switch[ $type ] ) ) {
382
-            $type = $type_switch[ $type ];
383
-        }
375
+		$type_switch = array(
376
+			'scale'     => 'radio',
377
+			'10radio'   => 'radio',
378
+			'rte'       => 'textarea',
379
+			'website'   => 'url',
380
+		);
381
+		if ( isset( $type_switch[ $type ] ) ) {
382
+			$type = $type_switch[ $type ];
383
+		}
384 384
 
385 385
 		$pro_fields = FrmField::pro_field_selection();
386 386
 		$types = array_keys( $pro_fields );
@@ -388,137 +388,137 @@  discard block
 block discarded – undo
388 388
 			$type = 'text';
389 389
 		}
390 390
 
391
-        return $type;
392
-    }
391
+		return $type;
392
+	}
393 393
 
394 394
 	public static function display_field_options( $display ) {
395 395
 		switch ( $display['type'] ) {
396
-            case 'captcha':
397
-                $display['required'] = false;
398
-                $display['invalid'] = true;
399
-                $display['default_blank'] = false;
396
+			case 'captcha':
397
+				$display['required'] = false;
398
+				$display['invalid'] = true;
399
+				$display['default_blank'] = false;
400 400
 				$display['captcha_size'] = true;
401
-            break;
402
-            case 'radio':
403
-                $display['default_blank'] = false;
404
-            break;
405
-            case 'text':
406
-            case 'textarea':
407
-                $display['size'] = true;
408
-                $display['clear_on_focus'] = true;
409
-            break;
410
-            case 'select':
411
-                $display['size'] = true;
412
-            break;
413
-            case 'url':
414
-            case 'website':
415
-            case 'email':
416
-                $display['size'] = true;
417
-                $display['clear_on_focus'] = true;
418
-                $display['invalid'] = true;
419
-        }
420
-
421
-        return $display;
422
-    }
423
-
424
-    public static function input_html( $field, $echo = true ) {
425
-        $class = array(); //$field['type'];
426
-        self::add_input_classes($field, $class);
427
-
428
-        $add_html = array();
429
-        self::add_html_size($field, $add_html);
430
-        self::add_html_length($field, $add_html);
431
-        self::add_html_placeholder($field, $add_html, $class);
401
+			break;
402
+			case 'radio':
403
+				$display['default_blank'] = false;
404
+			break;
405
+			case 'text':
406
+			case 'textarea':
407
+				$display['size'] = true;
408
+				$display['clear_on_focus'] = true;
409
+			break;
410
+			case 'select':
411
+				$display['size'] = true;
412
+			break;
413
+			case 'url':
414
+			case 'website':
415
+			case 'email':
416
+				$display['size'] = true;
417
+				$display['clear_on_focus'] = true;
418
+				$display['invalid'] = true;
419
+		}
420
+
421
+		return $display;
422
+	}
423
+
424
+	public static function input_html( $field, $echo = true ) {
425
+		$class = array(); //$field['type'];
426
+		self::add_input_classes($field, $class);
427
+
428
+		$add_html = array();
429
+		self::add_html_size($field, $add_html);
430
+		self::add_html_length($field, $add_html);
431
+		self::add_html_placeholder($field, $add_html, $class);
432 432
 		self::add_validation_messages( $field, $add_html );
433 433
 
434
-        $class = apply_filters('frm_field_classes', implode(' ', $class), $field);
434
+		$class = apply_filters('frm_field_classes', implode(' ', $class), $field);
435 435
 
436 436
 		FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
437 437
 
438
-        self::add_shortcodes_to_html($field, $add_html);
438
+		self::add_shortcodes_to_html($field, $add_html);
439 439
 
440 440
 		$add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
441 441
 		$add_html = ' ' . implode( ' ', $add_html ) . '  ';
442 442
 
443
-        if ( $echo ) {
444
-            echo $add_html;
445
-        }
443
+		if ( $echo ) {
444
+			echo $add_html;
445
+		}
446 446
 
447
-        return $add_html;
448
-    }
447
+		return $add_html;
448
+	}
449 449
 
450 450
 	private static function add_input_classes( $field, array &$class ) {
451
-        if ( isset($field['input_class']) && ! empty($field['input_class']) ) {
452
-            $class[] = $field['input_class'];
453
-        }
451
+		if ( isset($field['input_class']) && ! empty($field['input_class']) ) {
452
+			$class[] = $field['input_class'];
453
+		}
454 454
 
455
-        if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
456
-            return;
457
-        }
455
+		if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
456
+			return;
457
+		}
458 458
 
459
-        if ( isset($field['size']) && $field['size'] > 0 ) {
460
-            $class[] = 'auto_width';
461
-        }
462
-    }
459
+		if ( isset($field['size']) && $field['size'] > 0 ) {
460
+			$class[] = 'auto_width';
461
+		}
462
+	}
463 463
 
464 464
 	private static function add_html_size( $field, array &$add_html ) {
465 465
 		if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden', 'file', 'lookup' ) ) ) {
466
-            return;
467
-        }
466
+			return;
467
+		}
468 468
 
469
-        if ( FrmAppHelper::is_admin_page('formidable' ) ) {
470
-            return;
471
-        }
469
+		if ( FrmAppHelper::is_admin_page('formidable' ) ) {
470
+			return;
471
+		}
472 472
 
473
-        if ( is_numeric($field['size']) ) {
474
-            $field['size'] .= 'px';
475
-        }
473
+		if ( is_numeric($field['size']) ) {
474
+			$field['size'] .= 'px';
475
+		}
476 476
 
477
-        $important = apply_filters('frm_use_important_width', 1, $field);
478
-        // Note: This inline styling must stay since we cannot realistically set a class for every possible field size
477
+		$important = apply_filters('frm_use_important_width', 1, $field);
478
+		// Note: This inline styling must stay since we cannot realistically set a class for every possible field size
479 479
 		$add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"';
480 480
 
481
-        self::add_html_cols($field, $add_html);
482
-    }
481
+		self::add_html_cols($field, $add_html);
482
+	}
483 483
 
484 484
 	private static function add_html_cols( $field, array &$add_html ) {
485 485
 		if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
486
-            return;
487
-        }
486
+			return;
487
+		}
488 488
 
489
-        // convert to cols for textareas
490
-        $calc = array(
491
-            ''      => 9,
492
-            'px'    => 9,
493
-            'rem'   => 0.444,
494
-            'em'    => 0.544,
495
-        );
489
+		// convert to cols for textareas
490
+		$calc = array(
491
+			''      => 9,
492
+			'px'    => 9,
493
+			'rem'   => 0.444,
494
+			'em'    => 0.544,
495
+		);
496 496
 
497
-        // include "col" for valid html
498
-        $unit = trim(preg_replace('/[0-9]+/', '', $field['size']));
497
+		// include "col" for valid html
498
+		$unit = trim(preg_replace('/[0-9]+/', '', $field['size']));
499 499
 
500
-        if ( ! isset( $calc[ $unit ] ) ) {
501
-            return;
502
-        }
500
+		if ( ! isset( $calc[ $unit ] ) ) {
501
+			return;
502
+		}
503 503
 
504
-        $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
504
+		$size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
505 505
 
506 506
 		$add_html['cols'] = 'cols="' . absint( $size ) . '"';
507
-    }
507
+	}
508 508
 
509 509
 	private static function add_html_length( $field, array &$add_html ) {
510
-        // check for max setting and if this field accepts maxlength
510
+		// check for max setting and if this field accepts maxlength
511 511
 		if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden', 'file' ) ) ) {
512
-            return;
513
-        }
512
+			return;
513
+		}
514 514
 
515
-        if ( FrmAppHelper::is_admin_page('formidable' ) ) {
516
-            // don't load on form builder page
517
-            return;
518
-        }
515
+		if ( FrmAppHelper::is_admin_page('formidable' ) ) {
516
+			// don't load on form builder page
517
+			return;
518
+		}
519 519
 
520 520
 		$add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
521
-    }
521
+	}
522 522
 
523 523
 	private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
524 524
 		if ( empty( $field['default_value'] ) || FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -526,35 +526,35 @@  discard block
 block discarded – undo
526 526
 		}
527 527
 
528 528
 		$default_value_array = is_array( $field['default_value'] );
529
-        if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) {
529
+		if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) {
530 530
 			if ( $default_value_array ) {
531 531
 				$field['default_value'] = json_encode( $field['default_value'] );
532 532
 			}
533 533
 			$add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
534
-            return;
535
-        }
534
+			return;
535
+		}
536 536
 
537 537
 		if ( $default_value_array ) {
538 538
 			// don't include a json placeholder
539 539
 			return;
540 540
 		}
541 541
 
542
-        $frm_settings = FrmAppHelper::get_settings();
542
+		$frm_settings = FrmAppHelper::get_settings();
543 543
 
544 544
 		if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) {
545
-            // use HMTL5 placeholder with js fallback
545
+			// use HMTL5 placeholder with js fallback
546 546
 			$add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"';
547
-            wp_enqueue_script('jquery-placeholder');
548
-        } else if ( ! $frm_settings->use_html ) {
547
+			wp_enqueue_script('jquery-placeholder');
548
+		} else if ( ! $frm_settings->use_html ) {
549 549
 			$val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( '&#039;', "'", esc_attr( $field['default_value'] ) ) ) );
550 550
 			$add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"';
551
-            $class[] = 'frm_toggle_default';
551
+			$class[] = 'frm_toggle_default';
552 552
 
553
-            if ( $field['value'] == $field['default_value'] ) {
554
-                $class[] = 'frm_default';
555
-            }
556
-        }
557
-    }
553
+			if ( $field['value'] == $field['default_value'] ) {
554
+				$class[] = 'frm_default';
555
+			}
556
+		}
557
+	}
558 558
 
559 559
 	private static function add_validation_messages( $field, array &$add_html ) {
560 560
 		if ( FrmField::is_required( $field ) ) {
@@ -568,44 +568,44 @@  discard block
 block discarded – undo
568 568
 		}
569 569
 	}
570 570
 
571
-    private static function add_shortcodes_to_html( $field, array &$add_html ) {
572
-        if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
573
-            return;
574
-        }
571
+	private static function add_shortcodes_to_html( $field, array &$add_html ) {
572
+		if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
573
+			return;
574
+		}
575 575
 
576
-        foreach ( $field['shortcodes'] as $k => $v ) {
577
-            if ( 'opt' === $k ) {
578
-                continue;
579
-            }
576
+		foreach ( $field['shortcodes'] as $k => $v ) {
577
+			if ( 'opt' === $k ) {
578
+				continue;
579
+			}
580 580
 
581
-            if ( is_numeric($k) && strpos($v, '=') ) {
582
-                $add_html[] = $v;
583
-            } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
581
+			if ( is_numeric($k) && strpos($v, '=') ) {
582
+				$add_html[] = $v;
583
+			} else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
584 584
 				$add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
585
-            } else {
585
+			} else {
586 586
 				$add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
587
-            }
588
-
589
-            unset($k, $v);
590
-        }
591
-    }
592
-
593
-    public static function check_value( $opt, $opt_key, $field ) {
594
-        if ( is_array( $opt ) ) {
595
-            if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
596
-                $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
597
-            } else {
598
-                $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
599
-            }
600
-        }
601
-        return $opt;
602
-    }
587
+			}
588
+
589
+			unset($k, $v);
590
+		}
591
+	}
592
+
593
+	public static function check_value( $opt, $opt_key, $field ) {
594
+		if ( is_array( $opt ) ) {
595
+			if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
596
+				$opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
597
+			} else {
598
+				$opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
599
+			}
600
+		}
601
+		return $opt;
602
+	}
603 603
 
604 604
 	public static function check_label( $opt ) {
605
-        if ( is_array($opt) ) {
606
-            $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
607
-        }
605
+		if ( is_array($opt) ) {
606
+			$opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
607
+		}
608 608
 
609
-        return $opt;
610
-    }
609
+		return $opt;
610
+	}
611 611
 }
Please login to merge, or discard this patch.