PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 4 years ago CatalogBookingShortcodeService.php 2 years ago CatalogShortcodeService.php 4 years ago EventsCalendarBookingShortcodeService.php 1 year ago EventsListBookingShortcodeService.php 2 years ago EventsShortcodeService.php 3 years ago StepBookingShortcodeService.php 2 years ago
AmeliaShortcodeService.php
202 lines
1 <?php
2 /**
3 * @copyright © TMS-Plugins. All rights reserved.
4 * @licence See LICENCE.md for license details.
5 */
6
7 namespace AmeliaBooking\Infrastructure\WP\ShortcodeService;
8
9 use AmeliaBooking\Application\Services\Cache\CacheApplicationService;
10 use AmeliaBooking\Application\Services\CustomField\AbstractCustomFieldApplicationService;
11 use AmeliaBooking\Application\Services\Stash\StashApplicationService;
12 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
13 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
14 use AmeliaBooking\Domain\Services\Settings\SettingsService;
15 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
16 use AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage;
17 use AmeliaBooking\Infrastructure\WP\Translations\FrontendStrings;
18
19 /**
20 * Class AmeliaShortcodeService
21 *
22 * @package AmeliaBooking\Infrastructure\WP\ShortcodeService
23 */
24 class AmeliaShortcodeService
25 {
26 public static $counter = 0;
27
28 /**
29 * Prepare scripts and styles
30 * @throws InvalidArgumentException
31 * @throws \Interop\Container\Exception\ContainerException
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 // Enqueue Styles
80 wp_enqueue_style(
81 'amelia_booking_styles_vendor',
82 AMELIA_URL . 'public/css/frontend/vendor.css',
83 [],
84 AMELIA_VERSION
85 );
86
87 $customUrl = $settingsService->getSetting('activation', 'customUrl');
88
89 if ($settingsService->getSetting('customization', 'useGenerated') === null ||
90 $settingsService->getSetting('customization', 'useGenerated')
91 ) {
92 wp_enqueue_style(
93 'amelia_booking_styles',
94 (!empty($customUrl['uploadsPath']) ? $customUrl['uploadsPath'] : AMELIA_UPLOADS_URL) . '/amelia/css/amelia-booking.' .
95 $settingsService->getSetting('customization', 'hash') . '.css',
96 [],
97 AMELIA_VERSION
98 );
99 } else {
100 wp_enqueue_style(
101 'amelia_booking_styles',
102 AMELIA_URL . 'public/css/frontend/amelia-booking-' . str_replace('.', '-', AMELIA_VERSION) . '.css',
103 [],
104 AMELIA_VERSION
105 );
106 }
107
108 // Underscore
109 wp_enqueue_script('undescore', includes_url('js') . '/underscore.min.js');
110
111 // Strings Localization
112 wp_localize_script(
113 'amelia_booking_scripts',
114 'wpAmeliaLabels',
115 FrontendStrings::getAllStrings()
116 );
117
118 // Settings Localization
119 wp_localize_script(
120 'amelia_booking_scripts',
121 'wpAmeliaSettings',
122 $settingsService->getFrontendSettings()
123 );
124
125 wp_localize_script(
126 'amelia_booking_scripts',
127 'wpAmeliaUrls',
128 [
129 'wpAmeliaUseUploadsAmeliaPath' => AMELIA_UPLOADS_FILES_PATH_USE,
130 'wpAmeliaPluginURL' => empty($customUrl['enabled'])
131 ? AMELIA_URL : AMELIA_HOME_URL . $customUrl['pluginPath'],
132 'wpAmeliaPluginAjaxURL' => empty($customUrl['enabled'])
133 ? AMELIA_ACTION_URL : AMELIA_HOME_URL . $customUrl['ajaxPath'] . '?' . AMELIA_ACTION_SLUG . '',
134 ]
135 );
136
137 wp_localize_script(
138 'amelia_booking_scripts',
139 'localeLanguage',
140 [AMELIA_LOCALE]
141 );
142
143 $localeSubstitutes = $settingsService->getSetting('general', 'calendarLocaleSubstitutes');
144
145 if (isset($localeSubstitutes[AMELIA_LOCALE])) {
146 wp_localize_script(
147 'amelia_booking_scripts',
148 'ameliaCalendarLocale',
149 [$localeSubstitutes[AMELIA_LOCALE]]
150 );
151 }
152
153 wp_localize_script(
154 'amelia_booking_scripts',
155 'fileUploadExtensions',
156 array_keys(AbstractCustomFieldApplicationService::$allowedUploadedFileExtensions)
157 );
158
159 if ($settingsService->getSetting('activation', 'stash') && self::$counter === 1) {
160 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
161
162 /** @var StashApplicationService $stashAS */
163 $stashAS = $container->get('application.stash.service');
164
165 wp_localize_script(
166 'amelia_booking_scripts',
167 'ameliaEntities',
168 $stashAS->getStash()
169 );
170 }
171
172 if (!empty($_GET['ameliaCache']) || !empty($_GET['ameliaWcCache'])) {
173 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
174
175 /** @var CacheApplicationService $cacheAS */
176 $cacheAS = $container->get('application.cache.service');
177
178 try {
179 $cacheData = !empty($_GET['ameliaCache']) ?
180 $cacheAS->getCacheByName(sanitize_text_field($_GET['ameliaCache'])) :
181 $cacheAS->getWcCacheByName(sanitize_text_field($_GET['ameliaWcCache']));
182
183 wp_localize_script(
184 'amelia_booking_scripts',
185 'ameliaCache',
186 [$cacheData ? str_replace('&quot;', '\\"', json_encode($cacheData)) : '']
187 );
188 } catch (QueryExecutionException $e) {
189 }
190 }
191
192 wp_localize_script(
193 'amelia_booking_scripts',
194 'wpAmeliaTimeZone',
195 [DateTimeService::getTimeZone()->getName()]
196 );
197
198 do_action('ameliaScriptsLoaded');
199 do_action('amelia_scripts_loaded');
200 }
201 }
202