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

345 lines 8.8 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
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 = array(
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 = array(
55 'https://use.fontawesome.com/releases/v5.12.1/css/brands.css',
56 );
57
58 /**
59 * List of type-classes pairs for the icons that need specific
60 * classes (not solid) in the latest FontAwesome version.
61 *
62 * @var array
63 */
64 private static $fa_latest_map = array(
65 'calendar' => 'far fa-calendar-alt',
66 'refresh' => 'fas fa-sync-alt',
67 'external-link' => 'fas fa-external-link-alt',
68 'external-link-square' => 'fas fa-external-link-square-alt',
69 'sort-asc' => 'fas fa-sort-up',
70 'sort-desc' => 'fas fa-sort-down',
71 'commenting' => 'fas fa-comments',
72 'file-text' => 'fas fa-file-alt',
73 'file-text-o' => 'far fa-file-alt',
74 'sign-in' => 'fas fa-sign-in-alt',
75 'sign-out' => 'fas fa-sign-out-alt',
76 'edit' => 'far fa-edit',
77 'clock' => 'far fa-clock',
78 'clock-o' => 'far fa-clock',
79 'calendar-check' => 'far fa-calendar-check',
80 'envelope-o' => 'far fa-envelope',
81 'mobile' => 'fas fa-mobile-alt',
82 'tablet' => 'fas fa-tablet-alt',
83 'pie-chart' => 'fas fa-chart-pie',
84 'credit-card' => 'far fa-credit-card',
85 'sticky-note' => 'fas fa-sticky-note',
86 'invoice' => 'fas fa-file-invoice',
87 'snowflake' => 'far fa-snowflake',
88 );
89
90 /**
91 * Loads the necessary assets for the requested font family.
92 *
93 * @param string $font the font identifier to load
94 *
95 * @return void
96 */
97 public static function loadAssets($font = 'fa')
98 {
99 $document = JFactory::getDocument();
100
101 if ($font == 'fa') {
102
103 // get list of assets files to load
104 $font_files = self::$fa_use_legacy ? self::$fa_file_v47 : self::$fa_file_latest;
105 if (is_scalar($font_files)) {
106 $font_files = array($font_files);
107 }
108
109 // load files
110 $baseuri = VBO_SITE_URI.'resources/';
111 foreach ($font_files as $kf => $ff) {
112 // we allow the use of an array with the URI expressed in the key
113 $useuri = !is_numeric($kf) ? $kf : $baseuri;
114 // load the file
115 $document->addStyleSheet($useuri.$ff);
116 }
117 }
118
119 if ($font == 'icomoon') {
120 // we only need this file for IcoMoon
121 $document->addStyleSheet(VBO_ADMIN_URI . 'resources/fonts/vboicomoon.css');
122 }
123 }
124
125 /**
126 * Loads the remote assets from the CDN.
127 *
128 * @return boolean
129 */
130 public static function loadRemoteAssets()
131 {
132 if (self::$fa_use_legacy) {
133 return flase;
134 }
135
136 $document = JFactory::getDocument();
137
138 foreach (self::$fa_remote_assets_latest as $cdn_url) {
139 $document->addStyleSheet($cdn_url);
140 }
141
142 return true;
143 }
144
145 /**
146 * Gets the proper class name for the icon depending on the type
147 * and on the FA version currently in use.
148 *
149 * @param string $type the icon identifier
150 * @param string $classes a string with some optional classes
151 *
152 * @return string the full class name of the icon to load.
153 */
154 public static function i($type, $classes = '')
155 {
156 $classes = !empty($classes) ? ' '.ltrim($classes) : $classes;
157
158 if (substr($type, 0, 6) == 'vboicn') {
159 // no mapping required for IcoMoon
160 return $type.$classes;
161 }
162
163 // we can force the loading of a specific (full) and exact class, like for brands, in this case just return it
164 if (substr($type, 0, 2) == 'fa' && strpos($type, ' ') > 2 && strpos($type, 'fa-') !== false && strlen($type) > 5) {
165 // this is something like fas, far or fab, so we just print that
166 if (self::$fa_use_legacy) {
167 // strip anything that is not fa
168 $extratype = substr($type, 2, 1);
169 $type = str_replace('fa'.$extratype, 'fa', $type);
170 }
171
172 return "{$type}{$classes}";
173 }
174
175 if (self::$fa_use_legacy) {
176 // FontAwesome 4.7 had no solid or regular styles
177 return "fa fa-{$type}{$classes}";
178 }
179
180 if (isset(self::$fa_latest_map[$type])) {
181 // this type of icon requires a specific class for the latest FontAwesome version
182 return self::$fa_latest_map[$type].$classes;
183 }
184
185 // by default we use the solid style for the latest FontAwesome version
186 return "fas fa-{$type}{$classes}";
187 }
188
189 /**
190 * Echoes the requested icon string by passing all arguments to i().
191 *
192 * @return void
193 *
194 * @uses i()
195 */
196 public static function e()
197 {
198 $params = func_get_args();
199
200 $icn_class = call_user_func_array(array('VikBookingIcons', 'i'), $params);
201
202 echo '<i class="'.$icn_class.'"></i>';
203 }
204
205 /**
206 * Returns a list of default font-icons for characteristics.
207 *
208 * @param array $exclude_html a list of HTML full i tags to exclude.
209 * @param string $extra_class the default extra class for the icon tags.
210 * @param bool $sort whether the icons should be sorted by name ASC.
211 *
212 * @return array a list of pre-set icons into associative arrays.
213 *
214 * @since 1.13.5
215 */
216 public static function loadCharacteristicsPreset($exclude_html = array(), $extra_class = 'vbo-icn-carat', $sort = true)
217 {
218 $preset_icons = array(
219 array(
220 'name' => 'Square Meters',
221 'class' => self::i('cube', $extra_class),
222 ),
223 array(
224 'name' => 'Swimming Pool',
225 'class' => self::i('swimming-pool', $extra_class),
226 ),
227 array(
228 'name' => 'Wi-Fi',
229 'class' => self::i('wifi', $extra_class),
230 ),
231 array(
232 'name' => 'TV',
233 'class' => self::i('tv', $extra_class),
234 ),
235 array(
236 'name' => 'Air Conditioning',
237 'class' => self::i('snowflake', $extra_class),
238 ),
239 array(
240 'name' => 'Mini Bar',
241 'class' => self::i('cocktail', $extra_class),
242 ),
243 array(
244 'name' => 'Extra Bed',
245 'class' => self::i('bed', $extra_class),
246 ),
247 array(
248 'name' => 'Disabled Access',
249 'class' => self::i('wheelchair', $extra_class),
250 ),
251 array(
252 'name' => 'Bath',
253 'class' => self::i('bath', $extra_class),
254 ),
255 array(
256 'name' => 'Shower',
257 'class' => self::i('shower', $extra_class),
258 ),
259 array(
260 'name' => 'No Smoking',
261 'class' => self::i('smoking-ban', $extra_class),
262 ),
263 array(
264 'name' => 'Smoking',
265 'class' => self::i('smoking', $extra_class),
266 ),
267 array(
268 'name' => 'Coffee',
269 'class' => self::i('coffee', $extra_class),
270 ),
271 array(
272 'name' => 'Tea Mug',
273 'class' => self::i('mug-hot', $extra_class),
274 ),
275 array(
276 'name' => 'Kitchen Utensils',
277 'class' => self::i('utensils', $extra_class),
278 ),
279 array(
280 'name' => 'Gift',
281 'class' => self::i('gift', $extra_class),
282 ),
283 array(
284 'name' => 'Terrace',
285 'class' => self::i('umbrella-beach', $extra_class),
286 ),
287 array(
288 'name' => 'Mountain',
289 'class' => self::i('mountain', $extra_class),
290 ),
291 array(
292 'name' => 'Landscape',
293 'class' => self::i('image', $extra_class),
294 ),
295 array(
296 'name' => 'Nature',
297 'class' => self::i('tree', $extra_class),
298 ),
299 array(
300 'name' => 'City',
301 'class' => self::i('city', $extra_class),
302 ),
303 array(
304 'name' => 'Sea',
305 'class' => self::i('water', $extra_class),
306 ),
307 );
308
309 // check if some icons should be unset, maybe because already in use
310 $exclude_html = !is_array($exclude_html) ? array() : $exclude_html;
311 foreach ($exclude_html as $html) {
312 if (empty($html)) {
313 continue;
314 }
315 foreach ($preset_icons as $k => $v) {
316 if (strpos($html, $v['class']) !== false) {
317 // this class matches in the HTML passed, unset it
318 unset($preset_icons[$k]);
319 break;
320 }
321 }
322 }
323
324 // sort icons by name
325 if ($sort) {
326 $names_map = array();
327 foreach ($preset_icons as $k => $v) {
328 $names_map[$k] = $v['name'];
329 }
330 asort($names_map);
331 $sorted_preset = array();
332 foreach ($names_map as $k => $v) {
333 if (!isset($preset_icons[$k])) {
334 continue;
335 }
336 array_push($sorted_preset, $preset_icons[$k]);
337 }
338 $preset_icons = $sorted_preset;
339 }
340
341 // return the list
342 return $preset_icons;
343 }
344 }
345