PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / WP / WPMenu / SubmenuPageHandler.php
ameliabooking / src / Infrastructure / WP / WPMenu Last commit date
AdminBarMenu.php 3 months ago Submenu.php 3 months ago SubmenuPageHandler.php 3 weeks ago
SubmenuPageHandler.php
208 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\WP\WPMenu;
4
5 use AmeliaBooking\Application\Services\Helper\HelperService;
6 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
7 use AmeliaBooking\Domain\Services\Settings\SettingsService;
8 use AmeliaBooking\Infrastructure\WP\Integrations\WooCommerce\WooCommerceService;
9 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
10 use AmeliaBooking\Infrastructure\Licence\Licence;
11
12 /**
13 * Renders menu pages
14 */
15 class SubmenuPageHandler
16 {
17 /** @var SettingsService $settingsService */
18 private $settingsService;
19
20 /**
21 * SubmenuPageHandler constructor.
22 *
23 * @param SettingsService $settingsService
24 */
25 public function __construct(SettingsService $settingsService)
26 {
27 $this->settingsService = $settingsService;
28 }
29
30 /**
31 * Submenu page render function
32 *
33 * @param $page
34 */
35 public function render($page)
36 {
37
38 $this->renderRedesign($page);
39 }
40
41 // TODO - Redesign: Finish & Refactor method
42 private function renderRedesign($page)
43 {
44 $testFlagFileExists = file_exists(AMELIA_PATH . '/test_mode.flag');
45 define('AMELIA_TEST', $testFlagFileExists);
46
47 $isTestEnv = defined('AMELIA_TEST') && AMELIA_TEST;
48 $isDev = defined('AMELIA_DEV') && AMELIA_DEV && !$isTestEnv;
49 $scriptId = $isDev ? 'amelia_dev_main_script' : 'amelia_prod_main_script';
50
51 // Enqueue V3 scripts for customize page
52 if ($page === 'wpamelia-customize') {
53 $this->enqueueV3Scripts();
54 }
55
56 if ($isDev) {
57 wp_enqueue_script(
58 'amelia_dev_vite_client',
59 'http://localhost:5173/@vite/client',
60 [],
61 null,
62 false
63 );
64
65 wp_enqueue_script(
66 $scriptId,
67 'http://localhost:5173/src/main.ts',
68 [],
69 null,
70 true
71 );
72 } else {
73 wp_enqueue_script(
74 $scriptId,
75 AMELIA_URL . 'redesign/dist/index.js',
76 [],
77 AMELIA_VERSION,
78 true
79 );
80
81 wp_enqueue_style(
82 'amelia_prod_main_style',
83 AMELIA_URL . 'redesign/dist/index.css',
84 [],
85 AMELIA_VERSION
86 );
87 }
88
89 // WordPress enqueue
90 wp_enqueue_media();
91
92 $wcSettings = $this->settingsService->getSetting('payments', 'wc');
93
94 if ($wcSettings['enabled'] && WooCommerceService::isEnabled()) {
95 wp_localize_script(
96 $scriptId,
97 'wpAmeliaWcProducts',
98 WooCommerceService::getInitialProducts()
99 );
100 }
101
102 // Settings Localization
103 wp_localize_script(
104 $scriptId,
105 'wpAmeliaSettings',
106 $this->settingsService->getBackendSettings()
107 );
108
109 // Strings Localization
110 wp_localize_script(
111 $scriptId,
112 'wpAmeliaLabels',
113 BackendStrings::getAllStrings(),
114 );
115
116 // Paddle
117 if (in_array($page, ['wpamelia-notifications', 'wpamelia-settings'])) {
118 wp_enqueue_script('amelia_paddle', Licence::getPaddleUrl());
119 }
120
121 // Include the generic page template
122 include AMELIA_PATH . '/view/backend/redesign/page.php';
123 }
124
125 /**
126 * Enqueue V3 scripts for embedding in redesign app
127 */
128 private function enqueueV3Scripts()
129 {
130 $scriptId = AMELIA_DEV ? 'amelia_booking_scripts_dev_vite' : 'amelia_booking_script_index';
131
132 if (AMELIA_DEV) {
133 wp_enqueue_script(
134 'amelia_booking_scripts_dev_vite',
135 'http://localhost:3000/@vite/client',
136 [],
137 null,
138 false
139 );
140
141 wp_enqueue_script(
142 'amelia_booking_scripts_dev_main',
143 'http://localhost:3000/src/assets/js/admin/admin.js',
144 [],
145 null,
146 true
147 );
148 } else {
149 wp_enqueue_script(
150 $scriptId,
151 AMELIA_URL . 'v3/public/assets/admin.js',
152 [],
153 AMELIA_VERSION,
154 true
155 );
156
157 wp_enqueue_style(
158 'amelia_booking_v3_style',
159 AMELIA_URL . 'v3/public/assets/style.css',
160 [],
161 AMELIA_VERSION
162 );
163 }
164
165 wp_localize_script(
166 $scriptId,
167 'localeLanguage',
168 [AMELIA_LOCALE]
169 );
170
171 wp_localize_script(
172 $scriptId,
173 'wpAmeliaLanguages',
174 HelperService::getLanguages()
175 );
176
177 // Settings Localization
178 wp_localize_script(
179 $scriptId,
180 'wpAmeliaSettings',
181 $this->settingsService->getFrontendSettings()
182 );
183
184 // Labels
185 wp_localize_script(
186 $scriptId,
187 'wpAmeliaLabels',
188 BackendStrings::getAllStrings(),
189 );
190
191 wp_localize_script(
192 $scriptId,
193 'wpAmeliaTimeZone',
194 [DateTimeService::getTimeZone()->getName()]
195 );
196
197 wp_localize_script(
198 $scriptId,
199 'wpAmeliaUrls',
200 [
201 'wpAmeliaUseUploadsAmeliaPath' => AMELIA_UPLOADS_FILES_PATH_USE,
202 'wpAmeliaPluginURL' => AMELIA_URL,
203 'wpAmeliaPluginAjaxURL' => AMELIA_ACTION_URL
204 ]
205 );
206 }
207 }
208