2020-06-10 16:03:13 +00:00
|
|
|
<?php
|
|
|
|
namespace YTKNS;
|
|
|
|
|
2025-02-02 20:07:19 +00:00
|
|
|
use Index\Data\DbTools;
|
|
|
|
use Syokuhou\FileConfig;
|
|
|
|
|
2020-06-10 16:03:13 +00:00
|
|
|
define('YTKNS_STARTUP', microtime(true));
|
2025-02-02 20:07:19 +00:00
|
|
|
define('YTKNS_CLI', PHP_SAPI === 'cli');
|
2020-06-10 16:03:13 +00:00
|
|
|
define('YTKNS_ROOT', __DIR__);
|
|
|
|
define('YTKNS_SRC', YTKNS_ROOT . '/src');
|
|
|
|
define('YTKNS_TPL', YTKNS_ROOT . '/templates');
|
|
|
|
define('YTKNS_UPLOADS', YTKNS_ROOT . '/uploads');
|
|
|
|
define('YTKNS_PUB', YTKNS_ROOT . '/public');
|
|
|
|
define('YTKNS_SCREENSHOTS', YTKNS_PUB . '/ss');
|
|
|
|
define('YTKNS_DEBUG', is_file(YTKNS_ROOT . '/.debug'));
|
2025-02-02 20:07:19 +00:00
|
|
|
define('YTKNS_MAINTENANCE', is_file(YTKNS_ROOT . '/.maintenance'));
|
2020-06-10 16:03:13 +00:00
|
|
|
|
2025-02-02 20:07:19 +00:00
|
|
|
require_once YTKNS_ROOT . '/vendor/autoload.php';
|
2020-06-10 16:03:13 +00:00
|
|
|
|
|
|
|
define('ALLOWED_UPLOADS', [
|
|
|
|
'audio/mpeg', 'application/x-font-gdos', 'audio/ogg', 'application/ogg',
|
|
|
|
'image/jpeg', 'image/png', 'image/gif',
|
|
|
|
]);
|
|
|
|
define('SITE_EFFECTS', [
|
|
|
|
\YTKNS\Effects\BackgroundAudioEffect::class,
|
|
|
|
\YTKNS\Effects\BackgroundImageEffect::class,
|
|
|
|
\YTKNS\Effects\ForegroundImageEffect::class,
|
|
|
|
\YTKNS\Effects\ZoomTextEffect::class,
|
|
|
|
\YTKNS\Effects\NewlyCreatedPageEffect::class,
|
|
|
|
]);
|
|
|
|
define('EFFECT_UPLOADS', [
|
|
|
|
'BackgroundAudio' => ['ogg', 'mp3'],
|
|
|
|
'BackgroundImage' => ['img'],
|
|
|
|
'ForegroundImage' => ['img'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
error_reporting(YTKNS_DEBUG ? -1 : 0);
|
2025-02-02 20:07:19 +00:00
|
|
|
mb_internal_encoding('UTF-8');
|
|
|
|
date_default_timezone_set('GMT');
|
2020-06-10 16:03:13 +00:00
|
|
|
|
|
|
|
// Display exception report
|
|
|
|
set_exception_handler(function(\Throwable $ex) {
|
2025-02-02 20:07:19 +00:00
|
|
|
if(YTKNS_CLI) {
|
|
|
|
echo (string)$ex;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2020-06-10 16:03:13 +00:00
|
|
|
http_response_code(500);
|
|
|
|
|
|
|
|
$out = file_get_contents(YTKNS_TPL . (YTKNS_DEBUG ? '/debug/index.html' : '/errors/500.html'));
|
|
|
|
echo strtr($out, [
|
|
|
|
':raw_ex' => (string)$ex,
|
|
|
|
':type' => get_class($ex),
|
|
|
|
':msg' => $ex->getMessage(),
|
|
|
|
]);
|
|
|
|
exit;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Turn uncaught errors into uncaught exceptions.
|
|
|
|
set_error_handler(function(int $errno, string $errstr, string $errfile, int $errline) {
|
|
|
|
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
|
|
|
|
return true;
|
|
|
|
}, -1);
|
|
|
|
|
2025-02-02 20:07:19 +00:00
|
|
|
$cfg = FileConfig::fromFile(YTKNS_ROOT . '/ytkns.cfg');
|
2020-06-10 16:03:13 +00:00
|
|
|
|
2025-02-02 20:07:19 +00:00
|
|
|
$db = DbTools::create($cfg->getString('database:dsn', 'null:'));
|
|
|
|
$db->execute('SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\'');
|
2020-06-10 16:03:13 +00:00
|
|
|
|
2025-02-02 20:07:19 +00:00
|
|
|
$ctx = new YtknsContext($cfg, $db);
|
2020-06-10 16:03:13 +00:00
|
|
|
|
2025-02-02 20:07:19 +00:00
|
|
|
DB::init(
|
|
|
|
$cfg->getString('pdo:dsn'),
|
|
|
|
$cfg->getString('pdo:user'),
|
|
|
|
$cfg->getString('pdo:pass'),
|
|
|
|
DB::FLAGS
|
|
|
|
);
|