Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / core.php
blob35934becd483948a90d72c61eee285db5a9ea3ea
1 <?php
2 # MantisBT - A PHP based bugtracking system
4 # MantisBT is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * MantisBT Core
20 * Initialises the MantisBT core, connects to the database, starts plugins and
21 * performs other global operations that either help initialise MantisBT or
22 * are required to be executed on every page load.
24 * @package MantisBT
25 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
26 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
27 * @link http://www.mantisbt.org
29 * @uses authentication_api.php
30 * @uses collapse_api.php
31 * @uses compress_api.php
32 * @uses config_api.php
33 * @uses config_defaults_inc.php
34 * @uses config_inc.php
35 * @uses constant_inc.php
36 * @uses custom_constants_inc.php
37 * @uses custom_functions_inc.php
38 * @uses database_api.php
39 * @uses event_api.php
40 * @uses http_api.php
41 * @uses lang_api.php
42 * @uses mantis_offline.php
43 * @uses plugin_api.php
44 * @uses php_api.php
45 * @uses user_pref_api.php
46 * @uses wiki_api.php
47 * @uses utf8/utf8.php
48 * @uses utf8/str_pad.php
51 /**
52 * Before doing anything... check if MantisBT is down for maintenance
54 * To make MantisBT 'offline' simply create a file called
55 * 'mantis_offline.php' in the MantisBT root directory.
56 * Users are redirected to that file if it exists.
57 * If you have to test MantisBT while it's offline, add the
58 * parameter 'mbadmin=1' to the URL.
60 if ( file_exists( 'mantis_offline.php' ) && !isset( $_GET['mbadmin'] ) ) {
61 include( 'mantis_offline.php' );
62 exit;
65 $g_request_time = microtime( true );
67 ob_start();
69 # Load supplied constants
70 require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'constant_inc.php' );
72 # Load user-defined constants (if required)
73 if ( file_exists( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'custom_constants_inc.php' ) ) {
74 require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'custom_constants_inc.php' );
77 $t_config_inc_found = false;
79 # Include default configuration settings
80 require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'config_defaults_inc.php' );
82 # config_inc may not be present if this is a new install
83 if ( file_exists( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'config_inc.php' ) ) {
84 require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'config_inc.php' );
85 $t_config_inc_found = true;
88 # Allow an environment variable (defined in an Apache vhost for example)
89 # to specify a config file to load to override other local settings
90 $t_local_config = getenv( 'MANTIS_CONFIG' );
91 if ( $t_local_config && file_exists( $t_local_config ) ){
92 require_once( $t_local_config );
93 $t_config_inc_found = true;
96 # Remember (globally) which API files have already been loaded
97 $g_api_included = array();
99 # Define an API inclusion function to replace require_once
100 function require_api( $p_api_name ) {
101 global $g_api_included;
102 global $g_core_path;
103 if ( !isset( $g_api_included[$p_api_name] ) ) {
104 $t_existing_globals = get_defined_vars();
105 require_once( $g_core_path . $p_api_name );
106 $t_new_globals = array_diff_key( get_defined_vars(), $GLOBALS, array( 't_existing_globals' => 0, 't_new_globals' => 0 ) );
107 foreach ( $t_new_globals as $t_global_name => $t_global_value ) {
108 global $$t_global_name;
110 extract( $t_new_globals );
111 $g_api_included[$p_api_name] = 1;
115 # Remember (globally) which library files have already been loaded
116 $g_libraries_included = array();
118 # Define an API inclusion function to replace require_once
119 function require_lib( $p_library_name ) {
120 global $g_libraries_included;
121 global $g_library_path;
122 if ( !isset( $g_libraries_included[$p_library_name] ) ) {
123 $t_existing_globals = get_defined_vars();
124 require_once( $g_library_path . $p_library_name );
125 $t_new_globals = array_diff_key( get_defined_vars(), $GLOBALS, array( 't_existing_globals' => 0, 't_new_globals' => 0 ) );
126 foreach ( $t_new_globals as $t_global_name => $t_global_value ) {
127 global $$t_global_name;
129 extract( $t_new_globals );
130 $g_libraries_included[$p_library_name] = 1;
134 # Define an autoload function to automatically load classes when referenced
135 function __autoload( $className ) {
136 global $g_class_path;
137 global $g_library_path;
139 $t_require_path = $g_class_path . $className . '.class.php';
141 if ( file_exists( $t_require_path ) ) {
142 require_once( $t_require_path );
143 return;
146 $t_require_path = $g_library_path . 'rssbuilder' . DIRECTORY_SEPARATOR . 'class.' . $className . '.inc.php';
148 if ( file_exists( $t_require_path ) ) {
149 require_once( $t_require_path );
150 return;
154 # Register the autoload function to make it effective immediately
155 spl_autoload_register( '__autoload' );
157 # Load UTF8-capable string functions
158 require_lib( 'utf8/utf8.php' );
159 require_lib( 'utf8/str_pad.php' );
161 # Include PHP compatibility file
162 require_api( 'php_api.php' );
164 # Enforce our minimum PHP requirements
165 if( !php_version_at_least( PHP_MIN_VERSION ) ) {
166 @ob_end_clean();
167 echo '<b>FATAL ERROR: Your version of PHP is too old. MantisBT requires PHP version ' . PHP_MIN_VERSION . ' or newer</b><br />Your version of PHP is version ' . phpversion();
168 die();
171 # Ensure that output is blank so far (output at this stage generally denotes
172 # that an error has occurred)
173 if ( ( $t_output = ob_get_contents() ) != '' ) {
174 echo 'Possible Whitespace/Error in Configuration File - Aborting. Output so far follows:<br />';
175 echo var_dump( $t_output );
176 die;
179 # Start HTML compression handler (if enabled)
180 require_api( 'compress_api.php' );
181 compress_start_handler();
183 # If no configuration file exists, redirect the user to the admin page so
184 # they can complete installation and configuration of MantisBT
185 if ( false === $t_config_inc_found ) {
186 if ( !( isset( $_SERVER['SCRIPT_NAME'] ) && ( 0 < strpos( $_SERVER['SCRIPT_NAME'], 'admin' ) ) ) ) {
187 if ( OFF == $g_use_iis ) {
188 header( 'Status: 302' );
190 header( 'Content-Type: text/html' );
192 if ( ON == $g_use_iis ) {
193 header( "Refresh: 0;url=admin/install.php" );
194 } else {
195 header( "Location: admin/install.php" );
198 exit;
202 # Connect to the database
203 require_api( 'database_api.php' );
204 require_api( 'config_api.php' );
206 if( !isset( $g_skip_open_db ) ) {
207 if( OFF == $g_use_persistent_connections ) {
208 db_connect( config_get_global( 'dsn', false ), $g_hostname, $g_db_username, $g_db_password, $g_database_name, config_get_global( 'db_schema' ) );
209 } else {
210 db_connect( config_get_global( 'dsn', false ), $g_hostname, $g_db_username, $g_db_password, $g_database_name, config_get_global( 'db_schema' ), true );
212 } else {
213 if (!defined('PLUGINS_DISABLED') )
214 define( 'PLUGINS_DISABLED', true );
217 # Initialise plugins
218 require_api( 'plugin_api.php' );
219 if ( !defined( 'PLUGINS_DISABLED' ) ) {
220 plugin_init_installed();
223 # Initialise Wiki integration
224 if( config_get_global( 'wiki_enable' ) == ON ) {
225 require_api( 'wiki_api.php' );
226 wiki_init();
229 if ( !is_blank ( config_get_global( 'default_timezone' ) ) ) {
230 // if a default timezone is set in config, set it here, else we use php.ini's value
231 // having a timezone set avoids a php warning
232 date_default_timezone_set( config_get_global( 'default_timezone' ) );
233 } else {
234 config_set_global( 'default_timezone', date_default_timezone_get(), true );
237 if ( !isset( $g_login_anonymous ) ) {
238 $g_login_anonymous = true;
241 require_api( 'authentication_api.php' );
242 require_api( 'user_pref_api.php' );
243 if( auth_is_user_authenticated() ) {
244 date_default_timezone_set( user_pref_get_pref( auth_get_current_user_id(), 'timezone' ) );
247 require_api( 'collapse_api.php' );
248 if ( !defined( 'MANTIS_INSTALLER' ) ) {
249 collapse_cache_token();
252 # Load custom functions
253 require_api( 'custom_function_api.php' );
254 if ( file_exists( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'custom_functions_inc.php' ) ) {
255 require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'custom_functions_inc.php' );
258 # Set HTTP response headers
259 require_api( 'http_api.php' );
260 http_all_headers();
262 # Push default language to speed calls to lang_get
263 require_api( 'lang_api.php' );
264 if ( !isset( $g_skip_lang_load ) ) {
265 lang_push( lang_get_default() );
268 # Signal plugins that the core system is loaded
269 require_api( 'event_api.php' );
270 event_signal( 'EVENT_CORE_READY' );