public static function initialize($environment, $configdir) { if (self::$instance instanceof self) { return; } $configuration = array(); // Load config foreach (self::getConfigFiles($configdir) as $configfile) { $configuration = array_merge_recursive(array_reduce(array_intersect_key(self::loadConfigFile($configfile), array_flip(array('all', $environment))), array('self', 'mergeWrapper')), $configuration); } // Set our instance, load kxConfig self::$instance = new self($environment, new kxConfig($configuration)); // Add any classes we want added to the autoloader. foreach (kxEnv::get('kx:autoload:load') as $repo => $opts) { kxEnv::set(sprintf('kx:autoload:repository:%s:id', $repo), kxAutoload::registerRepository(sprintf('%s/%s/%s', KX_ROOT, 'application/lib', $opts['path']), array('prefix' => $opts['prefix']))); } // Set up our input, remove any magic quotes if (is_array($_POST) and !empty($_POST)) { foreach ($_POST as $BUTTER => $TOAST) { // Skip arrays if (!is_array($TOAST)) { $_POST[$BUTTER] = kxFunc::strip_magic($TOAST); } } } // Clean up all of our input (cookies, get/post requests, etc) kxFunc::cleanInput($_GET); kxFunc::cleanInput($_POST); kxFunc::cleanInput($_COOKIE); kxFunc::cleanInput($_REQUEST); //Okay NOW let's parse our input $input = kxFunc::parseInput($_GET, array()); // Allow $_POST to overwrite $_GET self::$request = kxFunc::parseInput($_POST, $input) + self::$request; // Grab our app $_application = preg_replace("/[^a-zA-Z0-9\\-\\_]/", "", isset($_REQUEST['app']) && trim($_REQUEST['app']) ? $_REQUEST['app'] : "core"); // Make sure we get (hopefully) a string if (is_array($_application)) { $_application = array_shift($_application); } define('KX_CURRENT_APP', $_application); kxEnv::$current_application = KX_CURRENT_APP; kxEnv::$current_module = isset(self::$request['module']) ? self::$request['module'] : ''; kxEnv::$current_section = isset(self::$request['section']) ? self::$request['section'] : ''; // Cleanup kxEnv::$current_module = kxFunc::alphaNum(kxEnv::$current_module); kxEnv::$current_section = kxFunc::alphaNum(kxEnv::$current_section); // Load the cache self::$cache = kxCache::instance(); }
<?php DEFINE('KX_ROOT', realpath(dirname(__FILE__))); DEFINE('KX_BOARD', KX_ROOT); DEFINE('KX_SCRIPT', KX_ROOT); DEFINE('KX_LIB', KX_ROOT . '/application/lib/kx'); // Full path to kx's library files DEFINE('KUSABA_RUNNING', true); require_once KX_LIB . "/../Twig/Autoloader.php"; Twig_Autoloader::register(); require_once KX_LIB . '/kxAutoload.class.php'; require_once KX_ROOT . '/application/lib/gettext/gettext.inc.php'; $repository = kxAutoload::registerRepository(KX_LIB, array('prefix' => 'kx')); // Add the autoloader repository in kx's lib dir, listen only for classes starting with the string 'kx' kxEnv::initialize('dev', KX_ROOT . '/config'); // Setup the main environment, make it read config files etc, the lots kxEnv::set('kx:autoload:repository:kx:id', $repository); // If we want to unload the kx autoloader at some point, store the id here. // Cleanup global namespace unset($repository);