-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
196 lines (165 loc) · 6.15 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/*
File: index.php
Also known as the bootstrap.
About: Author
Jaybill McCarthy
About: License
<http://letsgetbolts.com/docs/license>
*/
$ZZZZ_dump_include_path = @(boolean)$_GET['ZZZZ_dump_include_path'];
$basepath = realpath(__DIR__);
set_include_path(get_include_path().PATH_SEPARATOR.$basepath);
$ip = $_SERVER['REMOTE_ADDR'];
try {
require_once('header.php');
if ($isInstalled) {
if (!(boolean)$config['application']['launched']) {
$allowed_ips = explode(",", $config['application']['allowed_ips']);
$can_see = false;
foreach ($allowed_ips as $allowed_ip) {
if (strpos($ip, $allowed_ip) === 0) {
$can_see = true;
}
}
if (!$can_see) {
header ("Location: ".$config['application']['prelaunch_url']);
}
}
if (Bolts_Registry::get('on_screen_errors') === '1') {
ini_set('display_errors', 1);
ERROR_REPORTING(E_ALL);
}
}
if (Zend_Registry::isRegistered("theme")) {
$theme = Zend_Registry::get("theme");
} else {
Zend_Registry::set("theme", "default");
$theme = "default";
}
if (Zend_Registry::isRegistered("admin_theme")) {
$admin_theme = Zend_Registry::get("admin_theme");
} else {
Zend_Registry::set("admin_theme", "default");
$admin_theme = "default";
}
$theme_paths = array();
$theme_locations['frontend']['current_theme']['path'] = $basepath."/themes/frontend/".$theme;
$theme_locations['frontend']['current_theme']['url'] = "/themes/frontend/".$theme;
$theme_locations['frontend']['default_theme']['path'] = $basepath."/themes/frontend/default";
$theme_locations['frontend']['default_theme']['url'] = "/themes/frontend/default";
$theme_locations['admin']['current_theme']['path'] = $basepath."/themes/admin/".$admin_theme;
$theme_locations['admin']['current_theme']['url'] = "/themes/admin/".$admin_theme;
$theme_locations['admin']['default_theme']['path'] = $basepath."/core/bolts/views/admin";
$theme_locations['admin']['default_theme']['url'] = "/core/bolts/views/admin";
Zend_Registry::set("theme_locations", $theme_locations);
// Replace the ViewRenderer with Smarty as the default view
// args: template dir, smarty paths
if ($isInstalled) {
$smarty_config = new Zend_Config_Ini($config_file, 'smarty');
$smarty_config_array = $smarty_config->config->toArray();
} else {
$smarty_view_compiles = $basepath."/tmp/view_compiles";
$smarty_cache_dir = $basepath."/tmp/cache";
if (!file_exists($smarty_view_compiles)) {
throw new Exception("DIR_MISSING Missing directory ".$smarty_view_compiles);
}
if (!file_exists($smarty_cache_dir)) {
throw new Exception("DIR_MISSING Missing directory ".$smarty_cache_dir);
}
if (!is_writable($smarty_view_compiles)) {
throw new Exception("CANT_WRITE Can't write to directory ".$smarty_view_compiles);
}
if (!is_writable($smarty_cache_dir)) {
throw new Exception("CANT_WRITE Can't write to directory ".$smarty_cache_dir);
}
$smarty_config_array['compile_dir'] = $smarty_view_compiles;
$smarty_config_array['cache_dir'] = $smarty_cache_dir;
}
$smarty_config_array['plugins_dir'] = $smarty_plugins_dirs;
Zend_Registry::set('smarty_config', $smarty_config_array);
$view = new Bolts_View_Renderer(null, $smarty_config_array);
// Setup controller
$front = Zend_Controller_Front::getInstance();
$front->setDefaultModule("bolts");
$front->addModuleDirectory($core_module_dir);
$front->addModuleDirectory($module_dir);
$front->throwExceptions(true);
$front->setParam('noViewRenderer', false);
$view_renderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
$view_renderer->setNoController(true)
->setViewBasePathSpec($theme_locations['frontend']['current_theme']['path'].'/modules/:module')
->setViewScriptPathSpec(':controller/:action.:suffix')
->setViewScriptPathNoControllerSpec(':action.:suffix')
->setViewSuffix('tpl');
Zend_Controller_Action_HelperBroker::addHelper($view_renderer);
if ($isInstalled) {
$front->registerPlugin(new AclPlugin);
$Bolts_plugin->doAction('bootstrap', array('front_controller' => $front)); // ACTION HOOK
} else {
$front->registerPlugin(new InstallPlugin);
}
$router = new Zend_Controller_Router_Rewrite();
$front->setRouter($router);
if ($isInstalled) {
if (Bolts_Registry::get('enable_localization') == '1') {
$router->addRoute('default', new Zend_Controller_Router_Route(":locale/:module/:controller/:action/*", array(
'locale' => '',
'module' => "bolts",
'controller' => "index",
'action' => "index",
)));
} else {
$router->addRoute('default', new Zend_Controller_Router_Route(":module/:controller/:action/*", array(
'module' => "bolts",
'controller' => "index",
'action' => "index",
)));
}
if (file_exists($routes_file)) {
$routes = new Zend_Config_Ini($routes_file, 'default');
$router->addConfig($routes, 'routes');
}
$Bolts_plugin->doAction('bootstrap_routes', array('router' => $router)); // ACTION HOOK
}
if ($ZZZZ_dump_include_path) {
$include_paths = explode(":", get_include_path());
die(var_dump($include_paths, true));
}
$front->dispatch();
} catch (Zend_Db_Statement_Exception $ex) {
if (canDebug($ip, $config)) {
d($ex->getMessage());
dd($ex);
} else {
Bolts_Log::report("Database error", $ex, Zend_Log::EMERG);
header("Location: /errordocuments/error_DB.html");
}
} catch (Exception $ex) {
if (!empty($config) && canDebug($ip, $config)) {
d($ex->getMessage());
dd($ex);
} else {
$ex_type = trim(substr($ex->getMessage(), 0, strpos($ex->getMessage(), " ")));
switch ($ex_type) {
case "MISSING_LIBS":
header("Location: /errordocuments/error_LIBS.html");
break;
case "CANT_WRITE":
header("Location: /errordocuments/error_CANTWRITE.html");
break;
case "DIR_MISSING":
header("Location: /errordocuments/error_DIRMISSING.html");
break;
default:
if ($isInstalled) {
header("Location: /errordocuments/error_500.html");
Bolts_Log::report("Frontcontroller Error", $ex, Zend_Log::EMERG);
} else {
d($ex->getMessage());
dd($ex);
}
break;
}
}
}