forked from AKSW/OntoWiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
188 lines (165 loc) · 5.7 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
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
<?php
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
*
* @copyright Copyright (c) 2012, {@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
ini_set('max_execution_time', 240);
if ((int)substr(ini_get('memory_limit'), 0, -1) < 256) {
ini_set('memory_limit', '256M');
}
/*
* include path preparation
*/
// init with local path in order to prefer these over system paths
$includePath = ONTOWIKI_ROOT . 'libraries/' . PATH_SEPARATOR;
// append local Erfurt include path
if (file_exists(ONTOWIKI_ROOT . 'libraries/Erfurt/Erfurt/App.php')) {
$includePath .= ONTOWIKI_ROOT . 'libraries/Erfurt/' . PATH_SEPARATOR;
} else if (file_exists(ONTOWIKI_ROOT . 'libraries/Erfurt/library/Erfurt/App.php')) {
$includePath .= ONTOWIKI_ROOT . 'libraries/Erfurt/library' . PATH_SEPARATOR;
}
// append system include paths
$includePath .= get_include_path() . PATH_SEPARATOR;
// set the include path
set_include_path($includePath);
// 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);
/** check/include Zend_Application */
try {
// use include, so we can catch it with the error handler
require_once 'Zend/Application.php';
} catch (Exception $e) {
header('HTTP/1.1 500 Internal Server Error');
echo 'Fatal Error: Could not load Zend library.<br />' . PHP_EOL
. 'Maybe you need to install it with apt-get or with "make zend"?';
return;
}
// create application
$application = new Zend_Application(
'default',
ONTOWIKI_ROOT . 'application/config/application.ini'
);
/** check/include OntoWiki */
try {
// use include, so we can catch it with the error handler
require_once 'OntoWiki.php';
} catch (Exception $e) {
header('HTTP/1.1 500 Internal Server Error');
echo 'Fatal Error: Could not load the OntoWiki Application Framework classes.<br />' . PHP_EOL
. 'Your installation directory seems to be screwed.';
return;
}
/* check/include Erfurt_App */
try {
// use include, so we can catch it with the error handler
require_once 'Erfurt/App.php';
} catch (Exception $e) {
header('HTTP/1.1 500 Internal Server Error');
echo 'Fatal Error: Could not load the Erfurt Framework classes.<br />' . PHP_EOL
. 'Maybe you should install it with apt-get or with "make deploy"?';
return;
}
// 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();
$_SESSION['ONTOWIKI']['adaptiveCache'] = false;
$application->run();