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