This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.php
144 lines (123 loc) · 4.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
<?php
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
*
* @copyright Copyright (c) 2015, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
/**
* OntoWiki bootstrap file.
*
* @category OntoWiki
* @author Norman Heino <[email protected]>
*/
/* Profiling */
define('REQUEST_START', microtime(true));
/*
* error handling for the very first includes etc.
* http://stackoverflow.com/questions/1241728/
*/
function errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext)
{
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler('errorHandler');
/*
* method to get evironment variables which are prefixed with "REDIRECT_"
* in some configurations Apache prefixes the environment variables on each rewrite walkthrough
* e.g. under centos
*/
function getEnvVar ($key)
{
$prefix = "REDIRECT_";
if (isset($_SERVER[$key])) {
return $_SERVER[$key];
}
foreach ($_SERVER as $k => $v) {
if (substr($k, 0, strlen($prefix)) == $prefix) {
if (substr($k, -(strlen($key))) == $key) {
return $v;
}
}
}
return null;
}
/**
* Bootstrap constants
* @since 0.9.5
*/
if (!defined('__DIR__')) {
define('__DIR__', dirname(__FILE__));
} // fix for PHP < 5.3.0
define('BOOTSTRAP_FILE', basename(__FILE__));
define('ONTOWIKI_ROOT', rtrim(__DIR__, '/\\') . DIRECTORY_SEPARATOR);
define('APPLICATION_PATH', ONTOWIKI_ROOT . 'application'.DIRECTORY_SEPARATOR);
define('CACHE_PATH', ONTOWIKI_ROOT . 'cache'.DIRECTORY_SEPARATOR);
/**
* Old constants for < 0.9.5 backward compatibility
* @deprecated 0.9.5
*/
define('_OWBOOT', BOOTSTRAP_FILE);
define('_OWROOT', ONTOWIKI_ROOT);
define('OW_SHOW_MAX', 5);
// PHP environment settings
if ((int)ini_get('max_execution_time') < 240) {
ini_set('max_execution_time', 240);
}
if ((int)substr(ini_get('memory_limit'), 0, -1) < 256) {
ini_set('memory_limit', '256M');
}
// append local Erfurt include path
require_once('vendor/autoload.php');
// use default timezone from php.ini or let PHP guess it
date_default_timezone_set(@date_default_timezone_get());
// determine wheter rewrite engine works
// and redirect to a URL that doesn't need rewriting
// TODO: check for AllowOverride All
$rewriteEngineOn = false;
if (getEnvVar('ONTOWIKI_APACHE_MOD_REWRITE_ENABLED')) {
// used in .htaccess or in debian package config
// in some configurations Apache prefixes the env var with 'REDIRECT_'
$rewriteEngineOn = true;
} else if (function_exists('__virt_internal_dsn')) {
// compatible with Virtuoso VAD
$rewriteEngineOn = true;
} else if (function_exists('apache_get_modules')) {
// usually, we are not here
if (in_array('mod_rewrite', apache_get_modules())) {
// get .htaccess contents
$htaccess = @file_get_contents(ONTOWIKI_ROOT . '.htaccess');
// check if RewriteEngine is enabled
$rewriteEngineOn = preg_match('/.*[^#][\t ]+RewriteEngine[\t ]+On/i', $htaccess);
// explicitly request /index.php for non-rewritten requests
if (!$rewriteEngineOn && ! strpos($_SERVER['REQUEST_URI'], BOOTSTRAP_FILE)) {
header('Location: ' . rtrim($_SERVER['REQUEST_URI'], '/\\') . '/' . BOOTSTRAP_FILE, true, 302);
return;
}
}
}
define('ONTOWIKI_REWRITE', $rewriteEngineOn);
// create application
$application = new Zend_Application(
'default',
ONTOWIKI_ROOT . 'application/config/application.ini'
);
// restore old error handler
restore_error_handler();
// bootstrap
try {
$application->bootstrap();
} catch (Exception $e) {
header('HTTP/1.1 500 Internal Server Error');
echo 'Error on bootstrapping application: ';
echo $e->getMessage();
return;
}
$event = new Erfurt_Event('onPostBootstrap');
$event->bootstrap = $application->getBootstrap();
$event->trigger();
$application->run();