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