2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
2009-07-21 03:18:40 +00:00
|
|
|
/**
|
|
|
|
* \mainpage Shimmie2 / SCore Documentation
|
2009-07-21 06:36:12 +00:00
|
|
|
*
|
|
|
|
* SCore is a framework designed for writing flexible, extendable applications.
|
2013-11-28 05:34:31 +00:00
|
|
|
* Whereas most PHP apps are built monolithically, score's event-based nature
|
2009-07-21 06:36:12 +00:00
|
|
|
* allows parts to be mixed and matched. For instance, the most famous
|
|
|
|
* collection of score extensions is the Shimmie image board, which includes
|
|
|
|
* user management, a wiki, a private messaging system, etc. But one could
|
|
|
|
* easily remove the image board bits and simply have a wiki with users and
|
|
|
|
* PMs; or one could replace it with a blog module; or one could have a blog
|
|
|
|
* which links to images on an image board, with no wiki or messaging, and so
|
|
|
|
* on and so on...
|
2014-02-22 20:36:52 +00:00
|
|
|
*
|
2009-07-21 06:36:12 +00:00
|
|
|
* Dijkstra will kill me for personifying my architecture, but I can't think
|
|
|
|
* of a better way without going into all the little details.
|
2013-11-28 05:34:31 +00:00
|
|
|
* There are a bunch of Extension subclasses, they talk to each other by sending
|
|
|
|
* and receiving Event subclasses. The primary driver for each conversation is the
|
2012-03-05 13:56:36 +00:00
|
|
|
* initial PageRequestEvent. If an Extension wants to display something to the
|
|
|
|
* user, it adds a block to the Page data store. Once the conversation is over, the Page is passed to the
|
2009-07-21 03:18:40 +00:00
|
|
|
* current theme's Layout class which will tidy up the data and present it to
|
2012-03-05 13:56:36 +00:00
|
|
|
* the user. To see this in a more practical sense, see \ref hello.
|
2009-07-21 03:18:40 +00:00
|
|
|
*
|
2009-07-21 06:36:12 +00:00
|
|
|
* To learn more about the architecture:
|
|
|
|
*
|
|
|
|
* \li \ref eande
|
|
|
|
* \li \ref themes
|
|
|
|
*
|
|
|
|
* To learn more about practical development:
|
|
|
|
*
|
|
|
|
* \li \ref scglobals
|
|
|
|
* \li \ref unittests
|
|
|
|
*
|
|
|
|
* \page scglobals SCore Globals
|
2014-02-22 20:36:52 +00:00
|
|
|
*
|
2009-07-21 03:18:40 +00:00
|
|
|
* There are four global variables which are pretty essential to most extensions:
|
2014-02-22 20:36:52 +00:00
|
|
|
*
|
2009-07-21 03:18:40 +00:00
|
|
|
* \li $config -- some variety of Config subclass
|
|
|
|
* \li $database -- a Database object used to get raw SQL access
|
|
|
|
* \li $page -- a Page to holds all the loose bits of extension output
|
|
|
|
* \li $user -- the currently logged in User
|
2009-07-21 06:36:12 +00:00
|
|
|
*
|
|
|
|
* Each of these can be imported at the start of a function with eg "global $page, $user;"
|
2009-07-21 03:18:40 +00:00
|
|
|
*/
|
|
|
|
|
2020-01-27 19:28:58 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
|
|
|
* Make sure that shimmie is correctly installed *
|
|
|
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
if (!file_exists("data/config/shimmie.conf.php")) {
|
2020-02-06 02:19:51 +00:00
|
|
|
require_once "core/install.php";
|
|
|
|
install();
|
2019-05-28 16:59:38 +00:00
|
|
|
exit;
|
2011-12-24 21:56:26 +00:00
|
|
|
}
|
2007-10-27 19:38:13 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
if (!file_exists("vendor/")) {
|
|
|
|
//CHECK: Should we just point to install.php instead? Seems unsafe though.
|
|
|
|
print <<<EOD
|
2016-06-18 05:42:52 +00:00
|
|
|
<!DOCTYPE html>
|
2020-03-13 09:23:54 +00:00
|
|
|
<html lang="en">
|
2016-06-18 05:42:52 +00:00
|
|
|
<head>
|
|
|
|
<title>Shimmie Error</title>
|
2020-02-23 18:48:25 +00:00
|
|
|
<link rel="shortcut icon" href="ext/static_files/static/favicon.ico">
|
|
|
|
<link rel="stylesheet" href="ext/static_files/style.css" type="text/css">
|
2016-06-18 05:42:52 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="installer">
|
|
|
|
<h1>Install Error</h1>
|
|
|
|
<h3>Warning: Composer vendor folder does not exist!</h3>
|
|
|
|
<div class="container">
|
|
|
|
<p>Shimmie is unable to find the composer vendor directory.<br>
|
2018-11-07 00:08:26 +00:00
|
|
|
Have you followed the composer setup instructions found in the
|
2019-05-29 17:23:29 +00:00
|
|
|
<a href="https://github.com/shish/shimmie2#installation-development">README</a>?</p>
|
2016-06-18 05:42:52 +00:00
|
|
|
|
2018-11-07 00:08:26 +00:00
|
|
|
<p>If you are not intending to do any development with Shimmie,
|
|
|
|
it is highly recommend you use one of the pre-packaged releases
|
|
|
|
found on <a href="https://github.com/shish/shimmie2/releases">Github</a> instead.</p>
|
2016-06-18 05:42:52 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOD;
|
2019-05-28 16:59:38 +00:00
|
|
|
http_response_code(500);
|
|
|
|
exit;
|
2016-06-18 05:42:52 +00:00
|
|
|
}
|
|
|
|
|
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/polyfills.php";
|
|
|
|
require_once "core/util.php";
|
|
|
|
|
|
|
|
global $cache, $config, $database, $user, $page, $_tracer;
|
|
|
|
_sanitise_environment();
|
2020-03-13 09:23:54 +00:00
|
|
|
$_tracer = new EventTracer();
|
2020-01-27 19:28:58 +00:00
|
|
|
$_tracer->begin("Bootstrap");
|
|
|
|
_load_core_files();
|
|
|
|
$cache = new Cache(CACHE_DSN);
|
|
|
|
$database = new Database(DATABASE_DSN);
|
|
|
|
$config = new DatabaseConfig($database);
|
|
|
|
ExtensionInfo::load_all_extension_info();
|
|
|
|
Extension::determine_enabled_extensions();
|
|
|
|
require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php"));
|
|
|
|
_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-18 20:26:52 +00:00
|
|
|
// $_tracer->mark(@$_SERVER["REQUEST_URI"]);
|
|
|
|
$_tracer->begin(
|
|
|
|
$_SERVER["REQUEST_URI"] ?? "No Request",
|
|
|
|
[
|
|
|
|
"user"=>$_COOKIE["shm_user"] ?? "No User",
|
|
|
|
"ip"=>$_SERVER['REMOTE_ADDR'] ?? "No IP",
|
|
|
|
"user_agent"=>$_SERVER['HTTP_USER_AGENT'] ?? "No UA",
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!SPEED_HAX) {
|
|
|
|
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') {
|
|
|
|
send_event(new CommandEvent($argv));
|
|
|
|
} else {
|
|
|
|
send_event(new PageRequestEvent(_get_query()));
|
|
|
|
$page->display();
|
|
|
|
}
|
2008-01-02 21:49:12 +00:00
|
|
|
|
2019-09-29 13:30:55 +00:00
|
|
|
if ($database->transaction===true) {
|
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();
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
2019-06-25 15:07:46 +00:00
|
|
|
if ($database && $database->transaction===true) {
|
2019-05-28 16:59:38 +00:00
|
|
|
$database->rollback();
|
|
|
|
}
|
|
|
|
_fatal_error($e);
|
2020-03-18 20:26:52 +00:00
|
|
|
} finally {
|
|
|
|
$_tracer->end();
|
|
|
|
if (TRACE_FILE) {
|
|
|
|
if (
|
|
|
|
empty($_SERVER["REQUEST_URI"])
|
|
|
|
|| (
|
|
|
|
(microtime(true) - $_shm_load_start) > TRACE_THRESHOLD
|
|
|
|
&& ($_SERVER["REQUEST_URI"] ?? "") != "/upload"
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
$_tracer->flush(TRACE_FILE);
|
|
|
|
}
|
2019-09-29 13:30:55 +00:00
|
|
|
}
|
2019-07-05 19:49:47 +00:00
|
|
|
}
|