szurubooru/src/core.php

79 lines
2 KiB
PHP
Raw Normal View History

2013-10-09 19:23:39 +02:00
<?php
2014-05-04 21:23:12 +02:00
$startTime = microtime(true);
2014-03-13 19:47:27 +01:00
define('SZURU_VERSION', '0.7.1');
2013-10-20 11:12:56 +02:00
define('SZURU_LINK', 'http://github.com/rr-/szurubooru');
//basic settings and preparation
2013-11-17 14:39:50 +01:00
define('DS', DIRECTORY_SEPARATOR);
$rootDir = __DIR__ . DS . '..' . DS;
date_default_timezone_set('UTC');
setlocale(LC_CTYPE, 'en_US.UTF-8');
ini_set('memory_limit', '128M');
2013-10-12 22:54:25 +02:00
//basic include calls, autoloader init
2014-04-12 16:22:30 +02:00
require_once $rootDir . 'lib' . DS . 'TextCaseConverter' . DS . 'TextCaseConverter.php';
2013-11-17 14:39:50 +01:00
require_once $rootDir . 'lib' . DS . 'php-markdown' . DS . 'Michelf' . DS . 'Markdown.php';
require_once $rootDir . 'lib' . DS . 'php-markdown' . DS . 'Michelf' . DS . 'MarkdownExtra.php';
2014-04-29 21:35:29 +02:00
require_once $rootDir . 'lib' . DS . 'chibi-core' . DS . 'include.php';
\Chibi\AutoLoader::registerFilesystem($rootDir . 'lib' . DS . 'chibi-sql');
\Chibi\AutoLoader::registerFilesystem(__DIR__);
2014-04-29 21:35:29 +02:00
function getConfig()
{
global $config;
return $config;
}
2014-05-04 21:23:12 +02:00
function getContext()
{
global $context;
return $context;
}
function resetEnvironment()
{
//load config manually
global $config;
global $rootDir;
global $startTime;
$configPaths =
[
$rootDir . DS . 'data' . DS . 'config.ini',
$rootDir . DS . 'data' . DS . 'local.ini',
$rootDir . DS . 'tests' . DS . 'test.ini',
];
$config = new \Chibi\Config();
foreach ($configPaths as $path)
if (file_exists($path))
$config->loadIni($path);
$config->rootDir = $rootDir;
//prepare context
global $context;
$context = new StdClass;
$context->startTime = $startTime;
2014-05-04 21:23:12 +02:00
//extension sanity checks
$requiredExtensions = ['pdo', 'pdo_' . $config->main->dbDriver, 'gd', 'openssl', 'fileinfo'];
foreach ($requiredExtensions as $ext)
if (!extension_loaded($ext))
die('PHP extension "' . $ext . '" must be enabled to continue.' . PHP_EOL);
2013-12-14 11:14:36 +01:00
2014-05-04 21:23:12 +02:00
if (\Chibi\Database::connected())
\Chibi\Database::disconnect();
Auth::setCurrentUser(null);
Access::init();
Logger::init();
\Chibi\Database::connect(
$config->main->dbDriver,
TextHelper::absolutePath($config->main->dbLocation),
$config->main->dbUser,
$config->main->dbPass);
}
2013-10-12 14:53:47 +02:00
2014-05-04 21:23:12 +02:00
resetEnvironment();