2015-04-01 15:35:27 +00:00
|
|
|
<?php
|
|
|
|
/*
|
2016-07-26 17:29:53 +00:00
|
|
|
* Community Management System
|
2016-02-02 21:04:15 +00:00
|
|
|
* (c) 2013-2016 Julian van de Groep <http://flash.moe>
|
2015-04-01 15:35:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Sakura;
|
|
|
|
|
2016-07-26 23:02:42 +00:00
|
|
|
// Define version and root path
|
2016-08-03 23:40:47 +00:00
|
|
|
define('SAKURA_VERSION', 20160804);
|
2015-12-03 19:40:01 +00:00
|
|
|
define('ROOT', __DIR__ . '/');
|
2015-04-01 15:35:27 +00:00
|
|
|
|
2016-07-26 23:02:42 +00:00
|
|
|
// CLI mode
|
|
|
|
if (php_sapi_name() === 'cli') {
|
|
|
|
define('IN_CLI', true);
|
|
|
|
}
|
2015-04-01 15:35:27 +00:00
|
|
|
|
2016-08-05 19:13:55 +00:00
|
|
|
// Turn error reporting on regardless of anything
|
|
|
|
error_reporting(-1);
|
|
|
|
|
2016-01-26 18:09:18 +00:00
|
|
|
// Override expiration variables
|
|
|
|
ignore_user_abort(true);
|
|
|
|
set_time_limit(0);
|
|
|
|
|
2015-07-05 00:03:15 +00:00
|
|
|
// Set internal encoding method
|
|
|
|
mb_internal_encoding('utf-8');
|
|
|
|
|
2016-07-26 23:02:42 +00:00
|
|
|
// Check the PHP version
|
2016-03-27 22:15:51 +00:00
|
|
|
if (version_compare(phpversion(), '7.0.0', '<')) {
|
2016-08-04 21:24:08 +00:00
|
|
|
die('Sakura requires at least PHP 7.0.0, please upgrade to a newer PHP version.');
|
2015-08-23 22:08:36 +00:00
|
|
|
}
|
|
|
|
|
2016-02-27 16:46:16 +00:00
|
|
|
// Check if the composer autoloader exists
|
|
|
|
if (!file_exists(ROOT . 'vendor/autoload.php')) {
|
2016-08-04 21:24:08 +00:00
|
|
|
die('Autoloader not found, did you run composer install?');
|
2015-12-03 19:40:01 +00:00
|
|
|
}
|
2015-11-13 23:11:55 +00:00
|
|
|
|
2016-07-26 23:02:42 +00:00
|
|
|
// Include the autoloader
|
2016-02-27 16:46:16 +00:00
|
|
|
require_once ROOT . 'vendor/autoload.php';
|
|
|
|
|
2016-08-05 19:13:55 +00:00
|
|
|
// Register the handlers
|
|
|
|
set_exception_handler(['Sakura\ExceptionHandler', 'exception']);
|
|
|
|
set_error_handler(['Sakura\ExceptionHandler', 'error']);
|
|
|
|
|
2016-07-26 23:02:42 +00:00
|
|
|
// Load the configuration
|
2015-12-10 20:55:51 +00:00
|
|
|
Config::init(ROOT . 'config/config.ini');
|
2015-05-29 19:27:45 +00:00
|
|
|
|
2016-07-26 23:02:42 +00:00
|
|
|
// Start the database module
|
2016-07-26 17:29:53 +00:00
|
|
|
$capsule = new DB;
|
|
|
|
$capsule->addConnection(config('database'));
|
2016-02-25 16:06:29 +00:00
|
|
|
$capsule->setAsGlobal();
|
|
|
|
|
2016-07-26 23:02:42 +00:00
|
|
|
if (!defined('IN_CLI')) {
|
|
|
|
// Start output buffering
|
|
|
|
ob_start(config('performance.compression') ? 'ob_gzhandler' : null);
|
|
|
|
|
|
|
|
// Initialise the router and include the routes file
|
|
|
|
Router::init();
|
|
|
|
include_once ROOT . 'routes.php';
|
|
|
|
|
|
|
|
// Initialise the current session
|
|
|
|
$cookiePrefix = config('cookie.prefix');
|
2016-08-07 14:10:27 +00:00
|
|
|
CurrentSession::start(
|
2016-07-26 23:02:42 +00:00
|
|
|
intval($_COOKIE["{$cookiePrefix}id"] ?? 0),
|
2016-08-07 14:10:27 +00:00
|
|
|
$_COOKIE["{$cookiePrefix}session"] ?? '',
|
|
|
|
Net::ip()
|
2016-07-26 23:02:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Start templating engine and set base variables
|
2016-08-07 14:23:02 +00:00
|
|
|
Template::set(CurrentSession::$user->design());
|
2016-07-26 23:02:42 +00:00
|
|
|
Template::vars([
|
|
|
|
'get' => $_GET,
|
2016-08-07 14:10:27 +00:00
|
|
|
'user' => CurrentSession::$user,
|
2016-07-26 23:02:42 +00:00
|
|
|
'post' => $_POST,
|
|
|
|
'server' => $_SERVER,
|
|
|
|
'request' => $_REQUEST,
|
2016-07-30 13:48:09 +00:00
|
|
|
'session' => $_SESSION,
|
2016-07-26 23:02:42 +00:00
|
|
|
]);
|
|
|
|
}
|