PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.4
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 6.4, at classes/helpers/FrmEntriesHelper.php

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