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