PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.25
Booking for Appointments and Events Calendar – Amelia v1.2.25
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 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
Submenu.php 1 year ago SubmenuPageHandler.php 1 year ago
SubmenuPageHandler.php
454 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 if ($page !== 'wpamelia-customize-new') {
38 $this->renderOld($page);
39 } else {
40 $this->renderNew($page);
41 }
42 }
43
44 private function renderOld($page)
45 {
46 // Enqueue Scripts
47 wp_enqueue_script(
48 'amelia_booking_scripts',
49 AMELIA_URL . 'public/js/backend/amelia-booking.js',
50 [],
51 AMELIA_VERSION
52 );
53
54 if (in_array($page, ['wpamelia-locations', 'wpamelia-settings', 'wpamelia-appointments', 'wpamelia-events', 'wpamelia-dashboard', 'wpamelia-calendar', 'wpamelia-services', 'wpamelia-customers'])) {
55 $gmapApiKey = $this->settingsService->getSetting('general', 'gMapApiKey');
56
57 if ($gmapApiKey) {
58 wp_enqueue_script(
59 'google_maps_api',
60 "https://maps.googleapis.com/maps/api/js?key={$gmapApiKey}&libraries=places&loading=async&callback=Function.prototype"
61 );
62 }
63 }
64
65
66 if ($page === 'wpamelia-customers') {
67 wp_enqueue_script(
68 'papaparse',
69 "https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.1/papaparse.min.js"
70 );
71 }
72
73
74 if ($page === 'wpamelia-notifications') {
75 wp_enqueue_script('amelia_paddle', Licence::getPaddleUrl());
76 }
77
78 // Enqueue Styles
79 wp_enqueue_style(
80 'amelia_booking_styles',
81 AMELIA_URL . 'public/css/backend/amelia-booking.css',
82 [],
83 AMELIA_VERSION
84 );
85
86 // WordPress enqueue
87 wp_enqueue_media();
88
89 wp_localize_script(
90 'amelia_booking_scripts',
91 'wpAmeliaLanguages',
92 HelperService::getLanguages()
93 );
94
95 $wcSettings = $this->settingsService->getSetting('payments', 'wc');
96
97 if ($wcSettings['enabled'] && WooCommerceService::isEnabled()) {
98 wp_localize_script(
99 'amelia_booking_scripts',
100 'wpAmeliaWcProducts',
101 WooCommerceService::getInitialProducts()
102 );
103 }
104
105 // Strings Localization
106 switch ($page) {
107 case ('wpamelia-locations'):
108 wp_localize_script(
109 'amelia_booking_scripts',
110 'wpAmeliaLabels',
111 array_merge(
112 BackendStrings::getEntityFormStrings(),
113 BackendStrings::getLocationStrings(),
114 BackendStrings::getCommonStrings()
115 )
116 );
117
118 break;
119 case ('wpamelia-services'):
120 wp_localize_script(
121 'amelia_booking_scripts',
122 'wpAmeliaLabels',
123 array_merge(
124 BackendStrings::getPaymentStrings(),
125 BackendStrings::getSettingsStrings(),
126 BackendStrings::getEntityFormStrings(),
127 BackendStrings::getServiceStrings(),
128 BackendStrings::getBookableStrings(),
129 BackendStrings::getCommonStrings(),
130 BackendStrings::getAppointmentStrings(),
131 BackendStrings::getRecurringStrings(),
132 BackendStrings::getCustomerStrings(),
133 BackendStrings::getUserStrings()
134 )
135 );
136
137 break;
138 case ('wpamelia-employees'):
139 wp_localize_script(
140 'amelia_booking_scripts',
141 'wpAmeliaLabels',
142 array_merge(
143 BackendStrings::getEntityFormStrings(),
144 BackendStrings::getUserStrings(),
145 BackendStrings::getEmployeeStrings(),
146 BackendStrings::getStripeStrings(),
147 BackendStrings::getCommonStrings(),
148 BackendStrings::getScheduleStrings()
149 )
150 );
151
152 break;
153 case ('wpamelia-customers'):
154 wp_localize_script(
155 'amelia_booking_scripts',
156 'wpAmeliaLabels',
157 array_merge(
158 BackendStrings::getEntityFormStrings(),
159 BackendStrings::getUserStrings(),
160 BackendStrings::getCustomerStrings(),
161 BackendStrings::getCommonStrings(),
162 BackendStrings::getScheduleStrings(),
163 BackendStrings::getImportStrings(),
164 BackendStrings::getCustomizeStrings()
165 )
166 );
167
168 break;
169 case ('wpamelia-finance'):
170 wp_localize_script(
171 'amelia_booking_scripts',
172 'wpAmeliaLabels',
173 array_merge(
174 BackendStrings::getEntityFormStrings(),
175 BackendStrings::getCommonStrings(),
176 BackendStrings::getFinanceStrings(),
177 BackendStrings::getPaymentStrings(),
178 BackendStrings::getEventStrings()
179 )
180 );
181
182 break;
183 case ('wpamelia-appointments'):
184 wp_localize_script(
185 'amelia_booking_scripts',
186 'wpAmeliaLabels',
187 array_merge(
188 BackendStrings::getNotificationsStrings(),
189 BackendStrings::getEntityFormStrings(),
190 BackendStrings::getCommonStrings(),
191 BackendStrings::getUserStrings(),
192 BackendStrings::getCustomerStrings(),
193 BackendStrings::getAppointmentStrings(),
194 BackendStrings::getPaymentStrings(),
195 BackendStrings::getRecurringStrings()
196 )
197 );
198
199 break;
200
201 case ('wpamelia-events'):
202 wp_localize_script(
203 'amelia_booking_scripts',
204 'wpAmeliaLabels',
205 array_merge(
206 BackendStrings::getSettingsStrings(),
207 BackendStrings::getEntityFormStrings(),
208 BackendStrings::getCommonStrings(),
209 BackendStrings::getUserStrings(),
210 BackendStrings::getCustomerStrings(),
211 BackendStrings::getAppointmentStrings(),
212 BackendStrings::getEventStrings(),
213 BackendStrings::getBookableStrings(),
214 BackendStrings::getRecurringStrings()
215 )
216 );
217
218 break;
219
220 case ('wpamelia-dashboard'):
221 wp_localize_script(
222 'amelia_booking_scripts',
223 'wpAmeliaLabels',
224 array_merge(
225 BackendStrings::getEntityFormStrings(),
226 BackendStrings::getCommonStrings(),
227 BackendStrings::getAppointmentStrings(),
228 BackendStrings::getUserStrings(),
229 BackendStrings::getCustomerStrings(),
230 BackendStrings::getDashboardStrings(),
231 BackendStrings::getPaymentStrings(),
232 BackendStrings::getRecurringStrings(),
233 BackendStrings::getNotificationsStrings()
234 )
235 );
236
237 break;
238 case ('wpamelia-calendar'):
239 wp_localize_script(
240 'amelia_booking_scripts',
241 'wpAmeliaLabels',
242 array_merge(
243 BackendStrings::getEntityFormStrings(),
244 BackendStrings::getCommonStrings(),
245 BackendStrings::getAppointmentStrings(),
246 BackendStrings::getUserStrings(),
247 BackendStrings::getCustomerStrings(),
248 BackendStrings::getCalendarStrings(),
249 BackendStrings::getPaymentStrings(),
250 BackendStrings::getEventStrings(),
251 BackendStrings::getBookableStrings(),
252 BackendStrings::getRecurringStrings()
253 )
254 );
255
256 break;
257 case ('wpamelia-notifications'):
258 wp_localize_script(
259 'amelia_booking_scripts',
260 'wpAmeliaLabels',
261 array_merge(
262 BackendStrings::getCommonStrings(),
263 BackendStrings::getPaymentStrings(),
264 BackendStrings::getNotificationsStrings()
265 )
266 );
267
268 break;
269
270 case ('wpamelia-smsnotifications'):
271 wp_localize_script(
272 'amelia_booking_scripts',
273 'wpAmeliaLabels',
274 array_merge(
275 BackendStrings::getCommonStrings(),
276 BackendStrings::getNotificationsStrings()
277 )
278 );
279
280 break;
281 case ('wpamelia-settings'):
282 wp_localize_script(
283 'amelia_booking_scripts',
284 'wpAmeliaLabels',
285 array_merge(
286 BackendStrings::getEntityFormStrings(),
287 BackendStrings::getUserStrings(),
288 BackendStrings::getEmployeeStrings(),
289 BackendStrings::getStripeStrings(),
290 BackendStrings::getFinanceStrings(),
291 BackendStrings::getCommonStrings(),
292 BackendStrings::getScheduleStrings(),
293 BackendStrings::getSettingsStrings(),
294 BackendStrings::getNotificationsStrings()
295 )
296 );
297
298 break;
299 case ('wpamelia-customize'):
300 wp_localize_script(
301 'amelia_booking_scripts',
302 'wpAmeliaLabels',
303 array_merge(
304 BackendStrings::getCommonStrings(),
305 BackendStrings::getCustomizeStrings()
306 )
307 );
308
309 break;
310 case ('wpamelia-cf'):
311 wp_localize_script(
312 'amelia_booking_scripts',
313 'wpAmeliaLabels',
314 array_merge(
315 BackendStrings::getCommonStrings(),
316 BackendStrings::getCustomizeStrings(),
317 BackendStrings::getCustomerStrings()
318 )
319 );
320
321 break;
322 case ('wpamelia-whats-new'):
323 wp_localize_script(
324 'amelia_booking_scripts',
325 'wpAmeliaLabels',
326 array_merge(
327 BackendStrings::getWhatsNewStrings(),
328 BackendStrings::getNotificationsStrings(),
329 BackendStrings::getRecurringStrings(),
330 BackendStrings::getCommonStrings(),
331 BackendStrings::getAppointmentStrings()
332 )
333 );
334
335 break;
336 case ('wpamelia-lite-vs-premium'):
337 wp_localize_script(
338 'amelia_booking_scripts',
339 'wpAmeliaLabels',
340 BackendStrings::getLiteVsPremiumStrings()
341 );
342
343 break;
344 }
345
346 // Settings Localization
347 wp_localize_script(
348 'amelia_booking_scripts',
349 'wpAmeliaSettings',
350 $this->settingsService->getFrontendSettings()
351 );
352
353 wp_localize_script(
354 'amelia_booking_scripts',
355 'localeLanguage',
356 [AMELIA_LOCALE]
357 );
358
359 wp_localize_script(
360 'amelia_booking_scripts',
361 'wpAmeliaTimeZone',
362 [DateTimeService::getTimeZone()->getName()]
363 );
364
365 include AMELIA_PATH . '/view/backend/view.php';
366 }
367
368 private function renderNew($page)
369 {
370 $scriptId = AMELIA_DEV ? 'amelia_booking_scripts_dev_vite' : 'amelia_booking_script_index';
371
372 if (AMELIA_DEV) {
373 wp_enqueue_script(
374 'amelia_booking_scripts_dev_vite',
375 'http://localhost:3000/@vite/client',
376 [],
377 null,
378 false
379 );
380
381 wp_enqueue_script(
382 'amelia_booking_scripts_dev_main',
383 'http://localhost:3000/src/assets/js/admin/admin.js',
384 [],
385 null,
386 true
387 );
388 } else {
389 wp_enqueue_script(
390 $scriptId,
391 AMELIA_URL . 'v3/public/assets/admin.50d6f6dc.js',
392 [],
393 AMELIA_VERSION,
394 true
395 );
396 }
397
398 wp_localize_script(
399 $scriptId,
400 'localeLanguage',
401 [AMELIA_LOCALE]
402 );
403
404 wp_localize_script(
405 $scriptId,
406 'wpAmeliaLanguages',
407 HelperService::getLanguages()
408 );
409
410 // Settings Localization
411 wp_localize_script(
412 $scriptId,
413 'wpAmeliaSettings',
414 $this->settingsService->getFrontendSettings()
415 );
416
417 // Labels
418 wp_localize_script(
419 $scriptId,
420 'wpAmeliaLabels',
421 array_merge(
422 BackendStrings::getCommonStrings(),
423 BackendStrings::getSettingsStrings(),
424 BackendStrings::getCustomizeStrings()
425 )
426 );
427
428 wp_localize_script(
429 $scriptId,
430 'localeLanguage',
431 [AMELIA_LOCALE]
432 );
433
434 wp_localize_script(
435 $scriptId,
436 'wpAmeliaTimeZone',
437 [DateTimeService::getTimeZone()->getName()]
438 );
439
440 wp_localize_script(
441 $scriptId,
442 'wpAmeliaUrls',
443 [
444 'wpAmeliaUseUploadsAmeliaPath' => AMELIA_UPLOADS_FILES_PATH_USE,
445 'wpAmeliaPluginURL' => AMELIA_URL,
446 'wpAmeliaPluginAjaxURL' => AMELIA_ACTION_URL
447 ]
448 );
449
450 include AMELIA_PATH . '/view/backend/view-new.php';
451 }
452
453 }
454