2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
2023-01-11 00:51:57 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shimmie2;
|
|
|
|
|
2020-01-27 19:28:58 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
|
|
|
* Make sure that shimmie is correctly installed *
|
|
|
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2020-06-24 13:53:36 +00:00
|
|
|
require_once "core/sanitize_php.php";
|
2020-10-25 19:40:24 +00:00
|
|
|
require_once "core/polyfills.php";
|
2020-06-24 13:53:36 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
if (!file_exists("vendor/")) {
|
2020-03-23 19:50:28 +00:00
|
|
|
$cwd = getcwd();
|
2020-06-24 13:53:36 +00:00
|
|
|
die_nicely(
|
|
|
|
"Shimmie is unable to find the composer <code>vendor</code> directory.",
|
|
|
|
"
|
|
|
|
<p>To finish installing, you need to run <code>composer install</code>
|
|
|
|
in the shimmie directory (<code>$cwd</code>).</p>
|
|
|
|
<p>(If you don't have composer, <a href='https://getcomposer.org/'>get it here</a>)</p>
|
|
|
|
"
|
|
|
|
);
|
2016-06-18 05:42:52 +00:00
|
|
|
}
|
|
|
|
|
2024-01-17 20:19:13 +00:00
|
|
|
if (!file_exists("data/config/shimmie.conf.php") && !getenv("SHM_DATABASE_DSN")) {
|
2020-03-23 18:47:18 +00:00
|
|
|
require_once "core/install.php";
|
|
|
|
install();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2020-01-27 19:28:58 +00:00
|
|
|
require_once "vendor/autoload.php";
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
|
|
|
* Load files *
|
|
|
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
@include_once "data/config/shimmie.conf.php";
|
|
|
|
@include_once "data/config/extensions.conf.php";
|
|
|
|
require_once "core/sys_config.php";
|
|
|
|
require_once "core/util.php";
|
2023-07-05 19:33:38 +00:00
|
|
|
require_once "core/microhtml.php";
|
2020-01-27 19:28:58 +00:00
|
|
|
|
|
|
|
global $cache, $config, $database, $user, $page, $_tracer;
|
2020-06-24 13:53:36 +00:00
|
|
|
_set_up_shimmie_environment();
|
2023-01-10 22:44:09 +00:00
|
|
|
$_tracer = new \EventTracer();
|
2020-01-27 19:28:58 +00:00
|
|
|
$_tracer->begin("Bootstrap");
|
|
|
|
_load_core_files();
|
2023-02-02 16:04:35 +00:00
|
|
|
$cache = loadCache(CACHE_DSN);
|
2020-01-27 19:28:58 +00:00
|
|
|
$database = new Database(DATABASE_DSN);
|
|
|
|
$config = new DatabaseConfig($database);
|
2023-12-16 00:37:40 +00:00
|
|
|
_load_extension_files();
|
2020-01-27 19:28:58 +00:00
|
|
|
_load_theme_files();
|
|
|
|
$page = new Page();
|
|
|
|
_load_event_listeners();
|
|
|
|
$_tracer->end();
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
|
|
|
* Send events, display output *
|
|
|
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2009-01-04 16:24:06 +00:00
|
|
|
try {
|
2020-03-27 20:53:21 +00:00
|
|
|
// $_tracer->mark($_SERVER["REQUEST_URI"] ?? "No Request");
|
2020-03-18 20:26:52 +00:00
|
|
|
$_tracer->begin(
|
|
|
|
$_SERVER["REQUEST_URI"] ?? "No Request",
|
|
|
|
[
|
2023-11-11 21:49:12 +00:00
|
|
|
"user" => $_COOKIE["shm_user"] ?? "No User",
|
|
|
|
"ip" => get_real_ip() ?? "No IP",
|
|
|
|
"user_agent" => $_SERVER['HTTP_USER_AGENT'] ?? "No UA",
|
2020-03-18 20:26:52 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2024-09-04 14:12:01 +00:00
|
|
|
if (!(Extension::is_enabled(SpeedHaxInfo::KEY) && $config->get_bool(SpeedHaxConfig::NO_AUTO_DB_UPGRADE))) {
|
2020-03-18 20:26:52 +00:00
|
|
|
send_event(new DatabaseUpgradeEvent());
|
|
|
|
}
|
|
|
|
send_event(new InitExtEvent());
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
// start the page generation waterfall
|
2019-06-27 14:47:22 +00:00
|
|
|
$user = _get_user();
|
2019-07-04 17:48:33 +00:00
|
|
|
send_event(new UserLoginEvent($user));
|
2019-05-28 16:59:38 +00:00
|
|
|
if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') {
|
2024-01-10 21:10:42 +00:00
|
|
|
ob_end_flush();
|
2024-01-10 23:01:01 +00:00
|
|
|
ob_implicit_flush(true);
|
2024-01-11 00:55:05 +00:00
|
|
|
$app = new CliApp();
|
|
|
|
send_event(new CliGenEvent($app));
|
2024-08-31 16:05:18 +00:00
|
|
|
if ($app->run() !== 0) {
|
2024-01-16 01:28:44 +00:00
|
|
|
throw new \Exception("CLI command failed");
|
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
} else {
|
2024-02-09 16:36:57 +00:00
|
|
|
send_event(new PageRequestEvent($_SERVER['REQUEST_METHOD'], _get_query(), $_GET, $_POST));
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->display();
|
|
|
|
}
|
2008-01-02 21:49:12 +00:00
|
|
|
|
2020-10-27 22:03:56 +00:00
|
|
|
if ($database->is_transaction_open()) {
|
2019-06-24 21:58:50 +00:00
|
|
|
$database->commit();
|
|
|
|
}
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
// saving cache data and profiling data to disk can happen later
|
|
|
|
if (function_exists("fastcgi_finish_request")) {
|
|
|
|
fastcgi_finish_request();
|
|
|
|
}
|
2024-01-05 16:30:54 +00:00
|
|
|
$exit_code = 0;
|
2023-01-10 22:44:09 +00:00
|
|
|
} catch (\Exception $e) {
|
2024-01-15 22:22:11 +00:00
|
|
|
if ($database->is_transaction_open()) {
|
2019-05-28 16:59:38 +00:00
|
|
|
$database->rollback();
|
|
|
|
}
|
2024-08-31 16:05:18 +00:00
|
|
|
if (is_a($e, \Shimmie2\UserError::class)) {
|
2024-02-10 23:03:14 +00:00
|
|
|
$page->set_mode(PageMode::PAGE);
|
|
|
|
$page->set_code($e->http_code);
|
|
|
|
$page->set_title("Error");
|
|
|
|
$page->add_block(new Block(null, \MicroHTML\SPAN($e->getMessage())));
|
|
|
|
$page->display();
|
|
|
|
} else {
|
|
|
|
_fatal_error($e);
|
|
|
|
}
|
2024-01-05 16:30:54 +00:00
|
|
|
$exit_code = 1;
|
2020-03-18 20:26:52 +00:00
|
|
|
} finally {
|
|
|
|
$_tracer->end();
|
|
|
|
if (TRACE_FILE) {
|
|
|
|
if (
|
|
|
|
empty($_SERVER["REQUEST_URI"])
|
2020-10-25 17:05:36 +00:00
|
|
|
|| (@$_GET["trace"] == "on")
|
2020-03-18 20:26:52 +00:00
|
|
|
|| (
|
2023-01-11 13:27:57 +00:00
|
|
|
(ftime() - $_shm_load_start) > TRACE_THRESHOLD
|
2020-03-18 20:26:52 +00:00
|
|
|
&& ($_SERVER["REQUEST_URI"] ?? "") != "/upload"
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
$_tracer->flush(TRACE_FILE);
|
|
|
|
}
|
2019-09-29 13:30:55 +00:00
|
|
|
}
|
2019-07-05 19:49:47 +00:00
|
|
|
}
|
2024-01-05 16:30:54 +00:00
|
|
|
if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') {
|
|
|
|
exit($exit_code);
|
2024-01-05 16:33:59 +00:00
|
|
|
}
|