-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
138 lines (107 loc) · 3.33 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
<?php
// Version
define('VERSION', '0.1');
// Configuration
require_once(__DIR__ . '/config/blog.php');
// Startup
require_once(DIR_SYSTEM . 'startup.php');
// Registry
$registry = new Registry();
// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);
// Config
$config = new Config();
$registry->set('config', $config);
//flag for site being broken/administratively down
$site_down = false;
// Database
try {
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, '');
$registry->set('db', $db);
} catch (ErrorException $ex) {
$site_down = true;
}
$config->set('config_url', HTTP_SERVER);
$config->set('config_ssl', HTTPS_SERVER);
$config->set('config_short_url', HTTP_SHORT);
$config->set('config_short_ssl', HTTPS_SHORT);
$config->set('config_secure', true);
// Url
$url = new Url($config->get('config_ssl'), $config->get('config_secure') ? $config->get('config_ssl') : $config->get('config_url'));
$registry->set('url', $url);
// Short_Url
$short_url = new Url($config->get('config_short_url'), $config->get('config_secure') ? $config->get('config_ssl') : $config->get('config_short_url'));
$registry->set('short_url', $short_url);
// Log
$log = new Log('error.txt');
$registry->set('log', $log);
function error_handler($errno, $errstr, $errfile, $errline) {
global $log, $config;
switch ($errno) {
case E_NOTICE:
case E_USER_NOTICE:
$error = 'Notice';
break;
case E_WARNING:
case E_USER_WARNING:
$error = 'Warning';
break;
case E_ERROR:
case E_USER_ERROR:
$error = 'Fatal Error';
break;
default:
$error = 'Unknown';
break;
}
if ($config->get('config_error_display')) {
echo '<b>' . $error . '</b>: ' . $errstr . ' in <b>' . $errfile . '</b> on line <b>' . $errline . '</b>';
}
if ($config->get('config_error_log')) {
$log->write('PHP ' . $error . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
}
return true;
}
// Error Handler
set_error_handler('error_handler');
// Request
$request = new Request();
$registry->set('request', $request);
if(ENVIRONMENT != 'LIVE' && isset($request->get['theme'])){
$config->set('config_template', $request->get['theme']);
} else {
$config->set('config_template', 'default');
//$config->set('config_template', TEMPLATE_THEME);
}
// Response
$response = new Response();
$response->addHeader('Content-Type: text/html; charset=utf-8');
$response->setCompression($config->get('config_compression'));
$registry->set('response', $response);
// Cache
$cache = new Cache('file');
$registry->set('cache', $cache);
// Session
$session = new Session();
$registry->set('session', $session);
// Document
$registry->set('document', new Document());
// Front Controller
$controller = new Front($registry);
// SEO URL's
$controller->addPreAction(new Action('common/seo_url'));
// Maintenance Mode
//$controller->addPreAction(new Action('common/maintenance'));
// Router
if ($site_down) {
$action = new Action('error/site_down');
} else if (isset($request->get['route'])) {
$action = new Action($request->get['route']);
} else {
$action = new Action('error/not_found');
}
// Dispatch
$controller->dispatch($action, new Action('error/not_found'));
// Output
$response->output();