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 +159 -443 6.28 → 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 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,20 +360,17 @@
449 360 }
450 361
451 362 /**
452 363 * @since 4.02.04
453 - *
454 - * @param int|string $field_id Field ID.
455 - * @param array $args Additional arguments.
456 - *
457 - * @return mixed
458 364 */
459 365 private static function get_posted_meta( $field_id, $args ) {
460 366 if ( empty( $args['parent_field_id'] ) ) {
461 367 // Sanitizing is done next.
462 - $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
368 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
369 + $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : '';
463 370 } else {
464 - $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
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 ] ) : '';
465 373 }
466 374 return $value;
467 375 }
468 376
@@ -470,17 +378,14 @@
470 378 * Check if field has an "Other" option and if any other values are posted
471 379 *
472 380 * @since 2.0
473 381 *
474 - * @param object $field Field object.
475 - * @param array|string $value Field value, passed by reference.
476 - * @param array $args Arguments array, passed by reference.
477 - *
478 - * @return void
382 + * @param object $field
383 + * @param string|array $value
384 + * @param array $args
479 385 */
480 386 public static function maybe_set_other_validation( $field, &$value, &$args ) {
481 387 $args['other'] = false;
482 -
483 388 if ( ! $value || ! FrmAppHelper::pro_is_installed() ) {
484 389 return;
485 390 }
486 391
@@ -494,22 +399,22 @@
494 399 // Get other value for fields in repeating section.
495 400 self::set_other_repeating_vals( $field, $value, $args );
496 401
497 402 // Check if there are any posted "Other" values.
498 - if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
499 - return;
500 - }
403 + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) {
501 404
502 - // Save original value.
503 - $args['temp_value'] = $value;
504 - $args['other'] = true;
405 + // Save original value.
406 + $args['temp_value'] = $value;
407 + $args['other'] = true;
505 408
506 - // Sanitizing is done next.
507 - $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
508 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
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 );
509 413
510 - // Set the validation value now
511 - 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 + }
512 417 }
513 418
514 419 /**
515 420 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
@@ -515,13 +420,11 @@
515 420 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
516 421 *
517 422 * @since 2.0
518 423 *
519 - * @param object $field Field object.
520 - * @param array|string $value Field value, passed by reference.
521 - * @param array $args Arguments array, passed by reference.
522 - *
523 - * @return void
424 + * @param object $field
425 + * @param string|array $value
426 + * @param array $args
524 427 */
525 428 public static function set_other_repeating_vals( $field, &$value, &$args ) {
526 429 if ( ! $args['parent_field_id'] ) {
527 430 return;
@@ -527,20 +430,20 @@
527 430 return;
528 431 }
529 432
530 433 // Check if there are any other posted "other" values for this field.
531 - if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
532 - return;
533 - }
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;
534 438
535 - // Save original value
536 - $args['temp_value'] = $value;
537 - $args['other'] = true;
538 - $other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
539 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
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 );
540 442
541 - // Set the validation value now.
542 - 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 + }
543 446 }
544 447
545 448 /**
546 449 * Modify value used for validation
@@ -550,17 +453,15 @@
550 453 * Needs to accommodate for times when other opt is selected, but no other free text is entered
551 454 *
552 455 * @since 2.0
553 456 *
554 - * @param array|string $value
555 - * @param array|string $other_vals (usually of posted values).
556 - * @param object $field
557 - * @param array $args
558 - *
559 - * @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
560 461 */
561 462 public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
562 - // Checkboxes.
463 + // Checkboxes and multi-select dropdowns.
563 464 if ( is_array( $value ) && $field->type === 'checkbox' ) {
564 465 // Combine "Other" values with checked values. "Other" values will override checked box values.
565 466 foreach ( $other_vals as $k => $v ) {
566 467 if ( isset( $value[ $k ] ) && trim( $v ) === '' ) {
@@ -569,44 +470,40 @@
569 470 break;
570 471 }
571 472 }
572 473
573 - if ( is_array( $value ) && $value ) {
474 + if ( is_array( $value ) && ! empty( $value ) ) {
574 475 $value = array_merge( $value, $other_vals );
575 476 }
477 + } else {
478 + // Radio and dropdowns.
479 + $other_key = array_filter( array_keys( $field->options ), 'is_string' );
480 + $other_key = reset( $other_key );
576 481
577 - return;
578 - }
482 + // Multi-select dropdown.
483 + if ( is_array( $value ) ) {
484 + $o_key = array_search( $field->options[ $other_key ], $value );
579 485
580 - // Radio and dropdowns.
581 - $other_key = array_filter( array_keys( $field->options ), 'is_string' );
582 - $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 ];
583 489
584 - // Multi-select dropdown.
585 - if ( is_array( $value ) ) {
586 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
587 - $o_key = array_search( $field->options[ $other_key ], $value );
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 + }
588 495
589 - if ( $o_key !== false ) {
590 - // Modify the original value so other key will be preserved.
591 - $value[ $other_key ] = $value[ $o_key ];
592 -
593 - // By default, the array keys will be numeric for multi-select dropdowns.
594 - // If going backwards and forwards between pages, the array key will match the other key.
595 - if ( $o_key !== $other_key ) {
596 - unset( $value[ $o_key ] );
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 + }
597 501 }
598 -
599 - $args['temp_value'] = $value;
600 - $value[ $other_key ] = reset( $other_vals );
601 -
602 - if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
603 - unset( $value[ $other_key ] );
604 - }
502 + } elseif ( $field->options[ $other_key ] == $value ) {
503 + $value = $other_vals;
605 504 }
606 - } elseif ( $field->options[ $other_key ] == $value ) { // phpcs:ignore Universal.Operators.StrictComparisons
607 - $value = $other_vals;
608 - }//end if
505 + }
609 506 }
610 507
611 508 /**
612 509 * Add submitted values to a string for spam checking.
@@ -611,16 +508,13 @@
611 508 /**
612 509 * Add submitted values to a string for spam checking.
613 510 *
614 511 * @param array $values
615 - *
616 - * @return string
617 512 */
618 513 public static function entry_array_to_string( $values ) {
619 514 $content = '';
620 -
621 515 foreach ( $values['item_meta'] as $val ) {
622 - if ( $content !== '' ) {
516 + if ( $content != '' ) {
623 517 $content .= "\n\n";
624 518 }
625 519
626 520 if ( is_array( $val ) ) {
@@ -644,9 +538,9 @@
644 538 * @return string
645 539 */
646 540 public static function get_browser( $u_agent ) {
647 541 $bname = __( 'Unknown', 'formidable' );
648 - $platform = $bname;
542 + $platform = __( 'Unknown', 'formidable' );
649 543 $ub = '';
650 544
651 545 // Get the operating system
652 546 if ( preg_match( '/windows|win32/i', $u_agent ) ) {
@@ -666,15 +560,15 @@
666 560 'Netscape' => 'Netscape',
667 561 'Firefox' => 'Mozilla Firefox',
668 562 );
669 563
670 - // Next get the name of the useragent yes separately and for good reason.
671 - if ( str_contains( $u_agent, 'MSIE' ) && ! str_contains( $u_agent, 'Opera' ) ) {
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 ) {
672 566 $bname = 'Internet Explorer';
673 567 $ub = 'MSIE';
674 568 } else {
675 569 foreach ( $agent_options as $agent_key => $agent_name ) {
676 - if ( str_contains( $u_agent, $agent_key ) ) {
570 + if ( strpos( $u_agent, $agent_key ) !== false ) {
677 571 $bname = $agent_name;
678 572 $ub = $agent_key;
679 573 break;
680 574 }
@@ -680,21 +574,24 @@
680 574 }
681 575 }
682 576 }
683 577
684 - // Finally get the correct version number
578 + // finally get the correct version number
685 579 $known = array( 'Version', $ub, 'other' );
686 - $pattern = '#(?<browser>' . implode( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
687 - // Get the matching numbers.
688 - 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
689 582
690 - // See how many we have
583 + // see how many we have
691 584 $i = count( $matches['browser'] );
692 585
693 586 if ( $i > 1 ) {
694 - // We will have two since we are not using 'other' argument yet
695 - // See if version is before or after the name.
696 - $version = strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ? $matches['version'][0] : $matches['version'][1];
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 + }
697 594 } elseif ( $i === 1 ) {
698 595 $version = $matches['version'][0];
699 596 } else {
700 597 $version = '';
@@ -699,10 +596,10 @@
699 596 } else {
700 597 $version = '';
701 598 }
702 599
703 - // Check if we have a number
704 - if ( $version === '' ) {
600 + // check if we have a number
601 + if ( $version == '' ) {
705 602 $version = '?';
706 603 }
707 604
708 605 return $bname . ' ' . $version . ' / ' . $platform;
@@ -709,22 +606,17 @@
709 606 }
710 607
711 608 /**
712 609 * @since 3.0
713 - *
714 - * @param array $atts Action dropdown attributes.
715 - *
716 - * @return void
717 610 */
718 611 public static function actions_dropdown( $atts ) {
719 - $id = $atts['id'] ?? FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
612 + $id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
720 613 $links = self::get_action_links( $id, $atts['entry'] );
721 614
722 615 foreach ( $links as $link ) {
723 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
724 616 ?>
725 617 <div class="misc-pub-section">
726 - <a href="<?php echo esc_url( $link['url'] ); ?>"
618 + <a href="<?php echo esc_url( FrmAppHelper::maybe_full_screen_link( $link['url'] ) ); ?>"
727 619 <?php
728 620 if ( isset( $link['data'] ) ) {
729 621 foreach ( $link['data'] as $data => $value ) {
730 622 echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
@@ -729,13 +621,11 @@
729 621 foreach ( $link['data'] as $data => $value ) {
730 622 echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
731 623 }
732 624 }
733 -
734 625 if ( isset( $link['class'] ) ) {
735 626 echo 'class="' . esc_attr( $link['class'] ) . '" ';
736 627 }
737 -
738 628 if ( isset( $link['id'] ) ) {
739 629 echo 'id="' . esc_attr( $link['id'] ) . '" ';
740 630 }
741 631 ?>
@@ -744,45 +634,38 @@
744 634 <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span>
745 635 </a>
746 636 </div>
747 637 <?php
748 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
749 - }//end foreach
638 + }
750 639 }
751 640
752 641 /**
753 642 * @since 3.0
754 - *
755 - * @param int $id Entry ID.
756 - * @param array|object $entry Entry object.
757 - *
758 - * @return array
759 643 */
760 644 private static function get_action_links( $id, $entry ) {
761 645 $page = FrmAppHelper::get_param( 'frm_action' );
762 646 $actions = array();
763 647
764 - if ( $page !== 'show' ) {
648 + if ( $page != 'show' ) {
765 649 $actions['frm_view'] = array(
766 650 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=show&id=' . $id . '&form=' . $entry->form_id ),
767 651 'label' => __( 'View Entry', 'formidable' ),
768 - 'icon' => 'frmfont frm_save_icon',
652 + 'icon' => 'frm_icon_font frm_save_icon',
769 653 );
770 654 }
771 655
772 656 if ( current_user_can( 'frm_delete_entries' ) ) {
773 657 $actions['frm_delete'] = array(
774 - '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 ),
775 659 'label' => __( 'Delete Entry', 'formidable' ),
776 - 'icon' => 'frmfont frm_delete_icon',
660 + 'icon' => 'frm_icon_font frm_delete_icon',
777 661 'data' => array(
778 - 'frmverify' => __( 'Permanently delete this entry?', 'formidable' ),
779 - 'frmverify-btn' => 'frm-button-red',
662 + 'frmverify' => __( 'Delete this form entry?', 'formidable' ),
780 663 ),
781 664 );
782 665 }
783 666
784 - if ( $page === 'show' ) {
667 + if ( $page == 'show' ) {
785 668 $actions['frm_print'] = array(
786 669 'url' => '#',
787 670 'label' => __( 'Print Entry', 'formidable' ),
788 671 'data' => array(
@@ -787,9 +670,9 @@
787 670 'label' => __( 'Print Entry', 'formidable' ),
788 671 'data' => array(
789 672 'frmprint' => '1',
790 673 ),
791 - 'icon' => 'frmfont frm_printer_icon',
674 + 'icon' => 'frm_icon_font frm_printer_icon',
792 675 );
793 676 }
794 677
795 678 $actions['frm_resend'] = array(
@@ -800,21 +683,11 @@
800 683 'upgrade' => __( 'Resend Emails', 'formidable' ),
801 684 'medium' => 'resend-email',
802 685 'content' => 'entry',
803 686 ),
804 - 'icon' => 'frmfont frm_email_icon',
687 + 'icon' => 'frm_icon_font frm_email_icon',
805 688 );
806 689
807 - if ( ! function_exists( 'frm_pdfs_autoloader' ) ) {
808 - $actions['frm_download_pdf'] = array(
809 - 'url' => '#',
810 - 'label' => __( 'Download as PDF', 'formidable' ),
811 - 'class' => 'frm_noallow',
812 - 'data' => self::get_pdfs_upgrade_link_data( 'download-pdf-entry' ),
813 - 'icon' => 'frmfont frm_download_icon',
814 - );
815 - }
816 -
817 690 $actions['frm_edit'] = array(
818 691 'url' => '#',
819 692 'label' => __( 'Edit Entry', 'formidable' ),
820 693 'class' => 'frm_noallow',
@@ -822,167 +695,10 @@
822 695 'upgrade' => __( 'Entry edits', 'formidable' ),
823 696 'medium' => 'edit-entries',
824 697 'content' => 'entry',
825 698 ),
826 - 'icon' => 'frmfont frm_pencil_icon',
699 + 'icon' => 'frm_icon_font frm_pencil_icon',
827 700 );
828 701
829 702 return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
830 - }
831 -
832 - /**
833 - * Gets data attributes for PDFs addon upgrade link.
834 - *
835 - * @param string $medium The source of the upgrade link used for analytics data.
836 - *
837 - * @return array
838 - */
839 - private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) {
840 - $data = array(
841 - 'oneclick' => '',
842 - 'requires' => '',
843 - 'upgrade' => __( 'Forms to PDF', 'formidable' ),
844 - 'medium' => $medium,
845 - );
846 -
847 - $upgrading = FrmAddonsController::install_link( 'pdfs' );
848 -
849 - if ( isset( $upgrading['url'] ) ) {
850 - $data['oneclick'] = json_encode( $upgrading );
851 - } else {
852 - $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
853 - }
854 -
855 - return $data;
856 - }
857 -
858 - /**
859 - * @since 5.0.15
860 - *
861 - * @param int|string $entry_id
862 - *
863 - * @return void
864 - */
865 - public static function maybe_render_captcha_score( $entry_id ) {
866 - $query = array(
867 - 'item_id' => (int) $entry_id,
868 - 'field_id' => 0,
869 - );
870 - $metas_without_a_field = (array) FrmEntryMeta::getAll( $query, ' ORDER BY it.created_at DESC', '', true );
871 -
872 - foreach ( $metas_without_a_field as $meta ) {
873 - if ( empty( $meta->meta_value['captcha_score'] ) ) {
874 - continue;
875 - }
876 -
877 - echo '<div class="misc-pub-section">';
878 - FrmAppHelper::icon_by_class( 'frmfont frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
879 - echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
880 - echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
881 - echo '</div>';
882 - return;
883 - }
884 - }
885 -
886 - /**
887 - * Return entry status based on is_draft column value.
888 - *
889 - * @since 6.5
890 - *
891 - * @param int $status is_draft column.
892 - *
893 - * @return int
894 - */
895 - public static function get_entry_status( $status ) {
896 - $statuses = self::get_entry_statuses();
897 -
898 - if ( array_key_exists( $status, $statuses ) ) {
899 - return $status;
900 - }
901 -
902 - if ( ! $status ) {
903 - // If the status is empty, let's default to 0.
904 - return self::SUBMITTED_ENTRY_STATUS;
905 - }
906 -
907 - // 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.
908 - return self::DRAFT_ENTRY_STATUS;
909 - }
910 -
911 - /**
912 - * Return entry status label based on passed value.
913 - *
914 - * @since 6.5
915 - *
916 - * @param int $status is_draft column.
917 - *
918 - * @return string
919 - */
920 - public static function get_entry_status_label( $status ) {
921 - $statuses = self::get_entry_statuses();
922 - return $statuses[ self::get_entry_status( $status ) ];
923 - }
924 -
925 - /**
926 - * Get all entry statuses.
927 - *
928 - * @since 6.5
929 - * @since 6.6 function went from private to public.
930 - *
931 - * @return array<string>
932 - */
933 - public static function get_entry_statuses() {
934 - $default_entry_statuses = array(
935 - self::SUBMITTED_ENTRY_STATUS => __( 'Submitted', 'formidable' ),
936 - self::DRAFT_ENTRY_STATUS => __( 'Draft', 'formidable' ),
937 - );
938 -
939 - /**
940 - * Register entry status.
941 - *
942 - * "2" is used in abandonment-addon and reserved for "In progress".
943 - * "3" is used in abandonment-addon and reserved for "Abandoned".
944 - *
945 - * @since 6.5
946 - *
947 - * @param array<string> $extended_entry_status Entry statuses.
948 - */
949 - $extended_entry_status = apply_filters( 'frm_entry_statuses', array() );
950 -
951 - if ( ! is_array( $extended_entry_status ) ) {
952 - _doing_it_wrong( __METHOD__, esc_html__( 'Entry status must be return in array format.', 'formidable' ), '6.5' );
953 - $extended_entry_status = array();
954 - }
955 -
956 - return array_replace( $default_entry_statuses, $extended_entry_status );
957 - }
958 -
959 - /**
960 - * @since 6.17
961 - *
962 - * @return int
963 - */
964 - public static function get_visible_unread_inbox_count() {
965 - $menu_name = FrmAppHelper::get_menu_name();
966 -
967 - if ( ! in_array( $menu_name, array( 'Formidable', 'Forms' ), true ) ) {
968 - return 0;
969 - }
970 -
971 - $inbox = new FrmInbox();
972 - $inbox_count = count( $inbox->unread() );
973 -
974 - if ( ! $inbox_count ) {
975 - return 0;
976 - }
977 -
978 - if ( is_callable( 'FrmProSettingsController::inbox_badge' ) ) {
979 - $inbox_count = FrmProSettingsController::inbox_badge( $inbox_count );
980 -
981 - if ( ! $inbox_count ) {
982 - return 0;
983 - }
984 - }
985 -
986 - return $inbox_count;
987 703 }
988 704 }