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