public static function bootstrap() { # Asserting PHP 5.3.0+ if (version_compare(PHP_VERSION, '5.3.0', '<')) { die('Flake Fatal Error: Flake requires PHP 5.3.0+ to run properly. Your version is: ' . PHP_VERSION . '.'); } # Define safehash salt define("PROJECT_SAFEHASH_SALT", "strong-secret-salt"); # Define absolute server path to Flake Framework define("FLAKE_PATH_ROOT", PROJECT_PATH_ROOT . "Core/Frameworks/Flake/"); # ./ if (!defined('LF')) { define('LF', chr(10)); } if (!defined('CR')) { define('CR', chr(13)); } if (array_key_exists("SERVER_NAME", $_SERVER) && $_SERVER["SERVER_NAME"] === "mongoose") { define("MONGOOSE_SERVER", TRUE); } else { define("MONGOOSE_SERVER", FALSE); } # Undo magic_quotes as this cannot be disabled by .htaccess on PHP ran as CGI # Source: http://stackoverflow.com/questions/517008/how-to-turn-off-magic-quotes-on-shared-hosting # Also: https://github.com/netgusto/Baikal/issues/155 if (in_array(strtolower(ini_get('magic_quotes_gpc')), array('1', 'on'))) { $process = array(); if (isset($_GET) && is_array($_GET)) { $process[] =& $_GET; } if (isset($_POST) && is_array($_POST)) { $process[] =& $_POST; } if (isset($_COOKIE) && is_array($_COOKIE)) { $process[] =& $_COOKIE; } if (isset($_REQUEST) && is_array($_REQUEST)) { $process[] =& $_REQUEST; } while (list($key, $val) = each($process)) { foreach ($val as $k => $v) { unset($process[$key][$k]); if (is_array($v)) { $process[$key][stripslashes($k)] = $v; $process[] =& $process[$key][stripslashes($k)]; } else { $process[$key][stripslashes($k)] = stripslashes($v); } } } unset($process); } # Fixing some CGI environments, that prefix HTTP_AUTHORIZATION (forwarded in .htaccess) with "REDIRECT_" if (array_key_exists("REDIRECT_HTTP_AUTHORIZATION", $_SERVER)) { $_SERVER["HTTP_AUTHORIZATION"] = $_SERVER["REDIRECT_HTTP_AUTHORIZATION"]; } ################################################################################################# # determine Flake install root path # not using realpath here to avoid symlinks resolution define("PROJECT_PATH_CORE", PROJECT_PATH_ROOT . "Core/"); define("PROJECT_PATH_CORERESOURCES", PROJECT_PATH_CORE . "Resources/"); define("PROJECT_PATH_SPECIFIC", PROJECT_PATH_ROOT . "Specific/"); define("PROJECT_PATH_FRAMEWORKS", PROJECT_PATH_CORE . "Frameworks/"); define("PROJECT_PATH_WWWROOT", PROJECT_PATH_CORE . "WWWRoot/"); require_once PROJECT_PATH_CORE . "Distrib.php"; if (PROJECT_PACKAGE === "regular") { define("PROJECT_PATH_DOCUMENTROOT", PROJECT_PATH_ROOT . "html/"); } elseif (PROJECT_PACKAGE === "flat") { define("PROJECT_PATH_DOCUMENTROOT", PROJECT_PATH_ROOT); } else { throw new \Exception("Unrecognized PROJECT_PACKAGE value."); } # Determine PROJECT_BASEURI $sScript = substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"])); $sDirName = str_replace("\\", "/", dirname($sScript)); # fix windows backslashes if ($sDirName !== ".") { $sDirName = self::appendSlash($sDirName); } else { $sDirName = "/"; } $sBaseUrl = self::rmBeginSlash(self::rmProjectContext($sDirName)); define("PROJECT_BASEURI", self::prependSlash($sBaseUrl)); # SabreDAV needs a "/" at the beginning of BASEURL # Determine PROJECT_URI $sProtocol = \Flake\Util\Tools::getCurrentProtocol(); $sHttpBaseUrl = strtolower($_SERVER["REQUEST_URI"]); $sHttpBaseUrl = self::rmQuery($sHttpBaseUrl); $sHttpBaseUrl = self::rmScriptName($sHttpBaseUrl, $sScript); $sHttpBaseUrl = self::rmProjectContext($sHttpBaseUrl); define("PROJECT_URI", $sProtocol . "://" . $_SERVER["HTTP_HOST"] . $sHttpBaseUrl); unset($sScript); unset($sDirName); unset($sBaseUrl); unset($sProtocol); unset($sHttpBaseUrl); ################################################################################################# # Include Flake Framework config require_once FLAKE_PATH_ROOT . "config.php"; # Determine Router class $GLOBALS["ROUTER"] = \Flake\Util\Tools::router(); if (!\Flake\Util\Tools::isCliPhp()) { ini_set("html_errors", TRUE); session_start(); } setlocale(LC_ALL, FLAKE_LOCALE); date_default_timezone_set(FLAKE_TIMEZONE); $GLOBALS["TEMPLATESTACK"] = array(); $aUrlInfo = parse_url(PROJECT_URI); define("FLAKE_DOMAIN", $_SERVER["HTTP_HOST"]); define("FLAKE_URIPATH", \Flake\Util\Tools::stripBeginSlash($aUrlInfo["path"])); unset($aUrlInfo); # Include Project config # NOTE: DB initialization and App config files inclusion # do not break execution if not properly executed, as # these errors will have to be caught later in the process # notably by the App install tool, if available; breaking right now # would forbid such install tool forwarding, for instance $sConfigPath = PROJECT_PATH_SPECIFIC . "config.php"; $sConfigSystemPath = PROJECT_PATH_SPECIFIC . "config.system.php"; if (file_exists($sConfigPath)) { require_once $sConfigPath; } if (file_exists($sConfigSystemPath)) { require_once $sConfigSystemPath; } self::initDb(); }