__construct($a, $caller);
}
function __init() {
parent::__init();
$this->headers = array('http' => 'HTTP/1.1 200 OK');
}
/* */
function handleRequest() {
$rel_path = $this->getRequestPath();
if (!$rel_path) {
$this->handleRootRequest();
}
elseif (preg_match('/^post$/i', $_SERVER['REQUEST_METHOD'])) {
$this->handleUpdateRequest();
}
elseif (!file_exists($rel_path)) {
$this->handle404Request();
}
else {
$this->handlePassThroughRequest();
}
}
function setHeader($k, $v) {
$this->headers[$k] = $v;
}
function sendHeaders() {
foreach ($this->headers as $k => $v) {
header($v);
}
}
function getResult() {
return $this->result;
}
function go() {
$this->handleRequest();
$this->sendHeaders();
echo $this->getResult();
}
/* */
function getAbsBase() {
return preg_replace('/index\.php$/', '', ARC2::getScriptURI());
}
function getRelBase() {
return preg_replace('/index\.php$/', '', $_SERVER["SCRIPT_NAME"]);
}
function getRequestPath() {
$r = $_SERVER['REQUEST_URI'];
$r = preg_match('/^[^\/][a-z0-9]+\:[\/]+[^\/]+(.*)$/i', $r, $m) ? $m[1] : $r;
$r = substr($r, strlen($this->getRelBase()));
if (!$r || ($r == 'index.php')) return '';
$r = preg_replace('/\.[^\.]+$/', '', $r) . '.rdf';
return $r;
}
function getRequestURI(){
return $this->getAbsBase() . $this->getRequestPath();
}
function getTargetGraph() {
$r = preg_replace('/[\#\?].*$/', '', $this->getRequestURI());
$r = preg_replace('/\.rdf$/', '', $r);
return $r;
}
/* */
function handleRootRequest() {
$this->setHeader('content-type', 'Content-type: text/html; charset=utf-8');
$this->result = $this->getWelcomeDoc();
}
function handle404Request() {
$this->setHeader('content-type', 'Content-type: application/rdf+xml; charset=utf-8');
$this->setHeader('author-via', 'MS-Author-Via: SPARQL');
$this->result = '
This Web space allows the manipulation of RDF documents via SPARQL+ (or, more precisely, a slightly tweaked version of it which accepts INSERT and DELETE queries without an explicitly specified target graph).
'; } } /* */ function writeLog($v) { return 1; $fp = fopen('log.txt', 'a'); $now = time(); fwrite($fp, date('Y-m-d\TH:i:s\Z', $now) . ' : ' . $v . '' . "\r\n"); fclose($fp); } /* */ }