@@ -2,129 +2,129 @@ discard block |
||
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,246 +139,246 @@ discard block |
||
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 | 169 | $field_id = FrmField::create( $values ); |
170 | 170 | if ( ! $field_id ) { |
171 | 171 | wp_die(); |
172 | 172 | } |
173 | 173 | |
174 | - self::include_single_field($field_id, $values); |
|
174 | + self::include_single_field($field_id, $values); |
|
175 | 175 | |
176 | - wp_die(); |
|
177 | - } |
|
176 | + wp_die(); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Load a single field in the form builder along with all needed variables |
|
181 | - */ |
|
182 | - public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
183 | - $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
179 | + /** |
|
180 | + * Load a single field in the form builder along with all needed variables |
|
181 | + */ |
|
182 | + public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
183 | + $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
184 | 184 | $field_name = 'item_meta[' . $field_id . ']'; |
185 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
186 | - $id = $form_id ? $form_id : $field['form_id']; |
|
187 | - if ( $field['type'] == 'html' ) { |
|
188 | - $field['stop_filter'] = true; |
|
189 | - } |
|
185 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
186 | + $id = $form_id ? $form_id : $field['form_id']; |
|
187 | + if ( $field['type'] == 'html' ) { |
|
188 | + $field['stop_filter'] = true; |
|
189 | + } |
|
190 | 190 | |
191 | 191 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' ); |
192 | 192 | |
193 | - return $field; |
|
194 | - } |
|
193 | + return $field; |
|
194 | + } |
|
195 | 195 | |
196 | - public static function destroy() { |
|
196 | + public static function destroy() { |
|
197 | 197 | FrmAppHelper::permission_check('frm_edit_forms'); |
198 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
198 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
199 | 199 | |
200 | 200 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
201 | 201 | FrmField::destroy( $field_id ); |
202 | - wp_die(); |
|
203 | - } |
|
202 | + wp_die(); |
|
203 | + } |
|
204 | 204 | |
205 | - /* Field Options */ |
|
205 | + /* Field Options */ |
|
206 | 206 | |
207 | - //Add Single Option or Other Option |
|
208 | - public static function add_option() { |
|
207 | + //Add Single Option or Other Option |
|
208 | + public static function add_option() { |
|
209 | 209 | FrmAppHelper::permission_check('frm_edit_forms'); |
210 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
210 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
211 | 211 | |
212 | 212 | $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
213 | 213 | $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' ); |
214 | 214 | $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'absint' ); |
215 | 215 | |
216 | - $field = FrmField::getOne($id); |
|
216 | + $field = FrmField::getOne($id); |
|
217 | 217 | |
218 | - if ( 'other' == $opt_type ) { |
|
218 | + if ( 'other' == $opt_type ) { |
|
219 | 219 | $opt = __( 'Other', 'formidable' ); |
220 | - $other_val = ''; |
|
221 | - $opt_key = 'other_' . $opt_key; |
|
222 | - } else { |
|
220 | + $other_val = ''; |
|
221 | + $opt_key = 'other_' . $opt_key; |
|
222 | + } else { |
|
223 | 223 | $opt = __( 'New Option', 'formidable' ); |
224 | - } |
|
225 | - $field_val = $opt; |
|
224 | + } |
|
225 | + $field_val = $opt; |
|
226 | 226 | |
227 | - $field_data = $field; |
|
227 | + $field_data = $field; |
|
228 | 228 | $field = (array) $field; |
229 | 229 | $field['separate_value'] = isset( $field_data->field_options['separate_value'] ) ? $field_data->field_options['separate_value'] : 0; |
230 | 230 | unset( $field_data ); |
231 | 231 | |
232 | 232 | $field_name = 'item_meta[' . $id . ']'; |
233 | 233 | $html_id = FrmFieldsHelper::get_html_id( $field ); |
234 | - $checked = ''; |
|
234 | + $checked = ''; |
|
235 | 235 | |
236 | - if ( 'other' == $opt_type ) { |
|
236 | + if ( 'other' == $opt_type ) { |
|
237 | 237 | include( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' ); |
238 | - } else { |
|
238 | + } else { |
|
239 | 239 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
240 | - } |
|
241 | - wp_die(); |
|
242 | - } |
|
240 | + } |
|
241 | + wp_die(); |
|
242 | + } |
|
243 | 243 | |
244 | - public static function edit_option() { |
|
244 | + public static function edit_option() { |
|
245 | 245 | _deprecated_function( __FUNCTION__, '2.3' ); |
246 | - } |
|
246 | + } |
|
247 | 247 | |
248 | - public static function delete_option() { |
|
248 | + public static function delete_option() { |
|
249 | 249 | _deprecated_function( __FUNCTION__, '2.3' ); |
250 | - } |
|
250 | + } |
|
251 | 251 | |
252 | - public static function import_choices() { |
|
253 | - FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
252 | + public static function import_choices() { |
|
253 | + FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
254 | 254 | |
255 | 255 | $field_id = absint( $_REQUEST['field_id'] ); |
256 | 256 | |
257 | - global $current_screen, $hook_suffix; |
|
257 | + global $current_screen, $hook_suffix; |
|
258 | 258 | |
259 | - // Catch plugins that include admin-header.php before admin.php completes. |
|
260 | - if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
261 | - $hook_suffix = ''; |
|
262 | - set_current_screen(); |
|
263 | - } |
|
259 | + // Catch plugins that include admin-header.php before admin.php completes. |
|
260 | + if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
261 | + $hook_suffix = ''; |
|
262 | + set_current_screen(); |
|
263 | + } |
|
264 | 264 | |
265 | - if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
266 | - register_admin_color_schemes(); |
|
267 | - } |
|
265 | + if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
266 | + register_admin_color_schemes(); |
|
267 | + } |
|
268 | 268 | |
269 | 269 | $hook_suffix = ''; |
270 | 270 | $admin_body_class = ''; |
271 | 271 | |
272 | - if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
273 | - $admin_body_class .= ' folded'; |
|
274 | - } |
|
272 | + if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
273 | + $admin_body_class .= ' folded'; |
|
274 | + } |
|
275 | 275 | |
276 | - if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
277 | - $admin_body_class .= ' admin-bar'; |
|
278 | - } |
|
276 | + if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
277 | + $admin_body_class .= ' admin-bar'; |
|
278 | + } |
|
279 | 279 | |
280 | - if ( is_rtl() ) { |
|
281 | - $admin_body_class .= ' rtl'; |
|
282 | - } |
|
280 | + if ( is_rtl() ) { |
|
281 | + $admin_body_class .= ' rtl'; |
|
282 | + } |
|
283 | 283 | |
284 | - $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
285 | - $prepop = array(); |
|
286 | - FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
284 | + $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
285 | + $prepop = array(); |
|
286 | + FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
287 | 287 | |
288 | - $field = FrmField::getOne($field_id); |
|
288 | + $field = FrmField::getOne($field_id); |
|
289 | 289 | |
290 | - wp_enqueue_script( 'utils' ); |
|
290 | + wp_enqueue_script( 'utils' ); |
|
291 | 291 | wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' ); |
292 | - FrmAppHelper::load_admin_wide_js(); |
|
292 | + FrmAppHelper::load_admin_wide_js(); |
|
293 | 293 | |
294 | 294 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/import_choices.php' ); |
295 | - wp_die(); |
|
296 | - } |
|
295 | + wp_die(); |
|
296 | + } |
|
297 | 297 | |
298 | - public static function import_options() { |
|
298 | + public static function import_options() { |
|
299 | 299 | FrmAppHelper::permission_check('frm_edit_forms'); |
300 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
300 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
301 | 301 | |
302 | - if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
303 | - return; |
|
304 | - } |
|
302 | + if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
303 | + return; |
|
304 | + } |
|
305 | 305 | |
306 | 306 | $field_id = absint( $_POST['field_id'] ); |
307 | - $field = FrmField::getOne($field_id); |
|
307 | + $field = FrmField::getOne($field_id); |
|
308 | 308 | |
309 | 309 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { |
310 | - return; |
|
311 | - } |
|
310 | + return; |
|
311 | + } |
|
312 | 312 | |
313 | - $field = FrmFieldsHelper::setup_edit_vars($field); |
|
313 | + $field = FrmFieldsHelper::setup_edit_vars($field); |
|
314 | 314 | $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); |
315 | 315 | $opts = explode( "\n", rtrim( $opts, "\n" ) ); |
316 | 316 | $opts = array_map( 'trim', $opts ); |
317 | 317 | |
318 | - if ( $field['separate_value'] ) { |
|
319 | - foreach ( $opts as $opt_key => $opt ) { |
|
320 | - if ( strpos($opt, '|') !== false ) { |
|
321 | - $vals = explode('|', $opt); |
|
322 | - if ( $vals[0] != $vals[1] ) { |
|
323 | - $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
324 | - } |
|
325 | - unset($vals); |
|
326 | - } |
|
327 | - unset($opt_key, $opt); |
|
328 | - } |
|
329 | - } |
|
330 | - |
|
331 | - //Keep other options after bulk update |
|
332 | - if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
333 | - $other_array = array(); |
|
334 | - foreach ( $field['options'] as $opt_key => $opt ) { |
|
318 | + if ( $field['separate_value'] ) { |
|
319 | + foreach ( $opts as $opt_key => $opt ) { |
|
320 | + if ( strpos($opt, '|') !== false ) { |
|
321 | + $vals = explode('|', $opt); |
|
322 | + if ( $vals[0] != $vals[1] ) { |
|
323 | + $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
324 | + } |
|
325 | + unset($vals); |
|
326 | + } |
|
327 | + unset($opt_key, $opt); |
|
328 | + } |
|
329 | + } |
|
330 | + |
|
331 | + //Keep other options after bulk update |
|
332 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
333 | + $other_array = array(); |
|
334 | + foreach ( $field['options'] as $opt_key => $opt ) { |
|
335 | 335 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
336 | 336 | $other_array[ $opt_key ] = $opt; |
337 | 337 | } |
338 | - unset($opt_key, $opt); |
|
339 | - } |
|
340 | - if ( ! empty($other_array) ) { |
|
341 | - $opts = array_merge( $opts, $other_array); |
|
342 | - } |
|
343 | - } |
|
338 | + unset($opt_key, $opt); |
|
339 | + } |
|
340 | + if ( ! empty($other_array) ) { |
|
341 | + $opts = array_merge( $opts, $other_array); |
|
342 | + } |
|
343 | + } |
|
344 | 344 | |
345 | - $field['options'] = $opts; |
|
345 | + $field['options'] = $opts; |
|
346 | 346 | |
347 | - if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
347 | + if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
348 | 348 | $field_name = 'item_meta[' . $field['id'] . ']'; |
349 | 349 | |
350 | 350 | // Get html_id which will be used in single-option.php |
351 | 351 | $html_id = FrmFieldsHelper::get_html_id( $field ); |
352 | 352 | |
353 | 353 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); |
354 | - } else { |
|
355 | - FrmFieldsHelper::show_single_option($field); |
|
356 | - } |
|
354 | + } else { |
|
355 | + FrmFieldsHelper::show_single_option($field); |
|
356 | + } |
|
357 | 357 | |
358 | - wp_die(); |
|
359 | - } |
|
358 | + wp_die(); |
|
359 | + } |
|
360 | 360 | |
361 | - public static function update_order() { |
|
361 | + public static function update_order() { |
|
362 | 362 | FrmAppHelper::permission_check('frm_edit_forms'); |
363 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
363 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
364 | 364 | |
365 | 365 | $fields = FrmAppHelper::get_post_param( 'frm_field_id' ); |
366 | 366 | foreach ( (array) $fields as $position => $item ) { |
367 | 367 | FrmField::update( absint( $item ), array( 'field_order' => absint( $position ) ) ); |
368 | 368 | } |
369 | - wp_die(); |
|
370 | - } |
|
369 | + wp_die(); |
|
370 | + } |
|
371 | 371 | |
372 | 372 | public static function change_type( $type ) { |
373 | - $type_switch = array( |
|
374 | - 'scale' => 'radio', |
|
375 | - '10radio' => 'radio', |
|
376 | - 'rte' => 'textarea', |
|
377 | - 'website' => 'url', |
|
378 | - ); |
|
379 | - if ( isset( $type_switch[ $type ] ) ) { |
|
380 | - $type = $type_switch[ $type ]; |
|
381 | - } |
|
373 | + $type_switch = array( |
|
374 | + 'scale' => 'radio', |
|
375 | + '10radio' => 'radio', |
|
376 | + 'rte' => 'textarea', |
|
377 | + 'website' => 'url', |
|
378 | + ); |
|
379 | + if ( isset( $type_switch[ $type ] ) ) { |
|
380 | + $type = $type_switch[ $type ]; |
|
381 | + } |
|
382 | 382 | |
383 | 383 | $pro_fields = FrmField::pro_field_selection(); |
384 | 384 | $types = array_keys( $pro_fields ); |
@@ -386,137 +386,137 @@ discard block |
||
386 | 386 | $type = 'text'; |
387 | 387 | } |
388 | 388 | |
389 | - return $type; |
|
390 | - } |
|
389 | + return $type; |
|
390 | + } |
|
391 | 391 | |
392 | 392 | public static function display_field_options( $display ) { |
393 | 393 | switch ( $display['type'] ) { |
394 | - case 'captcha': |
|
395 | - $display['required'] = false; |
|
396 | - $display['invalid'] = true; |
|
397 | - $display['default_blank'] = false; |
|
394 | + case 'captcha': |
|
395 | + $display['required'] = false; |
|
396 | + $display['invalid'] = true; |
|
397 | + $display['default_blank'] = false; |
|
398 | 398 | $display['captcha_size'] = true; |
399 | - break; |
|
400 | - case 'radio': |
|
401 | - $display['default_blank'] = false; |
|
402 | - break; |
|
403 | - case 'text': |
|
404 | - case 'textarea': |
|
405 | - $display['size'] = true; |
|
406 | - $display['clear_on_focus'] = true; |
|
407 | - break; |
|
408 | - case 'select': |
|
409 | - $display['size'] = true; |
|
410 | - break; |
|
411 | - case 'url': |
|
412 | - case 'website': |
|
413 | - case 'email': |
|
414 | - $display['size'] = true; |
|
415 | - $display['clear_on_focus'] = true; |
|
416 | - $display['invalid'] = true; |
|
417 | - } |
|
418 | - |
|
419 | - return $display; |
|
420 | - } |
|
421 | - |
|
422 | - public static function input_html( $field, $echo = true ) { |
|
423 | - $class = array(); //$field['type']; |
|
424 | - self::add_input_classes($field, $class); |
|
425 | - |
|
426 | - $add_html = array(); |
|
427 | - self::add_html_size($field, $add_html); |
|
428 | - self::add_html_length($field, $add_html); |
|
429 | - self::add_html_placeholder($field, $add_html, $class); |
|
399 | + break; |
|
400 | + case 'radio': |
|
401 | + $display['default_blank'] = false; |
|
402 | + break; |
|
403 | + case 'text': |
|
404 | + case 'textarea': |
|
405 | + $display['size'] = true; |
|
406 | + $display['clear_on_focus'] = true; |
|
407 | + break; |
|
408 | + case 'select': |
|
409 | + $display['size'] = true; |
|
410 | + break; |
|
411 | + case 'url': |
|
412 | + case 'website': |
|
413 | + case 'email': |
|
414 | + $display['size'] = true; |
|
415 | + $display['clear_on_focus'] = true; |
|
416 | + $display['invalid'] = true; |
|
417 | + } |
|
418 | + |
|
419 | + return $display; |
|
420 | + } |
|
421 | + |
|
422 | + public static function input_html( $field, $echo = true ) { |
|
423 | + $class = array(); //$field['type']; |
|
424 | + self::add_input_classes($field, $class); |
|
425 | + |
|
426 | + $add_html = array(); |
|
427 | + self::add_html_size($field, $add_html); |
|
428 | + self::add_html_length($field, $add_html); |
|
429 | + self::add_html_placeholder($field, $add_html, $class); |
|
430 | 430 | self::add_validation_messages( $field, $add_html ); |
431 | 431 | |
432 | - $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
432 | + $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
433 | 433 | |
434 | 434 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
435 | 435 | |
436 | - self::add_shortcodes_to_html($field, $add_html); |
|
436 | + self::add_shortcodes_to_html($field, $add_html); |
|
437 | 437 | |
438 | 438 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
439 | 439 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
440 | 440 | |
441 | - if ( $echo ) { |
|
442 | - echo $add_html; |
|
443 | - } |
|
441 | + if ( $echo ) { |
|
442 | + echo $add_html; |
|
443 | + } |
|
444 | 444 | |
445 | - return $add_html; |
|
446 | - } |
|
445 | + return $add_html; |
|
446 | + } |
|
447 | 447 | |
448 | 448 | private static function add_input_classes( $field, array &$class ) { |
449 | - if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
450 | - $class[] = $field['input_class']; |
|
451 | - } |
|
449 | + if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
450 | + $class[] = $field['input_class']; |
|
451 | + } |
|
452 | 452 | |
453 | - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
454 | - return; |
|
455 | - } |
|
453 | + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
454 | + return; |
|
455 | + } |
|
456 | 456 | |
457 | - if ( isset($field['size']) && $field['size'] > 0 ) { |
|
458 | - $class[] = 'auto_width'; |
|
459 | - } |
|
460 | - } |
|
457 | + if ( isset($field['size']) && $field['size'] > 0 ) { |
|
458 | + $class[] = 'auto_width'; |
|
459 | + } |
|
460 | + } |
|
461 | 461 | |
462 | 462 | private static function add_html_size( $field, array &$add_html ) { |
463 | 463 | if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden', 'file', 'lookup' ) ) ) { |
464 | - return; |
|
465 | - } |
|
464 | + return; |
|
465 | + } |
|
466 | 466 | |
467 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
468 | - return; |
|
469 | - } |
|
467 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
468 | + return; |
|
469 | + } |
|
470 | 470 | |
471 | - if ( is_numeric($field['size']) ) { |
|
472 | - $field['size'] .= 'px'; |
|
473 | - } |
|
471 | + if ( is_numeric($field['size']) ) { |
|
472 | + $field['size'] .= 'px'; |
|
473 | + } |
|
474 | 474 | |
475 | - $important = apply_filters('frm_use_important_width', 1, $field); |
|
476 | - // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
475 | + $important = apply_filters('frm_use_important_width', 1, $field); |
|
476 | + // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
477 | 477 | $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"'; |
478 | 478 | |
479 | - self::add_html_cols($field, $add_html); |
|
480 | - } |
|
479 | + self::add_html_cols($field, $add_html); |
|
480 | + } |
|
481 | 481 | |
482 | 482 | private static function add_html_cols( $field, array &$add_html ) { |
483 | 483 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) { |
484 | - return; |
|
485 | - } |
|
484 | + return; |
|
485 | + } |
|
486 | 486 | |
487 | - // convert to cols for textareas |
|
488 | - $calc = array( |
|
489 | - '' => 9, |
|
490 | - 'px' => 9, |
|
491 | - 'rem' => 0.444, |
|
492 | - 'em' => 0.544, |
|
493 | - ); |
|
487 | + // convert to cols for textareas |
|
488 | + $calc = array( |
|
489 | + '' => 9, |
|
490 | + 'px' => 9, |
|
491 | + 'rem' => 0.444, |
|
492 | + 'em' => 0.544, |
|
493 | + ); |
|
494 | 494 | |
495 | - // include "col" for valid html |
|
496 | - $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
495 | + // include "col" for valid html |
|
496 | + $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
497 | 497 | |
498 | - if ( ! isset( $calc[ $unit ] ) ) { |
|
499 | - return; |
|
500 | - } |
|
498 | + if ( ! isset( $calc[ $unit ] ) ) { |
|
499 | + return; |
|
500 | + } |
|
501 | 501 | |
502 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
502 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
503 | 503 | |
504 | 504 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
505 | - } |
|
505 | + } |
|
506 | 506 | |
507 | 507 | private static function add_html_length( $field, array &$add_html ) { |
508 | - // check for max setting and if this field accepts maxlength |
|
508 | + // check for max setting and if this field accepts maxlength |
|
509 | 509 | if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden', 'file' ) ) ) { |
510 | - return; |
|
511 | - } |
|
510 | + return; |
|
511 | + } |
|
512 | 512 | |
513 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
514 | - // don't load on form builder page |
|
515 | - return; |
|
516 | - } |
|
513 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
514 | + // don't load on form builder page |
|
515 | + return; |
|
516 | + } |
|
517 | 517 | |
518 | 518 | $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"'; |
519 | - } |
|
519 | + } |
|
520 | 520 | |
521 | 521 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
522 | 522 | if ( empty( $field['default_value'] ) || FrmAppHelper::is_admin_page( 'formidable' ) ) { |
@@ -524,35 +524,35 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | $default_value_array = is_array( $field['default_value'] ); |
527 | - if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
527 | + if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
528 | 528 | if ( $default_value_array ) { |
529 | 529 | $field['default_value'] = json_encode( $field['default_value'] ); |
530 | 530 | } |
531 | 531 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
532 | - return; |
|
533 | - } |
|
532 | + return; |
|
533 | + } |
|
534 | 534 | |
535 | 535 | if ( $default_value_array ) { |
536 | 536 | // don't include a json placeholder |
537 | 537 | return; |
538 | 538 | } |
539 | 539 | |
540 | - $frm_settings = FrmAppHelper::get_settings(); |
|
540 | + $frm_settings = FrmAppHelper::get_settings(); |
|
541 | 541 | |
542 | 542 | if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) { |
543 | - // use HMTL5 placeholder with js fallback |
|
543 | + // use HMTL5 placeholder with js fallback |
|
544 | 544 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"'; |
545 | - wp_enqueue_script('jquery-placeholder'); |
|
546 | - } else if ( ! $frm_settings->use_html ) { |
|
545 | + wp_enqueue_script('jquery-placeholder'); |
|
546 | + } else if ( ! $frm_settings->use_html ) { |
|
547 | 547 | $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) ); |
548 | 548 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"'; |
549 | - $class[] = 'frm_toggle_default'; |
|
549 | + $class[] = 'frm_toggle_default'; |
|
550 | 550 | |
551 | - if ( $field['value'] == $field['default_value'] ) { |
|
552 | - $class[] = 'frm_default'; |
|
553 | - } |
|
554 | - } |
|
555 | - } |
|
551 | + if ( $field['value'] == $field['default_value'] ) { |
|
552 | + $class[] = 'frm_default'; |
|
553 | + } |
|
554 | + } |
|
555 | + } |
|
556 | 556 | |
557 | 557 | private static function add_validation_messages( $field, array &$add_html ) { |
558 | 558 | if ( FrmField::is_required( $field ) ) { |
@@ -566,44 +566,44 @@ discard block |
||
566 | 566 | } |
567 | 567 | } |
568 | 568 | |
569 | - private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
570 | - if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
571 | - return; |
|
572 | - } |
|
569 | + private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
570 | + if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
571 | + return; |
|
572 | + } |
|
573 | 573 | |
574 | - foreach ( $field['shortcodes'] as $k => $v ) { |
|
575 | - if ( 'opt' === $k ) { |
|
576 | - continue; |
|
577 | - } |
|
574 | + foreach ( $field['shortcodes'] as $k => $v ) { |
|
575 | + if ( 'opt' === $k ) { |
|
576 | + continue; |
|
577 | + } |
|
578 | 578 | |
579 | - if ( is_numeric($k) && strpos($v, '=') ) { |
|
580 | - $add_html[] = $v; |
|
581 | - } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
579 | + if ( is_numeric($k) && strpos($v, '=') ) { |
|
580 | + $add_html[] = $v; |
|
581 | + } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
582 | 582 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
583 | - } else { |
|
583 | + } else { |
|
584 | 584 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
585 | - } |
|
586 | - |
|
587 | - unset($k, $v); |
|
588 | - } |
|
589 | - } |
|
590 | - |
|
591 | - public static function check_value( $opt, $opt_key, $field ) { |
|
592 | - if ( is_array( $opt ) ) { |
|
593 | - if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
594 | - $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
595 | - } else { |
|
596 | - $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
597 | - } |
|
598 | - } |
|
599 | - return $opt; |
|
600 | - } |
|
585 | + } |
|
586 | + |
|
587 | + unset($k, $v); |
|
588 | + } |
|
589 | + } |
|
590 | + |
|
591 | + public static function check_value( $opt, $opt_key, $field ) { |
|
592 | + if ( is_array( $opt ) ) { |
|
593 | + if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
594 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
595 | + } else { |
|
596 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
597 | + } |
|
598 | + } |
|
599 | + return $opt; |
|
600 | + } |
|
601 | 601 | |
602 | 602 | public static function check_label( $opt ) { |
603 | - if ( is_array($opt) ) { |
|
604 | - $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
605 | - } |
|
603 | + if ( is_array($opt) ) { |
|
604 | + $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
605 | + } |
|
606 | 606 | |
607 | - return $opt; |
|
608 | - } |
|
607 | + return $opt; |
|
608 | + } |
|
609 | 609 | } |