<?php
/* Joe Presbrey <presbrey@mit.edu>
 * 2007/07/25
 */
require_once('_util.php');

if (stristr(get_request_subpath(), '..')) die('Invalid path.');
//$request_fullpath = DATA_PATH.DIRECTORY_SEPARATOR.get_request_subpath().'.n3'; //webtms
$request_fullpath = DATA_PATH.DIRECTORY_SEPARATOR.get_request_subpath();

if (($request_realpath = realpath($request_fullpath))!==FALSE) {
    $request_realdir = dirname($request_realpath);
    if (DATA_PATH == substr($request_realdir, 0, strlen(DATA_PATH))) {
        $data_file = $request_realdir.DIRECTORY_SEPARATOR.basename($request_fullpath);
	$meta_file = $request_realdir."/meta/".DIRECTORY_SEPARATOR.basename($request_fullpath);
        $ext = array_pop(explode('.',basename($data_file)));
        if (file_exists($data_file)) {
	  //header('Content-Type: text/rdf+n3'); //webtms
	  header('Content-Type: application/'.($ext=='n3'?'n3':'rdf+xml'));
            header('MS-Author-Via: SPARQL');
            readfile($data_file);
	    //if (file_exists($meta_file)) //webtms
	    //  readfile($meta_file);
            exit;
        }// else die('File not found.');
    } //else die('Invalid path.');
} //else die('Unwritable path.');
 
header('HTTP/1.1 200 OK');
header('Content-Type: application/rdf+xml');
exit('<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>');
//exit('<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1></body></html>');
