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 / AmeliaBookingShortcodeService.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
AmeliaBookingShortcodeService.php
272 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\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\Repository\CustomField\CustomFieldRepository;
17 use AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage;
18 use AmeliaBooking\Infrastructure\WP\Translations\FrontendStrings;
19 use Interop\Container\Exception\ContainerException;
20
21 /**
22 * Class AmeliaBookingShortcodeService
23 *
24 * @package AmeliaBooking\Infrastructure\WP\ShortcodeService
25 */
26 class AmeliaBookingShortcodeService
27 {
28 public static $counter = 1000;
29
30 /**
31 * Prepare scripts and styles
32 * @throws ContainerException
33 * @throws InvalidArgumentException
34 */
35 public static function prepareScriptsAndStyles()
36 {
37 $container = null;
38
39 self::$counter++;
40
41 if (self::$counter > 1001) {
42 return;
43 }
44
45 $settingsService = new SettingsService(new SettingsStorage());
46
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', 'stripe')['enabled'] === true) {
52 wp_enqueue_script('amelia_stripe_script', 'https://js.stripe.com/v3/');
53 }
54
55 if ($settingsService->getSetting('payments', 'square')['enabled'] === true) {
56 if ($settingsService->getSetting('payments', 'square')['testMode'] === true) {
57 wp_enqueue_script('amelia_square_js', 'https://sandbox.web.squarecdn.com/v1/square.js');
58 } else {
59 wp_enqueue_script('amelia_square_js', 'https://web.squarecdn.com/v1/square.js');
60 }
61 wp_enqueue_style(
62 'amelia_google_button_style',
63 'https://developers.google.com/reference/sdks/web/static/styles/code-preview.css',
64 [],
65 null,
66 'all'
67 );
68 }
69
70 if ($settingsService->getSetting('payments', 'razorpay')['enabled'] === true) {
71 wp_enqueue_script('amelia_razorpay_script', 'https://checkout.razorpay.com/v1/checkout.js');
72 }
73
74 $gmapApiKey = $settingsService->getSetting('general', 'gMapApiKey');
75
76 if ($gmapApiKey) {
77 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
78
79 /** @var CustomFieldRepository $customFieldRepository */
80 $customFieldRepository = $container->get('domain.customField.repository');
81
82 $addressCustomFields = $customFieldRepository->getByFieldValue('type', 'address');
83
84 if (count($addressCustomFields->getItems())) {
85 wp_enqueue_script(
86 'amelia_google_maps_api',
87 "https://maps.googleapis.com/maps/api/js?key={$gmapApiKey}&libraries=places&loading=async"
88 );
89 }
90 }
91
92 $scriptId = AMELIA_DEV ? 'amelia_booking_scripts_dev_vite' : 'amelia_booking_script_index';
93
94 if (AMELIA_DEV) {
95 wp_enqueue_script(
96 $scriptId,
97 'http://localhost:3000/@vite/client',
98 [],
99 null,
100 false
101 );
102
103 wp_enqueue_script(
104 'amelia_booking_scripts_dev_main',
105 'http://localhost:3000/src/assets/js/public/public.js',
106 [],
107 null,
108 true
109 );
110 } else {
111 wp_enqueue_script(
112 $scriptId,
113 AMELIA_URL . 'v3/public/assets/public.211276a3.js',
114 [],
115 AMELIA_VERSION,
116 true
117 );
118 }
119
120 $ameliaLocale = apply_filters('amelia_modify_locale_filter', AMELIA_LOCALE) ?: AMELIA_LOCALE;
121
122 wp_localize_script(
123 $scriptId,
124 'localeLanguage',
125 [$ameliaLocale]
126 );
127
128 wp_localize_script(
129 $scriptId,
130 'wpAmeliaSettings',
131 $settingsService->getFrontendSettings()
132 );
133
134 // Strings Localization
135 wp_localize_script(
136 $scriptId,
137 'wpAmeliaLabels',
138 FrontendStrings::getAllStrings()
139 );
140
141 wp_localize_script(
142 $scriptId,
143 'wpAmeliaTimeZone',
144 [DateTimeService::getTimeZone()->getName()]
145 );
146
147 $ameliaUrl = AMELIA_URL;
148
149 $ameliaActionUrl = AMELIA_ACTION_URL;
150
151 if (strpos($ameliaUrl, 'http://') === 0) {
152 $ameliaUrl = substr($ameliaUrl, strpos(substr($ameliaUrl, 7), '/') + 7);
153
154 $ameliaActionUrl = substr($ameliaActionUrl, strpos(substr($ameliaActionUrl, 7), '/') + 7);
155 } elseif (strpos($ameliaUrl, 'https://') === 0) {
156 $ameliaUrl = substr($ameliaUrl, strpos(substr($ameliaUrl, 8), '/') + 8);
157
158 $ameliaActionUrl = substr($ameliaActionUrl, strpos(substr($ameliaActionUrl, 8), '/') + 8);
159 }
160
161 wp_localize_script(
162 $scriptId,
163 'wpAmeliaUrls',
164 [
165 'wpAmeliaUseUploadsAmeliaPath' => AMELIA_UPLOADS_FILES_PATH_USE,
166 'wpAmeliaPluginURL' => $ameliaUrl,
167 'wpAmeliaPluginAjaxURL' => $ameliaActionUrl,
168 ]
169 );
170
171 if (!empty($_GET['ameliaCache']) || !empty($_GET['ameliaWcCache'])) {
172 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
173
174 /** @var CacheApplicationService $cacheAS */
175 $cacheAS = $container->get('application.cache.service');
176
177 try {
178 $cacheData = !empty($_GET['ameliaCache']) ?
179 $cacheAS->getCacheByName($_GET['ameliaCache']) : $cacheAS->getWcCacheByName($_GET['ameliaWcCache']);
180
181 wp_localize_script(
182 $scriptId,
183 'ameliaCache',
184 [$cacheData ? str_replace('&quot;', '\\"', json_encode($cacheData)) : '']
185 );
186 } catch (QueryExecutionException $e) {
187 }
188 }
189
190 if ($settingsService->getSetting('activation', 'stash')) {
191 $container = $container ?: require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
192
193 /** @var StashApplicationService $stashAS */
194 $stashAS = $container->get('application.stash.service');
195
196 wp_localize_script(
197 $scriptId,
198 'ameliaEntities',
199 $stashAS->getStash()
200 );
201 }
202
203 do_action('amelia_scripts_loaded');
204 }
205
206 /**
207 * @param string $tag
208 * @param string $handle
209 * @param string $src
210 *
211 * @return string
212 */
213 public static function prepareScripts($tag, $handle, $src)
214 {
215 switch ($handle) {
216 case ('amelia_booking_scripts_dev_vite'):
217 case ('amelia_booking_scripts_dev_main'):
218 case ('amelia_dev_vite_client'):
219 case ('amelia_dev_main_script'):
220 case ('amelia_prod_main_script'):
221 return "<script type='module' src='{$src}'></script>";
222
223 case ('amelia_booking_script_index'):
224 $settingsService = new SettingsService(new SettingsStorage());
225
226 if ($settingsService->getSetting('activation', 'v3RelativePath')) {
227 $customUrl = $settingsService->getSetting('activation', 'customUrl');
228
229 $position = strpos($src, $customUrl['pluginPath'] . 'v3/public/assets/public.');
230
231 if ($position !== false) {
232 $src = substr($src, $position);
233 }
234 } elseif (strpos($src, 'http://') === 0) {
235 $src = substr($src, strpos(substr($src, 7), '/') + 7);
236 } elseif (strpos($src, 'https://') === 0) {
237 $src = substr($src, strpos(substr($src, 8), '/') + 8);
238 }
239
240 $asyncLoading = $settingsService->getSetting('activation', 'v3AsyncLoading') ?
241 'async' : '';
242
243 return "<script type='module' {$asyncLoading} crossorigin src='{$src}'></script>";
244
245 case ('amelia_booking_script_vendor'):
246 return "<link rel='modulepreload' href='{$src}'>";
247
248 default:
249 return $tag;
250 }
251 }
252
253 /**
254 * @param string $tag
255 * @param string $handle
256 * @param string $href
257 *
258 * @return string
259 */
260 public static function prepareStyles($tag, $handle, $href)
261 {
262 switch ($handle) {
263 case ('amelia_booking_style_index'):
264 case ('amelia_booking_style_vendor'):
265 return "<link rel='stylesheet' href='{$href}'>";
266
267 default:
268 return $tag;
269 }
270 }
271 }
272