PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.1.3
Booking for Appointments and Events Calendar – Amelia v2.1.3
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 5 months ago AmeliaShortcodeService.php 8 months ago BookingShortcodeService.php 8 months ago CatalogBookingShortcodeService.php 8 months ago CatalogShortcodeService.php 8 months ago EventsCalendarBookingShortcodeService.php 8 months ago EventsListBookingShortcodeService.php 8 months ago EventsShortcodeService.php 8 months ago StepBookingShortcodeService.php 8 months ago
AmeliaShortcodeService.php
223 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. 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 */
33 public static function prepareScriptsAndStyles()
34 {
35 $container = null;
36
37 self::$counter++;
38
39 if (self::$counter > 1) {
40 return;
41 }
42
43 $settingsService = new SettingsService(new SettingsStorage());
44
45 // Enqueue Scripts
46 if ($settingsService->getSetting('payments', 'payPal')['enabled'] === true) {
47 wp_enqueue_script('amelia_paypal_script', 'https://www.paypalobjects.com/api/checkout.js');
48 }
49
50 if ($settingsService->getSetting('payments', 'razorpay')['enabled'] === true) {
51 wp_enqueue_script('amelia_razorpay_script', 'https://checkout.razorpay.com/v1/checkout.js');
52 }
53
54 $gmapApiKey = $settingsService->getSetting('general', 'gMapApiKey');
55
56 if ($gmapApiKey) {
57 wp_enqueue_script(
58 'amelia_google_maps_api',
59 "https://maps.googleapis.com/maps/api/js?key={$gmapApiKey}&libraries=places&loading=async"
60 );
61 }
62
63 // Fix for Divi theme.
64 // Don't enqueue script if it's activated Divi Visual Page Builder
65 if (empty($_GET['et_fb'])) {
66 wp_enqueue_script(
67 'amelia_booking_scripts',
68 AMELIA_URL . 'public/js/frontend/amelia-booking.js',
69 [],
70 AMELIA_VERSION,
71 true
72 );
73 }
74
75 if ($settingsService->getSetting('payments', 'stripe')['enabled'] === true) {
76 wp_enqueue_script('amelia_stripe_js', 'https://js.stripe.com/v3/');
77 }
78
79 if ($settingsService->getSetting('payments', 'square')['enabled'] === true) {
80 if ($settingsService->getSetting('payments', 'square')['testMode'] === true) {
81 wp_enqueue_script('amelia_square_js', 'https://sandbox.web.squarecdn.com/v1/square.js');
82 } else {
83 wp_enqueue_script('amelia_square_js', 'https://web.squarecdn.com/v1/square.js');
84 }
85 wp_enqueue_style(
86 'amelia_google_button_style',
87 'https://developers.google.com/reference/sdks/web/static/styles/code-preview.css',
88 [],
89 null,
90 'all'
91 );
92 }
93
94 // Enqueue Styles
95 wp_enqueue_style(
96 'amelia_booking_styles_vendor',
97 AMELIA_URL . 'public/css/frontend/vendor.css',
98 [],
99 AMELIA_VERSION
100 );
101
102 $customUrl = $settingsService->getSetting('activation', 'customUrl');
103
104 if (
105 $settingsService->getSetting('customization', 'useGenerated') === null ||
106 $settingsService->getSetting('customization', 'useGenerated')
107 ) {
108 wp_enqueue_style(
109 'amelia_booking_styles',
110 (!empty($customUrl['uploadsPath']) ? $customUrl['uploadsPath'] : AMELIA_UPLOADS_URL) . '/amelia/css/amelia-booking.' .
111 $settingsService->getSetting('customization', 'hash') . '.css',
112 [],
113 AMELIA_VERSION
114 );
115 } else {
116 wp_enqueue_style(
117 'amelia_booking_styles',
118 AMELIA_URL . 'public/css/frontend/amelia-booking-' . str_replace('.', '-', AMELIA_VERSION) . '.css',
119 [],
120 AMELIA_VERSION
121 );
122 }
123
124 // Underscore
125 wp_enqueue_script('undescore', includes_url('js') . '/underscore.min.js');
126
127 // Strings Localization
128 wp_localize_script(
129 'amelia_booking_scripts',
130 'wpAmeliaLabels',
131 FrontendStrings::getAllStrings()
132 );
133
134 // Settings Localization
135 wp_localize_script(
136 'amelia_booking_scripts',
137 'wpAmeliaSettings',
138 $settingsService->getFrontendSettings()
139 );
140
141 wp_localize_script(
142 'amelia_booking_scripts',
143 'wpAmeliaUrls',
144 [
145 'wpAmeliaUseUploadsAmeliaPath' => AMELIA_UPLOADS_FILES_PATH_USE,
146 'wpAmeliaPluginURL' => empty($customUrl['enabled'])
147 ? AMELIA_URL : AMELIA_HOME_URL . $customUrl['pluginPath'],
148 'wpAmeliaPluginAjaxURL' => empty($customUrl['enabled'])
149 ? AMELIA_ACTION_URL : AMELIA_HOME_URL . $customUrl['ajaxPath'] . '?' . AMELIA_ACTION_SLUG . '',
150 ]
151 );
152
153 wp_localize_script(
154 'amelia_booking_scripts',
155 'localeLanguage',
156 [AMELIA_LOCALE]
157 );
158
159 $localeSubstitutes = $settingsService->getSetting('general', 'calendarLocaleSubstitutes');
160
161 if (isset($localeSubstitutes[AMELIA_LOCALE])) {
162 wp_localize_script(
163 'amelia_booking_scripts',
164 'ameliaCalendarLocale',
165 [$localeSubstitutes[AMELIA_LOCALE]]
166 );
167 }
168
169 $allowedUploadedFileExtensions =
170 !empty($settingsService->getSetting('general', 'customFieldsAllowedExtensions'))
171 ? $settingsService->getSetting('general', 'customFieldsAllowedExtensions')
172 : AbstractCustomFieldApplicationService::$allowedUploadedFileExtensions;
173
174 wp_localize_script(
175 'amelia_booking_scripts',
176 'fileUploadExtensions',
177 array_keys($allowedUploadedFileExtensions)
178 );
179
180 if ($settingsService->getSetting('activation', 'stash') && self::$counter === 1) {
181 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
182
183 /** @var StashApplicationService $stashAS */
184 $stashAS = $container->get('application.stash.service');
185
186 wp_localize_script(
187 'amelia_booking_scripts',
188 'ameliaEntities',
189 $stashAS->getStash()
190 );
191 }
192
193 if (!empty($_GET['ameliaCache']) || !empty($_GET['ameliaWcCache'])) {
194 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
195
196 /** @var CacheApplicationService $cacheAS */
197 $cacheAS = $container->get('application.cache.service');
198
199 try {
200 $cacheData = !empty($_GET['ameliaCache']) ?
201 $cacheAS->getCacheByName(sanitize_text_field($_GET['ameliaCache'])) :
202 $cacheAS->getWcCacheByName(sanitize_text_field($_GET['ameliaWcCache']));
203
204 wp_localize_script(
205 'amelia_booking_scripts',
206 'ameliaCache',
207 [$cacheData ? str_replace('&quot;', '\\"', json_encode($cacheData)) : '']
208 );
209 } catch (QueryExecutionException $e) {
210 }
211 }
212
213 wp_localize_script(
214 'amelia_booking_scripts',
215 'wpAmeliaTimeZone',
216 [DateTimeService::getTimeZone()->getName()]
217 );
218
219 do_action('ameliaScriptsLoaded');
220 do_action('amelia_scripts_loaded');
221 }
222 }
223