PluginProbe
Booking Calendar / 11.2
Booking Calendar v11.2
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
booking / includes / page-form-builder / field-packs / _shared / hint-cost-like-wptpl.php

hint-cost-like-wptpl.php in Booking Calendar 11.2, at includes/page-form-builder/field-packs/_shared/hint-cost-like-wptpl.php

291 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shared helpers for cost-like BFB hint field packs.
4 *
5 * @package Booking Calendar
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Get a formatted preview cost value.
14 *
15 * @param int|float $preview_cost Preview amount.
16 * @param string $fallback Fallback text.
17 *
18 * @return string
19 */
20 function wpbc_bfb_hint_cost_like_preview_value( $preview_cost, $fallback ) {
21
22 $cur_sym = function_exists( 'wpbc_get_currency_symbol' ) ? wpbc_get_currency_symbol() : '$';
23 $preview = function_exists( 'wpbc_formate_cost_hint__no_html' ) ? wpbc_formate_cost_hint__no_html( $preview_cost, $cur_sym ) : $fallback;
24
25 return html_entity_decode( $preview, ENT_QUOTES, 'UTF-8' );
26 }
27
28 /**
29 * Register a cost-like hint field pack.
30 *
31 * @param array $packs Accumulated packs.
32 * @param array $cfg Pack config.
33 *
34 * @return array
35 */
36 function wpbc_bfb_hint_cost_like_register_pack( $packs, $cfg ) {
37
38 $packs[ $cfg['token'] ] = array(
39 'kind' => 'field',
40 'type' => $cfg['token'],
41 'label' => '',
42 'icon' => 'wpbc-bi-cash-coin',
43 'usage_key' => $cfg['token'],
44
45 'schema' => array(
46 'props' => array(
47 'prefix_text' => array( 'type' => 'string', 'default' => $cfg['prefix'] ),
48 'html_id' => array( 'type' => 'string', 'default' => '' ),
49 'cssclass' => array( 'type' => 'string', 'default' => '' ),
50 'help' => array( 'type' => 'string', 'default' => '' ),
51 ),
52 ),
53
54 'templates_printer' => $cfg['templates_printer'],
55 );
56
57 return $packs;
58 }
59
60 /**
61 * Enqueue a cost-like hint pack script.
62 *
63 * @param string $page Current admin page slug.
64 * @param array $cfg Pack config.
65 *
66 * @return void
67 */
68 function wpbc_bfb_hint_cost_like_enqueue_js( $page, $cfg ) {
69
70 if ( WPBC_BFB_BUILDER_PAGE_SLUG !== $page ) {
71 return;
72 }
73
74 wp_enqueue_script(
75 $cfg['handle'],
76 wpbc_plugin_url( '/includes/page-form-builder/field-packs/' . $cfg['folder'] . '/_out/' . $cfg['script_file'] ),
77 array( 'wp-util', 'wpbc-bfb' ),
78 WP_BK_VERSION_NUM,
79 true
80 );
81
82 wp_localize_script(
83 $cfg['handle'],
84 $cfg['boot_var'],
85 array(
86 'is_supported' => class_exists( 'wpdev_bk_biz_m' ) ? 1 : 0,
87 'upgrade_text' => __( 'This hint is available only in Booking Calendar Business Medium or higher versions.', 'booking' ),
88 'preview_value' => wpbc_bfb_hint_cost_like_preview_value( $cfg['preview_cost'], $cfg['preview_fallback'] ),
89 )
90 );
91 }
92
93 /**
94 * Print wp.template() blocks for a cost-like hint pack.
95 *
96 * @param string $page Current admin page slug.
97 * @param array $cfg Pack config.
98 *
99 * @return void
100 */
101 function wpbc_bfb_hint_cost_like_print_templates( $page, $cfg ) {
102
103 if ( WPBC_BFB_BUILDER_PAGE_SLUG !== $page ) {
104 return;
105 }
106
107 $token = $cfg['token'];
108 $template_id = 'wpbc-bfb-field-' . $token;
109 $inspector_id = 'wpbc-bfb-inspector-' . $token;
110 $exported = sprintf(
111 /* translators: 1: Field prefix text. 2: Shortcode name. */
112 __( 'Exported output: %1$s <strong>[%2$s]</strong>', 'booking' ),
113 $cfg['prefix'],
114 $token
115 );
116
117 ?>
118 <script type="text/html" id="tmpl-<?php echo esc_attr( $template_id ); ?>">
119 <span class="wpbc_bfb__noaction wpbc_bfb__no-drag-zone" inert="">
120 <span class="wpbc_bfb__<?php echo esc_attr( $token ); ?>_line {{ data.cssclass || '' }}"
121 <# if ( data.html_id ) { #> id="{{ data.html_id }}" <# } #>>
122 <# if ( data.prefix_text ) { #>
123 <span class="wpbc_bfb__<?php echo esc_attr( $token ); ?>_prefix">{{ data.prefix_text }}</span>
124 <# } #>
125 <# if ( data.prefix_text ) { #>&nbsp;<# } #>
126 <strong class="wpbc_bfb__<?php echo esc_attr( $token ); ?>_shortcode">{{{ data.preview_value || '<?php echo esc_js( $cfg['preview_fallback'] ); ?>' }}}</strong>
127 </span>
128
129 <# if ( ! data.is_supported && data.upgrade_text ) { #>
130 <div class="wpbc_bfb__help">
131 {{ data.upgrade_text }}
132 </div>
133 <# } #>
134
135 <# if ( data.help ) { #>
136 <div class="wpbc_bfb__help">{{ data.help }}</div>
137 <# } #>
138 </span>
139 </script>
140
141 <script type="text/html" id="tmpl-<?php echo esc_attr( $inspector_id ); ?>">
142 <div class="wpbc_bfb__inspector__head">
143 <div class="header_container">
144 <div class="header_title_content">
145 <h3 class="title"><?php echo esc_html( $cfg['inspector_title'] ); ?></h3>
146 <div class="desc">
147 <?php echo esc_html( $cfg['description'] ); ?>
148 </div>
149 </div>
150 <div class="actions wpbc_ajx_toolbar wpbc_no_borders">
151 <div class="ui_container ui_container_small">
152 <div class="ui_group">
153 <div class="ui_element">
154 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
155 data-action="deselect" aria-label="<?php echo esc_attr__( 'Deselect', 'booking' ); ?>">
156 <i class="menu_icon icon-1x wpbc_icn_remove_done"></i>
157 </button>
158 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
159 data-action="scrollto" aria-label="<?php echo esc_attr__( 'Scroll to field', 'booking' ); ?>">
160 <i class="menu_icon icon-1x wpbc_icn_ads_click filter_center_focus"></i>
161 </button>
162 </div>
163 <div class="ui_element">
164 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
165 data-action="move-up" aria-label="<?php echo esc_attr__( 'Move up', 'booking' ); ?>">
166 <i class="menu_icon icon-1x wpbc_icn_arrow_upward"></i>
167 </button>
168 <button type="button" class="button button-secondary wpbc_ui_control wpbc_ui_button"
169 data-action="move-down" aria-label="<?php echo esc_attr__( 'Move down', 'booking' ); ?>">
170 <i class="menu_icon icon-1x wpbc_icn_arrow_downward"></i>
171 </button>
172 </div>
173 <div class="ui_element">
174 <button data-action="delete"
175 aria-label="<?php echo esc_attr__( 'Delete', 'booking' ); ?>"
176 type="button"
177 class="button button-secondary wpbc_ui_control wpbc_ui_button wpbc_ui_button_danger button-link-delete">
178 <span class="in-button-text"><?php echo esc_html__( 'Delete', 'booking' ); ?></span>&nbsp;&nbsp;
179 <i class="menu_icon icon-1x wpbc_icn_delete_outline"></i>
180 </button>
181 </div>
182 </div>
183 </div>
184 </div>
185 </div>
186 </div>
187
188 <div class="wpbc_bfb__inspector__body">
189 <section class="wpbc_bfb__inspector__group wpbc_ui__collapsible_group is-open" data-group="basic">
190 <button type="button" class="group__header">
191 <h3><?php echo esc_html__( 'Basic', 'booking' ); ?></h3>
192 <i class="wpbc_ui_el__vert_menu_root_section_icon menu_icon icon-1x wpbc-bi-chevron-right"></i>
193 </button>
194 <div class="group__fields">
195 <div class="inspector__row">
196 <label class="inspector__label"><?php echo esc_html__( 'Text before shortcode', 'booking' ); ?></label>
197 <div class="inspector__control">
198 <input type="text"
199 class="inspector__input"
200 data-inspector-key="prefix_text"
201 value="{{ data.prefix_text || '<?php echo esc_js( $cfg['prefix'] ); ?>' }}">
202 </div>
203 </div>
204
205 <div class="inspector__row">
206 <label class="inspector__label"><?php echo esc_html__( 'Help text', 'booking' ); ?></label>
207 <div class="inspector__control">
208 <textarea class="inspector__textarea" rows="3" data-inspector-key="help">{{ data.help || '' }}</textarea>
209 </div>
210 </div>
211 </div>
212 </section>
213
214 <section class="wpbc_bfb__inspector__group wpbc_ui__collapsible_group" data-group="appearance">
215 <button type="button" class="group__header">
216 <h3><?php echo esc_html__( 'Appearance', 'booking' ); ?></h3>
217 <i class="wpbc_ui_el__vert_menu_root_section_icon menu_icon icon-1x wpbc-bi-chevron-right"></i>
218 </button>
219 <div class="group__fields">
220 <div class="inspector__row">
221 <label class="inspector__label"><?php echo esc_html__( 'CSS class', 'booking' ); ?></label>
222 <div class="inspector__control">
223 <input type="text"
224 class="inspector__input"
225 data-inspector-key="cssclass"
226 value="{{ data.cssclass || '' }}">
227 </div>
228 </div>
229
230 <div class="inspector__row">
231 <label class="inspector__label"><?php echo esc_html__( 'HTML ID', 'booking' ); ?></label>
232 <div class="inspector__control">
233 <input type="text"
234 class="inspector__input"
235 data-inspector-key="html_id"
236 value="{{ data.html_id || '' }}">
237 </div>
238 </div>
239
240 <div class="wpbc_bfb__inspector__note">
241 <?php echo esc_html( $exported ); ?>
242 </div>
243
244 <div class="wpbc_bfb__inspector__note">
245 <?php echo esc_html__( 'This hint is available only in Booking Calendar Business Medium or higher versions.', 'booking' ); ?>
246 </div>
247 </div>
248 </section>
249 </div>
250 </script>
251 <?php
252 }
253
254 /**
255 * Print a cost-like hint palette item.
256 *
257 * @param string $group Palette group.
258 * @param string $position Position.
259 * @param array $cfg Pack config.
260 *
261 * @return void
262 */
263 function wpbc_bfb_hint_cost_like_palette_item( $group, $position, $cfg ) {
264
265 if ( 'hints' !== $group || 'top' !== $position ) {
266 return;
267 }
268
269 $preview_value = wpbc_bfb_hint_cost_like_preview_value( $cfg['preview_cost'], $cfg['preview_fallback'] );
270
271 ?>
272 <li class="wpbc_bfb__field"
273 data-id="<?php echo esc_attr( $cfg['token'] ); ?>"
274 data-type="<?php echo esc_attr( $cfg['token'] ); ?>"
275 data-usage_key="<?php echo esc_attr( $cfg['token'] ); ?>"
276 data-prefix_text="<?php echo esc_attr( $cfg['prefix'] ); ?>"
277 data-preview_value="<?php echo esc_attr( $preview_value ); ?>"
278 data-help=""
279 data-label="">
280 <i class="menu_icon icon-1x wpbc_icn_attach_money"></i>
281 <span class="wpbc_bfb__field-label"><?php echo esc_html( $cfg['palette_label'] ); ?></span>
282 <?php
283 if ( ! class_exists( 'wpdev_bk_biz_m' ) ) {
284 echo '<span class="wpbc_pro_label">Pro | BM+</span>';
285 }
286 ?>
287 <span class="wpbc_bfb__field-type"><?php echo esc_html( $preview_value ); ?></span>
288 </li>
289 <?php
290 }
291