PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.27
Booking for Appointments and Events Calendar – Amelia v1.2.27
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 / ShortcodeService / AmeliaShortcodeService.php
ameliabooking / src / Infrastructure / WP / ShortcodeService Last commit date
AmeliaBookingShortcodeService.php 1 year ago AmeliaShortcodeService.php 1 year ago BookingShortcodeService.php 1 year ago CatalogBookingShortcodeService.php 1 year ago CatalogShortcodeService.php 1 year ago EventsCalendarBookingShortcodeService.php 1 year ago EventsListBookingShortcodeService.php 1 year ago EventsShortcodeService.php 1 year ago StepBookingShortcodeService.php 1 year ago
AmeliaShortcodeService.php
204 lines
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Infrastructure\WP\ShortcodeService;
9
10 use AmeliaBooking\Application\Services\Cache\CacheApplicationService;
11 use AmeliaBooking\Application\Services\CustomField\AbstractCustomFieldApplicationService;
12 use AmeliaBooking\Application\Services\Stash\StashApplicationService;
13 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
14 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
15 use AmeliaBooking\Domain\Services\Settings\SettingsService;
16 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
17 use AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage;
18 use AmeliaBooking\Infrastructure\WP\Translations\FrontendStrings;
19
20 /**
21 * Class AmeliaShortcodeService
22 *
23 * @package AmeliaBooking\Infrastructure\WP\ShortcodeService
24 */
25 class AmeliaShortcodeService
26 {
27 public static $counter = 0;
28
29 /**
30 * Prepare scripts and styles
31 * @throws InvalidArgumentException
32 * @throws \Interop\Container\Exception\ContainerException
33 */
34 public static function prepareScriptsAndStyles()
35 {
36 $container = null;
37
38 self::$counter++;
39
40 if (self::$counter > 1) {
41 return;
42 }
43
44 $settingsService = new SettingsService(new SettingsStorage());
45
46 // Enqueue Scripts
47 if ($settingsService->getSetting('payments', 'payPal')['enabled'] === true) {
48 wp_enqueue_script('amelia_paypal_script', 'https://www.paypalobjects.com/api/checkout.js');
49 }
50
51 if ($settingsService->getSetting('payments', 'razorpay')['enabled'] === true) {
52 wp_enqueue_script('amelia_razorpay_script', 'https://checkout.razorpay.com/v1/checkout.js');
53 }
54
55 $gmapApiKey = $settingsService->getSetting('general', 'gMapApiKey');
56
57 if ($gmapApiKey) {
58 wp_enqueue_script(
59 'amelia_google_maps_api',
60 "https://maps.googleapis.com/maps/api/js?key={$gmapApiKey}&libraries=places&loading=async"
61 );
62 }
63
64 // Fix for Divi theme.
65 // Don't enqueue script if it's activated Divi Visual Page Builder
66 if (empty($_GET['et_fb'])) {
67 wp_enqueue_script(
68 'amelia_booking_scripts',
69 AMELIA_URL . 'public/js/frontend/amelia-booking.js',
70 [],
71 AMELIA_VERSION,
72 true
73 );
74 }
75
76 if ($settingsService->getSetting('payments', 'stripe')['enabled'] === true) {
77 wp_enqueue_script('amelia_stripe_js', 'https://js.stripe.com/v3/');
78 }
79
80 // Enqueue Styles
81 wp_enqueue_style(
82 'amelia_booking_styles_vendor',
83 AMELIA_URL . 'public/css/frontend/vendor.css',
84 [],
85 AMELIA_VERSION
86 );
87
88 $customUrl = $settingsService->getSetting('activation', 'customUrl');
89
90 if (
91 $settingsService->getSetting('customization', 'useGenerated') === null ||
92 $settingsService->getSetting('customization', 'useGenerated')
93 ) {
94 wp_enqueue_style(
95 'amelia_booking_styles',
96 (!empty($customUrl['uploadsPath']) ? $customUrl['uploadsPath'] : AMELIA_UPLOADS_URL) . '/amelia/css/amelia-booking.' .
97 $settingsService->getSetting('customization', 'hash') . '.css',
98 [],
99 AMELIA_VERSION
100 );
101 } else {
102 wp_enqueue_style(
103 'amelia_booking_styles',
104 AMELIA_URL . 'public/css/frontend/amelia-booking-' . str_replace('.', '-', AMELIA_VERSION) . '.css',
105 [],
106 AMELIA_VERSION
107 );
108 }
109
110 // Underscore
111 wp_enqueue_script('undescore', includes_url('js') . '/underscore.min.js');
112
113 // Strings Localization
114 wp_localize_script(
115 'amelia_booking_scripts',
116 'wpAmeliaLabels',
117 FrontendStrings::getAllStrings()
118 );
119
120 // Settings Localization
121 wp_localize_script(
122 'amelia_booking_scripts',
123 'wpAmeliaSettings',
124 $settingsService->getFrontendSettings()
125 );
126
127 wp_localize_script(
128 'amelia_booking_scripts',
129 'wpAmeliaUrls',
130 [
131 'wpAmeliaUseUploadsAmeliaPath' => AMELIA_UPLOADS_FILES_PATH_USE,
132 'wpAmeliaPluginURL' => empty($customUrl['enabled'])
133 ? AMELIA_URL : AMELIA_HOME_URL . $customUrl['pluginPath'],
134 'wpAmeliaPluginAjaxURL' => empty($customUrl['enabled'])
135 ? AMELIA_ACTION_URL : AMELIA_HOME_URL . $customUrl['ajaxPath'] . '?' . AMELIA_ACTION_SLUG . '',
136 ]
137 );
138
139 wp_localize_script(
140 'amelia_booking_scripts',
141 'localeLanguage',
142 [AMELIA_LOCALE]
143 );
144
145 $localeSubstitutes = $settingsService->getSetting('general', 'calendarLocaleSubstitutes');
146
147 if (isset($localeSubstitutes[AMELIA_LOCALE])) {
148 wp_localize_script(
149 'amelia_booking_scripts',
150 'ameliaCalendarLocale',
151 [$localeSubstitutes[AMELIA_LOCALE]]
152 );
153 }
154
155 wp_localize_script(
156 'amelia_booking_scripts',
157 'fileUploadExtensions',
158 array_keys(AbstractCustomFieldApplicationService::$allowedUploadedFileExtensions)
159 );
160
161 if ($settingsService->getSetting('activation', 'stash') && self::$counter === 1) {
162 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
163
164 /** @var StashApplicationService $stashAS */
165 $stashAS = $container->get('application.stash.service');
166
167 wp_localize_script(
168 'amelia_booking_scripts',
169 'ameliaEntities',
170 $stashAS->getStash()
171 );
172 }
173
174 if (!empty($_GET['ameliaCache']) || !empty($_GET['ameliaWcCache'])) {
175 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
176
177 /** @var CacheApplicationService $cacheAS */
178 $cacheAS = $container->get('application.cache.service');
179
180 try {
181 $cacheData = !empty($_GET['ameliaCache']) ?
182 $cacheAS->getCacheByName(sanitize_text_field($_GET['ameliaCache'])) :
183 $cacheAS->getWcCacheByName(sanitize_text_field($_GET['ameliaWcCache']));
184
185 wp_localize_script(
186 'amelia_booking_scripts',
187 'ameliaCache',
188 [$cacheData ? str_replace('&quot;', '\\"', json_encode($cacheData)) : '']
189 );
190 } catch (QueryExecutionException $e) {
191 }
192 }
193
194 wp_localize_script(
195 'amelia_booking_scripts',
196 'wpAmeliaTimeZone',
197 [DateTimeService::getTimeZone()->getName()]
198 );
199
200 do_action('ameliaScriptsLoaded');
201 do_action('amelia_scripts_loaded');
202 }
203 }
204