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