| @@ -1,0 +1,88 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * @package VikBooking | |
| 4 | + * @subpackage core | |
| 5 | + * @author E4J s.r.l. | |
| 6 | + * @copyright Copyright (C) 2021 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 | + * Register CMS HTML helpers. | |
| 16 | + * | |
| 17 | + * @since 1.5 | |
| 18 | + */ | |
| 19 | +JHtml::addIncludePath(VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'html'); | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * Libraries autoloader. | |
| 23 | + * | |
| 24 | + * @since 1.5 | |
| 25 | + */ | |
| 26 | +spl_autoload_register(function($class) | |
| 27 | +{ | |
| 28 | + $vcm_exists = is_file(implode(DIRECTORY_SEPARATOR, [VCM_SITE_PATH, 'helpers', 'lib.vikchannelmanager.php'])); | |
| 29 | + | |
| 30 | + // handle base VCM library | |
| 31 | + if ($class === 'VikChannelManager' || $class === 'E4jConnectRequest') | |
| 32 | + { | |
| 33 | + return $vcm_exists && include_once implode(DIRECTORY_SEPARATOR, [VCM_SITE_PATH, 'helpers', 'lib.vikchannelmanager.php']); | |
| 34 | + } | |
| 35 | + | |
| 36 | + // handle config VCM library | |
| 37 | + if ($class === 'VikChannelManagerConfig') | |
| 38 | + { | |
| 39 | + return $vcm_exists && include_once implode(DIRECTORY_SEPARATOR, [VCM_SITE_PATH, 'helpers', 'vcm_config.php']); | |
| 40 | + } | |
| 41 | + | |
| 42 | + // handle base VBO library | |
| 43 | + if ($class === 'VikBooking') | |
| 44 | + { | |
| 45 | + return (bool) require_once implode(DIRECTORY_SEPARATOR, [VBO_SITE_PATH, 'helpers', 'lib.vikbooking.php']); | |
| 46 | + } | |
| 47 | + | |
| 48 | + $guess_vbo = stripos($class, 'VBO'); | |
| 49 | + $guess_vcm = stripos($class, 'VCM'); | |
| 50 | + | |
| 51 | + if ($guess_vbo !== 0 && $guess_vcm !== 0) | |
| 52 | + { | |
| 53 | + // ignore if we are loading an outsider | |
| 54 | + return false; | |
| 55 | + } | |
| 56 | + | |
| 57 | + // get the class prefix and base path | |
| 58 | + if ($guess_vbo === 0) | |
| 59 | + { | |
| 60 | + $class_prefix = 'VBO'; | |
| 61 | + $class_bpath = dirname(__FILE__); | |
| 62 | + } | |
| 63 | + else | |
| 64 | + { | |
| 65 | + $class_prefix = 'VCM'; | |
| 66 | + $class_bpath = str_replace('vikbooking', 'vikchannelmanager', dirname(__FILE__)); | |
| 67 | + } | |
| 68 | + | |
| 69 | + // remove prefix from class | |
| 70 | + $tmp = preg_replace("/^$class_prefix/", '', $class); | |
| 71 | + // separate camel-case intersections | |
| 72 | + $tmp = preg_replace("/([a-z])([A-Z])/", addslashes('$1' . DIRECTORY_SEPARATOR . '$2'), $tmp); | |
| 73 | + | |
| 74 | + // build path from which the class should be loaded | |
| 75 | + $path = $class_bpath . DIRECTORY_SEPARATOR . strtolower($tmp) . '.php'; | |
| 76 | + | |
| 77 | + // make sure the file exists | |
| 78 | + if (is_file($path)) | |
| 79 | + { | |
| 80 | + // include file and check if the class is now available | |
| 81 | + if ((include_once $path) && (class_exists($class) || interface_exists($class) || trait_exists($class))) | |
| 82 | + { | |
| 83 | + return true; | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + return false; | |
| 88 | +}); | |