$languages = unserialize(LANGUAGES); // If no language is given redirect to English version. $query = explode('/', rtrim(!empty($_GET['q']) ? $_GET['q'] : '')); if (empty($query) || !in_array($query[0], array_keys($languages))) { // Fallback to english. header('Location:' . alt_lang_url('en')); exit; } else { define('LANGUAGE', $query[0]); setlocale(LC_MESSAGES, $languages[LANGUAGE] . '.utf8'); bindtextdomain('messages', BASE_DIR . 'locale'); bind_textdomain_codeset('messages', 'UTF-8'); textdomain('messages'); } // Initialize or include components, that need to be language aware. LanguageCodes::init(); require_once BASE_DIR . 'inc/data.php'; // Will be set to true in the event that no controller is given // or the controller does not exist. $fallback = FALSE; // Look for controller in the query and check that it exists. if (!empty($query[1]) && class_exists($query[1])) { $controller = $query[1]::getInstance(); // Look for controller method in the query and check that it is public // and does not start with _. if (!empty($query[2]) && preg_match('/^_/', $query[2]) !== 1 && is_callable(array($controller, $query[2]))) { $params = array_slice($query, 3); call_user_func_array(array($controller, $query[2]), $params); } else { $controller->render(); }