Skip to content
Snippets Groups Projects
index.php 2.34 KiB
Newer Older
Alvaro Graves's avatar
Alvaro Graves committed
<?
alangrafu's avatar
alangrafu committed
//Import
if($_GET['q'] == 'import'){
  include_once('classes/Importer.php');
  $imp = new Importer();
  $imp->run();
  exit(0);
}

alangrafu's avatar
alangrafu committed
//Test if LODSPeaKr is configured
if(!file_exists('settings.inc.php')){
  echo 'Need to configure lodspeakr firstResults. Please run "install.sh" firstResults. Alternatively, you can <a href="import">import an existing application</a>';
alangrafu's avatar
alangrafu committed
  exit(0);
}

include_once('common.inc.php');
alangrafu's avatar
alangrafu committed

//Debug output
if($conf['debug']){
  error_reporting(E_ALL);
}else{
  error_reporting(E_ERROR);
}
alangrafu's avatar
alangrafu committed

include_once('classes/Utils.php');
include_once('classes/Queries.php');
include_once('classes/Endpoint.php');
alangrafu's avatar
alangrafu committed
include_once('classes/Convert.php');
$results = array();
$firstResults = array();
$endpoints['local'] = new Endpoint($conf['endpoint']['local'], $conf['endpointParams']['config']);
Alvaro Graves's avatar
Alvaro Graves committed

$acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']);
$extension = Utils::getExtension($acceptContentType); 
Alvaro Graves's avatar
Alvaro Graves committed

alangrafu's avatar
alangrafu committed

//Check content type is supported by LODSPeaKr
if($acceptContentType == NULL){
  Utils::send406($uri);
Alvaro Graves's avatar
Alvaro Graves committed
}
alangrafu's avatar
alangrafu committed

//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);
}

alangrafu's avatar
alangrafu committed
//Redirect to root URL if necessary
Alvaro Graves's avatar
Alvaro Graves committed
$uri = $conf['basedir'].$_GET['q'];
Alvaro Graves's avatar
Alvaro Graves committed
if($uri == $conf['basedir']){
  header('Location: '.$conf['root']);
Alvaro Graves's avatar
Alvaro Graves committed
  exit(0);
alangrafu's avatar
alangrafu committed
//Configure external URIs if necessary
if(isset($conf['mirror_external_uris']) && $conf['mirror_external_uris'] != false){
alangrafu's avatar
alangrafu committed
  $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{
  	Utils::send500("Error in mirroring configuration");
  	exit(1);
  }
  
alangrafu's avatar
alangrafu committed
}

alangrafu's avatar
alangrafu committed

//Modules
alangrafu's avatar
alangrafu committed
foreach($conf['modules']['available'] as $i){
  $className = $i.'Module';
  $currentModule = $conf['modules']['directory'].$className.'.php';
  if(!is_file($currentModule)){
  	Utils::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);
  }
}
alangrafu's avatar
alangrafu committed
Utils::send404($uri);
Alvaro Graves's avatar
Alvaro Graves committed
?>