This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/index.php

116 lines
2.8 KiB
PHP
Raw Normal View History

<?php
2009-07-21 03:18:40 +00:00
/**
* \mainpage Shimmie2 / SCore Documentation
*
* There are a bunch of Extension subclasses, they talk to eachother by sending
* and recieving Event subclasses. The topic of conversation is decided by the
* initial PageRequestEvent, and each extension puts its notes into the shared
* Page data store. Once the conversation is over, the Page is passed to the
* current theme's Layout class which will tidy up the data and present it to
* the user.
*
*
* \page globals Globals
*
* There are four global variables which are pretty essential to most extensions:
*
* \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
*/
// set up and purify the environment
define("DEBUG", true);
2009-01-04 16:24:06 +00:00
define("SCORE_VERSION", 's2hack');
define("VERSION", 'trunk');
2009-01-04 16:24:06 +00:00
if(!file_exists("config.php")) {
header("Location: install.php");
exit;
}
2009-01-04 16:24:06 +00:00
require_once "core/util.inc.php";
2009-07-21 03:18:40 +00:00
_version_check();
_sanitise_environment();
2009-01-04 16:24:06 +00:00
try {
// load base files
$files = array_merge(glob("core/*.php"), glob("ext/*/main.php"));
foreach($files as $filename) {
require_once $filename;
}
2009-01-04 16:24:06 +00:00
// connect to the database
$database = new Database();
$database->db->fnExecute = '_count_execs';
$config = new DatabaseConfig($database);
2009-01-04 16:24:06 +00:00
// load the theme parts
$_theme = $config->get_string("theme", "default");
if(!file_exists("themes/$_theme")) $_theme = "default";
require_once "themes/$_theme/page.class.php";
require_once "themes/$_theme/layout.class.php";
require_once "themes/$_theme/themelet.class.php";
2009-01-04 16:24:06 +00:00
$themelets = glob("ext/*/theme.php");
foreach($themelets as $filename) {
require_once $filename;
}
2009-01-04 16:24:06 +00:00
$custom_themelets = glob("themes/$_theme/*.theme.php");
if($custom_themelets) {
$m = array();
foreach($custom_themelets as $filename) {
if(preg_match("/themes\/$_theme\/(.*)\.theme\.php/",$filename,$m)
2009-06-05 19:53:00 +00:00
&& in_array("ext/{$m[1]}/theme.php", $themelets)) {
2009-01-04 16:24:06 +00:00
require_once $filename;
}
}
}
// initialise the extensions
foreach(get_declared_classes() as $class) {
if(is_subclass_of($class, "SimpleExtension")) {
$c = new $class();
$c->i_am($c);
add_event_listener($c);
}
}
2009-01-04 16:24:06 +00:00
// start the page generation waterfall
$page = new Page();
$user = _get_user($config, $database);
send_event(new InitExtEvent());
send_event(_get_page_request());
$page->display();
2009-01-04 16:24:06 +00:00
// for databases which support transactions
2009-01-22 15:51:50 +00:00
if($database->engine->name != "sqlite") {
$database->db->CommitTrans(true);
}
2009-01-04 16:24:06 +00:00
}
catch(Exception $e) {
$version = VERSION;
$message = $e->getMessage();
header("HTTP/1.0 500 Internal Error");
print <<<EOD
<html>
<head>
<title>Internal error - SCore-$version</title>
</head>
<body>
<h1>Internal Error</h1>
<p>$message
</body>
</html>
EOD;
}
?>