PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.8
VikBooking Hotel Booking Engine & PMS v1.8.8
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / site / helpers / icons.php

icons.php in VikBooking Hotel Booking Engine & PMS 1.8.8, at site/helpers/icons.php

511 lines 17.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - E4J srl
6 * @copyright Copyright (C) 2026 E4J srl. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 /**
14 * Helper class to load webfont utilities and render font icons.
15 * Fonts supported are FontAwesome and IcoMoon.
16 *
17 * @since 1.11 (J) - 1.1 (WP)
18 * @since 1.18.8 (J) - 1.8.8 (WP) adopted FA 7.2.0 as default webfont library in favour of FA 5.12.1.
19 */
20 final class VikBookingIcons
21 {
22 /**
23 * The list of CSS files to load for the FontAwesome webfonts.
24 * To save up resources, we only load the solid and regular icon styles.
25 *
26 * @var array
27 */
28 public static $fa_default_styles = [
29 'fontawesome.min.css',
30 'solid.min.css',
31 'regular.min.css',
32 ];
33
34 /**
35 * Associative list of known webfont style assets and related (relative) URL.
36 *
37 * @var array
38 *
39 * @since 1.18.8 (J) - 1.8.8 (WP)
40 */
41 public static $fa_style_assets = [
42 'brands' => 'brands.min.css',
43 ];
44
45 /**
46 * The list of CSS files that can be loaded from remote CDN URLs.
47 *
48 * @var array
49 *
50 * @deprecated 1.18.8 (J) - 1.8.8 (WP)
51 */
52 public static $fa_remote_assets = [];
53
54 /**
55 * Default font style prefix (Solid).
56 *
57 * @var string
58 */
59 private static $fa_default_style = 'fas';
60
61 /**
62 * List of name-class pairs for the icons that need specific
63 * classes or adjustments in the current FontAwesome version.
64 *
65 * @var array
66 */
67 private static $fa_resolve_map = [
68 'calendar' => 'far fa-calendar-days',
69 'refresh' => 'fas fa-rotate',
70 'sync' => 'fas fa-arrows-rotate',
71 'external-link' => 'fas fa-arrow-up-right-from-square',
72 'external-link-square' => 'fas fa-square-up-right',
73 'sort-asc' => 'fas fa-sort-up',
74 'sort-desc' => 'fas fa-sort-down',
75 'commenting' => 'fas fa-comments',
76 'file-text' => 'far fa-file-lines',
77 'file-text-o' => 'fas fa-file-lines',
78 'sign-in' => 'fas fa-right-to-bracket',
79 'sign-out' => 'fas fa-right-from-bracket',
80 'edit' => 'far fa-pen-to-square',
81 'clock' => 'far fa-clock',
82 'clock-o' => 'fas fa-clock',
83 'calendar-check' => 'far fa-calendar-check',
84 'envelope-o' => 'far fa-envelope',
85 'mobile' => 'fas fa-mobile-screen-button',
86 'tablet' => 'fas fa-tablet-screen-button',
87 'pie-chart' => 'fas fa-chart-pie',
88 'credit-card' => 'far fa-credit-card',
89 'sticky-note' => 'fas fa-note-sticky',
90 'invoice' => 'fas fa-file-invoice',
91 'snowflake' => 'far fa-snowflake',
92 'long-arrow-up' => 'fas fa-arrow-up-long',
93 'long-arrow-right' => 'fas fa-arrow-right-long',
94 'long-arrow-down' => 'fas fa-arrow-down-long',
95 'long-arrow-left' => 'fas fa-arrow-left-long',
96 'th' => 'fas fa-table-cells',
97 'ellipsis-h' => 'fas fa-ellipsis',
98 'ellipsis-v' => 'fas fa-ellipsis-vertical',
99 'magic' => 'fas fa-wand-magic-sparkles',
100 'cog' => 'fas fa-gear',
101 'cogs' => 'fas fa-gears',
102 'user-cog' => 'fas fa-user-gear',
103
104 /**
105 * Resolving map used until the older FA v5.12.1.
106 *
107 '__fa5' => [
108 'calendar' => 'far fa-calendar-alt',
109 'refresh' => 'fas fa-sync-alt',
110 'external-link' => 'fas fa-external-link-alt',
111 'external-link-square' => 'fas fa-external-link-square-alt',
112 'sort-asc' => 'fas fa-sort-up',
113 'sort-desc' => 'fas fa-sort-down',
114 'commenting' => 'fas fa-comments',
115 'file-text' => 'fas fa-file-alt',
116 'file-text-o' => 'far fa-file-alt',
117 'sign-in' => 'fas fa-sign-in-alt',
118 'sign-out' => 'fas fa-sign-out-alt',
119 'edit' => 'far fa-edit',
120 'clock' => 'far fa-clock',
121 'clock-o' => 'far fa-clock',
122 'calendar-check' => 'far fa-calendar-check',
123 'envelope-o' => 'far fa-envelope',
124 'mobile' => 'fas fa-mobile-alt',
125 'tablet' => 'fas fa-tablet-alt',
126 'pie-chart' => 'fas fa-chart-pie',
127 'credit-card' => 'far fa-credit-card',
128 'sticky-note' => 'fas fa-sticky-note',
129 'invoice' => 'fas fa-file-invoice',
130 'snowflake' => 'far fa-snowflake',
131 'long-arrow-up' => 'fas fa-long-arrow-alt-up',
132 'long-arrow-right' => 'fas fa-long-arrow-alt-right',
133 'long-arrow-down' => 'fas fa-long-arrow-alt-down',
134 'long-arrow-left' => 'fas fa-long-arrow-alt-left',
135 ],
136 *
137 */
138 ];
139
140 /**
141 * Loads the necessary assets for the requested font family.
142 *
143 * @param string $font the font identifier to load
144 *
145 * @return void
146 *
147 * @since 1.16.5 (J) - 1.6.5 (WP) added event to implement custom loadings.
148 */
149 public static function loadAssets($font = 'fa')
150 {
151 $document = JFactory::getDocument();
152
153 // trigger event to allow third-party plugins to prevent this loading and to load custom assets
154 $load_assets = VBOFactory::getPlatform()->getDispatcher()->filter('onLoadFontAssets', [$document, $font]);
155 if ($load_assets === false) {
156 return;
157 }
158
159 $versioning = [
160 'version' => defined('VIKBOOKING_SOFTWARE_VERSION') ? VIKBOOKING_SOFTWARE_VERSION : '1.0',
161 ];
162
163 if ($font == 'fa') {
164 // get list of default asset files to load
165 $font_files = self::$fa_default_styles;
166 if (is_scalar($font_files)) {
167 $font_files = [$font_files];
168 }
169
170 // load files
171 $baseuri = VBO_SITE_URI . 'resources/';
172 foreach ($font_files as $kf => $ff) {
173 // we allow the use of an array with the URI expressed in the key
174 $useuri = !is_numeric($kf) ? $kf : $baseuri;
175 // load the file
176 $document->addStyleSheet($useuri . $ff, $versioning);
177 }
178 }
179
180 if ($font == 'icomoon') {
181 // we only need this file for IcoMoon
182 $document->addStyleSheet(VBO_ADMIN_URI . 'resources/fonts/vboicomoon.css', $versioning);
183 }
184 }
185
186 /**
187 * Loads a specific webfont stylesheet asset, usually not loaded by default.
188 *
189 * @param string $style Known style identifier or stylesheet URL.
190 *
191 * @return bool True if an asset was loaded, false otherwise.
192 *
193 * @since 1.18.8 (J) - 1.8.8 (WP)
194 */
195 public static function loadAssetStyle(string $style)
196 {
197 $document = JFactory::getDocument();
198
199 // trigger event to allow third-party plugins to prevent this loading and to load custom assets
200 $load_asset = VBOFactory::getPlatform()->getDispatcher()->filter('onLoadFontAssetStyle', [$document, $style]);
201 if ($load_asset === false) {
202 return false;
203 }
204
205 if (preg_match('/^http/', $style)) {
206 // load asset style URL
207 $document->addStyleSheet($style);
208 return true;
209 }
210
211 $versioning = [
212 'version' => defined('VIKBOOKING_SOFTWARE_VERSION') ? VIKBOOKING_SOFTWARE_VERSION : '1.0',
213 ];
214
215 if (self::$fa_style_assets[$style] ?? null) {
216 // load known and local webfont style asset
217 $document->addStyleSheet(VBO_SITE_URI . 'resources/' . self::$fa_style_assets[$style], $versioning);
218 return true;
219 }
220
221 return false;
222 }
223
224 /**
225 * Loads the remote assets from the CDN, if any, by invoking third-party plugins.
226 *
227 * @return bool
228 *
229 * @since 1.16.5 (J) - 1.6.5 (WP) added event to implement custom loadings.
230 * @since 1.18.8 (J) - 1.8.8 (WP) no more remote assets to load, FA brands asset loaded by default for BC.
231 *
232 * @see loadAssetStyle()
233 */
234 public static function loadRemoteAssets()
235 {
236 static $loaded = null;
237
238 if ($loaded !== null) {
239 return true;
240 }
241
242 $loaded = true;
243
244 $document = JFactory::getDocument();
245
246 // trigger event to allow third-party plugins to prevent this loading and to load custom assets
247 $load_assets = VBOFactory::getPlatform()->getDispatcher()->filter('onLoadFontRemoteAssets', [$document]);
248 if ($load_assets === false) {
249 return false;
250 }
251
252 /**
253 * For BC this method will no longer load remote assets, but it will
254 * rather load the FA "brands" style asset through the new method.
255 *
256 * @since 1.18.8 (J) - 1.8.8 (WP)
257 */
258 self::loadAssetStyle('brands');
259
260 // scan remote assets list property, even if empty by default
261 foreach (self::$fa_remote_assets as $cdn_url) {
262 $document->addStyleSheet($cdn_url);
263 }
264
265 return true;
266 }
267
268 /**
269 * Gets the proper class name for the icon depending on the type
270 * and on the FA version currently in use.
271 *
272 * @param string $type the icon identifier.
273 * @param string $classes a string with some optional classes.
274 * @param string $style optional font icon style ("fas", "fab"..).
275 *
276 * @return string the full class name of the icon to load.
277 *
278 * @since 1.16.5 (J) - 1.6.5 (WP) added 3rd argument $style.
279 */
280 public static function i($type, $classes = '', $style = '')
281 {
282 $classes = !empty($classes) ? ' ' . ltrim($classes) : $classes;
283
284 if (substr($type, 0, 6) == 'vboicn') {
285 // no mapping required for IcoMoon
286 return $type . $classes;
287 }
288
289 // we can force the loading of a specific (full) and exact class, like for brands, in this case just return it
290 if (substr($type, 0, 2) == 'fa' && strpos($type, ' ') > 2 && strpos($type, 'fa-') !== false && strlen($type) > 5) {
291 return "{$type}{$classes}";
292 }
293
294 // get the map to eventually adjust or override certain icons
295 $override_map = self::getOverridesMap();
296
297 if (isset($override_map[$type])) {
298 // this type of icon requires a specific class for the current FontAwesome version
299 return $override_map[$type] . $classes;
300 }
301
302 // build font style (default to solid "fas")
303 $fstyle = !empty($style) ? $style : self::getDefaultFontStyle();
304
305 // by default we use the solid style for the current FontAwesome version
306 return "{$fstyle} fa-{$type}{$classes}";
307 }
308
309 /**
310 * Echoes the requested icon string by passing all arguments to i().
311 *
312 * @return void
313 *
314 * @uses i()
315 */
316 public static function e()
317 {
318 $params = func_get_args();
319
320 $icn_class = call_user_func_array(['VikBookingIcons', 'i'], $params);
321
322 echo '<i class="' . $icn_class . '"></i>';
323 }
324
325 /**
326 * Returns a list of default font-icons for characteristics.
327 *
328 * @param array $exclude_html a list of HTML full i tags to exclude.
329 * @param string $extra_class the default extra class for the icon tags.
330 * @param bool $sort whether the icons should be sorted by name ASC.
331 *
332 * @return array a list of pre-set icons into associative arrays.
333 *
334 * @since 1.13.5
335 */
336 public static function loadCharacteristicsPreset($exclude_html = [], $extra_class = 'vbo-icn-carat', $sort = true)
337 {
338 $preset_icons = [
339 [
340 'name' => 'Square Meters',
341 'class' => self::i('cube', $extra_class),
342 ],
343 [
344 'name' => 'Swimming Pool',
345 'class' => self::i('swimming-pool', $extra_class),
346 ],
347 [
348 'name' => 'Wi-Fi',
349 'class' => self::i('wifi', $extra_class),
350 ],
351 [
352 'name' => 'TV',
353 'class' => self::i('tv', $extra_class),
354 ],
355 [
356 'name' => 'Air Conditioning',
357 'class' => self::i('snowflake', $extra_class),
358 ],
359 [
360 'name' => 'Mini Bar',
361 'class' => self::i('cocktail', $extra_class),
362 ],
363 [
364 'name' => 'Extra Bed',
365 'class' => self::i('bed', $extra_class),
366 ],
367 [
368 'name' => 'Disabled Access',
369 'class' => self::i('wheelchair', $extra_class),
370 ],
371 [
372 'name' => 'Bath',
373 'class' => self::i('bath', $extra_class),
374 ],
375 [
376 'name' => 'Shower',
377 'class' => self::i('shower', $extra_class),
378 ],
379 [
380 'name' => 'No Smoking',
381 'class' => self::i('smoking-ban', $extra_class),
382 ],
383 [
384 'name' => 'Smoking',
385 'class' => self::i('smoking', $extra_class),
386 ],
387 [
388 'name' => 'Coffee',
389 'class' => self::i('coffee', $extra_class),
390 ],
391 [
392 'name' => 'Tea Mug',
393 'class' => self::i('mug-hot', $extra_class),
394 ],
395 [
396 'name' => 'Kitchen Utensils',
397 'class' => self::i('utensils', $extra_class),
398 ],
399 [
400 'name' => 'Gift',
401 'class' => self::i('gift', $extra_class),
402 ],
403 [
404 'name' => 'Terrace',
405 'class' => self::i('umbrella-beach', $extra_class),
406 ],
407 [
408 'name' => 'Mountain',
409 'class' => self::i('mountain', $extra_class),
410 ],
411 [
412 'name' => 'Landscape',
413 'class' => self::i('image', $extra_class),
414 ],
415 [
416 'name' => 'Nature',
417 'class' => self::i('tree', $extra_class),
418 ],
419 [
420 'name' => 'City',
421 'class' => self::i('city', $extra_class),
422 ],
423 [
424 'name' => 'Sea',
425 'class' => self::i('water', $extra_class),
426 ],
427 ];
428
429 // check if some icons should be unset, maybe because already in use
430 $exclude_html = !is_array($exclude_html) ? [] : $exclude_html;
431 foreach ($exclude_html as $html) {
432 if (empty($html)) {
433 continue;
434 }
435 foreach ($preset_icons as $k => $v) {
436 if (strpos($html, $v['class']) !== false) {
437 // this class matches in the HTML passed, unset it
438 unset($preset_icons[$k]);
439 break;
440 }
441 }
442 }
443
444 // sort icons by name
445 if ($sort) {
446 $names_map = [];
447 foreach ($preset_icons as $k => $v) {
448 $names_map[$k] = $v['name'];
449 }
450 asort($names_map);
451 $sorted_preset = [];
452 foreach ($names_map as $k => $v) {
453 if (!isset($preset_icons[$k])) {
454 continue;
455 }
456 array_push($sorted_preset, $preset_icons[$k]);
457 }
458 $preset_icons = $sorted_preset;
459 }
460
461 // return the list
462 return $preset_icons;
463 }
464
465 /**
466 * Loads the font icons override map.
467 *
468 * @return array
469 *
470 * @since 1.16.5 (J) - 1.6.5 (WP).
471 */
472 private static function getOverridesMap()
473 {
474 static $icons_map = null;
475
476 if ($icons_map) {
477 return $icons_map;
478 }
479
480 $icons_map = self::$fa_resolve_map;
481
482 // trigger event to allow third-party plugins to override the icons map
483 VBOFactory::getPlatform()->getDispatcher()->trigger('onBuildFontOverridesMap', [&$icons_map]);
484
485 return $icons_map ?: [];
486 }
487
488 /**
489 * Gets the default font style.
490 *
491 * @return string
492 *
493 * @since 1.16.5 (J) - 1.6.5 (WP).
494 */
495 private static function getDefaultFontStyle()
496 {
497 static $icons_style = null;
498
499 if ($icons_style !== null) {
500 return $icons_style;
501 }
502
503 $icons_style = self::$fa_default_style;
504
505 // trigger event to allow third-party plugins to override the default icons style
506 VBOFactory::getPlatform()->getDispatcher()->trigger('onGetFontDefaultStyle', [&$icons_style]);
507
508 return (string) $icons_style;
509 }
510 }
511