PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.1
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
formidable / classes / helpers / FrmEntriesHelper.php

FrmEntriesHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.1, at classes/helpers/FrmEntriesHelper.php

722 lines 23.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmEntriesHelper {
7
8 public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) {
9 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
10
11 $values = array(
12 'name' => '',
13 'description' => '',
14 'item_key' => '',
15 );
16
17 $values['fields'] = array();
18 if ( empty( $fields ) ) {
19 return apply_filters( 'frm_setup_new_entry', $values );
20 }
21
22 foreach ( (array) $fields as $field ) {
23 $original_default = $field->default_value;
24 self::prepare_field_default_value( $field );
25 $new_value = self::get_field_value_for_new_entry( $field, $reset, $args );
26
27 $field_array = FrmAppHelper::start_field_array( $field );
28 $field_array['value'] = $new_value;
29 $field_array['type'] = apply_filters( 'frm_field_type', $field->type, $field, $new_value );
30 $field_array['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
31 $field_array['reset_value'] = $reset;
32 $field_array['in_embed_form'] = isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0';
33 $field_array['original_default'] = $original_default;
34
35 FrmFieldsHelper::prepare_new_front_field( $field_array, $field, $args );
36
37 $field_array = array_merge( $field->field_options, $field_array );
38
39 $values['fields'][] = $field_array;
40
41 if ( ! $form || ! isset( $form->id ) ) {
42 $form = FrmForm::getOne( $field->form_id );
43 }
44 }
45
46 FrmAppHelper::unserialize_or_decode( $form->options );
47 if ( is_array( $form->options ) ) {
48 $values = array_merge( $values, $form->options );
49 }
50
51 $form_defaults = FrmFormsHelper::get_default_opts();
52 $form_defaults['custom_style'] = FrmAppHelper::custom_style_value( array() );
53
54 $values = array_merge( $form_defaults, $values );
55
56 return apply_filters( 'frm_setup_new_entry', $values );
57 }
58
59 /**
60 * @since 2.05
61 *
62 * @param object $field
63 */
64 private static function prepare_field_default_value( &$field ) {
65 //If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array
66 $return_array = FrmField::is_field_with_multiple_values( $field );
67
68 /**
69 * Do any shortcodes in default value and allow customization of default value.
70 * Calls FrmProFieldsHelper::get_default_value
71 */
72 $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true, $return_array );
73
74 if ( isset( $field->field_options['placeholder'] ) ) {
75 $field->field_options['placeholder'] = apply_filters( 'frm_get_default_value', $field->field_options['placeholder'], $field, false, false );
76 }
77 }
78
79 /**
80 * Set the value for each field
81 * This function is used when the form is first loaded and on all page turns *for a new entry*
82 *
83 * @since 2.0.13
84 *
85 * @param object $field - this is passed by reference since it is an object
86 * @param boolean $reset
87 * @param array $args
88 *
89 * @return string|array $new_value
90 */
91 private static function get_field_value_for_new_entry( $field, $reset, $args ) {
92 $new_value = $field->default_value;
93
94 if ( ! $reset && self::value_is_posted( $field, $args ) ) {
95 self::get_posted_value( $field, $new_value, $args );
96 }
97
98 if ( ! is_array( $new_value ) ) {
99 $new_value = str_replace( '"', '&quot;', $new_value );
100 }
101
102 return $new_value;
103 }
104
105 /**
106 * Check if a field has a posted value
107 *
108 * @since 2.01.0
109 *
110 * @param object $field
111 * @param array $args
112 *
113 * @return boolean $value_is_posted
114 */
115 public static function value_is_posted( $field, $args ) {
116 $value_is_posted = false;
117 if ( $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
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 ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
121 $value_is_posted = true;
122 }
123 } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
124 $value_is_posted = true;
125 }
126 }
127
128 return $value_is_posted;
129 }
130
131 public static function setup_edit_vars( $values, $record ) {
132 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
133
134 $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' );
135 $values['form_id'] = $record->form_id;
136 $values['is_draft'] = $record->is_draft;
137
138 return apply_filters( 'frm_setup_edit_entry_vars', $values, $record );
139 }
140
141 public static function replace_default_message( $message, $atts ) {
142 if ( strpos( $message, '[default-message' ) === false &&
143 strpos( $message, '[default_message' ) === false &&
144 ! empty( $message ) ) {
145 return $message;
146 }
147
148 if ( empty( $message ) ) {
149 $message = '[default-message]';
150 }
151
152 preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
153
154 foreach ( $shortcodes[0] as $short_key => $tag ) {
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 }
161
162 $default = FrmEntriesController::show_entry_shortcode( $this_atts );
163
164 // Add the default message.
165 $message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
166 }
167
168 return $message;
169 }
170
171 public static function prepare_display_value( $entry, $field, $atts ) {
172 $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
173
174 if ( FrmAppHelper::pro_is_installed() ) {
175 $empty = empty( $field_value );
176 FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value );
177 if ( $empty && ! empty( $field_value ) ) {
178 // We've got an entry id, so switch it to a value.
179 $atts['force_id'] = true;
180 }
181 }
182
183 if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) {
184 return self::display_value( $field_value, $field, $atts );
185 }
186
187 // This is an embeded form.
188 $val = '';
189
190 if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) {
191 // This is a repeating section.
192 $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) );
193 } else {
194 // Get all values for this field.
195 $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
196
197 if ( $child_values ) {
198 $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
199 }
200 }
201
202 $field_value = array();
203
204 if ( ! isset( $child_entries ) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) {
205 return $val;
206 }
207
208 foreach ( $child_entries as $child_entry ) {
209 $atts['item_id'] = $child_entry->id;
210 $atts['post_id'] = $child_entry->post_id;
211
212 // Fet the value for this field -- check for post values as well.
213 $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field );
214
215 if ( $entry_val || '0' === $entry_val ) {
216 // foreach entry get display_value.
217 $field_value[] = self::display_value( $entry_val, $field, $atts );
218 }
219
220 unset( $child_entry );
221 }
222
223 $sep = ', ';
224 if ( strpos( implode( ' ', (array) $field_value ), '<img' ) !== false ) {
225 $sep = '<br/>';
226 }
227 $val = implode( $sep, (array) $field_value );
228
229 return FrmAppHelper::kses( $val, 'all' );
230 }
231
232 /**
233 * Prepare the saved value for display
234 *
235 * @param array|string $value
236 * @param object $field
237 * @param array $atts
238 *
239 * @return string
240 */
241 public static function display_value( $value, $field, $atts = array() ) {
242
243 $defaults = array(
244 'type' => '',
245 'html' => false,
246 'show_filename' => true,
247 'truncate' => false,
248 'sep' => ', ',
249 'post_id' => 0,
250 'form_id' => $field->form_id,
251 'field' => $field,
252 'keepjs' => 0,
253 'return_array' => false,
254 );
255
256 $atts = wp_parse_args( $atts, $defaults );
257
258 if ( FrmField::is_image( $field ) || $field->type == 'star' ) {
259 $atts['truncate'] = false;
260 $atts['html'] = true;
261 }
262
263 $atts = apply_filters( 'frm_display_value_atts', $atts, $field, $value );
264
265 if ( ! isset( $field->field_options['post_field'] ) ) {
266 $field->field_options['post_field'] = '';
267 }
268
269 if ( ! isset( $field->field_options['custom_field'] ) ) {
270 $field->field_options['custom_field'] = '';
271 }
272
273 if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
274 $atts['pre_truncate'] = $atts['truncate'];
275 $atts['truncate'] = true;
276 $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0;
277
278 $value = FrmProEntryMetaHelper::get_post_value( $atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts );
279 $atts['truncate'] = $atts['pre_truncate'];
280 }
281
282 if ( $value == '' ) {
283 return $value;
284 }
285
286 $unfiltered_value = $value;
287 FrmAppHelper::unserialize_or_decode( $unfiltered_value );
288
289 $value = apply_filters( 'frm_display_value_custom', $unfiltered_value, $field, $atts );
290 $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) );
291
292 if ( $value == $unfiltered_value ) {
293 $value = FrmFieldsHelper::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
294 }
295
296 if ( $atts['truncate'] && $atts['type'] != 'url' ) {
297 $value = FrmAppHelper::truncate( $value, 50 );
298 }
299
300 if ( ! $atts['keepjs'] && ! is_array( $value ) ) {
301 $value = FrmAppHelper::kses( $value, 'all' );
302 }
303
304 return apply_filters( 'frm_display_value', $value, $field, $atts );
305 }
306
307 public static function set_posted_value( $field, $value, $args ) {
308 // If validating a field with "other" opt, set back to prev value now.
309 if ( isset( $args['other'] ) && $args['other'] ) {
310 $value = $args['temp_value'];
311 }
312 if ( empty( $args['parent_field_id'] ) ) {
313 $_POST['item_meta'][ $field->id ] = $value;
314 } else {
315 self::set_parent_field_posted_value( $field, $value, $args );
316 }
317 }
318
319 /**
320 * Init arrays if necessary, else we get fatal error.
321 *
322 * @since 4.01
323 */
324 private static function set_parent_field_posted_value( $field, $value, $args ) {
325 if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) && is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
326 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
327 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
328 }
329 } else {
330 // All of the section was probably removed.
331 $_POST['item_meta'][ $args['parent_field_id'] ] = array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
332 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
333 }
334
335 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; // phpcs:ignore WordPress.Security.NonceVerification.Missing
336 }
337
338 public static function get_posted_value( $field, &$value, $args ) {
339 if ( is_array( $field ) ) {
340 $field_id = $field['id'];
341 $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
342 } elseif ( is_object( $field ) ) {
343 $field_id = $field->id;
344 $field_obj = FrmFieldFactory::get_field_object( $field );
345 } elseif ( is_numeric( $field ) ) {
346 $field_id = $field;
347 $field_obj = FrmFieldFactory::get_field_object( $field );
348 } else {
349 $value = self::get_posted_meta( $field, $args );
350 FrmAppHelper::sanitize_value( 'sanitize_text_field', $value );
351 return;
352 }
353
354 $value = self::get_posted_meta( $field_id, $args );
355
356 $field_obj->sanitize_value( $value );
357 }
358
359 /**
360 * @since 4.02.04
361 */
362 private static function get_posted_meta( $field_id, $args ) {
363 if ( empty( $args['parent_field_id'] ) ) {
364 // Sanitizing is done next.
365 $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
366 } else {
367 $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
368 }
369 return $value;
370 }
371
372 /**
373 * Check if field has an "Other" option and if any other values are posted
374 *
375 * @since 2.0
376 *
377 * @param object $field
378 * @param string|array $value
379 * @param array $args
380 */
381 public static function maybe_set_other_validation( $field, &$value, &$args ) {
382 $args['other'] = false;
383 if ( ! $value || ! FrmAppHelper::pro_is_installed() ) {
384 return;
385 }
386
387 // Trim excess values if selection limit is exceeded for checkbox. Necessary to do here
388 // as the value set here will be used later in this class's set_posted_value() method.
389 if ( FrmField::is_checkbox( $field ) ) {
390 $field_obj = FrmFieldFactory::get_field_object( $field );
391 $field_obj->maybe_trim_excess_values( $value );
392 }
393
394 // Get other value for fields in repeating section.
395 self::set_other_repeating_vals( $field, $value, $args );
396
397 // Check if there are any posted "Other" values.
398 if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
399
400 // Save original value.
401 $args['temp_value'] = $value;
402 $args['other'] = true;
403
404 // Sanitizing is done next.
405 $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
406 FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
407
408 // Set the validation value now
409 self::set_other_validation_val( $value, $other_vals, $field, $args );
410 }
411 }
412
413 /**
414 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
415 *
416 * @since 2.0
417 *
418 * @param object $field
419 * @param string|array $value
420 * @param array $args
421 */
422 public static function set_other_repeating_vals( $field, &$value, &$args ) {
423 if ( ! $args['parent_field_id'] ) {
424 return;
425 }
426
427 // Check if there are any other posted "other" values for this field.
428 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
429 // Save original value
430 $args['temp_value'] = $value;
431 $args['other'] = true;
432
433 $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
434 FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
435
436 // Set the validation value now.
437 self::set_other_validation_val( $value, $other_vals, $field, $args );
438 }
439 }
440
441 /**
442 * Modify value used for validation
443 * This function essentially removes the "Other" radio or checkbox value from the $value being validated.
444 * It also adds any text from the free text fields to the value
445 *
446 * Needs to accommodate for times when other opt is selected, but no other free text is entered
447 *
448 * @since 2.0
449 *
450 * @param string|array $value
451 * @param string|array $other_vals (usually of posted values)
452 * @param object $field
453 * @param array $args
454 */
455 public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
456 // Checkboxes and multi-select dropdowns.
457 if ( is_array( $value ) && $field->type === 'checkbox' ) {
458 // Combine "Other" values with checked values. "Other" values will override checked box values.
459 foreach ( $other_vals as $k => $v ) {
460 if ( isset( $value[ $k ] ) && trim( $v ) === '' ) {
461 // If the other box is checked, but doesn't have a value.
462 $value = '';
463 break;
464 }
465 }
466
467 if ( is_array( $value ) && ! empty( $value ) ) {
468 $value = array_merge( $value, $other_vals );
469 }
470 } else {
471 // Radio and dropdowns.
472 $other_key = array_filter( array_keys( $field->options ), 'is_string' );
473 $other_key = reset( $other_key );
474
475 // Multi-select dropdown.
476 if ( is_array( $value ) ) {
477 $o_key = array_search( $field->options[ $other_key ], $value );
478
479 if ( $o_key !== false ) {
480 // Modify the original value so other key will be preserved.
481 $value[ $other_key ] = $value[ $o_key ];
482
483 // By default, the array keys will be numeric for multi-select dropdowns.
484 // If going backwards and forwards between pages, the array key will match the other key.
485 if ( $o_key !== $other_key ) {
486 unset( $value[ $o_key ] );
487 }
488
489 $args['temp_value'] = $value;
490 $value[ $other_key ] = reset( $other_vals );
491 if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
492 unset( $value[ $other_key ] );
493 }
494 }
495 } elseif ( $field->options[ $other_key ] == $value ) {
496 $value = $other_vals;
497 }
498 }
499 }
500
501 /**
502 * Add submitted values to a string for spam checking.
503 *
504 * @param array $values
505 */
506 public static function entry_array_to_string( $values ) {
507 $content = '';
508 foreach ( $values['item_meta'] as $val ) {
509 if ( $content != '' ) {
510 $content .= "\n\n";
511 }
512
513 if ( is_array( $val ) ) {
514 $val = FrmAppHelper::array_flatten( $val );
515 $val = implode( ', ', $val );
516 }
517
518 $content .= $val;
519 }
520
521 return $content;
522 }
523
524 /**
525 * Get the browser from the user agent
526 *
527 * @since 2.04
528 *
529 * @param string $u_agent
530 *
531 * @return string
532 */
533 public static function get_browser( $u_agent ) {
534 $bname = __( 'Unknown', 'formidable' );
535 $platform = __( 'Unknown', 'formidable' );
536 $ub = '';
537
538 // Get the operating system
539 if ( preg_match( '/windows|win32/i', $u_agent ) ) {
540 $platform = 'Windows';
541 } elseif ( preg_match( '/android/i', $u_agent ) ) {
542 $platform = 'Android';
543 } elseif ( preg_match( '/linux/i', $u_agent ) ) {
544 $platform = 'Linux';
545 } elseif ( preg_match( '/macintosh|mac os x/i', $u_agent ) ) {
546 $platform = 'OS X';
547 }
548
549 $agent_options = array(
550 'Chrome' => 'Google Chrome',
551 'Safari' => 'Apple Safari',
552 'Opera' => 'Opera',
553 'Netscape' => 'Netscape',
554 'Firefox' => 'Mozilla Firefox',
555 );
556
557 // Next get the name of the useragent yes seperately and for good reason
558 if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) {
559 $bname = 'Internet Explorer';
560 $ub = 'MSIE';
561 } else {
562 foreach ( $agent_options as $agent_key => $agent_name ) {
563 if ( strpos( $u_agent, $agent_key ) !== false ) {
564 $bname = $agent_name;
565 $ub = $agent_key;
566 break;
567 }
568 }
569 }
570
571 // finally get the correct version number
572 $known = array( 'Version', $ub, 'other' );
573 $pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
574 preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers
575
576 // see how many we have
577 $i = count( $matches['browser'] );
578
579 if ( $i > 1 ) {
580 //we will have two since we are not using 'other' argument yet
581 //see if version is before or after the name
582 if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) {
583 $version = $matches['version'][0];
584 } else {
585 $version = $matches['version'][1];
586 }
587 } elseif ( $i === 1 ) {
588 $version = $matches['version'][0];
589 } else {
590 $version = '';
591 }
592
593 // check if we have a number
594 if ( $version == '' ) {
595 $version = '?';
596 }
597
598 return $bname . ' ' . $version . ' / ' . $platform;
599 }
600
601 /**
602 * @since 3.0
603 */
604 public static function actions_dropdown( $atts ) {
605 $id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
606 $links = self::get_action_links( $id, $atts['entry'] );
607
608 foreach ( $links as $link ) {
609 ?>
610 <div class="misc-pub-section">
611 <a href="<?php echo esc_url( FrmAppHelper::maybe_full_screen_link( $link['url'] ) ); ?>"
612 <?php
613 if ( isset( $link['data'] ) ) {
614 foreach ( $link['data'] as $data => $value ) {
615 echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
616 }
617 }
618 if ( isset( $link['class'] ) ) {
619 echo 'class="' . esc_attr( $link['class'] ) . '" ';
620 }
621 if ( isset( $link['id'] ) ) {
622 echo 'id="' . esc_attr( $link['id'] ) . '" ';
623 }
624 ?>
625 >
626 <?php FrmAppHelper::icon_by_class( $link['icon'], array( 'aria-hidden' => 'true' ) ); ?>
627 <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span>
628 </a>
629 </div>
630 <?php
631 }
632 }
633
634 /**
635 * @since 3.0
636 */
637 private static function get_action_links( $id, $entry ) {
638 $page = FrmAppHelper::get_param( 'frm_action' );
639 $actions = array();
640
641 if ( $page != 'show' ) {
642 $actions['frm_view'] = array(
643 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=show&id=' . $id . '&form=' . $entry->form_id ),
644 'label' => __( 'View Entry', 'formidable' ),
645 'icon' => 'frm_icon_font frm_save_icon',
646 );
647 }
648
649 if ( current_user_can( 'frm_delete_entries' ) ) {
650 $actions['frm_delete'] = array(
651 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ),
652 'label' => __( 'Delete Entry', 'formidable' ),
653 'icon' => 'frm_icon_font frm_delete_icon',
654 'data' => array(
655 'frmverify' => __( 'Delete this form entry?', 'formidable' ),
656 ),
657 );
658 }
659
660 if ( $page == 'show' ) {
661 $actions['frm_print'] = array(
662 'url' => '#',
663 'label' => __( 'Print Entry', 'formidable' ),
664 'data' => array(
665 'frmprint' => '1',
666 ),
667 'icon' => 'frm_icon_font frm_printer_icon',
668 );
669 }
670
671 $actions['frm_resend'] = array(
672 'url' => '#',
673 'label' => __( 'Resend Emails', 'formidable' ),
674 'class' => 'frm_noallow',
675 'data' => array(
676 'upgrade' => __( 'Resend Emails', 'formidable' ),
677 'medium' => 'resend-email',
678 'content' => 'entry',
679 ),
680 'icon' => 'frm_icon_font frm_email_icon',
681 );
682
683 $actions['frm_edit'] = array(
684 'url' => '#',
685 'label' => __( 'Edit Entry', 'formidable' ),
686 'class' => 'frm_noallow',
687 'data' => array(
688 'upgrade' => __( 'Entry edits', 'formidable' ),
689 'medium' => 'edit-entries',
690 'content' => 'entry',
691 ),
692 'icon' => 'frm_icon_font frm_pencil_icon',
693 );
694
695 return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
696 }
697
698 /**
699 * @since 5.0.15
700 *
701 * @param string|int $entry_id
702 * @return void
703 */
704 public static function maybe_render_captcha_score( $entry_id ) {
705 $query = array(
706 'item_id' => (int) $entry_id,
707 'field_id' => 0,
708 );
709 $metas_without_a_field = (array) FrmEntryMeta::getAll( $query, ' ORDER BY it.created_at DESC', '', true );
710 foreach ( $metas_without_a_field as $meta ) {
711 if ( ! empty( $meta->meta_value['captcha_score'] ) ) {
712 echo '<div class="misc-pub-section">';
713 FrmAppHelper::icon_by_class( 'frm_icon_font frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
714 echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
715 echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
716 echo '</div>';
717 return;
718 }
719 }
720 }
721 }
722