forked from shish/shimmie2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
154 lines (139 loc) · 4.42 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* \mainpage Shimmie2 / SCore Documentation
*
* SCore is a framework designed for writing flexible, extendable applications.
* Whereas most PHP apps are built monolithicly, score's event-based nature
* 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...
*
* To learn about the innards of SCore, start with the \ref overview.
*
*
* \page overview High Level Overview
*
* Dijkstra will kill me for personifying my architecture, but I can't think
* of a better way without going into all the little details.
*
* 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.
*
* To learn more about the architecture:
*
* \li \ref eande
* \li \ref themes
*
* To learn more about practical development:
*
* \li \ref scglobals
* \li \ref unittests
* \li \ref hello
*
* \page scglobals SCore 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
*
* Each of these can be imported at the start of a function with eg "global $page, $user;"
*/
// set up and purify the environment
define("DEBUG", true);
define("COVERAGE", true);
define("CACHE_MEMCACHE", false);
define("CACHE_DIR", false);
define("VERSION", 'trunk');
define("SCORE_VERSION", 's2hack/'.VERSION);
define("COOKIE_PREFIX", 'shm');
if(empty($database_dsn) && !file_exists("config.php")) {
header("Location: install.php");
exit;
}
require_once "config.php";
require_once "core/util.inc.php";
if(COVERAGE) {
_start_coverage();
register_shutdown_function("_end_coverage");
}
_version_check();
_sanitise_environment();
_start_cache();
try {
// load base files
$files = array_merge(glob("core/*.php"), glob("ext/*/main.php"));
foreach($files as $filename) {
require_once $filename;
}
// connect to the database
$database = new Database();
//$database->db->fnExecute = '_count_execs'; // FIXME: PDO equivalent
$database->db->beginTransaction();
$config = new DatabaseConfig($database);
// load the theme parts
$_theme = $config->get_string("theme", "default");
if(!file_exists("themes/$_theme")) $_theme = "default";
if(file_exists("themes/$_theme/custompage.class.php")) require_once "themes/$_theme/custompage.class.php";
require_once "themes/$_theme/layout.class.php";
require_once "themes/$_theme/themelet.class.php";
$themelets = glob("ext/*/theme.php");
foreach($themelets as $filename) {
require_once $filename;
}
$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)
&& in_array("ext/{$m[1]}/theme.php", $themelets)) {
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, $c->get_priority());
}
}
// start the page generation waterfall
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
$user = _get_user($config, $database);
send_event(new InitExtEvent());
send_event(_get_page_request());
$page->display();
$database->db->commit();
_end_cache();
}
catch(Exception $e) {
$version = VERSION;
$message = $e->getMessage();
//$trace = var_dump($e->getTrace());
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;
$database->db->rollback();
}
?>