/
core.php
195 lines (158 loc) · 6.94 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
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net
# Mantis 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.
#
# Mantis 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 Mantis. If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------
# $Id: core.php,v 1.52.2.1 2007-10-13 22:33:13 giallu Exp $
# --------------------------------------------------------
###########################################################################
# INCLUDES
###########################################################################
# --------------------
# timer analysis
function microtime_float() {
list( $usec, $sec ) = explode( " ", microtime() );
return ( (float)$usec + (float)$sec );
}
$g_request_time = microtime_float();
# Before doing anything else, start output buffering so we don't prevent
# headers from being sent if there's a blank line in an included file
ob_start( 'compress_handler' );
# Include compatibility file before anything else
require_once( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR.'php_api.php' );
# Check if Mantis is down for maintenance
#
# To make Mantis 'offline' simply create a file called
# 'mantis_offline.php' in the mantis root directory.
# Users are redirected to that file if it exists.
# If you have to test Mantis while it's offline, add the
# parameter 'mbadmin=1' to the URL.
#
$t_mantis_offline = 'mantis_offline.php';
if ( file_exists( $t_mantis_offline ) && !isset( $_GET['mbadmin'] ) ) {
include( $t_mantis_offline );
exit;
}
# Load constants and configuration files
require_once( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR.'constant_inc.php' );
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;
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;
}
if ( false === $t_config_inc_found ) {
# 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['PHP_SELF'] ) && ( 0 < strpos( $_SERVER['PHP_SELF'], '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
}
}
# 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;
}
# Load rest of core in separate directory.
require_once( $t_core_path.'config_api.php' );
require_once( $t_core_path.'timer_api.php' );
require_once( $t_core_path.'logging_api.php' );
# load utility functions used by everything else
require_once( $t_core_path.'utility_api.php' );
require_once( $t_core_path.'compress_api.php' );
# Load internationalization functions (needed before database_api, in case database connection fails)
require_once( $t_core_path.'lang_api.php' );
# error functions should be loaded to allow database to print errors
require_once( $t_core_path.'authentication_api.php' );
require_once( $t_core_path.'html_api.php' );
require_once( $t_core_path.'error_api.php' );
require_once( $t_core_path.'gpc_api.php' );
require_once( $t_core_path.'session_api.php' );
require_once( $t_core_path.'form_api.php' );
# custom functions (in main directory)
# @@@ Move all such files to core/
require_once( $t_core_path . 'custom_function_api.php' );
$t_overrides = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'custom_functions_inc.php';
if ( file_exists( $t_overrides ) ) {
require_once( $t_overrides );
}
# initialize our timer
$g_timer = new BC_Timer;
# seed random number generator
list( $usec, $sec ) = explode( ' ', microtime() );
mt_srand( $sec*$usec );
# DATABASE WILL BE OPENED HERE!! THE DATABASE SHOULDN'T BE EXPLICITLY
# OPENED ANYWHERE ELSE.
require_once( $t_core_path.'database_api.php' );
# Basic browser detection
$t_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'none';
$t_browser_name = 'Normal';
if ( strpos( $t_user_agent, 'MSIE' ) ) {
$t_browser_name = 'IE';
}
# Headers to prevent caching
# with option to bypass if running from script
global $g_bypass_headers, $g_allow_browser_cache;
if ( !isset( $g_bypass_headers ) && !headers_sent() ) {
if ( isset( $g_allow_browser_cache ) && ON == $g_allow_browser_cache ) {
switch ( $t_browser_name ) {
#case 'IE':
# header( 'Cache-Control: private, proxy-revalidate' );
# break;
default:
header( 'Cache-Control: private, must-revalidate' );
break;
}
} else {
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
}
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s \G\M\T', time() ) );
# SEND USER-DEFINED HEADERS
foreach( config_get( 'custom_headers' ) as $t_header ) {
header( $t_header );
}
}
require_once( $t_core_path.'project_api.php' );
require_once( $t_core_path.'project_hierarchy_api.php' );
require_once( $t_core_path.'access_api.php' );
require_once( $t_core_path.'print_api.php' );
require_once( $t_core_path.'helper_api.php' );
require_once( $t_core_path.'user_api.php' );
# push push default language to speed calls to lang_get
lang_push( lang_get_default() );
if ( !isset( $g_bypass_headers ) && !headers_sent() ) {
header( 'Content-type: text/html;charset=' . lang_get( 'charset' ) );
}
?>