3 // ---------------------------------------------------
5 // ---------------------------------------------------
7 define('ROOT', dirname(__FILE__
));
9 define('APPLICATION_PATH', ROOT
. '/application');
10 define('LIBRARY_PATH', ROOT
. '/library');
11 define('FILES_DIR', ROOT
. '/upload'); // place where we will upload project files
12 define('CACHE_DIR', ROOT
. '/cache');
13 define('THEMES_DIR', ROOT
. '/public/assets/themes');
15 set_include_path(ROOT
. PATH_SEPARATOR
. APPLICATION_PATH
);
17 // ---------------------------------------------------
18 // Fix some $_SERVER vars (taken from wordpress code)
19 // ---------------------------------------------------
21 // Fix for IIS, which doesn't set REQUEST_URI
22 if(!isset($_SERVER['REQUEST_URI']) ||
trim($_SERVER['REQUEST_URI']) == '') {
23 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; // Does this work under CGI?
25 // Append the query string if it exists and isn't null
26 if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
27 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
31 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
32 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) ) {
33 $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
36 // Fix for Dreamhost and other PHP as CGI hosts
37 if(strstr($_SERVER['SCRIPT_NAME'], 'php.cgi')) unset($_SERVER['PATH_INFO']);
39 if(trim($_SERVER['PHP_SELF']) == '') $_SERVER['PHP_SELF'] = preg_replace("/(\?.*)?$/",'', $_SERVER["REQUEST_URI"]);
41 // ---------------------------------------------------
42 // Check if script is installed
43 // ---------------------------------------------------
45 // If script is not installed config.php will return false. Othervise it will
46 // return NULL. If we get false redirect to install folder
47 if(!include_once(ROOT
. '/config/config.php')) {
48 print "ProjectPier is not installed. Please redirect your browser to <b><a href=\"./". PUBLIC_FOLDER
. "/install\">" . PUBLIC_FOLDER
. "/install</a></b> folder and follow installation procedure";
52 // ---------------------------------------------------
53 // config.php + extended config
54 // ---------------------------------------------------
56 define('PRODUCT_NAME', 'ProjectPier');
57 if(!defined('PRODUCT_VERSION')) {
58 define('PRODUCT_VERSION', '0.8');
61 define('MAX_SEARCHABLE_FILE_SIZE', 1048576); // if file type is searchable script will load its content into search index. Using this constant you can set the max filesize of the file that will be imported. Noone wants 500MB in search index for single file
62 define('SESSION_LIFETIME', 3600);
63 define('REMEMBER_LOGIN_LIFETIME', 1209600); // two weeks
66 define('DEFAULT_CONTROLLER', 'dashboard');
67 define('DEFAULT_ACTION', 'index');
68 define('DEFAULT_THEME', 'default');
70 // Default cookie settings...
71 define('COOKIE_PATH', '/');
72 define('COOKIE_DOMAIN', '');
73 define('COOKIE_SECURE', false);
75 // ---------------------------------------------------
77 // ---------------------------------------------------
79 include_once 'environment/environment.php';
81 // Lets prepare everything for autoloader
82 require APPLICATION_PATH
. '/functions.php'; // __autoload() function is defined here...
83 @include ROOT
. '/cache/autoloader.php';
85 // Prepare logger... We might need it early...
86 if(!Env
::isDebugging()) {
87 Logger
::setSession(new Logger_Session('default'));
88 Logger
::setBackend(new Logger_Backend_File(CACHE_DIR
. '/log.php'));
90 set_error_handler('__production_error_handler');
91 set_exception_handler('__production_exception_handler');
94 register_shutdown_function('__shutdown');
96 // Connect to database...
98 DB
::connect(DB_ADAPTER
, array(
103 'persist' => DB_PERSIST
105 if(defined('DB_CHARSET') && trim(DB_CHARSET
)) {
106 DB
::execute("SET NAMES ?", DB_CHARSET
);
108 } catch(Exception
$e) {
109 if(Env
::isDebugging()) {
112 Logger
::log($e, Logger
::FATAL
);
113 Env
::executeAction('error', 'db_connect');
118 if(Env
::isDebugging()) {
119 benchmark_timer_set_marker('Init application');
122 // We need to call application.php after the routing is executed because
123 // some of the application classes may need CONTROLLER, ACTION or $_GET
124 // data collected by the matched route
125 require_once 'application.php';
127 // Set handle request timer...
128 if(Env
::isDebugging()) {
129 benchmark_timer_set_marker('Handle request');
132 // Get controller and action and execute...
134 Env
::executeAction(request_controller(), request_action());
135 } catch(Exception
$e) {
136 if(Env
::isDebugging()) {
139 Logger
::log($e, Logger
::FATAL
);
140 redirect_to(get_url('error', 'execute_action'));