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 / libraries / wordpress / version.php

version.php in VikBooking Hotel Booking Engine & PMS 1.6.4, at libraries/wordpress/version.php

469 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking - Libraries
4 * @subpackage wordpress
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2018 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 // do nothing if the class already exists
15 if (!class_exists('VersionListener'))
16 {
17 /**
18 * Version recognizer class to identify which platform version is running.
19 *
20 * @see JVersion Used to identify the installed platform version.
21 *
22 * @since 1.6
23 */
24 class VersionListener
25 {
26 /**
27 * The platform name.
28 *
29 * @var string
30 * @since 1.6.3
31 */
32 private static $platform = null;
33
34 /**
35 * The platform version.
36 *
37 * @var string
38 * @since 1.6.3
39 */
40 private static $version = null;
41
42 /**
43 * The identifier of the platform version.
44 *
45 * @var integer
46 */
47 private static $id = null;
48
49 /**
50 * Class constructor.
51 */
52 private function __construct()
53 {
54 // not accessible
55 }
56
57 /**
58 * Class cloner.
59 */
60 private function __clone()
61 {
62 // not accessible
63 }
64
65 /**
66 * Returns the current platform name.
67 *
68 * @return string The platform name.
69 *
70 * @since 1.6.3
71 */
72 public static function getPlatform()
73 {
74 if (self::$platform === null)
75 {
76 if (defined('WPINC'))
77 {
78 // wordpress is installed
79 self::$platform = 'wordpress';
80 }
81 else if (defined('_JEXEC'))
82 {
83 // joomla is installed
84 self::$platform = 'joomla';
85 }
86 else
87 {
88 // platform not supported
89 $self::$platform = false;
90 }
91 }
92
93 return self::$platform;
94 }
95
96 /**
97 * Checks if the current platform is Wordpress.
98 *
99 * @return boolean
100 *
101 * @since 1.6.3
102 */
103 public static function isWordpress()
104 {
105 return self::getPlatform() === 'wordpress';
106 }
107
108 /**
109 * Checks if the current platform is Wordpress.
110 *
111 * @return boolean
112 *
113 * @since 1.6.3
114 */
115 public static function isJoomla()
116 {
117 return self::getPlatform() === 'joomla';
118 }
119
120 /**
121 * Returns the current platform version.
122 *
123 * @return string The platform version.
124 *
125 * @since 1.6.3
126 */
127 public static function getVersion()
128 {
129 if (self::$version === null)
130 {
131 $version = new JVersion();
132 self::$version = $version->getShortVersion();
133 }
134
135 return self::$version;
136 }
137
138 /**
139 * Recognizes the Joomla version and return the respective indetifier.
140 *
141 * @return integer The identifier of the Joomla version.
142 */
143 public static function getID()
144 {
145 if (self::$id === null)
146 {
147 // UNSUPPORTED flag will be overridden (if supported)
148 self::$id = self::UNSUPPORTED;
149
150 if (class_exists('JVersion'))
151 {
152 // get platform version
153 $v = static::getVersion();
154
155 if (static::isJoomla())
156 {
157 // get Joomla version identifier
158 self::$id = static::getJoomlaID($v);
159 }
160 else if (static::isWordpress())
161 {
162 // get Wordpress version identifier
163 self::$id = static::getWordpressID($v);
164 }
165 }
166 }
167
168 return self::$id;
169 }
170
171 /**
172 * Detects the current Wordpress version constant.
173 *
174 * @param string $v The platform short version.
175 *
176 * @return integer The version constant.
177 *
178 * @since 1.6.3
179 */
180 protected static function getWordpressID($v)
181 {
182 if (version_compare($v, '4.0') >= 0 && version_compare($v, '5.0') < 0)
183 {
184 // wordpress 4.0
185 return self::WP4;
186 }
187 else if (version_compare($v, '5.0') >= 0)
188 {
189 // wordpress 5.0
190 return self::WP5;
191 }
192
193 // fallback to Wordpress 3.0 or lower
194 return self::WP3;
195 }
196
197 /**
198 * Detects the current Joomla! version constant.
199 *
200 * @param string $v The platform short version.
201 *
202 * @return integer The version constant.
203 *
204 * @since 1.6.3
205 */
206 protected static function getJoomlaID($v)
207 {
208 if (version_compare($v, '2.5') >= 0 && version_compare($v, '3.0') < 0)
209 {
210 // joomla 2.5
211 return self::J25;
212 }
213 else if (version_compare($v, '3.0') >= 0 && version_compare($v, '3.5') < 0)
214 {
215 // joomla 3.0, 3.1, 3.2, 3.3, 3.4
216 return self::J30;
217 }
218 else if (version_compare($v, '3.5') >= 0 && version_compare($v, '3.7') < 0)
219 {
220 // joomla 3.5, 3.6
221 return self::J35;
222 }
223 else if (version_compare($v, '3.7') >= 0 && version_compare($v, '4.0') < 0)
224 {
225 // joomla 3.7, 3.8, 3.9
226 return self::J37;
227 }
228 else if (version_compare($v, '4.0') >= 0)
229 {
230 // joomla 4.0
231 return self::J40;
232 }
233
234 // fallback to Joomla 1.5
235 return self::J15;
236 }
237
238 /**
239 * Checks if the installed Joomla is 1.5 or 1.6.
240 *
241 * @return boolean True if Joomla is 1.5 or 1.6, otherwise false.
242 */
243 public static function isJoomla15()
244 {
245 return self::getID() == self::J15;
246 }
247
248 /**
249 * Checks if the installed Joomla is 2.5.
250 *
251 * @return boolean True if Joomla is 2.5, otherwise false.
252 */
253 public static function isJoomla25()
254 {
255 return self::getID() == self::J25;
256 }
257
258 /**
259 * Checks if the installed Joomla is 3.x.
260 *
261 * @return boolean True if Joomla is between 3.0 and 4.0 (excluded), otherwise false.
262 *
263 * @since 1.8.3
264 */
265 public static function isJoomla3x()
266 {
267 return self::isJoomla30() || self::isJoomla35() || self::isJoomla37();
268 }
269
270 /**
271 * Checks if the installed Joomla is between 3.0 and 3.4.
272 *
273 * @return boolean True if Joomla is between 3.0 and 3.4, otherwise false.
274 */
275 public static function isJoomla30()
276 {
277 return self::getID() == self::J30;
278 }
279
280 /**
281 * Checks if the installed Joomla is between 3.5 and 4.0 (excluded).
282 *
283 * @return boolean True if Joomla is between 3.0 and 4.0 (excluded), otherwise false.
284 */
285 public static function isJoomla35()
286 {
287 return self::getID() == self::J35;
288 }
289
290 /**
291 * Checks if the installed Joomla is 3.7 or higher.
292 *
293 * @return boolean True if Joomla is 3.7 or higher, otherwise false.
294 */
295 public static function isJoomla37()
296 {
297 return self::getID() == self::J37;
298 }
299
300 /**
301 * Checks if the installed Joomla is 4.x.
302 *
303 * @return boolean True if Joomla is between 4.0 and 5.0 (excluded), otherwise false.
304 *
305 * @since 1.8.3
306 */
307 public static function isJoomla4x()
308 {
309 return self::isJoomla40();
310 }
311
312 /**
313 * Checks if the installed Joomla is 4.0 or higher.
314 *
315 * @return boolean True if Joomla is 4.0 or higher, otherwise false.
316 */
317 public static function isJoomla40()
318 {
319 return self::getID() == self::J40;
320 }
321
322 /**
323 * Checks if the installed Wordpress is 4.0 or higher.
324 *
325 * @return boolean True if Wordpress is 4.0 or higher, otherwise false.
326 */
327 public static function isWordpress4()
328 {
329 return self::getID() == self::WP4;
330 }
331
332 /**
333 * Checks if the installed Wordpress is 5.0 or higher.
334 *
335 * @return boolean True if Wordpress is 5.0 or higher, otherwise false.
336 */
337 public static function isWordpress5()
338 {
339 return self::getID() == self::WP5;
340 }
341
342 /**
343 * Checks if the installed Joomla is supported.
344 * The Joomla version is not supported when the class is not able
345 * to recognize the installed version.
346 *
347 * @return boolean True if the Joomla version is supported, otherwise false.
348 */
349 public static function isSupported()
350 {
351 return self::getID() != self::UNSUPPORTED;
352 }
353
354 /**
355 * Check if the current Joomla version is higher than the provided one.
356 *
357 * @param mixed The version to check.
358 * - int The platform ID will be compared;
359 * - string The platform version will be compared.
360 *
361 * @return boolean True if the current version is higher, otherwise false.
362 */
363 public static function isHigherThan($version)
364 {
365 if (is_int($version))
366 {
367 // compare platform ID only if an int was passed
368 return self::getID() > $version;
369 }
370
371 // compare current version with provided version
372 return version_compare(static::getVersion(), $version, '>');
373 }
374
375 /**
376 * Check if the current Joomla version is lower than the provided one.
377 *
378 * @param mixed The version to check.
379 * - int The platform ID will be compared;
380 * - string The platform version will be compared.
381 *
382 * @return boolean True if the current version is lower, otherwise false.
383 */
384 public static function isLowerThan($version)
385 {
386 if (is_int($version))
387 {
388 return self::getID() < $version;
389 }
390
391 // compare current version with provided version
392 return version_compare(static::getVersion(), $version, '<');
393 }
394
395 /**
396 * The UNSUPPORTED version identifier.
397 *
398 * @var integer
399 */
400 const UNSUPPORTED = -1;
401
402 /**
403 * The Joomla 1.5 version identifier.
404 *
405 * @var integer
406 */
407 const J15 = 0;
408
409 /**
410 * The Joomla 2.5 version identifier.
411 *
412 * @var integer
413 */
414 const J25 = 1;
415
416 /**
417 * The Joomla 3.0 to 3.4 version identifier.
418 *
419 * @var integer
420 */
421 const J30 = 2;
422
423 /**
424 * The Joomla 3.5 to 4.0 (excluded) version identifier.
425 *
426 * @var integer
427 */
428 const J35 = 3;
429
430 /**
431 * The Joomla 3.7 version identifier.
432 *
433 * @var integer
434 */
435 const J37 = 4;
436
437 /**
438 * The Joomla 4.0 version identifier.
439 *
440 * @var integer
441 */
442 const J40 = 5;
443
444 /**
445 * The Wordpress 3.0 version identifier.
446 *
447 * @var integer
448 * @since 1.6.3
449 */
450 const WP3 = 0;
451
452 /**
453 * The Wordpress 4.0 version identifier.
454 *
455 * @var integer
456 * @since 1.6.3
457 */
458 const WP4 = 1;
459
460 /**
461 * The Wordpress 5.0 version identifier.
462 *
463 * @var integer
464 * @since 1.6.3
465 */
466 const WP5 = 2;
467 }
468 }
469