PluginProbe
Booking Calendar / 11.9.1
Booking Calendar v11.9.1
11.9.1 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 All 206 releases
booking / includes / _shared-ui-catalog / class-wpbc-ui-catalog.php

class-wpbc-ui-catalog.php in Booking Calendar 11.9.1, at includes/_shared-ui-catalog/class-wpbc-ui-catalog.php

161 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shared asset boundary for template-driven administration catalogs.
4 *
5 * @package Booking Calendar
6 * @since 11.6.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Register and enqueue only the assets shared by independent catalogs.
15 *
16 * Domain data, SQL, permissions, and mutations deliberately remain outside
17 * this class. Later phases can extend the catalog mechanics without coupling
18 * this foundation to an individual administration page.
19 */
20 final class WPBC_UI_Catalog {
21
22 /**
23 * Build a cache-safe version for one generated shared asset.
24 *
25 * Shared catalog controllers can change independently during an in-version
26 * migration. Appending the generated file modification time prevents a
27 * cached lifecycle controller from running against a newer domain adapter.
28 *
29 * @param string $asset_filename Generated `_out` asset filename.
30 *
31 * @return string Plugin version with an optional file modification suffix.
32 */
33 private static function get_asset_version( $asset_filename ) {
34 $asset_filename = is_scalar( $asset_filename ) ? basename( (string) $asset_filename ) : '';
35 $asset_path = __DIR__ . '/_out/' . $asset_filename;
36 $modified_time = ( '' !== $asset_filename && is_file( $asset_path ) ) ? filemtime( $asset_path ) : false;
37
38 return false === $modified_time
39 ? (string) WP_BK_VERSION_NUM
40 : WP_BK_VERSION_NUM . '.' . (string) $modified_time;
41 }
42
43 /**
44 * Return a browser-safe configuration for one registered catalog mount.
45 *
46 * Trusted PHP template paths and provider objects live outside the stored
47 * configuration, so the returned array can be localized directly.
48 *
49 * @param string $catalog_id Registered catalog identifier.
50 * @param string $mount_id HTML element ID receiving the catalog.
51 * @param array $initial_request Normalized initial shared request.
52 * @param array $initial_response Normalized initial response contract.
53 *
54 * @return array<string,mixed> Browser configuration or an empty array.
55 */
56 public static function get_client_configuration( $catalog_id, $mount_id, $initial_request, $initial_response ) {
57 $registry = WPBC_UI_Catalog_Registry::get_instance();
58 $configuration = $registry->get_configuration( $catalog_id );
59 $mount_id = is_scalar( $mount_id ) ? sanitize_html_class( (string) $mount_id ) : '';
60
61 if ( empty( $configuration ) || '' === $mount_id || ! is_array( $initial_request ) || ! is_array( $initial_response ) ) {
62 return array();
63 }
64
65 $configuration['mount_id'] = $mount_id;
66 $configuration['preference_namespace'] = WPBC_UI_Catalog_Preferences::get_namespace( $catalog_id );
67 $configuration['initial_request'] = $initial_request;
68 $configuration['initial_response'] = $initial_response;
69
70 return $configuration;
71 }
72
73 /**
74 * Print allow-listed shared and catalog-owned WordPress templates.
75 *
76 * @param string $catalog_id Registered catalog identifier.
77 *
78 * @return array<int,string> Template identifiers made available.
79 */
80 public static function print_templates( $catalog_id ) {
81 return WPBC_UI_Catalog_Template_Loader::print_catalog_templates( $catalog_id );
82 }
83
84 /**
85 * Enqueue the shared catalog stylesheet.
86 *
87 * @return void
88 */
89 public static function enqueue_styles() {
90 wp_enqueue_style(
91 'wpbc-ui-catalog',
92 trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/wpbc_ui_catalog.css',
93 array(),
94 self::get_asset_version( 'wpbc_ui_catalog.css' )
95 );
96 }
97
98 /**
99 * Enqueue the domain-neutral catalog controller without optional mechanics.
100 *
101 * Non-catalog administration modules may reuse focused shared mechanics,
102 * such as rendered-overflow tooltips, without loading hierarchy, selection,
103 * or action-menu controllers. Sortable remains a dependency of the shared
104 * controller because catalog column ordering is implemented in that file.
105 *
106 * @return void
107 */
108 public static function enqueue_controller() {
109 wp_enqueue_script(
110 'wpbc-ui-catalog-sortable',
111 wpbc_plugin_url( '/vendors/sortablejs/Sortable.min.js' ),
112 array(),
113 WP_BK_VERSION_NUM,
114 array( 'in_footer' => WPBC_JS_IN_FOOTER )
115 );
116 wp_enqueue_script(
117 'wpbc-ui-catalog',
118 trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/wpbc_ui_catalog.js',
119 array( 'wp-util', 'wpbc-ui-catalog-sortable' ),
120 self::get_asset_version( 'wpbc_ui_catalog.js' ),
121 array( 'in_footer' => WPBC_JS_IN_FOOTER )
122 );
123 }
124
125 /**
126 * Enqueue shared catalog, hierarchy, selection, and row-action controllers.
127 *
128 * WordPress' `wp-util` package provides the allow-listed `wp.template()`
129 * renderer used by every template-driven catalog. The catalog script also
130 * exposes opt-in inline-workflow mechanics for sticky bars, busy controls,
131 * and changed-row presentation. Hierarchy, selection, inline workflow, and
132 * action menus do not perform domain reads or mutations.
133 *
134 * @return void
135 */
136 public static function enqueue_scripts() {
137 self::enqueue_controller();
138 wp_enqueue_script(
139 'wpbc-ui-catalog-hierarchy',
140 trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/wpbc_ui_catalog_hierarchy.js',
141 array( 'wpbc-ui-catalog' ),
142 self::get_asset_version( 'wpbc_ui_catalog_hierarchy.js' ),
143 array( 'in_footer' => WPBC_JS_IN_FOOTER )
144 );
145 wp_enqueue_script(
146 'wpbc-ui-catalog-selection',
147 trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/wpbc_ui_catalog_selection.js',
148 array( 'wpbc-ui-catalog' ),
149 self::get_asset_version( 'wpbc_ui_catalog_selection.js' ),
150 array( 'in_footer' => WPBC_JS_IN_FOOTER )
151 );
152 wp_enqueue_script(
153 'wpbc-ui-catalog-actions',
154 trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/wpbc_ui_catalog_actions.js',
155 array( 'wpbc-ui-catalog' ),
156 self::get_asset_version( 'wpbc_ui_catalog_actions.js' ),
157 array( 'in_footer' => WPBC_JS_IN_FOOTER )
158 );
159 }
160 }
161