PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.5
VikBooking Hotel Booking Engine & PMS v1.6.5
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.6.5, at site/helpers/icons.php

426 lines 11.1 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 - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. 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 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.
17 *
18 * @since 1.11 (J) - 1.1 (WP)
19 */
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;
28
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 ];
47
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 ];
57
58 /**
59 * Default font style prefix (Solid).
60 *
61 * @var string
62 */
63 private static $fa_default_style = 'fas';
64
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 ];
100
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();
113
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 }
119
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 }
126
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 }
136
137 if ($font == 'icomoon') {
138 // we only need this file for IcoMoon
139 $document->addStyleSheet(VBO_ADMIN_URI . 'resources/fonts/vboicomoon.css');
140 }
141 }
142
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();
153
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 }
159
160 if (self::$fa_use_legacy) {
161 return flase;
162 }
163
164 foreach (self::$fa_remote_assets_latest as $cdn_url) {
165 $document->addStyleSheet($cdn_url);
166 }
167
168 return true;
169 }
170
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;
186
187 if (substr($type, 0, 6) == 'vboicn') {
188 // no mapping required for IcoMoon
189 return $type . $classes;
190 }
191
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 }
200
201 return "{$type}{$classes}";
202 }
203
204 if (self::$fa_use_legacy) {
205 // FontAwesome 4.7 had no solid or regular styles
206 return "fa fa-{$type}{$classes}";
207 }
208
209 // get the map to eventually adjust or override certain icons
210 $override_map = self::getOverridesMap();
211
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 }
216
217 // build font style (default to solid "fas")
218 $fstyle = !empty($style) ? $style : self::getDefaultFontStyle();
219
220 // by default we use the solid style for the latest FontAwesome version
221 return "{$fstyle} fa-{$type}{$classes}";
222 }
223
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();
234
235 $icn_class = call_user_func_array(['VikBookingIcons', 'i'], $params);
236
237 echo '<i class="' . $icn_class . '"></i>';
238 }
239
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 ];
343
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 }
358
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 }
375
376 // return the list
377 return $preset_icons;
378 }
379
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;
390
391 if ($icons_map) {
392 return $icons_map;
393 }
394
395 $icons_map = self::$fa_latest_map;
396
397 // trigger event to allow third-party plugins to override the icons map
398 VBOFactory::getPlatform()->getDispatcher()->trigger('onBuildFontOverridesMap', [&$icons_map]);
399
400 return $icons_map ?: [];
401 }
402
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;
413
414 if ($icons_style !== null) {
415 return $icons_style;
416 }
417
418 $icons_style = self::$fa_default_style;
419
420 // trigger event to allow third-party plugins to override the default icons style
421 VBOFactory::getPlatform()->getDispatcher()->trigger('onGetFontDefaultStyle', [&$icons_style]);
422
423 return (string)$icons_style;
424 }
425 }
426