@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | 3 | die( 'You are not allowed to call this page directly.' ); |
4 | 4 | } |
5 | 5 | |
@@ -8,12 +8,12 @@ discard block |
||
8 | 8 | public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
9 | 9 | $values = array(); |
10 | 10 | foreach ( array( 'name' => '', 'description' => '', 'item_key' => '' ) as $var => $default ) { |
11 | - $values[ $var ] = FrmAppHelper::get_post_param( $var, $default, 'wp_kses_post' ); |
|
11 | + $values[$var] = FrmAppHelper::get_post_param( $var, $default, 'wp_kses_post' ); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | $values['fields'] = array(); |
15 | - if ( empty($fields) ) { |
|
16 | - return apply_filters('frm_setup_new_entry', $values); |
|
15 | + if ( empty( $fields ) ) { |
|
16 | + return apply_filters( 'frm_setup_new_entry', $values ); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | foreach ( (array) $fields as $field ) { |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | 'default_value' => $field->default_value, |
26 | 26 | 'name' => $field->name, |
27 | 27 | 'description' => $field->description, |
28 | - 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
28 | + 'type' => apply_filters( 'frm_field_type', $field->type, $field, $new_value ), |
|
29 | 29 | 'options' => $field->options, |
30 | 30 | 'required' => $field->required, |
31 | 31 | 'field_key' => $field->field_key, |
@@ -36,43 +36,43 @@ discard block |
||
36 | 36 | 'in_embed_form' => isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0', |
37 | 37 | ); |
38 | 38 | |
39 | - $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
39 | + $opt_defaults = FrmFieldsHelper::get_default_field_opts( $field_array['type'], $field, true ); |
|
40 | 40 | $opt_defaults['required_indicator'] = ''; |
41 | 41 | $opt_defaults['original_type'] = $field->type; |
42 | 42 | |
43 | 43 | foreach ( $opt_defaults as $opt => $default_opt ) { |
44 | - $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
45 | - unset($opt, $default_opt); |
|
44 | + $field_array[$opt] = ( isset( $field->field_options[$opt] ) && $field->field_options[$opt] != '' ) ? $field->field_options[$opt] : $default_opt; |
|
45 | + unset( $opt, $default_opt ); |
|
46 | 46 | } |
47 | 47 | |
48 | - unset($opt_defaults); |
|
48 | + unset( $opt_defaults ); |
|
49 | 49 | |
50 | 50 | if ( $field_array['custom_html'] == '' ) { |
51 | - $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
51 | + $field_array['custom_html'] = FrmFieldsHelper::get_default_html( $field->type ); |
|
52 | 52 | } |
53 | 53 | |
54 | - $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
54 | + $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
55 | 55 | $field_array = array_merge( $field->field_options, $field_array ); |
56 | 56 | |
57 | 57 | $values['fields'][] = $field_array; |
58 | 58 | |
59 | - if ( ! $form || ! isset($form->id) ) { |
|
60 | - $form = FrmForm::getOne($field->form_id); |
|
59 | + if ( ! $form || ! isset( $form->id ) ) { |
|
60 | + $form = FrmForm::getOne( $field->form_id ); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - $form->options = maybe_unserialize($form->options); |
|
65 | - if ( is_array($form->options) ) { |
|
64 | + $form->options = maybe_unserialize( $form->options ); |
|
65 | + if ( is_array( $form->options ) ) { |
|
66 | 66 | foreach ( $form->options as $opt => $value ) { |
67 | - $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
68 | - unset($opt, $value); |
|
67 | + $values[$opt] = FrmAppHelper::get_post_param( $opt, $value ); |
|
68 | + unset( $opt, $value ); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | 72 | $form_defaults = FrmFormsHelper::get_default_opts(); |
73 | 73 | |
74 | 74 | $frm_settings = FrmAppHelper::get_settings(); |
75 | - $form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' ); |
|
75 | + $form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' ); |
|
76 | 76 | |
77 | 77 | $values = array_merge( $form_defaults, $values ); |
78 | 78 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $return_array = FrmField::is_field_with_multiple_values( $field ); |
96 | 96 | |
97 | 97 | // Do any shortcodes in default value and allow customization of default value |
98 | - $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true, $return_array); |
|
98 | + $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true, $return_array ); |
|
99 | 99 | // Calls FrmProFieldsHelper::get_default_value |
100 | 100 | |
101 | 101 | $new_value = $field->default_value; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | if ( ! is_array( $new_value ) ) { |
111 | - $new_value = str_replace('"', '"', $new_value); |
|
111 | + $new_value = str_replace( '"', '"', $new_value ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | return $new_value; |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | if ( $_POST ) { |
128 | 128 | $repeating = isset( $args['repeating'] ) && $args['repeating']; |
129 | 129 | if ( $repeating ) { |
130 | - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { |
|
130 | + if ( isset( $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field->id] ) ) { |
|
131 | 131 | $value_is_posted = true; |
132 | 132 | } |
133 | - } else if ( isset( $_POST['item_meta'][ $field->id ] ) ) { |
|
133 | + } else if ( isset( $_POST['item_meta'][$field->id] ) ) { |
|
134 | 134 | $value_is_posted = true; |
135 | 135 | } |
136 | 136 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' ); |
142 | 142 | $values['form_id'] = $record->form_id; |
143 | 143 | $values['is_draft'] = $record->is_draft; |
144 | - return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
144 | + return apply_filters( 'frm_setup_edit_entry_vars', $values, $record ); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | public static function get_admin_params( $form = null ) { |
@@ -170,22 +170,22 @@ discard block |
||
170 | 170 | } |
171 | 171 | |
172 | 172 | public static function replace_default_message( $message, $atts ) { |
173 | - if ( strpos($message, '[default-message') === false && |
|
174 | - strpos($message, '[default_message') === false && |
|
173 | + if ( strpos( $message, '[default-message' ) === false && |
|
174 | + strpos( $message, '[default_message' ) === false && |
|
175 | 175 | ! empty( $message ) ) { |
176 | 176 | return $message; |
177 | 177 | } |
178 | 178 | |
179 | - if ( empty($message) ) { |
|
179 | + if ( empty( $message ) ) { |
|
180 | 180 | $message = '[default-message]'; |
181 | 181 | } |
182 | 182 | |
183 | - preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
183 | + preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER ); |
|
184 | 184 | |
185 | 185 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
186 | - $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
186 | + $add_atts = shortcode_parse_atts( $shortcodes[2][$short_key] ); |
|
187 | 187 | if ( $add_atts ) { |
188 | - $this_atts = array_merge($atts, $add_atts); |
|
188 | + $this_atts = array_merge( $atts, $add_atts ); |
|
189 | 189 | } else { |
190 | 190 | $this_atts = $atts; |
191 | 191 | } |
@@ -193,32 +193,32 @@ discard block |
||
193 | 193 | $default = FrmEntryFormat::show_entry( $this_atts ); |
194 | 194 | |
195 | 195 | // Add the default message |
196 | - $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
196 | + $message = str_replace( $shortcodes[0][$short_key], $default, $message ); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | return $message; |
200 | 200 | } |
201 | 201 | |
202 | 202 | public static function prepare_display_value( $entry, $field, $atts ) { |
203 | - $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false; |
|
203 | + $field_value = isset( $entry->metas[$field->id] ) ? $entry->metas[$field->id] : false; |
|
204 | 204 | |
205 | 205 | if ( FrmAppHelper::pro_is_installed() ) { |
206 | 206 | FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value ); |
207 | 207 | } |
208 | 208 | |
209 | - if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
210 | - return self::display_value($field_value, $field, $atts); |
|
209 | + if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) { |
|
210 | + return self::display_value( $field_value, $field, $atts ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | // this is an embeded form |
214 | 214 | $val = ''; |
215 | 215 | |
216 | - if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
216 | + if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) { |
|
217 | 217 | //this is a repeating section |
218 | 218 | $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) ); |
219 | 219 | } else { |
220 | 220 | // get all values for this field |
221 | - $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
221 | + $child_values = isset( $entry->metas[$atts['embedded_field_id']] ) ? $entry->metas[$atts['embedded_field_id']] : false; |
|
222 | 222 | |
223 | 223 | if ( $child_values ) { |
224 | 224 | $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | |
228 | 228 | $field_value = array(); |
229 | 229 | |
230 | - if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
230 | + if ( ! isset( $child_entries ) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
231 | 231 | return $val; |
232 | 232 | } |
233 | 233 | |
@@ -236,17 +236,17 @@ discard block |
||
236 | 236 | $atts['post_id'] = $child_entry->post_id; |
237 | 237 | |
238 | 238 | // get the value for this field -- check for post values as well |
239 | - $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
239 | + $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field ); |
|
240 | 240 | |
241 | 241 | if ( $entry_val ) { |
242 | 242 | // foreach entry get display_value |
243 | - $field_value[] = self::display_value($entry_val, $field, $atts); |
|
243 | + $field_value[] = self::display_value( $entry_val, $field, $atts ); |
|
244 | 244 | } |
245 | 245 | |
246 | - unset($child_entry); |
|
246 | + unset( $child_entry ); |
|
247 | 247 | } |
248 | 248 | |
249 | - $val = implode(', ', (array) $field_value ); |
|
249 | + $val = implode( ', ', (array) $field_value ); |
|
250 | 250 | $val = wp_kses_post( $val ); |
251 | 251 | |
252 | 252 | return $val; |
@@ -266,22 +266,22 @@ discard block |
||
266 | 266 | ); |
267 | 267 | |
268 | 268 | $atts = wp_parse_args( $atts, $defaults ); |
269 | - $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
269 | + $atts = apply_filters( 'frm_display_value_atts', $atts, $field, $value ); |
|
270 | 270 | |
271 | - if ( ! isset($field->field_options['post_field']) ) { |
|
271 | + if ( ! isset( $field->field_options['post_field'] ) ) { |
|
272 | 272 | $field->field_options['post_field'] = ''; |
273 | 273 | } |
274 | 274 | |
275 | - if ( ! isset($field->field_options['custom_field']) ) { |
|
275 | + if ( ! isset( $field->field_options['custom_field'] ) ) { |
|
276 | 276 | $field->field_options['custom_field'] = ''; |
277 | 277 | } |
278 | 278 | |
279 | 279 | if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
280 | 280 | $atts['pre_truncate'] = $atts['truncate']; |
281 | 281 | $atts['truncate'] = true; |
282 | - $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
282 | + $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0; |
|
283 | 283 | |
284 | - $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
284 | + $value = FrmProEntryMetaHelper::get_post_value( $atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts ); |
|
285 | 285 | $atts['truncate'] = $atts['pre_truncate']; |
286 | 286 | } |
287 | 287 | |
@@ -289,39 +289,39 @@ discard block |
||
289 | 289 | return $value; |
290 | 290 | } |
291 | 291 | |
292 | - $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts); |
|
292 | + $value = apply_filters( 'frm_display_value_custom', maybe_unserialize( $value ), $field, $atts ); |
|
293 | 293 | $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) ); |
294 | 294 | |
295 | 295 | $new_value = ''; |
296 | 296 | |
297 | - if ( is_array($value) && $atts['type'] != 'file' ) { |
|
297 | + if ( is_array( $value ) && $atts['type'] != 'file' ) { |
|
298 | 298 | foreach ( $value as $val ) { |
299 | - if ( is_array($val) ) { |
|
299 | + if ( is_array( $val ) ) { |
|
300 | 300 | //TODO: add options for display (li or ,) |
301 | - $new_value .= implode($atts['sep'], $val); |
|
301 | + $new_value .= implode( $atts['sep'], $val ); |
|
302 | 302 | if ( $atts['type'] != 'data' ) { |
303 | 303 | $new_value .= '<br/>'; |
304 | 304 | } |
305 | 305 | } |
306 | - unset($val); |
|
306 | + unset( $val ); |
|
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | - if ( ! empty($new_value) ) { |
|
310 | + if ( ! empty( $new_value ) ) { |
|
311 | 311 | $value = $new_value; |
312 | - } else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) { |
|
313 | - $value = implode($atts['sep'], $value); |
|
312 | + } else if ( is_array( $value ) && $atts['type'] != 'file' && ! $atts['return_array'] ) { |
|
313 | + $value = implode( $atts['sep'], $value ); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | if ( $atts['truncate'] && $atts['type'] != 'image' ) { |
317 | - $value = FrmAppHelper::truncate($value, 50); |
|
317 | + $value = FrmAppHelper::truncate( $value, 50 ); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | if ( ! $atts['keepjs'] && ! is_array( $value ) ) { |
321 | 321 | $value = wp_kses_post( $value ); |
322 | 322 | } |
323 | 323 | |
324 | - return apply_filters('frm_display_value', $value, $field, $atts); |
|
324 | + return apply_filters( 'frm_display_value', $value, $field, $atts ); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | public static function set_posted_value( $field, $value, $args ) { |
@@ -329,20 +329,20 @@ discard block |
||
329 | 329 | if ( isset( $args['other'] ) && $args['other'] ) { |
330 | 330 | $value = $args['temp_value']; |
331 | 331 | } |
332 | - if ( empty($args['parent_field_id']) ) { |
|
333 | - $_POST['item_meta'][ $field->id ] = $value; |
|
332 | + if ( empty( $args['parent_field_id'] ) ) { |
|
333 | + $_POST['item_meta'][$field->id] = $value; |
|
334 | 334 | } else { |
335 | - $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
335 | + $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field->id] = $value; |
|
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | 339 | public static function get_posted_value( $field, &$value, $args ) { |
340 | 340 | $field_id = is_object( $field ) ? $field->id : $field; |
341 | 341 | |
342 | - if ( empty($args['parent_field_id']) ) { |
|
343 | - $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
342 | + if ( empty( $args['parent_field_id'] ) ) { |
|
343 | + $value = isset( $_POST['item_meta'][$field_id] ) ? $_POST['item_meta'][$field_id] : ''; |
|
344 | 344 | } else { |
345 | - $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : ''; |
|
345 | + $value = isset( $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field_id] ) ? $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field_id] : ''; |
|
346 | 346 | } |
347 | 347 | } |
348 | 348 | |
@@ -365,12 +365,12 @@ discard block |
||
365 | 365 | self::set_other_repeating_vals( $field, $value, $args ); |
366 | 366 | |
367 | 367 | // Check if there are any posted "Other" values |
368 | - if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { |
|
368 | + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][$field->id] ) ) { |
|
369 | 369 | |
370 | 370 | // Save original value |
371 | 371 | $args['temp_value'] = $value; |
372 | 372 | $args['other'] = true; |
373 | - $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
373 | + $other_vals = stripslashes_deep( $_POST['item_meta']['other'][$field->id] ); |
|
374 | 374 | |
375 | 375 | // Set the validation value now |
376 | 376 | self::set_other_validation_val( $value, $other_vals, $field, $args ); |
@@ -392,12 +392,12 @@ discard block |
||
392 | 392 | } |
393 | 393 | |
394 | 394 | // Check if there are any other posted "other" values for this field |
395 | - if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { |
|
395 | + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']]['other'][$field->id] ) ) { |
|
396 | 396 | // Save original value |
397 | 397 | $args['temp_value'] = $value; |
398 | 398 | $args['other'] = true; |
399 | 399 | |
400 | - $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
400 | + $other_vals = $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']]['other'][$field->id]; |
|
401 | 401 | |
402 | 402 | // Set the validation value now |
403 | 403 | self::set_other_validation_val( $value, $other_vals, $field, $args ); |
@@ -429,27 +429,27 @@ discard block |
||
429 | 429 | } |
430 | 430 | } else { |
431 | 431 | // Radio and dropdowns |
432 | - $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
432 | + $other_key = array_filter( array_keys( $field->options ), 'is_string' ); |
|
433 | 433 | $other_key = reset( $other_key ); |
434 | 434 | |
435 | 435 | // Multi-select dropdown |
436 | 436 | if ( is_array( $value ) ) { |
437 | - $o_key = array_search( $field->options[ $other_key ], $value ); |
|
437 | + $o_key = array_search( $field->options[$other_key], $value ); |
|
438 | 438 | |
439 | 439 | if ( $o_key !== false ) { |
440 | 440 | // Modify the original value so other key will be preserved |
441 | - $value[ $other_key ] = $value[ $o_key ]; |
|
441 | + $value[$other_key] = $value[$o_key]; |
|
442 | 442 | |
443 | 443 | // By default, the array keys will be numeric for multi-select dropdowns |
444 | 444 | // If going backwards and forwards between pages, the array key will match the other key |
445 | 445 | if ( $o_key != $other_key ) { |
446 | - unset( $value[ $o_key ] ); |
|
446 | + unset( $value[$o_key] ); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | $args['temp_value'] = $value; |
450 | - $value[ $other_key ] = reset( $other_vals ); |
|
450 | + $value[$other_key] = reset( $other_vals ); |
|
451 | 451 | } |
452 | - } else if ( $field->options[ $other_key ] == $value ) { |
|
452 | + } else if ( $field->options[$other_key] == $value ) { |
|
453 | 453 | $value = $other_vals; |
454 | 454 | } |
455 | 455 | } |
@@ -468,9 +468,9 @@ discard block |
||
468 | 468 | $content .= "\n\n"; |
469 | 469 | } |
470 | 470 | |
471 | - if ( is_array($val) ) { |
|
471 | + if ( is_array( $val ) ) { |
|
472 | 472 | $val = FrmAppHelper::array_flatten( $val ); |
473 | - $val = implode(',', $val); |
|
473 | + $val = implode( ',', $val ); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | $content .= $val; |
@@ -515,6 +515,6 @@ discard block |
||
515 | 515 | } |
516 | 516 | |
517 | 517 | public static function entries_dropdown() { |
518 | - _deprecated_function( __FUNCTION__, '1.07.09'); |
|
518 | + _deprecated_function( __FUNCTION__, '1.07.09' ); |
|
519 | 519 | } |
520 | 520 | } |
@@ -5,69 +5,69 @@ discard block |
||
5 | 5 | |
6 | 6 | class FrmEntriesHelper { |
7 | 7 | |
8 | - public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
9 | - $values = array(); |
|
8 | + public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
9 | + $values = array(); |
|
10 | 10 | foreach ( array( 'name' => '', 'description' => '', 'item_key' => '' ) as $var => $default ) { |
11 | 11 | $values[ $var ] = FrmAppHelper::get_post_param( $var, $default, 'wp_kses_post' ); |
12 | - } |
|
13 | - |
|
14 | - $values['fields'] = array(); |
|
15 | - if ( empty($fields) ) { |
|
16 | - return apply_filters('frm_setup_new_entry', $values); |
|
17 | - } |
|
18 | - |
|
19 | - foreach ( (array) $fields as $field ) { |
|
20 | - $new_value = self::get_field_value_for_new_entry( $field, $reset, $args ); |
|
21 | - |
|
22 | - $field_array = array( |
|
23 | - 'id' => $field->id, |
|
24 | - 'value' => $new_value, |
|
25 | - 'default_value' => $field->default_value, |
|
26 | - 'name' => $field->name, |
|
27 | - 'description' => $field->description, |
|
28 | - 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
29 | - 'options' => $field->options, |
|
30 | - 'required' => $field->required, |
|
31 | - 'field_key' => $field->field_key, |
|
32 | - 'field_order' => $field->field_order, |
|
33 | - 'form_id' => $field->form_id, |
|
12 | + } |
|
13 | + |
|
14 | + $values['fields'] = array(); |
|
15 | + if ( empty($fields) ) { |
|
16 | + return apply_filters('frm_setup_new_entry', $values); |
|
17 | + } |
|
18 | + |
|
19 | + foreach ( (array) $fields as $field ) { |
|
20 | + $new_value = self::get_field_value_for_new_entry( $field, $reset, $args ); |
|
21 | + |
|
22 | + $field_array = array( |
|
23 | + 'id' => $field->id, |
|
24 | + 'value' => $new_value, |
|
25 | + 'default_value' => $field->default_value, |
|
26 | + 'name' => $field->name, |
|
27 | + 'description' => $field->description, |
|
28 | + 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
29 | + 'options' => $field->options, |
|
30 | + 'required' => $field->required, |
|
31 | + 'field_key' => $field->field_key, |
|
32 | + 'field_order' => $field->field_order, |
|
33 | + 'form_id' => $field->form_id, |
|
34 | 34 | 'parent_form_id' => isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id, |
35 | - 'reset_value' => $reset, |
|
35 | + 'reset_value' => $reset, |
|
36 | 36 | 'in_embed_form' => isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0', |
37 | - ); |
|
37 | + ); |
|
38 | 38 | |
39 | - $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
40 | - $opt_defaults['required_indicator'] = ''; |
|
39 | + $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
40 | + $opt_defaults['required_indicator'] = ''; |
|
41 | 41 | $opt_defaults['original_type'] = $field->type; |
42 | 42 | |
43 | 43 | foreach ( $opt_defaults as $opt => $default_opt ) { |
44 | - $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
45 | - unset($opt, $default_opt); |
|
46 | - } |
|
44 | + $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
45 | + unset($opt, $default_opt); |
|
46 | + } |
|
47 | 47 | |
48 | - unset($opt_defaults); |
|
48 | + unset($opt_defaults); |
|
49 | 49 | |
50 | - if ( $field_array['custom_html'] == '' ) { |
|
51 | - $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
52 | - } |
|
50 | + if ( $field_array['custom_html'] == '' ) { |
|
51 | + $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
52 | + } |
|
53 | 53 | |
54 | - $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
55 | - $field_array = array_merge( $field->field_options, $field_array ); |
|
54 | + $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
55 | + $field_array = array_merge( $field->field_options, $field_array ); |
|
56 | 56 | |
57 | - $values['fields'][] = $field_array; |
|
57 | + $values['fields'][] = $field_array; |
|
58 | 58 | |
59 | - if ( ! $form || ! isset($form->id) ) { |
|
60 | - $form = FrmForm::getOne($field->form_id); |
|
61 | - } |
|
62 | - } |
|
59 | + if ( ! $form || ! isset($form->id) ) { |
|
60 | + $form = FrmForm::getOne($field->form_id); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - $form->options = maybe_unserialize($form->options); |
|
65 | - if ( is_array($form->options) ) { |
|
66 | - foreach ( $form->options as $opt => $value ) { |
|
67 | - $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
68 | - unset($opt, $value); |
|
69 | - } |
|
70 | - } |
|
64 | + $form->options = maybe_unserialize($form->options); |
|
65 | + if ( is_array($form->options) ) { |
|
66 | + foreach ( $form->options as $opt => $value ) { |
|
67 | + $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
68 | + unset($opt, $value); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | 72 | $form_defaults = FrmFormsHelper::get_default_opts(); |
73 | 73 | |
@@ -77,19 +77,19 @@ discard block |
||
77 | 77 | $values = array_merge( $form_defaults, $values ); |
78 | 78 | |
79 | 79 | return apply_filters( 'frm_setup_new_entry', $values ); |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | 82 | /** |
83 | - * Set the value for each field |
|
84 | - * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
85 | - * |
|
86 | - * @since 2.0.13 |
|
87 | - * |
|
88 | - * @param object $field - this is passed by reference since it is an object |
|
89 | - * @param boolean $reset |
|
90 | - * @param array $args |
|
91 | - * @return string|array $new_value |
|
92 | - */ |
|
83 | + * Set the value for each field |
|
84 | + * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
85 | + * |
|
86 | + * @since 2.0.13 |
|
87 | + * |
|
88 | + * @param object $field - this is passed by reference since it is an object |
|
89 | + * @param boolean $reset |
|
90 | + * @param array $args |
|
91 | + * @return string|array $new_value |
|
92 | + */ |
|
93 | 93 | private static function get_field_value_for_new_entry( $field, $reset, $args ) { |
94 | 94 | //If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array |
95 | 95 | $return_array = FrmField::is_field_with_multiple_values( $field ); |
@@ -115,13 +115,13 @@ discard block |
||
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
118 | - * Check if a field has a posted value |
|
119 | - * |
|
120 | - * @since 2.01.0 |
|
121 | - * @param object $field |
|
122 | - * @param array $args |
|
123 | - * @return boolean $value_is_posted |
|
124 | - */ |
|
118 | + * Check if a field has a posted value |
|
119 | + * |
|
120 | + * @since 2.01.0 |
|
121 | + * @param object $field |
|
122 | + * @param array $args |
|
123 | + * @return boolean $value_is_posted |
|
124 | + */ |
|
125 | 125 | public static function value_is_posted( $field, $args ) { |
126 | 126 | $value_is_posted = false; |
127 | 127 | if ( $_POST ) { |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | |
140 | 140 | public static function setup_edit_vars( $values, $record ) { |
141 | 141 | $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' ); |
142 | - $values['form_id'] = $record->form_id; |
|
143 | - $values['is_draft'] = $record->is_draft; |
|
144 | - return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
145 | - } |
|
142 | + $values['form_id'] = $record->form_id; |
|
143 | + $values['is_draft'] = $record->is_draft; |
|
144 | + return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
145 | + } |
|
146 | 146 | |
147 | - public static function get_admin_params( $form = null ) { |
|
147 | + public static function get_admin_params( $form = null ) { |
|
148 | 148 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_admin_params' ); |
149 | 149 | return FrmForm::set_current_form( $form ); |
150 | - } |
|
150 | + } |
|
151 | 151 | |
152 | 152 | public static function set_current_form( $form_id ) { |
153 | 153 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::set_current_form' ); |
@@ -159,284 +159,284 @@ discard block |
||
159 | 159 | return FrmForm::get_current_form( $form_id ); |
160 | 160 | } |
161 | 161 | |
162 | - public static function get_current_form_id() { |
|
162 | + public static function get_current_form_id() { |
|
163 | 163 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_current_form_id' ); |
164 | 164 | return FrmForm::get_current_form_id(); |
165 | - } |
|
165 | + } |
|
166 | 166 | |
167 | - public static function maybe_get_entry( &$entry ) { |
|
167 | + public static function maybe_get_entry( &$entry ) { |
|
168 | 168 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntry::maybe_get_entry' ); |
169 | 169 | FrmEntry::maybe_get_entry( $entry ); |
170 | - } |
|
170 | + } |
|
171 | 171 | |
172 | 172 | public static function replace_default_message( $message, $atts ) { |
173 | - if ( strpos($message, '[default-message') === false && |
|
174 | - strpos($message, '[default_message') === false && |
|
175 | - ! empty( $message ) ) { |
|
176 | - return $message; |
|
177 | - } |
|
178 | - |
|
179 | - if ( empty($message) ) { |
|
180 | - $message = '[default-message]'; |
|
181 | - } |
|
182 | - |
|
183 | - preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
184 | - |
|
185 | - foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
186 | - $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
187 | - if ( $add_atts ) { |
|
188 | - $this_atts = array_merge($atts, $add_atts); |
|
189 | - } else { |
|
190 | - $this_atts = $atts; |
|
191 | - } |
|
173 | + if ( strpos($message, '[default-message') === false && |
|
174 | + strpos($message, '[default_message') === false && |
|
175 | + ! empty( $message ) ) { |
|
176 | + return $message; |
|
177 | + } |
|
178 | + |
|
179 | + if ( empty($message) ) { |
|
180 | + $message = '[default-message]'; |
|
181 | + } |
|
182 | + |
|
183 | + preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
184 | + |
|
185 | + foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
186 | + $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
187 | + if ( $add_atts ) { |
|
188 | + $this_atts = array_merge($atts, $add_atts); |
|
189 | + } else { |
|
190 | + $this_atts = $atts; |
|
191 | + } |
|
192 | 192 | |
193 | 193 | $default = FrmEntryFormat::show_entry( $this_atts ); |
194 | 194 | |
195 | - // Add the default message |
|
196 | - $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
197 | - } |
|
195 | + // Add the default message |
|
196 | + $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
197 | + } |
|
198 | 198 | |
199 | - return $message; |
|
200 | - } |
|
199 | + return $message; |
|
200 | + } |
|
201 | 201 | |
202 | 202 | public static function prepare_display_value( $entry, $field, $atts ) { |
203 | 203 | $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false; |
204 | 204 | |
205 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
205 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
206 | 206 | FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value ); |
207 | - } |
|
207 | + } |
|
208 | 208 | |
209 | - if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
210 | - return self::display_value($field_value, $field, $atts); |
|
211 | - } |
|
209 | + if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
210 | + return self::display_value($field_value, $field, $atts); |
|
211 | + } |
|
212 | 212 | |
213 | - // this is an embeded form |
|
214 | - $val = ''; |
|
213 | + // this is an embeded form |
|
214 | + $val = ''; |
|
215 | 215 | |
216 | - if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
217 | - //this is a repeating section |
|
216 | + if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
217 | + //this is a repeating section |
|
218 | 218 | $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) ); |
219 | - } else { |
|
220 | - // get all values for this field |
|
221 | - $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
219 | + } else { |
|
220 | + // get all values for this field |
|
221 | + $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
222 | 222 | |
223 | - if ( $child_values ) { |
|
224 | - $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
225 | - } |
|
226 | - } |
|
223 | + if ( $child_values ) { |
|
224 | + $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
225 | + } |
|
226 | + } |
|
227 | 227 | |
228 | - $field_value = array(); |
|
228 | + $field_value = array(); |
|
229 | 229 | |
230 | - if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
231 | - return $val; |
|
232 | - } |
|
230 | + if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
231 | + return $val; |
|
232 | + } |
|
233 | 233 | |
234 | - foreach ( $child_entries as $child_entry ) { |
|
235 | - $atts['item_id'] = $child_entry->id; |
|
236 | - $atts['post_id'] = $child_entry->post_id; |
|
234 | + foreach ( $child_entries as $child_entry ) { |
|
235 | + $atts['item_id'] = $child_entry->id; |
|
236 | + $atts['post_id'] = $child_entry->post_id; |
|
237 | 237 | |
238 | - // get the value for this field -- check for post values as well |
|
239 | - $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
238 | + // get the value for this field -- check for post values as well |
|
239 | + $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
240 | 240 | |
241 | - if ( $entry_val ) { |
|
242 | - // foreach entry get display_value |
|
243 | - $field_value[] = self::display_value($entry_val, $field, $atts); |
|
244 | - } |
|
241 | + if ( $entry_val ) { |
|
242 | + // foreach entry get display_value |
|
243 | + $field_value[] = self::display_value($entry_val, $field, $atts); |
|
244 | + } |
|
245 | 245 | |
246 | - unset($child_entry); |
|
247 | - } |
|
246 | + unset($child_entry); |
|
247 | + } |
|
248 | 248 | |
249 | - $val = implode(', ', (array) $field_value ); |
|
249 | + $val = implode(', ', (array) $field_value ); |
|
250 | 250 | $val = wp_kses_post( $val ); |
251 | 251 | |
252 | - return $val; |
|
253 | - } |
|
252 | + return $val; |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * Prepare the saved value for display |
|
257 | - * @return string |
|
258 | - */ |
|
255 | + /** |
|
256 | + * Prepare the saved value for display |
|
257 | + * @return string |
|
258 | + */ |
|
259 | 259 | public static function display_value( $value, $field, $atts = array() ) { |
260 | 260 | |
261 | - $defaults = array( |
|
262 | - 'type' => '', 'html' => false, 'show_filename' => true, |
|
263 | - 'truncate' => false, 'sep' => ', ', 'post_id' => 0, |
|
264 | - 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0, |
|
261 | + $defaults = array( |
|
262 | + 'type' => '', 'html' => false, 'show_filename' => true, |
|
263 | + 'truncate' => false, 'sep' => ', ', 'post_id' => 0, |
|
264 | + 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0, |
|
265 | 265 | 'return_array' => false, |
266 | - ); |
|
266 | + ); |
|
267 | 267 | |
268 | - $atts = wp_parse_args( $atts, $defaults ); |
|
269 | - $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
268 | + $atts = wp_parse_args( $atts, $defaults ); |
|
269 | + $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
270 | 270 | |
271 | - if ( ! isset($field->field_options['post_field']) ) { |
|
272 | - $field->field_options['post_field'] = ''; |
|
273 | - } |
|
271 | + if ( ! isset($field->field_options['post_field']) ) { |
|
272 | + $field->field_options['post_field'] = ''; |
|
273 | + } |
|
274 | 274 | |
275 | - if ( ! isset($field->field_options['custom_field']) ) { |
|
276 | - $field->field_options['custom_field'] = ''; |
|
277 | - } |
|
275 | + if ( ! isset($field->field_options['custom_field']) ) { |
|
276 | + $field->field_options['custom_field'] = ''; |
|
277 | + } |
|
278 | 278 | |
279 | - if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
280 | - $atts['pre_truncate'] = $atts['truncate']; |
|
281 | - $atts['truncate'] = true; |
|
282 | - $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
279 | + if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
280 | + $atts['pre_truncate'] = $atts['truncate']; |
|
281 | + $atts['truncate'] = true; |
|
282 | + $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
283 | 283 | |
284 | - $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
285 | - $atts['truncate'] = $atts['pre_truncate']; |
|
286 | - } |
|
284 | + $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
285 | + $atts['truncate'] = $atts['pre_truncate']; |
|
286 | + } |
|
287 | 287 | |
288 | - if ( $value == '' ) { |
|
289 | - return $value; |
|
290 | - } |
|
288 | + if ( $value == '' ) { |
|
289 | + return $value; |
|
290 | + } |
|
291 | 291 | |
292 | - $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts); |
|
292 | + $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts); |
|
293 | 293 | $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) ); |
294 | 294 | |
295 | - $new_value = ''; |
|
295 | + $new_value = ''; |
|
296 | 296 | |
297 | - if ( is_array($value) && $atts['type'] != 'file' ) { |
|
298 | - foreach ( $value as $val ) { |
|
299 | - if ( is_array($val) ) { |
|
297 | + if ( is_array($value) && $atts['type'] != 'file' ) { |
|
298 | + foreach ( $value as $val ) { |
|
299 | + if ( is_array($val) ) { |
|
300 | 300 | //TODO: add options for display (li or ,) |
301 | - $new_value .= implode($atts['sep'], $val); |
|
302 | - if ( $atts['type'] != 'data' ) { |
|
303 | - $new_value .= '<br/>'; |
|
304 | - } |
|
305 | - } |
|
306 | - unset($val); |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - if ( ! empty($new_value) ) { |
|
311 | - $value = $new_value; |
|
312 | - } else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) { |
|
313 | - $value = implode($atts['sep'], $value); |
|
314 | - } |
|
315 | - |
|
316 | - if ( $atts['truncate'] && $atts['type'] != 'image' ) { |
|
317 | - $value = FrmAppHelper::truncate($value, 50); |
|
318 | - } |
|
301 | + $new_value .= implode($atts['sep'], $val); |
|
302 | + if ( $atts['type'] != 'data' ) { |
|
303 | + $new_value .= '<br/>'; |
|
304 | + } |
|
305 | + } |
|
306 | + unset($val); |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + if ( ! empty($new_value) ) { |
|
311 | + $value = $new_value; |
|
312 | + } else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) { |
|
313 | + $value = implode($atts['sep'], $value); |
|
314 | + } |
|
315 | + |
|
316 | + if ( $atts['truncate'] && $atts['type'] != 'image' ) { |
|
317 | + $value = FrmAppHelper::truncate($value, 50); |
|
318 | + } |
|
319 | 319 | |
320 | 320 | if ( ! $atts['keepjs'] && ! is_array( $value ) ) { |
321 | 321 | $value = wp_kses_post( $value ); |
322 | 322 | } |
323 | 323 | |
324 | - return apply_filters('frm_display_value', $value, $field, $atts); |
|
325 | - } |
|
324 | + return apply_filters('frm_display_value', $value, $field, $atts); |
|
325 | + } |
|
326 | 326 | |
327 | 327 | public static function set_posted_value( $field, $value, $args ) { |
328 | - // If validating a field with "other" opt, set back to prev value now |
|
329 | - if ( isset( $args['other'] ) && $args['other'] ) { |
|
330 | - $value = $args['temp_value']; |
|
331 | - } |
|
332 | - if ( empty($args['parent_field_id']) ) { |
|
333 | - $_POST['item_meta'][ $field->id ] = $value; |
|
334 | - } else { |
|
335 | - $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
336 | - } |
|
337 | - } |
|
328 | + // If validating a field with "other" opt, set back to prev value now |
|
329 | + if ( isset( $args['other'] ) && $args['other'] ) { |
|
330 | + $value = $args['temp_value']; |
|
331 | + } |
|
332 | + if ( empty($args['parent_field_id']) ) { |
|
333 | + $_POST['item_meta'][ $field->id ] = $value; |
|
334 | + } else { |
|
335 | + $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
336 | + } |
|
337 | + } |
|
338 | 338 | |
339 | 339 | public static function get_posted_value( $field, &$value, $args ) { |
340 | 340 | $field_id = is_object( $field ) ? $field->id : $field; |
341 | 341 | |
342 | - if ( empty($args['parent_field_id']) ) { |
|
343 | - $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
344 | - } else { |
|
345 | - $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : ''; |
|
346 | - } |
|
342 | + if ( empty($args['parent_field_id']) ) { |
|
343 | + $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
344 | + } else { |
|
345 | + $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : ''; |
|
346 | + } |
|
347 | 347 | FrmAppHelper::sanitize_value( 'wp_kses_post', $value ); |
348 | 348 | $value = stripslashes_deep( $value ); |
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Check if field has an "Other" option and if any other values are posted |
|
353 | - * |
|
354 | - * @since 2.0 |
|
355 | - * |
|
356 | - * @param object $field |
|
357 | - * @param string|array $value |
|
358 | - * @param array $args |
|
359 | - */ |
|
360 | - public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
361 | - $args['other'] = false; |
|
362 | - if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
363 | - return; |
|
364 | - } |
|
365 | - |
|
366 | - // Get other value for fields in repeating section |
|
367 | - self::set_other_repeating_vals( $field, $value, $args ); |
|
368 | - |
|
369 | - // Check if there are any posted "Other" values |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Check if field has an "Other" option and if any other values are posted |
|
353 | + * |
|
354 | + * @since 2.0 |
|
355 | + * |
|
356 | + * @param object $field |
|
357 | + * @param string|array $value |
|
358 | + * @param array $args |
|
359 | + */ |
|
360 | + public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
361 | + $args['other'] = false; |
|
362 | + if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
363 | + return; |
|
364 | + } |
|
365 | + |
|
366 | + // Get other value for fields in repeating section |
|
367 | + self::set_other_repeating_vals( $field, $value, $args ); |
|
368 | + |
|
369 | + // Check if there are any posted "Other" values |
|
370 | 370 | if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { |
371 | 371 | |
372 | - // Save original value |
|
373 | - $args['temp_value'] = $value; |
|
374 | - $args['other'] = true; |
|
375 | - $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
376 | - |
|
377 | - // Set the validation value now |
|
378 | - self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
379 | - } |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
384 | - * |
|
385 | - * @since 2.0 |
|
386 | - * |
|
387 | - * @param object $field |
|
388 | - * @param string|array $value |
|
389 | - * @param array $args |
|
390 | - */ |
|
391 | - public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
392 | - if ( ! $args['parent_field_id'] ) { |
|
393 | - return; |
|
394 | - } |
|
395 | - |
|
396 | - // Check if there are any other posted "other" values for this field |
|
372 | + // Save original value |
|
373 | + $args['temp_value'] = $value; |
|
374 | + $args['other'] = true; |
|
375 | + $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
376 | + |
|
377 | + // Set the validation value now |
|
378 | + self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
379 | + } |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
384 | + * |
|
385 | + * @since 2.0 |
|
386 | + * |
|
387 | + * @param object $field |
|
388 | + * @param string|array $value |
|
389 | + * @param array $args |
|
390 | + */ |
|
391 | + public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
392 | + if ( ! $args['parent_field_id'] ) { |
|
393 | + return; |
|
394 | + } |
|
395 | + |
|
396 | + // Check if there are any other posted "other" values for this field |
|
397 | 397 | if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { |
398 | - // Save original value |
|
399 | - $args['temp_value'] = $value; |
|
400 | - $args['other'] = true; |
|
401 | - |
|
402 | - $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
403 | - |
|
404 | - // Set the validation value now |
|
405 | - self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
406 | - } |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Modify value used for validation |
|
411 | - * This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
412 | - * It also adds any text from the free text fields to the value |
|
413 | - * |
|
414 | - * Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
415 | - * |
|
416 | - * @since 2.0 |
|
417 | - * |
|
418 | - * @param string|array $value |
|
419 | - * @param string|array $other_vals (usually of posted values) |
|
420 | - * @param object $field |
|
421 | - * @param array $args |
|
422 | - */ |
|
423 | - public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
424 | - // Checkboxes and multi-select dropdowns |
|
425 | - if ( is_array( $value ) && $field->type == 'checkbox' ) { |
|
426 | - // Combine "Other" values with checked values. "Other" values will override checked box values. |
|
427 | - $value = array_merge( $value, $other_vals ); |
|
428 | - $value = array_filter( $value ); |
|
429 | - if ( count( $value ) == 0 ) { |
|
430 | - $value = ''; |
|
431 | - } |
|
432 | - } else { |
|
398 | + // Save original value |
|
399 | + $args['temp_value'] = $value; |
|
400 | + $args['other'] = true; |
|
401 | + |
|
402 | + $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
403 | + |
|
404 | + // Set the validation value now |
|
405 | + self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
406 | + } |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Modify value used for validation |
|
411 | + * This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
412 | + * It also adds any text from the free text fields to the value |
|
413 | + * |
|
414 | + * Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
415 | + * |
|
416 | + * @since 2.0 |
|
417 | + * |
|
418 | + * @param string|array $value |
|
419 | + * @param string|array $other_vals (usually of posted values) |
|
420 | + * @param object $field |
|
421 | + * @param array $args |
|
422 | + */ |
|
423 | + public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
424 | + // Checkboxes and multi-select dropdowns |
|
425 | + if ( is_array( $value ) && $field->type == 'checkbox' ) { |
|
426 | + // Combine "Other" values with checked values. "Other" values will override checked box values. |
|
427 | + $value = array_merge( $value, $other_vals ); |
|
428 | + $value = array_filter( $value ); |
|
429 | + if ( count( $value ) == 0 ) { |
|
430 | + $value = ''; |
|
431 | + } |
|
432 | + } else { |
|
433 | 433 | // Radio and dropdowns |
434 | - $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
435 | - $other_key = reset( $other_key ); |
|
434 | + $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
435 | + $other_key = reset( $other_key ); |
|
436 | 436 | |
437 | - // Multi-select dropdown |
|
438 | - if ( is_array( $value ) ) { |
|
439 | - $o_key = array_search( $field->options[ $other_key ], $value ); |
|
437 | + // Multi-select dropdown |
|
438 | + if ( is_array( $value ) ) { |
|
439 | + $o_key = array_search( $field->options[ $other_key ], $value ); |
|
440 | 440 | |
441 | 441 | if ( $o_key !== false ) { |
442 | 442 | // Modify the original value so other key will be preserved |
@@ -451,20 +451,20 @@ discard block |
||
451 | 451 | $args['temp_value'] = $value; |
452 | 452 | $value[ $other_key ] = reset( $other_vals ); |
453 | 453 | } |
454 | - } else if ( $field->options[ $other_key ] == $value ) { |
|
455 | - $value = $other_vals; |
|
456 | - } |
|
457 | - } |
|
458 | - } |
|
454 | + } else if ( $field->options[ $other_key ] == $value ) { |
|
455 | + $value = $other_vals; |
|
456 | + } |
|
457 | + } |
|
458 | + } |
|
459 | 459 | |
460 | 460 | public static function enqueue_scripts( $params ) { |
461 | 461 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmFormsController::enqueue_scripts' ); |
462 | 462 | FrmFormsController::enqueue_scripts( $params ); |
463 | 463 | } |
464 | 464 | |
465 | - // Add submitted values to a string for spam checking |
|
465 | + // Add submitted values to a string for spam checking |
|
466 | 466 | public static function entry_array_to_string( $values ) { |
467 | - $content = ''; |
|
467 | + $content = ''; |
|
468 | 468 | foreach ( $values['item_meta'] as $val ) { |
469 | 469 | if ( $content != '' ) { |
470 | 470 | $content .= "\n\n"; |
@@ -472,14 +472,14 @@ discard block |
||
472 | 472 | |
473 | 473 | if ( is_array($val) ) { |
474 | 474 | $val = FrmAppHelper::array_flatten( $val ); |
475 | - $val = implode(',', $val); |
|
475 | + $val = implode(',', $val); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | $content .= $val; |
479 | 479 | } |
480 | 480 | |
481 | 481 | return $content; |
482 | - } |
|
482 | + } |
|
483 | 483 | |
484 | 484 | public static function fill_entry_values( $atts, $f, array &$values ) { |
485 | 485 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryFormat::fill_entry_values' ); |
@@ -6,11 +6,11 @@ discard block |
||
6 | 6 | class FrmEntry { |
7 | 7 | |
8 | 8 | /** |
9 | - * Create a new entry |
|
10 | - * |
|
11 | - * @param array $values |
|
12 | - * @return int | boolean $entry_id |
|
13 | - */ |
|
9 | + * Create a new entry |
|
10 | + * |
|
11 | + * @param array $values |
|
12 | + * @return int | boolean $entry_id |
|
13 | + */ |
|
14 | 14 | public static function create( $values ) { |
15 | 15 | $entry_id = self::create_entry( $values, 'standard' ); |
16 | 16 | |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | - * Create a new entry with some differences depending on type |
|
22 | - * |
|
23 | - * @param array $values |
|
24 | - * @param string $type |
|
25 | - * @return int | boolean $entry_id |
|
26 | - */ |
|
21 | + * Create a new entry with some differences depending on type |
|
22 | + * |
|
23 | + * @param array $values |
|
24 | + * @param string $type |
|
25 | + * @return int | boolean $entry_id |
|
26 | + */ |
|
27 | 27 | private static function create_entry( $values, $type ) { |
28 | 28 | $new_values = self::before_insert_entry_in_database( $values, $type ); |
29 | 29 | |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | return $entry_id; |
38 | 38 | } |
39 | 39 | |
40 | - /** |
|
41 | - * check for duplicate entries created in the last minute |
|
42 | - * @return boolean |
|
43 | - */ |
|
40 | + /** |
|
41 | + * check for duplicate entries created in the last minute |
|
42 | + * @return boolean |
|
43 | + */ |
|
44 | 44 | public static function is_duplicate( $new_values, $values ) { |
45 | 45 | $duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values ); |
46 | 46 | |
@@ -48,55 +48,55 @@ discard block |
||
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
51 | - $check_val = $new_values; |
|
51 | + $check_val = $new_values; |
|
52 | 52 | $check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) ); |
53 | 53 | |
54 | 54 | unset( $check_val['created_at'], $check_val['updated_at'] ); |
55 | 55 | unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] ); |
56 | 56 | |
57 | - if ( $new_values['item_key'] == $new_values['name'] ) { |
|
58 | - unset($check_val['name']); |
|
59 | - } |
|
57 | + if ( $new_values['item_key'] == $new_values['name'] ) { |
|
58 | + unset($check_val['name']); |
|
59 | + } |
|
60 | 60 | |
61 | - global $wpdb; |
|
61 | + global $wpdb; |
|
62 | 62 | $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) ); |
63 | 63 | |
64 | - if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) { |
|
65 | - return false; |
|
66 | - } |
|
64 | + if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) { |
|
65 | + return false; |
|
66 | + } |
|
67 | 67 | |
68 | - $is_duplicate = false; |
|
69 | - foreach ( $entry_exists as $entry_exist ) { |
|
70 | - $is_duplicate = true; |
|
68 | + $is_duplicate = false; |
|
69 | + foreach ( $entry_exists as $entry_exist ) { |
|
70 | + $is_duplicate = true; |
|
71 | 71 | |
72 | - //add more checks here to make sure it's a duplicate |
|
73 | - $metas = FrmEntryMeta::get_entry_meta_info($entry_exist); |
|
74 | - $field_metas = array(); |
|
75 | - foreach ( $metas as $meta ) { |
|
72 | + //add more checks here to make sure it's a duplicate |
|
73 | + $metas = FrmEntryMeta::get_entry_meta_info($entry_exist); |
|
74 | + $field_metas = array(); |
|
75 | + foreach ( $metas as $meta ) { |
|
76 | 76 | $field_metas[ $meta->field_id ] = $meta->meta_value; |
77 | - } |
|
78 | - |
|
79 | - // If prev entry is empty and current entry is not, they are not duplicates |
|
80 | - $filtered_vals = array_filter( $values['item_meta'] ); |
|
81 | - if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
82 | - return false; |
|
83 | - } |
|
84 | - |
|
85 | - $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta'])); |
|
86 | - foreach ( $diff as $field_id => $meta_value ) { |
|
87 | - if ( ! empty($meta_value) ) { |
|
88 | - $is_duplicate = false; |
|
89 | - continue; |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - if ( $is_duplicate ) { |
|
77 | + } |
|
78 | + |
|
79 | + // If prev entry is empty and current entry is not, they are not duplicates |
|
80 | + $filtered_vals = array_filter( $values['item_meta'] ); |
|
81 | + if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
82 | + return false; |
|
83 | + } |
|
84 | + |
|
85 | + $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta'])); |
|
86 | + foreach ( $diff as $field_id => $meta_value ) { |
|
87 | + if ( ! empty($meta_value) ) { |
|
88 | + $is_duplicate = false; |
|
89 | + continue; |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + if ( $is_duplicate ) { |
|
94 | 94 | break; |
95 | - } |
|
96 | - } |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | - return $is_duplicate; |
|
99 | - } |
|
98 | + return $is_duplicate; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Determine if an entry needs to be checked as a possible duplicate |
@@ -125,46 +125,46 @@ discard block |
||
125 | 125 | return true; |
126 | 126 | } |
127 | 127 | |
128 | - public static function duplicate( $id ) { |
|
129 | - global $wpdb; |
|
128 | + public static function duplicate( $id ) { |
|
129 | + global $wpdb; |
|
130 | 130 | |
131 | - $values = self::getOne( $id ); |
|
131 | + $values = self::getOne( $id ); |
|
132 | 132 | |
133 | - $new_values = array(); |
|
133 | + $new_values = array(); |
|
134 | 134 | $new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
135 | - $new_values['name'] = $values->name; |
|
136 | - $new_values['is_draft'] = $values->is_draft; |
|
137 | - $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id; |
|
138 | - $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null; |
|
139 | - $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1); |
|
135 | + $new_values['name'] = $values->name; |
|
136 | + $new_values['is_draft'] = $values->is_draft; |
|
137 | + $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id; |
|
138 | + $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null; |
|
139 | + $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1); |
|
140 | 140 | |
141 | 141 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values ); |
142 | - if ( ! $query_results ) { |
|
143 | - return false; |
|
144 | - } |
|
142 | + if ( ! $query_results ) { |
|
143 | + return false; |
|
144 | + } |
|
145 | 145 | |
146 | - $entry_id = $wpdb->insert_id; |
|
146 | + $entry_id = $wpdb->insert_id; |
|
147 | 147 | |
148 | - global $frm_vars; |
|
149 | - if ( ! isset($frm_vars['saved_entries']) ) { |
|
150 | - $frm_vars['saved_entries'] = array(); |
|
151 | - } |
|
152 | - $frm_vars['saved_entries'][] = (int) $entry_id; |
|
148 | + global $frm_vars; |
|
149 | + if ( ! isset($frm_vars['saved_entries']) ) { |
|
150 | + $frm_vars['saved_entries'] = array(); |
|
151 | + } |
|
152 | + $frm_vars['saved_entries'][] = (int) $entry_id; |
|
153 | 153 | |
154 | - FrmEntryMeta::duplicate_entry_metas($id, $entry_id); |
|
154 | + FrmEntryMeta::duplicate_entry_metas($id, $entry_id); |
|
155 | 155 | self::clear_cache(); |
156 | 156 | |
157 | 157 | do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) ); |
158 | - return $entry_id; |
|
159 | - } |
|
158 | + return $entry_id; |
|
159 | + } |
|
160 | 160 | |
161 | 161 | /** |
162 | - * Update an entry (not via XML) |
|
163 | - * |
|
164 | - * @param int $id |
|
165 | - * @param array $values |
|
166 | - * @return boolean|int $update_results |
|
167 | - */ |
|
162 | + * Update an entry (not via XML) |
|
163 | + * |
|
164 | + * @param int $id |
|
165 | + * @param array $values |
|
166 | + * @return boolean|int $update_results |
|
167 | + */ |
|
168 | 168 | public static function update( $id, $values ) { |
169 | 169 | $update_results = self::update_entry( $id, $values, 'standard' ); |
170 | 170 | |
@@ -172,14 +172,14 @@ discard block |
||
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
175 | - * Update an entry with some differences depending on the update type |
|
176 | - * |
|
177 | - * @since 2.0.16 |
|
178 | - * |
|
179 | - * @param int $id |
|
180 | - * @param array $values |
|
181 | - * @return boolean|int $query_results |
|
182 | - */ |
|
175 | + * Update an entry with some differences depending on the update type |
|
176 | + * |
|
177 | + * @since 2.0.16 |
|
178 | + * |
|
179 | + * @param int $id |
|
180 | + * @param array $values |
|
181 | + * @return boolean|int $query_results |
|
182 | + */ |
|
183 | 183 | private static function update_entry( $id, $values, $update_type ) { |
184 | 184 | global $wpdb; |
185 | 185 | |
@@ -198,34 +198,34 @@ discard block |
||
198 | 198 | } |
199 | 199 | |
200 | 200 | public static function &destroy( $id ) { |
201 | - global $wpdb; |
|
202 | - $id = (int) $id; |
|
201 | + global $wpdb; |
|
202 | + $id = (int) $id; |
|
203 | 203 | |
204 | 204 | $entry = self::getOne( $id ); |
205 | - if ( ! $entry ) { |
|
206 | - $result = false; |
|
207 | - return $result; |
|
208 | - } |
|
205 | + if ( ! $entry ) { |
|
206 | + $result = false; |
|
207 | + return $result; |
|
208 | + } |
|
209 | 209 | |
210 | - do_action('frm_before_destroy_entry', $id, $entry); |
|
210 | + do_action('frm_before_destroy_entry', $id, $entry); |
|
211 | 211 | |
212 | 212 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) ); |
213 | 213 | $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) ); |
214 | 214 | |
215 | 215 | self::clear_cache(); |
216 | 216 | |
217 | - return $result; |
|
218 | - } |
|
217 | + return $result; |
|
218 | + } |
|
219 | 219 | |
220 | 220 | public static function &update_form( $id, $value, $form_id ) { |
221 | - global $wpdb; |
|
222 | - $form_id = isset($value) ? $form_id : null; |
|
221 | + global $wpdb; |
|
222 | + $form_id = isset($value) ? $form_id : null; |
|
223 | 223 | $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) ); |
224 | 224 | if ( $result ) { |
225 | 225 | self::clear_cache(); |
226 | 226 | } |
227 | - return $result; |
|
228 | - } |
|
227 | + return $result; |
|
228 | + } |
|
229 | 229 | |
230 | 230 | /** |
231 | 231 | * Clear entry caching |
@@ -261,161 +261,161 @@ discard block |
||
261 | 261 | } |
262 | 262 | |
263 | 263 | public static function getOne( $id, $meta = false ) { |
264 | - global $wpdb; |
|
264 | + global $wpdb; |
|
265 | 265 | |
266 | - $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
266 | + $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
267 | 267 | LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE "; |
268 | 268 | |
269 | - $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s'; |
|
270 | - $query_args = array( $id ); |
|
271 | - $query = $wpdb->prepare( $query, $query_args ); |
|
269 | + $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s'; |
|
270 | + $query_args = array( $id ); |
|
271 | + $query = $wpdb->prepare( $query, $query_args ); |
|
272 | 272 | |
273 | - if ( ! $meta ) { |
|
273 | + if ( ! $meta ) { |
|
274 | 274 | $entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' ); |
275 | - return stripslashes_deep($entry); |
|
276 | - } |
|
275 | + return stripslashes_deep($entry); |
|
276 | + } |
|
277 | 277 | |
278 | - $entry = FrmAppHelper::check_cache( $id, 'frm_entry' ); |
|
279 | - if ( $entry !== false ) { |
|
280 | - return stripslashes_deep($entry); |
|
281 | - } |
|
278 | + $entry = FrmAppHelper::check_cache( $id, 'frm_entry' ); |
|
279 | + if ( $entry !== false ) { |
|
280 | + return stripslashes_deep($entry); |
|
281 | + } |
|
282 | 282 | |
283 | - $entry = $wpdb->get_row( $query ); |
|
284 | - $entry = self::get_meta($entry); |
|
283 | + $entry = $wpdb->get_row( $query ); |
|
284 | + $entry = self::get_meta($entry); |
|
285 | 285 | |
286 | - return stripslashes_deep($entry); |
|
287 | - } |
|
286 | + return stripslashes_deep($entry); |
|
287 | + } |
|
288 | 288 | |
289 | 289 | public static function get_meta( $entry ) { |
290 | - if ( ! $entry ) { |
|
291 | - return $entry; |
|
292 | - } |
|
290 | + if ( ! $entry ) { |
|
291 | + return $entry; |
|
292 | + } |
|
293 | 293 | |
294 | - global $wpdb; |
|
294 | + global $wpdb; |
|
295 | 295 | $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id', array( 'item_id' => $entry->id, 'field_id !' => 0 ), 'field_id, meta_value, field_key, item_id' ); |
296 | 296 | |
297 | - $entry->metas = array(); |
|
297 | + $entry->metas = array(); |
|
298 | 298 | |
299 | 299 | $include_key = apply_filters( 'frm_include_meta_keys', false ); |
300 | - foreach ( $metas as $meta_val ) { |
|
301 | - if ( $meta_val->item_id == $entry->id ) { |
|
300 | + foreach ( $metas as $meta_val ) { |
|
301 | + if ( $meta_val->item_id == $entry->id ) { |
|
302 | 302 | $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
303 | 303 | if ( $include_key ) { |
304 | 304 | $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
305 | 305 | } |
306 | - continue; |
|
307 | - } |
|
306 | + continue; |
|
307 | + } |
|
308 | 308 | |
309 | - // include sub entries in an array |
|
309 | + // include sub entries in an array |
|
310 | 310 | if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) { |
311 | 311 | $entry->metas[ $meta_val->field_id ] = array(); |
312 | - } |
|
312 | + } |
|
313 | 313 | |
314 | 314 | $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value ); |
315 | 315 | |
316 | - unset($meta_val); |
|
317 | - } |
|
318 | - unset($metas); |
|
316 | + unset($meta_val); |
|
317 | + } |
|
318 | + unset($metas); |
|
319 | 319 | |
320 | - wp_cache_set( $entry->id, $entry, 'frm_entry'); |
|
320 | + wp_cache_set( $entry->id, $entry, 'frm_entry'); |
|
321 | 321 | |
322 | - return $entry; |
|
323 | - } |
|
322 | + return $entry; |
|
323 | + } |
|
324 | 324 | |
325 | - /** |
|
326 | - * @param string $id |
|
327 | - */ |
|
325 | + /** |
|
326 | + * @param string $id |
|
327 | + */ |
|
328 | 328 | public static function &exists( $id ) { |
329 | - global $wpdb; |
|
330 | - |
|
331 | - if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) { |
|
332 | - $exists = true; |
|
333 | - return $exists; |
|
334 | - } |
|
335 | - |
|
336 | - if ( is_numeric($id) ) { |
|
337 | - $where = array( 'id' => $id ); |
|
338 | - } else { |
|
339 | - $where = array( 'item_key' => $id ); |
|
340 | - } |
|
329 | + global $wpdb; |
|
330 | + |
|
331 | + if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) { |
|
332 | + $exists = true; |
|
333 | + return $exists; |
|
334 | + } |
|
335 | + |
|
336 | + if ( is_numeric($id) ) { |
|
337 | + $where = array( 'id' => $id ); |
|
338 | + } else { |
|
339 | + $where = array( 'item_key' => $id ); |
|
340 | + } |
|
341 | 341 | $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where ); |
342 | 342 | |
343 | - $exists = ($id && $id > 0) ? true : false; |
|
344 | - return $exists; |
|
345 | - } |
|
343 | + $exists = ($id && $id > 0) ? true : false; |
|
344 | + return $exists; |
|
345 | + } |
|
346 | 346 | |
347 | - public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
347 | + public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
348 | 348 | global $wpdb; |
349 | 349 | |
350 | - $limit = FrmAppHelper::esc_limit($limit); |
|
350 | + $limit = FrmAppHelper::esc_limit($limit); |
|
351 | 351 | |
352 | - $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form; |
|
353 | - $entries = wp_cache_get($cache_key, 'frm_entry'); |
|
352 | + $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form; |
|
353 | + $entries = wp_cache_get($cache_key, 'frm_entry'); |
|
354 | 354 | |
355 | - if ( false === $entries ) { |
|
356 | - $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
355 | + if ( false === $entries ) { |
|
356 | + $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
357 | 357 | $table = $wpdb->prefix . 'frm_items it '; |
358 | 358 | |
359 | - if ( $inc_form ) { |
|
360 | - $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
361 | - $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
362 | - } |
|
359 | + if ( $inc_form ) { |
|
360 | + $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
361 | + $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
362 | + } |
|
363 | 363 | |
364 | - if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
365 | - // sort by a requested field |
|
366 | - $field_id = (int) $order_matches[1]; |
|
364 | + if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
365 | + // sort by a requested field |
|
366 | + $field_id = (int) $order_matches[1]; |
|
367 | 367 | $fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id; |
368 | 368 | unset( $order_matches, $field_id ); |
369 | - } |
|
369 | + } |
|
370 | 370 | |
371 | 371 | // prepare the query |
372 | 372 | $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
373 | 373 | |
374 | - $entries = $wpdb->get_results($query, OBJECT_K); |
|
375 | - unset($query); |
|
374 | + $entries = $wpdb->get_results($query, OBJECT_K); |
|
375 | + unset($query); |
|
376 | 376 | |
377 | 377 | if ( ! FrmAppHelper::prevent_caching() ) { |
378 | 378 | wp_cache_set( $cache_key, $entries, 'frm_entry', 300 ); |
379 | 379 | } |
380 | - } |
|
380 | + } |
|
381 | 381 | |
382 | - if ( ! $meta || ! $entries ) { |
|
383 | - return stripslashes_deep($entries); |
|
384 | - } |
|
385 | - unset($meta); |
|
382 | + if ( ! $meta || ! $entries ) { |
|
383 | + return stripslashes_deep($entries); |
|
384 | + } |
|
385 | + unset($meta); |
|
386 | 386 | |
387 | - if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) { |
|
387 | + if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) { |
|
388 | 388 | $where = array( 'it.form_id' => substr( $where, 11 ) ); |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | - $meta_where = array( 'field_id !' => 0 ); |
|
392 | - if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) { |
|
393 | - $meta_where['fi.form_id'] = $where['it.form_id']; |
|
394 | - } else { |
|
395 | - $meta_where['item_id'] = array_keys( $entries ); |
|
396 | - } |
|
391 | + $meta_where = array( 'field_id !' => 0 ); |
|
392 | + if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) { |
|
393 | + $meta_where['fi.form_id'] = $where['it.form_id']; |
|
394 | + } else { |
|
395 | + $meta_where['item_id'] = array_keys( $entries ); |
|
396 | + } |
|
397 | 397 | |
398 | - $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
398 | + $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
399 | 399 | |
400 | - unset( $meta_where ); |
|
400 | + unset( $meta_where ); |
|
401 | 401 | |
402 | - if ( ! $metas ) { |
|
403 | - return stripslashes_deep($entries); |
|
404 | - } |
|
402 | + if ( ! $metas ) { |
|
403 | + return stripslashes_deep($entries); |
|
404 | + } |
|
405 | 405 | |
406 | - foreach ( $metas as $m_key => $meta_val ) { |
|
407 | - if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
408 | - continue; |
|
409 | - } |
|
406 | + foreach ( $metas as $m_key => $meta_val ) { |
|
407 | + if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
408 | + continue; |
|
409 | + } |
|
410 | 410 | |
411 | - if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
411 | + if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
412 | 412 | $entries[ $meta_val->item_id ]->metas = array(); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | 415 | $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
416 | 416 | |
417 | - unset($m_key, $meta_val); |
|
418 | - } |
|
417 | + unset($m_key, $meta_val); |
|
418 | + } |
|
419 | 419 | |
420 | 420 | if ( ! FrmAppHelper::prevent_caching() ) { |
421 | 421 | foreach ( $entries as $entry ) { |
@@ -424,31 +424,31 @@ discard block |
||
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - return stripslashes_deep($entries); |
|
428 | - } |
|
427 | + return stripslashes_deep($entries); |
|
428 | + } |
|
429 | 429 | |
430 | - // Pagination Methods |
|
431 | - public static function getRecordCount( $where = '' ) { |
|
432 | - global $wpdb; |
|
430 | + // Pagination Methods |
|
431 | + public static function getRecordCount( $where = '' ) { |
|
432 | + global $wpdb; |
|
433 | 433 | $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; |
434 | 434 | |
435 | - if ( is_numeric($where) ) { |
|
436 | - $table_join = 'frm_items'; |
|
437 | - $where = array( 'form_id' => $where ); |
|
438 | - } |
|
435 | + if ( is_numeric($where) ) { |
|
436 | + $table_join = 'frm_items'; |
|
437 | + $where = array( 'form_id' => $where ); |
|
438 | + } |
|
439 | 439 | |
440 | - if ( is_array( $where ) ) { |
|
441 | - $count = FrmDb::get_count( $table_join, $where ); |
|
442 | - } else { |
|
440 | + if ( is_array( $where ) ) { |
|
441 | + $count = FrmDb::get_count( $table_join, $where ); |
|
442 | + } else { |
|
443 | 443 | $cache_key = 'count_' . maybe_serialize( $where ); |
444 | 444 | $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ); |
445 | 445 | $count = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, 'get_var' ); |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - return $count; |
|
449 | - } |
|
448 | + return $count; |
|
449 | + } |
|
450 | 450 | |
451 | - public static function getPageCount( $p_size, $where = '' ) { |
|
451 | + public static function getPageCount( $p_size, $where = '' ) { |
|
452 | 452 | $p_size = (int) $p_size; |
453 | 453 | $count = 1; |
454 | 454 | if ( $p_size ) { |
@@ -459,16 +459,16 @@ discard block |
||
459 | 459 | } |
460 | 460 | |
461 | 461 | return $count; |
462 | - } |
|
462 | + } |
|
463 | 463 | |
464 | 464 | /** |
465 | - * Prepare the data before inserting it into the database |
|
466 | - * |
|
467 | - * @since 2.0.16 |
|
468 | - * @param array $values |
|
469 | - * @param string $type |
|
470 | - * @return array $new_values |
|
471 | - */ |
|
465 | + * Prepare the data before inserting it into the database |
|
466 | + * |
|
467 | + * @since 2.0.16 |
|
468 | + * @param array $values |
|
469 | + * @param string $type |
|
470 | + * @return array $new_values |
|
471 | + */ |
|
472 | 472 | private static function before_insert_entry_in_database( &$values, $type ) { |
473 | 473 | |
474 | 474 | self::sanitize_entry_post( $values ); |
@@ -483,13 +483,13 @@ discard block |
||
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
486 | - * Create an entry and perform after create actions |
|
487 | - * |
|
488 | - * @since 2.0.16 |
|
489 | - * @param array $values |
|
490 | - * @param array $new_values |
|
491 | - * @return boolean|int $entry_id |
|
492 | - */ |
|
486 | + * Create an entry and perform after create actions |
|
487 | + * |
|
488 | + * @since 2.0.16 |
|
489 | + * @param array $values |
|
490 | + * @param array $new_values |
|
491 | + * @return boolean|int $entry_id |
|
492 | + */ |
|
493 | 493 | private static function continue_to_create_entry( $values, $new_values ) { |
494 | 494 | $entry_id = self::insert_entry_into_database( $new_values ); |
495 | 495 | if ( ! $entry_id ) { |
@@ -501,37 +501,37 @@ discard block |
||
501 | 501 | return $entry_id; |
502 | 502 | } |
503 | 503 | |
504 | - /** |
|
505 | - * Sanitize the POST values before we use them |
|
506 | - * |
|
507 | - * @since 2.0 |
|
508 | - * @param array $values The POST values by reference |
|
509 | - */ |
|
510 | - public static function sanitize_entry_post( &$values ) { |
|
511 | - $sanitize_method = array( |
|
512 | - 'form_id' => 'absint', |
|
513 | - 'frm_action' => 'sanitize_title', |
|
514 | - 'form_key' => 'sanitize_title', |
|
515 | - 'item_key' => 'sanitize_title', |
|
516 | - 'item_name' => 'sanitize_text_field', |
|
517 | - 'frm_saving_draft' => 'absint', |
|
518 | - 'is_draft' => 'absint', |
|
519 | - 'post_id' => 'absint', |
|
520 | - 'parent_item_id' => 'absint', |
|
521 | - 'created_at' => 'sanitize_text_field', |
|
522 | - 'updated_at' => 'sanitize_text_field', |
|
523 | - ); |
|
524 | - |
|
525 | - FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
526 | - } |
|
527 | - |
|
528 | - /** |
|
529 | - * Prepare the new values for inserting into the database |
|
530 | - * |
|
531 | - * @since 2.0.16 |
|
532 | - * @param array $values |
|
533 | - * @return array $new_values |
|
534 | - */ |
|
504 | + /** |
|
505 | + * Sanitize the POST values before we use them |
|
506 | + * |
|
507 | + * @since 2.0 |
|
508 | + * @param array $values The POST values by reference |
|
509 | + */ |
|
510 | + public static function sanitize_entry_post( &$values ) { |
|
511 | + $sanitize_method = array( |
|
512 | + 'form_id' => 'absint', |
|
513 | + 'frm_action' => 'sanitize_title', |
|
514 | + 'form_key' => 'sanitize_title', |
|
515 | + 'item_key' => 'sanitize_title', |
|
516 | + 'item_name' => 'sanitize_text_field', |
|
517 | + 'frm_saving_draft' => 'absint', |
|
518 | + 'is_draft' => 'absint', |
|
519 | + 'post_id' => 'absint', |
|
520 | + 'parent_item_id' => 'absint', |
|
521 | + 'created_at' => 'sanitize_text_field', |
|
522 | + 'updated_at' => 'sanitize_text_field', |
|
523 | + ); |
|
524 | + |
|
525 | + FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
526 | + } |
|
527 | + |
|
528 | + /** |
|
529 | + * Prepare the new values for inserting into the database |
|
530 | + * |
|
531 | + * @since 2.0.16 |
|
532 | + * @param array $values |
|
533 | + * @return array $new_values |
|
534 | + */ |
|
535 | 535 | private static function package_entry_data( &$values ) { |
536 | 536 | global $wpdb; |
537 | 537 | |
@@ -564,67 +564,67 @@ discard block |
||
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
567 | - * Get the is_draft value for a new entry |
|
568 | - * |
|
569 | - * @since 2.0.16 |
|
570 | - * @param array $values |
|
571 | - * @return int |
|
572 | - */ |
|
567 | + * Get the is_draft value for a new entry |
|
568 | + * |
|
569 | + * @since 2.0.16 |
|
570 | + * @param array $values |
|
571 | + * @return int |
|
572 | + */ |
|
573 | 573 | private static function get_is_draft_value( $values ) { |
574 | 574 | return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; |
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
578 | - * Get the form_id value for a new entry |
|
579 | - * |
|
580 | - * @since 2.0.16 |
|
581 | - * @param array $values |
|
582 | - * @return int|null |
|
583 | - */ |
|
578 | + * Get the form_id value for a new entry |
|
579 | + * |
|
580 | + * @since 2.0.16 |
|
581 | + * @param array $values |
|
582 | + * @return int|null |
|
583 | + */ |
|
584 | 584 | private static function get_form_id( $values ) { |
585 | 585 | return isset( $values['form_id'] ) ? (int) $values['form_id'] : null; |
586 | 586 | } |
587 | 587 | |
588 | 588 | /** |
589 | - * Get the post_id value for a new entry |
|
590 | - * |
|
591 | - * @since 2.0.16 |
|
592 | - * @param array $values |
|
593 | - * @return int |
|
594 | - */ |
|
589 | + * Get the post_id value for a new entry |
|
590 | + * |
|
591 | + * @since 2.0.16 |
|
592 | + * @param array $values |
|
593 | + * @return int |
|
594 | + */ |
|
595 | 595 | private static function get_post_id( $values ) { |
596 | 596 | return isset( $values['post_id'] ) ? (int) $values['post_id']: 0; |
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
600 | - * Get the parent_item_id value for a new entry |
|
601 | - * |
|
602 | - * @since 2.0.16 |
|
603 | - * @param array $values |
|
604 | - * @return int |
|
605 | - */ |
|
600 | + * Get the parent_item_id value for a new entry |
|
601 | + * |
|
602 | + * @since 2.0.16 |
|
603 | + * @param array $values |
|
604 | + * @return int |
|
605 | + */ |
|
606 | 606 | private static function get_parent_item_id( $values ) { |
607 | 607 | return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0; |
608 | 608 | } |
609 | 609 | |
610 | 610 | /** |
611 | - * Get the created_at value for a new entry |
|
612 | - * |
|
613 | - * @since 2.0.16 |
|
614 | - * @param array $values |
|
615 | - * @return string |
|
616 | - */ |
|
611 | + * Get the created_at value for a new entry |
|
612 | + * |
|
613 | + * @since 2.0.16 |
|
614 | + * @param array $values |
|
615 | + * @return string |
|
616 | + */ |
|
617 | 617 | private static function get_created_at( $values ) { |
618 | 618 | return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1); |
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
622 | - * Get the updated_at value for a new entry |
|
623 | - * |
|
624 | - * @since 2.0.16 |
|
625 | - * @param array $values |
|
626 | - * @return string |
|
627 | - */ |
|
622 | + * Get the updated_at value for a new entry |
|
623 | + * |
|
624 | + * @since 2.0.16 |
|
625 | + * @param array $values |
|
626 | + * @return string |
|
627 | + */ |
|
628 | 628 | private static function get_updated_at( $values ) { |
629 | 629 | if ( isset( $values['updated_at'] ) ) { |
630 | 630 | $updated_at = $values['updated_at']; |
@@ -636,12 +636,12 @@ discard block |
||
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
639 | - * Get the description value for a new entry |
|
640 | - * |
|
641 | - * @since 2.0.16 |
|
642 | - * @param array $values |
|
643 | - * @return string |
|
644 | - */ |
|
639 | + * Get the description value for a new entry |
|
640 | + * |
|
641 | + * @since 2.0.16 |
|
642 | + * @param array $values |
|
643 | + * @return string |
|
644 | + */ |
|
645 | 645 | private static function get_entry_description( $values ) { |
646 | 646 | if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) { |
647 | 647 | $description = maybe_serialize( $values['description'] ); |
@@ -656,12 +656,12 @@ discard block |
||
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
659 | - * Get the user_id value for a new entry |
|
660 | - * |
|
661 | - * @since 2.0.16 |
|
662 | - * @param array $values |
|
663 | - * @return int |
|
664 | - */ |
|
659 | + * Get the user_id value for a new entry |
|
660 | + * |
|
661 | + * @since 2.0.16 |
|
662 | + * @param array $values |
|
663 | + * @return int |
|
664 | + */ |
|
665 | 665 | private static function get_entry_user_id( $values ) { |
666 | 666 | if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) { |
667 | 667 | $user_id = $values['frm_user_id']; |
@@ -674,12 +674,12 @@ discard block |
||
674 | 674 | } |
675 | 675 | |
676 | 676 | /** |
677 | - * Insert new entry into the database |
|
678 | - * |
|
679 | - * @since 2.0.16 |
|
680 | - * @param array $new_values |
|
681 | - * @return int | boolean $entry_id |
|
682 | - */ |
|
677 | + * Insert new entry into the database |
|
678 | + * |
|
679 | + * @since 2.0.16 |
|
680 | + * @param array $new_values |
|
681 | + * @return int | boolean $entry_id |
|
682 | + */ |
|
683 | 683 | private static function insert_entry_into_database( $new_values ) { |
684 | 684 | global $wpdb; |
685 | 685 | |
@@ -695,11 +695,11 @@ discard block |
||
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
698 | - * Add the new entry to global $frm_vars |
|
699 | - * |
|
700 | - * @since 2.0.16 |
|
701 | - * @param int $entry_id |
|
702 | - */ |
|
698 | + * Add the new entry to global $frm_vars |
|
699 | + * |
|
700 | + * @since 2.0.16 |
|
701 | + * @param int $entry_id |
|
702 | + */ |
|
703 | 703 | private static function add_new_entry_to_frm_vars( $entry_id ) { |
704 | 704 | global $frm_vars; |
705 | 705 | |
@@ -711,12 +711,12 @@ discard block |
||
711 | 711 | } |
712 | 712 | |
713 | 713 | /** |
714 | - * Add entry metas, if there are any |
|
715 | - * |
|
716 | - * @since 2.0.16 |
|
717 | - * @param array $values |
|
718 | - * @param int $entry_id |
|
719 | - */ |
|
714 | + * Add entry metas, if there are any |
|
715 | + * |
|
716 | + * @since 2.0.16 |
|
717 | + * @param array $values |
|
718 | + * @param int $entry_id |
|
719 | + */ |
|
720 | 720 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
721 | 721 | if ( isset($values['item_meta']) ) { |
722 | 722 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
@@ -724,12 +724,12 @@ discard block |
||
724 | 724 | } |
725 | 725 | |
726 | 726 | /** |
727 | - * Trigger frm_after_create_entry hooks |
|
728 | - * |
|
729 | - * @since 2.0.16 |
|
730 | - * @param int $entry_id |
|
731 | - * @param array $new_values |
|
732 | - */ |
|
727 | + * Trigger frm_after_create_entry hooks |
|
728 | + * |
|
729 | + * @since 2.0.16 |
|
730 | + * @param int $entry_id |
|
731 | + * @param array $new_values |
|
732 | + */ |
|
733 | 733 | private static function after_entry_created_actions( $entry_id, $values, $new_values ) { |
734 | 734 | // this is a child entry |
735 | 735 | $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' ); |
@@ -739,13 +739,13 @@ discard block |
||
739 | 739 | } |
740 | 740 | |
741 | 741 | /** |
742 | - * Actions to perform immediately after an entry is inserted in the frm_items database |
|
743 | - * |
|
744 | - * @since 2.0.16 |
|
745 | - * @param array $values |
|
746 | - * @param array $new_values |
|
747 | - * @param int $entry_id |
|
748 | - */ |
|
742 | + * Actions to perform immediately after an entry is inserted in the frm_items database |
|
743 | + * |
|
744 | + * @since 2.0.16 |
|
745 | + * @param array $values |
|
746 | + * @param array $new_values |
|
747 | + * @param int $entry_id |
|
748 | + */ |
|
749 | 749 | private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) { |
750 | 750 | |
751 | 751 | self::add_new_entry_to_frm_vars( $entry_id ); |
@@ -758,14 +758,14 @@ discard block |
||
758 | 758 | } |
759 | 759 | |
760 | 760 | /** |
761 | - * Perform some actions right before updating an entry |
|
762 | - * |
|
763 | - * @since 2.0.16 |
|
764 | - * @param int $id |
|
765 | - * @param array $values |
|
766 | - * @param string $update_type |
|
767 | - * @return boolean $update |
|
768 | - */ |
|
761 | + * Perform some actions right before updating an entry |
|
762 | + * |
|
763 | + * @since 2.0.16 |
|
764 | + * @param int $id |
|
765 | + * @param array $values |
|
766 | + * @param string $update_type |
|
767 | + * @return boolean $update |
|
768 | + */ |
|
769 | 769 | private static function before_update_entry( $id, &$values, $update_type ) { |
770 | 770 | $update = true; |
771 | 771 | |
@@ -783,13 +783,13 @@ discard block |
||
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
786 | - * Package the entry data for updating |
|
787 | - * |
|
788 | - * @since 2.0.16 |
|
789 | - * @param int $id |
|
790 | - * @param array $values |
|
791 | - * @return array $new_values |
|
792 | - */ |
|
786 | + * Package the entry data for updating |
|
787 | + * |
|
788 | + * @since 2.0.16 |
|
789 | + * @param int $id |
|
790 | + * @param array $values |
|
791 | + * @return array $new_values |
|
792 | + */ |
|
793 | 793 | private static function package_entry_to_update( $id, $values ) { |
794 | 794 | global $wpdb; |
795 | 795 | |
@@ -823,14 +823,14 @@ discard block |
||
823 | 823 | } |
824 | 824 | |
825 | 825 | /** |
826 | - * Perform some actions right after updating an entry |
|
827 | - * |
|
828 | - * @since 2.0.16 |
|
829 | - * @param boolean|int $query_results |
|
830 | - * @param int $id |
|
831 | - * @param array $values |
|
832 | - * @param array $new_values |
|
833 | - */ |
|
826 | + * Perform some actions right after updating an entry |
|
827 | + * |
|
828 | + * @since 2.0.16 |
|
829 | + * @param boolean|int $query_results |
|
830 | + * @param int $id |
|
831 | + * @param array $values |
|
832 | + * @param array $new_values |
|
833 | + */ |
|
834 | 834 | private static function after_update_entry( $query_results, $id, $values, $new_values ) { |
835 | 835 | if ( $query_results ) { |
836 | 836 | self::clear_cache(); |
@@ -852,13 +852,13 @@ discard block |
||
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
855 | - * Create entry from an XML import |
|
856 | - * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
857 | - * |
|
858 | - * @since 2.0.16 |
|
859 | - * @param array $values |
|
860 | - * @return int | boolean $entry_id |
|
861 | - */ |
|
855 | + * Create entry from an XML import |
|
856 | + * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
857 | + * |
|
858 | + * @since 2.0.16 |
|
859 | + * @param array $values |
|
860 | + * @return int | boolean $entry_id |
|
861 | + */ |
|
862 | 862 | public static function create_entry_from_xml( $values ) { |
863 | 863 | $entry_id = self::create_entry( $values, 'xml' ); |
864 | 864 | |
@@ -866,28 +866,28 @@ discard block |
||
866 | 866 | } |
867 | 867 | |
868 | 868 | /** |
869 | - * Update entry from an XML import |
|
870 | - * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
871 | - * |
|
872 | - * @since 2.0.16 |
|
873 | - * @param int $id |
|
874 | - * @param array $values |
|
875 | - * @return int | boolean $updated |
|
876 | - */ |
|
869 | + * Update entry from an XML import |
|
870 | + * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
871 | + * |
|
872 | + * @since 2.0.16 |
|
873 | + * @param int $id |
|
874 | + * @param array $values |
|
875 | + * @return int | boolean $updated |
|
876 | + */ |
|
877 | 877 | public static function update_entry_from_xml( $id, $values ) { |
878 | 878 | $updated = self::update_entry( $id, $values, 'xml' ); |
879 | 879 | |
880 | 880 | return $updated; |
881 | 881 | } |
882 | 882 | |
883 | - /** |
|
884 | - * @param string $key |
|
885 | - * @return int entry_id |
|
886 | - */ |
|
883 | + /** |
|
884 | + * @param string $key |
|
885 | + * @return int entry_id |
|
886 | + */ |
|
887 | 887 | public static function get_id_by_key( $key ) { |
888 | - $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
|
889 | - return $entry_id; |
|
890 | - } |
|
888 | + $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
|
889 | + return $entry_id; |
|
890 | + } |
|
891 | 891 | |
892 | 892 | public static function validate( $values, $exclude = false ) { |
893 | 893 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryValidate::validate' ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | 3 | die( 'You are not allowed to call this page directly.' ); |
4 | 4 | } |
5 | 5 | |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] ); |
56 | 56 | |
57 | 57 | if ( $new_values['item_key'] == $new_values['name'] ) { |
58 | - unset($check_val['name']); |
|
58 | + unset( $check_val['name'] ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | global $wpdb; |
62 | 62 | $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) ); |
63 | 63 | |
64 | - if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) { |
|
64 | + if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) { |
|
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | $is_duplicate = true; |
71 | 71 | |
72 | 72 | //add more checks here to make sure it's a duplicate |
73 | - $metas = FrmEntryMeta::get_entry_meta_info($entry_exist); |
|
73 | + $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist ); |
|
74 | 74 | $field_metas = array(); |
75 | 75 | foreach ( $metas as $meta ) { |
76 | - $field_metas[ $meta->field_id ] = $meta->meta_value; |
|
76 | + $field_metas[$meta->field_id] = $meta->meta_value; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | // If prev entry is empty and current entry is not, they are not duplicates |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | return false; |
83 | 83 | } |
84 | 84 | |
85 | - $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta'])); |
|
85 | + $diff = array_diff_assoc( $field_metas, array_map( 'maybe_serialize', $values['item_meta'] ) ); |
|
86 | 86 | foreach ( $diff as $field_id => $meta_value ) { |
87 | - if ( ! empty($meta_value) ) { |
|
87 | + if ( ! empty( $meta_value ) ) { |
|
88 | 88 | $is_duplicate = false; |
89 | 89 | continue; |
90 | 90 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | } |
114 | 114 | |
115 | 115 | // If CSV is importing, don't check for duplicates |
116 | - if ( defined('WP_IMPORTING') && WP_IMPORTING ) { |
|
116 | + if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
|
117 | 117 | return false; |
118 | 118 | } |
119 | 119 | |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | $new_values['name'] = $values->name; |
136 | 136 | $new_values['is_draft'] = $values->is_draft; |
137 | 137 | $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id; |
138 | - $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null; |
|
139 | - $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1); |
|
138 | + $new_values['form_id'] = $values->form_id ? (int) $values->form_id : null; |
|
139 | + $new_values['created_at'] = $new_values['updated_at'] = current_time( 'mysql', 1 ); |
|
140 | 140 | |
141 | 141 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values ); |
142 | 142 | if ( ! $query_results ) { |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | $entry_id = $wpdb->insert_id; |
147 | 147 | |
148 | 148 | global $frm_vars; |
149 | - if ( ! isset($frm_vars['saved_entries']) ) { |
|
149 | + if ( ! isset( $frm_vars['saved_entries'] ) ) { |
|
150 | 150 | $frm_vars['saved_entries'] = array(); |
151 | 151 | } |
152 | 152 | $frm_vars['saved_entries'][] = (int) $entry_id; |
153 | 153 | |
154 | - FrmEntryMeta::duplicate_entry_metas($id, $entry_id); |
|
154 | + FrmEntryMeta::duplicate_entry_metas( $id, $entry_id ); |
|
155 | 155 | self::clear_cache(); |
156 | 156 | |
157 | 157 | do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) ); |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | |
191 | 191 | $new_values = self::package_entry_to_update( $id, $values ); |
192 | 192 | |
193 | - $query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact('id') ); |
|
193 | + $query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact( 'id' ) ); |
|
194 | 194 | |
195 | 195 | self::after_update_entry( $query_results, $id, $values, $new_values ); |
196 | 196 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | return $result; |
208 | 208 | } |
209 | 209 | |
210 | - do_action('frm_before_destroy_entry', $id, $entry); |
|
210 | + do_action( 'frm_before_destroy_entry', $id, $entry ); |
|
211 | 211 | |
212 | 212 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) ); |
213 | 213 | $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) ); |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | |
220 | 220 | public static function &update_form( $id, $value, $form_id ) { |
221 | 221 | global $wpdb; |
222 | - $form_id = isset($value) ? $form_id : null; |
|
222 | + $form_id = isset( $value ) ? $form_id : null; |
|
223 | 223 | $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) ); |
224 | 224 | if ( $result ) { |
225 | 225 | self::clear_cache(); |
@@ -266,24 +266,24 @@ discard block |
||
266 | 266 | $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
267 | 267 | LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE "; |
268 | 268 | |
269 | - $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s'; |
|
269 | + $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s'; |
|
270 | 270 | $query_args = array( $id ); |
271 | 271 | $query = $wpdb->prepare( $query, $query_args ); |
272 | 272 | |
273 | 273 | if ( ! $meta ) { |
274 | 274 | $entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' ); |
275 | - return stripslashes_deep($entry); |
|
275 | + return stripslashes_deep( $entry ); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | $entry = FrmAppHelper::check_cache( $id, 'frm_entry' ); |
279 | 279 | if ( $entry !== false ) { |
280 | - return stripslashes_deep($entry); |
|
280 | + return stripslashes_deep( $entry ); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | $entry = $wpdb->get_row( $query ); |
284 | - $entry = self::get_meta($entry); |
|
284 | + $entry = self::get_meta( $entry ); |
|
285 | 285 | |
286 | - return stripslashes_deep($entry); |
|
286 | + return stripslashes_deep( $entry ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | public static function get_meta( $entry ) { |
@@ -299,25 +299,25 @@ discard block |
||
299 | 299 | $include_key = apply_filters( 'frm_include_meta_keys', false ); |
300 | 300 | foreach ( $metas as $meta_val ) { |
301 | 301 | if ( $meta_val->item_id == $entry->id ) { |
302 | - $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
|
302 | + $entry->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value ); |
|
303 | 303 | if ( $include_key ) { |
304 | - $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
|
304 | + $entry->metas[$meta_val->field_key] = $entry->metas[$meta_val->field_id]; |
|
305 | 305 | } |
306 | 306 | continue; |
307 | 307 | } |
308 | 308 | |
309 | 309 | // include sub entries in an array |
310 | - if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) { |
|
311 | - $entry->metas[ $meta_val->field_id ] = array(); |
|
310 | + if ( ! isset( $entry_metas[$meta_val->field_id] ) ) { |
|
311 | + $entry->metas[$meta_val->field_id] = array(); |
|
312 | 312 | } |
313 | 313 | |
314 | - $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value ); |
|
314 | + $entry->metas[$meta_val->field_id][] = maybe_unserialize( $meta_val->meta_value ); |
|
315 | 315 | |
316 | - unset($meta_val); |
|
316 | + unset( $meta_val ); |
|
317 | 317 | } |
318 | - unset($metas); |
|
318 | + unset( $metas ); |
|
319 | 319 | |
320 | - wp_cache_set( $entry->id, $entry, 'frm_entry'); |
|
320 | + wp_cache_set( $entry->id, $entry, 'frm_entry' ); |
|
321 | 321 | |
322 | 322 | return $entry; |
323 | 323 | } |
@@ -333,24 +333,24 @@ discard block |
||
333 | 333 | return $exists; |
334 | 334 | } |
335 | 335 | |
336 | - if ( is_numeric($id) ) { |
|
336 | + if ( is_numeric( $id ) ) { |
|
337 | 337 | $where = array( 'id' => $id ); |
338 | 338 | } else { |
339 | 339 | $where = array( 'item_key' => $id ); |
340 | 340 | } |
341 | 341 | $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where ); |
342 | 342 | |
343 | - $exists = ($id && $id > 0) ? true : false; |
|
343 | + $exists = ( $id && $id > 0 ) ? true : false; |
|
344 | 344 | return $exists; |
345 | 345 | } |
346 | 346 | |
347 | 347 | public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
348 | 348 | global $wpdb; |
349 | 349 | |
350 | - $limit = FrmAppHelper::esc_limit($limit); |
|
350 | + $limit = FrmAppHelper::esc_limit( $limit ); |
|
351 | 351 | |
352 | - $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form; |
|
353 | - $entries = wp_cache_get($cache_key, 'frm_entry'); |
|
352 | + $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form; |
|
353 | + $entries = wp_cache_get( $cache_key, 'frm_entry' ); |
|
354 | 354 | |
355 | 355 | if ( false === $entries ) { |
356 | 356 | $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
@@ -369,10 +369,10 @@ discard block |
||
369 | 369 | } |
370 | 370 | |
371 | 371 | // prepare the query |
372 | - $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
372 | + $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
373 | 373 | |
374 | - $entries = $wpdb->get_results($query, OBJECT_K); |
|
375 | - unset($query); |
|
374 | + $entries = $wpdb->get_results( $query, OBJECT_K ); |
|
375 | + unset( $query ); |
|
376 | 376 | |
377 | 377 | if ( ! FrmAppHelper::prevent_caching() ) { |
378 | 378 | wp_cache_set( $cache_key, $entries, 'frm_entry', 300 ); |
@@ -380,16 +380,16 @@ discard block |
||
380 | 380 | } |
381 | 381 | |
382 | 382 | if ( ! $meta || ! $entries ) { |
383 | - return stripslashes_deep($entries); |
|
383 | + return stripslashes_deep( $entries ); |
|
384 | 384 | } |
385 | - unset($meta); |
|
385 | + unset( $meta ); |
|
386 | 386 | |
387 | - if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) { |
|
387 | + if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) { |
|
388 | 388 | $where = array( 'it.form_id' => substr( $where, 11 ) ); |
389 | 389 | } |
390 | 390 | |
391 | 391 | $meta_where = array( 'field_id !' => 0 ); |
392 | - if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) { |
|
392 | + if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) { |
|
393 | 393 | $meta_where['fi.form_id'] = $where['it.form_id']; |
394 | 394 | } else { |
395 | 395 | $meta_where['item_id'] = array_keys( $entries ); |
@@ -400,21 +400,21 @@ discard block |
||
400 | 400 | unset( $meta_where ); |
401 | 401 | |
402 | 402 | if ( ! $metas ) { |
403 | - return stripslashes_deep($entries); |
|
403 | + return stripslashes_deep( $entries ); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | foreach ( $metas as $m_key => $meta_val ) { |
407 | - if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
407 | + if ( ! isset( $entries[$meta_val->item_id] ) ) { |
|
408 | 408 | continue; |
409 | 409 | } |
410 | 410 | |
411 | - if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
412 | - $entries[ $meta_val->item_id ]->metas = array(); |
|
411 | + if ( ! isset( $entries[$meta_val->item_id]->metas ) ) { |
|
412 | + $entries[$meta_val->item_id]->metas = array(); |
|
413 | 413 | } |
414 | 414 | |
415 | - $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
|
415 | + $entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value ); |
|
416 | 416 | |
417 | - unset($m_key, $meta_val); |
|
417 | + unset( $m_key, $meta_val ); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | if ( ! FrmAppHelper::prevent_caching() ) { |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - return stripslashes_deep($entries); |
|
427 | + return stripslashes_deep( $entries ); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | // Pagination Methods |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | global $wpdb; |
433 | 433 | $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; |
434 | 434 | |
435 | - if ( is_numeric($where) ) { |
|
435 | + if ( is_numeric( $where ) ) { |
|
436 | 436 | $table_join = 'frm_items'; |
437 | 437 | $where = array( 'form_id' => $where ); |
438 | 438 | } |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | self::sanitize_entry_post( $values ); |
475 | 475 | |
476 | 476 | if ( $type != 'xml' ) { |
477 | - $values = apply_filters('frm_pre_create_entry', $values); |
|
477 | + $values = apply_filters( 'frm_pre_create_entry', $values ); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | $new_values = self::package_entry_data( $values ); |
@@ -554,11 +554,11 @@ discard block |
||
554 | 554 | 'user_id' => self::get_entry_user_id( $values ), |
555 | 555 | ); |
556 | 556 | |
557 | - if ( is_array($new_values['name']) ) { |
|
558 | - $new_values['name'] = reset($new_values['name']); |
|
557 | + if ( is_array( $new_values['name'] ) ) { |
|
558 | + $new_values['name'] = reset( $new_values['name'] ); |
|
559 | 559 | } |
560 | 560 | |
561 | - $new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id']; |
|
561 | + $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id']; |
|
562 | 562 | |
563 | 563 | return $new_values; |
564 | 564 | } |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | * @return int |
572 | 572 | */ |
573 | 573 | private static function get_is_draft_value( $values ) { |
574 | - return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; |
|
574 | + return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | * @return int |
594 | 594 | */ |
595 | 595 | private static function get_post_id( $values ) { |
596 | - return isset( $values['post_id'] ) ? (int) $values['post_id']: 0; |
|
596 | + return isset( $values['post_id'] ) ? (int) $values['post_id'] : 0; |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | * @return int |
605 | 605 | */ |
606 | 606 | private static function get_parent_item_id( $values ) { |
607 | - return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0; |
|
607 | + return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id'] : 0; |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | /** |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | * @return string |
616 | 616 | */ |
617 | 617 | private static function get_created_at( $values ) { |
618 | - return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1); |
|
618 | + return isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | private static function add_new_entry_to_frm_vars( $entry_id ) { |
704 | 704 | global $frm_vars; |
705 | 705 | |
706 | - if ( ! isset($frm_vars['saved_entries']) ) { |
|
706 | + if ( ! isset( $frm_vars['saved_entries'] ) ) { |
|
707 | 707 | $frm_vars['saved_entries'] = array(); |
708 | 708 | } |
709 | 709 | |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | * @param int $entry_id |
719 | 719 | */ |
720 | 720 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
721 | - if ( isset($values['item_meta']) ) { |
|
721 | + if ( isset( $values['item_meta'] ) ) { |
|
722 | 722 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
723 | 723 | } |
724 | 724 | } |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' ); |
736 | 736 | |
737 | 737 | do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) ); |
738 | - do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id , compact( 'is_child' ) ); |
|
738 | + do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) ); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | /** |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | } |
777 | 777 | |
778 | 778 | if ( $update && $update_type != 'xml' ) { |
779 | - $values = apply_filters('frm_pre_update_entry', $values, $id); |
|
779 | + $values = apply_filters( 'frm_pre_update_entry', $values, $id ); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | return $update; |
@@ -797,27 +797,27 @@ discard block |
||
797 | 797 | 'name' => self::get_new_entry_name( $values ), |
798 | 798 | 'form_id' => self::get_form_id( $values ), |
799 | 799 | 'is_draft' => self::get_is_draft_value( $values ), |
800 | - 'updated_at' => current_time('mysql', 1), |
|
801 | - 'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : get_current_user_id(), |
|
800 | + 'updated_at' => current_time( 'mysql', 1 ), |
|
801 | + 'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(), |
|
802 | 802 | ); |
803 | 803 | |
804 | - if ( isset($values['post_id']) ) { |
|
804 | + if ( isset( $values['post_id'] ) ) { |
|
805 | 805 | $new_values['post_id'] = (int) $values['post_id']; |
806 | 806 | } |
807 | 807 | |
808 | - if ( isset($values['item_key']) ) { |
|
808 | + if ( isset( $values['item_key'] ) ) { |
|
809 | 809 | $new_values['item_key'] = FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key', $id ); |
810 | 810 | } |
811 | 811 | |
812 | - if ( isset($values['parent_item_id']) ) { |
|
812 | + if ( isset( $values['parent_item_id'] ) ) { |
|
813 | 813 | $new_values['parent_item_id'] = (int) $values['parent_item_id']; |
814 | 814 | } |
815 | 815 | |
816 | - if ( isset($values['frm_user_id']) && is_numeric($values['frm_user_id']) ) { |
|
816 | + if ( isset( $values['frm_user_id'] ) && is_numeric( $values['frm_user_id'] ) ) { |
|
817 | 817 | $new_values['user_id'] = $values['frm_user_id']; |
818 | 818 | } |
819 | 819 | |
820 | - $new_values = apply_filters('frm_update_entry', $new_values, $id); |
|
820 | + $new_values = apply_filters( 'frm_update_entry', $new_values, $id ); |
|
821 | 821 | |
822 | 822 | return $new_values; |
823 | 823 | } |
@@ -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,143 +139,143 @@ 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_count = FrmDb::get_count( $wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array( 'or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id ) ); |
170 | 170 | |
171 | - $values['field_order'] = $field_count + 1; |
|
171 | + $values['field_order'] = $field_count + 1; |
|
172 | 172 | |
173 | - $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values ); |
|
173 | + $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values ); |
|
174 | 174 | |
175 | - if ( ! $field_id = FrmField::create($values) ) { |
|
176 | - wp_die(); |
|
177 | - } |
|
175 | + if ( ! $field_id = FrmField::create($values) ) { |
|
176 | + wp_die(); |
|
177 | + } |
|
178 | 178 | |
179 | - self::include_single_field($field_id, $values); |
|
179 | + self::include_single_field($field_id, $values); |
|
180 | 180 | |
181 | - wp_die(); |
|
182 | - } |
|
181 | + wp_die(); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Load a single field in the form builder along with all needed variables |
|
186 | - */ |
|
187 | - public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
188 | - $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
184 | + /** |
|
185 | + * Load a single field in the form builder along with all needed variables |
|
186 | + */ |
|
187 | + public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
188 | + $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
189 | 189 | $field_name = 'item_meta[' . $field_id . ']'; |
190 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
191 | - $id = $form_id ? $form_id : $field['form_id']; |
|
192 | - if ( $field['type'] == 'html' ) { |
|
193 | - $field['stop_filter'] = true; |
|
194 | - } |
|
190 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
191 | + $id = $form_id ? $form_id : $field['form_id']; |
|
192 | + if ( $field['type'] == 'html' ) { |
|
193 | + $field['stop_filter'] = true; |
|
194 | + } |
|
195 | 195 | |
196 | 196 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' ); |
197 | 197 | |
198 | - return $field; |
|
199 | - } |
|
198 | + return $field; |
|
199 | + } |
|
200 | 200 | |
201 | - public static function destroy() { |
|
201 | + public static function destroy() { |
|
202 | 202 | FrmAppHelper::permission_check('frm_edit_forms'); |
203 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
203 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
204 | 204 | |
205 | 205 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
206 | 206 | FrmField::destroy( $field_id ); |
207 | - wp_die(); |
|
208 | - } |
|
207 | + wp_die(); |
|
208 | + } |
|
209 | 209 | |
210 | - /* Field Options */ |
|
210 | + /* Field Options */ |
|
211 | 211 | |
212 | - //Add Single Option or Other Option |
|
213 | - public static function add_option() { |
|
212 | + //Add Single Option or Other Option |
|
213 | + public static function add_option() { |
|
214 | 214 | FrmAppHelper::permission_check('frm_edit_forms'); |
215 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
215 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
216 | 216 | |
217 | 217 | $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
218 | 218 | $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' ); |
219 | 219 | |
220 | - //Get the field |
|
221 | - $field = FrmField::getOne($id); |
|
220 | + //Get the field |
|
221 | + $field = FrmField::getOne($id); |
|
222 | 222 | |
223 | 223 | if ( ! empty( $field->options ) ) { |
224 | 224 | $keys = array_keys( $field->options ); |
225 | - $last = str_replace( 'other_', '', end( $keys ) ); |
|
226 | - } else { |
|
227 | - $last = 0; |
|
228 | - } |
|
229 | - $opt_key = $last + 1; |
|
225 | + $last = str_replace( 'other_', '', end( $keys ) ); |
|
226 | + } else { |
|
227 | + $last = 0; |
|
228 | + } |
|
229 | + $opt_key = $last + 1; |
|
230 | 230 | |
231 | - if ( 'other' == $opt_type ) { |
|
231 | + if ( 'other' == $opt_type ) { |
|
232 | 232 | $opt = esc_html__( 'Other', 'formidable' ); |
233 | - $other_val = ''; |
|
234 | - $opt_key = 'other_' . $opt_key; |
|
235 | - |
|
236 | - //Update value of "other" in DB |
|
237 | - $field_options = maybe_unserialize( $field->field_options ); |
|
238 | - $field_options['other'] = 1; |
|
239 | - FrmField::update( $id, array( 'field_options' => maybe_serialize( $field_options ) ) ); |
|
240 | - } else { |
|
233 | + $other_val = ''; |
|
234 | + $opt_key = 'other_' . $opt_key; |
|
235 | + |
|
236 | + //Update value of "other" in DB |
|
237 | + $field_options = maybe_unserialize( $field->field_options ); |
|
238 | + $field_options['other'] = 1; |
|
239 | + FrmField::update( $id, array( 'field_options' => maybe_serialize( $field_options ) ) ); |
|
240 | + } else { |
|
241 | 241 | $first_opt = reset( $field->options ); |
242 | 242 | $next_opt = count( $field->options ); |
243 | - if ( $first_opt != '' ) { |
|
244 | - $next_opt++; |
|
245 | - } |
|
243 | + if ( $first_opt != '' ) { |
|
244 | + $next_opt++; |
|
245 | + } |
|
246 | 246 | $opt = esc_html__( 'Option', 'formidable' ) . ' ' . $next_opt; |
247 | - unset($next_opt); |
|
248 | - } |
|
249 | - $field_val = $opt; |
|
247 | + unset($next_opt); |
|
248 | + } |
|
249 | + $field_val = $opt; |
|
250 | 250 | $field->options[ $opt_key ] = $opt; |
251 | 251 | |
252 | - //Update options in DB |
|
252 | + //Update options in DB |
|
253 | 253 | FrmField::update( $id, array( 'options' => $field->options ) ); |
254 | 254 | |
255 | - $field_data = $field; |
|
256 | - $field = array( |
|
257 | - 'type' => $field_data->type, |
|
258 | - 'id' => $id, |
|
259 | - 'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0, |
|
260 | - 'form_id' => $field_data->form_id, |
|
261 | - 'field_key' => $field_data->field_key, |
|
262 | - ); |
|
255 | + $field_data = $field; |
|
256 | + $field = array( |
|
257 | + 'type' => $field_data->type, |
|
258 | + 'id' => $id, |
|
259 | + 'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0, |
|
260 | + 'form_id' => $field_data->form_id, |
|
261 | + 'field_key' => $field_data->field_key, |
|
262 | + ); |
|
263 | 263 | |
264 | 264 | $field_name = 'item_meta[' . $id . ']'; |
265 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
266 | - $checked = ''; |
|
265 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
266 | + $checked = ''; |
|
267 | 267 | |
268 | - if ( 'other' == $opt_type ) { |
|
268 | + if ( 'other' == $opt_type ) { |
|
269 | 269 | require( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' ); |
270 | - } else { |
|
270 | + } else { |
|
271 | 271 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
272 | - } |
|
273 | - wp_die(); |
|
274 | - } |
|
272 | + } |
|
273 | + wp_die(); |
|
274 | + } |
|
275 | 275 | |
276 | - public static function edit_option() { |
|
276 | + public static function edit_option() { |
|
277 | 277 | FrmAppHelper::permission_check('frm_edit_forms'); |
278 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
278 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
279 | 279 | |
280 | 280 | $element_id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' ); |
281 | 281 | $ids = explode( '-', $element_id ); |
@@ -283,43 +283,43 @@ discard block |
||
283 | 283 | |
284 | 284 | $orig_update_value = $update_value = trim( FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' ) ); |
285 | 285 | if ( strpos( $element_id, 'key_' ) ) { |
286 | - $new_value = $update_value; |
|
287 | - } else { |
|
288 | - $new_label = $update_value; |
|
289 | - } |
|
286 | + $new_value = $update_value; |
|
287 | + } else { |
|
288 | + $new_label = $update_value; |
|
289 | + } |
|
290 | 290 | |
291 | - $field = FrmField::getOne($id); |
|
292 | - $separate_values = FrmField::is_option_true( $field, 'separate_value' ); |
|
291 | + $field = FrmField::getOne($id); |
|
292 | + $separate_values = FrmField::is_option_true( $field, 'separate_value' ); |
|
293 | 293 | |
294 | - $this_opt_id = end($ids); |
|
294 | + $this_opt_id = end($ids); |
|
295 | 295 | $this_opt = (array) $field->options[ $this_opt_id ]; |
296 | 296 | $other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other') !== false ); |
297 | 297 | |
298 | - $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt); |
|
299 | - $value = isset($this_opt['value']) ? $this_opt['value'] : ''; |
|
298 | + $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt); |
|
299 | + $value = isset($this_opt['value']) ? $this_opt['value'] : ''; |
|
300 | 300 | |
301 | - if ( ! isset( $new_label ) ) { |
|
302 | - $new_label = $label; |
|
303 | - } |
|
301 | + if ( ! isset( $new_label ) ) { |
|
302 | + $new_label = $label; |
|
303 | + } |
|
304 | 304 | |
305 | - if ( isset($new_value) || isset($value) ) { |
|
306 | - $update_value = isset($new_value) ? $new_value : $value; |
|
307 | - } |
|
305 | + if ( isset($new_value) || isset($value) ) { |
|
306 | + $update_value = isset($new_value) ? $new_value : $value; |
|
307 | + } |
|
308 | 308 | |
309 | 309 | if ( $update_value != $new_label && $other_opt === false && $separate_values ) { |
310 | 310 | $field->options[ $this_opt_id ] = array( 'value' => $update_value, 'label' => $new_label ); |
311 | - } else { |
|
311 | + } else { |
|
312 | 312 | $field->options[ $this_opt_id ] = $orig_update_value; |
313 | - } |
|
313 | + } |
|
314 | 314 | |
315 | 315 | FrmField::update( $field->id, array( 'options' => $field->options ) ); |
316 | 316 | echo ( $orig_update_value == '' ) ? esc_html__( '(Blank)', 'formidable' ) : stripslashes( $orig_update_value ); |
317 | - wp_die(); |
|
318 | - } |
|
317 | + wp_die(); |
|
318 | + } |
|
319 | 319 | |
320 | - public static function delete_option() { |
|
320 | + public static function delete_option() { |
|
321 | 321 | FrmAppHelper::permission_check('frm_edit_forms'); |
322 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
322 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
323 | 323 | |
324 | 324 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
325 | 325 | $field = FrmField::getOne( $field_id ); |
@@ -327,313 +327,313 @@ discard block |
||
327 | 327 | $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'sanitize_title' ); |
328 | 328 | |
329 | 329 | $options = $field->options; |
330 | - unset( $options[ $opt_key ] ); |
|
331 | - $response = array( 'other' => true ); |
|
330 | + unset( $options[ $opt_key ] ); |
|
331 | + $response = array( 'other' => true ); |
|
332 | 332 | |
333 | - //If the deleted option is an "other" option |
|
333 | + //If the deleted option is an "other" option |
|
334 | 334 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
335 | - //Assume all other options are gone, unless proven otherwise |
|
336 | - $other = false; |
|
335 | + //Assume all other options are gone, unless proven otherwise |
|
336 | + $other = false; |
|
337 | 337 | |
338 | - //Check if all other options are really gone |
|
339 | - foreach ( $options as $o_key => $o_val ) { |
|
340 | - //If there is still an other option in the field, set other to true |
|
338 | + //Check if all other options are really gone |
|
339 | + foreach ( $options as $o_key => $o_val ) { |
|
340 | + //If there is still an other option in the field, set other to true |
|
341 | 341 | if ( FrmFieldsHelper::is_other_opt( $o_key ) ) { |
342 | - $other = true; |
|
343 | - break; |
|
344 | - } |
|
345 | - unset( $o_key, $o_val ); |
|
346 | - } |
|
347 | - |
|
348 | - //If all other options are gone |
|
349 | - if ( false === $other ) { |
|
350 | - $field_options = maybe_unserialize( $field->field_options ); |
|
351 | - $field_options['other'] = 0; |
|
342 | + $other = true; |
|
343 | + break; |
|
344 | + } |
|
345 | + unset( $o_key, $o_val ); |
|
346 | + } |
|
347 | + |
|
348 | + //If all other options are gone |
|
349 | + if ( false === $other ) { |
|
350 | + $field_options = maybe_unserialize( $field->field_options ); |
|
351 | + $field_options['other'] = 0; |
|
352 | 352 | FrmField::update( $field_id, array( 'field_options' => maybe_serialize( $field_options ) ) ); |
353 | - $response = array( 'other' => false ); |
|
354 | - } |
|
355 | - } |
|
356 | - echo json_encode( $response ); |
|
353 | + $response = array( 'other' => false ); |
|
354 | + } |
|
355 | + } |
|
356 | + echo json_encode( $response ); |
|
357 | 357 | |
358 | 358 | FrmField::update( $field_id, array( 'options' => maybe_serialize( $options ) ) ); |
359 | 359 | |
360 | - wp_die(); |
|
361 | - } |
|
360 | + wp_die(); |
|
361 | + } |
|
362 | 362 | |
363 | - public static function import_choices() { |
|
364 | - FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
363 | + public static function import_choices() { |
|
364 | + FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
365 | 365 | |
366 | 366 | $field_id = absint( $_REQUEST['field_id'] ); |
367 | 367 | |
368 | - global $current_screen, $hook_suffix; |
|
368 | + global $current_screen, $hook_suffix; |
|
369 | 369 | |
370 | - // Catch plugins that include admin-header.php before admin.php completes. |
|
371 | - if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
372 | - $hook_suffix = ''; |
|
373 | - set_current_screen(); |
|
374 | - } |
|
370 | + // Catch plugins that include admin-header.php before admin.php completes. |
|
371 | + if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
372 | + $hook_suffix = ''; |
|
373 | + set_current_screen(); |
|
374 | + } |
|
375 | 375 | |
376 | - if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
377 | - register_admin_color_schemes(); |
|
378 | - } |
|
376 | + if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
377 | + register_admin_color_schemes(); |
|
378 | + } |
|
379 | 379 | |
380 | - $hook_suffix = $admin_body_class = ''; |
|
380 | + $hook_suffix = $admin_body_class = ''; |
|
381 | 381 | |
382 | - if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
383 | - $admin_body_class .= ' folded'; |
|
384 | - } |
|
382 | + if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
383 | + $admin_body_class .= ' folded'; |
|
384 | + } |
|
385 | 385 | |
386 | - if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
387 | - $admin_body_class .= ' admin-bar'; |
|
388 | - } |
|
386 | + if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
387 | + $admin_body_class .= ' admin-bar'; |
|
388 | + } |
|
389 | 389 | |
390 | - if ( is_rtl() ) { |
|
391 | - $admin_body_class .= ' rtl'; |
|
392 | - } |
|
390 | + if ( is_rtl() ) { |
|
391 | + $admin_body_class .= ' rtl'; |
|
392 | + } |
|
393 | 393 | |
394 | - $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
395 | - $prepop = array(); |
|
396 | - FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
394 | + $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
395 | + $prepop = array(); |
|
396 | + FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
397 | 397 | |
398 | - $field = FrmField::getOne($field_id); |
|
398 | + $field = FrmField::getOne($field_id); |
|
399 | 399 | |
400 | - wp_enqueue_script( 'utils' ); |
|
400 | + wp_enqueue_script( 'utils' ); |
|
401 | 401 | wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' ); |
402 | - FrmAppHelper::load_admin_wide_js(); |
|
402 | + FrmAppHelper::load_admin_wide_js(); |
|
403 | 403 | |
404 | 404 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/import_choices.php' ); |
405 | - wp_die(); |
|
406 | - } |
|
405 | + wp_die(); |
|
406 | + } |
|
407 | 407 | |
408 | - public static function import_options() { |
|
408 | + public static function import_options() { |
|
409 | 409 | FrmAppHelper::permission_check('frm_edit_forms'); |
410 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
410 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
411 | 411 | |
412 | - if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
413 | - return; |
|
414 | - } |
|
412 | + if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
413 | + return; |
|
414 | + } |
|
415 | 415 | |
416 | 416 | $field_id = absint( $_POST['field_id'] ); |
417 | - $field = FrmField::getOne($field_id); |
|
417 | + $field = FrmField::getOne($field_id); |
|
418 | 418 | |
419 | 419 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { |
420 | - return; |
|
421 | - } |
|
420 | + return; |
|
421 | + } |
|
422 | 422 | |
423 | - $field = FrmFieldsHelper::setup_edit_vars($field); |
|
423 | + $field = FrmFieldsHelper::setup_edit_vars($field); |
|
424 | 424 | $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); |
425 | 425 | $opts = explode( "\n", rtrim( $opts, "\n" ) ); |
426 | 426 | $opts = array_map( 'trim', $opts ); |
427 | 427 | |
428 | - if ( $field['separate_value'] ) { |
|
429 | - foreach ( $opts as $opt_key => $opt ) { |
|
430 | - if ( strpos($opt, '|') !== false ) { |
|
431 | - $vals = explode('|', $opt); |
|
432 | - if ( $vals[0] != $vals[1] ) { |
|
433 | - $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
434 | - } |
|
435 | - unset($vals); |
|
436 | - } |
|
437 | - unset($opt_key, $opt); |
|
438 | - } |
|
439 | - } |
|
440 | - |
|
441 | - //Keep other options after bulk update |
|
442 | - if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
443 | - $other_array = array(); |
|
444 | - foreach ( $field['options'] as $opt_key => $opt ) { |
|
445 | - if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
|
446 | - $other_array[ $opt_key ] = $opt; |
|
447 | - } |
|
448 | - unset($opt_key, $opt); |
|
449 | - } |
|
450 | - if ( ! empty($other_array) ) { |
|
451 | - $opts = array_merge( $opts, $other_array); |
|
452 | - } |
|
453 | - } |
|
454 | - |
|
455 | - FrmField::update( $field_id, array( 'options' => maybe_serialize( $opts ) ) ); |
|
456 | - |
|
457 | - $field['options'] = $opts; |
|
458 | - $field_name = $field['name']; |
|
459 | - |
|
460 | - // Get html_id which will be used in single-option.php |
|
461 | - $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
462 | - |
|
463 | - if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
428 | + if ( $field['separate_value'] ) { |
|
429 | + foreach ( $opts as $opt_key => $opt ) { |
|
430 | + if ( strpos($opt, '|') !== false ) { |
|
431 | + $vals = explode('|', $opt); |
|
432 | + if ( $vals[0] != $vals[1] ) { |
|
433 | + $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
434 | + } |
|
435 | + unset($vals); |
|
436 | + } |
|
437 | + unset($opt_key, $opt); |
|
438 | + } |
|
439 | + } |
|
440 | + |
|
441 | + //Keep other options after bulk update |
|
442 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
443 | + $other_array = array(); |
|
444 | + foreach ( $field['options'] as $opt_key => $opt ) { |
|
445 | + if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
|
446 | + $other_array[ $opt_key ] = $opt; |
|
447 | + } |
|
448 | + unset($opt_key, $opt); |
|
449 | + } |
|
450 | + if ( ! empty($other_array) ) { |
|
451 | + $opts = array_merge( $opts, $other_array); |
|
452 | + } |
|
453 | + } |
|
454 | + |
|
455 | + FrmField::update( $field_id, array( 'options' => maybe_serialize( $opts ) ) ); |
|
456 | + |
|
457 | + $field['options'] = $opts; |
|
458 | + $field_name = $field['name']; |
|
459 | + |
|
460 | + // Get html_id which will be used in single-option.php |
|
461 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
462 | + |
|
463 | + if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
464 | 464 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); |
465 | - } else { |
|
466 | - FrmFieldsHelper::show_single_option($field); |
|
467 | - } |
|
465 | + } else { |
|
466 | + FrmFieldsHelper::show_single_option($field); |
|
467 | + } |
|
468 | 468 | |
469 | - wp_die(); |
|
470 | - } |
|
469 | + wp_die(); |
|
470 | + } |
|
471 | 471 | |
472 | - public static function update_order() { |
|
472 | + public static function update_order() { |
|
473 | 473 | FrmAppHelper::permission_check('frm_edit_forms'); |
474 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
474 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
475 | 475 | |
476 | 476 | $fields = FrmAppHelper::get_post_param( 'frm_field_id' ); |
477 | 477 | foreach ( (array) $fields as $position => $item ) { |
478 | 478 | FrmField::update( absint( $item ), array( 'field_order' => absint( $position ) ) ); |
479 | 479 | } |
480 | - wp_die(); |
|
481 | - } |
|
480 | + wp_die(); |
|
481 | + } |
|
482 | 482 | |
483 | 483 | public static function change_type( $type ) { |
484 | - $type_switch = array( |
|
485 | - 'scale' => 'radio', |
|
486 | - '10radio' => 'radio', |
|
487 | - 'rte' => 'textarea', |
|
488 | - 'website' => 'url', |
|
489 | - ); |
|
490 | - if ( isset( $type_switch[ $type ] ) ) { |
|
491 | - $type = $type_switch[ $type ]; |
|
492 | - } |
|
484 | + $type_switch = array( |
|
485 | + 'scale' => 'radio', |
|
486 | + '10radio' => 'radio', |
|
487 | + 'rte' => 'textarea', |
|
488 | + 'website' => 'url', |
|
489 | + ); |
|
490 | + if ( isset( $type_switch[ $type ] ) ) { |
|
491 | + $type = $type_switch[ $type ]; |
|
492 | + } |
|
493 | 493 | |
494 | 494 | $frm_field_selection = FrmField::field_selection(); |
495 | - $types = array_keys($frm_field_selection); |
|
496 | - if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
497 | - $type = 'text'; |
|
498 | - } |
|
495 | + $types = array_keys($frm_field_selection); |
|
496 | + if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
497 | + $type = 'text'; |
|
498 | + } |
|
499 | 499 | |
500 | - return $type; |
|
501 | - } |
|
500 | + return $type; |
|
501 | + } |
|
502 | 502 | |
503 | 503 | public static function display_field_options( $display ) { |
504 | 504 | switch ( $display['type'] ) { |
505 | - case 'captcha': |
|
506 | - $display['required'] = false; |
|
507 | - $display['invalid'] = true; |
|
508 | - $display['default_blank'] = false; |
|
505 | + case 'captcha': |
|
506 | + $display['required'] = false; |
|
507 | + $display['invalid'] = true; |
|
508 | + $display['default_blank'] = false; |
|
509 | 509 | $display['captcha_size'] = true; |
510 | - break; |
|
511 | - case 'radio': |
|
512 | - $display['default_blank'] = false; |
|
513 | - break; |
|
514 | - case 'text': |
|
515 | - case 'textarea': |
|
516 | - $display['size'] = true; |
|
517 | - $display['clear_on_focus'] = true; |
|
518 | - break; |
|
519 | - case 'select': |
|
520 | - $display['size'] = true; |
|
521 | - break; |
|
522 | - case 'url': |
|
523 | - case 'website': |
|
524 | - case 'email': |
|
525 | - $display['size'] = true; |
|
526 | - $display['clear_on_focus'] = true; |
|
527 | - $display['invalid'] = true; |
|
528 | - } |
|
529 | - |
|
530 | - return $display; |
|
531 | - } |
|
532 | - |
|
533 | - public static function input_html( $field, $echo = true ) { |
|
534 | - $class = array(); //$field['type']; |
|
535 | - self::add_input_classes($field, $class); |
|
536 | - |
|
537 | - $add_html = array(); |
|
538 | - self::add_html_size($field, $add_html); |
|
539 | - self::add_html_length($field, $add_html); |
|
540 | - self::add_html_placeholder($field, $add_html, $class); |
|
510 | + break; |
|
511 | + case 'radio': |
|
512 | + $display['default_blank'] = false; |
|
513 | + break; |
|
514 | + case 'text': |
|
515 | + case 'textarea': |
|
516 | + $display['size'] = true; |
|
517 | + $display['clear_on_focus'] = true; |
|
518 | + break; |
|
519 | + case 'select': |
|
520 | + $display['size'] = true; |
|
521 | + break; |
|
522 | + case 'url': |
|
523 | + case 'website': |
|
524 | + case 'email': |
|
525 | + $display['size'] = true; |
|
526 | + $display['clear_on_focus'] = true; |
|
527 | + $display['invalid'] = true; |
|
528 | + } |
|
529 | + |
|
530 | + return $display; |
|
531 | + } |
|
532 | + |
|
533 | + public static function input_html( $field, $echo = true ) { |
|
534 | + $class = array(); //$field['type']; |
|
535 | + self::add_input_classes($field, $class); |
|
536 | + |
|
537 | + $add_html = array(); |
|
538 | + self::add_html_size($field, $add_html); |
|
539 | + self::add_html_length($field, $add_html); |
|
540 | + self::add_html_placeholder($field, $add_html, $class); |
|
541 | 541 | self::add_validation_messages( $field, $add_html ); |
542 | 542 | |
543 | - $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
543 | + $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
544 | 544 | |
545 | 545 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
546 | 546 | |
547 | - self::add_shortcodes_to_html($field, $add_html); |
|
547 | + self::add_shortcodes_to_html($field, $add_html); |
|
548 | 548 | |
549 | 549 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
550 | 550 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
551 | 551 | |
552 | - if ( $echo ) { |
|
553 | - echo $add_html; |
|
554 | - } |
|
552 | + if ( $echo ) { |
|
553 | + echo $add_html; |
|
554 | + } |
|
555 | 555 | |
556 | - return $add_html; |
|
557 | - } |
|
556 | + return $add_html; |
|
557 | + } |
|
558 | 558 | |
559 | 559 | private static function add_input_classes( $field, array &$class ) { |
560 | - if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
561 | - $class[] = $field['input_class']; |
|
562 | - } |
|
560 | + if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
561 | + $class[] = $field['input_class']; |
|
562 | + } |
|
563 | 563 | |
564 | - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
565 | - return; |
|
566 | - } |
|
564 | + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
565 | + return; |
|
566 | + } |
|
567 | 567 | |
568 | - global $frm_vars; |
|
568 | + global $frm_vars; |
|
569 | 569 | if ( is_admin() && ! FrmAppHelper::is_preview_page() && ! in_array( $field['type'], array( 'scale', 'radio', 'checkbox', 'data', 'lookup' ) ) ) { |
570 | 570 | // Add the dyn_default_value class to some field inputs on form builder page |
571 | - $class[] = 'dyn_default_value'; |
|
572 | - } |
|
571 | + $class[] = 'dyn_default_value'; |
|
572 | + } |
|
573 | 573 | |
574 | - if ( isset($field['size']) && $field['size'] > 0 ) { |
|
575 | - $class[] = 'auto_width'; |
|
576 | - } |
|
577 | - } |
|
574 | + if ( isset($field['size']) && $field['size'] > 0 ) { |
|
575 | + $class[] = 'auto_width'; |
|
576 | + } |
|
577 | + } |
|
578 | 578 | |
579 | 579 | private static function add_html_size( $field, array &$add_html ) { |
580 | 580 | if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden', 'lookup' ) ) ) { |
581 | - return; |
|
582 | - } |
|
581 | + return; |
|
582 | + } |
|
583 | 583 | |
584 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
585 | - return; |
|
586 | - } |
|
584 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
585 | + return; |
|
586 | + } |
|
587 | 587 | |
588 | - if ( is_numeric($field['size']) ) { |
|
589 | - $field['size'] .= 'px'; |
|
590 | - } |
|
588 | + if ( is_numeric($field['size']) ) { |
|
589 | + $field['size'] .= 'px'; |
|
590 | + } |
|
591 | 591 | |
592 | - $important = apply_filters('frm_use_important_width', 1, $field); |
|
593 | - // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
592 | + $important = apply_filters('frm_use_important_width', 1, $field); |
|
593 | + // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
594 | 594 | $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"'; |
595 | 595 | |
596 | - self::add_html_cols($field, $add_html); |
|
597 | - } |
|
596 | + self::add_html_cols($field, $add_html); |
|
597 | + } |
|
598 | 598 | |
599 | 599 | private static function add_html_cols( $field, array &$add_html ) { |
600 | 600 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) { |
601 | - return; |
|
602 | - } |
|
601 | + return; |
|
602 | + } |
|
603 | 603 | |
604 | - // convert to cols for textareas |
|
605 | - $calc = array( |
|
606 | - '' => 9, |
|
607 | - 'px' => 9, |
|
608 | - 'rem' => 0.444, |
|
609 | - 'em' => 0.544, |
|
610 | - ); |
|
604 | + // convert to cols for textareas |
|
605 | + $calc = array( |
|
606 | + '' => 9, |
|
607 | + 'px' => 9, |
|
608 | + 'rem' => 0.444, |
|
609 | + 'em' => 0.544, |
|
610 | + ); |
|
611 | 611 | |
612 | - // include "col" for valid html |
|
613 | - $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
612 | + // include "col" for valid html |
|
613 | + $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
614 | 614 | |
615 | - if ( ! isset( $calc[ $unit ] ) ) { |
|
616 | - return; |
|
617 | - } |
|
615 | + if ( ! isset( $calc[ $unit ] ) ) { |
|
616 | + return; |
|
617 | + } |
|
618 | 618 | |
619 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
619 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
620 | 620 | |
621 | 621 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
622 | - } |
|
622 | + } |
|
623 | 623 | |
624 | 624 | private static function add_html_length( $field, array &$add_html ) { |
625 | - // check for max setting and if this field accepts maxlength |
|
625 | + // check for max setting and if this field accepts maxlength |
|
626 | 626 | if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden' ) ) ) { |
627 | - return; |
|
628 | - } |
|
627 | + return; |
|
628 | + } |
|
629 | 629 | |
630 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
631 | - // don't load on form builder page |
|
632 | - return; |
|
633 | - } |
|
630 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
631 | + // don't load on form builder page |
|
632 | + return; |
|
633 | + } |
|
634 | 634 | |
635 | 635 | $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"'; |
636 | - } |
|
636 | + } |
|
637 | 637 | |
638 | 638 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
639 | 639 | if ( empty( $field['default_value'] ) || FrmAppHelper::is_admin_page( 'formidable' ) ) { |
@@ -641,35 +641,35 @@ discard block |
||
641 | 641 | } |
642 | 642 | |
643 | 643 | $default_value_array = is_array( $field['default_value'] ); |
644 | - if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
644 | + if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
645 | 645 | if ( $default_value_array ) { |
646 | 646 | $field['default_value'] = json_encode( $field['default_value'] ); |
647 | 647 | } |
648 | 648 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
649 | - return; |
|
650 | - } |
|
649 | + return; |
|
650 | + } |
|
651 | 651 | |
652 | 652 | if ( $default_value_array ) { |
653 | 653 | // don't include a json placeholder |
654 | 654 | return; |
655 | 655 | } |
656 | 656 | |
657 | - $frm_settings = FrmAppHelper::get_settings(); |
|
657 | + $frm_settings = FrmAppHelper::get_settings(); |
|
658 | 658 | |
659 | 659 | if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) { |
660 | - // use HMTL5 placeholder with js fallback |
|
660 | + // use HMTL5 placeholder with js fallback |
|
661 | 661 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"'; |
662 | - wp_enqueue_script('jquery-placeholder'); |
|
663 | - } else if ( ! $frm_settings->use_html ) { |
|
662 | + wp_enqueue_script('jquery-placeholder'); |
|
663 | + } else if ( ! $frm_settings->use_html ) { |
|
664 | 664 | $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) ); |
665 | 665 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"'; |
666 | - $class[] = 'frm_toggle_default'; |
|
666 | + $class[] = 'frm_toggle_default'; |
|
667 | 667 | |
668 | - if ( $field['value'] == $field['default_value'] ) { |
|
669 | - $class[] = 'frm_default'; |
|
670 | - } |
|
671 | - } |
|
672 | - } |
|
668 | + if ( $field['value'] == $field['default_value'] ) { |
|
669 | + $class[] = 'frm_default'; |
|
670 | + } |
|
671 | + } |
|
672 | + } |
|
673 | 673 | |
674 | 674 | private static function add_validation_messages( $field, array &$add_html ) { |
675 | 675 | if ( FrmField::is_required( $field ) ) { |
@@ -690,44 +690,44 @@ discard block |
||
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
693 | - private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
694 | - if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
695 | - return; |
|
696 | - } |
|
693 | + private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
694 | + if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
695 | + return; |
|
696 | + } |
|
697 | 697 | |
698 | - foreach ( $field['shortcodes'] as $k => $v ) { |
|
699 | - if ( 'opt' === $k ) { |
|
700 | - continue; |
|
701 | - } |
|
698 | + foreach ( $field['shortcodes'] as $k => $v ) { |
|
699 | + if ( 'opt' === $k ) { |
|
700 | + continue; |
|
701 | + } |
|
702 | 702 | |
703 | - if ( is_numeric($k) && strpos($v, '=') ) { |
|
704 | - $add_html[] = $v; |
|
705 | - } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
703 | + if ( is_numeric($k) && strpos($v, '=') ) { |
|
704 | + $add_html[] = $v; |
|
705 | + } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
706 | 706 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
707 | - } else { |
|
707 | + } else { |
|
708 | 708 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
709 | - } |
|
710 | - |
|
711 | - unset($k, $v); |
|
712 | - } |
|
713 | - } |
|
714 | - |
|
715 | - public static function check_value( $opt, $opt_key, $field ) { |
|
716 | - if ( is_array( $opt ) ) { |
|
717 | - if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
718 | - $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
719 | - } else { |
|
720 | - $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
721 | - } |
|
722 | - } |
|
723 | - return $opt; |
|
724 | - } |
|
709 | + } |
|
710 | + |
|
711 | + unset($k, $v); |
|
712 | + } |
|
713 | + } |
|
714 | + |
|
715 | + public static function check_value( $opt, $opt_key, $field ) { |
|
716 | + if ( is_array( $opt ) ) { |
|
717 | + if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
718 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
719 | + } else { |
|
720 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
721 | + } |
|
722 | + } |
|
723 | + return $opt; |
|
724 | + } |
|
725 | 725 | |
726 | 726 | public static function check_label( $opt ) { |
727 | - if ( is_array($opt) ) { |
|
728 | - $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
729 | - } |
|
727 | + if ( is_array($opt) ) { |
|
728 | + $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
729 | + } |
|
730 | 730 | |
731 | - return $opt; |
|
732 | - } |
|
731 | + return $opt; |
|
732 | + } |
|
733 | 733 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | class FrmFieldsController { |
4 | 4 | |
5 | 5 | public static function load_field() { |
6 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
6 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
7 | 7 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
8 | 8 | |
9 | 9 | $fields = $_POST['field']; |
@@ -34,17 +34,17 @@ discard block |
||
34 | 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 | 39 | ob_start(); |
40 | 40 | include( $path . '/classes/views/frm-forms/add_field.php' ); |
41 | - $field_html[ $field_id ] = ob_get_contents(); |
|
41 | + $field_html[$field_id] = ob_get_contents(); |
|
42 | 42 | ob_end_clean(); |
43 | 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 | 49 | wp_die(); |
50 | 50 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * Create a new field with ajax |
54 | 54 | */ |
55 | 55 | public static function create() { |
56 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
56 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
57 | 57 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
58 | 58 | |
59 | 59 | $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $field = self::include_new_field( $field_type, $form_id ); |
63 | 63 | |
64 | 64 | // this hook will allow for multiple fields to be added at once |
65 | - do_action('frm_after_field_created', $field, $form_id); |
|
65 | + do_action( 'frm_after_field_created', $field, $form_id ); |
|
66 | 66 | |
67 | 67 | wp_die(); |
68 | 68 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | public static function include_new_field( $field_type, $form_id ) { |
78 | 78 | $values = array(); |
79 | 79 | if ( FrmAppHelper::pro_is_installed() ) { |
80 | - $values['post_type'] = FrmProFormsHelper::post_type($form_id); |
|
80 | + $values['post_type'] = FrmProFormsHelper::post_type( $form_id ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
@@ -89,27 +89,27 @@ discard block |
||
89 | 89 | return false; |
90 | 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 | 94 | return $field; |
95 | 95 | } |
96 | 96 | |
97 | 97 | public static function edit_name( $field = 'name', $id = '' ) { |
98 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
98 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
99 | 99 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
100 | 100 | |
101 | - if ( empty($field) ) { |
|
101 | + if ( empty( $field ) ) { |
|
102 | 102 | $field = 'name'; |
103 | 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)) == '' ) { |
|
112 | + if ( trim( strip_tags( $value ) ) == '' ) { |
|
113 | 113 | // set blank value if there is no content |
114 | 114 | $value = ''; |
115 | 115 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | public static function update_ajax_option() { |
126 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
126 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
127 | 127 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
128 | 128 | |
129 | 129 | $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' ); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | if ( isset( $_POST['separate_value'] ) ) { |
137 | 137 | $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1; |
138 | 138 | $field->field_options['separate_value'] = $new_val; |
139 | - unset($new_val); |
|
139 | + unset( $new_val ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | FrmField::update( $field_id, array( |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | public static function duplicate() { |
150 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
150 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
151 | 151 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
152 | 152 | |
153 | 153 | global $wpdb; |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | |
173 | 173 | $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values ); |
174 | 174 | |
175 | - if ( ! $field_id = FrmField::create($values) ) { |
|
175 | + if ( ! $field_id = FrmField::create( $values ) ) { |
|
176 | 176 | wp_die(); |
177 | 177 | } |
178 | 178 | |
179 | - self::include_single_field($field_id, $values); |
|
179 | + self::include_single_field( $field_id, $values ); |
|
180 | 180 | |
181 | 181 | wp_die(); |
182 | 182 | } |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | * Load a single field in the form builder along with all needed variables |
186 | 186 | */ |
187 | 187 | public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
188 | - $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
188 | + $field = FrmFieldsHelper::setup_edit_vars( FrmField::getOne( $field_id ) ); |
|
189 | 189 | $field_name = 'item_meta[' . $field_id . ']'; |
190 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
190 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
191 | 191 | $id = $form_id ? $form_id : $field['form_id']; |
192 | 192 | if ( $field['type'] == 'html' ) { |
193 | 193 | $field['stop_filter'] = true; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | public static function destroy() { |
202 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
202 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
203 | 203 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
204 | 204 | |
205 | 205 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | |
212 | 212 | //Add Single Option or Other Option |
213 | 213 | public static function add_option() { |
214 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
214 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
215 | 215 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
216 | 216 | |
217 | 217 | $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
218 | 218 | $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' ); |
219 | 219 | |
220 | 220 | //Get the field |
221 | - $field = FrmField::getOne($id); |
|
221 | + $field = FrmField::getOne( $id ); |
|
222 | 222 | |
223 | 223 | if ( ! empty( $field->options ) ) { |
224 | 224 | $keys = array_keys( $field->options ); |
@@ -241,13 +241,13 @@ discard block |
||
241 | 241 | $first_opt = reset( $field->options ); |
242 | 242 | $next_opt = count( $field->options ); |
243 | 243 | if ( $first_opt != '' ) { |
244 | - $next_opt++; |
|
244 | + $next_opt ++; |
|
245 | 245 | } |
246 | 246 | $opt = esc_html__( 'Option', 'formidable' ) . ' ' . $next_opt; |
247 | - unset($next_opt); |
|
247 | + unset( $next_opt ); |
|
248 | 248 | } |
249 | 249 | $field_val = $opt; |
250 | - $field->options[ $opt_key ] = $opt; |
|
250 | + $field->options[$opt_key] = $opt; |
|
251 | 251 | |
252 | 252 | //Update options in DB |
253 | 253 | FrmField::update( $id, array( 'options' => $field->options ) ); |
@@ -256,13 +256,13 @@ discard block |
||
256 | 256 | $field = array( |
257 | 257 | 'type' => $field_data->type, |
258 | 258 | 'id' => $id, |
259 | - 'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0, |
|
259 | + 'separate_value' => isset( $field_data->field_options['separate_value'] ) ? $field_data->field_options['separate_value'] : 0, |
|
260 | 260 | 'form_id' => $field_data->form_id, |
261 | 261 | 'field_key' => $field_data->field_key, |
262 | 262 | ); |
263 | 263 | |
264 | 264 | $field_name = 'item_meta[' . $id . ']'; |
265 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
265 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
266 | 266 | $checked = ''; |
267 | 267 | |
268 | 268 | if ( 'other' == $opt_type ) { |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | public static function edit_option() { |
277 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
277 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
278 | 278 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
279 | 279 | |
280 | 280 | $element_id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' ); |
@@ -288,28 +288,28 @@ discard block |
||
288 | 288 | $new_label = $update_value; |
289 | 289 | } |
290 | 290 | |
291 | - $field = FrmField::getOne($id); |
|
291 | + $field = FrmField::getOne( $id ); |
|
292 | 292 | $separate_values = FrmField::is_option_true( $field, 'separate_value' ); |
293 | 293 | |
294 | - $this_opt_id = end($ids); |
|
295 | - $this_opt = (array) $field->options[ $this_opt_id ]; |
|
296 | - $other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other') !== false ); |
|
294 | + $this_opt_id = end( $ids ); |
|
295 | + $this_opt = (array) $field->options[$this_opt_id]; |
|
296 | + $other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other' ) !== false ); |
|
297 | 297 | |
298 | - $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt); |
|
299 | - $value = isset($this_opt['value']) ? $this_opt['value'] : ''; |
|
298 | + $label = isset( $this_opt['label'] ) ? $this_opt['label'] : reset( $this_opt ); |
|
299 | + $value = isset( $this_opt['value'] ) ? $this_opt['value'] : ''; |
|
300 | 300 | |
301 | 301 | if ( ! isset( $new_label ) ) { |
302 | 302 | $new_label = $label; |
303 | 303 | } |
304 | 304 | |
305 | - if ( isset($new_value) || isset($value) ) { |
|
306 | - $update_value = isset($new_value) ? $new_value : $value; |
|
305 | + if ( isset( $new_value ) || isset( $value ) ) { |
|
306 | + $update_value = isset( $new_value ) ? $new_value : $value; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | if ( $update_value != $new_label && $other_opt === false && $separate_values ) { |
310 | - $field->options[ $this_opt_id ] = array( 'value' => $update_value, 'label' => $new_label ); |
|
310 | + $field->options[$this_opt_id] = array( 'value' => $update_value, 'label' => $new_label ); |
|
311 | 311 | } else { |
312 | - $field->options[ $this_opt_id ] = $orig_update_value; |
|
312 | + $field->options[$this_opt_id] = $orig_update_value; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | FrmField::update( $field->id, array( 'options' => $field->options ) ); |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | } |
319 | 319 | |
320 | 320 | public static function delete_option() { |
321 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
321 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
322 | 322 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
323 | 323 | |
324 | 324 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'sanitize_title' ); |
328 | 328 | |
329 | 329 | $options = $field->options; |
330 | - unset( $options[ $opt_key ] ); |
|
330 | + unset( $options[$opt_key] ); |
|
331 | 331 | $response = array( 'other' => true ); |
332 | 332 | |
333 | 333 | //If the deleted option is an "other" option |
@@ -393,9 +393,9 @@ discard block |
||
393 | 393 | |
394 | 394 | $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
395 | 395 | $prepop = array(); |
396 | - FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
396 | + FrmFieldsHelper::get_bulk_prefilled_opts( $prepop ); |
|
397 | 397 | |
398 | - $field = FrmField::getOne($field_id); |
|
398 | + $field = FrmField::getOne( $field_id ); |
|
399 | 399 | |
400 | 400 | wp_enqueue_script( 'utils' ); |
401 | 401 | wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' ); |
@@ -406,35 +406,35 @@ discard block |
||
406 | 406 | } |
407 | 407 | |
408 | 408 | public static function import_options() { |
409 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
409 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
410 | 410 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
411 | 411 | |
412 | - if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
412 | + if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
|
413 | 413 | return; |
414 | 414 | } |
415 | 415 | |
416 | 416 | $field_id = absint( $_POST['field_id'] ); |
417 | - $field = FrmField::getOne($field_id); |
|
417 | + $field = FrmField::getOne( $field_id ); |
|
418 | 418 | |
419 | 419 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { |
420 | 420 | return; |
421 | 421 | } |
422 | 422 | |
423 | - $field = FrmFieldsHelper::setup_edit_vars($field); |
|
423 | + $field = FrmFieldsHelper::setup_edit_vars( $field ); |
|
424 | 424 | $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); |
425 | 425 | $opts = explode( "\n", rtrim( $opts, "\n" ) ); |
426 | 426 | $opts = array_map( 'trim', $opts ); |
427 | 427 | |
428 | 428 | if ( $field['separate_value'] ) { |
429 | 429 | foreach ( $opts as $opt_key => $opt ) { |
430 | - if ( strpos($opt, '|') !== false ) { |
|
431 | - $vals = explode('|', $opt); |
|
430 | + if ( strpos( $opt, '|' ) !== false ) { |
|
431 | + $vals = explode( '|', $opt ); |
|
432 | 432 | if ( $vals[0] != $vals[1] ) { |
433 | - $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
433 | + $opts[$opt_key] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
434 | 434 | } |
435 | - unset($vals); |
|
435 | + unset( $vals ); |
|
436 | 436 | } |
437 | - unset($opt_key, $opt); |
|
437 | + unset( $opt_key, $opt ); |
|
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
@@ -443,12 +443,12 @@ discard block |
||
443 | 443 | $other_array = array(); |
444 | 444 | foreach ( $field['options'] as $opt_key => $opt ) { |
445 | 445 | if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
446 | - $other_array[ $opt_key ] = $opt; |
|
446 | + $other_array[$opt_key] = $opt; |
|
447 | 447 | } |
448 | - unset($opt_key, $opt); |
|
448 | + unset( $opt_key, $opt ); |
|
449 | 449 | } |
450 | - if ( ! empty($other_array) ) { |
|
451 | - $opts = array_merge( $opts, $other_array); |
|
450 | + if ( ! empty( $other_array ) ) { |
|
451 | + $opts = array_merge( $opts, $other_array ); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
@@ -463,14 +463,14 @@ discard block |
||
463 | 463 | if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
464 | 464 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); |
465 | 465 | } else { |
466 | - FrmFieldsHelper::show_single_option($field); |
|
466 | + FrmFieldsHelper::show_single_option( $field ); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | wp_die(); |
470 | 470 | } |
471 | 471 | |
472 | 472 | public static function update_order() { |
473 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
473 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
474 | 474 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
475 | 475 | |
476 | 476 | $fields = FrmAppHelper::get_post_param( 'frm_field_id' ); |
@@ -487,13 +487,13 @@ discard block |
||
487 | 487 | 'rte' => 'textarea', |
488 | 488 | 'website' => 'url', |
489 | 489 | ); |
490 | - if ( isset( $type_switch[ $type ] ) ) { |
|
491 | - $type = $type_switch[ $type ]; |
|
490 | + if ( isset( $type_switch[$type] ) ) { |
|
491 | + $type = $type_switch[$type]; |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | $frm_field_selection = FrmField::field_selection(); |
495 | - $types = array_keys($frm_field_selection); |
|
496 | - if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
495 | + $types = array_keys( $frm_field_selection ); |
|
496 | + if ( ! in_array( $type, $types ) && $type != 'captcha' ) { |
|
497 | 497 | $type = 'text'; |
498 | 498 | } |
499 | 499 | |
@@ -532,19 +532,19 @@ discard block |
||
532 | 532 | |
533 | 533 | public static function input_html( $field, $echo = true ) { |
534 | 534 | $class = array(); //$field['type']; |
535 | - self::add_input_classes($field, $class); |
|
535 | + self::add_input_classes( $field, $class ); |
|
536 | 536 | |
537 | 537 | $add_html = array(); |
538 | - self::add_html_size($field, $add_html); |
|
539 | - self::add_html_length($field, $add_html); |
|
540 | - self::add_html_placeholder($field, $add_html, $class); |
|
538 | + self::add_html_size( $field, $add_html ); |
|
539 | + self::add_html_length( $field, $add_html ); |
|
540 | + self::add_html_placeholder( $field, $add_html, $class ); |
|
541 | 541 | self::add_validation_messages( $field, $add_html ); |
542 | 542 | |
543 | - $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
543 | + $class = apply_filters( 'frm_field_classes', implode( ' ', $class ), $field ); |
|
544 | 544 | |
545 | 545 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
546 | 546 | |
547 | - self::add_shortcodes_to_html($field, $add_html); |
|
547 | + self::add_shortcodes_to_html( $field, $add_html ); |
|
548 | 548 | |
549 | 549 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
550 | 550 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | } |
558 | 558 | |
559 | 559 | private static function add_input_classes( $field, array &$class ) { |
560 | - if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
560 | + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) { |
|
561 | 561 | $class[] = $field['input_class']; |
562 | 562 | } |
563 | 563 | |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | $class[] = 'dyn_default_value'; |
572 | 572 | } |
573 | 573 | |
574 | - if ( isset($field['size']) && $field['size'] > 0 ) { |
|
574 | + if ( isset( $field['size'] ) && $field['size'] > 0 ) { |
|
575 | 575 | $class[] = 'auto_width'; |
576 | 576 | } |
577 | 577 | } |
@@ -581,19 +581,19 @@ discard block |
||
581 | 581 | return; |
582 | 582 | } |
583 | 583 | |
584 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
584 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
585 | 585 | return; |
586 | 586 | } |
587 | 587 | |
588 | - if ( is_numeric($field['size']) ) { |
|
588 | + if ( is_numeric( $field['size'] ) ) { |
|
589 | 589 | $field['size'] .= 'px'; |
590 | 590 | } |
591 | 591 | |
592 | - $important = apply_filters('frm_use_important_width', 1, $field); |
|
592 | + $important = apply_filters( 'frm_use_important_width', 1, $field ); |
|
593 | 593 | // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
594 | 594 | $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"'; |
595 | 595 | |
596 | - self::add_html_cols($field, $add_html); |
|
596 | + self::add_html_cols( $field, $add_html ); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | private static function add_html_cols( $field, array &$add_html ) { |
@@ -610,13 +610,13 @@ discard block |
||
610 | 610 | ); |
611 | 611 | |
612 | 612 | // include "col" for valid html |
613 | - $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
613 | + $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
|
614 | 614 | |
615 | - if ( ! isset( $calc[ $unit ] ) ) { |
|
615 | + if ( ! isset( $calc[$unit] ) ) { |
|
616 | 616 | return; |
617 | 617 | } |
618 | 618 | |
619 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
619 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[$unit]; |
|
620 | 620 | |
621 | 621 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
622 | 622 | } |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | return; |
628 | 628 | } |
629 | 629 | |
630 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
630 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
631 | 631 | // don't load on form builder page |
632 | 632 | return; |
633 | 633 | } |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) { |
660 | 660 | // use HMTL5 placeholder with js fallback |
661 | 661 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"'; |
662 | - wp_enqueue_script('jquery-placeholder'); |
|
662 | + wp_enqueue_script( 'jquery-placeholder' ); |
|
663 | 663 | } else if ( ! $frm_settings->use_html ) { |
664 | 664 | $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) ); |
665 | 665 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"'; |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | $format = FrmEntryValidate::phone_format( $field ); |
687 | 687 | $format = substr( $format, 2, -2 ); |
688 | 688 | $key = 'pattern'; |
689 | - $add_html[ $key ] = $key . '="' . esc_attr( $format ) . '"'; |
|
689 | + $add_html[$key] = $key . '="' . esc_attr( $format ) . '"'; |
|
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
@@ -700,15 +700,15 @@ discard block |
||
700 | 700 | continue; |
701 | 701 | } |
702 | 702 | |
703 | - if ( is_numeric($k) && strpos($v, '=') ) { |
|
703 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { |
|
704 | 704 | $add_html[] = $v; |
705 | - } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
706 | - $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
|
705 | + } else if ( ! empty( $k ) && isset( $add_html[$k] ) ) { |
|
706 | + $add_html[$k] = str_replace( $k . '="', $k . '="' . $v, $add_html[$k] ); |
|
707 | 707 | } else { |
708 | - $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
|
708 | + $add_html[$k] = $k . '="' . esc_attr( $v ) . '"'; |
|
709 | 709 | } |
710 | 710 | |
711 | - unset($k, $v); |
|
711 | + unset( $k, $v ); |
|
712 | 712 | } |
713 | 713 | } |
714 | 714 | |
@@ -724,8 +724,8 @@ discard block |
||
724 | 724 | } |
725 | 725 | |
726 | 726 | public static function check_label( $opt ) { |
727 | - if ( is_array($opt) ) { |
|
728 | - $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
727 | + if ( is_array( $opt ) ) { |
|
728 | + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | return $opt; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | public $id = 0; // the id of the post |
5 | 5 | |
6 | 6 | /** |
7 | - * @param int|string $id The id of the stylsheet or 'default' |
|
7 | + * @param integer $id The id of the stylsheet or 'default' |
|
8 | 8 | */ |
9 | 9 | public function __construct( $id = 0 ) { |
10 | 10 | $this->id = $id; |
@@ -120,6 +120,9 @@ discard block |
||
120 | 120 | set_transient('frmpro_css', $css); |
121 | 121 | } |
122 | 122 | |
123 | + /** |
|
124 | + * @param string $filename |
|
125 | + */ |
|
123 | 126 | private function get_css_content( $filename ) { |
124 | 127 | $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n"; |
125 | 128 |
@@ -1,52 +1,52 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class FrmStyle { |
3 | - public $number = false; // Unique ID number of the current instance. |
|
3 | + public $number = false; // Unique ID number of the current instance. |
|
4 | 4 | public $id = 0; // the id of the post |
5 | 5 | |
6 | 6 | /** |
7 | 7 | * @param int|string $id The id of the stylsheet or 'default' |
8 | 8 | */ |
9 | 9 | public function __construct( $id = 0 ) { |
10 | - $this->id = $id; |
|
11 | - } |
|
10 | + $this->id = $id; |
|
11 | + } |
|
12 | 12 | |
13 | - public function get_new() { |
|
13 | + public function get_new() { |
|
14 | 14 | $this->id = 0; |
15 | 15 | |
16 | - $max_slug_value = pow(36, 6); |
|
17 | - $min_slug_value = 37; // we want to have at least 2 characters in the slug |
|
18 | - $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
19 | - |
|
20 | - $style = array( |
|
21 | - 'post_type' => FrmStylesController::$post_type, |
|
22 | - 'ID' => '', |
|
23 | - 'post_title' => __( 'New Style', 'formidable' ), |
|
24 | - 'post_name' => $key, |
|
25 | - 'post_content' => $this->get_defaults(), |
|
26 | - 'menu_order' => '', |
|
27 | - 'post_status' => 'publish', |
|
28 | - ); |
|
16 | + $max_slug_value = pow(36, 6); |
|
17 | + $min_slug_value = 37; // we want to have at least 2 characters in the slug |
|
18 | + $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
19 | + |
|
20 | + $style = array( |
|
21 | + 'post_type' => FrmStylesController::$post_type, |
|
22 | + 'ID' => '', |
|
23 | + 'post_title' => __( 'New Style', 'formidable' ), |
|
24 | + 'post_name' => $key, |
|
25 | + 'post_content' => $this->get_defaults(), |
|
26 | + 'menu_order' => '', |
|
27 | + 'post_status' => 'publish', |
|
28 | + ); |
|
29 | 29 | |
30 | - return (object) $style; |
|
31 | - } |
|
30 | + return (object) $style; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | public function save( $settings ) { |
34 | 34 | return FrmAppHelper::save_settings( $settings, 'frm_styles' ); |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | 37 | public function duplicate( $id ) { |
38 | - // duplicating is a pro feature |
|
39 | - } |
|
38 | + // duplicating is a pro feature |
|
39 | + } |
|
40 | 40 | |
41 | - public function update( $id = 'default' ) { |
|
41 | + public function update( $id = 'default' ) { |
|
42 | 42 | $all_instances = $this->get_all(); |
43 | 43 | |
44 | 44 | if ( empty($id) ) { |
45 | - $new_style = (array) $this->get_new(); |
|
46 | - $all_instances[] = $new_style; |
|
45 | + $new_style = (array) $this->get_new(); |
|
46 | + $all_instances[] = $new_style; |
|
47 | 47 | } |
48 | 48 | |
49 | - $action_ids = array(); |
|
49 | + $action_ids = array(); |
|
50 | 50 | |
51 | 51 | foreach ( $all_instances as $number => $new_instance ) { |
52 | 52 | $new_instance = stripslashes_deep( (array) $new_instance); |
@@ -54,42 +54,42 @@ discard block |
||
54 | 54 | if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) { |
55 | 55 | $all_instances[ $number ] = $new_instance; |
56 | 56 | |
57 | - if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) { |
|
58 | - // this style was set to default, so remove default setting on previous default style |
|
59 | - $new_instance['menu_order'] = 0; |
|
60 | - $action_ids[] = $this->save($new_instance); |
|
61 | - } |
|
57 | + if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) { |
|
58 | + // this style was set to default, so remove default setting on previous default style |
|
59 | + $new_instance['menu_order'] = 0; |
|
60 | + $action_ids[] = $this->save($new_instance); |
|
61 | + } |
|
62 | 62 | |
63 | - // don't continue if not saving this style |
|
64 | - continue; |
|
63 | + // don't continue if not saving this style |
|
64 | + continue; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | $new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] ); |
68 | 68 | $new_instance['post_content'] = $_POST['frm_style_setting']['post_content']; |
69 | 69 | $new_instance['post_type'] = FrmStylesController::$post_type; |
70 | - $new_instance['post_status'] = 'publish'; |
|
70 | + $new_instance['post_status'] = 'publish'; |
|
71 | 71 | $new_instance['menu_order'] = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0; |
72 | 72 | |
73 | - if ( empty($id) ) { |
|
74 | - $new_instance['post_name'] = $new_instance['post_title']; |
|
75 | - } |
|
73 | + if ( empty($id) ) { |
|
74 | + $new_instance['post_name'] = $new_instance['post_title']; |
|
75 | + } |
|
76 | 76 | |
77 | - $default_settings = $this->get_defaults(); |
|
77 | + $default_settings = $this->get_defaults(); |
|
78 | 78 | |
79 | - foreach ( $default_settings as $setting => $default ) { |
|
79 | + foreach ( $default_settings as $setting => $default ) { |
|
80 | 80 | if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) { |
81 | - //if is a color |
|
81 | + //if is a color |
|
82 | 82 | $new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] ); |
83 | 83 | } else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) { |
84 | 84 | $new_instance['post_content'][ $setting ] = 0; |
85 | - } else if ( $setting == 'font' ) { |
|
86 | - $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] ); |
|
87 | - } |
|
88 | - } |
|
85 | + } else if ( $setting == 'font' ) { |
|
86 | + $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] ); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | 90 | $all_instances[ $number ] = $new_instance; |
91 | 91 | |
92 | - $action_ids[] = $this->save($new_instance); |
|
92 | + $action_ids[] = $this->save($new_instance); |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
@@ -98,26 +98,26 @@ discard block |
||
98 | 98 | return $action_ids; |
99 | 99 | } |
100 | 100 | |
101 | - /** |
|
102 | - * Create static css file |
|
103 | - */ |
|
101 | + /** |
|
102 | + * Create static css file |
|
103 | + */ |
|
104 | 104 | public function save_settings( $styles ) { |
105 | 105 | $filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php'; |
106 | 106 | update_option( 'frm_last_style_update', date('njGi') ); |
107 | 107 | |
108 | - if ( ! is_file($filename) ) { |
|
109 | - return; |
|
110 | - } |
|
108 | + if ( ! is_file($filename) ) { |
|
109 | + return; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | $css = $this->get_css_content( $filename ); |
113 | 113 | |
114 | 114 | $create_file = new FrmCreateFile( array( 'folder_name' => 'formidable/css', 'file_name' => 'formidablepro.css' ) ); |
115 | 115 | $create_file->create_file( $css ); |
116 | 116 | |
117 | - update_option('frmpro_css', $css); |
|
117 | + update_option('frmpro_css', $css); |
|
118 | 118 | |
119 | - delete_transient('frmpro_css'); |
|
120 | - set_transient('frmpro_css', $css); |
|
119 | + delete_transient('frmpro_css'); |
|
120 | + set_transient('frmpro_css', $css); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | private function get_css_content( $filename ) { |
@@ -126,280 +126,280 @@ discard block |
||
126 | 126 | $saving = true; |
127 | 127 | $frm_style = $this; |
128 | 128 | |
129 | - ob_start(); |
|
130 | - include( $filename ); |
|
129 | + ob_start(); |
|
130 | + include( $filename ); |
|
131 | 131 | $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) ); |
132 | - ob_end_clean(); |
|
132 | + ob_end_clean(); |
|
133 | 133 | |
134 | 134 | return $css; |
135 | 135 | } |
136 | 136 | |
137 | 137 | public function destroy( $id ) { |
138 | - return wp_delete_post($id); |
|
139 | - } |
|
138 | + return wp_delete_post($id); |
|
139 | + } |
|
140 | 140 | |
141 | - public function get_one() { |
|
142 | - if ( 'default' == $this->id ) { |
|
143 | - $style = $this->get_default_style(); |
|
144 | - if ( $style ) { |
|
145 | - $this->id = $style->ID; |
|
146 | - } else { |
|
147 | - $this->id = 0; |
|
148 | - } |
|
149 | - return $style; |
|
150 | - } |
|
141 | + public function get_one() { |
|
142 | + if ( 'default' == $this->id ) { |
|
143 | + $style = $this->get_default_style(); |
|
144 | + if ( $style ) { |
|
145 | + $this->id = $style->ID; |
|
146 | + } else { |
|
147 | + $this->id = 0; |
|
148 | + } |
|
149 | + return $style; |
|
150 | + } |
|
151 | 151 | |
152 | - $style = get_post($this->id); |
|
152 | + $style = get_post($this->id); |
|
153 | 153 | |
154 | - if ( ! $style ) { |
|
155 | - return $style; |
|
156 | - } |
|
154 | + if ( ! $style ) { |
|
155 | + return $style; |
|
156 | + } |
|
157 | 157 | |
158 | - $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
158 | + $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
159 | 159 | |
160 | - $default_values = $this->get_defaults(); |
|
160 | + $default_values = $this->get_defaults(); |
|
161 | 161 | |
162 | - // fill default values |
|
163 | - $style->post_content = $this->override_defaults($style->post_content); |
|
164 | - $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
162 | + // fill default values |
|
163 | + $style->post_content = $this->override_defaults($style->post_content); |
|
164 | + $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
165 | 165 | |
166 | - return $style; |
|
167 | - } |
|
166 | + return $style; |
|
167 | + } |
|
168 | 168 | |
169 | - public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) { |
|
170 | - $post_atts = array( |
|
169 | + public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) { |
|
170 | + $post_atts = array( |
|
171 | 171 | 'post_type' => FrmStylesController::$post_type, |
172 | 172 | 'post_status' => 'publish', |
173 | 173 | 'numberposts' => $limit, |
174 | 174 | 'orderby' => $orderby, |
175 | 175 | 'order' => $order, |
176 | - ); |
|
176 | + ); |
|
177 | 177 | |
178 | - $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts'); |
|
178 | + $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts'); |
|
179 | 179 | |
180 | - if ( empty($temp_styles) ) { |
|
181 | - global $wpdb; |
|
182 | - // make sure there wasn't a conflict with the query |
|
180 | + if ( empty($temp_styles) ) { |
|
181 | + global $wpdb; |
|
182 | + // make sure there wasn't a conflict with the query |
|
183 | 183 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' ); |
184 | - $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results'); |
|
185 | - |
|
186 | - if ( empty($temp_styles) ) { |
|
187 | - // create a new style if there are none |
|
188 | - $new = $this->get_new(); |
|
189 | - $new->post_title = $new->post_name = __( 'Formidable Style', 'formidable' ); |
|
190 | - $new->menu_order = 1; |
|
191 | - $new = $this->save( (array) $new); |
|
192 | - $this->update('default'); |
|
193 | - |
|
194 | - $post_atts['include'] = $new; |
|
195 | - |
|
196 | - $temp_styles = get_posts( $post_atts ); |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - $default_values = $this->get_defaults(); |
|
201 | - $default_style = false; |
|
202 | - |
|
203 | - $styles = array(); |
|
204 | - foreach ( $temp_styles as $style ) { |
|
205 | - $this->id = $style->ID; |
|
206 | - if ( $style->menu_order ) { |
|
207 | - if ( $default_style ) { |
|
208 | - // only return one default |
|
209 | - $style->menu_order = 0; |
|
210 | - } else { |
|
211 | - // check for a default style |
|
212 | - $default_style = $style->ID; |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
217 | - |
|
218 | - // fill default values |
|
219 | - $style->post_content = $this->override_defaults($style->post_content); |
|
220 | - $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
184 | + $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results'); |
|
185 | + |
|
186 | + if ( empty($temp_styles) ) { |
|
187 | + // create a new style if there are none |
|
188 | + $new = $this->get_new(); |
|
189 | + $new->post_title = $new->post_name = __( 'Formidable Style', 'formidable' ); |
|
190 | + $new->menu_order = 1; |
|
191 | + $new = $this->save( (array) $new); |
|
192 | + $this->update('default'); |
|
193 | + |
|
194 | + $post_atts['include'] = $new; |
|
195 | + |
|
196 | + $temp_styles = get_posts( $post_atts ); |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + $default_values = $this->get_defaults(); |
|
201 | + $default_style = false; |
|
202 | + |
|
203 | + $styles = array(); |
|
204 | + foreach ( $temp_styles as $style ) { |
|
205 | + $this->id = $style->ID; |
|
206 | + if ( $style->menu_order ) { |
|
207 | + if ( $default_style ) { |
|
208 | + // only return one default |
|
209 | + $style->menu_order = 0; |
|
210 | + } else { |
|
211 | + // check for a default style |
|
212 | + $default_style = $style->ID; |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
217 | + |
|
218 | + // fill default values |
|
219 | + $style->post_content = $this->override_defaults($style->post_content); |
|
220 | + $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
221 | 221 | |
222 | 222 | $styles[ $style->ID ] = $style; |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | - if ( ! $default_style ) { |
|
226 | - $default_style = reset($styles); |
|
225 | + if ( ! $default_style ) { |
|
226 | + $default_style = reset($styles); |
|
227 | 227 | $styles[ $default_style->ID ]->menu_order = 1; |
228 | - } |
|
228 | + } |
|
229 | 229 | |
230 | - return $styles; |
|
231 | - } |
|
230 | + return $styles; |
|
231 | + } |
|
232 | 232 | |
233 | 233 | public function get_default_style( $styles = null ) { |
234 | - if ( ! isset($styles) ) { |
|
234 | + if ( ! isset($styles) ) { |
|
235 | 235 | $styles = $this->get_all( 'menu_order', 'DESC', 1 ); |
236 | - } |
|
236 | + } |
|
237 | 237 | |
238 | - foreach ( $styles as $style ) { |
|
239 | - if ( $style->menu_order ) { |
|
240 | - return $style; |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
238 | + foreach ( $styles as $style ) { |
|
239 | + if ( $style->menu_order ) { |
|
240 | + return $style; |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | 245 | public function override_defaults( $settings ) { |
246 | - if ( ! is_array($settings) ) { |
|
247 | - return $settings; |
|
248 | - } |
|
249 | - |
|
250 | - $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height']; |
|
251 | - |
|
252 | - if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) { |
|
253 | - $settings['form_desc_size'] = $settings['description_font_size']; |
|
254 | - $settings['form_desc_color'] = $settings['description_color']; |
|
255 | - $settings['title_color'] = $settings['label_color']; |
|
256 | - } |
|
257 | - |
|
258 | - if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) { |
|
259 | - $settings['section_color'] = $settings['label_color']; |
|
260 | - $settings['section_border_color'] = $settings['border_color']; |
|
261 | - } |
|
262 | - |
|
263 | - if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) { |
|
264 | - $settings['submit_hover_bg_color'] = $settings['submit_bg_color']; |
|
265 | - $settings['submit_hover_color'] = $settings['submit_text_color']; |
|
266 | - $settings['submit_hover_border_color'] = $settings['submit_border_color']; |
|
267 | - |
|
268 | - $settings['submit_active_bg_color'] = $settings['submit_bg_color']; |
|
269 | - $settings['submit_active_color'] = $settings['submit_text_color']; |
|
270 | - $settings['submit_active_border_color'] = $settings['submit_border_color']; |
|
271 | - } |
|
272 | - |
|
273 | - return $settings; |
|
246 | + if ( ! is_array($settings) ) { |
|
247 | + return $settings; |
|
248 | + } |
|
249 | + |
|
250 | + $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height']; |
|
251 | + |
|
252 | + if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) { |
|
253 | + $settings['form_desc_size'] = $settings['description_font_size']; |
|
254 | + $settings['form_desc_color'] = $settings['description_color']; |
|
255 | + $settings['title_color'] = $settings['label_color']; |
|
256 | + } |
|
257 | + |
|
258 | + if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) { |
|
259 | + $settings['section_color'] = $settings['label_color']; |
|
260 | + $settings['section_border_color'] = $settings['border_color']; |
|
261 | + } |
|
262 | + |
|
263 | + if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) { |
|
264 | + $settings['submit_hover_bg_color'] = $settings['submit_bg_color']; |
|
265 | + $settings['submit_hover_color'] = $settings['submit_text_color']; |
|
266 | + $settings['submit_hover_border_color'] = $settings['submit_border_color']; |
|
267 | + |
|
268 | + $settings['submit_active_bg_color'] = $settings['submit_bg_color']; |
|
269 | + $settings['submit_active_color'] = $settings['submit_text_color']; |
|
270 | + $settings['submit_active_border_color'] = $settings['submit_border_color']; |
|
271 | + } |
|
272 | + |
|
273 | + return $settings; |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | public function get_defaults() { |
277 | - return array( |
|
278 | - 'theme_css' => 'ui-lightness', |
|
279 | - 'theme_name' => 'UI Lightness', |
|
277 | + return array( |
|
278 | + 'theme_css' => 'ui-lightness', |
|
279 | + 'theme_name' => 'UI Lightness', |
|
280 | 280 | |
281 | 281 | 'center_form' => '', |
282 | - 'form_width' => '100%', |
|
283 | - 'form_align' => 'left', |
|
284 | - 'direction' => is_rtl() ? 'rtl' : 'ltr', |
|
285 | - 'fieldset' => '0px', |
|
286 | - 'fieldset_color' => '000000', |
|
287 | - 'fieldset_padding' => '0 0 15px 0', |
|
288 | - 'fieldset_bg_color' => '', |
|
289 | - |
|
290 | - 'title_size' => '20px', |
|
291 | - 'title_color' => '444444', |
|
282 | + 'form_width' => '100%', |
|
283 | + 'form_align' => 'left', |
|
284 | + 'direction' => is_rtl() ? 'rtl' : 'ltr', |
|
285 | + 'fieldset' => '0px', |
|
286 | + 'fieldset_color' => '000000', |
|
287 | + 'fieldset_padding' => '0 0 15px 0', |
|
288 | + 'fieldset_bg_color' => '', |
|
289 | + |
|
290 | + 'title_size' => '20px', |
|
291 | + 'title_color' => '444444', |
|
292 | 292 | 'title_margin_top' => '10px', |
293 | 293 | 'title_margin_bottom' => '10px', |
294 | - 'form_desc_size' => '14px', |
|
295 | - 'form_desc_color' => '666666', |
|
294 | + 'form_desc_size' => '14px', |
|
295 | + 'form_desc_color' => '666666', |
|
296 | 296 | 'form_desc_margin_top' => '10px', |
297 | 297 | 'form_desc_margin_bottom' => '25px', |
298 | 298 | |
299 | - 'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif', |
|
300 | - 'font_size' => '14px', |
|
301 | - 'label_color' => '444444', |
|
302 | - 'weight' => 'bold', |
|
303 | - 'position' => 'none', |
|
304 | - 'align' => 'left', |
|
305 | - 'width' => '150px', |
|
306 | - 'required_color' => 'B94A48', |
|
307 | - 'required_weight' => 'bold', |
|
308 | - 'label_padding' => '0 0 3px 0', |
|
309 | - |
|
310 | - 'description_font_size' => '12px', |
|
311 | - 'description_color' => '666666', |
|
312 | - 'description_weight' => 'normal', |
|
313 | - 'description_style' => 'normal', |
|
314 | - 'description_align' => 'left', |
|
315 | - |
|
316 | - 'field_font_size' => '14px', |
|
317 | - 'field_height' => '32px', |
|
318 | - 'line_height' => 'normal', |
|
319 | - 'field_width' => '100%', |
|
320 | - 'auto_width' => false, |
|
321 | - 'field_pad' => '6px 10px', |
|
322 | - 'field_margin' => '20px', |
|
299 | + 'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif', |
|
300 | + 'font_size' => '14px', |
|
301 | + 'label_color' => '444444', |
|
302 | + 'weight' => 'bold', |
|
303 | + 'position' => 'none', |
|
304 | + 'align' => 'left', |
|
305 | + 'width' => '150px', |
|
306 | + 'required_color' => 'B94A48', |
|
307 | + 'required_weight' => 'bold', |
|
308 | + 'label_padding' => '0 0 3px 0', |
|
309 | + |
|
310 | + 'description_font_size' => '12px', |
|
311 | + 'description_color' => '666666', |
|
312 | + 'description_weight' => 'normal', |
|
313 | + 'description_style' => 'normal', |
|
314 | + 'description_align' => 'left', |
|
315 | + |
|
316 | + 'field_font_size' => '14px', |
|
317 | + 'field_height' => '32px', |
|
318 | + 'line_height' => 'normal', |
|
319 | + 'field_width' => '100%', |
|
320 | + 'auto_width' => false, |
|
321 | + 'field_pad' => '6px 10px', |
|
322 | + 'field_margin' => '20px', |
|
323 | 323 | 'field_weight' => 'normal', |
324 | - 'text_color' => '555555', |
|
325 | - //'border_color_hv' => 'cccccc', |
|
326 | - 'border_color' => 'cccccc', |
|
327 | - 'field_border_width' => '1px', |
|
328 | - 'field_border_style' => 'solid', |
|
329 | - |
|
330 | - 'bg_color' => 'ffffff', |
|
331 | - //'bg_color_hv' => 'ffffff', |
|
324 | + 'text_color' => '555555', |
|
325 | + //'border_color_hv' => 'cccccc', |
|
326 | + 'border_color' => 'cccccc', |
|
327 | + 'field_border_width' => '1px', |
|
328 | + 'field_border_style' => 'solid', |
|
329 | + |
|
330 | + 'bg_color' => 'ffffff', |
|
331 | + //'bg_color_hv' => 'ffffff', |
|
332 | 332 | 'remove_box_shadow' => '', |
333 | - 'bg_color_active' => 'ffffff', |
|
333 | + 'bg_color_active' => 'ffffff', |
|
334 | 334 | 'border_color_active' => '66afe9', |
335 | 335 | 'remove_box_shadow_active' => '', |
336 | - 'text_color_error' => '444444', |
|
337 | - 'bg_color_error' => 'ffffff', |
|
336 | + 'text_color_error' => '444444', |
|
337 | + 'bg_color_error' => 'ffffff', |
|
338 | 338 | 'border_color_error' => 'B94A48', |
339 | 339 | 'border_width_error' => '1px', |
340 | 340 | 'border_style_error' => 'solid', |
341 | - 'bg_color_disabled' => 'ffffff', |
|
342 | - 'border_color_disabled' => 'E5E5E5', |
|
343 | - 'text_color_disabled' => 'A1A1A1', |
|
344 | - |
|
345 | - 'radio_align' => 'block', |
|
346 | - 'check_align' => 'block', |
|
347 | - 'check_font_size' => '13px', |
|
348 | - 'check_label_color' => '444444', |
|
349 | - 'check_weight' => 'normal', |
|
350 | - |
|
351 | - 'section_font_size' => '18px', |
|
352 | - 'section_color' => '444444', |
|
353 | - 'section_weight' => 'bold', |
|
354 | - 'section_pad' => '15px 0 3px 0', |
|
355 | - 'section_mar_top' => '15px', |
|
341 | + 'bg_color_disabled' => 'ffffff', |
|
342 | + 'border_color_disabled' => 'E5E5E5', |
|
343 | + 'text_color_disabled' => 'A1A1A1', |
|
344 | + |
|
345 | + 'radio_align' => 'block', |
|
346 | + 'check_align' => 'block', |
|
347 | + 'check_font_size' => '13px', |
|
348 | + 'check_label_color' => '444444', |
|
349 | + 'check_weight' => 'normal', |
|
350 | + |
|
351 | + 'section_font_size' => '18px', |
|
352 | + 'section_color' => '444444', |
|
353 | + 'section_weight' => 'bold', |
|
354 | + 'section_pad' => '15px 0 3px 0', |
|
355 | + 'section_mar_top' => '15px', |
|
356 | 356 | 'section_mar_bottom' => '12px', |
357 | - 'section_bg_color' => '', |
|
358 | - 'section_border_color' => 'e8e8e8', |
|
359 | - 'section_border_width' => '2px', |
|
360 | - 'section_border_style' => 'solid', |
|
361 | - 'section_border_loc' => '-top', |
|
362 | - 'collapse_icon' => '6', |
|
363 | - 'collapse_pos' => 'after', |
|
364 | - 'repeat_icon' => '1', |
|
365 | - |
|
366 | - 'submit_style' => false, |
|
367 | - 'submit_font_size' => '14px', |
|
368 | - 'submit_width' => 'auto', |
|
369 | - 'submit_height' => 'auto', |
|
370 | - 'submit_bg_color' => 'ffffff', |
|
371 | - 'submit_border_color' => 'cccccc', |
|
372 | - 'submit_border_width' => '1px', |
|
373 | - 'submit_text_color' => '444444', |
|
374 | - 'submit_weight' => 'normal', |
|
375 | - 'submit_border_radius' => '4px', |
|
376 | - 'submit_bg_img' => '', |
|
377 | - 'submit_margin' => '10px', |
|
378 | - 'submit_padding' => '6px 11px', |
|
379 | - 'submit_shadow_color' => 'eeeeee', |
|
380 | - 'submit_hover_bg_color' => 'efefef', |
|
381 | - 'submit_hover_color' => '444444', |
|
382 | - 'submit_hover_border_color' => 'cccccc', |
|
383 | - 'submit_active_bg_color' => 'efefef', |
|
384 | - 'submit_active_color' => '444444', |
|
385 | - 'submit_active_border_color' => 'cccccc', |
|
386 | - |
|
387 | - 'border_radius' => '4px', |
|
388 | - 'error_bg' => 'F2DEDE', |
|
389 | - 'error_border' => 'EBCCD1', |
|
390 | - 'error_text' => 'B94A48', |
|
391 | - 'error_font_size' => '14px', |
|
392 | - |
|
393 | - 'success_bg_color' => 'DFF0D8', |
|
394 | - 'success_border_color' => 'D6E9C6', |
|
395 | - 'success_text_color' => '468847', |
|
396 | - 'success_font_size' => '14px', |
|
397 | - |
|
398 | - 'important_style' => false, |
|
399 | - |
|
400 | - 'custom_css' => '', |
|
401 | - ); |
|
402 | - } |
|
357 | + 'section_bg_color' => '', |
|
358 | + 'section_border_color' => 'e8e8e8', |
|
359 | + 'section_border_width' => '2px', |
|
360 | + 'section_border_style' => 'solid', |
|
361 | + 'section_border_loc' => '-top', |
|
362 | + 'collapse_icon' => '6', |
|
363 | + 'collapse_pos' => 'after', |
|
364 | + 'repeat_icon' => '1', |
|
365 | + |
|
366 | + 'submit_style' => false, |
|
367 | + 'submit_font_size' => '14px', |
|
368 | + 'submit_width' => 'auto', |
|
369 | + 'submit_height' => 'auto', |
|
370 | + 'submit_bg_color' => 'ffffff', |
|
371 | + 'submit_border_color' => 'cccccc', |
|
372 | + 'submit_border_width' => '1px', |
|
373 | + 'submit_text_color' => '444444', |
|
374 | + 'submit_weight' => 'normal', |
|
375 | + 'submit_border_radius' => '4px', |
|
376 | + 'submit_bg_img' => '', |
|
377 | + 'submit_margin' => '10px', |
|
378 | + 'submit_padding' => '6px 11px', |
|
379 | + 'submit_shadow_color' => 'eeeeee', |
|
380 | + 'submit_hover_bg_color' => 'efefef', |
|
381 | + 'submit_hover_color' => '444444', |
|
382 | + 'submit_hover_border_color' => 'cccccc', |
|
383 | + 'submit_active_bg_color' => 'efefef', |
|
384 | + 'submit_active_color' => '444444', |
|
385 | + 'submit_active_border_color' => 'cccccc', |
|
386 | + |
|
387 | + 'border_radius' => '4px', |
|
388 | + 'error_bg' => 'F2DEDE', |
|
389 | + 'error_border' => 'EBCCD1', |
|
390 | + 'error_text' => 'B94A48', |
|
391 | + 'error_font_size' => '14px', |
|
392 | + |
|
393 | + 'success_bg_color' => 'DFF0D8', |
|
394 | + 'success_border_color' => 'D6E9C6', |
|
395 | + 'success_text_color' => '468847', |
|
396 | + 'success_font_size' => '14px', |
|
397 | + |
|
398 | + 'important_style' => false, |
|
399 | + |
|
400 | + 'custom_css' => '', |
|
401 | + ); |
|
402 | + } |
|
403 | 403 | |
404 | 404 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
405 | 405 | return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']'; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class FrmStyle { |
3 | - public $number = false; // Unique ID number of the current instance. |
|
3 | + public $number = false; // Unique ID number of the current instance. |
|
4 | 4 | public $id = 0; // the id of the post |
5 | 5 | |
6 | 6 | /** |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | public function get_new() { |
14 | 14 | $this->id = 0; |
15 | 15 | |
16 | - $max_slug_value = pow(36, 6); |
|
16 | + $max_slug_value = pow( 36, 6 ); |
|
17 | 17 | $min_slug_value = 37; // we want to have at least 2 characters in the slug |
18 | - $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
18 | + $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 ); |
|
19 | 19 | |
20 | 20 | $style = array( |
21 | 21 | 'post_type' => FrmStylesController::$post_type, |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public function update( $id = 'default' ) { |
42 | 42 | $all_instances = $this->get_all(); |
43 | 43 | |
44 | - if ( empty($id) ) { |
|
44 | + if ( empty( $id ) ) { |
|
45 | 45 | $new_style = (array) $this->get_new(); |
46 | 46 | $all_instances[] = $new_style; |
47 | 47 | } |
@@ -49,15 +49,15 @@ discard block |
||
49 | 49 | $action_ids = array(); |
50 | 50 | |
51 | 51 | foreach ( $all_instances as $number => $new_instance ) { |
52 | - $new_instance = stripslashes_deep( (array) $new_instance); |
|
52 | + $new_instance = stripslashes_deep( (array) $new_instance ); |
|
53 | 53 | $this->id = $new_instance['ID']; |
54 | - if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) { |
|
55 | - $all_instances[ $number ] = $new_instance; |
|
54 | + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { |
|
55 | + $all_instances[$number] = $new_instance; |
|
56 | 56 | |
57 | - if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) { |
|
57 | + if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) { |
|
58 | 58 | // this style was set to default, so remove default setting on previous default style |
59 | 59 | $new_instance['menu_order'] = 0; |
60 | - $action_ids[] = $this->save($new_instance); |
|
60 | + $action_ids[] = $this->save( $new_instance ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | // don't continue if not saving this style |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | $new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] ); |
68 | 68 | $new_instance['post_content'] = $_POST['frm_style_setting']['post_content']; |
69 | 69 | $new_instance['post_type'] = FrmStylesController::$post_type; |
70 | - $new_instance['post_status'] = 'publish'; |
|
70 | + $new_instance['post_status'] = 'publish'; |
|
71 | 71 | $new_instance['menu_order'] = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0; |
72 | 72 | |
73 | - if ( empty($id) ) { |
|
73 | + if ( empty( $id ) ) { |
|
74 | 74 | $new_instance['post_name'] = $new_instance['post_title']; |
75 | 75 | } |
76 | 76 | |
@@ -79,21 +79,21 @@ discard block |
||
79 | 79 | foreach ( $default_settings as $setting => $default ) { |
80 | 80 | if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) { |
81 | 81 | //if is a color |
82 | - $new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] ); |
|
83 | - } else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) { |
|
84 | - $new_instance['post_content'][ $setting ] = 0; |
|
82 | + $new_instance['post_content'][$setting] = str_replace( '#', '', $new_instance['post_content'][$setting] ); |
|
83 | + } else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][$setting] ) ) { |
|
84 | + $new_instance['post_content'][$setting] = 0; |
|
85 | 85 | } else if ( $setting == 'font' ) { |
86 | - $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] ); |
|
86 | + $new_instance['post_content'][$setting] = $this->force_balanced_quotation( $new_instance['post_content'][$setting] ); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | - $all_instances[ $number ] = $new_instance; |
|
90 | + $all_instances[$number] = $new_instance; |
|
91 | 91 | |
92 | - $action_ids[] = $this->save($new_instance); |
|
92 | + $action_ids[] = $this->save( $new_instance ); |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
96 | - $this->save_settings($all_instances); |
|
96 | + $this->save_settings( $all_instances ); |
|
97 | 97 | |
98 | 98 | return $action_ids; |
99 | 99 | } |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function save_settings( $styles ) { |
105 | 105 | $filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php'; |
106 | - update_option( 'frm_last_style_update', date('njGi') ); |
|
106 | + update_option( 'frm_last_style_update', date( 'njGi' ) ); |
|
107 | 107 | |
108 | - if ( ! is_file($filename) ) { |
|
108 | + if ( ! is_file( $filename ) ) { |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | $create_file = new FrmCreateFile( array( 'folder_name' => 'formidable/css', 'file_name' => 'formidablepro.css' ) ); |
115 | 115 | $create_file->create_file( $css ); |
116 | 116 | |
117 | - update_option('frmpro_css', $css); |
|
117 | + update_option( 'frmpro_css', $css ); |
|
118 | 118 | |
119 | - delete_transient('frmpro_css'); |
|
120 | - set_transient('frmpro_css', $css); |
|
119 | + delete_transient( 'frmpro_css' ); |
|
120 | + set_transient( 'frmpro_css', $css ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | private function get_css_content( $filename ) { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | } |
136 | 136 | |
137 | 137 | public function destroy( $id ) { |
138 | - return wp_delete_post($id); |
|
138 | + return wp_delete_post( $id ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | public function get_one() { |
@@ -149,19 +149,19 @@ discard block |
||
149 | 149 | return $style; |
150 | 150 | } |
151 | 151 | |
152 | - $style = get_post($this->id); |
|
152 | + $style = get_post( $this->id ); |
|
153 | 153 | |
154 | 154 | if ( ! $style ) { |
155 | 155 | return $style; |
156 | 156 | } |
157 | 157 | |
158 | - $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
158 | + $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content ); |
|
159 | 159 | |
160 | 160 | $default_values = $this->get_defaults(); |
161 | 161 | |
162 | 162 | // fill default values |
163 | - $style->post_content = $this->override_defaults($style->post_content); |
|
164 | - $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
163 | + $style->post_content = $this->override_defaults( $style->post_content ); |
|
164 | + $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
|
165 | 165 | |
166 | 166 | return $style; |
167 | 167 | } |
@@ -175,21 +175,21 @@ discard block |
||
175 | 175 | 'order' => $order, |
176 | 176 | ); |
177 | 177 | |
178 | - $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts'); |
|
178 | + $temp_styles = FrmAppHelper::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' ); |
|
179 | 179 | |
180 | - if ( empty($temp_styles) ) { |
|
180 | + if ( empty( $temp_styles ) ) { |
|
181 | 181 | global $wpdb; |
182 | 182 | // make sure there wasn't a conflict with the query |
183 | 183 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' ); |
184 | - $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results'); |
|
184 | + $temp_styles = FrmAppHelper::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' ); |
|
185 | 185 | |
186 | - if ( empty($temp_styles) ) { |
|
186 | + if ( empty( $temp_styles ) ) { |
|
187 | 187 | // create a new style if there are none |
188 | 188 | $new = $this->get_new(); |
189 | 189 | $new->post_title = $new->post_name = __( 'Formidable Style', 'formidable' ); |
190 | 190 | $new->menu_order = 1; |
191 | - $new = $this->save( (array) $new); |
|
192 | - $this->update('default'); |
|
191 | + $new = $this->save( (array) $new ); |
|
192 | + $this->update( 'default' ); |
|
193 | 193 | |
194 | 194 | $post_atts['include'] = $new; |
195 | 195 | |
@@ -213,25 +213,25 @@ discard block |
||
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
216 | + $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content ); |
|
217 | 217 | |
218 | 218 | // fill default values |
219 | - $style->post_content = $this->override_defaults($style->post_content); |
|
220 | - $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
219 | + $style->post_content = $this->override_defaults( $style->post_content ); |
|
220 | + $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
|
221 | 221 | |
222 | - $styles[ $style->ID ] = $style; |
|
222 | + $styles[$style->ID] = $style; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | if ( ! $default_style ) { |
226 | - $default_style = reset($styles); |
|
227 | - $styles[ $default_style->ID ]->menu_order = 1; |
|
226 | + $default_style = reset( $styles ); |
|
227 | + $styles[$default_style->ID]->menu_order = 1; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | return $styles; |
231 | 231 | } |
232 | 232 | |
233 | 233 | public function get_default_style( $styles = null ) { |
234 | - if ( ! isset($styles) ) { |
|
234 | + if ( ! isset( $styles ) ) { |
|
235 | 235 | $styles = $this->get_all( 'menu_order', 'DESC', 1 ); |
236 | 236 | } |
237 | 237 | |
@@ -243,24 +243,24 @@ discard block |
||
243 | 243 | } |
244 | 244 | |
245 | 245 | public function override_defaults( $settings ) { |
246 | - if ( ! is_array($settings) ) { |
|
246 | + if ( ! is_array( $settings ) ) { |
|
247 | 247 | return $settings; |
248 | 248 | } |
249 | 249 | |
250 | - $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height']; |
|
250 | + $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height']; |
|
251 | 251 | |
252 | - if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) { |
|
252 | + if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) { |
|
253 | 253 | $settings['form_desc_size'] = $settings['description_font_size']; |
254 | 254 | $settings['form_desc_color'] = $settings['description_color']; |
255 | 255 | $settings['title_color'] = $settings['label_color']; |
256 | 256 | } |
257 | 257 | |
258 | - if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) { |
|
258 | + if ( ! isset( $settings['section_color'] ) && isset( $settings['label_color'] ) ) { |
|
259 | 259 | $settings['section_color'] = $settings['label_color']; |
260 | 260 | $settings['section_border_color'] = $settings['border_color']; |
261 | 261 | } |
262 | 262 | |
263 | - if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) { |
|
263 | + if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) { |
|
264 | 264 | $settings['submit_hover_bg_color'] = $settings['submit_bg_color']; |
265 | 265 | $settings['submit_hover_color'] = $settings['submit_text_color']; |
266 | 266 | $settings['submit_hover_border_color'] = $settings['submit_border_color']; |
@@ -1,26 +1,26 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class FrmEntryValidate { |
4 | - public static function validate( $values, $exclude = false ) { |
|
5 | - global $wpdb; |
|
4 | + public static function validate( $values, $exclude = false ) { |
|
5 | + global $wpdb; |
|
6 | 6 | |
7 | - FrmEntry::sanitize_entry_post( $values ); |
|
8 | - $errors = array(); |
|
7 | + FrmEntry::sanitize_entry_post( $values ); |
|
8 | + $errors = array(); |
|
9 | 9 | |
10 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
11 | - $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
12 | - return $errors; |
|
13 | - } |
|
10 | + if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
11 | + $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
12 | + return $errors; |
|
13 | + } |
|
14 | 14 | |
15 | 15 | if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) { |
16 | - $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
17 | - } |
|
16 | + $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
17 | + } |
|
18 | 18 | |
19 | - if ( ! isset($values['item_key']) || $values['item_key'] == '' ) { |
|
19 | + if ( ! isset($values['item_key']) || $values['item_key'] == '' ) { |
|
20 | 20 | $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
21 | - } |
|
21 | + } |
|
22 | 22 | |
23 | - $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
23 | + $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
24 | 24 | // Don't get subfields |
25 | 25 | $where['fr.parent_form_id'] = array( null, 0 ); |
26 | 26 | // Don't get excluded fields (like file upload fields in the ajax validation) |
@@ -28,42 +28,42 @@ discard block |
||
28 | 28 | $where['fi.type not'] = $exclude; |
29 | 29 | } |
30 | 30 | |
31 | - $posted_fields = FrmField::getAll($where, 'field_order'); |
|
31 | + $posted_fields = FrmField::getAll($where, 'field_order'); |
|
32 | 32 | |
33 | - // Pass exclude value to validate_field function so it can be used for repeating sections |
|
34 | - $args = array( 'exclude' => $exclude ); |
|
33 | + // Pass exclude value to validate_field function so it can be used for repeating sections |
|
34 | + $args = array( 'exclude' => $exclude ); |
|
35 | 35 | |
36 | - foreach ( $posted_fields as $posted_field ) { |
|
37 | - self::validate_field($posted_field, $errors, $values, $args); |
|
38 | - unset($posted_field); |
|
39 | - } |
|
36 | + foreach ( $posted_fields as $posted_field ) { |
|
37 | + self::validate_field($posted_field, $errors, $values, $args); |
|
38 | + unset($posted_field); |
|
39 | + } |
|
40 | 40 | |
41 | - // check for spam |
|
42 | - self::spam_check( $exclude, $values, $errors ); |
|
41 | + // check for spam |
|
42 | + self::spam_check( $exclude, $values, $errors ); |
|
43 | 43 | |
44 | - $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
44 | + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
45 | 45 | |
46 | - return $errors; |
|
47 | - } |
|
46 | + return $errors; |
|
47 | + } |
|
48 | 48 | |
49 | - public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
50 | - $defaults = array( |
|
51 | - 'id' => $posted_field->id, |
|
52 | - 'parent_field_id' => '', // the id of the repeat or embed form |
|
53 | - 'key_pointer' => '', // the pointer in the posted array |
|
54 | - 'exclude' => array(), // exclude these field types from validation |
|
55 | - ); |
|
56 | - $args = wp_parse_args( $args, $defaults ); |
|
49 | + public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
50 | + $defaults = array( |
|
51 | + 'id' => $posted_field->id, |
|
52 | + 'parent_field_id' => '', // the id of the repeat or embed form |
|
53 | + 'key_pointer' => '', // the pointer in the posted array |
|
54 | + 'exclude' => array(), // exclude these field types from validation |
|
55 | + ); |
|
56 | + $args = wp_parse_args( $args, $defaults ); |
|
57 | 57 | |
58 | - if ( empty($args['parent_field_id']) ) { |
|
58 | + if ( empty($args['parent_field_id']) ) { |
|
59 | 59 | $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
60 | - } else { |
|
61 | - // value is from a nested form |
|
62 | - $value = $values; |
|
63 | - } |
|
60 | + } else { |
|
61 | + // value is from a nested form |
|
62 | + $value = $values; |
|
63 | + } |
|
64 | 64 | |
65 | - // Check for values in "Other" fields |
|
66 | - FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
65 | + // Check for values in "Other" fields |
|
66 | + FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
67 | 67 | |
68 | 68 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
69 | 69 | |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | $value = reset($value); |
73 | 73 | } |
74 | 74 | |
75 | - if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
75 | + if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
76 | 76 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
77 | - } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
78 | - $_POST['item_name'] = $value; |
|
79 | - } |
|
77 | + } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
78 | + $_POST['item_name'] = $value; |
|
79 | + } |
|
80 | 80 | |
81 | 81 | if ( $value != '' ) { |
82 | 82 | self::validate_url_field( $errors, $posted_field, $value, $args ); |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | self::validate_phone_field( $errors, $posted_field, $value, $args ); |
86 | 86 | } |
87 | 87 | |
88 | - FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
88 | + FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
89 | 89 | |
90 | - self::validate_recaptcha($errors, $posted_field, $args); |
|
90 | + self::validate_recaptcha($errors, $posted_field, $args); |
|
91 | 91 | |
92 | 92 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
93 | 93 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | 96 | private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) { |
97 | 97 | if ( FrmField::is_option_true_in_object( $field, 'default_blank' ) && $value == $field->default_value ) { |
@@ -101,32 +101,32 @@ discard block |
||
101 | 101 | |
102 | 102 | public static function validate_url_field( &$errors, $field, &$value, $args ) { |
103 | 103 | if ( $value == '' || ! in_array( $field->type, array( 'website', 'url', 'image' ) ) ) { |
104 | - return; |
|
105 | - } |
|
104 | + return; |
|
105 | + } |
|
106 | 106 | |
107 | - if ( trim($value) == 'http://' ) { |
|
108 | - $value = ''; |
|
109 | - } else { |
|
110 | - $value = esc_url_raw( $value ); |
|
107 | + if ( trim($value) == 'http://' ) { |
|
108 | + $value = ''; |
|
109 | + } else { |
|
110 | + $value = esc_url_raw( $value ); |
|
111 | 111 | $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'http://' . $value; |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - //validate the url format |
|
115 | - if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) { |
|
114 | + //validate the url format |
|
115 | + if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) { |
|
116 | 116 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
117 | - } |
|
118 | - } |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | 120 | public static function validate_email_field( &$errors, $field, $value, $args ) { |
121 | - if ( $value == '' || $field->type != 'email' ) { |
|
122 | - return; |
|
123 | - } |
|
121 | + if ( $value == '' || $field->type != 'email' ) { |
|
122 | + return; |
|
123 | + } |
|
124 | 124 | |
125 | - //validate the email format |
|
126 | - if ( ! is_email($value) ) { |
|
125 | + //validate the email format |
|
126 | + if ( ! is_email($value) ) { |
|
127 | 127 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
128 | - } |
|
129 | - } |
|
128 | + } |
|
129 | + } |
|
130 | 130 | |
131 | 131 | public static function validate_number_field( &$errors, $field, $value, $args ) { |
132 | 132 | //validate the number format |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | } |
204 | 204 | |
205 | 205 | public static function validate_recaptcha( &$errors, $field, $args ) { |
206 | - if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) { |
|
207 | - return; |
|
208 | - } |
|
206 | + if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) { |
|
207 | + return; |
|
208 | + } |
|
209 | 209 | |
210 | 210 | $frm_settings = FrmAppHelper::get_settings(); |
211 | 211 | if ( empty( $frm_settings->pubkey ) ) { |
@@ -213,57 +213,57 @@ discard block |
||
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | - if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
217 | - // If captcha is missing, check if it was already verified |
|
216 | + if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
217 | + // If captcha is missing, check if it was already verified |
|
218 | 218 | if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) { |
219 | - // There was no captcha submitted |
|
219 | + // There was no captcha submitted |
|
220 | 220 | $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' ); |
221 | - } |
|
222 | - return; |
|
223 | - } |
|
221 | + } |
|
222 | + return; |
|
223 | + } |
|
224 | 224 | |
225 | - $arg_array = array( |
|
226 | - 'body' => array( |
|
225 | + $arg_array = array( |
|
226 | + 'body' => array( |
|
227 | 227 | 'secret' => $frm_settings->privkey, |
228 | 228 | 'response' => $_POST['g-recaptcha-response'], |
229 | 229 | 'remoteip' => FrmAppHelper::get_ip_address(), |
230 | 230 | ), |
231 | 231 | ); |
232 | - $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
|
233 | - $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
232 | + $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
|
233 | + $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
234 | 234 | |
235 | - if ( isset( $response['success'] ) && ! $response['success'] ) { |
|
236 | - // What happens when the CAPTCHA was entered incorrectly |
|
235 | + if ( isset( $response['success'] ) && ! $response['success'] ) { |
|
236 | + // What happens when the CAPTCHA was entered incorrectly |
|
237 | 237 | $errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
238 | - } else if ( is_wp_error( $resp ) ) { |
|
238 | + } else if ( is_wp_error( $resp ) ) { |
|
239 | 239 | $error_string = $resp->get_error_message(); |
240 | 240 | $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
241 | 241 | $errors[ 'field' . $args['id'] ] .= ' ' . $error_string; |
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * check for spam |
|
247 | - * @param boolean $exclude |
|
248 | - * @param array $values |
|
249 | - * @param array $errors by reference |
|
250 | - */ |
|
251 | - public static function spam_check( $exclude, $values, &$errors ) { |
|
252 | - if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
253 | - // only check spam if there are no other errors |
|
254 | - return; |
|
255 | - } |
|
256 | - |
|
257 | - if ( self::is_akismet_spam( $values ) ) { |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * check for spam |
|
247 | + * @param boolean $exclude |
|
248 | + * @param array $values |
|
249 | + * @param array $errors by reference |
|
250 | + */ |
|
251 | + public static function spam_check( $exclude, $values, &$errors ) { |
|
252 | + if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
253 | + // only check spam if there are no other errors |
|
254 | + return; |
|
255 | + } |
|
256 | + |
|
257 | + if ( self::is_akismet_spam( $values ) ) { |
|
258 | 258 | if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) { |
259 | 259 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
260 | 260 | } |
261 | - } |
|
261 | + } |
|
262 | 262 | |
263 | - if ( self::blacklist_check( $values ) ) { |
|
264 | - $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
|
265 | - } |
|
266 | - } |
|
263 | + if ( self::blacklist_check( $values ) ) { |
|
264 | + $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
|
265 | + } |
|
266 | + } |
|
267 | 267 | |
268 | 268 | private static function is_akismet_spam( $values ) { |
269 | 269 | global $wpcom_api_key; |
@@ -275,54 +275,54 @@ discard block |
||
275 | 275 | return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ); |
276 | 276 | } |
277 | 277 | |
278 | - public static function blacklist_check( $values ) { |
|
279 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
280 | - return false; |
|
281 | - } |
|
278 | + public static function blacklist_check( $values ) { |
|
279 | + if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
280 | + return false; |
|
281 | + } |
|
282 | 282 | |
283 | - $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
283 | + $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
284 | 284 | |
285 | - if ( empty( $mod_keys ) ) { |
|
286 | - return false; |
|
287 | - } |
|
285 | + if ( empty( $mod_keys ) ) { |
|
286 | + return false; |
|
287 | + } |
|
288 | 288 | |
289 | - $content = FrmEntriesHelper::entry_array_to_string($values); |
|
289 | + $content = FrmEntriesHelper::entry_array_to_string($values); |
|
290 | 290 | |
291 | 291 | if ( empty($content) ) { |
292 | - return false; |
|
292 | + return false; |
|
293 | 293 | } |
294 | 294 | |
295 | - $words = explode( "\n", $mod_keys ); |
|
295 | + $words = explode( "\n", $mod_keys ); |
|
296 | 296 | |
297 | - foreach ( (array) $words as $word ) { |
|
298 | - $word = trim( $word ); |
|
297 | + foreach ( (array) $words as $word ) { |
|
298 | + $word = trim( $word ); |
|
299 | 299 | |
300 | - if ( empty($word) ) { |
|
301 | - continue; |
|
302 | - } |
|
300 | + if ( empty($word) ) { |
|
301 | + continue; |
|
302 | + } |
|
303 | 303 | |
304 | - if ( preg_match('#' . preg_quote( $word, '#' ) . '#', $content) ) { |
|
305 | - return true; |
|
306 | - } |
|
307 | - } |
|
304 | + if ( preg_match('#' . preg_quote( $word, '#' ) . '#', $content) ) { |
|
305 | + return true; |
|
306 | + } |
|
307 | + } |
|
308 | 308 | |
309 | - return false; |
|
310 | - } |
|
309 | + return false; |
|
310 | + } |
|
311 | 311 | |
312 | - /** |
|
313 | - * Check entries for spam |
|
314 | - * |
|
315 | - * @return boolean true if is spam |
|
316 | - */ |
|
317 | - public static function akismet( $values ) { |
|
318 | - $content = FrmEntriesHelper::entry_array_to_string( $values ); |
|
312 | + /** |
|
313 | + * Check entries for spam |
|
314 | + * |
|
315 | + * @return boolean true if is spam |
|
316 | + */ |
|
317 | + public static function akismet( $values ) { |
|
318 | + $content = FrmEntriesHelper::entry_array_to_string( $values ); |
|
319 | 319 | |
320 | 320 | if ( empty( $content ) ) { |
321 | - return false; |
|
321 | + return false; |
|
322 | 322 | } |
323 | 323 | |
324 | - $datas = array(); |
|
325 | - self::parse_akismet_array( $datas, $content ); |
|
324 | + $datas = array(); |
|
325 | + self::parse_akismet_array( $datas, $content ); |
|
326 | 326 | |
327 | 327 | $query_string = ''; |
328 | 328 | foreach ( $datas as $key => $data ) { |
@@ -330,35 +330,35 @@ discard block |
||
330 | 330 | unset( $key, $data ); |
331 | 331 | } |
332 | 332 | |
333 | - $response = Akismet::http_post($query_string, 'comment-check'); |
|
333 | + $response = Akismet::http_post($query_string, 'comment-check'); |
|
334 | 334 | |
335 | 335 | return ( is_array( $response ) && $response[1] == 'true' ); |
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @since 2.0 |
|
340 | - * @param string $content |
|
341 | - */ |
|
342 | - private static function parse_akismet_array( &$datas, $content ) { |
|
343 | - $datas['blog'] = FrmAppHelper::site_url(); |
|
344 | - $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() ); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @since 2.0 |
|
340 | + * @param string $content |
|
341 | + */ |
|
342 | + private static function parse_akismet_array( &$datas, $content ) { |
|
343 | + $datas['blog'] = FrmAppHelper::site_url(); |
|
344 | + $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() ); |
|
345 | 345 | $datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ); |
346 | 346 | $datas['referrer'] = isset( $_SERVER['HTTP_REFERER'] ) ? FrmAppHelper::get_server_value( 'HTTP_REFERER' ) : false; |
347 | - $datas['comment_type'] = 'formidable'; |
|
348 | - $datas['comment_content'] = $content; |
|
347 | + $datas['comment_type'] = 'formidable'; |
|
348 | + $datas['comment_content'] = $content; |
|
349 | 349 | |
350 | - if ( $permalink = get_permalink() ) { |
|
351 | - $datas['permalink'] = $permalink; |
|
352 | - } |
|
350 | + if ( $permalink = get_permalink() ) { |
|
351 | + $datas['permalink'] = $permalink; |
|
352 | + } |
|
353 | 353 | |
354 | - foreach ( $_SERVER as $key => $value ) { |
|
354 | + foreach ( $_SERVER as $key => $value ) { |
|
355 | 355 | if ( ! in_array( $key, array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ) ) && is_string( $value ) ) { |
356 | 356 | $datas[ $key ] = wp_strip_all_tags( $value ); |
357 | - } else { |
|
357 | + } else { |
|
358 | 358 | $datas[ $key ] = ''; |
359 | - } |
|
359 | + } |
|
360 | 360 | |
361 | - unset($key, $value); |
|
362 | - } |
|
363 | - } |
|
361 | + unset($key, $value); |
|
362 | + } |
|
363 | + } |
|
364 | 364 | } |
@@ -7,20 +7,20 @@ discard block |
||
7 | 7 | FrmEntry::sanitize_entry_post( $values ); |
8 | 8 | $errors = array(); |
9 | 9 | |
10 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
10 | + if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) { |
|
11 | 11 | $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
12 | 12 | return $errors; |
13 | 13 | } |
14 | 14 | |
15 | - if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) { |
|
15 | + if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values['frm_submit_entry_' . $values['form_id']] ) || ! wp_verify_nonce( $values['frm_submit_entry_' . $values['form_id']], 'frm_submit_entry_nonce' ) ) ) { |
|
16 | 16 | $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
17 | 17 | } |
18 | 18 | |
19 | - if ( ! isset($values['item_key']) || $values['item_key'] == '' ) { |
|
19 | + if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) { |
|
20 | 20 | $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
21 | 21 | } |
22 | 22 | |
23 | - $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
23 | + $where = apply_filters( 'frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
24 | 24 | // Don't get subfields |
25 | 25 | $where['fr.parent_form_id'] = array( null, 0 ); |
26 | 26 | // Don't get excluded fields (like file upload fields in the ajax validation) |
@@ -28,20 +28,20 @@ discard block |
||
28 | 28 | $where['fi.type not'] = $exclude; |
29 | 29 | } |
30 | 30 | |
31 | - $posted_fields = FrmField::getAll($where, 'field_order'); |
|
31 | + $posted_fields = FrmField::getAll( $where, 'field_order' ); |
|
32 | 32 | |
33 | 33 | // Pass exclude value to validate_field function so it can be used for repeating sections |
34 | 34 | $args = array( 'exclude' => $exclude ); |
35 | 35 | |
36 | 36 | foreach ( $posted_fields as $posted_field ) { |
37 | - self::validate_field($posted_field, $errors, $values, $args); |
|
38 | - unset($posted_field); |
|
37 | + self::validate_field( $posted_field, $errors, $values, $args ); |
|
38 | + unset( $posted_field ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | // check for spam |
42 | 42 | self::spam_check( $exclude, $values, $errors ); |
43 | 43 | |
44 | - $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
44 | + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude' ) ); |
|
45 | 45 | |
46 | 46 | return $errors; |
47 | 47 | } |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | ); |
56 | 56 | $args = wp_parse_args( $args, $defaults ); |
57 | 57 | |
58 | - if ( empty($args['parent_field_id']) ) { |
|
59 | - $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
|
58 | + if ( empty( $args['parent_field_id'] ) ) { |
|
59 | + $value = isset( $values['item_meta'][$args['id']] ) ? $values['item_meta'][$args['id']] : ''; |
|
60 | 60 | } else { |
61 | 61 | // value is from a nested form |
62 | 62 | $value = $values; |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
69 | 69 | |
70 | 70 | // Reset arrays with only one value if it's not a field where array keys need to be preserved |
71 | - if ( is_array($value) && count( $value ) == 1 && isset( $value[0] ) ) { |
|
72 | - $value = reset($value); |
|
71 | + if ( is_array( $value ) && count( $value ) == 1 && isset( $value[0] ) ) { |
|
72 | + $value = reset( $value ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
76 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
76 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
77 | 77 | } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
78 | 78 | $_POST['item_name'] = $value; |
79 | 79 | } |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | self::validate_phone_field( $errors, $posted_field, $value, $args ); |
86 | 86 | } |
87 | 87 | |
88 | - FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
88 | + FrmEntriesHelper::set_posted_value( $posted_field, $value, $args ); |
|
89 | 89 | |
90 | - self::validate_recaptcha($errors, $posted_field, $args); |
|
90 | + self::validate_recaptcha( $errors, $posted_field, $args ); |
|
91 | 91 | |
92 | 92 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
93 | 93 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | return; |
105 | 105 | } |
106 | 106 | |
107 | - if ( trim($value) == 'http://' ) { |
|
107 | + if ( trim( $value ) == 'http://' ) { |
|
108 | 108 | $value = ''; |
109 | 109 | } else { |
110 | 110 | $value = esc_url_raw( $value ); |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | //validate the url format |
115 | - if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) { |
|
116 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
115 | + if ( ! preg_match( '/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value ) ) { |
|
116 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | //validate the email format |
126 | - if ( ! is_email($value) ) { |
|
127 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
126 | + if ( ! is_email( $value ) ) { |
|
127 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - if ( ! is_numeric( $value) ) { |
|
138 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
137 | + if ( ! is_numeric( $value ) ) { |
|
138 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | // validate number settings |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | if ( $frm_settings->use_html && isset( $field->field_options['minnum'] ) && isset( $field->field_options['maxnum'] ) ) { |
146 | 146 | //minnum maxnum |
147 | 147 | if ( (float) $value < $field->field_options['minnum'] ) { |
148 | - $errors[ 'field' . $args['id'] ] = __( 'Please select a higher number', 'formidable' ); |
|
148 | + $errors['field' . $args['id']] = __( 'Please select a higher number', 'formidable' ); |
|
149 | 149 | } else if ( (float) $value > $field->field_options['maxnum'] ) { |
150 | - $errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' ); |
|
150 | + $errors['field' . $args['id']] = __( 'Please select a lower number', 'formidable' ); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $pattern = self::phone_format( $field ); |
162 | 162 | |
163 | 163 | if ( ! preg_match( $pattern, $value ) ) { |
164 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
164 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -213,11 +213,11 @@ discard block |
||
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | - if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
216 | + if ( ! isset( $_POST['g-recaptcha-response'] ) ) { |
|
217 | 217 | // If captcha is missing, check if it was already verified |
218 | 218 | if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) { |
219 | 219 | // There was no captcha submitted |
220 | - $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' ); |
|
220 | + $errors['field' . $args['id']] = __( 'The captcha is missing from this form', 'formidable' ); |
|
221 | 221 | } |
222 | 222 | return; |
223 | 223 | } |
@@ -230,15 +230,15 @@ discard block |
||
230 | 230 | ), |
231 | 231 | ); |
232 | 232 | $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
233 | - $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
233 | + $response = json_decode( wp_remote_retrieve_body( $resp ), true ); |
|
234 | 234 | |
235 | 235 | if ( isset( $response['success'] ) && ! $response['success'] ) { |
236 | 236 | // What happens when the CAPTCHA was entered incorrectly |
237 | - $errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
|
237 | + $errors['field' . $args['id']] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
|
238 | 238 | } else if ( is_wp_error( $resp ) ) { |
239 | 239 | $error_string = $resp->get_error_message(); |
240 | - $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
|
241 | - $errors[ 'field' . $args['id'] ] .= ' ' . $error_string; |
|
240 | + $errors['field' . $args['id']] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
|
241 | + $errors['field' . $args['id']] .= ' ' . $error_string; |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | |
268 | 268 | private static function is_akismet_spam( $values ) { |
269 | 269 | global $wpcom_api_key; |
270 | - return ( is_callable('Akismet::http_post') && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet( $values ) ); |
|
270 | + return ( is_callable( 'Akismet::http_post' ) && ( get_option( 'wordpress_api_key' ) || $wpcom_api_key ) && self::akismet( $values ) ); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | private static function is_akismet_enabled_for_user( $form_id ) { |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | } |
277 | 277 | |
278 | 278 | public static function blacklist_check( $values ) { |
279 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
279 | + if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) { |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
@@ -286,9 +286,9 @@ discard block |
||
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | |
289 | - $content = FrmEntriesHelper::entry_array_to_string($values); |
|
289 | + $content = FrmEntriesHelper::entry_array_to_string( $values ); |
|
290 | 290 | |
291 | - if ( empty($content) ) { |
|
291 | + if ( empty( $content ) ) { |
|
292 | 292 | return false; |
293 | 293 | } |
294 | 294 | |
@@ -297,11 +297,11 @@ discard block |
||
297 | 297 | foreach ( (array) $words as $word ) { |
298 | 298 | $word = trim( $word ); |
299 | 299 | |
300 | - if ( empty($word) ) { |
|
300 | + if ( empty( $word ) ) { |
|
301 | 301 | continue; |
302 | 302 | } |
303 | 303 | |
304 | - if ( preg_match('#' . preg_quote( $word, '#' ) . '#', $content) ) { |
|
304 | + if ( preg_match( '#' . preg_quote( $word, '#' ) . '#', $content ) ) { |
|
305 | 305 | return true; |
306 | 306 | } |
307 | 307 | } |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | unset( $key, $data ); |
331 | 331 | } |
332 | 332 | |
333 | - $response = Akismet::http_post($query_string, 'comment-check'); |
|
333 | + $response = Akismet::http_post( $query_string, 'comment-check' ); |
|
334 | 334 | |
335 | 335 | return ( is_array( $response ) && $response[1] == 'true' ); |
336 | 336 | } |
@@ -353,12 +353,12 @@ discard block |
||
353 | 353 | |
354 | 354 | foreach ( $_SERVER as $key => $value ) { |
355 | 355 | if ( ! in_array( $key, array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ) ) && is_string( $value ) ) { |
356 | - $datas[ $key ] = wp_strip_all_tags( $value ); |
|
356 | + $datas[$key] = wp_strip_all_tags( $value ); |
|
357 | 357 | } else { |
358 | - $datas[ $key ] = ''; |
|
358 | + $datas[$key] = ''; |
|
359 | 359 | } |
360 | 360 | |
361 | - unset($key, $value); |
|
361 | + unset( $key, $value ); |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | } |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | $this->file_name = $atts['file_name']; |
19 | 19 | $this->error_message = isset( $atts['error_message'] ) ? $atts['error_message'] : ''; |
20 | 20 | $this->uploads = wp_upload_dir(); |
21 | - $this->chmod_dir = defined('FS_CHMOD_DIR') ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); |
|
22 | - $this->chmod_file = defined('FS_CHMOD_FILE') ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
|
21 | + $this->chmod_dir = defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); |
|
22 | + $this->chmod_file = defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function create_file( $file_content ) { |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | private function get_ftp_creds( $type ) { |
86 | 86 | $credentials = get_option( 'ftp_credentials', array( 'hostname' => '', 'username' => '' ) ); |
87 | 87 | |
88 | - $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : $credentials['hostname']; |
|
89 | - $credentials['username'] = defined('FTP_USER') ? FTP_USER : $credentials['username']; |
|
90 | - $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : ''; |
|
88 | + $credentials['hostname'] = defined( 'FTP_HOST' ) ? FTP_HOST : $credentials['hostname']; |
|
89 | + $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : $credentials['username']; |
|
90 | + $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : ''; |
|
91 | 91 | |
92 | 92 | // Check to see if we are setting the public/private keys for ssh |
93 | - $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : ''; |
|
94 | - $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : ''; |
|
93 | + $credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : ''; |
|
94 | + $credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : ''; |
|
95 | 95 | |
96 | 96 | // Sanitize the hostname, Some people might pass in odd-data: |
97 | 97 | $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); //Strip any schemes off |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <li id="frm_delete_field_<?php echo esc_attr( $field['id'] ); ?>-<?php echo esc_attr( $opt_key ) ?>_container" class="frm_single_option"> |
2 | 2 | <a href="javascript:void(0)" class="frm_single_visible_hover frm_icon_font frm_delete_icon" data-fid="<?php echo esc_attr( $field['id'] ); ?>"> </a> |
3 | 3 | <?php if ( $field['type'] != 'select' ) { ?> |
4 | - <input type="<?php echo esc_attr( $field['type'] ) ?>" name="<?php echo esc_attr( $field_name ) ?><?php echo ( $field['type'] == 'checkbox' ) ? '[]' : ''; ?>" value="<?php echo esc_attr($field_val) ?>"<?php echo isset( $checked ) ? $checked : ''; ?>/> |
|
4 | + <input type="<?php echo esc_attr( $field['type'] ) ?>" name="<?php echo esc_attr( $field_name ) ?><?php echo ( $field['type'] == 'checkbox' ) ? '[]' : ''; ?>" value="<?php echo esc_attr( $field_val ) ?>"<?php echo isset( $checked ) ? $checked : ''; ?>/> |
|
5 | 5 | <?php } ?> |
6 | - <label class="frm_ipe_field_option field_<?php echo esc_attr( $field['id'] ) ?>_option <?php echo esc_attr( $field['separate_value'] ? 'frm_with_key' : '' ); ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ) ?>"><?php echo ($opt == '') ? __( '(Blank)', 'formidable' ) : $opt ?></label> |
|
6 | + <label class="frm_ipe_field_option field_<?php echo esc_attr( $field['id'] ) ?>_option <?php echo esc_attr( $field['separate_value'] ? 'frm_with_key' : '' ); ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ) ?>"><?php echo ( $opt == '' ) ? __( '(Blank)', 'formidable' ) : $opt ?></label> |
|
7 | 7 | <span class="frm_option_key field_<?php echo esc_attr( $field['id'] ) ?>_option_key<?php echo esc_attr( $field['separate_value'] ? '' : ' frm_hidden' ); ?>"> |
8 | 8 | <label class="frm-show-click frm_ipe_field_option_key" id="field_key_<?php echo esc_attr( $field['id'] . '-' . $opt_key ) ?>"><?php echo ( $field_val == '' ) ? esc_html__( '(Blank)', 'formidable' ) : $field_val ?></label> |
9 | 9 | </span> |
10 | 10 | </li> |
11 | 11 | <?php |
12 | -unset($field_val, $opt, $opt_key); |
|
12 | +unset( $field_val, $opt, $opt_key ); |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <div class="field-group field-group-background clearfix frm-first-row"> |
2 | 2 | <label><?php _e( 'Color', 'formidable' ) ?></label> |
3 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('label_color') ) ?>" id="frm_label_color" class="hex" value="<?php echo esc_attr( $style->post_content['label_color'] ) ?>" /> |
|
3 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'label_color' ) ) ?>" id="frm_label_color" class="hex" value="<?php echo esc_attr( $style->post_content['label_color'] ) ?>" /> |
|
4 | 4 | </div> |
5 | 5 | <div class="field-group clearfix frm-first-row"> |
6 | 6 | <label><?php _e( 'Weight', 'formidable' ) ?></label> |
7 | - <select name="<?php echo esc_attr( $frm_style->get_field_name('weight') ) ?>" id="frm_weight"> |
|
7 | + <select name="<?php echo esc_attr( $frm_style->get_field_name( 'weight' ) ) ?>" id="frm_weight"> |
|
8 | 8 | <?php foreach ( FrmStyle::get_bold_options() as $value => $name ) { ?> |
9 | 9 | <option value="<?php echo esc_attr( $value ) ?>" <?php selected( $style->post_content['weight'], $value ) ?>><?php echo esc_html( $name ) ?></option> |
10 | 10 | <?php } ?> |
@@ -12,45 +12,45 @@ discard block |
||
12 | 12 | </div> |
13 | 13 | <div class="field-group clearfix frm-first-row"> |
14 | 14 | <label><?php _e( 'Size', 'formidable' ) ?></label> |
15 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('font_size') ) ?>" id="frm_font_size" value="<?php echo esc_attr($style->post_content['font_size']) ?>" size="3" /> |
|
15 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'font_size' ) ) ?>" id="frm_font_size" value="<?php echo esc_attr( $style->post_content['font_size'] ) ?>" size="3" /> |
|
16 | 16 | </div> |
17 | 17 | |
18 | 18 | <div class="field-group clearfix frm_clear"> |
19 | 19 | <label><?php _e( 'Position', 'formidable' ) ?></label> |
20 | - <select name="<?php echo esc_attr( $frm_style->get_field_name('position') ) ?>" id="frm_position"> |
|
20 | + <select name="<?php echo esc_attr( $frm_style->get_field_name( 'position' ) ) ?>" id="frm_position"> |
|
21 | 21 | <?php foreach ( array( 'none' => __( 'top', 'formidable' ), 'left' => __( 'left', 'formidable' ), 'right' => __( 'right', 'formidable' ), 'no_label' => __( 'none', 'formidable' ) ) as $pos => $pos_label ) { ?> |
22 | - <option value="<?php echo esc_attr( $pos ) ?>" <?php selected($style->post_content['position'], $pos) ?>><?php echo esc_html( $pos_label ) ?></option> |
|
22 | + <option value="<?php echo esc_attr( $pos ) ?>" <?php selected( $style->post_content['position'], $pos ) ?>><?php echo esc_html( $pos_label ) ?></option> |
|
23 | 23 | <?php } ?> |
24 | 24 | </select> |
25 | 25 | </div> |
26 | 26 | |
27 | 27 | <div class="field-group clearfix"> |
28 | 28 | <label><?php _e( 'Align', 'formidable' ) ?></label> |
29 | - <select name="<?php echo esc_attr( $frm_style->get_field_name('align') ) ?>" id="frm_align"> |
|
30 | - <option value="left" <?php selected($style->post_content['align'], 'left') ?>><?php _e( 'left', 'formidable' ) ?></option> |
|
31 | - <option value="right" <?php selected($style->post_content['align'], 'right') ?>><?php _e( 'right', 'formidable' ) ?></option> |
|
29 | + <select name="<?php echo esc_attr( $frm_style->get_field_name( 'align' ) ) ?>" id="frm_align"> |
|
30 | + <option value="left" <?php selected( $style->post_content['align'], 'left' ) ?>><?php _e( 'left', 'formidable' ) ?></option> |
|
31 | + <option value="right" <?php selected( $style->post_content['align'], 'right' ) ?>><?php _e( 'right', 'formidable' ) ?></option> |
|
32 | 32 | </select> |
33 | 33 | </div> |
34 | 34 | |
35 | 35 | <div class="field-group clearfix"> |
36 | 36 | <label><?php _e( 'Width', 'formidable' ) ?></label> |
37 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('width') ) ?>" id="frm_width" value="<?php echo esc_attr( $style->post_content['width'] ) ?>" /> |
|
37 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'width' ) ) ?>" id="frm_width" value="<?php echo esc_attr( $style->post_content['width'] ) ?>" /> |
|
38 | 38 | </div> |
39 | 39 | |
40 | 40 | <div class="field-group clearfix frm_clear"> |
41 | 41 | <label><?php _e( 'Padding', 'formidable' ) ?></label> |
42 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('label_padding') ) ?>" id="frm_label_padding" value="<?php echo esc_attr( $style->post_content['label_padding'] ) ?>" /> |
|
42 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'label_padding' ) ) ?>" id="frm_label_padding" value="<?php echo esc_attr( $style->post_content['label_padding'] ) ?>" /> |
|
43 | 43 | </div> |
44 | 44 | |
45 | 45 | <div class="clear"></div> |
46 | 46 | <h3><?php _e( 'Required Indicator', 'formidable' ) ?></h3> |
47 | 47 | <div class="field-group field-group-border clearfix after-h3"> |
48 | 48 | <label class="background"><?php _e( 'Color', 'formidable' ) ?></label> |
49 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('required_color') ) ?>" id="frm_required_color" class="hex" value="<?php echo esc_attr( $style->post_content['required_color'] ) ?>" /> |
|
49 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'required_color' ) ) ?>" id="frm_required_color" class="hex" value="<?php echo esc_attr( $style->post_content['required_color'] ) ?>" /> |
|
50 | 50 | </div> |
51 | 51 | <div class="field-group clearfix after-h3"> |
52 | 52 | <label><?php _e( 'Weight', 'formidable' ) ?></label> |
53 | - <select name="<?php echo esc_attr( $frm_style->get_field_name('required_weight') ) ?>" id="frm_required_weight"> |
|
53 | + <select name="<?php echo esc_attr( $frm_style->get_field_name( 'required_weight' ) ) ?>" id="frm_required_weight"> |
|
54 | 54 | <?php foreach ( FrmStyle::get_bold_options() as $value => $name ) { ?> |
55 | 55 | <option value="<?php echo esc_attr( $value ) ?>" <?php selected( $style->post_content['required_weight'], $value ) ?>><?php echo esc_html( $name ) ?></option> |
56 | 56 | <?php } ?> |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <p class="frm_no_top_margin"> |
2 | 2 | <label for="frm_submit_style"> |
3 | - <input type="checkbox" name="<?php echo esc_attr( $frm_style->get_field_name('submit_style') ) ?>" id="frm_submit_style" <?php checked( $style->post_content['submit_style'], 1 ) ?> value="1" /> |
|
3 | + <input type="checkbox" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_style' ) ) ?>" id="frm_submit_style" <?php checked( $style->post_content['submit_style'], 1 ) ?> value="1" /> |
|
4 | 4 | <?php esc_html_e( 'Disable submit button styling', 'formidable' ); ?> |
5 | 5 | <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Note: If disabled, you may not see the change take effect until you make 2 more styling changes or click "Update Options".', 'formidable' ) ?>"></span> |
6 | 6 | </label> |
@@ -9,10 +9,10 @@ discard block |
||
9 | 9 | <div class="posttypediv"> |
10 | 10 | <ul class="posttype-tabs add-menu-item-tabs"> |
11 | 11 | <li <?php echo ( 'default' == $current_tab ? ' class="tabs"' : '' ); ?>> |
12 | - <a href="<?php echo esc_url('?page=formidable-styles&page-tab=default#tabs-panel-button-default') ?>" class="nav-tab-link" data-type="tabs-panel-button-default" ><?php _e( 'Default', 'formidable' ) ?></a> |
|
12 | + <a href="<?php echo esc_url( '?page=formidable-styles&page-tab=default#tabs-panel-button-default' ) ?>" class="nav-tab-link" data-type="tabs-panel-button-default" ><?php _e( 'Default', 'formidable' ) ?></a> |
|
13 | 13 | </li> |
14 | 14 | <li <?php echo ( 'button-hover' == $current_tab ? ' class="tabs"' : '' ); ?>> |
15 | - <a href="<?php echo esc_url('?page=formidable-styles&page-tab=button-hover#page-button-hover') ?>" class="nav-tab-link" data-type="tabs-panel-button-hover" ><?php _e( 'Hover', 'formidable' ) ?></a> |
|
15 | + <a href="<?php echo esc_url( '?page=formidable-styles&page-tab=button-hover#page-button-hover' ) ?>" class="nav-tab-link" data-type="tabs-panel-button-hover" ><?php _e( 'Hover', 'formidable' ) ?></a> |
|
16 | 16 | </li> |
17 | 17 | <li <?php echo ( 'button-click' == $current_tab ? ' class="tabs"' : '' ); ?>> |
18 | 18 | <a href="?page=formidable-styles&page-tab=button-click#tabs-panel-button-click" class="nav-tab-link" data-type="tabs-panel-button-click"><?php _e( 'Click', 'formidable' ) ?></a> |
@@ -24,22 +24,22 @@ discard block |
||
24 | 24 | ?>"> |
25 | 25 | <div class="field-group field-group-border clearfix"> |
26 | 26 | <label><?php _e( 'Size', 'formidable' ) ?></label> |
27 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_font_size') ) ?>" id="frm_submit_font_size" value="<?php echo esc_attr( $style->post_content['submit_font_size'] ) ?>" size="3" /> |
|
27 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_font_size' ) ) ?>" id="frm_submit_font_size" value="<?php echo esc_attr( $style->post_content['submit_font_size'] ) ?>" size="3" /> |
|
28 | 28 | </div> |
29 | 29 | |
30 | 30 | <div class="field-group clearfix"> |
31 | 31 | <label><?php _e( 'Width', 'formidable' ) ?></label> |
32 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_width') ) ?>" id="frm_submit_width" value="<?php echo esc_attr( $style->post_content['submit_width'] ) ?>" size="5" /> |
|
32 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_width' ) ) ?>" id="frm_submit_width" value="<?php echo esc_attr( $style->post_content['submit_width'] ) ?>" size="5" /> |
|
33 | 33 | </div> |
34 | 34 | |
35 | 35 | <div class="field-group clearfix"> |
36 | 36 | <label><?php _e( 'Height', 'formidable' ) ?></label> |
37 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_height') ) ?>" id="frm_submit_height" value="<?php echo esc_attr( $style->post_content['submit_height'] ) ?>" size="5" /> |
|
37 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_height' ) ) ?>" id="frm_submit_height" value="<?php echo esc_attr( $style->post_content['submit_height'] ) ?>" size="5" /> |
|
38 | 38 | </div> |
39 | 39 | |
40 | 40 | <div class="field-group clearfix"> |
41 | 41 | <label><?php _e( 'Weight', 'formidable' ) ?></label> |
42 | - <select name="<?php echo esc_attr( $frm_style->get_field_name('submit_weight') ) ?>" id="frm_submit_weight"> |
|
42 | + <select name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_weight' ) ) ?>" id="frm_submit_weight"> |
|
43 | 43 | <?php foreach ( FrmStyle::get_bold_options() as $value => $name ) { ?> |
44 | 44 | <option value="<?php echo esc_attr( $value ) ?>" <?php selected( $style->post_content['submit_weight'], $value ) ?>><?php echo esc_html( $name ) ?></option> |
45 | 45 | <?php } ?> |
@@ -48,48 +48,48 @@ discard block |
||
48 | 48 | |
49 | 49 | <div class="field-group clearfix"> |
50 | 50 | <label><?php _e( 'Corners', 'formidable' ) ?></label> |
51 | - <input type="text" value="<?php echo esc_attr( $style->post_content['submit_border_radius'] ) ?>" name="<?php echo esc_attr( $frm_style->get_field_name('submit_border_radius') ) ?>" id="frm_submit_border_radius" size="4"/> |
|
51 | + <input type="text" value="<?php echo esc_attr( $style->post_content['submit_border_radius'] ) ?>" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_border_radius' ) ) ?>" id="frm_submit_border_radius" size="4"/> |
|
52 | 52 | </div> |
53 | 53 | |
54 | 54 | <div class="field-group field-group-border clearfix"> |
55 | 55 | <label><?php _e( 'BG Color', 'formidable' ) ?></label> |
56 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_bg_color') ) ?>" id="frm_submit_bg_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_bg_color'] ) ?>" /> |
|
56 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_bg_color' ) ) ?>" id="frm_submit_bg_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_bg_color'] ) ?>" /> |
|
57 | 57 | </div> |
58 | 58 | |
59 | 59 | <div class="field-group clearfix"> |
60 | 60 | <label><?php _e( 'Text', 'formidable' ) ?></label> |
61 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_text_color') ) ?>" id="frm_submit_text_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_text_color'] ) ?>" /> |
|
61 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_text_color' ) ) ?>" id="frm_submit_text_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_text_color'] ) ?>" /> |
|
62 | 62 | </div> |
63 | 63 | |
64 | 64 | <div class="field-group field-group-border clearfix"> |
65 | 65 | <label><?php _e( 'Border', 'formidable' ) ?></label> |
66 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_border_color') ) ?>" id="frm_submit_border_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_border_color'] ) ?>" /> |
|
66 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_border_color' ) ) ?>" id="frm_submit_border_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_border_color'] ) ?>" /> |
|
67 | 67 | </div> |
68 | 68 | |
69 | 69 | <div class="field-group clearfix"> |
70 | 70 | <label><?php _e( 'Thickness', 'formidable' ) ?></label> |
71 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_border_width') ) ?>" id="frm_submit_border_width" value="<?php echo esc_attr( $style->post_content['submit_border_width'] ) ?>" size="4" /> |
|
71 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_border_width' ) ) ?>" id="frm_submit_border_width" value="<?php echo esc_attr( $style->post_content['submit_border_width'] ) ?>" size="4" /> |
|
72 | 72 | </div> |
73 | 73 | |
74 | 74 | <div class="field-group clearfix"> |
75 | 75 | <label><?php _e( 'Shadow', 'formidable' ) ?></label> |
76 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_shadow_color') ) ?>" id="frm_submit_shadow_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_shadow_color'] ) ?>" /> |
|
76 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_shadow_color' ) ) ?>" id="frm_submit_shadow_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_shadow_color'] ) ?>" /> |
|
77 | 77 | </div> |
78 | 78 | |
79 | 79 | <div class="clear"></div> |
80 | 80 | <div class="field-group field-group-border frm-full"> |
81 | 81 | <label><?php _e( 'BG Image', 'formidable' ) ?></label> |
82 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_bg_img') ) ?>" id="frm_submit_bg_img" value="<?php echo esc_attr( $style->post_content['submit_bg_img'] ) ?>" /> |
|
82 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_bg_img' ) ) ?>" id="frm_submit_bg_img" value="<?php echo esc_attr( $style->post_content['submit_bg_img'] ) ?>" /> |
|
83 | 83 | </div> |
84 | 84 | |
85 | 85 | <div class="field-group field-group-border clearfix"> |
86 | 86 | <label><?php _e( 'Margin', 'formidable' ) ?></label> |
87 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_margin') ) ?>" id="frm_submit_margin" value="<?php echo esc_attr( $style->post_content['submit_margin'] ) ?>" size="6" /> |
|
87 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_margin' ) ) ?>" id="frm_submit_margin" value="<?php echo esc_attr( $style->post_content['submit_margin'] ) ?>" size="6" /> |
|
88 | 88 | </div> |
89 | 89 | |
90 | 90 | <div class="field-group clearfix"> |
91 | 91 | <label><?php _e( 'Padding', 'formidable' ) ?></label> |
92 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_padding') ) ?>" id="frm_submit_padding" value="<?php echo esc_attr( $style->post_content['submit_padding'] ) ?>" size="6" /> |
|
92 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_padding' ) ) ?>" id="frm_submit_padding" value="<?php echo esc_attr( $style->post_content['submit_padding'] ) ?>" size="6" /> |
|
93 | 93 | </div> |
94 | 94 | <div class="clear"></div> |
95 | 95 | </div><!-- /.tabs-panel --> |
@@ -99,17 +99,17 @@ discard block |
||
99 | 99 | ?>"> |
100 | 100 | <div class="field-group clearfix"> |
101 | 101 | <label><?php _e( 'BG Color', 'formidable' ) ?></label> |
102 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_hover_bg_color') ) ?>" id="frm_submit_hover_bg_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_hover_bg_color'] ) ?>" /> |
|
102 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_hover_bg_color' ) ) ?>" id="frm_submit_hover_bg_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_hover_bg_color'] ) ?>" /> |
|
103 | 103 | </div> |
104 | 104 | |
105 | 105 | <div class="field-group clearfix"> |
106 | 106 | <label><?php _e( 'Text', 'formidable' ) ?></label> |
107 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_hover_color') ) ?>" id="frm_submit_hover_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_hover_color'] ) ?>" /> |
|
107 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_hover_color' ) ) ?>" id="frm_submit_hover_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_hover_color'] ) ?>" /> |
|
108 | 108 | </div> |
109 | 109 | |
110 | 110 | <div class="field-group clearfix"> |
111 | 111 | <label><?php _e( 'Border', 'formidable' ) ?></label> |
112 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_hover_border_color') ) ?>" id="frm_submit_hover_border_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_hover_border_color'] ) ?>" /> |
|
112 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_hover_border_color' ) ) ?>" id="frm_submit_hover_border_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_hover_border_color'] ) ?>" /> |
|
113 | 113 | </div> |
114 | 114 | |
115 | 115 | <div class="clear"></div> |
@@ -120,17 +120,17 @@ discard block |
||
120 | 120 | ?>"> |
121 | 121 | <div class="field-group clearfix"> |
122 | 122 | <label><?php _e( 'BG Color', 'formidable' ) ?></label> |
123 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_active_bg_color') ) ?>" id="frm_submit_active_bg_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_active_bg_color'] ) ?>" /> |
|
123 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_active_bg_color' ) ) ?>" id="frm_submit_active_bg_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_active_bg_color'] ) ?>" /> |
|
124 | 124 | </div> |
125 | 125 | |
126 | 126 | <div class="field-group clearfix"> |
127 | 127 | <label><?php _e( 'Text', 'formidable' ) ?></label> |
128 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_active_color') ) ?>" id="frm_submit_active_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_active_color'] ) ?>" /> |
|
128 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_active_color' ) ) ?>" id="frm_submit_active_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_active_color'] ) ?>" /> |
|
129 | 129 | </div> |
130 | 130 | |
131 | 131 | <div class="field-group clearfix"> |
132 | 132 | <label><?php _e( 'Border', 'formidable' ) ?></label> |
133 | - <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name('submit_active_border_color') ) ?>" id="frm_submit_active_border_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_active_border_color'] ) ?>" /> |
|
133 | + <input type="text" name="<?php echo esc_attr( $frm_style->get_field_name( 'submit_active_border_color' ) ) ?>" id="frm_submit_active_border_color" class="hex" value="<?php echo esc_attr( $style->post_content['submit_active_border_color'] ) ?>" /> |
|
134 | 134 | </div> |
135 | 135 | |
136 | 136 | <div class="clear"></div> |