-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.php
305 lines (247 loc) · 9.14 KB
/
core.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
# MantisBT - a php based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* @package MantisBT
* @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
* @copyright Copyright (C) 2002 - 2014 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/
/**
* Before doing anything... check if MantisBT is down for maintenance
*
* To make MantisBT 'offline' simply create a file called
* 'mantis_offline.php' in the MantisBT root directory.
* Users are redirected to that file if it exists.
* If you have to test MantisBT while it's offline, add the
* parameter 'mbadmin=1' to the URL.
*/
if ( file_exists( 'mantis_offline.php' ) && !isset( $_GET['mbadmin'] ) ) {
include( 'mantis_offline.php' );
exit;
}
$g_request_time = microtime(true);
ob_start();
/**
* Load supplied constants
*/
require_once( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR.'constant_inc.php' );
/**
* Load user-defined constants (if required)
*/
if ( file_exists( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'custom_constants_inc.php' ) ) {
require_once( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'custom_constants_inc.php' );
# Check for the old name of the user-defined constants file (to be deprecated in 1.3)
} else if ( file_exists( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'custom_constant_inc.php' ) ) {
require_once( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'custom_constant_inc.php' );
}
$t_config_inc_found = false;
/**
* Include default configuration settings
*/
require_once( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'config_defaults_inc.php' );
# config_inc may not be present if this is a new install
if ( file_exists( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'config_inc.php' ) ) {
require_once( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'config_inc.php' );
$t_config_inc_found = true;
}
# Allow an environment variable (defined in an Apache vhost for example)
# to specify a config file to load to override other local settings
$t_local_config = getenv( 'MANTIS_CONFIG' );
if ( $t_local_config && file_exists( $t_local_config ) ){
require_once( $t_local_config );
$t_config_inc_found = true;
}
unset( $t_local_config );
# Attempt to find the location of the core files.
$t_core_path = dirname(__FILE__).DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR;
if (isset($GLOBALS['g_core_path']) && !isset( $HTTP_GET_VARS['g_core_path'] ) && !isset( $HTTP_POST_VARS['g_core_path'] ) && !isset( $HTTP_COOKIE_VARS['g_core_path'] ) ) {
$t_core_path = $g_core_path;
}
$g_core_path = $t_core_path;
unset( $t_core_path );
/*
* Set include paths
*/
define ( 'BASE_PATH' , dirname( __FILE__ ) );
$mantisLibrary = BASE_PATH . DIRECTORY_SEPARATOR . 'library';
$mantisCore = $g_core_path;
/*
* Prepend the application/ and tests/ directories to the
* include_path.
*/
$path = array(
$mantisCore,
$mantisLibrary,
get_include_path()
);
set_include_path( implode( PATH_SEPARATOR, $path ) );
/*
* Unset global variables that are no longer needed.
*/
unset($mantisRoot, $mantisLibrary, $mantisCore, $path);
require_once( 'mobile_api.php' );
if ( strlen( $GLOBALS['g_mantistouch_url'] ) > 0 && mobile_is_mobile_browser() ) {
$t_url = sprintf( $GLOBALS['g_mantistouch_url'], $GLOBALS['g_path'] );
$t_issue_id = '';
if ( strstr( $_SERVER['SCRIPT_NAME'], 'view.php' ) !== false ) {
$t_issue_id = (int)$_GET['id'];
}
if ( !empty( $t_issue_id ) ) {
if ( strstr( $t_url, 'url=' ) !== false ) {
$t_url .= '&issue_id=' . $t_issue_id;
} else {
$t_url .= '?issue_id=' . $t_issue_id;
}
}
if ( OFF == $g_use_iis ) {
header( 'Status: 302' );
}
header( 'Content-Type: text/html' );
if ( ON == $g_use_iis ) {
header( "Refresh: 0;$t_url" );
} else {
header( "Location: $t_url" );
}
exit; # additional output can cause problems so let's just stop output here
}
# load UTF8-capable string functions
require_once( 'utf8/utf8.php' );
require_once( UTF8 . '/str_pad.php' );
# Include compatibility file before anything else
require_once( 'php_api.php' );
# Define an autoload function to automatically load classes when referenced.
function __autoload( $className ) {
global $g_core_path;
$t_require_path = $g_core_path . 'classes' . DIRECTORY_SEPARATOR . $className . '.class.php';
if ( file_exists( $t_require_path ) ) {
require_once( $t_require_path );
return;
}
$t_require_path = BASE_PATH . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'rssbuilder' . DIRECTORY_SEPARATOR . 'class.' . $className . '.inc.php';
if ( file_exists( $t_require_path ) ) {
require_once( $t_require_path );
return;
}
}
spl_autoload_register( '__autoload' );
if ( ($t_output = ob_get_contents()) != '') {
echo 'Possible Whitespace/Error in Configuration File - Aborting. Output so far follows:<br />';
echo var_dump($t_output);
die;
}
unset( $t_output );
require_once( 'utility_api.php' );
require_once( 'compress_api.php' );
compress_start_handler();
if ( false === $t_config_inc_found ) {
if( php_sapi_name() == 'cli' ) {
echo "Error: config_inc.php file not found; ensure MantisBT is properly setup.\n";
exit(1);
}
# if not found, redirect to the admin page to install the system
# this needs to be long form and not replaced by is_page_name as that function isn't loaded yet
if ( !( isset( $_SERVER['SCRIPT_NAME'] ) && ( 0 < strpos( $_SERVER['SCRIPT_NAME'], 'admin' ) ) ) ) {
if ( OFF == $g_use_iis ) {
header( 'Status: 302' );
}
header( 'Content-Type: text/html' );
if ( ON == $g_use_iis ) {
header( "Refresh: 0;url=admin/install.php" );
} else {
header( "Location: admin/install.php" );
}
exit; # additional output can cause problems so let's just stop output here
}
}
# Load rest of core in separate directory.
require_once( 'config_api.php' );
require_once( 'logging_api.php' );
# Load internationalization functions (needed before database_api, in case database connection fails)
require_once( 'lang_api.php' );
# error functions should be loaded to allow database to print errors
require_once( 'error_api.php' );
require_once( 'helper_api.php' );
# DATABASE WILL BE OPENED HERE!! THE DATABASE SHOULDN'T BE EXPLICITLY
# OPENED ANYWHERE ELSE.
require_once( 'database_api.php' );
# PHP Sessions
require_once( 'session_api.php' );
# Initialize Event System
require_once( 'event_api.php' );
require_once( 'events_inc.php' );
# Plugin initialization
require_once( 'plugin_api.php' );
if ( !defined( 'PLUGINS_DISABLED' ) ) {
plugin_init_installed();
}
# Authentication and user setup
require_once( 'authentication_api.php' );
require_once( 'project_api.php' );
require_once( 'project_hierarchy_api.php' );
require_once( 'user_api.php' );
require_once( 'access_api.php' );
# Wiki Integration
if( config_get_global( 'wiki_enable' ) == ON ) {
require_once( 'wiki_api.php' );
wiki_init();
}
# Display API's
require_once( 'http_api.php' );
require_once( 'html_api.php' );
require_once( 'gpc_api.php' );
require_once( 'form_api.php' );
require_once( 'print_api.php' );
require_once( 'collapse_api.php' );
if ( !isset( $g_login_anonymous ) ) {
$g_login_anonymous = true;
}
# Attempt to set the current timezone to the user's desired value
# Note that PHP 5.1 on RHEL/CentOS doesn't support the timezone functions
# used here so we just skip this action on RHEL/CentOS platforms.
if ( function_exists( 'timezone_identifiers_list' ) ) {
if ( !is_blank ( config_get_global( 'default_timezone' ) ) ) {
// if a default timezone is set in config, set it here, else we use php.ini's value
// having a timezone set avoids a php warning
date_default_timezone_set( config_get_global( 'default_timezone' ) );
} else {
# To ensure proper detection of timezone settings issues, we must not
# initialize the default timezone when executing admin checks
if( basename( $_SERVER['SCRIPT_NAME'] ) != 'check.php' ) {
config_set_global( 'default_timezone', date_default_timezone_get(), true );
}
}
if ( auth_is_user_authenticated() ) {
date_default_timezone_set( user_pref_get_pref( auth_get_current_user_id(), 'timezone' ) );
}
}
if ( !defined( 'MANTIS_INSTALLER' ) ) {
collapse_cache_token();
}
// custom functions (in main directory)
/** @todo Move all such files to core/ */
require_once( 'custom_function_api.php' );
$t_overrides = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'custom_functions_inc.php';
if ( file_exists( $t_overrides ) ) {
require_once( $t_overrides );
}
unset( $t_overrides );
// set HTTP response headers
http_all_headers();
// push push default language to speed calls to lang_get
if ( !isset( $g_skip_lang_load ) ) {
lang_push( lang_get_default() );
}
# signal plugins that the core system is loaded
event_signal( 'EVENT_CORE_READY' );