PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.09.08
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.09.08
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / controllers / FrmFormsController.php

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

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