szurubooru/src/core.php

97 lines
2.5 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;
2014-05-06 15:09:06 +02:00
chdir($rootDir);
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-05-07 17:39:40 +02:00
require_once $rootDir . 'src' . DS . 'routes.php';
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;
}
2014-05-06 12:01:29 +02:00
function prepareConfig($testEnvironment)
2014-05-04 21:23:12 +02:00
{
//load config manually
global $config;
global $rootDir;
2014-05-06 12:01:29 +02:00
$configPaths = [];
if (!$testEnvironment)
{
$configPaths []= $rootDir . DS . 'data' . DS . 'config.ini';
$configPaths []= $rootDir . DS . 'data' . DS . 'local.ini';
}
else
{
$configPaths []= $rootDir . DS . 'tests' . DS . 'config.ini';
}
2014-05-04 21:23:12 +02:00
$config = new \Chibi\Config();
foreach ($configPaths as $path)
if (file_exists($path))
$config->loadIni($path);
$config->rootDir = $rootDir;
2014-05-06 12:01:29 +02:00
}
2014-05-04 21:23:12 +02:00
2014-05-06 12:01:29 +02:00
function prepareEnvironment($testEnvironment)
{
2014-05-04 21:23:12 +02:00
//prepare context
global $context;
2014-05-06 12:01:29 +02:00
global $startTime;
2014-05-04 21:23:12 +02:00
$context = new StdClass;
$context->startTime = $startTime;
2014-05-06 12:01:29 +02:00
$config = getConfig();
2014-05-06 15:09:06 +02:00
TransferHelper::createDirectory($config->main->filesPath);
TransferHelper::createDirectory($config->main->thumbsPath);
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();
2014-05-07 09:26:04 +02:00
Mailer::init();
2014-05-04 21:23:12 +02:00
\Chibi\Database::connect(
$config->main->dbDriver,
TextHelper::absolutePath($config->main->dbLocation),
2014-05-06 12:01:29 +02:00
isset($config->main->dbUser) ? $config->main->dbUser : null,
isset($config->main->dbPass) ? $config->main->dbPass : null);
2014-05-04 21:23:12 +02:00
}
2013-10-12 14:53:47 +02:00
2014-05-06 12:01:29 +02:00
prepareConfig(false);
prepareEnvironment(false);