| @@ -4,8 +4,18 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmFormsController { |
| 7 | 7 | |
| 8 | + /** | |
| 9 | + * Track the form that opened the redirect URL in a new tab. This is used to check if we should show the default | |
| 10 | + * message in the currect tab. | |
| 11 | + * | |
| 12 | + * @since 6.2 | |
| 13 | + * | |
| 14 | + * @var array Keys are form IDs and values are 1. | |
| 15 | + */ | |
| 16 | + private static $redirected_in_new_tab = array(); | |
| 17 | + | |
| 8 | 18 | public static function menu() { |
| 9 | 19 | $menu_label = __( 'Forms', 'formidable' ); |
| 10 | 20 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 11 | 21 | $menu_label .= ' (Lite)'; |
| @@ -272,9 +282,10 @@ | ||
| 272 | 282 | $url = admin_url( 'admin.php?page=formidable' ); |
| 273 | 283 | $message = 'form_duplicate_error'; |
| 274 | 284 | |
| 275 | 285 | if ( $form ) { |
| 276 | - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) ); | |
| 286 | + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : ''; | |
| 287 | + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template ); | |
| 277 | 288 | $message = 'form_duplicated'; |
| 278 | 289 | } |
| 279 | 290 | |
| 280 | 291 | $url .= '&message=' . $message; |
| @@ -387,13 +398,29 @@ | ||
| 387 | 398 | add_filter( 'is_active_sidebar', '__return_false' ); |
| 388 | 399 | FrmStylesController::enqueue_css( 'enqueue', true ); |
| 389 | 400 | |
| 390 | 401 | if ( false === get_template_part( 'page' ) ) { |
| 402 | + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { | |
| 403 | + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' ); | |
| 404 | + } | |
| 391 | 405 | self::fallback_when_page_template_part_is_not_supported_by_theme(); |
| 392 | 406 | } |
| 393 | 407 | } |
| 394 | 408 | |
| 395 | 409 | /** |
| 410 | + * Add padding to the body for block themes. | |
| 411 | + * | |
| 412 | + * @since 6.5.2 | |
| 413 | + * | |
| 414 | + * @param array $classes The body classes list. | |
| 415 | + * @return array | |
| 416 | + */ | |
| 417 | + public static function preview_block_theme_body_classnames( $classes ) { | |
| 418 | + $classes[] = 'has-global-padding'; | |
| 419 | + return $classes; | |
| 420 | + } | |
| 421 | + | |
| 422 | + /** | |
| 396 | 423 | * Not every theme supports get_template_part( 'page' ). |
| 397 | 424 | * When this is not supported, false is returned, and we can handle a fallback. |
| 398 | 425 | */ |
| 399 | 426 | private static function fallback_when_page_template_part_is_not_supported_by_theme() { |
| @@ -670,9 +697,9 @@ | ||
| 670 | 697 | self::create_default_on_submit_action( $form_id ); |
| 671 | 698 | self::create_default_email_action( $form_id ); |
| 672 | 699 | |
| 673 | 700 | $response = array( |
| 674 | - 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 701 | + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 675 | 702 | ); |
| 676 | 703 | |
| 677 | 704 | echo wp_json_encode( $response ); |
| 678 | 705 | wp_die(); |
| @@ -678,46 +705,13 @@ | ||
| 678 | 705 | wp_die(); |
| 679 | 706 | } |
| 680 | 707 | |
| 681 | 708 | /** |
| 682 | - * Create a custom template from a form | |
| 683 | - * | |
| 684 | - * @since 3.06 | |
| 685 | - */ | |
| 686 | - public static function build_template() { | |
| 687 | - global $wpdb; | |
| 688 | - | |
| 689 | - FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 690 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 691 | - | |
| 692 | - $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' ); | |
| 693 | - $new_form_id = FrmForm::duplicate( $form_id, 1, true ); | |
| 694 | - if ( ! $new_form_id ) { | |
| 695 | - $response = array( | |
| 696 | - 'message' => __( 'There was an error creating a template.', 'formidable' ), | |
| 697 | - ); | |
| 698 | - } else { | |
| 699 | - $new_values = self::get_modal_values(); | |
| 700 | - $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) ); | |
| 701 | - if ( $query_results ) { | |
| 702 | - FrmForm::clear_form_cache(); | |
| 703 | - } | |
| 704 | - | |
| 705 | - $response = array( | |
| 706 | - 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(), | |
| 707 | - ); | |
| 708 | - } | |
| 709 | - | |
| 710 | - echo wp_json_encode( $response ); | |
| 711 | - wp_die(); | |
| 712 | - } | |
| 713 | - | |
| 714 | - /** | |
| 715 | 709 | * Before creating a new form, get the name and description from the modal. |
| 716 | 710 | * |
| 717 | 711 | * @since 4.0 |
| 718 | 712 | */ |
| 719 | - private static function get_modal_values() { | |
| 713 | + public static function get_modal_values() { | |
| 720 | 714 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 721 | 715 | $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 722 | 716 | |
| 723 | 717 | return array( |
| @@ -879,14 +873,14 @@ | ||
| 879 | 873 | * @return array<string,string> |
| 880 | 874 | */ |
| 881 | 875 | public static function get_columns( $columns ) { |
| 882 | 876 | $columns['cb'] = '<input type="checkbox" />'; |
| 883 | - $columns['name'] = __( 'Form Title', 'formidable' ); | |
| 884 | - $columns['entries'] = __( 'Entries', 'formidable' ); | |
| 877 | + $columns['name'] = esc_html__( 'Form Title', 'formidable' ); | |
| 878 | + $columns['entries'] = esc_html__( 'Entries', 'formidable' ); | |
| 885 | 879 | $columns['id'] = 'ID'; |
| 886 | - $columns['form_key'] = __( 'Key', 'formidable' ); | |
| 887 | - $columns['shortcode'] = __( 'Actions', 'formidable' ); | |
| 888 | - $columns['created_at'] = __( 'Date', 'formidable' ); | |
| 880 | + $columns['form_key'] = esc_html__( 'Key', 'formidable' ); | |
| 881 | + $columns['shortcode'] = esc_html__( 'Actions', 'formidable' ); | |
| 882 | + $columns['created_at'] = esc_html__( 'Date', 'formidable' ); | |
| 889 | 883 | |
| 890 | 884 | add_screen_option( |
| 891 | 885 | 'per_page', |
| 892 | 886 | array( |
| @@ -940,147 +934,43 @@ | ||
| 940 | 934 | |
| 941 | 935 | return $save; |
| 942 | 936 | } |
| 943 | 937 | |
| 944 | - /** | |
| 945 | - * @return bool | |
| 946 | - */ | |
| 947 | - public static function expired() { | |
| 948 | - global $frm_expired; | |
| 949 | - return $frm_expired; | |
| 950 | - } | |
| 938 | + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 939 | + global $frm_vars; | |
| 951 | 940 | |
| 952 | - /** | |
| 953 | - * Get data from api before rendering it so that we can flag the modal as expired | |
| 954 | - * | |
| 955 | - * @return void | |
| 956 | - */ | |
| 957 | - public static function before_list_templates() { | |
| 958 | - global $frm_templates; | |
| 959 | - global $frm_expired; | |
| 960 | - global $frm_license_type; | |
| 961 | - | |
| 962 | - $api = new FrmFormTemplateApi(); | |
| 963 | - $frm_templates = $api->get_api_info(); | |
| 964 | - $expired = false; | |
| 965 | - $license_type = ''; | |
| 966 | - if ( isset( $frm_templates['error'] ) ) { | |
| 967 | - $error = $frm_templates['error']['message']; | |
| 968 | - $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error ); | |
| 969 | - $expired = 'expired' === $frm_templates['error']['code']; | |
| 970 | - $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : ''; | |
| 971 | - unset( $frm_templates['error'] ); | |
| 972 | - } | |
| 973 | - | |
| 974 | - $frm_expired = $expired; | |
| 975 | - $frm_license_type = $license_type; | |
| 976 | - } | |
| 977 | - | |
| 978 | - /** | |
| 979 | - * @return void | |
| 980 | - */ | |
| 981 | - public static function list_templates() { | |
| 982 | - global $frm_templates; | |
| 983 | - global $frm_license_type; | |
| 984 | - | |
| 985 | - $templates = $frm_templates; | |
| 986 | - $custom_templates = array(); | |
| 987 | - $templates_by_category = array(); | |
| 988 | - | |
| 989 | - self::add_user_templates( $custom_templates ); | |
| 990 | - | |
| 991 | - foreach ( $templates as $template ) { | |
| 992 | - if ( ! isset( $template['categories'] ) ) { | |
| 993 | - continue; | |
| 994 | - } | |
| 995 | - | |
| 996 | - foreach ( $template['categories'] as $category ) { | |
| 997 | - if ( ! isset( $templates_by_category[ $category ] ) ) { | |
| 998 | - $templates_by_category[ $category ] = array(); | |
| 999 | - } | |
| 1000 | - | |
| 1001 | - $templates_by_category[ $category ][] = $template; | |
| 1002 | - } | |
| 1003 | - } | |
| 1004 | - unset( $template ); | |
| 1005 | - | |
| 1006 | - // Subcategories that are included elsewhere. | |
| 1007 | - $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' ); | |
| 1008 | - | |
| 1009 | - $categories = array_keys( $templates_by_category ); | |
| 1010 | - $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() ); | |
| 1011 | - $categories = array_diff( $categories, $redundant_cats ); | |
| 1012 | - sort( $categories ); | |
| 1013 | - | |
| 1014 | - array_walk( | |
| 1015 | - $custom_templates, | |
| 1016 | - function( &$template ) { | |
| 1017 | - $template['custom'] = true; | |
| 1018 | - } | |
| 941 | + $form = FrmForm::getOne( $id ); | |
| 942 | + $error_args = array( | |
| 943 | + 'title' => __( 'You can\'t edit the form', 'formidable' ), | |
| 944 | + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ), | |
| 945 | + 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 946 | + 'continue_url' => add_query_arg( | |
| 947 | + array( | |
| 948 | + 'page' => 'formidable', | |
| 949 | + ) | |
| 950 | + ), | |
| 1019 | 951 | ); |
| 1020 | - | |
| 1021 | - $my_templates_translation = __( 'My Templates', 'formidable' ); | |
| 1022 | - $categories = array_merge( array( $my_templates_translation ), $categories ); | |
| 1023 | - $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' ); | |
| 1024 | - $license_type = $frm_license_type; | |
| 1025 | - $args = compact( 'pricing', 'license_type' ); | |
| 1026 | - $where = apply_filters( 'frm_forms_dropdown', array(), '' ); | |
| 1027 | - $forms = FrmForm::get_published_forms( $where ); | |
| 1028 | - $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/'; | |
| 1029 | - | |
| 1030 | - $templates_by_category[ $my_templates_translation ] = $custom_templates; | |
| 1031 | - | |
| 1032 | - unset( $pricing, $license_type, $where ); | |
| 1033 | - wp_enqueue_script( 'accordion' ); // register accordion for template groups | |
| 1034 | - require $view_path . 'list-templates.php'; | |
| 1035 | - } | |
| 1036 | - | |
| 1037 | - /** | |
| 1038 | - * @since 4.03.01 | |
| 1039 | - */ | |
| 1040 | - private static function get_template_categories( $templates ) { | |
| 1041 | - $categories = array(); | |
| 1042 | - foreach ( $templates as $template ) { | |
| 1043 | - if ( isset( $template['categories'] ) ) { | |
| 1044 | - $categories = array_merge( $categories, $template['categories'] ); | |
| 1045 | - } | |
| 952 | + if ( ! $form ) { | |
| 953 | + FrmAppController::show_error_modal( $error_args ); | |
| 954 | + return; | |
| 1046 | 955 | } |
| 1047 | - $exclude_cats = FrmFormsHelper::ignore_template_categories(); | |
| 1048 | - $categories = array_unique( $categories ); | |
| 1049 | - $categories = array_diff( $categories, $exclude_cats ); | |
| 1050 | - sort( $categories ); | |
| 1051 | - return $categories; | |
| 1052 | - } | |
| 1053 | 956 | |
| 1054 | - private static function add_user_templates( &$templates ) { | |
| 1055 | - $user_templates = array( | |
| 1056 | - 'is_template' => 1, | |
| 1057 | - 'default_template' => 0, | |
| 1058 | - ); | |
| 1059 | - $user_templates = FrmForm::getAll( $user_templates, 'name' ); | |
| 1060 | - foreach ( $user_templates as $template ) { | |
| 1061 | - $template = array( | |
| 1062 | - 'id' => $template->id, | |
| 1063 | - 'name' => $template->name, | |
| 1064 | - 'key' => $template->form_key, | |
| 1065 | - 'description' => $template->description, | |
| 1066 | - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ), | |
| 1067 | - 'released' => $template->created_at, | |
| 1068 | - 'installed' => 1, | |
| 957 | + if ( 'trash' === $form->status ) { | |
| 958 | + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' ); | |
| 959 | + $error_args['continue_url'] = add_query_arg( | |
| 960 | + array( | |
| 961 | + 'page' => 'formidable', | |
| 962 | + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ), | |
| 963 | + 'form_type' => 'trash', | |
| 964 | + 'frm_action' => 'untrash', | |
| 965 | + 'id' => $id, | |
| 966 | + ) | |
| 1069 | 967 | ); |
| 1070 | - array_unshift( $templates, $template ); | |
| 1071 | - unset( $template ); | |
| 968 | + $error_args['continue_text'] = __( 'Restore form', 'formidable' ); | |
| 969 | + FrmAppController::show_error_modal( $error_args ); | |
| 970 | + return; | |
| 1072 | 971 | } |
| 1073 | - } | |
| 1074 | 972 | |
| 1075 | - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1076 | - global $frm_vars; | |
| 1077 | - | |
| 1078 | - $form = FrmForm::getOne( $id ); | |
| 1079 | - if ( ! $form ) { | |
| 1080 | - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) ); | |
| 1081 | - } | |
| 1082 | - | |
| 1083 | 973 | if ( $form->parent_form_id ) { |
| 1084 | 974 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
| 1085 | 975 | 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>' ) ); |
| 1086 | 976 | } |
| @@ -1259,8 +1149,21 @@ | ||
| 1259 | 1149 | 'screenshot' => 'chat.png', |
| 1260 | 1150 | ) |
| 1261 | 1151 | ), |
| 1262 | 1152 | ), |
| 1153 | + 'abandonment' => array( | |
| 1154 | + 'name' => __( 'Form Abandonment', 'formidable' ), | |
| 1155 | + 'icon' => 'frm_icon_font frm_abandoned_icon', | |
| 1156 | + 'html_class' => 'frm_show_upgrade_tab frm_noallow', | |
| 1157 | + 'data' => FrmAppHelper::get_upgrade_data_params( | |
| 1158 | + 'abandonment', | |
| 1159 | + array( | |
| 1160 | + 'upgrade' => __( 'Form abandonment settings', 'formidable' ), | |
| 1161 | + 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ), | |
| 1162 | + 'screenshot' => 'abandonment.png', | |
| 1163 | + ) | |
| 1164 | + ), | |
| 1165 | + ), | |
| 1263 | 1166 | 'html' => array( |
| 1264 | 1167 | 'name' => __( 'Customize HTML', 'formidable' ), |
| 1265 | 1168 | 'class' => __CLASS__, |
| 1266 | 1169 | 'function' => 'html_settings', |
| @@ -1267,9 +1170,9 @@ | ||
| 1267 | 1170 | 'icon' => 'frm_icon_font frm_code_icon', |
| 1268 | 1171 | ), |
| 1269 | 1172 | ); |
| 1270 | 1173 | |
| 1271 | - foreach ( array( 'landing', 'chat' ) as $feature ) { | |
| 1174 | + foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) { | |
| 1272 | 1175 | if ( ! FrmAppHelper::show_new_feature( $feature ) ) { |
| 1273 | 1176 | unset( $sections[ $feature ] ); |
| 1274 | 1177 | } |
| 1275 | 1178 | } |
| @@ -1605,13 +1508,17 @@ | ||
| 1605 | 1508 | * Replace any [form_name] shortcodes in a string. |
| 1606 | 1509 | * |
| 1607 | 1510 | * @since 5.5 |
| 1608 | 1511 | * |
| 1609 | - * @param string $string | |
| 1512 | + * @param string|array $string | |
| 1610 | 1513 | * @param stdClass|string|int $form |
| 1611 | - * @return string | |
| 1514 | + * @return string|array | |
| 1612 | 1515 | */ |
| 1613 | 1516 | public static function replace_form_name_shortcodes( $string, $form ) { |
| 1517 | + if ( ! is_string( $string ) ) { | |
| 1518 | + return $string; | |
| 1519 | + } | |
| 1520 | + | |
| 1614 | 1521 | if ( false === strpos( $string, '[form_name]' ) ) { |
| 1615 | 1522 | return $string; |
| 1616 | 1523 | } |
| 1617 | 1524 | |
| @@ -1777,8 +1684,33 @@ | ||
| 1777 | 1684 | return; |
| 1778 | 1685 | } |
| 1779 | 1686 | } |
| 1780 | 1687 | |
| 1688 | + /** | |
| 1689 | + * Rename a form. | |
| 1690 | + * | |
| 1691 | + * Handles the AJAX request for renaming a form. | |
| 1692 | + * | |
| 1693 | + * @since 6.7 | |
| 1694 | + * | |
| 1695 | + * @return void | |
| 1696 | + */ | |
| 1697 | + public static function rename_form() { | |
| 1698 | + // Check permission and nonce | |
| 1699 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 1700 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 1701 | + | |
| 1702 | + // Get posted data | |
| 1703 | + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); | |
| 1704 | + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' ); | |
| 1705 | + | |
| 1706 | + // Update the form name and form key. | |
| 1707 | + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' ); | |
| 1708 | + FrmForm::update( $form_id, compact( 'name', 'form_key' ) ); | |
| 1709 | + | |
| 1710 | + wp_send_json_success( compact( 'form_key' ) ); | |
| 1711 | + } | |
| 1712 | + | |
| 1781 | 1713 | public static function json_error( $errors ) { |
| 1782 | 1714 | $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
| 1783 | 1715 | |
| 1784 | 1716 | return $errors; |
| @@ -2261,8 +2193,13 @@ | ||
| 2261 | 2193 | if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) { |
| 2262 | 2194 | return array(); |
| 2263 | 2195 | } |
| 2264 | 2196 | |
| 2197 | + // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab. | |
| 2198 | + if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) { | |
| 2199 | + return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) ); | |
| 2200 | + } | |
| 2201 | + | |
| 2265 | 2202 | $entry = FrmEntry::getOne( $args['entry_id'], true ); |
| 2266 | 2203 | $actions = FrmOnSubmitHelper::get_actions( $args['form']->id ); |
| 2267 | 2204 | $met_actions = array(); |
| 2268 | 2205 | $has_redirect = false; |
| @@ -2508,13 +2445,19 @@ | ||
| 2508 | 2445 | |
| 2509 | 2446 | $doing_ajax = FrmAppHelper::doing_ajax(); |
| 2510 | 2447 | |
| 2511 | 2448 | if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs. |
| 2512 | - echo json_encode( array( 'redirect' => $success_url ) ); | |
| 2449 | + echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) ); | |
| 2513 | 2450 | wp_die(); |
| 2514 | 2451 | } |
| 2515 | 2452 | |
| 2516 | 2453 | if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs. |
| 2454 | + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2455 | + self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ); | |
| 2456 | + self::$redirected_in_new_tab[ $args['form']->id ] = 1; | |
| 2457 | + return; | |
| 2458 | + } | |
| 2459 | + | |
| 2517 | 2460 | wp_redirect( esc_url_raw( $success_url ) ); |
| 2518 | 2461 | die(); // do not use wp_die or redirect fails |
| 2519 | 2462 | } |
| 2520 | 2463 | |
| @@ -2522,8 +2465,63 @@ | ||
| 2522 | 2465 | self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) ); |
| 2523 | 2466 | } |
| 2524 | 2467 | |
| 2525 | 2468 | /** |
| 2469 | + * Prints open in new tab js with fallback handler. | |
| 2470 | + * | |
| 2471 | + * @since 6.3.1 | |
| 2472 | + * | |
| 2473 | + * @param string $success_url Success URL. | |
| 2474 | + * @param array $args See {@see FrmFormsController::redirect_after_submit()}. | |
| 2475 | + */ | |
| 2476 | + private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) { | |
| 2477 | + echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");'; | |
| 2478 | + echo 'if ( ! newTab ) {'; | |
| 2479 | + | |
| 2480 | + $data = array( | |
| 2481 | + 'formId' => intval( $args['form']->id ), | |
| 2482 | + 'message' => self::get_redirect_fallback_message( $success_url, $args ), | |
| 2483 | + ); | |
| 2484 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2485 | + echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';'; | |
| 2486 | + echo '}</script>'; | |
| 2487 | + } | |
| 2488 | + | |
| 2489 | + /** | |
| 2490 | + * Gets response data for redirect action when AJAX submitting. | |
| 2491 | + * | |
| 2492 | + * @since 6.3.1 | |
| 2493 | + * | |
| 2494 | + * @param array $args See {@see FrmFormsController::run_success_action()}. | |
| 2495 | + * @return array | |
| 2496 | + */ | |
| 2497 | + private static function get_ajax_redirect_response_data( $args ) { | |
| 2498 | + $response_data = array( 'redirect' => $args['success_url'] ); | |
| 2499 | + | |
| 2500 | + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2501 | + $response_data['openInNewTab'] = 1; | |
| 2502 | + | |
| 2503 | + $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg(); | |
| 2504 | + | |
| 2505 | + $args['form']->options['success_msg'] = $args['message']; | |
| 2506 | + $args['form']->options['edit_msg'] = $args['message']; | |
| 2507 | + if ( ! isset( $args['fields'] ) ) { | |
| 2508 | + $args['fields'] = FrmField::get_all_for_form( $args['form']->id ); | |
| 2509 | + } | |
| 2510 | + | |
| 2511 | + $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args ); | |
| 2512 | + | |
| 2513 | + ob_start(); | |
| 2514 | + self::show_lone_success_messsage( $args ); | |
| 2515 | + $response_data['content'] = ob_get_clean(); | |
| 2516 | + | |
| 2517 | + $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args ); | |
| 2518 | + } | |
| 2519 | + | |
| 2520 | + return $response_data; | |
| 2521 | + } | |
| 2522 | + | |
| 2523 | + /** | |
| 2526 | 2524 | * Redirects after submitting using JS. This is used when showing message before redirecting. |
| 2527 | 2525 | * |
| 2528 | 2526 | * @since 6.0 |
| 2529 | 2527 | * |
| @@ -2531,8 +2529,9 @@ | ||
| 2531 | 2529 | */ |
| 2532 | 2530 | private static function redirect_after_submit_using_js( $args ) { |
| 2533 | 2531 | $success_msg = FrmOnSubmitHelper::get_default_redirect_msg(); |
| 2534 | 2532 | $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args ); |
| 2533 | + $success_url = esc_url_raw( $args['success_url'] ); | |
| 2535 | 2534 | |
| 2536 | 2535 | /** |
| 2537 | 2536 | * Filters the delay time before redirecting when On Submit Redirect action is delayed. |
| 2538 | 2537 | * |
| @@ -2541,8 +2540,14 @@ | ||
| 2541 | 2540 | * @param int $delay_time Delay time in miliseconds. |
| 2542 | 2541 | */ |
| 2543 | 2542 | $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 ); |
| 2544 | 2543 | |
| 2544 | + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2545 | + $redirect_js = 'window.open("' . $success_url . '", "_blank")'; | |
| 2546 | + } else { | |
| 2547 | + $redirect_js = 'window.location="' . $success_url . '";'; | |
| 2548 | + } | |
| 2549 | + | |
| 2545 | 2550 | add_filter( 'frm_use_wpautop', '__return_true' ); |
| 2546 | 2551 | |
| 2547 | 2552 | echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2548 | 2553 | echo '<script>'; |
| @@ -2548,9 +2553,9 @@ | ||
| 2548 | 2553 | echo '<script>'; |
| 2549 | 2554 | if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load. |
| 2550 | 2555 | echo 'window.onload=function(){'; |
| 2551 | 2556 | } |
| 2552 | - echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');'; | |
| 2557 | + echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2553 | 2558 | if ( empty( $args['doing_ajax'] ) ) { |
| 2554 | 2559 | echo '};'; |
| 2555 | 2560 | } |
| 2556 | 2561 | echo '</script>'; |
| @@ -2564,10 +2569,9 @@ | ||
| 2564 | 2569 | * @param array $args |
| 2565 | 2570 | */ |
| 2566 | 2571 | private static function get_redirect_message( $success_url, $success_msg, $args ) { |
| 2567 | 2572 | $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' . |
| 2568 | - /* translators: %1$s: Start link HTML, %2$s: End link HTML */ | |
| 2569 | - sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) . | |
| 2573 | + self::get_redirect_fallback_message( $success_url, $args ) . | |
| 2570 | 2574 | '</div></div>'; |
| 2571 | 2575 | |
| 2572 | 2576 | $redirect_args = array( |
| 2573 | 2577 | 'entry_id' => $args['entry_id'], |
| @@ -2578,8 +2582,31 @@ | ||
| 2578 | 2582 | return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args ); |
| 2579 | 2583 | } |
| 2580 | 2584 | |
| 2581 | 2585 | /** |
| 2586 | + * Gets fallback message when redirecting failed. | |
| 2587 | + * | |
| 2588 | + * @since 6.3.1 | |
| 2589 | + * | |
| 2590 | + * @param string $success_url Redirect URL. | |
| 2591 | + * @param array $args Contains `form` object. | |
| 2592 | + * @return string | |
| 2593 | + */ | |
| 2594 | + private static function get_redirect_fallback_message( $success_url, $args ) { | |
| 2595 | + $target = ''; | |
| 2596 | + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2597 | + $target = ' target="_blank"'; | |
| 2598 | + } | |
| 2599 | + | |
| 2600 | + return sprintf( | |
| 2601 | + /* translators: %1$s: Start link HTML, %2$s: End link HTML */ | |
| 2602 | + __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), | |
| 2603 | + '<a href="' . esc_url( $success_url ) . '"' . $target . '>', | |
| 2604 | + '</a>' | |
| 2605 | + ); | |
| 2606 | + } | |
| 2607 | + | |
| 2608 | + /** | |
| 2582 | 2609 | * Prepare to show the success message and empty form after submit |
| 2583 | 2610 | * |
| 2584 | 2611 | * @since 2.05 |
| 2585 | 2612 | */ |
| @@ -3012,6 +3039,46 @@ | ||
| 3012 | 3039 | * @since 3.06 |
| 3013 | 3040 | */ |
| 3014 | 3041 | public static function add_new() { |
| 3015 | 3042 | _deprecated_function( __FUNCTION__, '4.08' ); |
| 3043 | + } | |
| 3044 | + | |
| 3045 | + /** | |
| 3046 | + * Create a custom template from a form | |
| 3047 | + * | |
| 3048 | + * @since 3.06 | |
| 3049 | + * @deprecated x.x | |
| 3050 | + */ | |
| 3051 | + public static function build_template() { | |
| 3052 | + _deprecated_function( __METHOD__, 'x.x' ); | |
| 3053 | + } | |
| 3054 | + | |
| 3055 | + /** | |
| 3056 | + * @deprecated x.x | |
| 3057 | + * | |
| 3058 | + * @return bool | |
| 3059 | + */ | |
| 3060 | + public static function expired() { | |
| 3061 | + _deprecated_function( __METHOD__, 'x.x' ); | |
| 3062 | + return FrmAddonsController::is_license_expired(); | |
| 3063 | + } | |
| 3064 | + | |
| 3065 | + /** | |
| 3066 | + * Get data from api before rendering it so that we can flag the modal as expired | |
| 3067 | + * | |
| 3068 | + * @deprecated x.x | |
| 3069 | + * | |
| 3070 | + * @return void | |
| 3071 | + */ | |
| 3072 | + public static function before_list_templates() { | |
| 3073 | + _deprecated_function( __METHOD__, 'x.x' ); | |
| 3074 | + } | |
| 3075 | + | |
| 3076 | + /** | |
| 3077 | + * @deprecated x.x | |
| 3078 | + * | |
| 3079 | + * @return void | |
| 3080 | + */ | |
| 3081 | + public static function list_templates() { | |
| 3082 | + _deprecated_function( __METHOD__, 'x.x' ); | |
| 3016 | 3083 | } |
| 3017 | 3084 | } |