/** * Initalizes the <i>Application</i>. */ public static function initalize() { // Initalizes configuration array require "../local/config.php"; Application::$config = $cfg; // Reads mode from config if (isset(Application::$config["mode"]) && Application::$config["mode"] == false) { // development mode Application::$mode = false; } else { // production mode // turns off all error reporting error_reporting(0); } // Initializes MySQL-connection if (!isset(Application::$config["mysql"])) { // Throws an error of there's no MySQL-access-data die("<b>Error: </b>MySQL access data is missing."); } switch (strtolower(Application::$config["mysql"]["driver"])) { // Checks, whether the mysql-driver from config is valid and constructs the classes instance ... case "pdo": Application::$connection = new PDOConnection(Application::$config["mysql"]["access"]["hostname"], Application::$config["mysql"]["access"]["database"], Application::$config["mysql"]["access"]["username"], Application::$config["mysql"]["access"]["password"]); break; default: // ...or lets the whole thing die otherwise. die("<b>Error: </b>Driver <i>" . Application::$config["mysql"]["driver"] . "</i> is invalid."); } // Initalizes path array $path = $_REQUEST["path"]; // Gets the path string. $path = strtolower($path); // Makes the path ignoring upper-/lowercase. $path = trim("/"); // Strips slashes from end of path, which prevents an empty array element. $path = explode("/", $path); // Transforms path string to array. Application::$path = $path; // Calculates ProjectEngine's root directory Application::$cookiePath = preg_replace("/^(.*)" . preg_quote($_GET["path"], "/") . "\$/", "\$1", $_SERVER["REQUEST_URI"]); Application::$root = $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["HTTP_HOST"] . Application::$cookiePath; // Configures session and starts it session_cache_expire(); session_cache_limiter("nocache"); session_name("pe-session"); session_set_cookie_params(time() + 30 * 24 * 60 * 60, Application::$cookiePath); session_start(); }
Application::setConfigValue("mysql/access/database", "\"" . $_REQUEST["database"] . "\""); Application::setConfigValue("mysql/access/hostname", "\"" . $_REQUEST["hostname"] . "\""); Application::setConfigValue("mysql/access/port", "\"" . $_REQUEST["port"] . "\""); if ($_REQUEST["password"] == "") { Application::setConfigValue("mysql/access/password", "null"); } else { Application::setConfigValue("mysql/access/password", "\"" . $_REQUEST["password"] . "\""); } Application::setConfigValue("mysql/access/username", "\"" . $_REQUEST["username"] . "\""); Application::setConfigValue("mysql/driver", "\"pdo\""); // Adds the other options to config Application::setConfigValue("authentication/guests", $_REQUEST["guests"]); // Adds some default values to config Application::setConfigValue("mode", "true"); // Tests MySQL connection Application::initalize(); $success = true; try { Application::$connection->connect(); } catch (MySQLException $exception) { $success = false; $error = $exception->getError(); } // Redirects to the next step or shows an error message if ($success) { $file = fopen("../local/installer.txt", "w"); fwrite($file, "3"); fclose($file); header("Location: " . preg_replace("/\\?.*/", "", $_SERVER["REQUEST_URI"])); } else { ?>