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