PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/helpers/FrmEntriesHelper.php +156 -419 6.335.4 View file →
@@ -4,34 +4,8 @@
4 4 }
5 5
6 6 class FrmEntriesHelper {
7 7
8 - /**
9 - * "Submitted" entry status.
10 - *
11 - * @since 6.4.2
12 - *
13 - * @var int
14 - */
15 - const SUBMITTED_ENTRY_STATUS = 0;
16 -
17 - /**
18 - * "Draft" entry status.
19 - *
20 - * @since 6.4.2
21 - *
22 - * @var int
23 - */
24 - const DRAFT_ENTRY_STATUS = 1;
25 -
26 - /**
27 - * @param mixed $fields
28 - * @param object|string $form
29 - * @param bool $reset
30 - * @param array $args
31 - *
32 - * @return array
33 - */
34 8 public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) {
35 9 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
36 10
37 11 $values = array(
@@ -40,10 +14,9 @@
40 14 'item_key' => '',
41 15 );
42 16
43 17 $values['fields'] = array();
44 -
45 - if ( ! $fields ) {
18 + if ( empty( $fields ) ) {
46 19 return apply_filters( 'frm_setup_new_entry', $values );
47 20 }
48 21
49 22 foreach ( (array) $fields as $field ) {
@@ -48,23 +21,20 @@
48 21
49 22 foreach ( (array) $fields as $field ) {
50 23 $original_default = $field->default_value;
51 24 self::prepare_field_default_value( $field );
52 - $new_value = self::get_field_value_for_new_entry( $field, $reset, $args );
25 + $new_value = self::get_field_value_for_new_entry( $field, $reset, $args );
26 +
53 27 $field_array = FrmAppHelper::start_field_array( $field );
54 28 $field_array['value'] = $new_value;
55 29 $field_array['type'] = apply_filters( 'frm_field_type', $field->type, $field, $new_value );
56 - $field_array['parent_form_id'] = $args['parent_form_id'] ?? $field->form_id;
30 + $field_array['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
57 31 $field_array['reset_value'] = $reset;
58 - $field_array['in_embed_form'] = $args['in_embed_form'] ?? '0';
32 + $field_array['in_embed_form'] = isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0';
59 33 $field_array['original_default'] = $original_default;
60 34
61 35 FrmFieldsHelper::prepare_new_front_field( $field_array, $field, $args );
62 36
63 - if ( ! is_array( $field->field_options ) ) {
64 - $field->field_options = array();
65 - }
66 -
67 37 $field_array = array_merge( $field->field_options, $field_array );
68 38
69 39 $values['fields'][] = $field_array;
70 40
@@ -70,12 +40,11 @@
70 40
71 41 if ( ! $form || ! isset( $form->id ) ) {
72 42 $form = FrmForm::getOne( $field->form_id );
73 43 }
74 - }//end foreach
44 + }
75 45
76 46 FrmAppHelper::unserialize_or_decode( $form->options );
77 -
78 47 if ( is_array( $form->options ) ) {
79 48 $values = array_merge( $values, $form->options );
80 49 }
81 50
@@ -90,13 +59,11 @@
90 59 /**
91 60 * @since 2.05
92 61 *
93 62 * @param object $field
94 - *
95 - * @return void
96 63 */
97 64 private static function prepare_field_default_value( &$field ) {
98 - // If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array.
65 + //If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array
99 66 $return_array = FrmField::is_field_with_multiple_values( $field );
100 67
101 68 /**
102 69 * Do any shortcodes in default value and allow customization of default value.
@@ -114,13 +81,13 @@
114 81 * This function is used when the form is first loaded and on all page turns *for a new entry*
115 82 *
116 83 * @since 2.0.13
117 84 *
118 - * @param object $field - this is passed by reference since it is an object.
119 - * @param bool $reset
120 - * @param array $args
85 + * @param object $field - this is passed by reference since it is an object
86 + * @param boolean $reset
87 + * @param array $args
121 88 *
122 - * @return array|string New value.
89 + * @return string|array $new_value
123 90 */
124 91 private static function get_field_value_for_new_entry( $field, $reset, $args ) {
125 92 $new_value = $field->default_value;
126 93
@@ -128,9 +95,9 @@
128 95 self::get_posted_value( $field, $new_value, $args );
129 96 }
130 97
131 98 if ( ! is_array( $new_value ) ) {
132 - return str_replace( '"', '"', $new_value );
99 + $new_value = str_replace( '"', '"', $new_value );
133 100 }
134 101
135 102 return $new_value;
136 103 }
@@ -140,38 +107,28 @@
140 107 *
141 108 * @since 2.01.0
142 109 *
143 110 * @param object $field
144 - * @param array $args
111 + * @param array $args
145 112 *
146 - * @return bool True if a value is posted.
113 + * @return boolean $value_is_posted
147 114 */
148 115 public static function value_is_posted( $field, $args ) {
149 116 $value_is_posted = false;
150 -
151 - if ( ! $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
152 - return $value_is_posted;
153 - }
154 -
155 - $repeating = ! empty( $args['repeating'] );
156 -
157 - if ( $repeating ) {
158 - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
117 + if ( $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
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 ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
121 + $value_is_posted = true;
122 + }
123 + } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
159 124 $value_is_posted = true;
160 125 }
161 - } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
162 - $value_is_posted = true;
163 126 }
164 127
165 128 return $value_is_posted;
166 129 }
167 130
168 - /**
169 - * @param array $values
170 - * @param object $record
171 - *
172 - * @return array
173 - */
174 131 public static function setup_edit_vars( $values, $record ) {
175 132 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
176 133
177 134 $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' );
@@ -180,22 +137,16 @@
180 137
181 138 return apply_filters( 'frm_setup_edit_entry_vars', $values, $record );
182 139 }
183 140
184 - /**
185 - * @param string $message
186 - * @param array $atts
187 - *
188 - * @return string
189 - */
190 141 public static function replace_default_message( $message, $atts ) {
191 - if ( ! str_contains( $message, '[default-message' ) &&
192 - ! str_contains( $message, '[default_message' ) &&
193 - $message ) {
142 + if ( strpos( $message, '[default-message' ) === false &&
143 + strpos( $message, '[default_message' ) === false &&
144 + ! empty( $message ) ) {
194 145 return $message;
195 146 }
196 147
197 - if ( ! $message ) {
148 + if ( empty( $message ) ) {
198 149 $message = '[default-message]';
199 150 }
200 151
201 152 preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
@@ -200,12 +151,17 @@
200 151
201 152 preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
202 153
203 154 foreach ( $shortcodes[0] as $short_key => $tag ) {
204 - $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
205 - $this_atts = $add_atts ? array_merge( $atts, $add_atts ) : $atts;
206 - $default = FrmEntriesController::show_entry_shortcode( $this_atts );
155 + $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
156 + if ( ! empty( $add_atts ) ) {
157 + $this_atts = array_merge( $atts, $add_atts );
158 + } else {
159 + $this_atts = $atts;
160 + }
207 161
162 + $default = FrmEntriesController::show_entry_shortcode( $this_atts );
163 +
208 164 // Add the default message.
209 165 $message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
210 166 }
211 167
@@ -211,48 +167,33 @@
211 167
212 168 return $message;
213 169 }
214 170
215 - /**
216 - * @param stdClass $entry
217 - * @param stdClass $field
218 - * @param array $atts
219 - *
220 - * @return string
221 - */
222 171 public static function prepare_display_value( $entry, $field, $atts ) {
223 - $field_value = $entry->metas[ $field->id ] ?? false;
172 + $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
224 173
225 174 if ( FrmAppHelper::pro_is_installed() ) {
226 - $empty = ! $field_value;
175 + $empty = empty( $field_value );
227 176 FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value );
228 -
229 - if ( $empty && $field_value ) {
177 + if ( $empty && ! empty( $field_value ) ) {
230 178 // We've got an entry id, so switch it to a value.
231 179 $atts['force_id'] = true;
232 180 }
233 181 }
234 182
235 - // phpcs:ignore Universal.Operators.StrictComparisons
236 183 if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) {
237 184 return self::display_value( $field_value, $field, $atts );
238 185 }
239 186
240 - if ( ! FrmAppHelper::pro_is_installed() ) {
241 - return '';
242 - }
187 + // This is an embeded form.
188 + $val = '';
243 189
244 - if ( is_callable( 'FrmProEntriesHelper::prepare_child_display_value' ) ) {
245 - return FrmProEntriesHelper::prepare_child_display_value( $entry, $field, $atts );
246 - }
247 -
248 - // This is an embedded form.
249 - if ( str_starts_with( $atts['embedded_field_id'], 'form' ) ) {
190 + if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) {
250 191 // This is a repeating section.
251 - $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ), '', '', true );
192 + $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) );
252 193 } else {
253 194 // Get all values for this field.
254 - $child_values = $entry->metas[ $atts['embedded_field_id'] ] ?? false;
195 + $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
255 196
256 197 if ( $child_values ) {
257 198 $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
258 199 }
@@ -257,14 +198,14 @@
257 198 $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
258 199 }
259 200 }
260 201
261 - if ( empty( $child_entries ) ) {
262 - return '';
202 + $field_value = array();
203 +
204 + if ( ! isset( $child_entries ) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) {
205 + return $val;
263 206 }
264 207
265 - $field_value = array();
266 -
267 208 foreach ( $child_entries as $child_entry ) {
268 209 $atts['item_id'] = $child_entry->id;
269 210 $atts['post_id'] = $child_entry->post_id;
270 211
@@ -271,9 +212,9 @@
271 212 // Fet the value for this field -- check for post values as well.
272 213 $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field );
273 214
274 215 if ( $entry_val || '0' === $entry_val ) {
275 - // For each entry get display_value.
216 + // foreach entry get display_value.
276 217 $field_value[] = self::display_value( $entry_val, $field, $atts );
277 218 }
278 219
279 220 unset( $child_entry );
@@ -279,15 +220,13 @@
279 220 unset( $child_entry );
280 221 }
281 222
282 223 $sep = ', ';
283 -
284 - if ( str_contains( implode( ' ', $field_value ), '<img' ) ) {
224 + if ( strpos( implode( ' ', (array) $field_value ), '<img' ) !== false ) {
285 225 $sep = '<br/>';
286 226 }
227 + $val = implode( $sep, (array) $field_value );
287 228
288 - $val = implode( $sep, $field_value );
289 -
290 229 return FrmAppHelper::kses( $val, 'all' );
291 230 }
292 231
293 232 /**
@@ -293,14 +232,15 @@
293 232 /**
294 233 * Prepare the saved value for display
295 234 *
296 235 * @param array|string $value
297 - * @param object $field
298 - * @param array $atts
236 + * @param object $field
237 + * @param array $atts
299 238 *
300 239 * @return string
301 240 */
302 241 public static function display_value( $value, $field, $atts = array() ) {
242 +
303 243 $defaults = array(
304 244 'type' => '',
305 245 'html' => false,
306 246 'show_filename' => true,
@@ -314,9 +254,9 @@
314 254 );
315 255
316 256 $atts = wp_parse_args( $atts, $defaults );
317 257
318 - if ( FrmField::is_image( $field ) || $field->type === 'star' ) {
258 + if ( FrmField::is_image( $field ) || $field->type == 'star' ) {
319 259 $atts['truncate'] = false;
320 260 $atts['html'] = true;
321 261 }
322 262
@@ -321,12 +261,8 @@
321 261 }
322 262
323 263 $atts = apply_filters( 'frm_display_value_atts', $atts, $field, $value );
324 264
325 - if ( is_string( $field->field_options ) ) {
326 - $field->field_options = array();
327 - }
328 -
329 265 if ( ! isset( $field->field_options['post_field'] ) ) {
330 266 $field->field_options['post_field'] = '';
331 267 }
332 268
@@ -333,34 +269,32 @@
333 269 if ( ! isset( $field->field_options['custom_field'] ) ) {
334 270 $field->field_options['custom_field'] = '';
335 271 }
336 272
337 - if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] === 'tag' ) ) {
273 + if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
338 274 $atts['pre_truncate'] = $atts['truncate'];
339 275 $atts['truncate'] = true;
340 - $atts['exclude_cat'] = $field->field_options['exclude_cat'] ?? 0;
276 + $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0;
341 277
342 278 $value = FrmProEntryMetaHelper::get_post_value( $atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts );
343 279 $atts['truncate'] = $atts['pre_truncate'];
344 280 }
345 281
346 - // phpcs:ignore Universal.Operators.StrictComparisons
347 282 if ( $value == '' ) {
348 283 return $value;
349 284 }
350 285
351 286 $unfiltered_value = $value;
352 - FrmFieldsHelper::prepare_field_value( $unfiltered_value, $field->type );
287 + FrmAppHelper::unserialize_or_decode( $unfiltered_value );
353 288
354 289 $value = apply_filters( 'frm_display_value_custom', $unfiltered_value, $field, $atts );
355 290 $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) );
356 291
357 - // phpcs:ignore Universal.Operators.StrictComparisons
358 292 if ( $value == $unfiltered_value ) {
359 293 $value = FrmFieldsHelper::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
360 294 }
361 295
362 - if ( $atts['truncate'] && $atts['type'] !== 'url' ) {
296 + if ( $atts['truncate'] && $atts['type'] != 'url' ) {
363 297 $value = FrmAppHelper::truncate( $value, 50 );
364 298 }
365 299
366 300 if ( ! $atts['keepjs'] && ! is_array( $value ) ) {
@@ -369,21 +303,13 @@
369 303
370 304 return apply_filters( 'frm_display_value', $value, $field, $atts );
371 305 }
372 306
373 - /**
374 - * @param object $field
375 - * @param mixed $value
376 - * @param array $args
377 - *
378 - * @return void
379 - */
380 307 public static function set_posted_value( $field, $value, $args ) {
381 308 // If validating a field with "other" opt, set back to prev value now.
382 - if ( ! empty( $args['other'] ) ) {
309 + if ( isset( $args['other'] ) && $args['other'] ) {
383 310 $value = $args['temp_value'];
384 311 }
385 -
386 312 if ( empty( $args['parent_field_id'] ) ) {
387 313 $_POST['item_meta'][ $field->id ] = $value;
388 314 } else {
389 315 self::set_parent_field_posted_value( $field, $value, $args );
@@ -393,18 +319,12 @@
393 319 /**
394 320 * Init arrays if necessary, else we get fatal error.
395 321 *
396 322 * @since 4.01
397 - *
398 - * @param object $field Field object.
399 - * @param mixed $value Value to set.
400 - * @param array $args Additional arguments.
401 - *
402 - * @return void
403 323 */
404 324 private static function set_parent_field_posted_value( $field, $value, $args ) {
405 - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) && is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
406 - if ( ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) || ! is_array( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
325 + if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) && is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
326 + if ( ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) || ! is_array( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
407 327 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
408 328 }
409 329 } else {
410 330 // All of the section was probably removed.
@@ -414,27 +334,15 @@
414 334
415 335 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; // phpcs:ignore WordPress.Security.NonceVerification.Missing
416 336 }
417 337
418 - /**
419 - * @param array|int|object|string $field
420 - * @param mixed $value
421 - * @param array $args
422 - *
423 - * @return void
424 - */
425 338 public static function get_posted_value( $field, &$value, $args ) {
426 339 if ( is_array( $field ) ) {
427 340 $field_id = $field['id'];
428 341 $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
429 342 } elseif ( is_object( $field ) ) {
430 - $field_id = $field->id;
431 -
432 - if ( 'hidden' === $field->type && ! empty( $field->field_options['original_type'] ) ) {
433 - $field_obj = FrmFieldFactory::get_field_type( $field->field_options['original_type'], $field );
434 - } else {
435 - $field_obj = FrmFieldFactory::get_field_object( $field );
436 - }
343 + $field_id = $field->id;
344 + $field_obj = FrmFieldFactory::get_field_object( $field );
437 345 } elseif ( is_numeric( $field ) ) {
438 346 $field_id = $field;
439 347 $field_obj = FrmFieldFactory::get_field_object( $field );
440 348 } else {
@@ -449,21 +357,15 @@
449 357 }
450 358
451 359 /**
452 360 * @since 4.02.04
453 - * @since 6.29 This is public.
454 - *
455 - * @param int|string $field_id Field ID.
456 - * @param array $args Additional arguments.
457 - *
458 - * @return mixed
459 361 */
460 - public static function get_posted_meta( $field_id, $args ) {
362 + private static function get_posted_meta( $field_id, $args ) {
461 363 if ( empty( $args['parent_field_id'] ) ) {
462 364 // Sanitizing is done next.
463 - $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
365 + $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
464 366 } else {
465 - $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 ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
367 + $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 ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
466 368 }
467 369 return $value;
468 370 }
469 371
@@ -471,17 +373,14 @@
471 373 * Check if field has an "Other" option and if any other values are posted
472 374 *
473 375 * @since 2.0
474 376 *
475 - * @param object $field Field object.
476 - * @param array|string $value Field value, passed by reference.
477 - * @param array $args Arguments array, passed by reference.
478 - *
479 - * @return void
377 + * @param object $field
378 + * @param string|array $value
379 + * @param array $args
480 380 */
481 381 public static function maybe_set_other_validation( $field, &$value, &$args ) {
482 382 $args['other'] = false;
483 -
484 383 if ( ! $value || ! FrmAppHelper::pro_is_installed() ) {
485 384 return;
486 385 }
487 386
@@ -495,22 +394,21 @@
495 394 // Get other value for fields in repeating section.
496 395 self::set_other_repeating_vals( $field, $value, $args );
497 396
498 397 // Check if there are any posted "Other" values.
499 - if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
500 - return;
501 - }
398 + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
502 399
503 - // Save original value.
504 - $args['temp_value'] = $value;
505 - $args['other'] = true;
400 + // Save original value.
401 + $args['temp_value'] = $value;
402 + $args['other'] = true;
506 403
507 - // Sanitizing is done next.
508 - $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
509 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
404 + // Sanitizing is done next.
405 + $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
406 + FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
510 407
511 - // Set the validation value now
512 - self::set_other_validation_val( $value, $other_vals, $field, $args );
408 + // Set the validation value now
409 + self::set_other_validation_val( $value, $other_vals, $field, $args );
410 + }
513 411 }
514 412
515 413 /**
516 414 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
@@ -516,13 +414,11 @@
516 414 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
517 415 *
518 416 * @since 2.0
519 417 *
520 - * @param object $field Field object.
521 - * @param array|string $value Field value, passed by reference.
522 - * @param array $args Arguments array, passed by reference.
523 - *
524 - * @return void
418 + * @param object $field
419 + * @param string|array $value
420 + * @param array $args
525 421 */
526 422 public static function set_other_repeating_vals( $field, &$value, &$args ) {
527 423 if ( ! $args['parent_field_id'] ) {
528 424 return;
@@ -528,20 +424,19 @@
528 424 return;
529 425 }
530 426
531 427 // Check if there are any other posted "other" values for this field.
532 - if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
533 - return;
534 - }
428 + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
429 + // Save original value
430 + $args['temp_value'] = $value;
431 + $args['other'] = true;
535 432
536 - // Save original value
537 - $args['temp_value'] = $value;
538 - $args['other'] = true;
539 - $other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
540 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
433 + $other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
434 + FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
541 435
542 - // Set the validation value now.
543 - self::set_other_validation_val( $value, $other_vals, $field, $args );
436 + // Set the validation value now.
437 + self::set_other_validation_val( $value, $other_vals, $field, $args );
438 + }
544 439 }
545 440
546 441 /**
547 442 * Modify value used for validation
@@ -551,17 +446,15 @@
551 446 * Needs to accommodate for times when other opt is selected, but no other free text is entered
552 447 *
553 448 * @since 2.0
554 449 *
555 - * @param array|string $value
556 - * @param array|string $other_vals (usually of posted values).
557 - * @param object $field
558 - * @param array $args
559 - *
560 - * @return void
450 + * @param string|array $value
451 + * @param string|array $other_vals (usually of posted values)
452 + * @param object $field
453 + * @param array $args
561 454 */
562 455 public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
563 - // Checkboxes.
456 + // Checkboxes and multi-select dropdowns.
564 457 if ( is_array( $value ) && $field->type === 'checkbox' ) {
565 458 // Combine "Other" values with checked values. "Other" values will override checked box values.
566 459 foreach ( $other_vals as $k => $v ) {
567 460 if ( isset( $value[ $k ] ) && trim( $v ) === '' ) {
@@ -570,44 +463,40 @@
570 463 break;
571 464 }
572 465 }
573 466
574 - if ( is_array( $value ) && $value ) {
467 + if ( is_array( $value ) && ! empty( $value ) ) {
575 468 $value = array_merge( $value, $other_vals );
576 469 }
470 + } else {
471 + // Radio and dropdowns.
472 + $other_key = array_filter( array_keys( $field->options ), 'is_string' );
473 + $other_key = reset( $other_key );
577 474
578 - return;
579 - }
475 + // Multi-select dropdown.
476 + if ( is_array( $value ) ) {
477 + $o_key = array_search( $field->options[ $other_key ], $value );
580 478
581 - // Radio and dropdowns.
582 - $other_key = array_filter( array_keys( $field->options ), 'is_string' );
583 - $other_key = reset( $other_key );
479 + if ( $o_key !== false ) {
480 + // Modify the original value so other key will be preserved.
481 + $value[ $other_key ] = $value[ $o_key ];
584 482
585 - // Multi-select dropdown.
586 - if ( is_array( $value ) ) {
587 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
588 - $o_key = array_search( $field->options[ $other_key ], $value );
483 + // By default, the array keys will be numeric for multi-select dropdowns.
484 + // If going backwards and forwards between pages, the array key will match the other key.
485 + if ( $o_key !== $other_key ) {
486 + unset( $value[ $o_key ] );
487 + }
589 488
590 - if ( $o_key !== false ) {
591 - // Modify the original value so other key will be preserved.
592 - $value[ $other_key ] = $value[ $o_key ];
593 -
594 - // By default, the array keys will be numeric for multi-select dropdowns.
595 - // If going backwards and forwards between pages, the array key will match the other key.
596 - if ( $o_key !== $other_key ) {
597 - unset( $value[ $o_key ] );
489 + $args['temp_value'] = $value;
490 + $value[ $other_key ] = reset( $other_vals );
491 + if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
492 + unset( $value[ $other_key ] );
493 + }
598 494 }
599 -
600 - $args['temp_value'] = $value;
601 - $value[ $other_key ] = reset( $other_vals );
602 -
603 - if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
604 - unset( $value[ $other_key ] );
605 - }
495 + } elseif ( $field->options[ $other_key ] == $value ) {
496 + $value = $other_vals;
606 497 }
607 - } elseif ( $field->options[ $other_key ] == $value ) { // phpcs:ignore Universal.Operators.StrictComparisons
608 - $value = $other_vals;
609 - }//end if
498 + }
610 499 }
611 500
612 501 /**
613 502 * Add submitted values to a string for spam checking.
@@ -612,16 +501,13 @@
612 501 /**
613 502 * Add submitted values to a string for spam checking.
614 503 *
615 504 * @param array $values
616 - *
617 - * @return string
618 505 */
619 506 public static function entry_array_to_string( $values ) {
620 507 $content = '';
621 -
622 508 foreach ( $values['item_meta'] as $val ) {
623 - if ( $content !== '' ) {
509 + if ( $content != '' ) {
624 510 $content .= "\n\n";
625 511 }
626 512
627 513 if ( is_array( $val ) ) {
@@ -645,9 +531,9 @@
645 531 * @return string
646 532 */
647 533 public static function get_browser( $u_agent ) {
648 534 $bname = __( 'Unknown', 'formidable' );
649 - $platform = $bname;
535 + $platform = __( 'Unknown', 'formidable' );
650 536 $ub = '';
651 537
652 538 // Get the operating system
653 539 if ( preg_match( '/windows|win32/i', $u_agent ) ) {
@@ -667,15 +553,15 @@
667 553 'Netscape' => 'Netscape',
668 554 'Firefox' => 'Mozilla Firefox',
669 555 );
670 556
671 - // Next get the name of the useragent yes separately and for good reason.
672 - if ( str_contains( $u_agent, 'MSIE' ) && ! str_contains( $u_agent, 'Opera' ) ) {
557 + // Next get the name of the useragent yes seperately and for good reason
558 + if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) {
673 559 $bname = 'Internet Explorer';
674 560 $ub = 'MSIE';
675 561 } else {
676 562 foreach ( $agent_options as $agent_key => $agent_name ) {
677 - if ( str_contains( $u_agent, $agent_key ) ) {
563 + if ( strpos( $u_agent, $agent_key ) !== false ) {
678 564 $bname = $agent_name;
679 565 $ub = $agent_key;
680 566 break;
681 567 }
@@ -681,21 +567,24 @@
681 567 }
682 568 }
683 569 }
684 570
685 - // Finally get the correct version number
571 + // finally get the correct version number
686 572 $known = array( 'Version', $ub, 'other' );
687 - $pattern = '#(?<browser>' . implode( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
688 - // Get the matching numbers.
689 - preg_match_all( $pattern, $u_agent, $matches );
573 + $pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
574 + preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers
690 575
691 - // See how many we have
576 + // see how many we have
692 577 $i = count( $matches['browser'] );
693 578
694 579 if ( $i > 1 ) {
695 - // We will have two since we are not using 'other' argument yet
696 - // See if version is before or after the name.
697 - $version = strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ? $matches['version'][0] : $matches['version'][1];
580 + //we will have two since we are not using 'other' argument yet
581 + //see if version is before or after the name
582 + if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) {
583 + $version = $matches['version'][0];
584 + } else {
585 + $version = $matches['version'][1];
586 + }
698 587 } elseif ( $i === 1 ) {
699 588 $version = $matches['version'][0];
700 589 } else {
701 590 $version = '';
@@ -700,10 +589,10 @@
700 589 } else {
701 590 $version = '';
702 591 }
703 592
704 - // Check if we have a number
705 - if ( $version === '' ) {
593 + // check if we have a number
594 + if ( $version == '' ) {
706 595 $version = '?';
707 596 }
708 597
709 598 return $bname . ' ' . $version . ' / ' . $platform;
@@ -710,22 +599,17 @@
710 599 }
711 600
712 601 /**
713 602 * @since 3.0
714 - *
715 - * @param array $atts Action dropdown attributes.
716 - *
717 - * @return void
718 603 */
719 604 public static function actions_dropdown( $atts ) {
720 - $id = $atts['id'] ?? FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
605 + $id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
721 606 $links = self::get_action_links( $id, $atts['entry'] );
722 607
723 608 foreach ( $links as $link ) {
724 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
725 609 ?>
726 610 <div class="misc-pub-section">
727 - <a href="<?php echo esc_url( $link['url'] ); ?>"
611 + <a href="<?php echo esc_url( FrmAppHelper::maybe_full_screen_link( $link['url'] ) ); ?>"
728 612 <?php
729 613 if ( isset( $link['data'] ) ) {
730 614 foreach ( $link['data'] as $data => $value ) {
731 615 echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
@@ -730,13 +614,11 @@
730 614 foreach ( $link['data'] as $data => $value ) {
731 615 echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
732 616 }
733 617 }
734 -
735 618 if ( isset( $link['class'] ) ) {
736 619 echo 'class="' . esc_attr( $link['class'] ) . '" ';
737 620 }
738 -
739 621 if ( isset( $link['id'] ) ) {
740 622 echo 'id="' . esc_attr( $link['id'] ) . '" ';
741 623 }
742 624 ?>
@@ -745,45 +627,38 @@
745 627 <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span>
746 628 </a>
747 629 </div>
748 630 <?php
749 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
750 - }//end foreach
631 + }
751 632 }
752 633
753 634 /**
754 635 * @since 3.0
755 - *
756 - * @param int $id Entry ID.
757 - * @param array|object $entry Entry object.
758 - *
759 - * @return array
760 636 */
761 637 private static function get_action_links( $id, $entry ) {
762 638 $page = FrmAppHelper::get_param( 'frm_action' );
763 639 $actions = array();
764 640
765 - if ( $page !== 'show' ) {
641 + if ( $page != 'show' ) {
766 642 $actions['frm_view'] = array(
767 643 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=show&id=' . $id . '&form=' . $entry->form_id ),
768 644 'label' => __( 'View Entry', 'formidable' ),
769 - 'icon' => 'frmfont frm_save_icon',
645 + 'icon' => 'frm_icon_font frm_save_icon',
770 646 );
771 647 }
772 648
773 649 if ( current_user_can( 'frm_delete_entries' ) ) {
774 650 $actions['frm_delete'] = array(
775 - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ) ),
651 + 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ),
776 652 'label' => __( 'Delete Entry', 'formidable' ),
777 - 'icon' => 'frmfont frm_delete_icon',
653 + 'icon' => 'frm_icon_font frm_delete_icon',
778 654 'data' => array(
779 - 'frmverify' => __( 'Permanently delete this entry?', 'formidable' ),
780 - 'frmverify-btn' => 'frm-button-red',
655 + 'frmverify' => __( 'Delete this form entry?', 'formidable' ),
781 656 ),
782 657 );
783 658 }
784 659
785 - if ( $page === 'show' ) {
660 + if ( $page == 'show' ) {
786 661 $actions['frm_print'] = array(
787 662 'url' => '#',
788 663 'label' => __( 'Print Entry', 'formidable' ),
789 664 'data' => array(
@@ -788,9 +663,9 @@
788 663 'label' => __( 'Print Entry', 'formidable' ),
789 664 'data' => array(
790 665 'frmprint' => '1',
791 666 ),
792 - 'icon' => 'frmfont frm_printer_icon',
667 + 'icon' => 'frm_icon_font frm_printer_icon',
793 668 );
794 669 }
795 670
796 671 $actions['frm_resend'] = array(
@@ -801,21 +676,11 @@
801 676 'upgrade' => __( 'Resend Emails', 'formidable' ),
802 677 'medium' => 'resend-email',
803 678 'content' => 'entry',
804 679 ),
805 - 'icon' => 'frmfont frm_email_icon',
680 + 'icon' => 'frm_icon_font frm_email_icon',
806 681 );
807 682
808 - if ( ! function_exists( 'frm_pdfs_autoloader' ) ) {
809 - $actions['frm_download_pdf'] = array(
810 - 'url' => '#',
811 - 'label' => __( 'Download as PDF', 'formidable' ),
812 - 'class' => 'frm_noallow',
813 - 'data' => self::get_pdfs_upgrade_link_data( 'download-pdf-entry' ),
814 - 'icon' => 'frmfont frm_download_icon',
815 - );
816 - }
817 -
818 683 $actions['frm_edit'] = array(
819 684 'url' => '#',
820 685 'label' => __( 'Edit Entry', 'formidable' ),
821 686 'class' => 'frm_noallow',
@@ -823,9 +688,9 @@
823 688 'upgrade' => __( 'Entry edits', 'formidable' ),
824 689 'medium' => 'edit-entries',
825 690 'content' => 'entry',
826 691 ),
827 - 'icon' => 'frmfont frm_pencil_icon',
692 + 'icon' => 'frm_icon_font frm_pencil_icon',
828 693 );
829 694
830 695 return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
831 696 }
@@ -830,38 +695,11 @@
830 695 return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
831 696 }
832 697
833 698 /**
834 - * Gets data attributes for PDFs addon upgrade link.
835 - *
836 - * @param string $medium The source of the upgrade link used for analytics data.
837 - *
838 - * @return array
839 - */
840 - private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) {
841 - $data = array(
842 - 'oneclick' => '',
843 - 'requires' => '',
844 - 'upgrade' => __( 'Forms to PDF', 'formidable' ),
845 - 'medium' => $medium,
846 - );
847 -
848 - $upgrading = FrmAddonsController::install_link( 'pdfs' );
849 -
850 - if ( isset( $upgrading['url'] ) ) {
851 - $data['oneclick'] = json_encode( $upgrading );
852 - } else {
853 - $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
854 - }
855 -
856 - return $data;
857 - }
858 -
859 - /**
860 699 * @since 5.0.15
861 700 *
862 - * @param int|string $entry_id
863 - *
701 + * @param string|int $entry_id
864 702 * @return void
865 703 */
866 704 public static function maybe_render_captcha_score( $entry_id ) {
867 705 $query = array(
@@ -868,117 +706,16 @@
868 706 'item_id' => (int) $entry_id,
869 707 'field_id' => 0,
870 708 );
871 709 $metas_without_a_field = (array) FrmEntryMeta::getAll( $query, ' ORDER BY it.created_at DESC', '', true );
872 -
873 710 foreach ( $metas_without_a_field as $meta ) {
874 - if ( empty( $meta->meta_value['captcha_score'] ) ) {
875 - continue;
711 + if ( ! empty( $meta->meta_value['captcha_score'] ) ) {
712 + echo '<div class="misc-pub-section">';
713 + FrmAppHelper::icon_by_class( 'frm_icon_font frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
714 + echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
715 + echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
716 + echo '</div>';
717 + return;
876 718 }
877 -
878 - echo '<div class="misc-pub-section">';
879 - FrmAppHelper::icon_by_class( 'frmfont frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
880 - echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
881 - echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
882 - echo '</div>';
883 - return;
884 719 }
885 - }
886 -
887 - /**
888 - * Return entry status based on is_draft column value.
889 - *
890 - * @since 6.5
891 - *
892 - * @param int $status is_draft column.
893 - *
894 - * @return int
895 - */
896 - public static function get_entry_status( $status ) {
897 - if ( array_key_exists( $status, self::get_entry_statuses() ) ) {
898 - return $status;
899 - }
900 -
901 - if ( ! $status ) {
902 - // If the status is empty, let's default to 0.
903 - return self::SUBMITTED_ENTRY_STATUS;
904 - }
905 -
906 - // If it has a value that isn't in the array, let's default to 1. There may be old entries that don't have a value for is_draft.
907 - return self::DRAFT_ENTRY_STATUS;
908 - }
909 -
910 - /**
911 - * Return entry status label based on passed value.
912 - *
913 - * @since 6.5
914 - *
915 - * @param int $status is_draft column.
916 - *
917 - * @return string
918 - */
919 - public static function get_entry_status_label( $status ) {
920 - return self::get_entry_statuses()[ self::get_entry_status( $status ) ];
921 - }
922 -
923 - /**
924 - * Get all entry statuses.
925 - *
926 - * @since 6.5
927 - * @since 6.6 function went from private to public.
928 - *
929 - * @return array<string>
930 - */
931 - public static function get_entry_statuses() {
932 - $default_entry_statuses = array(
933 - self::SUBMITTED_ENTRY_STATUS => __( 'Submitted', 'formidable' ),
934 - self::DRAFT_ENTRY_STATUS => __( 'Draft', 'formidable' ),
935 - );
936 -
937 - /**
938 - * Register entry status.
939 - *
940 - * "2" is used in abandonment-addon and reserved for "In progress".
941 - * "3" is used in abandonment-addon and reserved for "Abandoned".
942 - *
943 - * @since 6.5
944 - *
945 - * @param array<string> $extended_entry_status Entry statuses.
946 - */
947 - $extended_entry_status = apply_filters( 'frm_entry_statuses', array() );
948 -
949 - if ( ! is_array( $extended_entry_status ) ) {
950 - _doing_it_wrong( __METHOD__, esc_html__( 'Entry status must be return in array format.', 'formidable' ), '6.5' );
951 - $extended_entry_status = array();
952 - }
953 -
954 - return array_replace( $default_entry_statuses, $extended_entry_status );
955 - }
956 -
957 - /**
958 - * @since 6.17
959 - *
960 - * @return int
961 - */
962 - public static function get_visible_unread_inbox_count() {
963 - if ( ! in_array( FrmAppHelper::get_menu_name(), array( 'Formidable', 'Forms' ), true ) ) {
964 - return 0;
965 - }
966 -
967 - $inbox = new FrmInbox();
968 - $inbox_count = count( $inbox->unread() );
969 -
970 - if ( ! $inbox_count ) {
971 - return 0;
972 - }
973 -
974 - if ( is_callable( 'FrmProSettingsController::inbox_badge' ) ) {
975 - $inbox_count = FrmProSettingsController::inbox_badge( $inbox_count );
976 -
977 - if ( ! $inbox_count ) {
978 - return 0;
979 - }
980 - }
981 -
982 - return $inbox_count;
983 720 }
984 721 }