2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-12-04 23:38:32 +01:00
|
|
|
/************************************************************************************
|
|
|
|
************************************************************************************
|
|
|
|
** **
|
|
|
|
** If you can read this text in your browser then you don't have PHP installed. **
|
2009-11-27 02:26:35 +01:00
|
|
|
** Please install PHP 5.0 or higher, preferably PHP 5.2 or 5.3. **
|
2008-12-04 23:38:32 +01:00
|
|
|
** **
|
|
|
|
************************************************************************************
|
|
|
|
************************************************************************************/
|
|
|
|
|
2009-03-22 23:59:14 +01:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage core
|
|
|
|
*/
|
2009-08-11 05:50:40 +02:00
|
|
|
|
|
|
|
if(version_compare(phpversion(), 5, '<')) {
|
2008-12-04 23:38:32 +01:00
|
|
|
header("HTTP/1.1 500 Server Error");
|
|
|
|
echo str_replace('$PHPVersion', phpversion(), file_get_contents("dev/install/php5-required.html"));
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-01-09 05:18:36 +01:00
|
|
|
* Main file that handles every page request.
|
2008-02-25 03:10:37 +01:00
|
|
|
*
|
|
|
|
* The main.php does a number of set-up activities for the request.
|
|
|
|
*
|
2008-08-11 01:29:30 +02:00
|
|
|
* - Includes the first one of the following files that it finds: (root)/_ss_environment.php,
|
|
|
|
* (root)/../_ss_environment.php, or (root)/../../_ss_environment.php
|
2008-02-25 03:10:37 +01:00
|
|
|
* - Gets an up-to-date manifest from {@link ManifestBuilder}
|
|
|
|
* - Sets up error handlers with {@link Debug::loadErrorHandlers()}
|
2008-08-11 01:29:30 +02:00
|
|
|
* - Calls {@link DB::connect()}, passing it the global variable $databaseConfig that should
|
2009-03-22 23:59:14 +01:00
|
|
|
* be defined in an _config.php
|
2008-02-25 03:10:37 +01:00
|
|
|
* - Sets up the default director rules using {@link Director::addRules()}
|
|
|
|
*
|
2008-08-11 01:29:30 +02:00
|
|
|
* After that, it calls {@link Director::direct()}, which is responsible for doing most of the
|
|
|
|
* real work.
|
2008-02-25 03:10:37 +01:00
|
|
|
*
|
2008-08-11 01:29:30 +02:00
|
|
|
* Finally, main.php will use {@link Profiler} to show a profile if the querystring variable
|
|
|
|
* "debug_profile" is set.
|
2008-02-25 03:10:37 +01:00
|
|
|
*
|
|
|
|
* CONFIGURING THE WEBSERVER
|
|
|
|
*
|
2008-08-11 01:29:30 +02:00
|
|
|
* To use Sapphire, every request that doesn't point directly to a file should be rewritten to
|
|
|
|
* sapphire/main.php?url=(url). For example, http://www.example.com/about-us/rss would be rewritten
|
|
|
|
* to http://www.example.com/sapphire/main.php?url=about-us/rss
|
2008-02-25 03:10:37 +01:00
|
|
|
*
|
2008-08-11 01:29:30 +02:00
|
|
|
* It's important that requests that point directly to a file aren't rewritten; otherwise, visitors
|
|
|
|
* won't be able to download any CSS, JS, image files, or other downloads.
|
2008-02-25 03:10:37 +01:00
|
|
|
*
|
|
|
|
* On Apache, RewriteEngine can be used to do this.
|
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage core
|
|
|
|
* @see Director::direct()
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Include Sapphire's core code
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
require_once("core/Core.php");
|
2008-02-25 03:10:37 +01:00
|
|
|
|
2008-08-11 01:29:30 +02:00
|
|
|
if (function_exists('mb_http_output')) {
|
2007-07-19 12:40:28 +02:00
|
|
|
mb_http_output('UTF-8');
|
|
|
|
mb_internal_encoding('UTF-8');
|
2011-08-26 17:57:43 +02:00
|
|
|
mb_regex_encoding('UTF-8');
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
2009-05-15 01:14:51 +02:00
|
|
|
// IIS will sometimes generate this.
|
|
|
|
if(!empty($_SERVER['HTTP_X_ORIGINAL_URL'])) {
|
|
|
|
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
|
|
|
|
}
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
// Apache rewrite rules use this
|
2008-08-11 01:29:30 +02:00
|
|
|
if (isset($_GET['url'])) {
|
2007-10-02 06:59:06 +02:00
|
|
|
$url = $_GET['url'];
|
2008-10-09 01:04:55 +02:00
|
|
|
// IIS includes get variables in url
|
|
|
|
$i = strpos($url, '?');
|
|
|
|
if($i !== false) {
|
|
|
|
$url = substr($url, 0, $i);
|
|
|
|
}
|
2007-10-02 06:59:06 +02:00
|
|
|
|
|
|
|
// Lighttpd uses this
|
|
|
|
} else {
|
2009-01-05 07:19:48 +01:00
|
|
|
if(strpos($_SERVER['REQUEST_URI'],'?') !== false) {
|
|
|
|
list($url, $query) = explode('?', $_SERVER['REQUEST_URI'], 2);
|
|
|
|
parse_str($query, $_GET);
|
|
|
|
if ($_GET) $_REQUEST = array_merge((array)$_REQUEST, (array)$_GET);
|
|
|
|
} else {
|
|
|
|
$url = $_SERVER["REQUEST_URI"];
|
|
|
|
}
|
2007-10-02 06:59:06 +02:00
|
|
|
}
|
|
|
|
|
2010-10-13 05:56:48 +02:00
|
|
|
// Remove base folders from the URL if webroot is hosted in a subfolder
|
2009-02-02 00:49:53 +01:00
|
|
|
if (substr(strtolower($url), 0, strlen(BASE_URL)) == strtolower(BASE_URL)) $url = substr($url, strlen(BASE_URL));
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
if (isset($_GET['debug_profile'])) {
|
|
|
|
Profiler::init();
|
|
|
|
Profiler::mark('all_execution');
|
|
|
|
Profiler::mark('main.php init');
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
// Connect to database
|
2011-03-30 22:56:21 +02:00
|
|
|
require_once("model/DB.php");
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-11-18 02:48:37 +01:00
|
|
|
// Redirect to the installer if no database is selected
|
|
|
|
if(!isset($databaseConfig) || !isset($databaseConfig['database']) || !$databaseConfig['database']) {
|
2011-10-28 23:31:58 +02:00
|
|
|
if(!file_exists(BASE_PATH . '/install.php')) {
|
|
|
|
die('SilverStripe Framework requires a $databaseConfig defined.');
|
|
|
|
}
|
2009-01-05 07:19:48 +01:00
|
|
|
$s = (isset($_SERVER['SSL']) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')) ? 's' : '';
|
2010-04-14 05:47:37 +02:00
|
|
|
$installURL = "http$s://" . $_SERVER['HTTP_HOST'] . BASE_URL . '/install.php';
|
2010-04-14 05:46:40 +02:00
|
|
|
|
|
|
|
// The above dirname() will equate to "\" on Windows when installing directly from http://localhost (not using
|
|
|
|
// a sub-directory), this really messes things up in some browsers. Let's get rid of the backslashes
|
|
|
|
$installURL = str_replace('\\', '', $installURL);
|
|
|
|
|
2008-11-18 02:48:37 +01:00
|
|
|
header("Location: $installURL");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2008-08-11 01:29:30 +02:00
|
|
|
if (isset($_GET['debug_profile'])) Profiler::mark('DB::connect');
|
2007-07-19 12:40:28 +02:00
|
|
|
DB::connect($databaseConfig);
|
2008-08-11 01:29:30 +02:00
|
|
|
if (isset($_GET['debug_profile'])) Profiler::unmark('DB::connect');
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
if (isset($_GET['debug_profile'])) Profiler::unmark('main.php init');
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2011-05-01 07:33:02 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// Direct away - this is the "main" function, that hands control to the appropriate controller
|
2011-05-01 07:33:02 +02:00
|
|
|
DataModel::set_inst(new DataModel());
|
|
|
|
Director::direct($url, DataModel::inst());
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-08-11 01:29:30 +02:00
|
|
|
if (isset($_GET['debug_profile'])) {
|
2007-07-19 12:40:28 +02:00
|
|
|
Profiler::unmark('all_execution');
|
2009-06-25 11:53:51 +02:00
|
|
|
if(!Director::isLive()) {
|
|
|
|
Profiler::show(isset($_GET['profile_trace']));
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|