-
Notifications
You must be signed in to change notification settings - Fork 25
/
init.php
72 lines (60 loc) · 2.62 KB
/
init.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
<?php
if (file_exists(dirname(__FILE__).'/version.txt')) {
define('JETHRO_VERSION', trim(file_get_contents(dirname(__FILE__).'/version.txt')));
} else {
define('JETHRO_VERSION', 'DEV');
}
$path_sep = defined('PATH_SEPARATOR') ? PATH_SEPARATOR : ((FALSE === strpos($_ENV['OS'], 'Win')) ? ';' : ':');
set_include_path(ini_get('include_path').$path_sep.JETHRO_ROOT.$path_sep.JETHRO_ROOT.'/include/'.$path_sep.JETHRO_ROOT.'/db_objects/');
spl_autoload_register(function ($class_name) {
// If this autoloader fails, we want it to quietly continue on to other autoloaders
// (eg the Composer one). But the @(shutup) operator does not supress include-once
// errors in PHP8+. And file_exists does not take include_path into account.
// So this ugly approach to supressing 'file not found' errors is necessary.
$old_er = error_reporting();
error_reporting(0);
@include_once strtolower($class_name) . '.class.php';
error_reporting($old_er);
});
// set error level such that we cope with PHP versions before and after 5.3 when E_DEPRECATED was introduced.
$error_level = defined('E_DEPRECATED') ? (E_ALL & ~constant('E_DEPRECATED') /*& ~constant('E_STRICT')*/) : E_ALL;
error_reporting($error_level);
@ini_set('display_errors', 1);
require_once JETHRO_ROOT.'/include/general.php';
strip_all_slashes();
if (php_sapi_name() != 'cli') {
// Make sure we're at the correct URL
$do_redirect = FALSE;
if (REQUIRE_HTTPS && !defined('IS_PUBLIC') && empty($_SERVER['HTTPS'])) {
$do_redirect = TRUE;
}
if (strpos(array_get($_SERVER, 'HTTP_HOST', array_get($_SERVER, 'SERVER_NAME', '')).$_SERVER['REQUEST_URI'], str_replace(Array('http://', 'https://'), '', BASE_URL)) !== 0) {
$do_redirect = TRUE;
}
if ($do_redirect) {
header('Location: '.build_url(Array()));
exit();
}
}
// Set up the DB
require_once JETHRO_ROOT .'/include/jethrodb.php';
JethroDB::init(ifdef('DB_MODE', 'PRIVATE'));
// Apply Mysql mode if applicable
if ($sqlMode = ifdef('SQL_MODE')) {
$GLOBALS['db']->query('SET SESSION sql_mode="'.$sqlMode.'"');
}
@ini_set('default_charset', 'UTF-8');
Config_Manager::init();
// If max length is set, set the cookie timeout - this will allow sessions to outlast browser invocations
$expiryTime = defined('SESSION_MAXLENGTH_MINS') ? SESSION_MAXLENGTH_MINS * 60 : NULL;
session_set_cookie_params($expiryTime, parse_url(BASE_URL, PHP_URL_PATH));
if (session_id() == '') {
session_name('JethroSess');
session_start();
upgrade_session_cookie();
}
if (defined('TIMEZONE') && constant('TIMEZONE')) {
date_default_timezone_set(constant('TIMEZONE'));
$res = $GLOBALS['db']->query('SET time_zone = "'.date('P').'"');
}
@ini_set('default_charset', 'UTF-8');