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 / AmeliaBookingShortcodeService.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
AmeliaBookingShortcodeService.php
267 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\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.42505216.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
204 /**
205 * @param string $tag
206 * @param string $handle
207 * @param string $src
208 *
209 * @return string
210 */
211 public static function prepareScripts($tag, $handle, $src)
212 {
213 switch ($handle) {
214 case ('amelia_booking_scripts_dev_vite'):
215 case ('amelia_booking_scripts_dev_main'):
216 return "<script type='module' src='{$src}'></script>";
217
218 case ('amelia_booking_script_index'):
219 $settingsService = new SettingsService(new SettingsStorage());
220
221 if ($settingsService->getSetting('activation', 'v3RelativePath')) {
222 $customUrl = $settingsService->getSetting('activation', 'customUrl');
223
224 $position = strpos($src, $customUrl['pluginPath'] . 'v3/public/assets/public.');
225
226 if ($position !== false) {
227 $src = substr($src, $position);
228 }
229 } elseif (strpos($src, 'http://') === 0) {
230 $src = substr($src, strpos(substr($src, 7), '/') + 7);
231 } elseif (strpos($src, 'https://') === 0) {
232 $src = substr($src, strpos(substr($src, 8), '/') + 8);
233 }
234
235 $asyncLoading = $settingsService->getSetting('activation', 'v3AsyncLoading') ?
236 'async' : '';
237
238 return "<script type='module' {$asyncLoading} crossorigin src='{$src}'></script>";
239
240 case ('amelia_booking_script_vendor'):
241 return "<link rel='modulepreload' href='{$src}'>";
242
243 default:
244 return $tag;
245 }
246 }
247
248 /**
249 * @param string $tag
250 * @param string $handle
251 * @param string $href
252 *
253 * @return string
254 */
255 public static function prepareStyles($tag, $handle, $href)
256 {
257 switch ($handle) {
258 case ('amelia_booking_style_index'):
259 case ('amelia_booking_style_vendor'):
260 return "<link rel='stylesheet' href='{$href}'>";
261
262 default:
263 return $tag;
264 }
265 }
266 }
267