PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.31
Booking for Appointments and Events Calendar – Amelia v1.2.31
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
219 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 if ($settingsService->getSetting('payments', 'square')['enabled'] === true) {
81 if ($settingsService->getSetting('payments', 'square')['testMode'] === true) {
82 wp_enqueue_script('amelia_square_js', 'https://sandbox.web.squarecdn.com/v1/square.js');
83 } else {
84 wp_enqueue_script('amelia_square_js', 'https://web.squarecdn.com/v1/square.js');
85 }
86 wp_enqueue_style(
87 'amelia_google_button_style',
88 'https://developers.google.com/reference/sdks/web/static/styles/code-preview.css',
89 [],
90 null,
91 'all'
92 );
93 }
94
95 // Enqueue Styles
96 wp_enqueue_style(
97 'amelia_booking_styles_vendor',
98 AMELIA_URL . 'public/css/frontend/vendor.css',
99 [],
100 AMELIA_VERSION
101 );
102
103 $customUrl = $settingsService->getSetting('activation', 'customUrl');
104
105 if (
106 $settingsService->getSetting('customization', 'useGenerated') === null ||
107 $settingsService->getSetting('customization', 'useGenerated')
108 ) {
109 wp_enqueue_style(
110 'amelia_booking_styles',
111 (!empty($customUrl['uploadsPath']) ? $customUrl['uploadsPath'] : AMELIA_UPLOADS_URL) . '/amelia/css/amelia-booking.' .
112 $settingsService->getSetting('customization', 'hash') . '.css',
113 [],
114 AMELIA_VERSION
115 );
116 } else {
117 wp_enqueue_style(
118 'amelia_booking_styles',
119 AMELIA_URL . 'public/css/frontend/amelia-booking-' . str_replace('.', '-', AMELIA_VERSION) . '.css',
120 [],
121 AMELIA_VERSION
122 );
123 }
124
125 // Underscore
126 wp_enqueue_script('undescore', includes_url('js') . '/underscore.min.js');
127
128 // Strings Localization
129 wp_localize_script(
130 'amelia_booking_scripts',
131 'wpAmeliaLabels',
132 FrontendStrings::getAllStrings()
133 );
134
135 // Settings Localization
136 wp_localize_script(
137 'amelia_booking_scripts',
138 'wpAmeliaSettings',
139 $settingsService->getFrontendSettings()
140 );
141
142 wp_localize_script(
143 'amelia_booking_scripts',
144 'wpAmeliaUrls',
145 [
146 'wpAmeliaUseUploadsAmeliaPath' => AMELIA_UPLOADS_FILES_PATH_USE,
147 'wpAmeliaPluginURL' => empty($customUrl['enabled'])
148 ? AMELIA_URL : AMELIA_HOME_URL . $customUrl['pluginPath'],
149 'wpAmeliaPluginAjaxURL' => empty($customUrl['enabled'])
150 ? AMELIA_ACTION_URL : AMELIA_HOME_URL . $customUrl['ajaxPath'] . '?' . AMELIA_ACTION_SLUG . '',
151 ]
152 );
153
154 wp_localize_script(
155 'amelia_booking_scripts',
156 'localeLanguage',
157 [AMELIA_LOCALE]
158 );
159
160 $localeSubstitutes = $settingsService->getSetting('general', 'calendarLocaleSubstitutes');
161
162 if (isset($localeSubstitutes[AMELIA_LOCALE])) {
163 wp_localize_script(
164 'amelia_booking_scripts',
165 'ameliaCalendarLocale',
166 [$localeSubstitutes[AMELIA_LOCALE]]
167 );
168 }
169
170 wp_localize_script(
171 'amelia_booking_scripts',
172 'fileUploadExtensions',
173 array_keys(AbstractCustomFieldApplicationService::$allowedUploadedFileExtensions)
174 );
175
176 if ($settingsService->getSetting('activation', 'stash') && self::$counter === 1) {
177 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
178
179 /** @var StashApplicationService $stashAS */
180 $stashAS = $container->get('application.stash.service');
181
182 wp_localize_script(
183 'amelia_booking_scripts',
184 'ameliaEntities',
185 $stashAS->getStash()
186 );
187 }
188
189 if (!empty($_GET['ameliaCache']) || !empty($_GET['ameliaWcCache'])) {
190 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
191
192 /** @var CacheApplicationService $cacheAS */
193 $cacheAS = $container->get('application.cache.service');
194
195 try {
196 $cacheData = !empty($_GET['ameliaCache']) ?
197 $cacheAS->getCacheByName(sanitize_text_field($_GET['ameliaCache'])) :
198 $cacheAS->getWcCacheByName(sanitize_text_field($_GET['ameliaWcCache']));
199
200 wp_localize_script(
201 'amelia_booking_scripts',
202 'ameliaCache',
203 [$cacheData ? str_replace('&quot;', '\\"', json_encode($cacheData)) : '']
204 );
205 } catch (QueryExecutionException $e) {
206 }
207 }
208
209 wp_localize_script(
210 'amelia_booking_scripts',
211 'wpAmeliaTimeZone',
212 [DateTimeService::getTimeZone()->getName()]
213 );
214
215 do_action('ameliaScriptsLoaded');
216 do_action('amelia_scripts_loaded');
217 }
218 }
219