/
index.php
183 lines (149 loc) · 6.02 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
<?php
/**
* index.php
*
* This is the main controller file. It handles the invocation of the various
* modules, plugin initialization and template rendering. It also loads the
* config file, etc.
*
* @author Joe Stump <joe@joestump.net>
* @copyright Joe Stump <joe@joestump.net>
* @filesource
* @link http://www.jcssolutions.com
* @link http://www.jerum.com
* @package JAX
*/
session_start();
$_COOKIE['jax_userID'] = $_SESSION['jax_userID'];
$_COOKIE['jax_sessionID'] = $_SESSION['jax_sessionID'];
require_once('./JxConfig.php');
$initialized = array(); // keep track of modules we have initalized
if (JX_PATH_MODE === JX_PATH_MODE_HOSTED &&
is_dir(JX_HOSTED_PATH.'/modules')) {
$dir = dir(JX_HOSTED_PATH.'/modules');
while (false !== ($entry = $dir->read())) {
$module = JX_HOSTED_PATH.'/modules/'.$entry;
if (is_dir($module) && !in_array($entry,array('.','..','CVS'))) {
if (file_exists($module.'/init.php') &&
file_exists($module.'/'.$entry.'.php')) {
include($module.'/init.php');
$initialized[] = $entry;
}
}
}
$dir->close();
}
$dir = dir(JX_CORE_PATH.'/modules');
while (false !== ($entry = $dir->read())) {
$module = JX_CORE_PATH.'/modules/'.$entry;
if (!in_array($entry,$initialized) &&
is_dir($module) && !in_array($entry,array('.','..','CVS'))) {
if (file_exists($module.'/init.php')) {
include($module.'/init.php');
}
}
}
$dir->close();
JxUri::parseURI();
$jaxHandler = JxUri::getHandler();
$jaxModule = JxUri::getModule();
$null = null;
if (strlen($jaxModule)) {
if (JX_PATH_MODE === JX_PATH_MODE_DEFAULT) {
$jaxModulePath = JX_CORE_PATH.'/modules';
define('JX_CONTENT_PATH',JX_CORE_PATH.'/content');
define('JX_SECURE_CONTENT_PATH',JX_CORE_PATH.'/../secure');
define('JX_BASE_PATH',JX_CORE_PATH);
} else {
define('JX_CONTENT_PATH',JX_HOSTED_PATH.'/content');
define('JX_SECURE_CONTENT_PATH',JX_CORE_PATH.'/../secure');
if (in_array($jaxModule,$initialized)) {
define('JX_BASE_PATH',JX_HOSTED_PATH);
} else {
define('JX_BASE_PATH',JX_CORE_PATH);
}
$jaxModulePath = JX_BASE_PATH.'/modules';
}
define('JX_BASE_LOG',JX_BASE_PATH.'/jax.log');
$log = & JxSingleton::factory('log');
JxPlugin::initializePlugins();
JxPlugin::doHook('indexTop',$null);
// Decide if we are running a default module or a sub-module
$jaxClass = JxUri::getClass();
if (file_exists($jaxModulePath.'/'.$jaxModule.'/'.$jaxClass.'.php')) {
$jaxModuleFile = $jaxClass; // we are running a sub-module
} else {
$jaxModuleFile = $jaxModule;
}
if(JxModule::isValid($jaxModule)) {
require_once($jaxModulePath.'/'.$jaxModule.'/config.php');
require_once($jaxModulePath.'/'.$jaxModule.'/'.$jaxModuleFile.'.php');
$module = & new $jaxModuleFile();
// Possibly not used ... grep came up negative
// $GLOBALS['jax_user'] = & new JxUser($_COOKIE['jax_userID']);
if (!JxModule::isError($module)) {
// They don't have proper perms to access this module
if (!$module->authenticate()) {
if (defined('JX_LOGIN_URL')) {
$go = JX_LOGIN_URL;
} else {
$go = $_SERVER['SCRIPT_NAME'].'/users/login';
}
$go .= '?pg='.urldecode($_SERVER['REQUEST_URI']);
JxHttp::redirect($go);
} else {
// If the module *must* be ran via SSL (ie. checkout) and
// we are being requested at port 80 we need to redirect.
if ($module->forceSSL && JX_HTTP_PROTOCOL != 'https') {
$go = 'https://'.$_SERVER['SERVER_NAME'].
$_SERVER['REQUEST_URI'];
JxHttp::redirect($go);
} elseif (!$module->forceSSL && JX_HTTP_PROTOCOL == 'https') {
$go = 'http://'.$_SERVER['SERVER_NAME'].
$_SERVER['REQUEST_URI'];
JxHttp::redirect($go);
}
$result = null;
if (strlen($jaxHandler) &&
method_exists($module,$jaxHandler)) {
$result = $module->$jaxHandler();
} elseif (method_exists($module,'__default')) {
$result = $module->__default();
}
if (PEAR::isError($result)) {
$errorTemplatePath = JX_BASE_PATH.'/tpl/'.JX_TEMPLATE;
$template = & new JxTemplate($errorTemplatePath);
$module->template = $template;
$module->template->assign('msg',$result->getMessage());
$module->templateFile = 'error.tpl';
}
if ($module->user->track) {
ob_start();
}
$module->render();
if ($module->user->track) {
$contents = ob_get_contents();
ob_end_clean();
}
}
}
} else {
// we have an invalid module
die("The requested module does not exist or is in a state of error!");
}
JxPlugin::doHook('indexBottom',$null);
} else {
if(strlen(JX_DEFAULT_MODULE)) {
$go = JX_APP_PATH.'/'.JX_DEFAULT_MODULE;
if(strlen(JX_DEFAULT_HANDLER)) {
$go .= '/eventHandler='.JX_DEFAULT_HANDLER;
}
} elseif(strlen(trim(JX_DEFAULT_URI))) {
$go = JX_DEFAULT_URI;
} else {
die("JAX Error: No default module defined!");
}
JxHttp::redirect($go);
}
session_write_close();
?>