From 5bec9a542360ead31212ad4d7c52f7c718a2ee7a Mon Sep 17 00:00:00 2001 From: alangrafu <alvaro@graves.cl> Date: Fri, 4 Nov 2011 02:10:44 -0700 Subject: [PATCH] First functional copy-able apps TODO: include app-level params, such as root, as well as provenance data (where was this application originated, at which time it was collected, etc.) --- .gitignore | 2 + benegesserit.php | 248 +++++++++++++++++++ classes/BasicSpecialFunction.php | 28 ++- classes/Exporter.php | 404 +++++++++++++++++++++++++++++++ classes/Utils.php | 10 +- common.inc.php | 12 +- index.php | 11 +- settings.default.inc.php | 9 - 8 files changed, 694 insertions(+), 30 deletions(-) create mode 100644 benegesserit.php create mode 100644 classes/Exporter.php diff --git a/.gitignore b/.gitignore index ab433ef7..e286011f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ models/local:AsDAsd.model.html/dbpedia/alla2 meta/db.sqlite meta/db.sqlite + +meta/db.sqlite diff --git a/benegesserit.php b/benegesserit.php new file mode 100644 index 00000000..91497f00 --- /dev/null +++ b/benegesserit.php @@ -0,0 +1,248 @@ +<? +define("LS", "http://lodspeakr.org/lda/"); +define("SKOS", "http://www.w3.org/2004/02/skos/core#"); +define("RDF", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); +define("DC", "http://purl.org/dc/terms/"); +define("CNT", "http://www.w3.org/2011/content#"); +define("RDFS", "http://www.w3.org/2000/01/rdf-schema#"); +define("FILE", "settings.inc.php"); + +class Importer{ + + private $basedir; + private $external_basedir; + public function run(){ + if(is_file(FILE)){ + echo "There is an existing ".FILE." file on this installation. Please remove it before importing a new one"; + exit(0); + } + if(!isset($_GET['import'])){ + echo 'Please include a "?import=http://example.org/lodspeakr/benegesserit" at the end of the URL'; + exit(0); + } + if(!is_writable('.')){ + echo 'The webserver needs write permissions in "lodspeakr/" "lodspeakr/models/" and "lodspeakr/views/" dirs to import settings.'; + exit(0); + } + + $this->external_basedir = str_replace('benegesserit', '', $_GET['import']); + echo $this->external_basedir; + include_once('lib/arc2/ARC2.php'); + $parser = ARC2::getTurtleParser(); + $parser->parse($_GET['import']); + $triples = $parser->getTriples(); + + $appArr = $this->search($triples, null, RDF.'type', LS.'Application'); + if(!(sizeof($appArr) > 0)){ + echo "I can't find an application from the URL given"; + exit(0); + } + + $app = $appArr[0]['s']; + + $compArr = $this->search($triples, null, SKOS.'broader', $app); + $content = "<?\n\$conf['debug'] = false;\n\$conf['use_external_uris'] = true;\n\n"; + + $this->basedir = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; + $arr = explode("lodspeakr/benegesserit", $this->basedir); + $this->basedir = $arr[0]; + $content .= "\$conf['basedir'] = \"$this->basedir\";\n"; + + $pwd = getcwd(); + $content .= "\$conf['home'] = \"$pwd/\";\n"; + + foreach($compArr as $v){ + $component = $v['s']; + $componentTypeArr = $this->search($triples, $component, RDF.'type', null); + $compType = $componentTypeArr[0]['o']; + + $params = array(); + $q = $this->search($triples, $component, LS.'usedParameter', null); + foreach($q as $p){ + $param = $p['o']; + $labelArr = $this->search($triples, $param, RDFS.'label', null); + $label = $labelArr[0]['o']; + $format = $this->search($triples, $param, DC.'hasFormat', null); + $cntArr = $this->search($triples, $format[0]['o'], CNT.'chars', null); + $cnt = $cntArr[0]['o']; + $params[$label] = $cnt; + } + + $inputs = array(); + $q = $this->search($triples, $component, LS.'usedInput', null); + foreach($q as $p){ + $param = $p['o']; + $labelArr = $this->search($triples, $param, RDFS.'label', null); + if(sizeof($labelArr)>0){ + $label = $labelArr[0]['o']; + $format = $this->search($triples, $param, DC.'hasFormat', null); + $cntArr = $this->search($triples, $format[0]['o'], CNT.'chars', null); + $cnt = $cntArr[0]['o']; + $inputs[$label] = $cnt; + } + } + if($compType == LS."LodspeakrEndpointManagerComponent"){ + $content .= $this->createEndpoints($params); + }elseif($compType == LS."LodspeakrNamespaceManagerComponent"){ + $content .= $this->createNamespaces($params); + }elseif($compType == LS."LodspeakrSparqlEndpointRetriever"){ + $this->createModels($inputs); + }elseif($compType == LS."LodspeakrVisualComponent"){ + $this->createViews($inputs); + }else{ + trigger_error("Component '$component' (of type $compType) not supported", E_USER_WARNING); + } + } + $content .= "?>\n"; + try{ + $fh = fopen(FILE, 'a'); + fwrite($fh, $content); + fclose($fh); + } catch (Exception $e) { + echo 'Caught exception while writing settings: ', $e->getMessage(), "\n"; + exit(1); + } + } + + private function createEndpoints($ep){ + require('common.inc.php'); + $endpoints = ""; + try{ + foreach($ep as $k => $v){ + if($conf['endpoint'][$k] != $v){ + $endpoints .= "\$conf[\"endpoint\"][\"$k\"] = \"$v\";\n"; + } + } + $endpoints .= "\n\n"; + } catch (Exception $e) { + echo 'Caught exception while importing endpoints: ', $e->getMessage(), "\n"; + exit(1); + } + return $endpoints; + } + + private function createNamespaces($ns){ + require('namespaces.php'); + $namespaces = ""; + try{ + foreach($ns as $k => $v){ + if($conf["ns"][$k] != $v){ + if(preg_match("|^".$this->external_basedir."|", $v)){ + $newns = preg_replace("|^".$this->external_basedir."|", $this->basedir, $v); + $namespaces .= "\$conf[\"ns\"][\"".$k."_ext\"] = \"$newns\";\n"; + } + $namespaces .= "\$conf[\"ns\"][\"$k\"] = \"$v\";\n"; + } + } + $namespaces .= "\n\n"; + } catch (Exception $e) { + echo 'Caught exception while importing namespaces: ', $e->getMessage(), "\n"; + exit(1); + } + return $namespaces; + } + + private function createModels($models){ + try{ + foreach($models as $k => $v){ + $path = explode("/", $k); + for($i=0; $i<sizeof($path)-1; $i++){ + if(file_exists($path[$i])){ + if(!is_dir($path[$i])){ + unlink($path[$i]); + mkdir($path[$i]); + } + }else{ + mkdir($path[$i]); + } + chdir($path[$i]); + } + + $fh = fopen(end($path), 'w'); + fwrite($fh, $v); + fclose($fh); + for($i=0; $i<sizeof($path)-1; $i++){ + chdir('..'); + } + } + } catch (Exception $e) { + echo 'Caught exception while importing models: ', $e->getMessage(), "\n"; + exit(1); + } + } + + + private function createViews($views){ + try{ + foreach($views as $k => $v){ + $path = explode("/", $k); + for($i=0; $i<sizeof($path)-1; $i++){ + if(file_exists($path[$i])){ + if(!is_dir($path[$i])){ + unlink($path[$i]); + mkdir($path[$i]); + } + }else{ + mkdir($path[$i]); + } + chdir($path[$i]); + } + + $fh = fopen(end($path), 'w'); + fwrite($fh, $v); + fclose($fh); + for($i=0; $i<sizeof($path)-1; $i++){ + chdir('..'); + } + } + } catch (Exception $e) { + echo 'Caught exception while importing views: ', $e->getMessage(), "\n"; + exit(1); + } + } + + + private function search($graph, $s = null, $p = null, $o = null){ + $results = array(); + foreach($graph as $v){ + $threeOks = 0; + + //Check subject + if($s != null){ + if($v['s'] == $s){ + $threeOks++; + } + }else{ + $threeOks++; + } + + //Check predicate + if($p != null){ + if($v['p'] == $p){ + $threeOks++; + } + }else{ + $threeOks++; + } + + //Check object + if($o != null){ + if($v['o'] == $o){ + $threeOks++; + } + }else{ + $threeOks++; + } + + if($threeOks == 3){ + array_push($results, $v); + } + + } + return $results; + } +} + +$imp = new Importer(); +$imp->run(); +?> diff --git a/classes/BasicSpecialFunction.php b/classes/BasicSpecialFunction.php index fa39c6cc..e680410b 100644 --- a/classes/BasicSpecialFunction.php +++ b/classes/BasicSpecialFunction.php @@ -42,7 +42,6 @@ class SpecialFunction extends AbstractSpecialFunction{ $modelFile = $conf['special']['uri'].".".$f.$conf['model']['extension'].".".$extension; if(!is_file($conf['model']['directory'].$modelFile) || !is_file($conf['view']['directory'].$viewFile)){ throw new Exception('Method does not exist!'); - Utils::send404($uri); } $endpoints = $context['endpoints']; array_pop($params); @@ -62,8 +61,18 @@ class SpecialFunction extends AbstractSpecialFunction{ } $data['query'] =$queryHeader . $query;*/ //$e->query($data['query'], Utils::getResultsType($query)); + $prefixHeader = array(); for($i=0;$i<sizeof($params);$i++){ + if($conf['use_external_uris']){ + $altUri = Utils::curie2uri($params[$i]); + $altUri = preg_replace("|^".$conf['basedir']."|", $conf['ns']['local'], $altUri); +echo $altUri."\n"; + $params[$i] = Utils::uri2curie($altUri); + } + } + + for($i=0;$i<sizeof($params);$i++){ $auxPrefix = Utils::getPrefix($params[$i]); if($auxPrefix['ns'] != NULL){ $prefixHeader[] = $auxPrefix; @@ -71,14 +80,14 @@ class SpecialFunction extends AbstractSpecialFunction{ $args["arg".$i]=$params[$i]; } $data['params'] = $params; -$base = $conf['view']['standard']; -$base['type'] = $modelFile; -$base['this']['value'] = $uri; -$base['this']['curie'] = Utils::uri2curie($uri); -$base['this']['contentType'] = $acceptContentType; -$base['model']['directory'] = $conf['model']['directory']; -$base['view']['directory'] = $conf['view']['directory']; -$base['ns'] = $conf['ns']; $base['ns'] = $conf['ns']; + $base = $conf['view']['standard']; + $base['type'] = $modelFile; + $base['this']['value'] = $uri; + $base['this']['curie'] = Utils::uri2curie($uri); + $base['this']['contentType'] = $acceptContentType; + $base['model']['directory'] = $conf['model']['directory']; + $base['view']['directory'] = $conf['view']['directory']; + $base['ns'] = $conf['ns']; $base['ns'] = $conf['ns']; $base['type'] = $modelFile; $base['header'] = $prefixHeader; $base['args'] = $args; @@ -98,6 +107,7 @@ $base['ns'] = $conf['ns']; $base['ns'] = $conf['ns']; $rRoot = &$resulst; Utils::processDocument($viewFile, $base, $results); }catch (Exception $ex){ + echo $ex->getMessage()." ".$ex->getLine(); trigger_error($ex->getMessage(), E_ERROR); Utils::send500($uri); } diff --git a/classes/Exporter.php b/classes/Exporter.php new file mode 100644 index 00000000..790cbff7 --- /dev/null +++ b/classes/Exporter.php @@ -0,0 +1,404 @@ +<? + +class Exporter{ + private $serialization; + private $graph; + public function __construct(){ + $this->serialization = ""; + $this->graph = array(); + define("CNT", "http://www.w3.org/2011/content#"); + define("NSVIZON", "http://graves.cl/vizon/"); + define("LS", "http://lodspeakr.org/lda/"); + define("LDA", "http://tw.rpi.edu/lda/"); + define("DC", "http://purl.org/dc/terms/"); + define("RDF", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); + define("RDFS", "http://www.w3.org/2000/01/rdf-schema#"); + define("OPMV", "http://openprovenance.org/ontology#"); + define("SKOS", "http://www.w3.org/2004/02/skos/core#"); + } + + public function run(){ + global $conf; + $triples = array(); + $t = array(); + $t['s'] = $conf['basedir']; + $t['s_type'] = 'uri'; + $t['p'] = RDF.'type'; + $t['o'] = OPMV.'Agent'; + $t['o_type'] = 'uri'; + array_push($triples, $t); + $t['o'] = SKOS.'Concept'; + array_push($triples, $t); + $t['o'] = LS.'Application'; + array_push($triples, $t); + $t['s'] = $conf['basedir'].'endpointManagerComponent'; + $t['s_type'] = 'uri'; + $t['p'] = SKOS.'broader'; + $t['o'] = $conf['basedir']; + $t['o_type'] = 'uri'; + array_push($triples, $t); + $t['p'] = RDF.'type'; + $t['o'] = LS.'LodspeakrEndpointManagerComponent'; + $t['o_type'] = 'uri'; + array_push($triples, $t); + + $t2 = array(); + $t2['s'] = $t['o']; + $t2['s_type'] = 'uri'; + $t2['p'] = RDFS.'subClassOf'; + $t2['o'] = LDA."DataComponent"; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + + //Endpoints + foreach($conf['endpoint'] as $k => $v){ + $t['p'] = LS.'usedParameter'; + $t['o'] = uniqid("_:b"); + $t['o_type'] = 'bnode'; + array_push($triples, $t); + + $t2 = array(); + $t2['s'] = $t['o']; + $t2['s_type'] = 'uri'; + $t2['p'] = RDF.'type'; + $t2['o'] = LS."Parameter"; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + $t2['p'] = RDFS.'label'; + $t2['o'] = $k; + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + $t2['p'] = DC.'hasFormat'; + $t2['o'] = uniqid("_:b"); + $t2['o_type'] = 'bnode'; + array_push($triples, $t2); + + $t2['s'] = $t2['o']; + $t2['s_type'] = 'bnode'; + $t2['p'] = RDF.'type'; + $t2['o'] = CNT."ContentAsText"; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + $t2['p'] = CNT.'chars'; + $t2['o'] = ($v); + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + $t2['p'] = DC.'format'; + $t2['o'] = 'text/plain;charset=utf-8'; + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + + } + + $t['s'] = $conf['basedir'].'namespaceManagerComponent'; + $t['s_type'] = 'uri'; + $t['p'] = SKOS.'broader'; + $t['o'] = $conf['basedir']; + $t['o_type'] = 'uri'; + array_push($triples, $t); + $t['p'] = RDF.'type'; + $t['o'] = LS.'LodspeakrNamespaceManagerComponent'; + $t['o_type'] = 'uri'; + array_push($triples, $t); + $t2['s'] = $t['o']; + $t2['s_type'] = 'uri'; + $t2['p'] = RDFS.'subClassOf'; + $t2['o'] = LDA."ProcessComponent"; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + + //Namepsaces + foreach($conf['ns'] as $k => $v){ + $t['p'] = LS.'usedParameter'; + $t['o'] = uniqid("_:b"); + $t['o_type'] = 'bnode'; + array_push($triples, $t); + + $t2 = array(); + $t2['s'] = $t['o']; + $t2['s_type'] = 'uri'; + $t2['p'] = RDF.'type'; + $t2['o'] = LS."Parameter"; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + $t2['p'] = RDFS.'label'; + $t2['o'] = $k; + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + $t2['p'] = DC.'hasFormat'; + $t2['o'] = uniqid("_:b"); + $t2['o_type'] = 'bnode'; + array_push($triples, $t2); + + $t2['s'] = $t2['o']; + $t2['s_type'] = 'bnode'; + $t2['p'] = RDF.'type'; + $t2['o'] = CNT."ContentAsText"; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + $t2['p'] = CNT.'chars'; + $t2['o'] = ($v); + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + $t2['p'] = DC.'format'; + $t2['o'] = 'text/plain;charset=utf-8'; + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + + } + + + + require($conf['home'].'lib/arc2/ARC2.php'); + $ser = ARC2::getTurtleSerializer(); + + $sparqlComponent = $conf['basedir'].'sparqlComponent';//uniqid("_:b"); + //echo $ser->getSerializedTriples($triples); + //var_dump($this->getComponents($conf['home'].$conf['view']['directory'])); + $models = $this->getComponents($conf['home'].$conf['model']['directory'], ''); + + //Define Process + $t = array(); + $t['s'] = uniqid("_:b"); + $t['s_type'] = 'bnode'; + $t['p'] = RDF.'type'; + $t['o'] = OPMV.'Process'; + $t['o_type'] = 'uri'; + array_push($triples, $t); + foreach($models as $k=>$m){ + + + + //Controlled by + $t['p'] = OPMV.'wasControlledBy'; + $t['o'] = $sparqlComponent; + $t['o_type'] = 'bnode'; + array_push($triples, $t); + + //Associated Agent to this installation + $aux = $t['o']; + $t['s'] = $t['o']; + $t['p'] = SKOS.'broader'; + $t['o'] = $conf['basedir']; + $t['o_type'] = 'uri'; + array_push($triples, $t); + + //Return object for later triple + $t['o'] = $sparqlComponent; + + // Type of query + $t2 = array(); + $t2['s'] = $t['o']; + $t2['s_type'] = 'bnode'; + $t2['p'] = RDF.'type'; + $t2['o'] = LS.'LodspeakrSparqlEndpointRetriever'; + $t2['o_type'] = 'uri'; + + $t3 = array(); + $t3['s'] = $t2['o']; + $t3['s_type'] = 'uri'; + $t3['p'] = RDFS.'subClassOf'; + $t3['o'] = LDA."ProcessComponent"; + $t3['o_type'] = 'uri'; + array_push($triples, $t3); + + array_push($triples, $t2); + $t2['p'] = RDFS.'label'; + $t2['o'] = 'Sparql endpoint component for LODSPeaKr'; + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + + $t['p'] = LS.'usedInput'; + $t['o'] = $conf['basedir'].$conf['model']['directory'].$k; + $t['o_type'] = 'uri'; + array_push($triples, $t); + + $t2 = array(); + $t2['s'] = $t['o']; + $t2['s_type'] = 'uri'; + $t2['p'] = RDF.'type'; + $t2['o'] = LS."Input"; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + $t2['p'] = RDFS.'label'; + $t2['o'] = $conf['model']['directory'].$k; + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + + $t2['p'] = DC.'hasFormat'; + $t2['o'] = uniqid("_:b"); + $t2['o_type'] = 'bnode'; + array_push($triples, $t2); + + $t2['s'] = $t2['o']; + $t2['s_type'] = 'bnode'; + $t2['p'] = RDF.'type'; + $t2['o'] = CNT."ContentAsText"; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + $t2['p'] = CNT.'chars'; + $t2['o'] = ($m); + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + $t2['p'] = DC.'format'; + $t2['o'] = 'text/plain;charset=utf-8'; + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + //break; + } + + + //Views + + $viewsComponent = $conf['basedir'].'visualizationComponent';//uniqid("_:b"); + $views = $this->getComponents($conf['home'].$conf['view']['directory'], ''); + + //Define Process + $t = array(); + $t['s'] = uniqid("_:b"); + $t['s_type'] = 'bnode'; + $t['p'] = RDF.'type'; + $t['o'] = OPMV.'Process'; + $t['o_type'] = 'uri'; + array_push($triples, $t); + foreach($views as $k=>$m){ + + + + //Controlled by + $t['p'] = OPMV.'wasControlledBy'; + $t['o'] = $viewsComponent; + $t['o_type'] = 'bnode'; + array_push($triples, $t); + + //Associated Agent to this installation + $aux = $t['o']; + $t['s'] = $t['o']; + $t['p'] = SKOS.'broader'; + $t['o'] = $conf['basedir']; + $t['o_type'] = 'uri'; + array_push($triples, $t); + + //Return object for later triple + $t['o'] = $viewsComponent; + + // Type of query + $t2 = array(); + $t2['s'] = $t['o']; + $t2['s_type'] = 'bnode'; + $t2['p'] = RDF.'type'; + $t2['o'] = LS.'LodspeakrVisualComponent'; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + + $t3 = array(); + $t3['s'] = $t2['o']; + $t3['s_type'] = 'uri'; + $t3['p'] = RDFS.'subClassOf'; + $t3['o'] = LDA."VisualComponent"; + $t3['o_type'] = 'uri'; + array_push($triples, $t3); + + $t2['p'] = RDFS.'label'; + $t2['o'] = 'Haanga-based visualization component for LODSPeaKr'; + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + + $t['p'] = LS.'usedInput'; + $t['o'] = $conf['basedir'].$conf['view']['directory'].$k; + $t['o_type'] = 'uri'; + array_push($triples, $t); + + + $t2 = array(); + $t2['s'] = $t['o']; + $t2['s_type'] = 'uri'; + $t2['p'] = RDF.'type'; + $t2['o'] = LS."Input"; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + $t2['p'] = RDFS.'label'; + $t2['o'] = $conf['view']['directory'].$k; + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + $t2['p'] = DC.'hasFormat'; + $t2['o'] = uniqid("_:b"); + $t2['o_type'] = 'bnode'; + array_push($triples, $t2); + + $t2['s'] = $t2['o']; + $t2['s_type'] = 'bnode'; + $t2['p'] = RDF.'type'; + $t2['o'] = CNT."ContentAsText"; + $t2['o_type'] = 'uri'; + array_push($triples, $t2); + $t2['p'] = CNT.'chars'; + $t2['o'] = ($m); + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + $t2['p'] = DC.'format'; + $t2['o'] = 'text/plain;charset=utf-8'; + $t2['o_type'] = 'literal'; + array_push($triples, $t2); + //break; + } + + + echo $ser->getSerializedTriples($triples); + } + + private static function getTriple($s, $p, $o){ + } + + private function createParameter($name, $value){ + $s = uniqid("_:b"); + $s_type = 'bnode'; + $p = RDF."type"; + $o = NSVIZON."Parameter"; + $o_type = 'uri'; + + + } + + private function getViews($dir){ + global $conf; + $files = ""; + chdir($dir); + $handle = opendir('.'); + while (false !== ($viewFile = readdir($handle))) { + if($viewFile != "." && $viewFile != ".."){ + $files .= $viewFile.": ".htmlspecialchars(file_get_contents($viewFile))."\n"; + $t = array(); + } + } + chdir(".."); + return $files; + } + + private function getComponents($dir, $prefix){ + global $conf; + $files = array(); + $subDirs = array(); + chdir($dir); + $handle = opendir('.'); + while (false !== ($modelFile = readdir($handle))) { + if($modelFile != "." && $modelFile != ".."){ + if(is_dir($modelFile)){ + //Save it for later, after all the queries in the current directory has been resolved + $subDirs[]=$modelFile; + }else{ + $files[$prefix.$modelFile] = (file_get_contents($modelFile))."\n"; + } + } + } + + foreach($subDirs as $dir){ + //$files[$dir] = array(); + $files = array_merge($files, $this->getComponents($dir, $prefix.$dir."/")); + } + chdir(".."); + return $files; + } +} + +?> diff --git a/classes/Utils.php b/classes/Utils.php index 7d8c4e4d..9e9685ed 100644 --- a/classes/Utils.php +++ b/classes/Utils.php @@ -191,11 +191,11 @@ class Utils{ public static function getResultsType($query){ global $conf; if(preg_match("/select/i", $query)){ - return $conf['endpoint']['select']['output']; + return $conf['output']['select']; }elseif(preg_match("/describe/i", $query)){ - return $conf['endpoint']['describe']['output']; + return $conf['output']['describe']; }elseif(preg_match("/construct/i", $query)){ - return $conf['endpoint']['describe']['output']; + return $conf['output']['describe']; }else{ Utils::send500(null); } @@ -300,7 +300,7 @@ class Utils{ if(!isset($rPointer[$modelFile])){ $rPointer[$modelFile] = array(); } - if(Utils::getResultsType($query) == $conf['endpoint']['select']['output']){ + if(Utils::getResultsType($query) == $conf['output']['select']){ $rPointer[$modelFile] = Utils::sparqlResult2Obj($aux); /*if(sizeof($rPointer)>0){ $rPointer[$modelFile]['first'] = $rPointer[$modelFile][0]; @@ -309,7 +309,7 @@ class Utils{ $rPointer[$modelFile] = $aux; } }else{ - if(Utils::getResultsType($query) == $conf['endpoint']['select']['output']){ + if(Utils::getResultsType($query) == $conf['output']['select']){ $rPointer = Utils::sparqlResult2Obj($aux); /*if(sizeof($rPointer)>0){ $rPointer['first'] = $rPointer[0]; diff --git a/common.inc.php b/common.inc.php index 0def982e..98bbe268 100644 --- a/common.inc.php +++ b/common.inc.php @@ -1,10 +1,9 @@ <? -$conf['endpoint']['select']['output'] = 'json'; -$conf['endpoint']['describe']['output'] = 'rdf'; -$conf['endpoint']['config']['output'] = $conf['endpoint']['select']['output']; -$conf['endpoint']['config']['named_graph'] = ''; -$conf['endpoint']['config']['show_inline'] = 0; +$conf['output']['select'] = 'json'; +$conf['output']['describe'] = 'rdf'; +$conf['endpointParams']['config']['show_inline'] = 0; +$conf['endpointParams']['config']['named_graph'] = ''; //ALternative endpoints $conf['endpoint']['dbpedia'] = 'http://dbpedia.org/sparql'; $conf['endpoint']['logd'] = 'http://logd.tw.rpi.edu/sparql'; @@ -25,7 +24,8 @@ $conf['resource']['url_delimiter'] = "%u"; $conf['http_accept']['html'] = array('text/html'); $conf['http_accept']['rdf'] = array('application/rdf+xml'); -$conf['http_accept']['ttl'] = array('text/n3', 'application/x-turtle', 'application/turtle', 'text/turtle'); +$conf['http_accept']['ttl'] = array( + 'text/n3', 'application/x-turtle', 'application/turtle', 'text/turtle'); $conf['http_accept']['json'] = array('application/json', 'application/x-javascript', 'text/javascript', 'text/x-javascript', 'text/x-json'); $conf['http_accept']['nt'] = array('text/plain'); diff --git a/index.php b/index.php index 83c61a54..35563e5c 100755 --- a/index.php +++ b/index.php @@ -18,7 +18,7 @@ include_once('classes/Convert.php'); $results = array(); $endpoints = array(); -$endpoints['local'] = new Endpoint($conf['endpoint']['local'], $conf['endpoint']['config']); +$endpoints['local'] = new Endpoint($conf['endpoint']['local'], $conf['endpointParams']['config']); $metaDb = new MetaDb($conf['metadata']['db']['location']); $acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']); @@ -28,6 +28,15 @@ if($acceptContentType == NULL){ Utils::send406($uri); } +if($_GET['q'] == 'benegesserit'){ + include_once('settings.inc.php'); + include_once('classes/Exporter.php'); + $exp = new Exporter(); + $exp->run(); + exit(0); +} + + $uri = $conf['basedir'].$_GET['q']; $localUri = $uri; if($uri == $conf['basedir']){ diff --git a/settings.default.inc.php b/settings.default.inc.php index 778ddabc..4a79f894 100644 --- a/settings.default.inc.php +++ b/settings.default.inc.php @@ -1,18 +1,9 @@ <? $conf['endpoint']['host'] = 'http://myendpoint/sparql/'; -$conf['endpoint']['config']['output'] = 'json'; -$conf['endpoint']['config']['named_graph'] = ''; $conf['endpoint']['config']['show_inline'] = 0; $conf['basedir'] = 'http://mybaseurl/'; -$conf['metaendpoint']['host'] = 'http://mymetadataendpoint/sparql'; -$conf['metaendpoint']['config']['output'] = 'json'; -$conf['metaendpoint']['config']['show_inline'] = 0; -$conf['metaendpoint']['config']['key'] = 'keyForExecutePostInARC2'; -$conf['metaendpoint']['config']['named_graph'] = 'http://lodspeakr.org/metadata'; - - $conf['ns']['rdf'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; $conf['ns']['rdfs'] = 'http://www.w3.org/2000/01/rdf-schema#'; $conf['ns']['dcterms'] = 'http://purl.org/dc/terms/'; -- GitLab