PREFIX akts: "; $threestore = $_SERVER['SERVER_NAME']; $resource = basename($_SERVER['REQUEST_URI']); $uri = "http://$threestore/rdf/$resource"; // For safety, here you should check your threestore existence // Build the RDF - could use DESCRIBE or whatever else you want instead of the following $q = "$PREFIX CONSTRUCT { <$uri> ?p ?o . } WHERE { <$uri> ?p ?o . }"; $cmd = '/usr/local/bin/ts-query -d '.$threestore.' ' . escapeshellarg($q); $results = ""; exec($cmd, $results); $r1 = array_slice($results, 0, -1); $q = "$PREFIX CONSTRUCT { ?s ?p <$uri> . } WHERE { ?s ?p <$uri> . }"; $cmd = '/usr/local/bin/ts-query -d '.$threestore.' ' . escapeshellarg($q); $results = ""; exec($cmd, $results); $r2 = array_slice($results, 2); $results = array_merge($r1, $r2); if ((empty($results)) || ($results[2] == '')) { // threestore did not exist or query was empty, so issue real 404 // could do the multilanguage bit here header('HTTP/1.1 404 Not Found'); echo "\n\n404 Not Found\n"; echo "\n

Not Found

\n

The requested URL ".$_SERVER['REQUEST_URI']." was not found on this server.

\n"; echo "
\n".$_SERVER['SERVER_SIGNATURE']."\n\n"; exit; } else { header('HTTP/1.1 200 OK'); header('Content-type: text/xml'); if (CACHING) { # Could probably have more error checking for caching # Uses tmp file to avoid concurrent access to partially built file, by using rename (thanks Steve Harris!) if (!file_exists("$threestore")) system("mkdir ".escapeshellarg("$threestore")); $tmp = "tmp-".rand(); $handle = fopen("$threestore/$tmp", "w"); }; foreach ($results as $key => $value) { echo $value."\n"; if (CACHING) fwrite($handle, $value."\n"); }; if (CACHING) { rename("$threestore/$tmp", "$threestore/$resource"); fclose($handle); }; } ?>