|
1
|
|
|
<?php |
|
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
3
|
|
|
die( 'You are not allowed to call this page directly.' ); |
|
4
|
|
|
} |
|
5
|
|
|
|
|
6
|
|
|
class FrmEntriesHelper { |
|
7
|
|
|
|
|
8
|
|
|
public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
9
|
|
|
$values = array( |
|
10
|
|
|
'name' => '', |
|
11
|
|
|
'description' => '', |
|
12
|
|
|
'item_key' => '', |
|
13
|
|
|
); |
|
14
|
|
|
|
|
15
|
|
|
$values['fields'] = array(); |
|
16
|
|
|
if ( empty( $fields ) ) { |
|
17
|
|
|
return apply_filters( 'frm_setup_new_entry', $values ); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
foreach ( (array) $fields as $field ) { |
|
21
|
|
|
$original_default = $field->default_value; |
|
22
|
|
|
self::prepare_field_default_value( $field ); |
|
23
|
|
|
$new_value = self::get_field_value_for_new_entry( $field, $reset, $args ); |
|
24
|
|
|
|
|
25
|
|
|
$field_array = FrmAppHelper::start_field_array( $field ); |
|
26
|
|
|
$field_array['value'] = $new_value; |
|
27
|
|
|
$field_array['type'] = apply_filters( 'frm_field_type', $field->type, $field, $new_value ); |
|
28
|
|
|
$field_array['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id; |
|
29
|
|
|
$field_array['reset_value'] = $reset; |
|
30
|
|
|
$field_array['in_embed_form'] = isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0'; |
|
31
|
|
|
$field_array['original_default'] = $original_default; |
|
32
|
|
|
|
|
33
|
|
|
FrmFieldsHelper::prepare_new_front_field( $field_array, $field, $args ); |
|
34
|
|
|
|
|
35
|
|
|
$field_array = array_merge( $field->field_options, $field_array ); |
|
36
|
|
|
|
|
37
|
|
|
$values['fields'][] = $field_array; |
|
38
|
|
|
|
|
39
|
|
|
if ( ! $form || ! isset( $form->id ) ) { |
|
40
|
|
|
$form = FrmForm::getOne( $field->form_id ); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
FrmAppHelper::unserialize_or_decode( $form->options ); |
|
45
|
|
|
if ( is_array( $form->options ) ) { |
|
46
|
|
|
$values = array_merge( $values, $form->options ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$form_defaults = FrmFormsHelper::get_default_opts(); |
|
50
|
|
|
$frm_settings = FrmAppHelper::get_settings(); |
|
51
|
|
|
|
|
52
|
|
|
$form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' ); |
|
53
|
|
|
|
|
54
|
|
|
$values = array_merge( $form_defaults, $values ); |
|
55
|
|
|
|
|
56
|
|
|
return apply_filters( 'frm_setup_new_entry', $values ); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @since 2.05 |
|
61
|
|
|
* |
|
62
|
|
|
* @param object $field |
|
63
|
|
|
*/ |
|
64
|
|
|
private static function prepare_field_default_value( &$field ) { |
|
65
|
|
|
//If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array |
|
66
|
|
|
$return_array = FrmField::is_field_with_multiple_values( $field ); |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Do any shortcodes in default value and allow customization of default value. |
|
70
|
|
|
* Calls FrmProFieldsHelper::get_default_value |
|
71
|
|
|
*/ |
|
72
|
|
|
$field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true, $return_array ); |
|
73
|
|
|
|
|
74
|
|
|
if ( isset( $field->field_options['placeholder'] ) ) { |
|
75
|
|
|
$field->field_options['placeholder'] = apply_filters( 'frm_get_default_value', $field->field_options['placeholder'], $field, false, false ); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Set the value for each field |
|
81
|
|
|
* This function is used when the form is first loaded and on all page turns *for a new entry* |
|
82
|
|
|
* |
|
83
|
|
|
* @since 2.0.13 |
|
84
|
|
|
* |
|
85
|
|
|
* @param object $field - this is passed by reference since it is an object |
|
86
|
|
|
* @param boolean $reset |
|
87
|
|
|
* @param array $args |
|
88
|
|
|
* |
|
89
|
|
|
* @return string|array $new_value |
|
90
|
|
|
*/ |
|
91
|
|
|
private static function get_field_value_for_new_entry( $field, $reset, $args ) { |
|
92
|
|
|
$new_value = $field->default_value; |
|
93
|
|
|
|
|
94
|
|
|
if ( ! $reset && self::value_is_posted( $field, $args ) ) { |
|
95
|
|
|
self::get_posted_value( $field, $new_value, $args ); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if ( ! is_array( $new_value ) ) { |
|
99
|
|
|
$new_value = str_replace( '"', '"', $new_value ); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $new_value; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Check if a field has a posted value |
|
107
|
|
|
* |
|
108
|
|
|
* @since 2.01.0 |
|
109
|
|
|
* |
|
110
|
|
|
* @param object $field |
|
111
|
|
|
* @param array $args |
|
112
|
|
|
* |
|
113
|
|
|
* @return boolean $value_is_posted |
|
114
|
|
|
*/ |
|
115
|
|
|
public static function value_is_posted( $field, $args ) { |
|
116
|
|
|
$value_is_posted = false; |
|
117
|
|
|
if ( $_POST ) { |
|
118
|
|
|
$repeating = isset( $args['repeating'] ) && $args['repeating']; |
|
119
|
|
|
if ( $repeating ) { |
|
120
|
|
|
if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { |
|
121
|
|
|
$value_is_posted = true; |
|
122
|
|
|
} |
|
123
|
|
|
} elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { |
|
124
|
|
|
$value_is_posted = true; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $value_is_posted; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public static function setup_edit_vars( $values, $record ) { |
|
132
|
|
|
$values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' ); |
|
133
|
|
|
$values['form_id'] = $record->form_id; |
|
134
|
|
|
$values['is_draft'] = $record->is_draft; |
|
135
|
|
|
|
|
136
|
|
|
return apply_filters( 'frm_setup_edit_entry_vars', $values, $record ); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public static function replace_default_message( $message, $atts ) { |
|
140
|
|
|
if ( strpos( $message, '[default-message' ) === false && |
|
141
|
|
|
strpos( $message, '[default_message' ) === false && |
|
142
|
|
|
! empty( $message ) ) { |
|
143
|
|
|
return $message; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
if ( empty( $message ) ) { |
|
147
|
|
|
$message = '[default-message]'; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER ); |
|
151
|
|
|
|
|
152
|
|
|
foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
153
|
|
|
$add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] ); |
|
154
|
|
|
if ( ! empty( $add_atts ) ) { |
|
155
|
|
|
$this_atts = array_merge( $atts, $add_atts ); |
|
156
|
|
|
} else { |
|
157
|
|
|
$this_atts = $atts; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
$default = FrmEntriesController::show_entry_shortcode( $this_atts ); |
|
161
|
|
|
|
|
162
|
|
|
// Add the default message. |
|
163
|
|
|
$message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
return $message; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public static function prepare_display_value( $entry, $field, $atts ) { |
|
170
|
|
|
$field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false; |
|
171
|
|
|
|
|
172
|
|
|
if ( FrmAppHelper::pro_is_installed() ) { |
|
173
|
|
|
$empty = empty( $field_value ); |
|
174
|
|
|
FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value ); |
|
175
|
|
|
if ( $empty && ! empty( $field_value ) ) { |
|
176
|
|
|
// We've got an entry id, so switch it to a value. |
|
177
|
|
|
$atts['force_id'] = true; |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) { |
|
182
|
|
|
return self::display_value( $field_value, $field, $atts ); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
// This is an embeded form. |
|
186
|
|
|
$val = ''; |
|
187
|
|
|
|
|
188
|
|
|
if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) { |
|
189
|
|
|
// This is a repeating section. |
|
190
|
|
|
$child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) ); |
|
191
|
|
|
} else { |
|
192
|
|
|
// Get all values for this field. |
|
193
|
|
|
$child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
194
|
|
|
|
|
195
|
|
|
if ( $child_values ) { |
|
196
|
|
|
$child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
$field_value = array(); |
|
201
|
|
|
|
|
202
|
|
|
if ( ! isset( $child_entries ) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
|
|
|
|
|
203
|
|
|
return $val; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
foreach ( $child_entries as $child_entry ) { |
|
207
|
|
|
$atts['item_id'] = $child_entry->id; |
|
208
|
|
|
$atts['post_id'] = $child_entry->post_id; |
|
209
|
|
|
|
|
210
|
|
|
// Fet the value for this field -- check for post values as well. |
|
211
|
|
|
$entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field ); |
|
212
|
|
|
|
|
213
|
|
|
if ( $entry_val ) { |
|
214
|
|
|
// foreach entry get display_value. |
|
215
|
|
|
$field_value[] = self::display_value( $entry_val, $field, $atts ); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
unset( $child_entry ); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
$sep = ', '; |
|
222
|
|
|
if ( strpos( implode( ' ', (array) $field_value ), '<img' ) !== false ) { |
|
223
|
|
|
$sep = '<br/>'; |
|
224
|
|
|
} |
|
225
|
|
|
$val = implode( $sep, (array) $field_value ); |
|
226
|
|
|
|
|
227
|
|
|
return FrmAppHelper::kses( $val, 'all' ); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Prepare the saved value for display |
|
232
|
|
|
* |
|
233
|
|
|
* @param array|string $value |
|
234
|
|
|
* @param object $field |
|
235
|
|
|
* @param array $atts |
|
236
|
|
|
* |
|
237
|
|
|
* @return string |
|
238
|
|
|
*/ |
|
239
|
|
|
public static function display_value( $value, $field, $atts = array() ) { |
|
240
|
|
|
|
|
241
|
|
|
$defaults = array( |
|
242
|
|
|
'type' => '', |
|
243
|
|
|
'html' => false, |
|
244
|
|
|
'show_filename' => true, |
|
245
|
|
|
'truncate' => false, |
|
246
|
|
|
'sep' => ', ', |
|
247
|
|
|
'post_id' => 0, |
|
248
|
|
|
'form_id' => $field->form_id, |
|
249
|
|
|
'field' => $field, |
|
250
|
|
|
'keepjs' => 0, |
|
251
|
|
|
'return_array' => false, |
|
252
|
|
|
); |
|
253
|
|
|
|
|
254
|
|
|
$atts = wp_parse_args( $atts, $defaults ); |
|
255
|
|
|
|
|
256
|
|
|
if ( FrmField::is_image( $field ) || $field->type == 'star' ) { |
|
257
|
|
|
$atts['truncate'] = false; |
|
258
|
|
|
$atts['html'] = true; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
$atts = apply_filters( 'frm_display_value_atts', $atts, $field, $value ); |
|
262
|
|
|
|
|
263
|
|
|
if ( ! isset( $field->field_options['post_field'] ) ) { |
|
264
|
|
|
$field->field_options['post_field'] = ''; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
if ( ! isset( $field->field_options['custom_field'] ) ) { |
|
268
|
|
|
$field->field_options['custom_field'] = ''; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
272
|
|
|
$atts['pre_truncate'] = $atts['truncate']; |
|
273
|
|
|
$atts['truncate'] = true; |
|
274
|
|
|
$atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0; |
|
275
|
|
|
|
|
276
|
|
|
$value = FrmProEntryMetaHelper::get_post_value( $atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts ); |
|
277
|
|
|
$atts['truncate'] = $atts['pre_truncate']; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
if ( $value == '' ) { |
|
281
|
|
|
return $value; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
$unfiltered_value = $value; |
|
285
|
|
|
FrmAppHelper::unserialize_or_decode( $unfiltered_value ); |
|
286
|
|
|
|
|
287
|
|
|
$value = apply_filters( 'frm_display_value_custom', $unfiltered_value, $field, $atts ); |
|
288
|
|
|
$value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) ); |
|
289
|
|
|
|
|
290
|
|
|
if ( $value == $unfiltered_value ) { |
|
291
|
|
|
$value = FrmFieldsHelper::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) ); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
if ( $atts['truncate'] && $atts['type'] != 'url' ) { |
|
295
|
|
|
$value = FrmAppHelper::truncate( $value, 50 ); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
if ( ! $atts['keepjs'] && ! is_array( $value ) ) { |
|
299
|
|
|
$value = FrmAppHelper::kses( $value, 'all' ); |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
return apply_filters( 'frm_display_value', $value, $field, $atts ); |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
public static function set_posted_value( $field, $value, $args ) { |
|
306
|
|
|
// If validating a field with "other" opt, set back to prev value now. |
|
307
|
|
|
if ( isset( $args['other'] ) && $args['other'] ) { |
|
308
|
|
|
$value = $args['temp_value']; |
|
309
|
|
|
} |
|
310
|
|
|
if ( empty( $args['parent_field_id'] ) ) { |
|
311
|
|
|
$_POST['item_meta'][ $field->id ] = $value; |
|
312
|
|
|
} else { |
|
313
|
|
|
self::set_parent_field_posted_value( $field, $value, $args ); |
|
314
|
|
|
} |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* Init arrays if necessary, else we get fatal error. |
|
319
|
|
|
* |
|
320
|
|
|
* @since 4.01 |
|
321
|
|
|
*/ |
|
322
|
|
|
private static function set_parent_field_posted_value( $field, $value, $args ) { |
|
323
|
|
|
if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) && |
|
324
|
|
|
is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) { |
|
325
|
|
|
|
|
326
|
|
|
if ( ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) || |
|
327
|
|
|
! is_array( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) ) { |
|
328
|
|
|
$_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array(); |
|
329
|
|
|
} |
|
330
|
|
|
} else { |
|
331
|
|
|
// All of the section was probably removed. |
|
332
|
|
|
$_POST['item_meta'][ $args['parent_field_id'] ] = array(); |
|
333
|
|
|
$_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array(); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
$_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
public static function get_posted_value( $field, &$value, $args ) { |
|
340
|
|
|
if ( is_array( $field ) ) { |
|
341
|
|
|
$field_id = $field['id']; |
|
342
|
|
|
$field_obj = FrmFieldFactory::get_field_object( $field['id'] ); |
|
343
|
|
|
} else if ( is_object( $field ) ) { |
|
344
|
|
|
$field_id = $field->id; |
|
345
|
|
|
$field_obj = FrmFieldFactory::get_field_object( $field ); |
|
346
|
|
|
} else if ( is_numeric( $field ) ) { |
|
347
|
|
|
$field_id = $field; |
|
348
|
|
|
$field_obj = FrmFieldFactory::get_field_object( $field ); |
|
349
|
|
|
} else { |
|
350
|
|
|
$value = self::get_posted_meta( $field, $args ); |
|
351
|
|
|
FrmAppHelper::sanitize_value( 'sanitize_text_field', $value ); |
|
352
|
|
|
return; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
$value = self::get_posted_meta( $field_id, $args ); |
|
356
|
|
|
|
|
357
|
|
|
$field_obj->sanitize_value( $value ); |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* @since 4.02.04 |
|
362
|
|
|
*/ |
|
363
|
|
|
private static function get_posted_meta( $field_id, $args ) { |
|
364
|
|
|
if ( empty( $args['parent_field_id'] ) ) { |
|
365
|
|
|
// Sanitizing is done next. |
|
366
|
|
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
|
367
|
|
|
$value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : ''; |
|
368
|
|
|
} else { |
|
369
|
|
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
|
370
|
|
|
$value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) : ''; |
|
371
|
|
|
} |
|
372
|
|
|
return $value; |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* Check if field has an "Other" option and if any other values are posted |
|
377
|
|
|
* |
|
378
|
|
|
* @since 2.0 |
|
379
|
|
|
* |
|
380
|
|
|
* @param object $field |
|
381
|
|
|
* @param string|array $value |
|
382
|
|
|
* @param array $args |
|
383
|
|
|
*/ |
|
384
|
|
|
public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
385
|
|
|
$args['other'] = false; |
|
386
|
|
|
if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
387
|
|
|
return; |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
// Trim excess values if selection limit is exceeded for checkbox. Necessary to do here |
|
391
|
|
|
// as the value set here will be used later in this class's set_posted_value() method. |
|
392
|
|
|
if ( FrmField::is_checkbox( $field ) ) { |
|
393
|
|
|
$field_obj = FrmFieldFactory::get_field_object( $field ); |
|
394
|
|
|
$field_obj->maybe_trim_excess_values( $value ); |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
// Get other value for fields in repeating section. |
|
398
|
|
|
self::set_other_repeating_vals( $field, $value, $args ); |
|
399
|
|
|
|
|
400
|
|
|
// Check if there are any posted "Other" values. |
|
401
|
|
|
if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { |
|
402
|
|
|
|
|
403
|
|
|
// Save original value. |
|
404
|
|
|
$args['temp_value'] = $value; |
|
405
|
|
|
$args['other'] = true; |
|
406
|
|
|
|
|
407
|
|
|
// Sanitizing is done next. |
|
408
|
|
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
|
409
|
|
|
$other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); |
|
410
|
|
|
FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals ); |
|
411
|
|
|
|
|
412
|
|
|
// Set the validation value now |
|
413
|
|
|
self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
414
|
|
|
} |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
/** |
|
418
|
|
|
* Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
419
|
|
|
* |
|
420
|
|
|
* @since 2.0 |
|
421
|
|
|
* |
|
422
|
|
|
* @param object $field |
|
423
|
|
|
* @param string|array $value |
|
424
|
|
|
* @param array $args |
|
425
|
|
|
*/ |
|
426
|
|
|
public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
427
|
|
|
if ( ! $args['parent_field_id'] ) { |
|
428
|
|
|
return; |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
// Check if there are any other posted "other" values for this field. |
|
432
|
|
|
if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { |
|
433
|
|
|
// Save original value |
|
434
|
|
|
$args['temp_value'] = $value; |
|
435
|
|
|
$args['other'] = true; |
|
436
|
|
|
|
|
437
|
|
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
|
438
|
|
|
$other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ); |
|
439
|
|
|
FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals ); |
|
440
|
|
|
|
|
441
|
|
|
// Set the validation value now. |
|
442
|
|
|
self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
443
|
|
|
} |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
/** |
|
447
|
|
|
* Modify value used for validation |
|
448
|
|
|
* This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
449
|
|
|
* It also adds any text from the free text fields to the value |
|
450
|
|
|
* |
|
451
|
|
|
* Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
452
|
|
|
* |
|
453
|
|
|
* @since 2.0 |
|
454
|
|
|
* |
|
455
|
|
|
* @param string|array $value |
|
456
|
|
|
* @param string|array $other_vals (usually of posted values) |
|
457
|
|
|
* @param object $field |
|
458
|
|
|
* @param array $args |
|
459
|
|
|
*/ |
|
460
|
|
|
public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
461
|
|
|
// Checkboxes and multi-select dropdowns. |
|
462
|
|
|
if ( is_array( $value ) && $field->type === 'checkbox' ) { |
|
463
|
|
|
// Combine "Other" values with checked values. "Other" values will override checked box values. |
|
464
|
|
|
foreach ( $other_vals as $k => $v ) { |
|
|
|
|
|
|
465
|
|
|
if ( isset( $value[ $k ] ) && trim( $v ) === '' ) { |
|
466
|
|
|
// If the other box is checked, but doesn't have a value. |
|
467
|
|
|
$value = ''; |
|
468
|
|
|
break; |
|
469
|
|
|
} |
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
|
|
if ( is_array( $value ) && ! empty( $value ) ) { |
|
473
|
|
|
$value = array_merge( $value, $other_vals ); |
|
474
|
|
|
} |
|
475
|
|
|
} else { |
|
476
|
|
|
// Radio and dropdowns. |
|
477
|
|
|
$other_key = array_filter( array_keys( $field->options ), 'is_string' ); |
|
478
|
|
|
$other_key = reset( $other_key ); |
|
479
|
|
|
|
|
480
|
|
|
// Multi-select dropdown. |
|
481
|
|
|
if ( is_array( $value ) ) { |
|
482
|
|
|
$o_key = array_search( $field->options[ $other_key ], $value ); |
|
483
|
|
|
|
|
484
|
|
|
if ( $o_key !== false ) { |
|
485
|
|
|
// Modify the original value so other key will be preserved. |
|
486
|
|
|
$value[ $other_key ] = $value[ $o_key ]; |
|
487
|
|
|
|
|
488
|
|
|
// By default, the array keys will be numeric for multi-select dropdowns. |
|
489
|
|
|
// If going backwards and forwards between pages, the array key will match the other key. |
|
490
|
|
|
if ( $o_key !== $other_key ) { |
|
491
|
|
|
unset( $value[ $o_key ] ); |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
$args['temp_value'] = $value; |
|
495
|
|
|
$value[ $other_key ] = reset( $other_vals ); |
|
496
|
|
|
if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) { |
|
497
|
|
|
unset( $value[ $other_key ] ); |
|
498
|
|
|
} |
|
499
|
|
|
} |
|
500
|
|
|
} elseif ( $field->options[ $other_key ] == $value ) { |
|
501
|
|
|
$value = $other_vals; |
|
502
|
|
|
} |
|
503
|
|
|
} |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
/** |
|
507
|
|
|
* Add submitted values to a string for spam checking. |
|
508
|
|
|
* |
|
509
|
|
|
* @param array $values |
|
510
|
|
|
*/ |
|
511
|
|
|
public static function entry_array_to_string( $values ) { |
|
512
|
|
|
$content = ''; |
|
513
|
|
|
foreach ( $values['item_meta'] as $val ) { |
|
514
|
|
|
if ( $content != '' ) { |
|
515
|
|
|
$content .= "\n\n"; |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
if ( is_array( $val ) ) { |
|
519
|
|
|
$val = FrmAppHelper::array_flatten( $val ); |
|
520
|
|
|
$val = implode( ', ', $val ); |
|
521
|
|
|
} |
|
522
|
|
|
|
|
523
|
|
|
$content .= $val; |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
return $content; |
|
527
|
|
|
} |
|
528
|
|
|
|
|
529
|
|
|
/** |
|
530
|
|
|
* Get the browser from the user agent |
|
531
|
|
|
* |
|
532
|
|
|
* @since 2.04 |
|
533
|
|
|
* |
|
534
|
|
|
* @param string $u_agent |
|
535
|
|
|
* |
|
536
|
|
|
* @return string |
|
537
|
|
|
*/ |
|
538
|
|
|
public static function get_browser( $u_agent ) { |
|
539
|
|
|
$bname = __( 'Unknown', 'formidable' ); |
|
540
|
|
|
$platform = __( 'Unknown', 'formidable' ); |
|
541
|
|
|
$ub = ''; |
|
542
|
|
|
|
|
543
|
|
|
// Get the operating system |
|
544
|
|
|
if ( preg_match( '/windows|win32/i', $u_agent ) ) { |
|
545
|
|
|
$platform = 'Windows'; |
|
546
|
|
|
} elseif ( preg_match( '/android/i', $u_agent ) ) { |
|
547
|
|
|
$platform = 'Android'; |
|
548
|
|
|
} elseif ( preg_match( '/linux/i', $u_agent ) ) { |
|
549
|
|
|
$platform = 'Linux'; |
|
550
|
|
|
} elseif ( preg_match( '/macintosh|mac os x/i', $u_agent ) ) { |
|
551
|
|
|
$platform = 'OS X'; |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
$agent_options = array( |
|
555
|
|
|
'Chrome' => 'Google Chrome', |
|
556
|
|
|
'Safari' => 'Apple Safari', |
|
557
|
|
|
'Opera' => 'Opera', |
|
558
|
|
|
'Netscape' => 'Netscape', |
|
559
|
|
|
'Firefox' => 'Mozilla Firefox', |
|
560
|
|
|
); |
|
561
|
|
|
|
|
562
|
|
|
// Next get the name of the useragent yes seperately and for good reason |
|
563
|
|
|
if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) { |
|
564
|
|
|
$bname = 'Internet Explorer'; |
|
565
|
|
|
$ub = 'MSIE'; |
|
566
|
|
|
} else { |
|
567
|
|
|
foreach ( $agent_options as $agent_key => $agent_name ) { |
|
568
|
|
|
if ( strpos( $u_agent, $agent_key ) !== false ) { |
|
569
|
|
|
$bname = $agent_name; |
|
570
|
|
|
$ub = $agent_key; |
|
571
|
|
|
break; |
|
572
|
|
|
} |
|
573
|
|
|
} |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
// finally get the correct version number |
|
577
|
|
|
$known = array( 'Version', $ub, 'other' ); |
|
578
|
|
|
$pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#'; |
|
579
|
|
|
preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers |
|
580
|
|
|
|
|
581
|
|
|
// see how many we have |
|
582
|
|
|
$i = count( $matches['browser'] ); |
|
583
|
|
|
|
|
584
|
|
|
if ( $i > 1 ) { |
|
585
|
|
|
//we will have two since we are not using 'other' argument yet |
|
586
|
|
|
//see if version is before or after the name |
|
587
|
|
|
if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) { |
|
588
|
|
|
$version = $matches['version'][0]; |
|
589
|
|
|
} else { |
|
590
|
|
|
$version = $matches['version'][1]; |
|
591
|
|
|
} |
|
592
|
|
|
} elseif ( $i === 1 ) { |
|
593
|
|
|
$version = $matches['version'][0]; |
|
594
|
|
|
} else { |
|
595
|
|
|
$version = ''; |
|
596
|
|
|
} |
|
597
|
|
|
|
|
598
|
|
|
// check if we have a number |
|
599
|
|
|
if ( $version == '' ) { |
|
600
|
|
|
$version = '?'; |
|
601
|
|
|
} |
|
602
|
|
|
|
|
603
|
|
|
return $bname . ' ' . $version . ' / ' . $platform; |
|
604
|
|
|
} |
|
605
|
|
|
|
|
606
|
|
|
/** |
|
607
|
|
|
* @since 3.0 |
|
608
|
|
|
*/ |
|
609
|
|
|
public static function actions_dropdown( $atts ) { |
|
610
|
|
|
$id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); |
|
611
|
|
|
$links = self::get_action_links( $id, $atts['entry'] ); |
|
612
|
|
|
|
|
613
|
|
|
foreach ( $links as $link ) { |
|
614
|
|
|
?> |
|
615
|
|
|
<div class="misc-pub-section"> |
|
616
|
|
|
<a href="<?php echo esc_url( FrmAppHelper::maybe_full_screen_link( $link['url'] ) ); ?>" |
|
617
|
|
|
<?php |
|
618
|
|
View Code Duplication |
if ( isset( $link['data'] ) ) { |
|
|
|
|
|
|
619
|
|
|
foreach ( $link['data'] as $data => $value ) { |
|
620
|
|
|
echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" '; |
|
621
|
|
|
} |
|
622
|
|
|
} |
|
623
|
|
|
if ( isset( $link['class'] ) ) { |
|
624
|
|
|
echo 'class="' . esc_attr( $link['class'] ) . '" '; |
|
625
|
|
|
} |
|
626
|
|
|
if ( isset( $link['id'] ) ) { |
|
627
|
|
|
echo 'id="' . esc_attr( $link['id'] ) . '" '; |
|
628
|
|
|
} |
|
629
|
|
|
?> |
|
630
|
|
|
> |
|
631
|
|
|
<?php FrmAppHelper::icon_by_class( $link['icon'], array( 'aria-hidden' => 'true' ) ); ?> |
|
632
|
|
|
<span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span> |
|
633
|
|
|
</a> |
|
634
|
|
|
</div> |
|
635
|
|
|
<?php |
|
636
|
|
|
} |
|
637
|
|
|
} |
|
638
|
|
|
|
|
639
|
|
|
/** |
|
640
|
|
|
* @since 3.0 |
|
641
|
|
|
*/ |
|
642
|
|
|
private static function get_action_links( $id, $entry ) { |
|
643
|
|
|
$page = FrmAppHelper::get_param( 'frm_action' ); |
|
644
|
|
|
$actions = array(); |
|
645
|
|
|
|
|
646
|
|
|
if ( $page != 'show' ) { |
|
647
|
|
|
$actions['frm_view'] = array( |
|
648
|
|
|
'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=show&id=' . $id . '&form=' . $entry->form_id ), |
|
649
|
|
|
'label' => __( 'View Entry', 'formidable' ), |
|
650
|
|
|
'icon' => 'frm_icon_font frm_save_icon', |
|
651
|
|
|
); |
|
652
|
|
|
} |
|
653
|
|
|
|
|
654
|
|
|
if ( current_user_can( 'frm_delete_entries' ) ) { |
|
655
|
|
|
$actions['frm_delete'] = array( |
|
656
|
|
|
'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ), |
|
657
|
|
|
'label' => __( 'Delete Entry', 'formidable' ), |
|
658
|
|
|
'icon' => 'frm_icon_font frm_delete_icon', |
|
659
|
|
|
'data' => array( |
|
660
|
|
|
'frmverify' => __( 'Delete this form entry?', 'formidable' ), |
|
661
|
|
|
), |
|
662
|
|
|
); |
|
663
|
|
|
} |
|
664
|
|
|
|
|
665
|
|
|
if ( $page == 'show' ) { |
|
666
|
|
|
$actions['frm_print'] = array( |
|
667
|
|
|
'url' => '#', |
|
668
|
|
|
'label' => __( 'Print Entry', 'formidable' ), |
|
669
|
|
|
'data' => array( |
|
670
|
|
|
'frmprint' => '1', |
|
671
|
|
|
), |
|
672
|
|
|
'icon' => 'frm_icon_font frm_printer_icon', |
|
673
|
|
|
); |
|
674
|
|
|
} |
|
675
|
|
|
|
|
676
|
|
|
$actions['frm_resend'] = array( |
|
677
|
|
|
'url' => '#', |
|
678
|
|
|
'label' => __( 'Resend Emails', 'formidable' ), |
|
679
|
|
|
'class' => 'frm_noallow', |
|
680
|
|
|
'data' => array( |
|
681
|
|
|
'upgrade' => __( 'Resend Emails', 'formidable' ), |
|
682
|
|
|
'medium' => 'resend-email', |
|
683
|
|
|
'content' => 'entry', |
|
684
|
|
|
), |
|
685
|
|
|
'icon' => 'frm_icon_font frm_email_icon', |
|
686
|
|
|
); |
|
687
|
|
|
|
|
688
|
|
|
$actions['frm_edit'] = array( |
|
689
|
|
|
'url' => '#', |
|
690
|
|
|
'label' => __( 'Edit Entry', 'formidable' ), |
|
691
|
|
|
'class' => 'frm_noallow', |
|
692
|
|
|
'data' => array( |
|
693
|
|
|
'upgrade' => __( 'Entry edits', 'formidable' ), |
|
694
|
|
|
'medium' => 'edit-entries', |
|
695
|
|
|
'content' => 'entry', |
|
696
|
|
|
), |
|
697
|
|
|
'icon' => 'frm_icon_font frm_pencil_icon', |
|
698
|
|
|
); |
|
699
|
|
|
|
|
700
|
|
|
return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) ); |
|
701
|
|
|
} |
|
702
|
|
|
} |
|
703
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.