| @@ -1,0 +1,88 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * @package VikBooking | |
| 4 | + * @subpackage core | |
| 5 | + * @author E4J s.r.l. | |
| 6 | + * @copyright Copyright (C) 2023 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 | +/** | |
| 15 | + * Detects the platform on which the system is running. | |
| 16 | + * | |
| 17 | + * @since 1.16.1 (J) - 1.6.1 (WP) | |
| 18 | + */ | |
| 19 | +final class VBOPlatformDetection | |
| 20 | +{ | |
| 21 | + /** | |
| 22 | + * @var string | |
| 23 | + */ | |
| 24 | + private static $platform = ''; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * Tells whether the current platform is WordPress. | |
| 28 | + * | |
| 29 | + * @return bool | |
| 30 | + */ | |
| 31 | + public static function isWordPress() | |
| 32 | + { | |
| 33 | + if (!static::$platform) { | |
| 34 | + static::detect(); | |
| 35 | + } | |
| 36 | + | |
| 37 | + return (static::$platform === 'wordpress'); | |
| 38 | + } | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Tells whether the current platform is Joomla. | |
| 42 | + * | |
| 43 | + * @return bool | |
| 44 | + */ | |
| 45 | + public static function isJoomla() | |
| 46 | + { | |
| 47 | + if (!static::$platform) { | |
| 48 | + static::detect(); | |
| 49 | + } | |
| 50 | + | |
| 51 | + return (static::$platform === 'joomla'); | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Tells whether the current execution is made by the WordPress REST API framework. | |
| 56 | + * Useful to tell, for example, if the Gutenberg preview is calling the REST endpoint. | |
| 57 | + * | |
| 58 | + * @return bool | |
| 59 | + * | |
| 60 | + * @since 1.16.7 (J) - 1.6.7 (WP) | |
| 61 | + */ | |
| 62 | + public static function isWordPressRestApi() | |
| 63 | + { | |
| 64 | + $requestUri = JFactory::getApplication()->input->server->getString('REQUEST_URI', ''); | |
| 65 | + | |
| 66 | + if (static::isWordPress()) { | |
| 67 | + if (strpos($requestUri, trailingslashit(rest_get_url_prefix())) !== false || JUri::getInstance($requestUri)->hasVar('rest_route')) { | |
| 68 | + return true; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + return false; | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Detects the name of the platform on which we are running the software. | |
| 77 | + * | |
| 78 | + * @return void | |
| 79 | + */ | |
| 80 | + private static function detect() | |
| 81 | + { | |
| 82 | + if (defined('ABSPATH') && function_exists('wp_die')) { | |
| 83 | + static::$platform = 'wordpress'; | |
| 84 | + } else { | |
| 85 | + static::$platform = 'joomla'; | |
| 86 | + } | |
| 87 | + } | |
| 88 | +} | |