2015-04-01 15:35:27 +00:00
|
|
|
<?php
|
|
|
|
/*
|
2015-05-24 22:06:53 +00:00
|
|
|
* Sakura 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
|
|
|
*/
|
|
|
|
|
|
|
|
// Declare namespace
|
|
|
|
namespace Sakura;
|
|
|
|
|
|
|
|
// Define Sakura version
|
2016-03-31 20:03:25 +00:00
|
|
|
define('SAKURA_VERSION', 20160331);
|
2015-04-01 15:35:27 +00:00
|
|
|
|
|
|
|
// Define Sakura Path
|
2015-12-03 19:40:01 +00:00
|
|
|
define('ROOT', __DIR__ . '/');
|
2015-04-01 15:35:27 +00:00
|
|
|
|
2015-12-04 14:19:10 +00:00
|
|
|
// Turn error reporting on for the initial startup sequence
|
|
|
|
error_reporting(-1);
|
2015-04-01 15:35:27 +00:00
|
|
|
|
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-03-27 22:15:51 +00:00
|
|
|
// Stop the execution if the PHP Version is older than 7.0.0
|
|
|
|
if (version_compare(phpversion(), '7.0.0', '<')) {
|
|
|
|
throw new \Exception('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')) {
|
|
|
|
throw new \Exception('Autoloader not found, did you run composer?');
|
2015-12-03 19:40:01 +00:00
|
|
|
}
|
2015-11-13 23:11:55 +00:00
|
|
|
|
2016-02-27 16:46:16 +00:00
|
|
|
// Require composer libraries
|
|
|
|
require_once ROOT . 'vendor/autoload.php';
|
|
|
|
|
2016-02-13 13:36:21 +00:00
|
|
|
// Setup the autoloader
|
|
|
|
spl_autoload_register(function ($className) {
|
2016-02-20 11:20:58 +00:00
|
|
|
// Replace \ with /
|
|
|
|
$className = str_replace('\\', '/', $className);
|
|
|
|
|
2016-02-13 13:36:21 +00:00
|
|
|
// Create a throwaway count variable
|
|
|
|
$i = 1;
|
|
|
|
|
|
|
|
// Replace the sakura namespace with the libraries directory
|
2016-02-20 11:20:58 +00:00
|
|
|
$className = str_replace('Sakura/', 'libraries/', $className, $i);
|
2016-02-13 13:36:21 +00:00
|
|
|
|
|
|
|
// Require the file
|
|
|
|
require_once ROOT . $className . '.php';
|
|
|
|
});
|
2015-04-01 15:35:27 +00:00
|
|
|
|
|
|
|
// Set Error handler
|
2016-01-17 01:58:31 +00:00
|
|
|
set_error_handler(['Sakura\Utils', 'errorHandler']);
|
2015-04-01 15:35:27 +00:00
|
|
|
|
2015-12-10 20:55:51 +00:00
|
|
|
// Load the local configuration
|
|
|
|
Config::init(ROOT . 'config/config.ini');
|
2015-05-29 19:27:45 +00:00
|
|
|
|
2015-12-04 14:19:10 +00:00
|
|
|
// Change error reporting according to the dev configuration
|
2015-12-27 04:37:57 +00:00
|
|
|
error_reporting(Config::local('dev', 'show_errors') ? -1 : 0);
|
2015-12-04 14:19:10 +00:00
|
|
|
|
2016-02-25 16:06:29 +00:00
|
|
|
// Create a new database capsule
|
|
|
|
$capsule = new \Illuminate\Database\Capsule\Manager;
|
|
|
|
|
|
|
|
// Add the connection
|
|
|
|
$capsule->addConnection(Config::local('database'));
|
|
|
|
|
|
|
|
// Make the capsule globally accessible
|
|
|
|
$capsule->setAsGlobal();
|
|
|
|
|
2015-09-12 19:57:44 +00:00
|
|
|
// Check if we the system has a cron service
|
2015-12-04 14:19:10 +00:00
|
|
|
if (Config::get('no_cron_service')) {
|
2015-09-12 19:57:44 +00:00
|
|
|
// If not do an "asynchronous" call to the cron.php script
|
2015-12-04 14:19:10 +00:00
|
|
|
if (Config::get('no_cron_last') < (time() - Config::get('no_cron_interval'))) {
|
2016-03-31 20:03:25 +00:00
|
|
|
$phpDir = PHP_BINDIR;
|
|
|
|
$cronPath = ROOT . 'cron.php';
|
|
|
|
|
2015-09-12 19:57:44 +00:00
|
|
|
// Check OS
|
2015-09-14 20:51:23 +00:00
|
|
|
if (substr(strtolower(PHP_OS), 0, 3) == 'win') {
|
2016-03-31 20:03:25 +00:00
|
|
|
$cronPath = addslashes($cronPath);
|
|
|
|
|
|
|
|
pclose(popen("start /B {$phpDir}\php.exe {$cronPath}", 'r'));
|
2015-09-12 19:57:44 +00:00
|
|
|
} else {
|
2016-03-31 20:03:25 +00:00
|
|
|
pclose(popen("{$phpDir}/php {$cronPath} > /dev/null 2>/dev/null &", 'r'));
|
2015-09-12 19:57:44 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 20:03:25 +00:00
|
|
|
unset($phpDir, $cronPath);
|
|
|
|
|
2015-09-12 19:57:44 +00:00
|
|
|
// Update last execution time
|
2016-02-18 23:28:44 +00:00
|
|
|
Config::set('no_cron_last', time());
|
2015-09-12 19:57:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 19:27:45 +00:00
|
|
|
// Start output buffering
|
2015-12-04 14:19:10 +00:00
|
|
|
ob_start(Config::get('use_gzip') ? 'ob_gzhandler' : null);
|
2015-04-01 15:35:27 +00:00
|
|
|
|
2016-01-30 00:18:23 +00:00
|
|
|
// Initialise the router
|
|
|
|
Router::init();
|
|
|
|
|
|
|
|
// Include routes file
|
|
|
|
include_once ROOT . 'routes.php';
|
|
|
|
|
2016-03-31 20:03:25 +00:00
|
|
|
// Initialise the current session
|
|
|
|
ActiveUser::init(
|
|
|
|
intval($_COOKIE[Config::get('cookie_prefix') . 'id'] ?? 0),
|
|
|
|
$_COOKIE[Config::get('cookie_prefix') . 'session'] ?? ''
|
|
|
|
);
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-09-04 23:49:53 +00:00
|
|
|
// Create the Urls object
|
|
|
|
$urls = new Urls();
|
|
|
|
|
2016-03-24 18:28:32 +00:00
|
|
|
// Prepare the name of the template to load
|
2016-03-28 14:47:43 +00:00
|
|
|
$templateName = Config::get('site_style');
|
2015-07-30 01:12:53 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!defined('SAKURA_NO_TPL')) {
|
2016-02-04 20:56:40 +00:00
|
|
|
// Start templating engine
|
|
|
|
Template::set($templateName);
|
|
|
|
|
2015-07-30 01:12:53 +00:00
|
|
|
// Set base page rendering data
|
2016-02-18 23:28:44 +00:00
|
|
|
Template::vars([
|
2015-07-30 01:12:53 +00:00
|
|
|
'sakura' => [
|
2015-08-20 23:17:27 +00:00
|
|
|
'versionInfo' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'version' => SAKURA_VERSION,
|
2015-12-04 14:19:10 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
'dev' => [
|
2015-12-27 04:37:57 +00:00
|
|
|
'showChangelog' => Config::local('dev', 'show_changelog'),
|
2015-08-20 23:17:27 +00:00
|
|
|
],
|
|
|
|
|
2015-12-04 14:19:10 +00:00
|
|
|
'resources' => Config::get('content_path') . '/data/' . $templateName,
|
2015-08-20 23:17:27 +00:00
|
|
|
|
2016-03-31 20:03:25 +00:00
|
|
|
'currentPage' => $_SERVER['REQUEST_URI'] ?? null,
|
|
|
|
'referrer' => $_SERVER['HTTP_REFERER'] ?? null,
|
2015-07-30 01:12:53 +00:00
|
|
|
],
|
|
|
|
|
2016-03-25 01:31:57 +00:00
|
|
|
'session' => array_merge([
|
2016-03-31 20:03:25 +00:00
|
|
|
'checkLogin' => ActiveUser::$user->id && !ActiveUser::$user->permission(Perms\Site::DEACTIVATED),
|
|
|
|
'sessionId' => ActiveUser::$session->sessionId,
|
2016-03-25 01:31:57 +00:00
|
|
|
], $_SESSION),
|
2015-08-19 19:44:01 +00:00
|
|
|
|
2016-03-31 20:03:25 +00:00
|
|
|
'user' => ActiveUser::$user,
|
2015-09-14 20:51:23 +00:00
|
|
|
'urls' => $urls,
|
2015-11-15 14:29:26 +00:00
|
|
|
|
|
|
|
'get' => $_GET,
|
|
|
|
'post' => $_POST,
|
2016-03-25 01:31:57 +00:00
|
|
|
'request' => $_REQUEST,
|
2016-02-27 16:46:16 +00:00
|
|
|
'server' => $_SERVER,
|
2016-02-18 23:28:44 +00:00
|
|
|
]);
|
2015-07-30 01:12:53 +00:00
|
|
|
|
2015-09-16 20:34:36 +00:00
|
|
|
// Site closing
|
2015-12-04 14:19:10 +00:00
|
|
|
if (Config::get('site_closed')) {
|
2016-02-04 20:56:40 +00:00
|
|
|
// Set parse variables
|
|
|
|
Template::vars([
|
2016-03-28 14:47:43 +00:00
|
|
|
'message' => Config::get('site_closed_reason'),
|
2015-09-16 20:34:36 +00:00
|
|
|
]);
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2015-09-16 20:34:36 +00:00
|
|
|
exit;
|
|
|
|
}
|
2015-07-30 01:12:53 +00:00
|
|
|
}
|