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

FrmFormsController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.0, at classes/controllers/FrmFormsController.php

2,246 lines 64.3 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 FrmFormsController {
7
8 public static function menu() {
9 $menu_label = __( 'Forms', 'formidable' );
10 if ( ! FrmAppHelper::pro_is_installed() ) {
11 $menu_label .= ' (Lite)';
12 }
13 add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
14
15 self::maybe_load_listing_hooks();
16 }
17
18 public static function maybe_load_listing_hooks() {
19 $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
20 if ( ! empty( $action ) && ! in_array( $action, array( 'list', 'trash', 'untrash', 'destroy' ) ) ) {
21 return;
22 }
23
24 add_filter( 'get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' );
25
26 add_filter( 'manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
27 add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
28 }
29
30 public static function head() {
31 if ( wp_is_mobile() ) {
32 wp_enqueue_script( 'jquery-touch-punch' );
33 }
34 }
35
36 public static function register_widgets() {
37 require_once( FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php' );
38 register_widget( 'FrmShowForm' );
39 }
40
41 /**
42 * Show a message about conditional logic
43 *
44 * @since 4.06.03
45 */
46 public static function logic_tip() {
47 echo '<a href="javascript:void(0)" class="frm_noallow frm_show_upgrade frm_add_logic_link" data-upgrade="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '" data-message="' . esc_attr__( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', 'formidable' ) . esc_attr( ' <img src="https://cdn.formidableforms.com/wp-content/themes/fp2015git/images/survey/survey-logic.png" srcset="https://cdn.formidableforms.com/wp-content/themes/fp2015git/images/survey/survey-logic@2x.png 2x" alt="Conditional Logic options"/>' ) . '" data-medium="builder" data-content="logic">';
48 FrmAppHelper::icon_by_class( 'frmfont frm_swap_icon' );
49 esc_html_e( 'Add Conditional Logic', 'formidable' );
50 echo '</a>';
51 }
52
53 /**
54 * By default, Divi processes form shortcodes on the edit post page.
55 * Now that won't do.
56 *
57 * @since 3.01
58 */
59 public static function prevent_divi_conflict( $shortcodes ) {
60 $shortcodes[] = 'formidable';
61
62 return $shortcodes;
63 }
64
65 public static function list_form() {
66 FrmAppHelper::permission_check( 'frm_view_forms' );
67
68 $message = '';
69 $params = FrmForm::list_page_params();
70 $errors = self::process_bulk_form_actions( array() );
71 if ( isset( $errors['message'] ) ) {
72 $message = $errors['message'];
73 unset( $errors['message'] );
74 }
75 $errors = apply_filters( 'frm_admin_list_form_action', $errors );
76
77 return self::display_forms_list( $params, $message, $errors );
78 }
79
80 /**
81 * Load the scripts before a modal can be triggered.
82 *
83 * @since 4.0
84 */
85 private static function init_modal() {
86 wp_enqueue_script( 'jquery-ui-dialog' );
87 wp_enqueue_style( 'jquery-ui-dialog' );
88 }
89
90 /**
91 * Create the default email action
92 *
93 * @since 2.02.11
94 *
95 * @param object $form
96 */
97 private static function create_default_email_action( $form ) {
98 FrmForm::maybe_get_form( $form );
99 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
100
101 if ( $create_email ) {
102 $action_control = FrmFormActionsController::get_form_actions( 'email' );
103 $action_control->create( $form->id );
104 }
105 }
106
107 public static function edit( $values = false ) {
108 FrmAppHelper::permission_check( 'frm_edit_forms' );
109
110 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
111
112 return self::get_edit_vars( $id );
113 }
114
115 public static function settings( $id = false, $message = '' ) {
116 FrmAppHelper::permission_check( 'frm_edit_forms' );
117
118 if ( ! $id || ! is_numeric( $id ) ) {
119 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
120 }
121
122 return self::get_settings_vars( $id, array(), $message );
123 }
124
125 public static function update_settings() {
126 FrmAppHelper::permission_check( 'frm_edit_forms' );
127
128 $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
129
130 $errors = FrmForm::validate( $_POST );
131 $warnings = FrmFormsHelper::check_for_warnings( $_POST );
132
133 if ( count( $errors ) > 0 ) {
134 return self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
135 }
136
137 do_action( 'frm_before_update_form_settings', $id );
138
139 $antispam_was_on = self::antispam_was_on( $id );
140
141 FrmForm::update( $id, $_POST );
142
143 $antispam_is_on = ! empty( $_POST['options']['antispam'] );
144 if ( $antispam_is_on !== $antispam_was_on ) {
145 FrmAntiSpam::clear_caches();
146 }
147
148 $message = __( 'Settings Successfully Updated', 'formidable' );
149
150 return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
151 }
152
153 /**
154 * @param int $form_id
155 * @return bool
156 */
157 private static function antispam_was_on( $form_id ) {
158 $form = FrmForm::getOne( $form_id );
159 return ! empty( $form->options['antispam'] );
160 }
161
162 public static function update( $values = array() ) {
163 if ( empty( $values ) ) {
164 $values = $_POST;
165 }
166
167 // Set radio button and checkbox meta equal to "other" value.
168 if ( FrmAppHelper::pro_is_installed() ) {
169 $values = FrmProEntry::mod_other_vals( $values, 'back' );
170 }
171
172 $errors = FrmForm::validate( $values );
173 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
174 if ( $permission_error !== false ) {
175 $errors['form'] = $permission_error;
176 }
177
178 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
179
180 if ( count( $errors ) > 0 ) {
181 return self::get_edit_vars( $id, $errors );
182 } else {
183 FrmForm::update( $id, $values );
184 $message = __( 'Form was successfully updated.', 'formidable' );
185
186 if ( self::is_too_long( $values ) ) {
187 $message .= '<br/> ' . sprintf(
188 /* translators: %1$s: Start link HTML, %2$s: end link HTML */
189 __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
190 '<a href="https://formidableforms.com/knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/?utm_source=WordPress&utm_medium=builder&utm_campaign=liteplugin" target="_blank" rel="noopener">',
191 '</a>'
192 );
193 }
194
195 if ( defined( 'DOING_AJAX' ) ) {
196 wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // WPCS: XSS ok.
197 }
198
199 return self::get_edit_vars( $id, array(), $message );
200 }
201 }
202
203 /**
204 * Check if the value at the end of the form was included.
205 * If it's missing, it means other values at the end of the form
206 * were likely not saved either.
207 *
208 * @since 3.06.01
209 */
210 private static function is_too_long( $values ) {
211 return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] );
212 }
213
214 /**
215 * Redirect to the url for creating from a template
216 * Also delete the current form
217 *
218 * @since 2.0
219 * @deprecated 3.06
220 */
221 public static function _create_from_template() {
222 _deprecated_function( __FUNCTION__, '3.06' );
223
224 FrmAppHelper::permission_check( 'frm_edit_forms' );
225 check_ajax_referer( 'frm_ajax', 'nonce' );
226
227 $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
228 $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
229
230 if ( $current_form ) {
231 FrmForm::destroy( $current_form );
232 }
233
234 echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) );
235 wp_die();
236 }
237
238 public static function duplicate() {
239 FrmAppHelper::permission_check( 'frm_edit_forms' );
240
241 $params = FrmForm::list_page_params();
242 $form = FrmForm::duplicate( $params['id'], $params['template'], true );
243 $message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
244 if ( $form ) {
245 return self::get_edit_vars( $form, array(), $message, true );
246 } else {
247 return self::display_forms_list( $params, __( 'There was a problem creating the new template.', 'formidable' ) );
248 }
249 }
250
251 public static function page_preview() {
252 $params = FrmForm::list_page_params();
253 if ( ! $params['form'] ) {
254 return;
255 }
256
257 $form = FrmForm::getOne( $params['form'] );
258 if ( $form ) {
259 return self::show_form( $form->id, '', true, true );
260 }
261 }
262
263 /**
264 * @since 3.0
265 */
266 public static function show_page_preview() {
267 echo self::page_preview(); // WPCS: XSS ok.
268 }
269
270 public static function preview() {
271 do_action( 'frm_wp' );
272
273 global $frm_vars;
274 $frm_vars['preview'] = true;
275
276 self::load_wp();
277
278 $include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' );
279 if ( $include_theme ) {
280 self::set_preview_query();
281 self::load_theme_preview();
282 } else {
283 self::load_direct_preview();
284 }
285
286 wp_die();
287 }
288
289 /**
290 * @since 3.0
291 */
292 private static function load_wp() {
293 if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) {
294 global $wp;
295 $root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
296 include_once( $root . '/wp-config.php' );
297 $wp->init();
298 $wp->register_globals();
299 }
300 }
301
302 private static function set_preview_query() {
303 $random_page = get_posts(
304 array(
305 'numberposts' => 1,
306 'orderby' => 'date',
307 'order' => 'ASC',
308 'post_type' => 'page',
309 )
310 );
311
312 if ( ! empty( $random_page ) ) {
313 $random_page = reset( $random_page );
314 query_posts(
315 array(
316 'post_type' => 'page',
317 'page_id' => $random_page->ID,
318 )
319 );
320 }
321 }
322
323 /**
324 * @since 3.0
325 */
326 private static function load_theme_preview() {
327 add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
328 add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
329 add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
330 add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' );
331 add_filter( 'is_active_sidebar', '__return_false' );
332 FrmStylesController::enqueue_css( 'enqueue', true );
333
334 if ( false === get_template_part( 'page' ) ) {
335 self::fallback_when_page_template_part_is_not_supported_by_theme();
336 }
337 }
338
339 /**
340 * Not every theme supports get_template_part( 'page' ).
341 * When this is not supported, false is returned, and we can handle a fallback.
342 */
343 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
344 if ( have_posts() ) {
345 the_post();
346 get_header( '' );
347 // add some generic class names to the container to add some natural padding to the content.
348 // .entry-content catches the WordPress TwentyTwenty theme.
349 // .container catches Customizr content.
350 echo '<div class="container entry-content">';
351 the_content();
352 echo '</div>';
353 get_footer();
354 }
355 }
356
357 /**
358 * Set the page title for the theme preview page
359 *
360 * @since 3.0
361 */
362 public static function preview_page_title( $title ) {
363 if ( in_the_loop() ) {
364 $title = self::preview_title( $title );
365 }
366
367 return $title;
368 }
369
370 /**
371 * Set the page title for the theme preview page
372 *
373 * @since 3.0
374 */
375 public static function preview_title( $title ) {
376 return __( 'Form Preview', 'formidable' );
377 }
378
379 /**
380 * Set the page content for the theme preview page
381 *
382 * @since 3.0
383 */
384 public static function preview_content( $content ) {
385 if ( in_the_loop() ) {
386 $content = self::show_page_preview();
387 }
388
389 return $content;
390 }
391
392 /**
393 * @since 3.0
394 */
395 private static function load_direct_preview() {
396 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
397
398 $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
399 if ( $key == '' ) {
400 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
401 }
402
403 $form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
404 if ( empty( $form ) ) {
405 $form = FrmForm::getAll( array(), '', 1 );
406 }
407
408 require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
409 }
410
411 public static function untrash() {
412 self::change_form_status( 'untrash' );
413 }
414
415 public static function bulk_untrash( $ids ) {
416 FrmAppHelper::permission_check( 'frm_edit_forms' );
417
418 $count = FrmForm::set_status( $ids, 'published' );
419
420 /* translators: %1$s: Number of forms */
421 $message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
422
423 return $message;
424 }
425
426 /**
427 * @since 3.06
428 */
429 public static function ajax_trash() {
430 FrmAppHelper::permission_check( 'frm_delete_forms' );
431 check_ajax_referer( 'frm_ajax', 'nonce' );
432 $form_id = FrmAppHelper::get_param( 'id', '', 'post', 'absint' );
433 FrmForm::set_status( $form_id, 'trash' );
434 wp_die();
435 }
436
437 public static function trash() {
438 self::change_form_status( 'trash' );
439 }
440
441 /**
442 * @param string $status
443 *
444 * @return int The number of forms changed
445 */
446 public static function change_form_status( $status ) {
447 $available_status = array(
448 'untrash' => array(
449 'permission' => 'frm_edit_forms',
450 'new_status' => 'published',
451 ),
452 'trash' => array(
453 'permission' => 'frm_delete_forms',
454 'new_status' => 'trash',
455 ),
456 );
457
458 if ( ! isset( $available_status[ $status ] ) ) {
459 return;
460 }
461
462 FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
463
464 $params = FrmForm::list_page_params();
465
466 //check nonce url
467 check_admin_referer( $status . '_form_' . $params['id'] );
468
469 $count = 0;
470 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
471 $count ++;
472 }
473
474 $form_type = FrmAppHelper::get_simple_request(
475 array(
476 'param' => 'form_type',
477 'type' => 'request',
478 )
479 );
480
481 /* translators: %1$s: Number of forms */
482 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
483
484 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
485 $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' );
486
487 $message = $available_status[ $status ]['message'];
488
489 self::display_forms_list( $params, $message );
490 }
491
492 public static function bulk_trash( $ids ) {
493 FrmAppHelper::permission_check( 'frm_delete_forms' );
494
495 $count = 0;
496 foreach ( $ids as $id ) {
497 if ( FrmForm::trash( $id ) ) {
498 $count ++;
499 }
500 }
501
502 $current_page = FrmAppHelper::get_simple_request(
503 array(
504 'param' => 'form_type',
505 'type' => 'request',
506 )
507 );
508 $message = sprintf(
509 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
510 _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ),
511 $count,
512 '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">',
513 '</a>'
514 );
515
516 return $message;
517 }
518
519 public static function destroy() {
520 FrmAppHelper::permission_check( 'frm_delete_forms' );
521
522 $params = FrmForm::list_page_params();
523
524 // Check nonce url.
525 check_admin_referer( 'destroy_form_' . $params['id'] );
526
527 $count = 0;
528 if ( FrmForm::destroy( $params['id'] ) ) {
529 $count ++;
530 }
531
532 /* translators: %1$s: Number of forms */
533 $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
534
535 self::display_forms_list( $params, $message );
536 }
537
538 public static function bulk_destroy( $ids ) {
539 FrmAppHelper::permission_check( 'frm_delete_forms' );
540
541 $count = 0;
542 foreach ( $ids as $id ) {
543 $d = FrmForm::destroy( $id );
544 if ( $d ) {
545 $count ++;
546 }
547 }
548
549 /* translators: %1$s: Number of forms */
550 $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
551
552 return $message;
553 }
554
555 private static function delete_all() {
556 // Check nonce url.
557 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
558 if ( $permission_error !== false ) {
559 self::display_forms_list( array(), '', array( $permission_error ) );
560
561 return;
562 }
563
564 $count = FrmForm::scheduled_delete( time() );
565
566 /* translators: %1$s: Number of forms */
567 $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
568
569 self::display_forms_list( array(), $message );
570 }
571
572 /**
573 * Create a new form from the modal.
574 *
575 * @since 4.0
576 */
577 public static function build_new_form() {
578 global $wpdb;
579
580 FrmAppHelper::permission_check( 'frm_edit_forms' );
581 check_ajax_referer( 'frm_ajax', 'nonce' );
582
583 $new_values = self::get_modal_values();
584 $new_values['form_key'] = $new_values['name'];
585
586 $form_id = FrmForm::create( $new_values );
587
588 self::create_default_email_action( $form_id );
589
590 $response = array(
591 'redirect' => FrmForm::get_edit_link( $form_id ),
592 );
593
594 echo wp_json_encode( $response );
595 wp_die();
596 }
597
598 /**
599 * Create a custom template from a form
600 *
601 * @since 3.06
602 */
603 public static function build_template() {
604 global $wpdb;
605
606 FrmAppHelper::permission_check( 'frm_edit_forms' );
607 check_ajax_referer( 'frm_ajax', 'nonce' );
608
609 $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
610 $new_form_id = FrmForm::duplicate( $form_id, 1, true );
611 if ( ! $new_form_id ) {
612 $response = array(
613 'message' => __( 'There was an error creating a template.', 'formidable' ),
614 );
615 } else {
616 $new_values = self::get_modal_values();
617 $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
618 if ( $query_results ) {
619 FrmForm::clear_form_cache();
620 }
621
622 $response = array(
623 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ),
624 );
625 }
626
627 echo wp_json_encode( $response );
628 wp_die();
629 }
630
631 /**
632 * Before creating a new form, get the name and description from the modal.
633 *
634 * @since 4.0
635 */
636 private static function get_modal_values() {
637 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
638 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
639
640 return array(
641 'name' => $name,
642 'description' => $desc,
643 );
644 }
645
646 /**
647 * Inserts Formidable button
648 * Hook exists since 2.5.0
649 *
650 * @since 2.0.15
651 */
652 public static function insert_form_button() {
653 if ( current_user_can( 'frm_view_forms' ) ) {
654 FrmAppHelper::load_admin_wide_js();
655 $menu_name = FrmAppHelper::get_menu_name();
656 $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
657 echo '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' .
658 FrmAppHelper::kses( $icon, 'all' ) .
659 ' ' . esc_html( $menu_name ) . '</a>'; // WPCS: XSS ok.
660 }
661 }
662
663 public static function insert_form_popup() {
664 $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
665 if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) {
666 return;
667 }
668
669 FrmAppHelper::load_admin_wide_js();
670
671 $shortcodes = array(
672 'formidable' => array(
673 'name' => __( 'Form', 'formidable' ),
674 'label' => __( 'Insert a Form', 'formidable' ),
675 ),
676 );
677
678 $shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes );
679
680 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php' );
681 }
682
683 public static function get_shortcode_opts() {
684 FrmAppHelper::permission_check( 'frm_view_forms' );
685 check_ajax_referer( 'frm_ajax', 'nonce' );
686
687 $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
688 if ( empty( $shortcode ) ) {
689 wp_die();
690 }
691
692 echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
693 echo '<input type="radio" name="frmsc" value="' . esc_attr( $shortcode ) . '" id="sc-' . esc_attr( $shortcode ) . '" class="frm_hidden" />';
694
695 $form_id = '';
696 $opts = array();
697 switch ( $shortcode ) {
698 case 'formidable':
699 $opts = array(
700 'form_id' => 'id',
701 'title' => array(
702 'val' => 1,
703 'label' => __( 'Display form title', 'formidable' ),
704 ),
705 'description' => array(
706 'val' => 1,
707 'label' => __( 'Display form description', 'formidable' ),
708 ),
709 'minimize' => array(
710 'val' => 1,
711 'label' => __( 'Minimize form HTML', 'formidable' ),
712 ),
713 );
714 }
715 $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
716
717 if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
718 // allow other shortcodes to use the required form id option
719 $form_id = $opts['form_id'];
720 unset( $opts['form_id'] );
721 }
722
723 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
724
725 echo '</div>';
726
727 wp_die();
728 }
729
730 public static function display_forms_list( $params = array(), $message = '', $errors = array() ) {
731 FrmAppHelper::permission_check( 'frm_view_forms' );
732
733 global $wpdb, $frm_vars;
734
735 if ( empty( $params ) ) {
736 $params = FrmForm::list_page_params();
737 }
738
739 $wp_list_table = new FrmFormsListHelper( compact( 'params' ) );
740
741 $pagenum = $wp_list_table->get_pagenum();
742
743 $wp_list_table->prepare_items();
744
745 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
746 if ( $pagenum > $total_pages && $total_pages > 0 ) {
747 wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
748 die();
749 }
750
751 require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php' );
752 }
753
754 public static function get_columns( $columns ) {
755 $columns['cb'] = '<input type="checkbox" />';
756 $columns['id'] = 'ID';
757
758 $type = FrmAppHelper::get_simple_request(
759 array(
760 'param' => 'form_type',
761 'type' => 'request',
762 'default' => 'published',
763 )
764 );
765
766 if ( 'template' == $type ) {
767 $columns['name'] = __( 'Template Name', 'formidable' );
768 $columns['type'] = __( 'Type', 'formidable' );
769 $columns['form_key'] = __( 'Key', 'formidable' );
770 } else {
771 $columns['name'] = __( 'Form Title', 'formidable' );
772 $columns['entries'] = __( 'Entries', 'formidable' );
773 $columns['form_key'] = __( 'Key', 'formidable' );
774 $columns['shortcode'] = __( 'Shortcodes', 'formidable' );
775 }
776
777 $columns['created_at'] = __( 'Date', 'formidable' );
778
779 add_screen_option(
780 'per_page',
781 array(
782 'label' => __( 'Forms', 'formidable' ),
783 'default' => 20,
784 'option' => 'formidable_page_formidable_per_page',
785 )
786 );
787
788 return $columns;
789 }
790
791 public static function get_sortable_columns() {
792 return array(
793 'id' => 'id',
794 'name' => 'name',
795 'description' => 'description',
796 'form_key' => 'form_key',
797 'created_at' => 'created_at',
798 );
799 }
800
801 public static function hidden_columns( $hidden_columns ) {
802 $type = FrmAppHelper::get_simple_request(
803 array(
804 'param' => 'form_type',
805 'type' => 'request',
806 )
807 );
808
809 if ( $type === 'template' ) {
810 $hidden_columns[] = 'id';
811 $hidden_columns[] = 'form_key';
812 }
813
814 return $hidden_columns;
815 }
816
817 public static function save_per_page( $save, $option, $value ) {
818 if ( $option == 'formidable_page_formidable_per_page' ) {
819 $save = (int) $value;
820 }
821
822 return $save;
823 }
824
825 /**
826 * @return bool
827 */
828 public static function expired() {
829 global $frm_expired;
830 return $frm_expired;
831 }
832
833 /**
834 * Get data from api before rendering it so that we can flag the modal as expired
835 */
836 public static function before_list_templates() {
837 global $frm_templates;
838 global $frm_expired;
839 global $frm_license_type;
840
841 $api = new FrmFormTemplateApi();
842 $frm_templates = $api->get_api_info();
843 $expired = false;
844 $license_type = '';
845 if ( isset( $frm_templates['error'] ) ) {
846 $error = $frm_templates['error']['message'];
847 $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
848 $expired = 'expired' === $frm_templates['error']['code'];
849 $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : '';
850 unset( $frm_templates['error'] );
851 }
852
853 $frm_expired = $expired;
854 $frm_license_type = $license_type;
855 }
856
857 public static function list_templates() {
858 global $frm_templates;
859 global $frm_license_type;
860
861 $templates = $frm_templates;
862 $custom_templates = array();
863 $templates_by_category = array();
864
865 self::add_user_templates( $custom_templates );
866
867 foreach ( $templates as $template ) {
868 if ( ! isset( $template['categories'] ) ) {
869 continue;
870 }
871
872 foreach ( $template['categories'] as $category ) {
873 if ( ! isset( $templates_by_category[ $category ] ) ) {
874 $templates_by_category[ $category ] = array();
875 }
876
877 $templates_by_category[ $category ][] = $template;
878 }
879 }
880 unset( $template );
881
882 // Subcategories that are included elsewhere.
883 $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' );
884
885 $categories = array_keys( $templates_by_category );
886 $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() );
887 $categories = array_diff( $categories, $redundant_cats );
888 sort( $categories );
889
890 array_walk(
891 $custom_templates,
892 function( &$template ) {
893 $template['custom'] = true;
894 }
895 );
896
897 $my_templates_translation = __( 'My Templates', 'formidable' );
898 $categories = array_merge( array( $my_templates_translation ), $categories );
899 $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
900 $license_type = $frm_license_type;
901 $args = compact( 'pricing', 'license_type' );
902 $where = apply_filters( 'frm_forms_dropdown', array(), '' );
903 $forms = FrmForm::get_published_forms( $where );
904 $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/';
905
906 $templates_by_category[ $my_templates_translation ] = $custom_templates;
907
908 unset( $pricing, $license_type, $where );
909 wp_enqueue_script( 'accordion' ); // register accordion for template groups
910 require $view_path . 'list-templates.php';
911 }
912
913 /**
914 * @since 4.03.01
915 */
916 private static function get_template_categories( $templates ) {
917 $categories = array();
918 foreach ( $templates as $template ) {
919 if ( isset( $template['categories'] ) ) {
920 $categories = array_merge( $categories, $template['categories'] );
921 }
922 }
923 $exclude_cats = FrmFormsHelper::ignore_template_categories();
924 $categories = array_unique( $categories );
925 $categories = array_diff( $categories, $exclude_cats );
926 sort( $categories );
927 return $categories;
928 }
929
930 private static function add_user_templates( &$templates ) {
931 $user_templates = array(
932 'is_template' => 1,
933 'default_template' => 0,
934 );
935 $user_templates = FrmForm::getAll( $user_templates, 'name' );
936 foreach ( $user_templates as $template ) {
937 $template = array(
938 'id' => $template->id,
939 'name' => $template->name,
940 'key' => $template->form_key,
941 'description' => $template->description,
942 'url' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ),
943 'released' => $template->created_at,
944 'installed' => 1,
945 );
946 array_unshift( $templates, $template );
947 unset( $template );
948 }
949 }
950
951 private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
952 global $frm_vars;
953
954 $form = FrmForm::getOne( $id );
955 if ( ! $form ) {
956 wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
957 }
958
959 if ( $form->parent_form_id ) {
960 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
961 wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( FrmForm::get_edit_link( $form->parent_form_id ) ) . '">', '</a>' ) );
962 }
963
964 $frm_field_selection = FrmField::field_selection();
965
966 $fields = FrmField::get_all_for_form( $form->id );
967
968 // Automatically add end section fields if they don't exist (2.0 migration).
969 $reset_fields = false;
970 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
971
972 if ( $reset_fields ) {
973 $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
974 }
975
976 unset( $reset_fields );
977
978 $args = array( 'parent_form_id' => $form->id );
979 $values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true, array(), $args );
980 $values['fields'] = $fields;
981
982 $edit_message = __( 'Form was successfully updated.', 'formidable' );
983 if ( $form->is_template && $message == $edit_message ) {
984 $message = __( 'Template was successfully updated.', 'formidable' );
985 }
986
987 $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
988 $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] );
989
990 if ( defined( 'DOING_AJAX' ) ) {
991 wp_die();
992 } else {
993 require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
994 }
995 }
996
997 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
998 FrmAppHelper::permission_check( 'frm_edit_forms' );
999
1000 global $frm_vars;
1001
1002 if ( ! is_array( $args ) ) {
1003 // For reverse compatibility.
1004 $args = array(
1005 'message' => $args,
1006 );
1007 }
1008
1009 $defaults = array(
1010 'message' => '',
1011 'warnings' => array(),
1012 );
1013 $args = array_merge( $defaults, $args );
1014 $message = $args['message'];
1015 $warnings = $args['warnings'];
1016
1017 $form = FrmForm::getOne( $id );
1018 $fields = FrmField::get_all_for_form( $id );
1019 $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
1020
1021 self::clean_submit_html( $values );
1022
1023 $sections = self::get_settings_tabs( $values );
1024 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
1025
1026 require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
1027 }
1028
1029 /**
1030 * @since 4.0
1031 */
1032 public static function form_publish_button( $atts ) {
1033 $values = $atts['values'];
1034 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
1035 }
1036
1037 /**
1038 * Get a list of all the settings tabs for the form settings page.
1039 *
1040 * @since 4.0
1041 *
1042 * @param array $values
1043 * @return array
1044 */
1045 private static function get_settings_tabs( $values ) {
1046 $sections = array(
1047 'advanced' => array(
1048 'name' => __( 'General', 'formidable' ),
1049 'title' => __( 'General Form Settings', 'formidable' ),
1050 'function' => array( __CLASS__, 'advanced_settings' ),
1051 'icon' => 'frm_icon_font frm_settings_icon',
1052 ),
1053 'email' => array(
1054 'name' => __( 'Actions & Notifications', 'formidable' ),
1055 'function' => array( 'FrmFormActionsController', 'email_settings' ),
1056 'id' => 'frm_notification_settings',
1057 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1058 ),
1059 'permissions' => array(
1060 'name' => __( 'Form Permissions', 'formidable' ),
1061 'icon' => 'frm_icon_font frm_lock_icon',
1062 'html_class' => 'frm_show_upgrade frm_noallow',
1063 'data' => array(
1064 'medium' => 'permissions',
1065 'upgrade' => __( 'Form Permissions', 'formidable' ),
1066 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1067 ),
1068 ),
1069 'scheduling' => array(
1070 'name' => __( 'Form Scheduling', 'formidable' ),
1071 'icon' => 'frm_icon_font frm_calendar_icon',
1072 'html_class' => 'frm_show_upgrade frm_noallow',
1073 'data' => array(
1074 'medium' => 'scheduling',
1075 'upgrade' => __( 'Form scheduling settings', 'formidable' ),
1076 ),
1077 ),
1078 'buttons' => array(
1079 'name' => __( 'Styling & Buttons', 'formidable' ),
1080 'class' => __CLASS__,
1081 'function' => 'buttons_settings',
1082 'icon' => 'frm_icon_font frm_pallet_icon',
1083 ),
1084 'html' => array(
1085 'name' => __( 'Customize HTML', 'formidable' ),
1086 'class' => __CLASS__,
1087 'function' => 'html_settings',
1088 'icon' => 'frm_icon_font frm_code_icon',
1089 ),
1090 );
1091
1092 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1093
1094 if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
1095 // Prevent settings from showing in 2 spots.
1096 unset( $sections['permissions'], $sections['scheduling'] );
1097 }
1098
1099 foreach ( $sections as $key => $section ) {
1100 $defaults = array(
1101 'html_class' => '',
1102 'name' => ucfirst( $key ),
1103 'icon' => 'frm_icon_font frm_settings_icon',
1104 );
1105
1106 $section = array_merge( $defaults, $section );
1107
1108 if ( ! isset( $section['anchor'] ) ) {
1109 $section['anchor'] = $key;
1110 }
1111 $section['anchor'] .= '_settings';
1112
1113 if ( ! isset( $section['title'] ) ) {
1114 $section['title'] = $section['name'];
1115 }
1116
1117 if ( ! isset( $section['id'] ) ) {
1118 $section['id'] = $section['anchor'];
1119 }
1120
1121 $sections[ $key ] = $section;
1122 }
1123
1124 return $sections;
1125 }
1126
1127 /**
1128 * @since 4.0
1129 *
1130 * @param array $values
1131 */
1132 public static function advanced_settings( $values ) {
1133 $first_h3 = 'frm_first_h3';
1134
1135 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-advanced.php';
1136 }
1137
1138 /**
1139 * @param array $values
1140 */
1141 private static function render_spam_settings( $values ) {
1142 if ( function_exists( 'akismet_http_post' ) ) {
1143 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1144 }
1145 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/honeypot.php';
1146 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/antispam.php';
1147 }
1148
1149 /**
1150 * @since 4.0
1151 *
1152 * @param array $values
1153 */
1154 public static function buttons_settings( $values ) {
1155 $styles = apply_filters( 'frm_get_style_opts', array() );
1156
1157 $frm_settings = FrmAppHelper::get_settings();
1158 $no_global_style = $frm_settings->load_style === 'none';
1159
1160 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' );
1161 }
1162
1163 /**
1164 * @since 4.0
1165 *
1166 * @param array $values
1167 */
1168 public static function html_settings( $values ) {
1169 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1170 }
1171
1172 /**
1173 * Replace old Submit Button href with new href to avoid errors in Chrome
1174 *
1175 * @since 2.03.08
1176 *
1177 * @param array|boolean $values
1178 */
1179 private static function clean_submit_html( &$values ) {
1180 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1181 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
1182 }
1183 }
1184
1185 public static function mb_tags_box( $form_id, $class = '' ) {
1186 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1187 $linked_forms = array();
1188 $col = 'one';
1189 $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1190
1191 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1192 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1193
1194 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1195
1196 include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1197 }
1198
1199 /**
1200 * @since 3.04.01
1201 */
1202 private static function advanced_helpers( $atts ) {
1203 $advanced_helpers = array(
1204 'default' => array(
1205 'heading' => __( 'Customize field values with the following parameters.', 'formidable' ),
1206 'codes' => self::get_advanced_shortcodes(),
1207 ),
1208 );
1209
1210 $user_fields = self::user_shortcodes();
1211 if ( ! empty( $user_fields ) ) {
1212 $user_helpers = array();
1213 foreach ( $user_fields as $uk => $uf ) {
1214 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1215 unset( $uk, $uf );
1216 }
1217
1218 $advanced_helpers['user_id'] = array(
1219 'codes' => $user_helpers,
1220 );
1221 }
1222
1223 /**
1224 * Add extra helper shortcodes on the Advanced tab in form settings and views
1225 *
1226 * @since 3.04.01
1227 *
1228 * @param array $atts - Includes fields and form_id
1229 */
1230 return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
1231 }
1232
1233 /**
1234 * Get an array of the options to display in the advanced tab
1235 * of the customization panel
1236 *
1237 * @since 2.0.6
1238 */
1239 private static function get_advanced_shortcodes() {
1240 $adv_shortcodes = array(
1241 'x sep=", "' => array(
1242 'label' => __( 'Separator', 'formidable' ),
1243 'title' => __( 'Use a different separator for checkbox fields', 'formidable' ),
1244 ),
1245 'x format="d-m-Y"' => array(
1246 'label' => __( 'Date Format', 'formidable' ),
1247 ),
1248 'x show="field_label"' => array(
1249 'label' => __( 'Field Label', 'formidable' ),
1250 ),
1251 'x wpautop=0' => array(
1252 'label' => __( 'No Auto P', 'formidable' ),
1253 'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
1254 ),
1255 );
1256 $adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1257
1258 // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
1259
1260 return $adv_shortcodes;
1261 }
1262
1263 /**
1264 * @since 3.04.01
1265 */
1266 private static function user_shortcodes() {
1267 $options = array(
1268 'ID' => __( 'User ID', 'formidable' ),
1269 'first_name' => __( 'First Name', 'formidable' ),
1270 'last_name' => __( 'Last Name', 'formidable' ),
1271 'display_name' => __( 'Display Name', 'formidable' ),
1272 'user_login' => __( 'User Login', 'formidable' ),
1273 'user_email' => __( 'Email', 'formidable' ),
1274 'avatar' => __( 'Avatar', 'formidable' ),
1275 'author_link' => __( 'Author Link', 'formidable' ),
1276 );
1277
1278 return apply_filters( 'frm_user_shortcodes', $options );
1279 }
1280
1281 /**
1282 * Get an array of the helper shortcodes to display in the customization panel
1283 *
1284 * @since 2.0.6
1285 */
1286 private static function get_shortcode_helpers( $settings_tab ) {
1287 $entry_shortcodes = array(
1288 'id' => __( 'Entry ID', 'formidable' ),
1289 'key' => __( 'Entry Key', 'formidable' ),
1290 'post_id' => __( 'Post ID', 'formidable' ),
1291 'ip' => __( 'User IP', 'formidable' ),
1292 'created-at' => __( 'Entry created', 'formidable' ),
1293 'updated-at' => __( 'Entry updated', 'formidable' ),
1294 '' => '',
1295 'siteurl' => __( 'Site URL', 'formidable' ),
1296 'sitename' => __( 'Site Name', 'formidable' ),
1297 );
1298
1299 if ( ! FrmAppHelper::pro_is_installed() ) {
1300 unset( $entry_shortcodes['post_id'] );
1301 }
1302
1303 if ( $settings_tab ) {
1304 $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
1305 $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
1306 $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
1307 }
1308
1309 /**
1310 * Use this hook to add or remove buttons in the helpers section
1311 * in the customization panel
1312 *
1313 * @since 2.0.6
1314 */
1315 $entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
1316
1317 return $entry_shortcodes;
1318 }
1319
1320 /**
1321 * Insert the form class setting into the form
1322 */
1323 public static function form_classes( $form ) {
1324 if ( isset( $form->options['form_class'] ) ) {
1325 echo esc_attr( sanitize_text_field( $form->options['form_class'] ) );
1326 }
1327
1328 if ( isset( $form->options['js_validate'] ) && $form->options['js_validate'] ) {
1329 echo ' frm_js_validate ';
1330 }
1331 }
1332
1333 public static function get_email_html() {
1334 FrmAppHelper::permission_check( 'frm_view_forms' );
1335 check_ajax_referer( 'frm_ajax', 'nonce' );
1336
1337 echo FrmEntriesController::show_entry_shortcode( // WPCS: XSS ok.
1338 array(
1339 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1340 'default_email' => true,
1341 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1342 )
1343 );
1344 wp_die();
1345 }
1346
1347 public static function filter_content( $content, $form, $entry = false ) {
1348 self::get_entry_by_param( $entry );
1349 if ( ! $entry ) {
1350 return $content;
1351 }
1352
1353 if ( is_object( $form ) ) {
1354 $form = $form->id;
1355 }
1356
1357 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1358 $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1359
1360 return $content;
1361 }
1362
1363 private static function get_entry_by_param( &$entry ) {
1364 if ( ! $entry || ! is_object( $entry ) ) {
1365 if ( ! $entry || ! is_numeric( $entry ) ) {
1366 $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
1367 }
1368
1369 FrmEntry::maybe_get_entry( $entry );
1370 }
1371 }
1372
1373 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1374 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1375 }
1376
1377 public static function process_bulk_form_actions( $errors ) {
1378 if ( ! $_REQUEST ) {
1379 return $errors;
1380 }
1381
1382 $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1383 if ( $bulkaction == - 1 ) {
1384 $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1385 }
1386
1387 if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
1388 FrmAppHelper::remove_get_action();
1389
1390 $bulkaction = str_replace( 'bulk_', '', $bulkaction );
1391 }
1392
1393 $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
1394 if ( empty( $ids ) ) {
1395 $errors[] = __( 'No forms were specified', 'formidable' );
1396
1397 return $errors;
1398 }
1399
1400 $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
1401 if ( $permission_error !== false ) {
1402 $errors[] = $permission_error;
1403
1404 return $errors;
1405 }
1406
1407 if ( ! is_array( $ids ) ) {
1408 $ids = explode( ',', $ids );
1409 }
1410
1411 switch ( $bulkaction ) {
1412 case 'delete':
1413 $message = self::bulk_destroy( $ids );
1414 break;
1415 case 'trash':
1416 $message = self::bulk_trash( $ids );
1417 break;
1418 case 'untrash':
1419 $message = self::bulk_untrash( $ids );
1420 }
1421
1422 if ( isset( $message ) && ! empty( $message ) ) {
1423 $errors['message'] = $message;
1424 }
1425
1426 return $errors;
1427 }
1428
1429 public static function route() {
1430 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1431 $vars = array();
1432 FrmAppHelper::include_svg();
1433
1434 if ( isset( $_POST['frm_compact_fields'] ) ) {
1435 FrmAppHelper::permission_check( 'frm_edit_forms' );
1436
1437 // Javascript needs to be allowed in some field settings.
1438 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1439 $json_vars = htmlspecialchars_decode( nl2br( str_replace( '&quot;', '"', wp_unslash( $_POST['frm_compact_fields'] ) ) ) );
1440 $json_vars = json_decode( $json_vars, true );
1441 if ( empty( $json_vars ) ) {
1442 // json decoding failed so we should return an error message.
1443 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1444 if ( 'edit' == $action ) {
1445 $action = 'update';
1446 }
1447
1448 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1449 } else {
1450 $vars = FrmAppHelper::json_to_array( $json_vars );
1451 $action = $vars[ $action ];
1452 unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] );
1453 $_REQUEST = array_merge( $_REQUEST, $vars );
1454 $_POST = array_merge( $_POST, $_REQUEST );
1455 }
1456 } else {
1457 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1458 if ( isset( $_REQUEST['delete_all'] ) ) {
1459 // Override the action for this page.
1460 $action = 'delete_all';
1461 }
1462 }
1463
1464 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1465 FrmAppHelper::trigger_hook_load( 'form' );
1466
1467 switch ( $action ) {
1468 case 'new':
1469 return self::new_form( $vars );
1470 case 'create':
1471 case 'edit':
1472 case 'update':
1473 case 'duplicate':
1474 case 'trash':
1475 case 'untrash':
1476 case 'destroy':
1477 case 'delete_all':
1478 case 'settings':
1479 case 'update_settings':
1480 return self::$action( $vars );
1481 case 'lite-reports':
1482 return self::no_reports( $vars );
1483 case 'views':
1484 return self::no_views( $vars );
1485 default:
1486 do_action( 'frm_form_action_' . $action );
1487 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1488 return;
1489 }
1490
1491 $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1492 if ( $action == - 1 ) {
1493 $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1494 }
1495
1496 if ( strpos( $action, 'bulk_' ) === 0 ) {
1497 FrmAppHelper::remove_get_action();
1498
1499 return self::list_form();
1500 }
1501
1502 return self::display_forms_list();
1503 }
1504 }
1505
1506 public static function json_error( $errors ) {
1507 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1508
1509 return $errors;
1510 }
1511
1512 /**
1513 * Education for premium features.
1514 *
1515 * @since 4.05
1516 */
1517 public static function add_form_style_tab_options() {
1518 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' );
1519 }
1520
1521 /**
1522 * Add education about views.
1523 *
1524 * @since 4.07
1525 */
1526 public static function no_views( $values = array() ) {
1527 FrmAppHelper::include_svg();
1528 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1529 $form = $id ? FrmForm::getOne( $id ) : false;
1530
1531 include FrmAppHelper::plugin_path() . '/classes/views/shared/views-info.php';
1532 }
1533
1534 /**
1535 * Add education about reports.
1536 *
1537 * @since 4.07
1538 */
1539 public static function no_reports( $values = array() ) {
1540 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1541 $form = $id ? FrmForm::getOne( $id ) : false;
1542
1543 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
1544 }
1545
1546 /* FRONT-END FORMS */
1547 public static function admin_bar_css() {
1548 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1549 return;
1550 }
1551
1552 self::move_menu_to_footer();
1553
1554 add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
1555 FrmAppHelper::load_font_style();
1556 }
1557
1558 /**
1559 * @since 4.05.02
1560 */
1561 private static function move_menu_to_footer() {
1562 $settings = FrmAppHelper::get_settings();
1563 if ( empty( $settings->admin_bar ) ) {
1564 remove_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
1565 }
1566 }
1567
1568 public static function admin_bar_configure() {
1569 global $frm_vars;
1570 if ( empty( $frm_vars['forms_loaded'] ) ) {
1571 return;
1572 }
1573
1574 $actions = array();
1575 foreach ( $frm_vars['forms_loaded'] as $form ) {
1576 if ( is_object( $form ) ) {
1577 $actions[ $form->id ] = $form->name;
1578 }
1579 unset( $form );
1580 }
1581
1582 if ( empty( $actions ) ) {
1583 return;
1584 }
1585
1586 self::add_menu_to_admin_bar();
1587 self::add_forms_to_admin_bar( $actions );
1588 }
1589
1590 /**
1591 * @since 2.05.07
1592 */
1593 public static function add_menu_to_admin_bar() {
1594 global $wp_admin_bar;
1595
1596 $wp_admin_bar->add_node(
1597 array(
1598 'id' => 'frm-forms',
1599 'title' => '<span class="ab-icon"></span><span class="ab-label">' . FrmAppHelper::get_menu_name() . '</span>',
1600 'href' => admin_url( 'admin.php?page=formidable' ),
1601 'meta' => array(
1602 'title' => FrmAppHelper::get_menu_name(),
1603 ),
1604 )
1605 );
1606 }
1607
1608 /**
1609 * @since 2.05.07
1610 */
1611 private static function add_forms_to_admin_bar( $actions ) {
1612 global $wp_admin_bar;
1613
1614 asort( $actions );
1615
1616 foreach ( $actions as $form_id => $name ) {
1617
1618 $wp_admin_bar->add_node(
1619 array(
1620 'parent' => 'frm-forms',
1621 'id' => 'edit_form_' . $form_id,
1622 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
1623 'href' => FrmForm::get_edit_link( $form_id ),
1624 )
1625 );
1626 }
1627 }
1628
1629 /**
1630 * The formidable shortcode
1631 *
1632 * @param array $atts The params from the shortcode.
1633 */
1634 public static function get_form_shortcode( $atts ) {
1635 global $frm_vars;
1636 if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1637 $sc = '[formidable';
1638 $sc .= FrmAppHelper::array_to_html_params( $atts );
1639 return $sc . ']';
1640 }
1641
1642 $shortcode_atts = shortcode_atts(
1643 array(
1644 'id' => '',
1645 'key' => '',
1646 'title' => false,
1647 'description' => false,
1648 'readonly' => false,
1649 'entry_id' => false,
1650 'fields' => array(),
1651 'exclude_fields' => array(),
1652 'minimize' => false,
1653 ),
1654 $atts
1655 );
1656 do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts );
1657
1658 return self::show_form( $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], $shortcode_atts['description'], $atts );
1659 }
1660
1661 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
1662 if ( empty( $id ) ) {
1663 $id = $key;
1664 }
1665
1666 $form = self::maybe_get_form_to_show( $id );
1667 if ( ! $form ) {
1668 return __( 'Please select a valid form', 'formidable' );
1669 }
1670
1671 FrmAppController::maybe_update_styles();
1672
1673 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1674 FrmAppHelper::trigger_hook_load( 'form', $form );
1675
1676 $form = apply_filters( 'frm_pre_display_form', $form );
1677
1678 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
1679
1680 if ( self::is_viewable_draft_form( $form ) ) {
1681 // don't show a draft form on a page
1682 $form = __( 'Please select a valid form', 'formidable' );
1683 } elseif ( ! FrmForm::is_visible_to_user( $form ) ) {
1684 $form = do_shortcode( $frm_settings->login_msg );
1685 } else {
1686 do_action( 'frm_pre_get_form', $form );
1687 $form = self::get_form( $form, $title, $description, $atts );
1688
1689 /**
1690 * Use this shortcode to check for external shortcodes that may span
1691 * across multiple fields in the customizable HTML
1692 *
1693 * @since 2.0.8
1694 */
1695 $form = apply_filters( 'frm_filter_final_form', $form );
1696 }
1697
1698 return $form;
1699 }
1700
1701 private static function maybe_get_form_to_show( $id ) {
1702 $form = false;
1703
1704 if ( ! empty( $id ) ) { // no form id or key set
1705 $form = FrmForm::getOne( $id );
1706 if ( ! $form || $form->parent_form_id || $form->status == 'trash' ) {
1707 $form = false;
1708 }
1709 }
1710
1711 return $form;
1712 }
1713
1714 private static function is_viewable_draft_form( $form ) {
1715 return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
1716 }
1717
1718 public static function get_form( $form, $title, $description, $atts = array() ) {
1719 ob_start();
1720
1721 do_action( 'frm_before_get_form', $atts );
1722
1723 self::get_form_contents( $form, $title, $description, $atts );
1724 self::enqueue_scripts( FrmForm::get_params( $form ) );
1725
1726 $contents = ob_get_contents();
1727 ob_end_clean();
1728
1729 self::maybe_minimize_form( $atts, $contents );
1730
1731 return $contents;
1732 }
1733
1734 public static function enqueue_scripts( $params ) {
1735 do_action( 'frm_enqueue_form_scripts', $params );
1736 }
1737
1738 public static function get_form_contents( $form, $title, $description, $atts ) {
1739 $params = FrmForm::get_params( $form );
1740 $errors = self::get_saved_errors( $form, $params );
1741 $fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
1742 $reset = false;
1743 $pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
1744
1745 $handle_process_here = $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST;
1746
1747 if ( ! $handle_process_here ) {
1748 do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
1749 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
1750 self::show_form_after_submit( $pass_args );
1751 }
1752 } elseif ( ! empty( $errors ) ) {
1753 self::show_form_after_submit( $pass_args );
1754
1755 } else {
1756
1757 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
1758
1759 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
1760 $entry_id = self::just_created_entry( $form->id );
1761 $pass_args['entry_id'] = $entry_id;
1762 $pass_args['reset'] = true;
1763 $pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
1764
1765 self::run_success_action( $pass_args );
1766
1767 do_action(
1768 'frm_after_entry_processed',
1769 array(
1770 'entry_id' => $entry_id,
1771 'form' => $form,
1772 )
1773 );
1774 }
1775 }
1776 }
1777
1778 /**
1779 * If the form was processed earlier (init), get the generated errors
1780 *
1781 * @since 2.05
1782 */
1783 private static function get_saved_errors( $form, $params ) {
1784 global $frm_vars;
1785
1786 if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) {
1787 $errors = $frm_vars['created_entries'][ $form->id ]['errors'];
1788 } else {
1789 $errors = array();
1790 }
1791
1792 return $errors;
1793 }
1794
1795 /**
1796 * @since 2.2.7
1797 */
1798 public static function just_created_entry( $form_id ) {
1799 global $frm_vars;
1800
1801 return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0;
1802 }
1803
1804 /**
1805 * @since 3.0
1806 */
1807 private static function get_confirmation_method( $atts ) {
1808 $opt = 'success_action';
1809 $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
1810 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
1811
1812 if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
1813 $method = 'message';
1814 }
1815
1816 return $method;
1817 }
1818
1819 public static function maybe_trigger_redirect( $form, $params, $args ) {
1820 if ( ! isset( $params['id'] ) ) {
1821 global $frm_vars;
1822 $params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id'];
1823 }
1824
1825 $conf_method = self::get_confirmation_method(
1826 array(
1827 'form' => $form,
1828 'entry_id' => $params['id'],
1829 )
1830 );
1831
1832 if ( 'redirect' === $conf_method ) {
1833 self::trigger_redirect( $form, $params, $args );
1834 }
1835 }
1836
1837 public static function trigger_redirect( $form, $params, $args ) {
1838 $success_args = array(
1839 'action' => $params['action'],
1840 'conf_method' => 'redirect',
1841 'form' => $form,
1842 'entry_id' => $params['id'],
1843 );
1844
1845 if ( isset( $args['ajax'] ) ) {
1846 $success_args['ajax'] = $args['ajax'];
1847 }
1848
1849 self::run_success_action( $success_args );
1850 }
1851
1852 /**
1853 * Used when the success action is not 'message'
1854 *
1855 * @since 2.05
1856 */
1857 public static function run_success_action( $args ) {
1858 $extra_args = $args;
1859 unset( $extra_args['form'] );
1860
1861 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
1862
1863 $opt = ( ! isset( $args['action'] ) || $args['action'] == 'create' ) ? 'success' : 'edit';
1864
1865 $args['success_opt'] = $opt;
1866 if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[ $opt . '_page_id' ] ) ) {
1867 self::load_page_after_submit( $args );
1868 } elseif ( $args['conf_method'] == 'redirect' ) {
1869 self::redirect_after_submit( $args );
1870 } else {
1871 self::show_message_after_save( $args );
1872 }
1873 }
1874
1875 /**
1876 * @since 3.0
1877 */
1878 private static function load_page_after_submit( $args ) {
1879 global $post;
1880 $opt = $args['success_opt'];
1881 if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
1882 $page = get_post( $args['form']->options[ $opt . '_page_id' ] );
1883 $old_post = $post;
1884 $post = $page;
1885 $content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] );
1886 echo apply_filters( 'the_content', $content ); // WPCS: XSS ok.
1887 $post = $old_post;
1888 }
1889 }
1890
1891 /**
1892 * @since 3.0
1893 */
1894 private static function redirect_after_submit( $args ) {
1895 global $frm_vars;
1896
1897 add_filter( 'frm_use_wpautop', '__return_false' );
1898
1899 $opt = $args['success_opt'];
1900 $success_url = trim( $args['form']->options[ $opt . '_url' ] );
1901 $success_url = apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] );
1902 $success_url = do_shortcode( $success_url );
1903
1904 $success_msg = isset( $args['form']->options[ $opt . '_msg' ] ) ? $args['form']->options[ $opt . '_msg' ] : __( 'Please wait while you are redirected.', 'formidable' );
1905
1906 $redirect_msg = self::get_redirect_message( $success_url, $success_msg, $args );
1907
1908 $args['id'] = $args['entry_id'];
1909 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
1910
1911 add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
1912 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
1913
1914 $doing_ajax = FrmAppHelper::doing_ajax();
1915
1916 if ( isset( $args['ajax'] ) && $args['ajax'] && $doing_ajax ) {
1917 echo json_encode( array( 'redirect' => $success_url ) );
1918 wp_die();
1919 } elseif ( ! headers_sent() ) {
1920 wp_redirect( esc_url_raw( $success_url ) );
1921 die(); // do not use wp_die or redirect fails
1922 } else {
1923 add_filter( 'frm_use_wpautop', '__return_true' );
1924
1925 echo $redirect_msg; // WPCS: XSS ok.
1926 echo "<script type='text/javascript'>window.onload = function(){setTimeout(window.location='" . esc_url_raw( $success_url ) . "', 8000);}</script>";
1927 }
1928 }
1929
1930 /**
1931 * @since 3.0
1932 *
1933 * @param string $success_url
1934 * @param string $success_msg
1935 * @param array $args
1936 */
1937 private static function get_redirect_message( $success_url, $success_msg, $args ) {
1938 $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg frm_message" role="status">' . $success_msg . '<br/>' .
1939 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1940 sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
1941 '</div></div>';
1942
1943 $redirect_args = array(
1944 'entry_id' => $args['entry_id'],
1945 'form_id' => $args['form']->id,
1946 'form' => $args['form'],
1947 );
1948
1949 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
1950 }
1951
1952 /**
1953 * Prepare to show the success message and empty form after submit
1954 *
1955 * @since 2.05
1956 */
1957 public static function show_message_after_save( $atts ) {
1958 $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'] );
1959
1960 if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
1961 self::show_form_after_submit( $atts );
1962 } else {
1963 self::show_lone_success_messsage( $atts );
1964 }
1965 }
1966
1967 /**
1968 * Show an empty form
1969 *
1970 * @since 2.05
1971 */
1972 private static function show_form_after_submit( $args ) {
1973 self::fill_atts_for_form_display( $args );
1974
1975 $errors = $args['errors'];
1976 $message = $args['message'];
1977 $form = $args['form'];
1978 $title = $args['title'];
1979 $description = $args['description'];
1980
1981 if ( empty( $args['fields'] ) ) {
1982 $values = array(
1983 'custom_style' => FrmAppHelper::custom_style_value( array() ),
1984 );
1985 } else {
1986 $values = FrmEntriesHelper::setup_new_vars( $args['fields'], $form, $args['reset'] );
1987 }
1988 unset( $args );
1989
1990 $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
1991
1992 $frm_settings = FrmAppHelper::get_settings();
1993 $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
1994
1995 global $frm_vars;
1996 self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
1997
1998 $message_placement = self::message_placement( $form, $message );
1999
2000 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
2001 }
2002
2003 /**
2004 * @return string - 'before', 'after', or 'submit'
2005 *
2006 * @since 4.05.02
2007 */
2008 private static function message_placement( $form, $message ) {
2009 $place = 'before';
2010
2011 if ( $message && isset( $form->options['form_class'] ) ) {
2012 if ( strpos( $form->options['form_class'], 'frm_below_success' ) !== false ) {
2013 $place = 'after';
2014 } elseif ( strpos( $form->options['form_class'], 'frm_inline_success' ) !== false ) {
2015 $place = 'submit';
2016 }
2017 }
2018
2019 /**
2020 * @return string - 'before' or 'after'
2021 *
2022 * @since 4.05.02
2023 */
2024 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
2025 }
2026
2027 /**
2028 * Get all the values needed on the new.php entry page
2029 *
2030 * @since 2.05
2031 */
2032 private static function fill_atts_for_form_display( &$args ) {
2033 $defaults = array(
2034 'errors' => array(),
2035 'message' => '',
2036 'fields' => array(),
2037 'form' => array(),
2038 'title' => true,
2039 'description' => false,
2040 'reset' => false,
2041 );
2042 $args = wp_parse_args( $args, $defaults );
2043 }
2044
2045 /**
2046 * Show the success message without the form
2047 *
2048 * @since 2.05
2049 */
2050 private static function show_lone_success_messsage( $atts ) {
2051 global $frm_vars;
2052 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
2053 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
2054
2055 $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
2056
2057 $errors = array();
2058 $form = $atts['form'];
2059 $message = $atts['message'];
2060
2061 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
2062 }
2063
2064 /**
2065 * Prepare the success message before it's shown
2066 *
2067 * @since 2.05
2068 */
2069 private static function prepare_submit_message( $form, $entry_id ) {
2070 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
2071
2072 if ( $entry_id && is_numeric( $entry_id ) ) {
2073 $message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg;
2074 $class = 'frm_message';
2075 } else {
2076 $message = $frm_settings->failed_msg;
2077 $class = FrmFormsHelper::form_error_class();
2078 }
2079
2080 $message = FrmFormsHelper::get_success_message( compact( 'message', 'form', 'entry_id', 'class' ) );
2081
2082 return apply_filters( 'frm_main_feedback', $message, $form, $entry_id );
2083 }
2084
2085 public static function front_head() {
2086 $version = FrmAppHelper::plugin_version();
2087 $suffix = FrmAppHelper::js_suffix();
2088
2089 if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
2090 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
2091 } else {
2092 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
2093 }
2094
2095 add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
2096
2097 if ( FrmAppHelper::is_admin() ) {
2098 // don't load this in back-end
2099 return;
2100 }
2101
2102 FrmAppHelper::localize_script( 'front' );
2103 FrmStylesController::enqueue_css( 'register' );
2104 }
2105
2106 /**
2107 * @since 3.0
2108 */
2109 public static function has_combo_js_file() {
2110 return is_readable( FrmAppHelper::plugin_path() . '/js/frm.min.js' );
2111 }
2112
2113 public static function maybe_load_css( $form, $this_load, $global_load ) {
2114 $load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load );
2115
2116 if ( ! $load_css ) {
2117 return;
2118 }
2119
2120 global $frm_vars;
2121 self::footer_js( 'header' );
2122 $frm_vars['css_loaded'] = true;
2123
2124 self::load_late_css();
2125 }
2126
2127 /**
2128 * If css is loaded only on applicable pages, include it before the form loads
2129 * to prevent a flash of unstyled form.
2130 *
2131 * @since 4.01
2132 */
2133 private static function load_late_css() {
2134 $frm_settings = FrmAppHelper::get_settings();
2135 $late_css = $frm_settings->load_style === 'dynamic';
2136 if ( ! $late_css ) {
2137 return;
2138 }
2139
2140 global $wp_styles;
2141 if ( is_array( $wp_styles->queue ) && in_array( 'formidable', $wp_styles->queue ) ) {
2142 wp_print_styles( 'formidable' );
2143 }
2144 }
2145
2146 public static function defer_script_loading( $tag, $handle ) {
2147 if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
2148 $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag );
2149 }
2150
2151 return $tag;
2152 }
2153
2154 public static function footer_js( $location = 'footer' ) {
2155 global $frm_vars;
2156
2157 FrmStylesController::enqueue_css();
2158
2159 if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2160 // load formidable js
2161 wp_enqueue_script( 'formidable' );
2162 }
2163 }
2164
2165 /**
2166 * @since 2.0.8
2167 */
2168 private static function maybe_minimize_form( $atts, &$content ) {
2169 // check if minimizing is turned on
2170 if ( self::is_minification_on( $atts ) ) {
2171 $content = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $content );
2172 }
2173 }
2174
2175 /**
2176 * @since 2.0.8
2177 * @return boolean
2178 */
2179 private static function is_minification_on( $atts ) {
2180 return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
2181 }
2182
2183 /**
2184 * @deprecated 4.0
2185 */
2186 public static function new_form( $values = array() ) {
2187 FrmDeprecated::new_form( $values );
2188 }
2189
2190 /**
2191 * @deprecated 4.0
2192 */
2193 public static function create( $values = array() ) {
2194 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
2195 self::update( $values );
2196 }
2197
2198 /**
2199 * @deprecated 1.07.05
2200 * @codeCoverageIgnore
2201 */
2202 public static function add_default_templates( $path, $default = true, $template = true ) {
2203 FrmDeprecated::add_default_templates( $path, $default, $template );
2204 }
2205
2206 /**
2207 * @deprecated 3.0
2208 * @codeCoverageIgnore
2209 */
2210 public static function bulk_create_template( $ids ) {
2211 return FrmDeprecated::bulk_create_template( $ids );
2212 }
2213
2214 /**
2215 * @deprecated 2.03
2216 * @codeCoverageIgnore
2217 */
2218 public static function register_pro_scripts() {
2219 FrmDeprecated::register_pro_scripts();
2220 }
2221
2222 /**
2223 * @deprecated 3.0
2224 * @codeCoverageIgnore
2225 */
2226 public static function edit_key() {
2227 FrmDeprecated::edit_key();
2228 }
2229
2230 /**
2231 * @deprecated 3.0
2232 * @codeCoverageIgnore
2233 */
2234 public static function edit_description() {
2235 FrmDeprecated::edit_description();
2236 }
2237
2238 /**
2239 * @deprecated 4.08
2240 * @since 3.06
2241 */
2242 public static function add_new() {
2243 _deprecated_function( __FUNCTION__, '4.08' );
2244 }
2245 }
2246