| 1 |
<?php |
| 2 |
/** |
| 3 |
* Description. |
| 4 |
* |
| 5 |
* @package Booking Calendar. |
| 6 |
* @author wpdevelop, oplugins |
| 7 |
* @web-site https://wpbookingcalendar.com/ |
| 8 |
* @email info@wpbookingcalendar.com |
| 9 |
* |
| 10 |
* @since 11.0.x |
| 11 |
* @file ../includes/page-form-builder/advanced-mode/bfb-advanced-mode.php |
| 12 |
* |
| 13 |
* @modified 2026-01-28 17:31 |
| 14 |
*/ |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; // Exit if accessed directly. |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
/** |
| 22 |
* Render "Advanced Form" editor panel (CodeMirror textareas). |
| 23 |
* |
| 24 |
* Notes: |
| 25 |
* - This is an "edit mode" UI only (Stage 1). |
| 26 |
* - Values are filled by JS from exporter: WPBC_BFB_Exporter.export_all(). |
| 27 |
* - Import back into Builder JSON can be added later (Stage 2). |
| 28 |
* |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
function wpbc_bfb__adavanced_mode__render_advanced_form_editor_panel() { |
| 32 |
|
| 33 |
?> |
| 34 |
<div class="wpbc_bfb__advanced_editor"> |
| 35 |
|
| 36 |
<div class="wpbc_bfb__advanced_editor__head"> |
| 37 |
|
| 38 |
<div class="wpbc_bfb__advanced_editor__toolbar" style="display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin:0 0 14px;"> |
| 39 |
<button type="button" class="button" id="wpbc_bfb__advanced_regenerate_btn"> |
| 40 |
<?php esc_html_e( 'Regenerate from Builder', 'booking' ); ?> |
| 41 |
</button> |
| 42 |
|
| 43 |
<label style="display:inline-flex;gap:6px;align-items:center;"> |
| 44 |
<input type="checkbox" id="wpbc_bfb__advanced_autosync" checked="checked"/> |
| 45 |
<?php esc_html_e( 'Auto-sync while Builder changes', 'booking' ); ?> |
| 46 |
</label> |
| 47 |
|
| 48 |
<span id="wpbc_bfb__advanced_dirty_hint" style="display:none;"> |
| 49 |
<?php esc_html_e( 'Edited (auto-sync paused).', 'booking' ); ?> |
| 50 |
</span> |
| 51 |
</div> |
| 52 |
</div> |
| 53 |
|
| 54 |
<!-- Tabs --> |
| 55 |
<?php |
| 56 |
|
| 57 |
$tabs_config = array( |
| 58 |
'advanced_mode__booking_form' => array( |
| 59 |
'title' => __( 'Booking Form', 'booking' ), |
| 60 |
'type' => 'panel', |
| 61 |
'css_classes' => '', |
| 62 |
), |
| 63 |
'advanced_mode__booking_data' => array( |
| 64 |
'title' => __( 'Booking fields data', 'booking' ), |
| 65 |
'type' => 'panel', |
| 66 |
'css_classes' => '', |
| 67 |
), |
| 68 |
); |
| 69 |
|
| 70 |
WPBC_BFB_UI_Top_Tabs::render( |
| 71 |
array( |
| 72 |
'active_tab' => 'advanced_mode__booking_form', |
| 73 |
'tabs' => $tabs_config, |
| 74 |
'nav_container_id' => 'wpbc_bfb__top_horisontal__advanced_mode', |
| 75 |
'panels_root_id' => 'wpbc_bfb__advanced_mode_panels', |
| 76 |
) |
| 77 |
); |
| 78 |
|
| 79 |
?> |
| 80 |
<div id="wpbc_bfb__advanced_mode_panels"> |
| 81 |
<style type="text/css"> |
| 82 |
#wpbc_bfb__advanced_mode_panels .CodeMirror{ |
| 83 |
height: 450px; |
| 84 |
} |
| 85 |
</style> |
| 86 |
<div class="wpbc_bfb__tab_section wpbc_bfb__tab_section__advanced_mode__booking_form"> |
| 87 |
<!-- Booking form --> |
| 88 |
<div class="wpbc_bfb__advanced_editor__block" style="flex: 1 1 auto;min-width:320px;"> |
| 89 |
<textarea id="wpbc_bfb__advanced_form_editor" rows="25" style="width:100%;min-height:540px;font-family:monospace;font-size:12px;"></textarea> |
| 90 |
|
| 91 |
<div style="display:flex;gap:10px;align-items:center;margin-top:10px;flex-wrap:wrap;"> |
| 92 |
<button type="button" class="button" id="wpbc_bfb__advanced_copy_form_btn"> |
| 93 |
<?php esc_html_e( 'Copy Advanced Form', 'booking' ); ?> |
| 94 |
</button> |
| 95 |
</div> |
| 96 |
</div> |
| 97 |
|
| 98 |
</div> |
| 99 |
|
| 100 |
<div class="wpbc_bfb__tab_section wpbc_bfb__tab_section__advanced_mode__booking_data"> |
| 101 |
<!-- "Content of booking fields data" --> |
| 102 |
<div class="wpbc_bfb__advanced_editor__block" style="flex: 1 1 auto;min-width:320px;"> |
| 103 |
<textarea id="wpbc_bfb__content_form_editor" rows="25" style="width:100%;min-height:540px;font-family:monospace;font-size:12px;"></textarea> |
| 104 |
|
| 105 |
<div style="display:flex;gap:10px;align-items:center;margin-top:10px;flex-wrap:wrap;"> |
| 106 |
<button type="button" class="button" id="wpbc_bfb__advanced_copy_content_btn"> |
| 107 |
<?php esc_html_e( 'Copy Content Template', 'booking' ); ?> |
| 108 |
</button> |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
|
| 112 |
</div> |
| 113 |
</div> |
| 114 |
</div> |
| 115 |
<?php |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
/** |
| 120 |
* Enqueue WordPress Code Editor (CodeMirror) and expose settings to JS. |
| 121 |
* |
| 122 |
* @return void |
| 123 |
*/ |
| 124 |
function wpbc_bfb__adavanced_mode__enqueue_code_editor_for_advanced_tab() { |
| 125 |
|
| 126 |
// If user desctivated the code highlighting ? |
| 127 |
if ( ! function_exists( 'wp_enqueue_code_editor' ) ) { |
| 128 |
|
| 129 |
if ( class_exists( 'wpdev_bk_personal' ) ) { |
| 130 |
wp_enqueue_script( 'wpbc-bfb-advanced-form-editor', wpbc_plugin_url( '/includes/page-form-builder/advanced-mode/_out/bfb-advanced-form-editor.js' ), array(), WP_BK_VERSION_NUM, true ); |
| 131 |
} else { |
| 132 |
wp_enqueue_script( 'wpbc-bfb-advanced-form-editor', wpbc_plugin_url( '/includes/page-form-builder/advanced-mode/_out/bfb-advanced-free.js' ), array(), WP_BK_VERSION_NUM, true ); |
| 133 |
} |
| 134 |
return; |
| 135 |
} |
| 136 |
|
| 137 |
$settings = wp_enqueue_code_editor( array( 'type' => 'text/html' ) ); |
| 138 |
|
| 139 |
// Bail if user disabled CodeMirror. |
| 140 |
if ( false === $settings ) { |
| 141 |
return; |
| 142 |
} |
| 143 |
|
| 144 |
// Ensure core editor script is available. Enqueue only if registered and not yet enqueued. |
| 145 |
if ( wp_script_is( 'wp-theme-plugin-editor', 'registered' ) && ! wp_script_is( 'wp-theme-plugin-editor', 'enqueued' ) ) { |
| 146 |
wp_enqueue_script( 'wp-theme-plugin-editor' ); |
| 147 |
} |
| 148 |
|
| 149 |
wp_enqueue_style( 'wp-codemirror' ); |
| 150 |
|
| 151 |
/** |
| 152 |
* IMPORTANT: |
| 153 |
* Use a script handle that is guaranteed to exist on this page. |
| 154 |
* If "wpbc_all" is always enqueued here, keep it. |
| 155 |
* Otherwise localize into your builder main handle. |
| 156 |
*/ |
| 157 |
wp_localize_script( 'wpbc_all', 'wpbc_bfb_code_editor_settings', $settings ); |
| 158 |
|
| 159 |
if ( class_exists( 'wpdev_bk_personal' ) ) { |
| 160 |
wp_enqueue_script( 'wpbc-bfb-advanced-form-editor', wpbc_plugin_url( '/includes/page-form-builder/advanced-mode/_out/bfb-advanced-form-editor.js' ), array( 'wpbc_all', 'wpbc-bfb_exporter', 'code-editor', 'wp-theme-plugin-editor' ), WP_BK_VERSION_NUM, true ); |
| 161 |
} else { |
| 162 |
wp_enqueue_script( 'wpbc-bfb-advanced-form-editor', wpbc_plugin_url( '/includes/page-form-builder/advanced-mode/_out/bfb-advanced-free.js' ), array( 'wpbc_all', 'wpbc-bfb_exporter', 'code-editor', 'wp-theme-plugin-editor' ), WP_BK_VERSION_NUM, true ); |
| 163 |
} |
| 164 |
} |
| 165 |
|