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

2,289 lines 65.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class 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
981 /**
982 * Allows modifying the list of fields in the form builder.
983 *
984 * @since 5.0.04
985 *
986 * @param object[] $fields Array of fields.
987 * @param array $args The arguments. Contains `form`.
988 */
989 $values['fields'] = apply_filters( 'frm_fields_in_form_builder', $fields, compact( 'form' ) );
990
991 $edit_message = __( 'Form was successfully updated.', 'formidable' );
992 if ( $form->is_template && $message == $edit_message ) {
993 $message = __( 'Template was successfully updated.', 'formidable' );
994 }
995
996 $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
997 $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] );
998
999 if ( defined( 'DOING_AJAX' ) ) {
1000 wp_die();
1001 } else {
1002 require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
1003 }
1004 }
1005
1006 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1007 FrmAppHelper::permission_check( 'frm_edit_forms' );
1008
1009 global $frm_vars;
1010
1011 if ( ! is_array( $args ) ) {
1012 // For reverse compatibility.
1013 $args = array(
1014 'message' => $args,
1015 );
1016 }
1017
1018 $defaults = array(
1019 'message' => '',
1020 'warnings' => array(),
1021 );
1022 $args = array_merge( $defaults, $args );
1023 $message = $args['message'];
1024 $warnings = $args['warnings'];
1025
1026 $form = FrmForm::getOne( $id );
1027 $fields = FrmField::get_all_for_form( $id );
1028 $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
1029
1030 /**
1031 * Allows changing fields in the form settings.
1032 *
1033 * @since 5.0.04
1034 *
1035 * @param array $fields Array of fields.
1036 * @param array $args The arguments. Contains `form`.
1037 */
1038 $values['fields'] = apply_filters( 'frm_fields_in_settings', $values['fields'], compact( 'form' ) );
1039
1040 self::clean_submit_html( $values );
1041
1042 $sections = self::get_settings_tabs( $values );
1043 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
1044
1045 require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
1046 }
1047
1048 /**
1049 * @since 4.0
1050 */
1051 public static function form_publish_button( $atts ) {
1052 $values = $atts['values'];
1053 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
1054 }
1055
1056 /**
1057 * Get a list of all the settings tabs for the form settings page.
1058 *
1059 * @since 4.0
1060 *
1061 * @param array $values
1062 * @return array
1063 */
1064 private static function get_settings_tabs( $values ) {
1065 $sections = array(
1066 'advanced' => array(
1067 'name' => __( 'General', 'formidable' ),
1068 'title' => __( 'General Form Settings', 'formidable' ),
1069 'function' => array( __CLASS__, 'advanced_settings' ),
1070 'icon' => 'frm_icon_font frm_settings_icon',
1071 ),
1072 'email' => array(
1073 'name' => __( 'Actions & Notifications', 'formidable' ),
1074 'function' => array( 'FrmFormActionsController', 'email_settings' ),
1075 'id' => 'frm_notification_settings',
1076 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1077 ),
1078 'permissions' => array(
1079 'name' => __( 'Form Permissions', 'formidable' ),
1080 'icon' => 'frm_icon_font frm_lock_icon',
1081 'html_class' => 'frm_show_upgrade frm_noallow',
1082 'data' => array(
1083 'medium' => 'permissions',
1084 'upgrade' => __( 'Form Permissions', 'formidable' ),
1085 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1086 ),
1087 ),
1088 'scheduling' => array(
1089 'name' => __( 'Form Scheduling', 'formidable' ),
1090 'icon' => 'frm_icon_font frm_calendar_icon',
1091 'html_class' => 'frm_show_upgrade frm_noallow',
1092 'data' => array(
1093 'medium' => 'scheduling',
1094 'upgrade' => __( 'Form scheduling settings', 'formidable' ),
1095 ),
1096 ),
1097 'buttons' => array(
1098 'name' => __( 'Styling & Buttons', 'formidable' ),
1099 'class' => __CLASS__,
1100 'function' => 'buttons_settings',
1101 'icon' => 'frm_icon_font frm_pallet_icon',
1102 ),
1103 'html' => array(
1104 'name' => __( 'Customize HTML', 'formidable' ),
1105 'class' => __CLASS__,
1106 'function' => 'html_settings',
1107 'icon' => 'frm_icon_font frm_code_icon',
1108 ),
1109 );
1110
1111 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1112
1113 if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
1114 // Prevent settings from showing in 2 spots.
1115 unset( $sections['permissions'], $sections['scheduling'] );
1116 }
1117
1118 foreach ( $sections as $key => $section ) {
1119 $defaults = array(
1120 'html_class' => '',
1121 'name' => ucfirst( $key ),
1122 'icon' => 'frm_icon_font frm_settings_icon',
1123 );
1124
1125 $section = array_merge( $defaults, $section );
1126
1127 if ( ! isset( $section['anchor'] ) ) {
1128 $section['anchor'] = $key;
1129 }
1130 $section['anchor'] .= '_settings';
1131
1132 if ( ! isset( $section['title'] ) ) {
1133 $section['title'] = $section['name'];
1134 }
1135
1136 if ( ! isset( $section['id'] ) ) {
1137 $section['id'] = $section['anchor'];
1138 }
1139
1140 $sections[ $key ] = $section;
1141 }
1142
1143 return $sections;
1144 }
1145
1146 /**
1147 * @since 4.0
1148 *
1149 * @param array $values
1150 */
1151 public static function advanced_settings( $values ) {
1152 $first_h3 = 'frm_first_h3';
1153
1154 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-advanced.php';
1155 }
1156
1157 /**
1158 * @param array $values
1159 */
1160 private static function render_spam_settings( $values ) {
1161 if ( function_exists( 'akismet_http_post' ) ) {
1162 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1163 }
1164 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/honeypot.php';
1165 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/antispam.php';
1166 }
1167
1168 /**
1169 * @since 4.0
1170 *
1171 * @param array $values
1172 */
1173 public static function buttons_settings( $values ) {
1174 $styles = apply_filters( 'frm_get_style_opts', array() );
1175
1176 $frm_settings = FrmAppHelper::get_settings();
1177 $no_global_style = $frm_settings->load_style === 'none';
1178
1179 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' );
1180 }
1181
1182 /**
1183 * @since 4.0
1184 *
1185 * @param array $values
1186 */
1187 public static function html_settings( $values ) {
1188 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1189 }
1190
1191 /**
1192 * Replace old Submit Button href with new href to avoid errors in Chrome
1193 *
1194 * @since 2.03.08
1195 *
1196 * @param array|boolean $values
1197 */
1198 private static function clean_submit_html( &$values ) {
1199 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1200 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
1201 }
1202 }
1203
1204 public static function mb_tags_box( $form_id, $class = '' ) {
1205 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1206
1207 /**
1208 * Allows modifying the list of fields in the tags box.
1209 *
1210 * @since 5.0.04
1211 *
1212 * @param array $fields The list of fields.
1213 * @param array $args The arguments. Contains `form_id`.
1214 */
1215 $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1216 $linked_forms = array();
1217 $col = 'one';
1218 $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1219
1220 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1221 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1222
1223 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1224
1225 include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1226 }
1227
1228 /**
1229 * @since 3.04.01
1230 */
1231 private static function advanced_helpers( $atts ) {
1232 $advanced_helpers = array(
1233 'default' => array(
1234 'heading' => __( 'Customize field values with the following parameters.', 'formidable' ),
1235 'codes' => self::get_advanced_shortcodes(),
1236 ),
1237 );
1238
1239 $user_fields = self::user_shortcodes();
1240 if ( ! empty( $user_fields ) ) {
1241 $user_helpers = array();
1242 foreach ( $user_fields as $uk => $uf ) {
1243 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1244 unset( $uk, $uf );
1245 }
1246
1247 $advanced_helpers['user_id'] = array(
1248 'codes' => $user_helpers,
1249 );
1250 }
1251
1252 /**
1253 * Add extra helper shortcodes on the Advanced tab in form settings and views
1254 *
1255 * @since 3.04.01
1256 *
1257 * @param array $atts - Includes fields and form_id
1258 */
1259 return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
1260 }
1261
1262 /**
1263 * Get an array of the options to display in the advanced tab
1264 * of the customization panel
1265 *
1266 * @since 2.0.6
1267 */
1268 private static function get_advanced_shortcodes() {
1269 $adv_shortcodes = array(
1270 'x sep=", "' => array(
1271 'label' => __( 'Separator', 'formidable' ),
1272 'title' => __( 'Use a different separator for checkbox fields', 'formidable' ),
1273 ),
1274 'x format="d-m-Y"' => array(
1275 'label' => __( 'Date Format', 'formidable' ),
1276 ),
1277 'x show="field_label"' => array(
1278 'label' => __( 'Field Label', 'formidable' ),
1279 ),
1280 'x wpautop=0' => array(
1281 'label' => __( 'No Auto P', 'formidable' ),
1282 'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
1283 ),
1284 );
1285 $adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1286
1287 // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
1288
1289 return $adv_shortcodes;
1290 }
1291
1292 /**
1293 * @since 3.04.01
1294 */
1295 private static function user_shortcodes() {
1296 $options = array(
1297 'ID' => __( 'User ID', 'formidable' ),
1298 'first_name' => __( 'First Name', 'formidable' ),
1299 'last_name' => __( 'Last Name', 'formidable' ),
1300 'display_name' => __( 'Display Name', 'formidable' ),
1301 'user_login' => __( 'User Login', 'formidable' ),
1302 'user_email' => __( 'Email', 'formidable' ),
1303 'avatar' => __( 'Avatar', 'formidable' ),
1304 'author_link' => __( 'Author Link', 'formidable' ),
1305 );
1306
1307 return apply_filters( 'frm_user_shortcodes', $options );
1308 }
1309
1310 /**
1311 * Get an array of the helper shortcodes to display in the customization panel
1312 *
1313 * @since 2.0.6
1314 */
1315 private static function get_shortcode_helpers( $settings_tab ) {
1316 $entry_shortcodes = array(
1317 'id' => __( 'Entry ID', 'formidable' ),
1318 'key' => __( 'Entry Key', 'formidable' ),
1319 'post_id' => __( 'Post ID', 'formidable' ),
1320 'ip' => __( 'User IP', 'formidable' ),
1321 'created-at' => __( 'Entry created', 'formidable' ),
1322 'updated-at' => __( 'Entry updated', 'formidable' ),
1323 '' => '',
1324 'siteurl' => __( 'Site URL', 'formidable' ),
1325 'sitename' => __( 'Site Name', 'formidable' ),
1326 );
1327
1328 if ( ! FrmAppHelper::pro_is_installed() ) {
1329 unset( $entry_shortcodes['post_id'] );
1330 }
1331
1332 if ( $settings_tab ) {
1333 $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
1334 $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
1335 $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
1336 }
1337
1338 /**
1339 * Use this hook to add or remove buttons in the helpers section
1340 * in the customization panel
1341 *
1342 * @since 2.0.6
1343 */
1344 $entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
1345
1346 return $entry_shortcodes;
1347 }
1348
1349 /**
1350 * Insert the form class setting into the form
1351 */
1352 public static function form_classes( $form ) {
1353 if ( isset( $form->options['form_class'] ) ) {
1354 echo esc_attr( sanitize_text_field( $form->options['form_class'] ) );
1355 }
1356
1357 if ( ! empty( $form->options['js_validate'] ) ) {
1358 echo ' frm_js_validate ';
1359 self::add_js_validate_form_to_global_vars( $form );
1360 }
1361 }
1362
1363 /**
1364 * @since 5.0.03
1365 *
1366 * @param stdClass $form
1367 */
1368 public static function add_js_validate_form_to_global_vars( $form ) {
1369 global $frm_vars;
1370 if ( ! isset( $frm_vars['js_validate_forms'] ) ) {
1371 $frm_vars['js_validate_forms'] = array();
1372 }
1373 $frm_vars['js_validate_forms'][ $form->id ] = $form;
1374 }
1375
1376 public static function get_email_html() {
1377 FrmAppHelper::permission_check( 'frm_view_forms' );
1378 check_ajax_referer( 'frm_ajax', 'nonce' );
1379
1380 echo FrmEntriesController::show_entry_shortcode( // WPCS: XSS ok.
1381 array(
1382 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1383 'default_email' => true,
1384 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1385 )
1386 );
1387 wp_die();
1388 }
1389
1390 public static function filter_content( $content, $form, $entry = false ) {
1391 self::get_entry_by_param( $entry );
1392 if ( ! $entry ) {
1393 return $content;
1394 }
1395
1396 if ( is_object( $form ) ) {
1397 $form = $form->id;
1398 }
1399
1400 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1401 $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1402
1403 return $content;
1404 }
1405
1406 private static function get_entry_by_param( &$entry ) {
1407 if ( ! $entry || ! is_object( $entry ) ) {
1408 if ( ! $entry || ! is_numeric( $entry ) ) {
1409 $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
1410 }
1411
1412 FrmEntry::maybe_get_entry( $entry );
1413 }
1414 }
1415
1416 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1417 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1418 }
1419
1420 public static function process_bulk_form_actions( $errors ) {
1421 if ( ! $_REQUEST ) {
1422 return $errors;
1423 }
1424
1425 $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1426 if ( $bulkaction == - 1 ) {
1427 $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1428 }
1429
1430 if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
1431 FrmAppHelper::remove_get_action();
1432
1433 $bulkaction = str_replace( 'bulk_', '', $bulkaction );
1434 }
1435
1436 $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
1437 if ( empty( $ids ) ) {
1438 $errors[] = __( 'No forms were specified', 'formidable' );
1439
1440 return $errors;
1441 }
1442
1443 $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
1444 if ( $permission_error !== false ) {
1445 $errors[] = $permission_error;
1446
1447 return $errors;
1448 }
1449
1450 if ( ! is_array( $ids ) ) {
1451 $ids = explode( ',', $ids );
1452 }
1453
1454 switch ( $bulkaction ) {
1455 case 'delete':
1456 $message = self::bulk_destroy( $ids );
1457 break;
1458 case 'trash':
1459 $message = self::bulk_trash( $ids );
1460 break;
1461 case 'untrash':
1462 $message = self::bulk_untrash( $ids );
1463 }
1464
1465 if ( isset( $message ) && ! empty( $message ) ) {
1466 $errors['message'] = $message;
1467 }
1468
1469 return $errors;
1470 }
1471
1472 public static function route() {
1473 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1474 $vars = array();
1475 FrmAppHelper::include_svg();
1476
1477 if ( isset( $_POST['frm_compact_fields'] ) ) {
1478 FrmAppHelper::permission_check( 'frm_edit_forms' );
1479
1480 // Javascript needs to be allowed in some field settings.
1481 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1482 $json_vars = htmlspecialchars_decode( nl2br( str_replace( '&quot;', '"', wp_unslash( $_POST['frm_compact_fields'] ) ) ) );
1483 $json_vars = json_decode( $json_vars, true );
1484 if ( empty( $json_vars ) ) {
1485 // json decoding failed so we should return an error message.
1486 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1487 if ( 'edit' == $action ) {
1488 $action = 'update';
1489 }
1490
1491 add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1492 } else {
1493 $vars = FrmAppHelper::json_to_array( $json_vars );
1494 $action = $vars[ $action ];
1495 unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] );
1496 $_REQUEST = array_merge( $_REQUEST, $vars );
1497 $_POST = array_merge( $_POST, $_REQUEST );
1498 }
1499 } else {
1500 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1501 if ( isset( $_REQUEST['delete_all'] ) ) {
1502 // Override the action for this page.
1503 $action = 'delete_all';
1504 }
1505 }
1506
1507 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1508 FrmAppHelper::trigger_hook_load( 'form' );
1509
1510 switch ( $action ) {
1511 case 'new':
1512 return self::new_form( $vars );
1513 case 'create':
1514 case 'edit':
1515 case 'update':
1516 case 'duplicate':
1517 case 'trash':
1518 case 'untrash':
1519 case 'destroy':
1520 case 'delete_all':
1521 case 'settings':
1522 case 'update_settings':
1523 return self::$action( $vars );
1524 case 'lite-reports':
1525 return self::no_reports( $vars );
1526 case 'views':
1527 return self::no_views( $vars );
1528 default:
1529 do_action( 'frm_form_action_' . $action );
1530 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1531 return;
1532 }
1533
1534 $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1535 if ( $action == - 1 ) {
1536 $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1537 }
1538
1539 if ( strpos( $action, 'bulk_' ) === 0 ) {
1540 FrmAppHelper::remove_get_action();
1541
1542 return self::list_form();
1543 }
1544
1545 return self::display_forms_list();
1546 }
1547 }
1548
1549 public static function json_error( $errors ) {
1550 $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1551
1552 return $errors;
1553 }
1554
1555 /**
1556 * Education for premium features.
1557 *
1558 * @since 4.05
1559 */
1560 public static function add_form_style_tab_options() {
1561 include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' );
1562 }
1563
1564 /**
1565 * Add education about views.
1566 *
1567 * @since 4.07
1568 */
1569 public static function no_views( $values = array() ) {
1570 FrmAppHelper::include_svg();
1571 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1572 $form = $id ? FrmForm::getOne( $id ) : false;
1573
1574 include FrmAppHelper::plugin_path() . '/classes/views/shared/views-info.php';
1575 }
1576
1577 /**
1578 * Add education about reports.
1579 *
1580 * @since 4.07
1581 */
1582 public static function no_reports( $values = array() ) {
1583 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1584 $form = $id ? FrmForm::getOne( $id ) : false;
1585
1586 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
1587 }
1588
1589 /* FRONT-END FORMS */
1590 public static function admin_bar_css() {
1591 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1592 return;
1593 }
1594
1595 self::move_menu_to_footer();
1596
1597 add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
1598 FrmAppHelper::load_font_style();
1599 }
1600
1601 /**
1602 * @since 4.05.02
1603 */
1604 private static function move_menu_to_footer() {
1605 $settings = FrmAppHelper::get_settings();
1606 if ( empty( $settings->admin_bar ) ) {
1607 remove_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
1608 }
1609 }
1610
1611 public static function admin_bar_configure() {
1612 global $frm_vars;
1613 if ( empty( $frm_vars['forms_loaded'] ) ) {
1614 return;
1615 }
1616
1617 $actions = array();
1618 foreach ( $frm_vars['forms_loaded'] as $form ) {
1619 if ( is_object( $form ) ) {
1620 $actions[ $form->id ] = $form->name;
1621 }
1622 unset( $form );
1623 }
1624
1625 if ( empty( $actions ) ) {
1626 return;
1627 }
1628
1629 self::add_menu_to_admin_bar();
1630 self::add_forms_to_admin_bar( $actions );
1631 }
1632
1633 /**
1634 * @since 2.05.07
1635 */
1636 public static function add_menu_to_admin_bar() {
1637 global $wp_admin_bar;
1638
1639 $wp_admin_bar->add_node(
1640 array(
1641 'id' => 'frm-forms',
1642 'title' => '<span class="ab-icon"></span><span class="ab-label">' . FrmAppHelper::get_menu_name() . '</span>',
1643 'href' => admin_url( 'admin.php?page=formidable' ),
1644 'meta' => array(
1645 'title' => FrmAppHelper::get_menu_name(),
1646 ),
1647 )
1648 );
1649 }
1650
1651 /**
1652 * @since 2.05.07
1653 */
1654 private static function add_forms_to_admin_bar( $actions ) {
1655 global $wp_admin_bar;
1656
1657 asort( $actions );
1658
1659 foreach ( $actions as $form_id => $name ) {
1660
1661 $wp_admin_bar->add_node(
1662 array(
1663 'parent' => 'frm-forms',
1664 'id' => 'edit_form_' . $form_id,
1665 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
1666 'href' => FrmForm::get_edit_link( $form_id ),
1667 )
1668 );
1669 }
1670 }
1671
1672 /**
1673 * The formidable shortcode
1674 *
1675 * @param array $atts The params from the shortcode.
1676 */
1677 public static function get_form_shortcode( $atts ) {
1678 global $frm_vars;
1679 if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1680 $sc = '[formidable';
1681 $sc .= FrmAppHelper::array_to_html_params( $atts );
1682 return $sc . ']';
1683 }
1684
1685 $shortcode_atts = shortcode_atts(
1686 array(
1687 'id' => '',
1688 'key' => '',
1689 'title' => false,
1690 'description' => false,
1691 'readonly' => false,
1692 'entry_id' => false,
1693 'fields' => array(),
1694 'exclude_fields' => array(),
1695 'minimize' => false,
1696 ),
1697 $atts
1698 );
1699 do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts );
1700
1701 return self::show_form( $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], $shortcode_atts['description'], $atts );
1702 }
1703
1704 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
1705 if ( empty( $id ) ) {
1706 $id = $key;
1707 }
1708
1709 $form = self::maybe_get_form_to_show( $id );
1710 if ( ! $form ) {
1711 return __( 'Please select a valid form', 'formidable' );
1712 }
1713
1714 FrmAppController::maybe_update_styles();
1715
1716 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1717 FrmAppHelper::trigger_hook_load( 'form', $form );
1718
1719 $form = apply_filters( 'frm_pre_display_form', $form );
1720
1721 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
1722
1723 if ( self::is_viewable_draft_form( $form ) ) {
1724 // don't show a draft form on a page
1725 $form = __( 'Please select a valid form', 'formidable' );
1726 } elseif ( ! FrmForm::is_visible_to_user( $form ) ) {
1727 $form = do_shortcode( $frm_settings->login_msg );
1728 } else {
1729 do_action( 'frm_pre_get_form', $form );
1730 $form = self::get_form( $form, $title, $description, $atts );
1731
1732 /**
1733 * Use this shortcode to check for external shortcodes that may span
1734 * across multiple fields in the customizable HTML
1735 *
1736 * @since 2.0.8
1737 */
1738 $form = apply_filters( 'frm_filter_final_form', $form );
1739 }
1740
1741 return $form;
1742 }
1743
1744 private static function maybe_get_form_to_show( $id ) {
1745 $form = false;
1746
1747 if ( ! empty( $id ) ) { // no form id or key set
1748 $form = FrmForm::getOne( $id );
1749 if ( ! $form || $form->parent_form_id || $form->status == 'trash' ) {
1750 $form = false;
1751 }
1752 }
1753
1754 return $form;
1755 }
1756
1757 private static function is_viewable_draft_form( $form ) {
1758 return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
1759 }
1760
1761 public static function get_form( $form, $title, $description, $atts = array() ) {
1762 ob_start();
1763
1764 do_action( 'frm_before_get_form', $atts );
1765
1766 self::get_form_contents( $form, $title, $description, $atts );
1767 self::enqueue_scripts( FrmForm::get_params( $form ) );
1768
1769 $contents = ob_get_contents();
1770 ob_end_clean();
1771
1772 self::maybe_minimize_form( $atts, $contents );
1773
1774 return $contents;
1775 }
1776
1777 public static function enqueue_scripts( $params ) {
1778 do_action( 'frm_enqueue_form_scripts', $params );
1779 }
1780
1781 public static function get_form_contents( $form, $title, $description, $atts ) {
1782 $params = FrmForm::get_params( $form );
1783 $errors = self::get_saved_errors( $form, $params );
1784 $fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
1785 $reset = false;
1786 $pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
1787
1788 $handle_process_here = $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST;
1789
1790 if ( ! $handle_process_here ) {
1791 do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
1792 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
1793 self::show_form_after_submit( $pass_args );
1794 }
1795 } elseif ( ! empty( $errors ) ) {
1796 self::show_form_after_submit( $pass_args );
1797
1798 } else {
1799
1800 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
1801
1802 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
1803 $entry_id = self::just_created_entry( $form->id );
1804 $pass_args['entry_id'] = $entry_id;
1805 $pass_args['reset'] = true;
1806 $pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
1807
1808 self::run_success_action( $pass_args );
1809
1810 do_action(
1811 'frm_after_entry_processed',
1812 array(
1813 'entry_id' => $entry_id,
1814 'form' => $form,
1815 )
1816 );
1817 }
1818 }
1819 }
1820
1821 /**
1822 * If the form was processed earlier (init), get the generated errors
1823 *
1824 * @since 2.05
1825 */
1826 private static function get_saved_errors( $form, $params ) {
1827 global $frm_vars;
1828
1829 if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) {
1830 $errors = $frm_vars['created_entries'][ $form->id ]['errors'];
1831 } else {
1832 $errors = array();
1833 }
1834
1835 return $errors;
1836 }
1837
1838 /**
1839 * @since 2.2.7
1840 */
1841 public static function just_created_entry( $form_id ) {
1842 global $frm_vars;
1843
1844 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;
1845 }
1846
1847 /**
1848 * @since 3.0
1849 */
1850 private static function get_confirmation_method( $atts ) {
1851 $opt = 'success_action';
1852 $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
1853 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
1854
1855 if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
1856 $method = 'message';
1857 }
1858
1859 return $method;
1860 }
1861
1862 public static function maybe_trigger_redirect( $form, $params, $args ) {
1863 if ( ! isset( $params['id'] ) ) {
1864 global $frm_vars;
1865 $params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id'];
1866 }
1867
1868 $conf_method = self::get_confirmation_method(
1869 array(
1870 'form' => $form,
1871 'entry_id' => $params['id'],
1872 )
1873 );
1874
1875 if ( 'redirect' === $conf_method ) {
1876 self::trigger_redirect( $form, $params, $args );
1877 }
1878 }
1879
1880 public static function trigger_redirect( $form, $params, $args ) {
1881 $success_args = array(
1882 'action' => $params['action'],
1883 'conf_method' => 'redirect',
1884 'form' => $form,
1885 'entry_id' => $params['id'],
1886 );
1887
1888 if ( isset( $args['ajax'] ) ) {
1889 $success_args['ajax'] = $args['ajax'];
1890 }
1891
1892 self::run_success_action( $success_args );
1893 }
1894
1895 /**
1896 * Used when the success action is not 'message'
1897 *
1898 * @since 2.05
1899 */
1900 public static function run_success_action( $args ) {
1901 $extra_args = $args;
1902 unset( $extra_args['form'] );
1903
1904 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
1905
1906 $opt = ( ! isset( $args['action'] ) || $args['action'] == 'create' ) ? 'success' : 'edit';
1907
1908 $args['success_opt'] = $opt;
1909 if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[ $opt . '_page_id' ] ) ) {
1910 self::load_page_after_submit( $args );
1911 } elseif ( $args['conf_method'] == 'redirect' ) {
1912 self::redirect_after_submit( $args );
1913 } else {
1914 self::show_message_after_save( $args );
1915 }
1916 }
1917
1918 /**
1919 * @since 3.0
1920 */
1921 private static function load_page_after_submit( $args ) {
1922 global $post;
1923 $opt = $args['success_opt'];
1924 if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
1925 $page = get_post( $args['form']->options[ $opt . '_page_id' ] );
1926 $old_post = $post;
1927 $post = $page;
1928 $content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] );
1929 echo apply_filters( 'the_content', $content ); // WPCS: XSS ok.
1930 $post = $old_post;
1931 }
1932 }
1933
1934 /**
1935 * @since 3.0
1936 */
1937 private static function redirect_after_submit( $args ) {
1938 global $frm_vars;
1939
1940 add_filter( 'frm_use_wpautop', '__return_false' );
1941
1942 $opt = $args['success_opt'];
1943 $success_url = trim( $args['form']->options[ $opt . '_url' ] );
1944 $success_url = apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] );
1945 $success_url = do_shortcode( $success_url );
1946
1947 $success_msg = isset( $args['form']->options[ $opt . '_msg' ] ) ? $args['form']->options[ $opt . '_msg' ] : __( 'Please wait while you are redirected.', 'formidable' );
1948
1949 $redirect_msg = self::get_redirect_message( $success_url, $success_msg, $args );
1950
1951 $args['id'] = $args['entry_id'];
1952 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
1953
1954 add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
1955 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
1956
1957 $doing_ajax = FrmAppHelper::doing_ajax();
1958
1959 if ( isset( $args['ajax'] ) && $args['ajax'] && $doing_ajax ) {
1960 echo json_encode( array( 'redirect' => $success_url ) );
1961 wp_die();
1962 } elseif ( ! headers_sent() ) {
1963 wp_redirect( esc_url_raw( $success_url ) );
1964 die(); // do not use wp_die or redirect fails
1965 } else {
1966 add_filter( 'frm_use_wpautop', '__return_true' );
1967
1968 echo $redirect_msg; // WPCS: XSS ok.
1969 echo "<script type='text/javascript'>window.onload = function(){setTimeout(window.location='" . esc_url_raw( $success_url ) . "', 8000);}</script>";
1970 }
1971 }
1972
1973 /**
1974 * @since 3.0
1975 *
1976 * @param string $success_url
1977 * @param string $success_msg
1978 * @param array $args
1979 */
1980 private static function get_redirect_message( $success_url, $success_msg, $args ) {
1981 $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/>' .
1982 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1983 sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
1984 '</div></div>';
1985
1986 $redirect_args = array(
1987 'entry_id' => $args['entry_id'],
1988 'form_id' => $args['form']->id,
1989 'form' => $args['form'],
1990 );
1991
1992 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
1993 }
1994
1995 /**
1996 * Prepare to show the success message and empty form after submit
1997 *
1998 * @since 2.05
1999 */
2000 public static function show_message_after_save( $atts ) {
2001 $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'] );
2002
2003 if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
2004 self::show_form_after_submit( $atts );
2005 } else {
2006 self::show_lone_success_messsage( $atts );
2007 }
2008 }
2009
2010 /**
2011 * Show an empty form
2012 *
2013 * @since 2.05
2014 */
2015 private static function show_form_after_submit( $args ) {
2016 self::fill_atts_for_form_display( $args );
2017
2018 $errors = $args['errors'];
2019 $message = $args['message'];
2020 $form = $args['form'];
2021 $title = $args['title'];
2022 $description = $args['description'];
2023
2024 if ( empty( $args['fields'] ) ) {
2025 $values = array(
2026 'custom_style' => FrmAppHelper::custom_style_value( array() ),
2027 );
2028 } else {
2029 $values = FrmEntriesHelper::setup_new_vars( $args['fields'], $form, $args['reset'] );
2030 }
2031 unset( $args );
2032
2033 $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
2034
2035 $frm_settings = FrmAppHelper::get_settings();
2036 $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
2037
2038 global $frm_vars;
2039 self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
2040
2041 $message_placement = self::message_placement( $form, $message );
2042
2043 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
2044 }
2045
2046 /**
2047 * @return string - 'before', 'after', or 'submit'
2048 *
2049 * @since 4.05.02
2050 */
2051 private static function message_placement( $form, $message ) {
2052 $place = 'before';
2053
2054 if ( $message && isset( $form->options['form_class'] ) ) {
2055 if ( strpos( $form->options['form_class'], 'frm_below_success' ) !== false ) {
2056 $place = 'after';
2057 } elseif ( strpos( $form->options['form_class'], 'frm_inline_success' ) !== false ) {
2058 $place = 'submit';
2059 }
2060 }
2061
2062 /**
2063 * @return string - 'before' or 'after'
2064 *
2065 * @since 4.05.02
2066 */
2067 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
2068 }
2069
2070 /**
2071 * Get all the values needed on the new.php entry page
2072 *
2073 * @since 2.05
2074 */
2075 private static function fill_atts_for_form_display( &$args ) {
2076 $defaults = array(
2077 'errors' => array(),
2078 'message' => '',
2079 'fields' => array(),
2080 'form' => array(),
2081 'title' => true,
2082 'description' => false,
2083 'reset' => false,
2084 );
2085 $args = wp_parse_args( $args, $defaults );
2086 }
2087
2088 /**
2089 * Show the success message without the form
2090 *
2091 * @since 2.05
2092 */
2093 private static function show_lone_success_messsage( $atts ) {
2094 global $frm_vars;
2095 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
2096 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
2097
2098 $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
2099
2100 $errors = array();
2101 $form = $atts['form'];
2102 $message = $atts['message'];
2103
2104 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
2105 }
2106
2107 /**
2108 * Prepare the success message before it's shown
2109 *
2110 * @since 2.05
2111 */
2112 private static function prepare_submit_message( $form, $entry_id ) {
2113 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
2114
2115 if ( $entry_id && is_numeric( $entry_id ) ) {
2116 $message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg;
2117 $class = 'frm_message';
2118 } else {
2119 $message = $frm_settings->failed_msg;
2120 $class = FrmFormsHelper::form_error_class();
2121 }
2122
2123 $message = FrmFormsHelper::get_success_message( compact( 'message', 'form', 'entry_id', 'class' ) );
2124
2125 return apply_filters( 'frm_main_feedback', $message, $form, $entry_id );
2126 }
2127
2128 public static function front_head() {
2129 $version = FrmAppHelper::plugin_version();
2130 $suffix = FrmAppHelper::js_suffix();
2131
2132 if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
2133 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
2134 } else {
2135 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
2136 }
2137
2138 add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
2139
2140 if ( FrmAppHelper::is_admin() ) {
2141 // don't load this in back-end
2142 return;
2143 }
2144
2145 FrmAppHelper::localize_script( 'front' );
2146 FrmStylesController::enqueue_css( 'register' );
2147 }
2148
2149 /**
2150 * @since 3.0
2151 */
2152 public static function has_combo_js_file() {
2153 return is_readable( FrmAppHelper::plugin_path() . '/js/frm.min.js' );
2154 }
2155
2156 public static function maybe_load_css( $form, $this_load, $global_load ) {
2157 $load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load );
2158
2159 if ( ! $load_css ) {
2160 return;
2161 }
2162
2163 global $frm_vars;
2164 self::footer_js( 'header' );
2165 $frm_vars['css_loaded'] = true;
2166
2167 self::load_late_css();
2168 }
2169
2170 /**
2171 * If css is loaded only on applicable pages, include it before the form loads
2172 * to prevent a flash of unstyled form.
2173 *
2174 * @since 4.01
2175 */
2176 private static function load_late_css() {
2177 $frm_settings = FrmAppHelper::get_settings();
2178 $late_css = $frm_settings->load_style === 'dynamic';
2179 if ( ! $late_css ) {
2180 return;
2181 }
2182
2183 global $wp_styles;
2184 if ( is_array( $wp_styles->queue ) && in_array( 'formidable', $wp_styles->queue ) ) {
2185 wp_print_styles( 'formidable' );
2186 }
2187 }
2188
2189 public static function defer_script_loading( $tag, $handle ) {
2190 if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
2191 $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag );
2192 }
2193
2194 return $tag;
2195 }
2196
2197 public static function footer_js( $location = 'footer' ) {
2198 global $frm_vars;
2199
2200 FrmStylesController::enqueue_css();
2201
2202 if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2203 // load formidable js
2204 wp_enqueue_script( 'formidable' );
2205 }
2206 }
2207
2208 /**
2209 * @since 2.0.8
2210 */
2211 private static function maybe_minimize_form( $atts, &$content ) {
2212 // check if minimizing is turned on
2213 if ( self::is_minification_on( $atts ) ) {
2214 $content = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $content );
2215 }
2216 }
2217
2218 /**
2219 * @since 2.0.8
2220 * @return boolean
2221 */
2222 private static function is_minification_on( $atts ) {
2223 return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
2224 }
2225
2226 /**
2227 * @deprecated 4.0
2228 */
2229 public static function new_form( $values = array() ) {
2230 FrmDeprecated::new_form( $values );
2231 }
2232
2233 /**
2234 * @deprecated 4.0
2235 */
2236 public static function create( $values = array() ) {
2237 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
2238 self::update( $values );
2239 }
2240
2241 /**
2242 * @deprecated 1.07.05
2243 * @codeCoverageIgnore
2244 */
2245 public static function add_default_templates( $path, $default = true, $template = true ) {
2246 FrmDeprecated::add_default_templates( $path, $default, $template );
2247 }
2248
2249 /**
2250 * @deprecated 3.0
2251 * @codeCoverageIgnore
2252 */
2253 public static function bulk_create_template( $ids ) {
2254 return FrmDeprecated::bulk_create_template( $ids );
2255 }
2256
2257 /**
2258 * @deprecated 2.03
2259 * @codeCoverageIgnore
2260 */
2261 public static function register_pro_scripts() {
2262 FrmDeprecated::register_pro_scripts();
2263 }
2264
2265 /**
2266 * @deprecated 3.0
2267 * @codeCoverageIgnore
2268 */
2269 public static function edit_key() {
2270 FrmDeprecated::edit_key();
2271 }
2272
2273 /**
2274 * @deprecated 3.0
2275 * @codeCoverageIgnore
2276 */
2277 public static function edit_description() {
2278 FrmDeprecated::edit_description();
2279 }
2280
2281 /**
2282 * @deprecated 4.08
2283 * @since 3.06
2284 */
2285 public static function add_new() {
2286 _deprecated_function( __FUNCTION__, '4.08' );
2287 }
2288 }
2289