-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.php
executable file
·98 lines (81 loc) · 2.39 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
<?php
//Import
if($_GET['q'] == 'import'){
include_once('classes/Importer.php');
$imp = new Importer();
$imp->run();
exit(0);
}
//Test if LODSPeaKr is configured
if(!file_exists('settings.inc.php')){
echo 'Need to configure lodspeakr first. Please run "install.sh". Alternatively, you can <a href="import">import an existing application</a>';
exit(0);
}
include_once('common.inc.php');
//Debug output
if($conf['debug']){
error_reporting(E_ALL);
}else{
error_reporting(E_ERROR);
}
include_once('classes/HTTPStatus.php');
include_once('classes/Utils.php');
include_once('classes/Queries.php');
include_once('classes/Endpoint.php');
include_once('classes/Convert.php');
$results = array();
$firstResults = array();
$endpoints = array();
$endpoints['local'] = new Endpoint($conf['endpoint']['local'], $conf['endpointParams']['config']);
$acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']);
$extension = Utils::getExtension($acceptContentType);
//Check content type is supported by LODSPeaKr
if($acceptContentType == NULL){
HTTPStatus::send406($uri);
}
//Export
if($conf['export'] && $_GET['q'] == 'export'){
include_once('settings.inc.php');
include_once('classes/Exporter.php');
$exp = new Exporter();
header('Content-Type: text/plain');
$exp->run();
exit(0);
}
//Redirect to root URL if necessary
$uri = $conf['basedir'].$_GET['q'];
$localUri = $uri;
if($uri == $conf['basedir']){
header('Location: '.$conf['root']);
exit(0);
}
//Configure external URIs if necessary
if(isset($conf['mirror_external_uris']) && $conf['mirror_external_uris'] != false){
$localUri = $conf['basedir'].$_GET['q'];
if(is_bool($conf['mirror_external_uris'])){
$uri = $conf['ns']['local'].$_GET['q'];
}elseif(is_string($conf['mirror_external_uris'])){
$uri = $conf['mirror_external_uris'].$_GET['q'];
}else{
HTTPStatus::send500("Error in mirroring configuration");
exit(1);
}
}
//Modules
foreach($conf['modules']['available'] as $i){
$className = $i.'Module';
$currentModule = $conf['modules']['directory'].$className.'.php';
if(!is_file($currentModule)){
HTTPStatus::send500("<br/>Can't load or error in module <tt>".$currentModule."</tt>" );
exit(1);
}
require_once($currentModule);
$module = new $className();
$matching = $module->match($uri);
if($matching != FALSE){
$module->execute($matching);
exit(0);
}
}
HTTPStatus::send404($uri);
?>