diff --git a/.gitignore b/.gitignore index e286011f908b8f907b9de0af8ae6bfec1c7a9240..63f65d5f0b3c3d5f65471ce1e149d9381e95482a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,12 +4,4 @@ views/* models/* cache/* meta/* -models/local:AsDAsd.model.html/dbpedia/alla2 - -models/local:AsDAsd.model.html/dbpedia/alla2 - -meta/db.sqlite - -meta/db.sqlite - meta/db.sqlite diff --git a/classes/BasicSpecialFunction.php b/classes/BasicSpecialFunction.php index e87f2c97c553a833042ee73c370bf5f733a46e9d..3a4f2977bb5240796af156f3629d5c8720f48e50 100644 --- a/classes/BasicSpecialFunction.php +++ b/classes/BasicSpecialFunction.php @@ -6,7 +6,7 @@ class SpecialFunction extends AbstractSpecialFunction{ protected function getFunction($uri){ global $conf; $count = 1; - $prefixUri = $conf['basedir'].$conf['special']['uri']."/"; + $prefixUri = $conf['basedir']; $aux = str_replace($prefixUri, '', $uri, $count); $functionAndParams = explode('/', $aux); return $functionAndParams[0]; @@ -15,7 +15,7 @@ class SpecialFunction extends AbstractSpecialFunction{ protected function getParams($uri){ global $conf; $count = 1; - $prefixUri = $conf['basedir'].$conf['special']['uri']; + $prefixUri = $conf['basedir']; $functionAndParams = explode('/', str_replace($prefixUri, '', $uri, $count)); if(sizeof($functionAndParams) > 1){ array_shift($functionAndParams); @@ -27,21 +27,21 @@ class SpecialFunction extends AbstractSpecialFunction{ public function execute($uri, $context){ global $conf; - global $base; + global $lodspk; global $results; global $rRoot; $f = $this->getFunction($uri); $params = array(); $params = $this->getParams($uri); - $params[] = $context; + //$params[] = $context; $acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']); $extension = Utils::getExtension($acceptContentType); $args = array(); try{ - $viewFile = $conf['special']['uri'].".".$f.$conf['view']['extension'].".".$extension; - $modelFile = $conf['special']['uri'].".".$f.$conf['model']['extension'].".".$extension; + $viewFile = $conf['service']['prefix'].$f."/".$extension.".template"; + $modelFile = $conf['service']['prefix'].$f."/".$extension.".queries"; if(!(is_dir($conf['model']['directory'].$modelFile) || is_file($conf['model']['directory'].$modelFile))){ - $msg = '<h1>Method does not exist!</h1><br/>This means that <tt>'.$conf['model']['directory'].$modelFile."</tt> doesn't exist.<br/>Please refer to this tutorial to create one.<br/>"; + $msg = '<h1>Method does not exist!</h1><br/>This means that <tt>'.$modelFile."</tt> doesn't exist.<br/>Please refer to this tutorial to create one.<br/>"; throw new Exception($msg); } if(!is_file($conf['view']['directory'].$viewFile)){ @@ -49,10 +49,11 @@ class SpecialFunction extends AbstractSpecialFunction{ throw new Exception($msg); } $endpoints = $context['endpoints']; - array_pop($params); - array_shift($params); + //array_pop($params); + //array_shift($params); $prefixHeader = array(); + for($i=0;$i<sizeof($params);$i++){ if($conf['mirror_external_uris']){ $altUri = Utils::curie2uri($params[$i]); @@ -60,37 +61,38 @@ class SpecialFunction extends AbstractSpecialFunction{ $params[$i] = Utils::uri2curie($altUri); } } - - for($i=0;$i<sizeof($params);$i++){ + + for($i=0;$i<sizeof($params);$i++){ $auxPrefix = Utils::getPrefix($params[$i]); if($auxPrefix['ns'] != NULL){ $prefixHeader[] = $auxPrefix; } $args["arg".$i]=$params[$i]; } - $results['params'] = $params; - $base = $conf['view']['standard']; - $base['type'] = $modelFile; - $base['root'] = $conf['root']; - $base['home'] = $conf['basedir']; - $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['endpoint'] = $conf['endpoint']; - $base['type'] = $modelFile; - $base['header'] = $prefixHeader; - $base['args'] = $args; - $base['baseUrl'] = $conf['basedir']; - $base['this']['value'] = $uri; - $base['this']['contentType'] = $acceptContentType; - $base['view']['directory'] = $conf['home'].$conf['view']['directory']; - $base['model']['directory'] = $conf['home'].$conf['model']['directory']; + $results['params'] = $params; + $lodspk = $conf['view']['standard']; + $lodspk['type'] = $modelFile; + $lodspk['root'] = $conf['root']; + $lodspk['home'] = $conf['basedir']; + $lodspk['this']['value'] = $uri; + $lodspk['this']['curie'] = Utils::uri2curie($uri); + $lodspk['this']['contentType'] = $acceptContentType; + $lodspk['model']['directory'] = $conf['model']['directory']; + $lodspk['view']['directory'] = $conf['view']['directory']; + $lodspk['ns'] = $conf['ns']; + $lodspk['endpoint'] = $conf['endpoint']; + $lodspk['type'] = $modelFile; + $lodspk['header'] = $prefixHeader; + $lodspk['args'] = $args; + $lodspk['module'] = 'service'; + $lodspk['add_mirrored_uris'] = false; + $lodspk['baseUrl'] = $conf['basedir']; + $lodspk['this']['value'] = $uri; + $lodspk['this']['contentType'] = $acceptContentType; + $lodspk['view']['directory'] = $conf['home'].$conf['view']['directory'].$conf['service']['prefix'].$f.'/'; + $lodspk['model']['directory'] = $conf['home'].$conf['model']['directory']; chdir($conf['model']['directory']); $first = array(); - $results = array(); Utils::queryFile($modelFile, $endpoints['local'], $results, $first); chdir($conf['home']); $results = Utils::internalize($results); @@ -98,7 +100,11 @@ class SpecialFunction extends AbstractSpecialFunction{ if(is_array($results)){ $results = Convert::array_to_object($results); } - Utils::processDocument($viewFile, $base, $results); + + //Need to redefine viewFile as 'local' i.e., inside service.foo/ so I can load files with the relative path correctly + $viewFile = $extension.".template"; + Utils::processDocument($viewFile, $lodspk, $results); + }catch (Exception $ex){ echo $ex->getMessage(); trigger_error($ex->getMessage(), E_ERROR); diff --git a/classes/Endpoint.php b/classes/Endpoint.php index 42da91c4934ac26e60573d6264e68f4e562c3c1e..1bd8f34b6c0a14c8e4a38b237cb11faa18ef01a3 100644 --- a/classes/Endpoint.php +++ b/classes/Endpoint.php @@ -33,15 +33,35 @@ class Endpoint{ curl_setopt($c, CURLOPT_HTTPHEADER, $context); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $aux = curl_exec($c); // execute the curl command + if($conf['debug']){ + if($aux == false){ + trigger_error("Error executing SPARQL query: ".curl_error($c), E_USER_ERROR); + echo("Error executing SPARQL query: ".curl_error($c)); + } + } curl_close($c); $this->params['output'] = $auxoutput; if(preg_match("/select/i", $q)){ $r = json_decode($aux, true); + if($conf['debug']){ + if($r == false){ + trigger_error("Warning: Results from a SELECT sparql query couldn't get parsed", E_USER_WARNING); + echo("Warning: Results from a SELECT sparql query couldn't get parsed"); + } + } + } return $r; } if(preg_match("/describe/i", $q)){ return $aux; } + if(preg_match("/construct/i", $q)){ + return $aux; + } + if(preg_match("/ask/i", $q)){ + $r = json_decode($aux, true); + return $r; + } } public function queryPost($q){ @@ -57,6 +77,10 @@ class Endpoint{ return $result; } + public function getSparqlURL(){ + return $this->sparqlUrl; + } + } ?> diff --git a/classes/Queries.php b/classes/Queries.php index 3e2451ef27cd2afbd6355fd179ccf254ebbd007e..533f7383abfbbda0c89684c4db9e05be160c9c14 100644 --- a/classes/Queries.php +++ b/classes/Queries.php @@ -2,16 +2,25 @@ class Queries{ public static function uriExist($uri, $e){ - $q = "SELECT * WHERE{ - {<$uri> ?p1 ?o1} - UNION - {?s1 <$uri> ?o2} - UNION - {?s2 ?p2 <$uri>} - }LIMIT 1"; - - $r = $e->query($q); - if(sizeof($r['results']['bindings'])>0){ + $q = "ASK WHERE{ + { + GRAPH ?g{ + {<$uri> ?p1 []} + UNION + {[] <$uri> []} + UNION + {[] ?p2 <$uri>} + } + }UNION{ + {<$uri> ?p1 []} + UNION + {[] <$uri> []} + UNION + {[] ?p2 <$uri>} + } + }"; + $r = $e->query($q); + if($r['boolean'] && strtolower($r['boolean']) !== false){ return true; } return false; @@ -19,11 +28,21 @@ class Queries{ public static function getClass($uri, $e){ $q = "SELECT DISTINCT ?class ?inst WHERE{ - { - <$uri> a ?class . + { + GRAPH ?g{ + { + <$uri> a ?class . + }UNION{ + ?inst a <$uri> . + } + } }UNION{ - ?inst a <$uri> . - } + { + <$uri> a ?class . + }UNION{ + ?inst a <$uri> . + } + } }"; try{ $r = $e->query($q); diff --git a/classes/Utils.php b/classes/Utils.php index 2c7581fd54bca5b4accc910fee429ab5075d4802..ac0c979d6642e3e136b09afd404329de23e27714 100644 --- a/classes/Utils.php +++ b/classes/Utils.php @@ -12,13 +12,13 @@ class Utils{ public static function send404($uri){ header("HTTP/1.0 404 Not Found"); - echo "LODSPeaKr could not find ".$uri." or information about it.\n\n"; + echo "LODSPeaKr could not find ".$uri." or information about it.\nNo URIs in the triple store, or services configured with that URI\n"; exit(0); } public static function send406($uri){ header("HTTP/1.0 406 Not Acceptable"); - echo "I can't find a representation suitable for the content type you accept\n\n"; + echo "LODSPeaKr can't find a representation suitable for the content type you accept\n\n"; exit(0); } @@ -156,13 +156,40 @@ class Utils{ return $ct; } + + private static function travelTree($tree){ + $results = array(); + if(is_string($tree)){ + return $tree; + } + foreach($tree as $t){ + $aux = Utils::travelTree($t); + if(is_array($aux)){ + $results = array_merge($results, $aux); + }else{ + array_push($results, $aux); + } + } + return $results; + } + + private static function serializeRdf($data, $extension){ - global $conf; - require('lib/arc2/ARC2.php'); + global $conf; + global $lodspk; + $ser; + $dPointer; + $docs = Utils::travelTree($data); + require_once('lib/arc2/ARC2.php'); $parser = ARC2::getRDFParser(); - $parser->parse($conf['basedir'], $data); - $triples = $parser->getTriples(); - if($conf['mirror_external_uris']){ + $triples = array(); + + foreach($docs as $d){ + $parser->parse($conf['basedir'], $d); + $t = $parser->getTriples(); + $triples = array_merge($triples, $t); + } + if($lodspk['add_mirrored_uris']){ global $uri; global $localUri; $t = array(); @@ -175,7 +202,6 @@ class Utils{ $t['p'] = "http://www.w3.org/2000/10/swap/pim/contact#preferredURI"; array_push($triples, $t); } - $ser; switch ($extension){ case 'ttl': $ser = ARC2::getTurtleSerializer(); @@ -194,16 +220,16 @@ class Utils{ return $doc; } - public static function processDocument($viewFile, $base, $data){ + public static function processDocument($viewFile, $lodspk, $data){ global $conf; - $contentType = $base['this']['contentType']; + $contentType = $lodspk['this']['contentType']; $extension = Utils::getExtension($contentType); - + header('Content-Type: '.$contentType); - if(!is_object($data)){ + if($extension != 'html'){ $data = Utils::serializeRdf($data, $extension); } - Utils::showView($base, $data, $viewFile); + Utils::showView($lodspk, $data, $viewFile); } public static function getResultsType($query){ @@ -222,12 +248,12 @@ class Utils{ public static function queryDir($modelDir, &$r, &$f){ global $conf; global $uri; - global $base; + global $lodspk; global $endpoints; global $results; - $base['model']['directory'] = $modelDir; + $lodspk['model']['directory'] = $modelDir; $originalDir = getcwd(); - + $subDirs= array(); trigger_error("Entering $modelDir from ".getcwd(), E_USER_NOTICE); chdir($modelDir); $handle = opendir('.'); @@ -235,7 +261,7 @@ class Utils{ while (false !== ($modelFile = readdir($handle))) { if($modelFile != "." && $modelFile != ".." && strpos($modelFile, ".") !== 0){ if(is_dir($modelFile)){ - //Save it for later, after all the queries in the current directory has been resolved + trigger_error("Save $modelFile for later, after all the queries in the current directory has been resolved", E_USER_NOTICE); $subDirs[]=$modelFile; }else{ $e = null; @@ -251,7 +277,7 @@ class Utils{ }else{ $e = $endpoints[$modelDir]; } - if($modelDir != $base['type']){ + if($modelDir != $lodspk['type']){ if(!isset($r[$modelDir]) ){ $r[$modelDir] = array(); $f[$modelDir] = array(); @@ -264,17 +290,19 @@ class Utils{ } } closedir($handle); - $originalDir = $base['model']['directory']; - foreach($subDirs as $v){ - if(!isset($r[$modelDir])){ - $r[$modelDir] = array(); - } - if($modelDir != $base['type']){ - Utils::queryDir($v, $r[$modelDir]); - }else{ - Utils::queryDir($v, $r); - } - } + $originalDir = $lodspk['model']['directory']; + if(isset($subDirs)){ + foreach($subDirs as $v){ + if(!isset($r[$modelDir])){ + $r[$modelDir] = array(); + } + if($modelDir != $lodspk['type']){ + Utils::queryDir($v, $r[$modelDir]); + }else{ + Utils::queryDir($v, $r); + } + } + } chdir($conf['home']); //return $data; } @@ -282,13 +310,12 @@ class Utils{ public static function queryFile($modelFile, $e, &$rPointer, &$fPointer){ global $conf; - global $base; + global $lodspk; global $results; global $first; - $uri = $base['this']['value']; + $uri = $lodspk['this']['value']; $data = array(); - - + $strippedModelFile = str_replace('.query', '',$modelFile); if(!is_dir($modelFile)){ require_once($conf['home'].'lib/Haanga/lib/Haanga.php'); Haanga::configure(array( @@ -297,43 +324,112 @@ class Utils{ )); //Haanga supports the dot (.) convention only for objects - if(is_array($base)){ - $baseObj = Convert::array_to_object($base); - $base = $baseObj; + if(is_array($lodspk)){ + $lodspkObj = Convert::array_to_object($lodspk); + $lodspk = $lodspkObj; } $r2 = Convert::array_copy($results); - $r = Convert::array_to_object($r2); + $models = Convert::array_to_object($r2); $f = Convert::array_to_object($first); - $vars = compact('uri', 'base', 'r', 'f'); + $vars = compact('uri', 'lodspk', 'models', 'f'); + $fnc = Haanga::compile(file_get_contents($modelFile)); $query = $fnc($vars, TRUE); - if(is_object($base)){ - $baseObj = Convert::object_to_array($base); - $base = $baseObj; + + if(is_object($lodspk)){ + $lodspkObj = Convert::object_to_array($lodspk); + $lodspk = $lodspkObj; } + + if($lodspk['transform_select_query']==true){ + include_once($conf['home'].'lib/arc2/ARC2.php'); + $parser = ARC2::getSPARQLParser(); + $parser->parse($query); + $sparqlConstruct = array(); + if (!$parser->getErrors()) { + $resultVars = array(); + $q_infos = $parser->getQueryInfos(); + foreach($q_infos['query']['result_vars'] as $v){ + if($v['type'] == 'var'){ + $resultVars[$v['value']] = 1; + } + }; + $x = Utils::extractObj($q_infos['query']['pattern']); + foreach($x as $v){ + if(($resultVars[$v['s']] && $v['s_type'] == 'var') + || ($resultVars[$v['p']] && $v['p_type'] == 'var') + || ($resultVars[$v['o']] && $v['o_type'] == 'var')){ + array_push($sparqlConstruct, $v); + } + } + $construct = ""; + foreach($sparqlConstruct as $v){ + if($v['s_type'] == 'uri'){ + $construct .= "<".$v['s']."> "; + }elseif($v['s_type'] == 'var'){ + $construct .= '?'.$v['s'].' '; + }else{ + $construct.= $v['s']." "; + } + + if($v['p_type'] == 'uri'){ + $construct .= "<".$v['p']."> "; + }elseif($v['p_type'] == 'var'){ + $construct .= '?'.$v['p'].' '; + }else{ + $construct.= $v['p']." "; + } + + if($v['o_type'] == 'uri'){ + $construct .= "<".$v['o']."> "; + }elseif($v['o_type'] == 'literal'){ + $construct .= '"'.$v['o'].'" '; + }elseif($v['o_type'] == 'var'){ + $construct .= '?'.$v['o'].' '; + }else{ + $construct.= $v['o']." "; + } + + $construct .= ".\n"; + } + if($construct == ""){ + if(sizeof($q_infos['query']['result_vars'])>0){ + //For now, assuming variables are in the GRAPH ?g + $query = "CONSTRUCT {?g ?x ?y} WHERE{GRAPH ?g{?g ?x ?y}}"; + }else{ + Utils::send500(); + } + }else{ + $query = preg_replace('/select\n?.*\n?where/i', 'CONSTRUCT {'.$construct.'} WHERE', $query); + } + }else { + Utils::send500("invalid query: " . $parser->getErrors()); + } + } if($conf['debug']){ + echo "$modelFile (against ".$e->getSparqlUrl().")\n-------------------------------------------------\n"; echo $query; } - trigger_error("Running query on endpoint", E_USER_NOTICE); - $aux = $e->query($query, Utils::getResultsType($query)); - if($modelFile != $base['type']){ - if(!isset($rPointer[$modelFile])){ - $rPointer[$modelFile] = array(); - $first[$modelFile] = array(); + trigger_error("Running query from ".$modelFile." on endpoint ".$e->getSparqlURL(), E_USER_NOTICE); + $aux = $e->query($query, Utils::getResultsType($query)); + if($modelFile != $lodspk['type']){ + if(!isset($rPointer[$strippedModelFile])){ + $rPointer[$strippedModelFile] = array(); + $first[$strippedModelFile] = array(); } if(Utils::getResultsType($query) == $conf['output']['select']){ - $rPointer[$modelFile] = Utils::sparqlResult2Obj($aux); - $fPointer[$modelFile] = $rPointer[$modelFile][0]; + $rPointer[$strippedModelFile] = Utils::sparqlResult2Obj($aux); + $fPointer[$strippedModelFile] = $rPointer[$strippedModelFile][0]; /*if(sizeof($rPointer)>0){ $rPointer[$modelFile]['first'] = $rPointer[$modelFile][0]; }*/ }else{ - $rPointer[$modelFile] = $aux; + $rPointer[$strippedModelFile] = $aux; } }else{ if(Utils::getResultsType($query) == $conf['output']['select']){ $rPointer = Utils::sparqlResult2Obj($aux); - $fPointer[$modelFile] = $rPointer[0]; + $fPointer[$strippedModelFile] = $rPointer[0]; /*if(sizeof($rPointer)>0){ $rPointer['first'] = $rPointer[0]; }*/ @@ -342,12 +438,12 @@ class Utils{ } } }else{ - trigger_error("$modelFile is a directory, will process it later", E_USER_NOTICE); - if($modelFile != $base['type']){ - if(!isset($rPointer[$modelFile])){ - $rPointer[$modelFile] = array(); + trigger_error("$modelFile is a directory, will process it later", E_USER_NOTICE); + if($modelFile != $lodspk['type']){ + if(!isset($rPointer[$strippedModelFile])){ + $rPointer[$strippedModelFile] = array(); } - Utils::queryDir($modelFile, $rPointer[$modelFile], $fPointer[$modelFile]); + Utils::queryDir($modelFile, $rPointer[$strippedModelFile], $fPointer[$strippedModelFile]); }else{ Utils::queryDir($modelFile, $rPointer, $fPointer); } @@ -366,6 +462,9 @@ class Utils{ }*/ }else{ if(isset($value['uri']) && $value['uri'] == 1){ + if($conf['mirror_external_uris']){ + $value['mirroredUri'] = $value['value']; + } $value['value'] = preg_replace("|^".$conf['ns']['local']."|", $conf['basedir'], $value['value']); $value['curie'] = Utils::uri2curie($value['value']); $array[$key] = $value; @@ -392,26 +491,33 @@ class Utils{ } - public static function showView($baseData, $data, $view){ + public static function showView($lodspkData, $data, $view){ global $conf; - $base = $conf['view']['standard']; - $base = $baseData; - if(isset($baseData['params'])){ - $base['this']['params'] = $baseData['params']; + global $uri; + global $extension; + //$lodspk = $conf['view']['standard']; + $lodspk = $lodspkData; + + if(isset($lodspkData['params'])){ + $lodspk['this']['params'] = $lodspkData['params']; } require_once('lib/Haanga/lib/Haanga.php'); Haanga::configure(array( - 'template_dir' => $base['view']['directory'], + 'template_dir' => $lodspk['view']['directory'], 'cache_dir' => $conf['home'].'cache/', )); - $r = $data; - $first = $base['first']; - unset($base['first']); - $vars = compact('base', 'r', 'first'); + $models = $data; + $first = $lodspk['first']; + unset($lodspk['first']); + $lodspk = $lodspk; + //unset($lodspk); + $vars = compact('uri','lodspk', 'models', 'first'); if($conf['debug']){ var_dump($vars); } - if(is_file($base['view']['directory'].$view)){ + if(is_string($data)){ + echo($data); + }elseif(is_file($lodspk['view']['directory'].$view)){ Haanga::Load($view, $vars); }else{ $fnc = Haanga::compile($view); @@ -420,38 +526,23 @@ class Utils{ } - public static function getModelandView($t, $extension){ - global $conf; - //Defining default views and models - $curieType=""; - $modelFile = $conf['model']['default'].$conf['model']['extension'].".".$extension; - $viewFile = $conf['view']['default'].$conf['view']['extension'].".".$extension; - - //Get the first class available - /* TODO: Allow user to priotize - * which class should be used - * Example: URI is foaf:Person and ex:Student - * If both, prefer ex:Student - */ - $typesAndValues = array(); - foreach($t as $v){ - $curie = Utils::uri2curie($v); - $typesAndValues[$curie] = 0; - if(isset($conf['types']['priorities'][$curie]) && $conf['types']['priorities'][$curie] >= 0){ - $typesAndValues[$curie] = $conf['types']['priorities'][$curie]; - } - } - arsort($typesAndValues); - foreach($typesAndValues as $v => $w){ - $auxViewFile = $conf['view']['directory'].$v.$conf['view']['extension'].".".$extension; - $auxModelFile = $conf['model']['directory'].$v.$conf['model']['extension'].".".$extension; - if(file_exists($auxModelFile) && file_exists($auxViewFile) && $v != null){ - $viewFile = $v.$conf['view']['extension'].".".$extension; - $modelFile = $v.$conf['model']['extension'].".".$extension; - break; + private static function extractObj($obj, $term = 'triple'){ + $triples = array(); + if(is_array($obj)){ + foreach($obj as $k => $v){ + if($v['type'] != 'triple'){ + $aux = Utils::extractObj($v); + if($aux['type'] != 'triple'){ + $triples = array_merge($triples,$aux); + }else{ + $triples = array_merge($triples, $aux); + } + }else{ + array_push($triples, $v); + } } } - return array($modelFile, $viewFile); + return $triples; } } diff --git a/classes/modules/abstractModule.php b/classes/modules/abstractModule.php new file mode 100644 index 0000000000000000000000000000000000000000..a9169d452dc2b32ea13f86498fc9f306dab7aed7 --- /dev/null +++ b/classes/modules/abstractModule.php @@ -0,0 +1,9 @@ +<? +abstract class AbstractModule{ + + abstract protected function match($uri); + abstract protected function execute($params); + +} + +?> diff --git a/classes/modules/serviceModule.php b/classes/modules/serviceModule.php new file mode 100644 index 0000000000000000000000000000000000000000..d358b49f27c0348a34d41aaa2bda128b442dc4ab --- /dev/null +++ b/classes/modules/serviceModule.php @@ -0,0 +1,147 @@ +<? +require_once('abstractModule.php'); +class ServiceModule extends abstractModule{ + //Service module + + public function match($uri){ + global $conf; + global $acceptContentType; + global $localUri; + global $lodspk; + $q = preg_replace('|^'.$conf['basedir'].'|', '', $localUri); + $qArr = explode('/', $q); + if(sizeof($qArr)==0){ + return FALSE; + } + $extension = Utils::getExtension($acceptContentType); + $lodspk['model']['directory'] = $conf['home'].$conf['model']['directory'].$conf['service']['prefix'].$qArr[0]."/"; + $lodspk['view']['directory'] = $conf['home'].$conf['view']['directory'].$conf['service']['prefix'].$qArr[0].'/'; + $viewFile = $extension.".template"; + $modelFile = $extension.".queries"; + if(file_exists($lodspk['model']['directory'].$modelFile) && file_exists($lodspk['view']['directory'].$viewFile) && $qArr[0] != null){ + trigger_error("Using model ".$modelFile." and view ".$viewFile, E_USER_NOTICE); + return array($modelFile, $viewFile); + }elseif($extension != 'html' && file_exists($conf['model']['directory'].$conf['service']['prefix'].$qArr[0].'/html.queries')){ + $modelFile = $conf['home'].$conf['model']['directory'].$conf['service']['prefix'].$qArr[0].'/html.queries'; + $viewFile = null; + trigger_error("Using ".$modelFile." as model. It will be used as a CONSTRUCT", E_USER_NOTICE); + return array($modelFile, $viewFile); + } + + return FALSE; + } + +public function execute($service){ + global $conf; + global $localUri; + global $uri; + global $acceptContentType; + global $endpoints; + global $lodspk; + global $first; + $context = array(); + $context['contentType'] = $acceptContentType; + $context['endpoints'] = $endpoints; + //$sp = new SpecialFunction(); + //$sp->execute($localUri, $context); + $f = $this->getFunction($localUri); + $params = array(); + $params = $this->getParams($localUri); + //$params[] = $context; + $acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']); + $extension = Utils::getExtension($acceptContentType); + $args = array(); + list($modelFile, $viewFile) = $service; + + try{ + $prefixHeader = array(); + + for($i=0;$i<sizeof($params);$i++){ + if($conf['mirror_external_uris']){ + $altUri = Utils::curie2uri($params[$i]); + $altUri = preg_replace("|^".$conf['basedir']."|", $conf['ns']['local'], $altUri); + $params[$i] = Utils::uri2curie($altUri); + } + } + + for($i=0;$i<sizeof($params);$i++){ + $auxPrefix = Utils::getPrefix($params[$i]); + if($auxPrefix['ns'] != NULL){ + $prefixHeader[] = $auxPrefix; + } + $args["arg".$i]=$params[$i]; + } + $results['params'] = $params; + //$lodspk = $conf['view']['standard']; + $lodspk['type'] = $modelFile; + $lodspk['root'] = $conf['root']; + $lodspk['home'] = $conf['basedir']; + $lodspk['this']['value'] = $uri; + $lodspk['this']['curie'] = Utils::uri2curie($uri); + $lodspk['this']['contentType'] = $acceptContentType; + //$lodspk['model']['directory'] = $conf['model']['directory']; + //$lodspk['view']['directory'] = $conf['view']['directory']; + $lodspk['ns'] = $conf['ns']; + $lodspk['endpoint'] = $conf['endpoint']; + $lodspk['type'] = $modelFile; + $lodspk['header'] = $prefixHeader; + $lodspk['args'] = $args; + $lodspk['module'] = 'service'; + $lodspk['add_mirrored_uris'] = false; + $lodspk['baseUrl'] = $conf['basedir']; + $lodspk['this']['value'] = $uri; + $lodspk['this']['contentType'] = $acceptContentType; + //$lodspk['view']['directory'] = $viewFile;//$conf['home'].$conf['view']['directory'];//.$conf['service']['prefix'].$f.'/'; + //$lodspk['model']['directory'] = $conf['home'].$conf['model']['directory']; + if($viewFile == null){ + $lodspk['transform_select_query'] = true; + } + chdir($lodspk['model']['directory']); + + Utils::queryFile($modelFile, $endpoints['local'], $results, $first); + $results = Utils::internalize($results); + + $lodspk['first'] = Utils::getFirsts($results); + chdir($conf['home']); + if(is_array($results)){ + $results = Convert::array_to_object($results); + } + + //Need to redefine viewFile as 'local' i.e., inside service.foo/ so I can load files with the relative path correctly + //$viewFile = $extension.".template"; + + Utils::processDocument($viewFile, $lodspk, $results); + + }catch (Exception $ex){ + echo $ex->getMessage(); + trigger_error($ex->getMessage(), E_ERROR); + Utils::send500($uri); + } + exit(0); +} + + +protected function getFunction($uri){ + global $conf; + $count = 1; + $prefixUri = $conf['basedir']; + $aux = str_replace($prefixUri, '', $uri, $count); + $functionAndParams = explode('/', $aux); + return $functionAndParams[0]; +} + +protected function getParams($uri){ + global $conf; + $count = 1; + $prefixUri = $conf['basedir']; + $functionAndParams = explode('/', str_replace($prefixUri, '', $uri, $count)); + if(sizeof($functionAndParams) > 1){ + array_shift($functionAndParams); + return $functionAndParams; + }else{ + return array(null); + } +} + +} +?> diff --git a/classes/modules/staticModule.php b/classes/modules/staticModule.php new file mode 100644 index 0000000000000000000000000000000000000000..6f59daa99f936161d35499aaedb63ad200b1abba --- /dev/null +++ b/classes/modules/staticModule.php @@ -0,0 +1,32 @@ +<? +require_once('abstractModule.php'); +class StaticModule extends abstractModule{ + //Static module + + public function match($uri){ + global $conf; + global $localUri; + global $uri; + global $acceptContentType; + global $endpoints; + global $lodspk; + $q = preg_replace('|^'.$conf['basedir'].'|', '', $localUri); + if(sizeof($q)>0 && file_exists($conf['home'].$conf['static']['directory'].$q)){ + return $q; + } + return FALSE; + } + + public function execute($file){ + global $conf; + global $localUri; + global $uri; + global $acceptContentType; + global $endpoints; + global $lodspk; + header("Content-type: "); + echo file_get_contents($conf['static']['directory'].$file); + } + +} +?> diff --git a/classes/modules/typeModule.php b/classes/modules/typeModule.php new file mode 100644 index 0000000000000000000000000000000000000000..7cc6a0e95987d34e122ad930b5b071bb35dd46e1 --- /dev/null +++ b/classes/modules/typeModule.php @@ -0,0 +1,142 @@ +<? +require_once('abstractModule.php'); +class TypeModule extends abstractModule{ + //Class module + + public function match($uri){ + global $conf; + global $localUri; + global $uri; + global $acceptContentType; + global $endpoints; + global $lodspk; + + require_once($conf['home'].'classes/MetaDb.php'); + $metaDb = new MetaDb($conf['metadata']['db']['location']); + + $pair = Queries::getMetadata($localUri, $acceptContentType, $metaDb); + + if($pair == NULL){ // Original URI is not in metadata + if(Queries::uriExist($uri, $endpoints['local'])){ + $page = Queries::createPage($uri, $localUri, $acceptContentType, $metaDb); + if($page == NULL){ + Utils::send500("Can't write sqlite database."); + } + Utils::send303($page, $acceptContentType); + exit(0); + }else{ + return false; //Utils::send404($uri); + } + } + return $pair; + } + + public function execute($pair){ + global $conf; + global $localUri; + global $uri; + global $acceptContentType; + global $endpoints; + global $lodspk; + global $results; + global $first; + list($res, $page, $format) = $pair; + //If resource is not the page, send a 303 to the document + if($res == $localUri){ + Utils::send303($page, $acceptContentType); + } + + $uri = $res; + if($conf['mirror_external_uris']){ + $localUri = preg_replace("|^".$conf['ns']['local']."|", $conf['basedir'], $res); + } + + $extension = Utils::getExtension($format); + + /*Redefine Content type based on the + * dcterms:format for this page + */ + $acceptContentType = $format; + + //Check if files for model and view exist + $t=Queries::getClass($uri, $endpoints['local']); + + list($modelFile, $viewFile) = $this->getModelandView($t, $extension); + $lodspk = $conf['view']['standard']; + if($viewFile == null){ + $lodspk['transform_select_query'] = true; + } + $lodspk['module'] = 'type'; + $lodspk['add_mirrored_uris'] = true; + $lodspk['type'] = $modelFile; + $lodspk['this']['value'] = $uri; + $lodspk['this']['curie'] = Utils::uri2curie($uri); + $lodspk['thislocal']['value'] = $localUri; + $lodspk['thislocal']['curie'] = Utils::uri2curie($localUri); + + $lodspk['this']['extension'] = $extension; + $lodspk['this']['contentType'] = $acceptContentType; + $lodspk['model']['directory'] = $conf['model']['directory']; + $lodspk['view']['directory'] = $conf['view']['directory']; + $lodspk['ns'] = $conf['ns']; + + + chdir($conf['home'].$conf['model']['directory']); + + Utils::queryFile($modelFile, $endpoints['local'], $results, $first); + $results = Utils::internalize($results); + + $lodspk['first'] = Utils::getFirsts($results); + chdir($conf['home']); + if(is_array($results)){ + $resultsObj = Convert::array_to_object($results); + }else{ + $resultsObj = $results; + } + Utils::processDocument($viewFile, $lodspk, $resultsObj); + + } + + private static function getModelandView($t, $extension){ + global $conf; + global $results; + global $rPointer; + global $lodspk; + //Defining default views and models + $curieType=""; + $modelFile = 'type.rdfs:Resource/html.queries'; + $viewFile = null;//'type.rdfs:Resource/html.template'; + + //Get the first type available + $typesAndValues = array(); + foreach($t as $v){ + $curie = Utils::uri2curie($v); + $typesAndValues[$curie] = 0; + if(isset($conf['types']['priorities'][$curie]) && $conf['types']['priorities'][$curie] >= 0){ + $typesAndValues[$curie] = $conf['types']['priorities'][$curie]; + } + } + arsort($typesAndValues); + foreach($typesAndValues as $v => $w){ + $auxViewFile = $conf['view']['directory'].$conf['type']['prefix'].$v.'/'.$extension.'.template'; + $auxModelFile = $conf['model']['directory'].$conf['type']['prefix'].$v.'/'.$extension.'.queries'; + if(file_exists($auxModelFile) && file_exists($auxViewFile) && $v != null){ + $viewFile = $conf['type']['prefix'].$v.'/'.$extension.'.template'; + $modelFile = $conf['type']['prefix'].$v.'/'.$extension.'.queries'; + break; + }elseif($extension != 'html' && + file_exists($conf['model']['directory'].$conf['type']['prefix'].$v.'/html.queries')){ + $modelFile = $conf['type']['prefix'].$v.'/html.queries'; + $viewFile = null; + trigger_error("LODSPeaKr can't find the proper query. Using HTML query instead.", E_USER_NOTICE); + break; + } + } + if($viewFile == null && $extension == 'html'){ + $viewFile = 'type.rdfs:Resource/html.template'; + } + return array($modelFile, $viewFile); + } + +} +?> diff --git a/classes/modules/uriModule.php b/classes/modules/uriModule.php new file mode 100644 index 0000000000000000000000000000000000000000..b89e199144123f0cc15a7181cedae210d1f4ffbb --- /dev/null +++ b/classes/modules/uriModule.php @@ -0,0 +1,121 @@ +<? +require_once('abstractModule.php'); +class UriModule extends abstractModule{ + //Uri module + + public function match($uri){ + global $conf; + global $localUri; + global $uri; + global $acceptContentType; + global $endpoints; + global $lodspk; + + require_once('classes/MetaDb.php'); + $metaDb = new MetaDb($conf['metadata']['db']['location']); + + $pair = Queries::getMetadata($localUri, $acceptContentType, $metaDb); + + if($pair == NULL){ // Original URI is not in metadata + if(Queries::uriExist($uri, $endpoints['local'])){ + $page = Queries::createPage($uri, $localUri, $acceptContentType, $metaDb); + if($page == NULL){ + Utils::send500("Can't write sqlite database."); + } + Utils::send303($page, $acceptContentType); + exit(0); + }else{ + return false; //Utils::send404($uri); + } + } + $extension = Utils::getExtension($pair[2]); + $curie = Utils::uri2curie($pair[0]); + list($modelFile, $viewFile) = $this->getModelandView($curie, $extension); + + if($modelFile == NULL){ + return FALSE; + } + return $pair; + } + + public function execute($pair){ + global $conf; + global $localUri; + global $uri; + global $acceptContentType; + global $endpoints; + global $lodspk; + global $results; + global $first; + list($res, $page, $format) = $pair; + $uri = $res; + $curie = Utils::uri2curie($res); + + //If resource is not the page, send a 303 to the document + if($res == $localUri){ + Utils::send303($page, $acceptContentType); + } + + $uri = $res; + if($conf['mirror_external_uris']){ + $localUri = preg_replace("|^".$conf['ns']['local']."|", $conf['basedir'], $res); + } + + $extension = Utils::getExtension($format); + + /*Redefine Content type based on the + * dcterms:format for this page + */ + $acceptContentType = $format; + + $curie = Utils::uri2curie($uri); + list($modelFile, $viewFile) = $this->getModelandView($curie, $extension); + if($modelFile == NULL){ + return; + } + + $lodspk = $conf['view']['standard']; + $lodspk['type'] = $modelFile; + $lodspk['module'] = 'uri'; + $lodspk['add_mirrored_uris'] = true; + $lodspk['this']['value'] = $uri; + $lodspk['this']['curie'] = Utils::uri2curie($uri); + $lodspk['thislocal']['value'] = $localUri; + $lodspk['thislocal']['curie'] = Utils::uri2curie($localUri); + + $lodspk['this']['contentType'] = $acceptContentType; + $lodspk['model']['directory'] = $conf['model']['directory']; + $lodspk['view']['directory'] = $conf['view']['directory']; + $lodspk['ns'] = $conf['ns']; + + + chdir($conf['home'].$conf['model']['directory']); + + Utils::queryFile($modelFile, $endpoints['local'], $results, $first); + $results = Utils::internalize($results); + + $lodspk['first'] = Utils::getFirsts($results); + chdir($conf['home']); + if(is_array($results)){ + $resultsObj = Convert::array_to_object($results); + }else{ + $resultsObj = $results; + } + Utils::processDocument($viewFile, $lodspk, $resultsObj); + + } + + private static function getModelandView($uri, $extension){ + global $conf; + $auxViewFile = $conf['view']['directory'].$conf['uri']['prefix'].$uri.'/'.$extension.'.template'; + $auxModelFile = $conf['model']['directory'].$conf['uri']['prefix'].$uri.'/'.$extension.'.queries'; + if(file_exists($auxModelFile) && file_exists($auxViewFile) ){ + $viewFile = $conf['uri']['prefix'].$uri.'/'.$extension.'.template'; + $modelFile = $conf['uri']['prefix'].$uri.'/'.$extension.'.queries'; + return array($modelFile, $viewFile); + } + return array(NULL, NULL); + } + +} +?> diff --git a/common.inc.php b/common.inc.php index 5f443ea60be8a22eb0b4b75cf1848d00db45594d..6fd297de03aa1ea0ee119b12263320b9e37d87d1 100644 --- a/common.inc.php +++ b/common.inc.php @@ -32,8 +32,11 @@ $conf['http_accept']['json'] = array('application/json', 'application/x-javascri $conf['http_accept']['nt'] = array('text/plain'); -$conf['special']['uri'] = 'special'; -$conf['special']['class'] = 'classes/BasicSpecialFunction.php'; +$conf['service']['prefix'] = 'service.'; +$conf['service']['class'] = 'classes/BasicSpecialFunction.php'; + +$conf['type']['prefix'] = 'type.'; +$conf['uri']['prefix'] = 'uri.'; //Frontpage when user goes to http://example.org/ $conf['root'] = 'index.html'; @@ -45,6 +48,11 @@ $conf['types']['priorities']['rdfs:Resource'] = -1; //Debug $conf['debug'] = false; +//Modules: LODSPeaKr will try to match the requested URI +//using the modules in the following order +$conf['modules'] = array(); +$conf['modules']['directory'] = 'classes/modules/'; +$conf['modules']['available'] = array('static','uri', 'type', 'service'); include_once('settings.inc.php'); $conf['view']['standard']['baseUrl'] = $conf['basedir']; diff --git a/index.php b/index.php index 577d3a83e5d78bc7aef666291fefc3da08990317..7bd8b7fc1fcb446a7347d0fa4b3a20fa89138cbe 100755 --- a/index.php +++ b/index.php @@ -22,29 +22,25 @@ if($conf['debug']){ error_reporting(E_ERROR); } - - include_once('classes/Utils.php'); include_once('classes/Queries.php'); include_once('classes/Endpoint.php'); -include_once('classes/MetaDb.php'); include_once('classes/Convert.php'); $results = array(); $first = array(); $endpoints = array(); $endpoints['local'] = new Endpoint($conf['endpoint']['local'], $conf['endpointParams']['config']); -$metaDb = new MetaDb($conf['metadata']['db']['location']); $acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']); $extension = Utils::getExtension($acceptContentType); + +//Check content type is supported by LODSPeaKr if($acceptContentType == NULL){ Utils::send406($uri); } -if(sizeof($_GET['q'])>0 && file_exists($conf['static']['directory'].$_GET['q'])){ - echo file_get_contents($conf['static']['directory'].$_GET['q']); - exit(0); -} + +//Export if($conf['export'] && $_GET['q'] == 'export'){ include_once('settings.inc.php'); include_once('classes/Exporter.php'); @@ -54,87 +50,37 @@ if($conf['export'] && $_GET['q'] == 'export'){ exit(0); } - +//Redirect to root URL if necessary $uri = $conf['basedir'].$_GET['q']; $localUri = $uri; if($uri == $conf['basedir']){ header('Location: '.$conf['root']); exit(0); -}elseif(preg_match("|^".$conf['basedir'].$conf['special']['uri']."|", $uri)){ - include_once($conf['special']['class']); - $context = array(); - $context['contentType'] = $acceptContentType; - $context['endpoints'] = $endpoints; - $sp = new SpecialFunction(); - $sp->execute($uri, $context); - exit(0); } + +//Configure external URIs if necessary if($conf['mirror_external_uris']){ $uri = $conf['ns']['local'].$_GET['q']; $localUri = $conf['basedir'].$_GET['q']; -} - -$pair = Queries::getMetadata($localUri, $acceptContentType, $metaDb); - -if($pair == NULL){ // Original URI is not in metadata - if(Queries::uriExist($uri, $endpoints['local'])){ - $page = Queries::createPage($uri, $localUri, $acceptContentType, $metaDb); - if($page == NULL){ - Utils::send500(NULL); - } - Utils::send303($page, $acceptContentType); - }else{ - Utils::send404($uri); - } -} -list($res, $page, $format) = $pair; - -//If resource is not the page, send a 303 to the document -if($res == $localUri){ - Utils::send303($page, $acceptContentType); -} - -$uri = $res; -if($conf['mirror_external_uris']){ - $localUri = preg_replace("|^".$conf['ns']['local']."|", $conf['basedir'], $res); } -$extension = Utils::getExtension($format); - -/*Redefine Content type based on the -* dcterms:format for this page -*/ -$acceptContentType = $format; - -//Check if files for model and view exist -$t=Queries::getClass($uri, $endpoints['local']); - -list($modelFile, $viewFile) = Utils::getModelandView($t, $extension); -$base = $conf['view']['standard']; -$base['type'] = $modelFile; -$base['this']['value'] = $uri; -$base['this']['curie'] = Utils::uri2curie($uri); -$base['thislocal']['value'] = $localUri; -$base['thislocal']['curie'] = Utils::uri2curie($localUri); -$base['this']['contentType'] = $acceptContentType; -$base['model']['directory'] = $conf['model']['directory']; -$base['view']['directory'] = $conf['view']['directory']; -$base['ns'] = $conf['ns']; - - -chdir($conf['model']['directory']); - -Utils::queryFile($modelFile, $endpoints['local'], $results, $first); -$results = Utils::internalize($results); -$base['first'] = Utils::getFirsts($results); -chdir($conf['home']); -if(is_array($results)){ - $resultsObj = Convert::array_to_object($results); -}else{ - $resultsObj = $results; +//Modules +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); + } } -Utils::processDocument($viewFile, $base, $resultsObj); -//} +Utils::send404($uri); ?> diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/GoogleMaps.php b/lib/Haanga/lib/Haanga/Extension/Filter/Googlemaps.php similarity index 76% rename from lib/Haanga/lib/Haanga/Extension/Filter/GoogleMaps.php rename to lib/Haanga/lib/Haanga/Extension/Filter/Googlemaps.php index 85b7e0c56a462f52fd958ac3212e0f1335c0822f..08faea9a6a61aa1480aac9554db0007bcf0a06ab 100644 --- a/lib/Haanga/lib/Haanga/Extension/Filter/GoogleMaps.php +++ b/lib/Haanga/lib/Haanga/Extension/Filter/Googlemaps.php @@ -1,6 +1,6 @@ <?php -class Haanga_Extension_Filter_GoogleMaps{ +class Haanga_Extension_Filter_Googlemaps{ public $is_safe = TRUE; static function main($obj, $varname){ $data = ""; @@ -43,7 +43,7 @@ class Haanga_Extension_Filter_GoogleMaps{ $east = $k->$names[1]->value; } - $nameArr .= $k->$names[2]->value; + $nameArr .= '"'.$k->$names[2]->value.'"'; $firstColumn = false; } @@ -72,21 +72,18 @@ class Haanga_Extension_Filter_GoogleMaps{ var latArray = [".$latArr."]; var lonArray = [".$longArr."]; var labelArray = [".$nameArr."]; - - for (var i = 0; i < latArray.length; i++) { - var position = new google.maps.LatLng(latArray[i], lonArray[i]); - var marker = new google.maps.Marker({ - position: position, - map: map - }); - - marker.setTitle(labelArray[i]); - var infowindow = new google.maps.InfoWindow({ - content: labelArray[i] - }); - google.maps.event.addListener(marker, 'click', function() { - infowindow.open(marker.get('map'), marker); - }); + var marker = new Array(); + for (var i = 0; i < labelArray.length; i++) { + var position = new google.maps.LatLng(latArray[i], lonArray[i]); + marker = new google.maps.Marker({position: position,map: map}); + marker.setTitle(labelArray[i]); + var infowindow = new google.maps.InfoWindow({content: i+labelArray[i]}); + google.maps.event.addListener(marker, 'click', (function(marker, i) { + return function() { + infowindow.setContent(labelArray[i]); + infowindow.open(map, marker); + } + })(marker, i)); } } diff --git a/lib/Haanga/lib/Haanga/Extension/Filter/Urldecode.php b/lib/Haanga/lib/Haanga/Extension/Filter/Urldecode.php new file mode 100644 index 0000000000000000000000000000000000000000..b0b213385a31a722cba962c72c1d6808447ee456 --- /dev/null +++ b/lib/Haanga/lib/Haanga/Extension/Filter/Urldecode.php @@ -0,0 +1,11 @@ +<?php + +class Haanga_Extension_Filter_UrlDecode +{ + + public static function generator($cmp, $args) + { + $cmp->var_is_safe = TRUE; + return hexec('urldecode', $args[0]); + } +} diff --git a/models/rdfs:Resource.model.html b/models/rdfs:Resource.model.html deleted file mode 100644 index 5e8f44e2f6e46c5d1bb4858707c27526d1b5e405..0000000000000000000000000000000000000000 --- a/models/rdfs:Resource.model.html +++ /dev/null @@ -1,8 +0,0 @@ -SELECT ?s2 ?p2 ?s1 ?p1 WHERE { - { - <{{uri}}> ?s1 ?p1 . - }UNION{ - ?s2 ?p2 <{{uri}}> . - } -} - diff --git a/models/rdfs:Resource.model.rdf b/models/rdfs:Resource.model.rdf deleted file mode 100644 index 61df9dc82ae823fb1ebafe746788f4ebecb6f20c..0000000000000000000000000000000000000000 --- a/models/rdfs:Resource.model.rdf +++ /dev/null @@ -1 +0,0 @@ -DESCRIBE <{{uri}}> diff --git a/models/special.classes.model.html b/models/service.classes/html.queries/main.query similarity index 100% rename from models/special.classes.model.html rename to models/service.classes/html.queries/main.query diff --git a/models/service.instances/html.queries/main.query b/models/service.instances/html.queries/main.query new file mode 100644 index 0000000000000000000000000000000000000000..5ff6cf27a42a08634ab1974a5b043a59ebcd2431 --- /dev/null +++ b/models/service.instances/html.queries/main.query @@ -0,0 +1,6 @@ +{%for h in lodspk.header %} +PREFIX {{h.prefix}}: <{{h.ns}}> +{%endfor%} +SELECT DISTINCT ?resource WHERE { + ?resource a {{lodspk.args.arg0}} +} diff --git a/models/special.namedGraphs.model.html b/models/service.namedGraphs/html.queries/main.query similarity index 68% rename from models/special.namedGraphs.model.html rename to models/service.namedGraphs/html.queries/main.query index b73ae66e3f2a16aed3d8342b2b913e4984f7885a..3c0f060c416a4a36a8ecc8d21ad23581ab05f660 100644 --- a/models/special.namedGraphs.model.html +++ b/models/service.namedGraphs/html.queries/main.query @@ -1,5 +1,5 @@ SELECT DISTINCT ?g WHERE { GRAPH ?g{ - ?s ?p ?o . + [] ?p ?resource . } } diff --git a/models/special.instances.model.html b/models/special.instances.model.html deleted file mode 100644 index d7de13cc16c4e8ec8619293db9b4a9cf8a1a76fb..0000000000000000000000000000000000000000 --- a/models/special.instances.model.html +++ /dev/null @@ -1,6 +0,0 @@ -{%for h in base.header %} -PREFIX {{h.prefix}}: <{{h.ns}}> -{%endfor%} -SELECT DISTINCT ?resource WHERE { - ?resource a {{base.args.arg0}} . -} diff --git a/models/type.rdfs:Resource/html.queries/main.query b/models/type.rdfs:Resource/html.queries/main.query new file mode 100644 index 0000000000000000000000000000000000000000..2f315c7c5e89f64ea6ed61f19505e523b64b03d0 --- /dev/null +++ b/models/type.rdfs:Resource/html.queries/main.query @@ -0,0 +1,18 @@ +SELECT ?s2 ?p2 ?s1 ?p1 WHERE { +{ +GRAPH ?g{ + { + <{{uri}}> ?s1 ?p1 . + }UNION{ + ?s2 ?p2 <{{uri}}> . + + } +} +}UNION{ { + <{{uri}}> ?s1 ?p1 . + }UNION{ + ?s2 ?p2 <{{uri}}> . + + } +} +} diff --git a/css/basic.css b/static/css/basic.css similarity index 100% rename from css/basic.css rename to static/css/basic.css diff --git a/css/person.css b/static/css/person.css similarity index 100% rename from css/person.css rename to static/css/person.css diff --git a/static/index.html b/static/index.html index 7a29d7e7569c5b9b554bbd8ef752c5c68cf4b90f..83751e8b401333baf5365a2c6a9a205d9ad1eaa0 100644 --- a/static/index.html +++ b/static/index.html @@ -1,17 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> - <html xmlns="http://www.w3.org/1999/xhtml" xmlns:local="http://localhost/lodspeakr/" + <html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.0" xml:lang="en"> <head> <title>Main</title> - <link href="http://localhost/lodspeakr//lodspeakr/css/basic.css" rel="stylesheet" type="text/css" media="screen" /> + <link href="css/basic.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <h1>Services available</h1> <ul> - <li><a href='special/classes'>List of classes in the triple store</a></li> - <li><a href='special/namedGraphs'>Named graphs in the triple store</a></li> + <li><a href='classes'>List of classes in the triple store</a></li> + <li><a href='namedGraphs'>Named graphs in the triple store</a></li> </ul> </body> </html> diff --git a/templates/README b/templates/README deleted file mode 100644 index 767f7497b383237f3b089197c2e8453d80102c64..0000000000000000000000000000000000000000 --- a/templates/README +++ /dev/null @@ -1 +0,0 @@ -This directory will include useful templates for different classes. diff --git a/templates/models/foaf:Person.model.html b/templates/models/foaf:Person.model.html deleted file mode 100644 index 3936a5ccc999c0349cc7ce6a185f2e2c81974ded..0000000000000000000000000000000000000000 --- a/templates/models/foaf:Person.model.html +++ /dev/null @@ -1,14 +0,0 @@ -PREFIX foaf: <http://xmlns.com/foaf/0.1/> -SELECT ?name ?firstName ?lastName ?img ?homepage ?k WHERE { - { - %u foaf:name ?name ; - foaf:firstName ?firstName; - foaf:depiction ?img ; - foaf:homepage ?homepage; - foaf:lastName ?lastName . - }UNION{ - %u foaf:knows ?k . - } -} - - diff --git a/templates/views/foaf:Person.view.html b/templates/views/foaf:Person.view.html deleted file mode 100644 index 78b9530191d710395bb453c8496c8f3c06538850..0000000000000000000000000000000000000000 --- a/templates/views/foaf:Person.view.html +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" - "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> - <html {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" - {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en"> - <head> - <title>Page about {{row.value.name}}</title> - <link href="{{base.baseUrl}}lodspeakr/css/person.css" rel="stylesheet" type="text/css" media="screen" /> - </head> - <body> - {% for row in r %} - {% if row.value.name != '' %} - <h1>{{row.value.firstName}} {{row.value.lastName}}{% if row.value.img != '' %} <img src="{{row.value.img}}" width="100px"/>{%endif%}</h1> - <p>This is a page about {{row.value.name}}. He has a personal homepage located at <a href='{{row.value.homepage}}'>{{row.value.homepage}}</a>.</p> - {%endif%} - {% endfor %} - - - {% for row in r %} - {% if row.value.k != '' %}<p>He knows <a href='{{row.value.k}}'>{{row.value.k}}</a></p>{%endif%} - {% endfor %} - </body> -</html> - - diff --git a/utils/lodspk.sh b/utils/lodspk.sh new file mode 100755 index 0000000000000000000000000000000000000000..bf1504aee8885c5c5765ea6e84e278278dfa2c28 --- /dev/null +++ b/utils/lodspk.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# +# https://github.com/alangrafu/lodspeakr/blob/master/utils/ldspk.sh +USAGE="Usage: $0 create|delete uri|type|service foo [html|rdf|ttl|nt|json]" +USAGEDEBUG="Usage: $0 debug on|off" +if [[ $# -eq 0 || "$1" == "--help" ]]; then + echo $USAGE + exit 1 +fi + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +operations=( create delete debug backup ) +currentOperation= + +if [[ ${operations[@]} =~ $1 ]]; then + currentOperation=$1 +else + echo "Operation \"$1\" not valid" + echo $USAGE + exit 1 +fi + +## Backup +if [[ $currentOperation == "backup" ]]; then + $DIR/modules/backup.sh +fi + +## Create/delete +if [[ $currentOperation == "create" || $currentOperation == "delete" ]]; then + modules=( type service uri ) + formats=( html rdf ttl nt json all ) + currentModule= + currentFormat= + if [[ ${modules[@]} =~ $2 ]]; then + currentModule=$2 + else + echo "Module \"$2\" not valid" + echo $USAGE + exit 1 + fi + + currentUnit=$3 + + if [[ ${formats[@]} =~ $4 ]]; then + currentFormat=$4 + else + if [ -z "$4" ]; then + currentFormat="all" + else + echo "Format \"$4\" not valid" + echo $USAGE + exit 1 + fi + fi + $DIR/modules/create-$currentModule.sh "$currentUnit" "$currentFormat" +fi + +## Debug +if [[ $currentOperation == "debug" ]]; then + debugOptions=( on off 0 1 ) + debugOperation= + if [[ ${debugOptions[@]} =~ $2 ]] + then + debugOperation=$2 + else + echo "Debug option not supported. Operation aborted" >&2 + echo $USAGEDEBUG + exit 1 + fi + php $DIR/modules/debug.php "$debugOperation" +fi diff --git a/utils/modules/backup.sh b/utils/modules/backup.sh new file mode 100755 index 0000000000000000000000000000000000000000..396de7661cfdf508b49ffe88547c4c33981cfb57 --- /dev/null +++ b/utils/modules/backup.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +BACKUPDIR=$HOME/lodspeakr_backup +cd $DIR/../.. +if [[ ! -d $BACKUPDIR ]]; then + echo "WARNING: No $BACKUPDIR dir. Creating it." >&2 + mkdir $BACKUPDIR +fi + +if [[ ! -d $BACKUPDIR ]]; then + echo "ERROR: Couldn't create $BACKUPDIR. Operation aborted" >&2 + exit 1 +fi + +tmpFile=lodspeakr_backup_`date +%Y%m%d%H%M%S`.tar.gz + +tar -czf $tmpFile settings.inc.php models views + +mv $tmpFile $BACKUPDIR/ +echo "New backup $tmpFile created" + diff --git a/utils/modules/create-service.sh b/utils/modules/create-service.sh new file mode 100755 index 0000000000000000000000000000000000000000..4fdddb342249dc1535dfe0c0f1b558aebcfbe737 --- /dev/null +++ b/utils/modules/create-service.sh @@ -0,0 +1,120 @@ +#!/bin/bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +initToken='service' + +modelHtml=$(cat <<QUERY +{%for h in base.header %} +PREFIX {{h.prefix}}: <{{h.ns}}> +{%endfor%} +SELECT DISTINCT ?resource WHERE { + {%if base.args.arg0 %}GRAPH <{{lodspk.args.arg0}}>{ {%endif%} + [] a ?resource . + {%if base.args.arg0 %} } {%endif%} +} +QUERY) + +viewHtml=$(cat <<VIEW +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" + "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" + {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en"> + <head> + <title>My new Service</title> + <link href="{{lodspk.baseUrl}}css/basic.css" rel="stylesheet" type="text/css" media="screen" /> + </head> + <body> + <h1>Classes available</h1> + <ul> + {% for row in models.main %} + <li><a href="{{lodspk.baseUrl}}special/instances/{{ row.resource.curie }}">{{row.resource.curie}}</a></li> + {% endfor %} + </ul> + </body> +</html> +VIEW) + +modelRdf=$(cat <<QUERY +DESCRIBE ?resource WHERE { + [] a ?resource . +} +QUERY) + +viewRdf=$(cat <<QUERY +{{r|safe}} +QUERY) + +modelTtl=$modelRdf +viewTtl=$viewRdf +modelNt=$modelRdf +viewNt=$viewRdf +modelJson=$modelRdf +viewJson=$viewJson + +#Check models +mainModelDir=$DIR/../../models/$initToken.$1 + +if [ -e "$mainModelDir" ] +then + echo "WARNING: At least one model for $1 exists." >&2 +else + mkdir $mainModelDir +fi + +obj=( ) +if [ "$2" == "all" ] +then + obj=( html rdf ttl nt json ) +else + obj=( $2 ) +fi + +for i in ${obj[@]} +do + if [ -e $mainModelDir/$i.queries ] + then + echo ERROR: $initToken.$1/$i.queries exists in models. Operation aborted >&2 + exit 1 + fi +done + + +#Check views +mainViewDir=$DIR/../../views/$initToken.$1 + +if [ -e "$mainViewDir" ] +then + echo "WARNING: At least one view for $1 exists." >&2 +else + mkdir $mainViewDir +fi + + +for i in ${obj[@]} +do + if [ -e $mainViewDir/$i.template ] + then + echo ERROR: $initToken.$1/$i already exist in views. Operation aborted >&2 + exit 1 + fi +done + + +#Create file structure + +for i in ${obj[@]} +do + mkdir $mainModelDir/$i.queries + if [ "$i" == "html" ] + then + echo "$modelHtml" > $mainModelDir/$i.queries/main.query + echo "$viewHtml" > $mainViewDir/$i.template + else + echo "$modelRdf" > $mainModelDir/$i.queries/main.query + echo "$viewRdf" > $mainViewDir/$i.template + fi +done + +echo $initToken.$1 created/modified successfully! >&2 diff --git a/utils/modules/create-type.sh b/utils/modules/create-type.sh new file mode 100755 index 0000000000000000000000000000000000000000..18a5cff11171effecbce2faaec7ffbf82f4d398b --- /dev/null +++ b/utils/modules/create-type.sh @@ -0,0 +1,165 @@ +#!/bin/bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +initToken='type' + +modelHtml=$(cat <<QUERY +SELECT ?s2 ?p2 ?s1 ?p1 WHERE { + { + GRAPH ?g{ + { + <{{uri}}> ?s1 ?p1 . + }UNION{ + ?s2 ?p2 <{{uri}}> . + } + } + }UNION{ + { + <{{uri}}> ?s1 ?p1 . + }UNION{ + ?s2 ?p2 <{{uri}}> . + } + } +} +QUERY +) + + +viewHtml=$(cat <<VIEW +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" + "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" + {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en"> + <head> + <title>Page about {{lodspk.this.value}}</title> + <link href="{{lodspk.baseUrl}}css/basic.css" rel="stylesheet" type="text/css" media="screen" /> + <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version" href="{{lodspk.this.value}}.rdf" /> + <link rel="alternate" type="text/turtle" title="Turtle Version" href="{{lodspk.this.value}}.ttl" /> + <link rel="alternate" type="text/plain" title="N-Triples Version" href="{{lodspk.this.value}}.nt" /> + <link rel="alternate" type="application/json" title="RDFJSON Version" href="{{lodspk.this.value}}.json" /> + </head> + <body about="{{lodspk.this.value}}"> + <h1>Page about <a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a></h1> + <br/> + <h2>Class $1</h2> + <div> + <h2>Information from {{lodspk.this.curie}}</h2> + <table> + {% for row in models.main %} + + {% if row.s1%} + <tr> + <td><a href='{{row.s1.value}}'>{{row.s1.curie}}</a></td> + + {% if row.p1.uri == 1 %} + <td><a rel='{{row.s1.curie}}' href='{{row.p1.value}}'>{{row.p1.curie}}</a></td> + {% else %} + <td><span property='{{row.s1.curie}}'>{{row.p1.value}}</span></td> + {% endif %} + + </tr> + {% endif %} + {% endfor %} + </table> + + <br/><br/> + <h2>Information pointing to {{lodspk.this.curie}}</h2> + <table> + {% for row in models.main %} + {% if row.s2%} + <tr> + <td><a href='{{row.s2.value}}'>{{row.s2.curie}}</a></td> + <td><a rev='[{{row.p2.curie}}]' href='{{row.s2.value}}'>{{row.p2.curie}}</a></td> + </tr> + {%endif %} + {% endfor %} + </table> + </div> + </body> +</html> +VIEW) + +modelRdf=$(cat <<QUERY +DESCRIBE ?resource WHERE { + [] a ?resource . +} +QUERY) + +viewRdf=$(cat <<VIEW +{{models.main|safe}} +VIEW) + +modelTtl=$modelRdf +viewTtl=$viewRdf +modelNt=$modelRdf +viewNt=$viewRdf +modelJson=$modelRdf +viewJson=$viewJson + +#Check models +mainModelDir=$DIR/../../models/$initToken.$1 + +if [ -e "$mainModelDir" ] +then + echo "WARNING: At least one model for $1 exists." >&2 +else + mkdir $mainModelDir +fi + +obj=( ) +if [ "$2" == "all" ] +then + obj=( html rdf ttl nt json ) +else + obj=( $2 ) +fi + +for i in ${obj[@]} +do + if [ -e $mainModelDir/$i.queries ] + then + echo ERROR: $initToken.$1/$i.queries exists in models. Operation aborted >&2 + exit 1 + fi +done + + +#Check views +mainViewDir=$DIR/../../views/$initToken.$1 + +if [ -e "$mainViewDir" ] +then + echo "WARNING: At least one view for $1 exists." >&2 +else + mkdir $mainViewDir +fi + + +for i in ${obj[@]} +do + if [ -e $mainViewDir/$i.template ] + then + echo ERROR: $initToken.$1/$i already exist in views. Operation aborted >&2 + exit 1 + fi +done + + +#Create file structure + +for i in ${obj[@]} +do + mkdir $mainModelDir/$i.queries + if [ "$i" == "html" ] + then + echo "$modelHtml" > $mainModelDir/$i.queries/main.query + echo "$viewHtml" > $mainViewDir/$i.template + else + echo "$modelRdf" > $mainModelDir/$i.queries/main.query + echo "$viewRdf" > $mainViewDir/$i.template + fi +done + +echo $initToken.$1 created/modified successfully! >&2 diff --git a/utils/modules/create-uri.sh b/utils/modules/create-uri.sh new file mode 100755 index 0000000000000000000000000000000000000000..e2587bd7d19ffe686f36f6e7690f47876144b3e1 --- /dev/null +++ b/utils/modules/create-uri.sh @@ -0,0 +1,153 @@ +#!/bin/bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +initToken='uri' + +modelHtml=$(cat <<QUERY +SELECT ?s2 ?p2 ?s1 ?p1 WHERE { + { + <{{uri}}> ?s1 ?p1 . + }UNION{ + ?s2 ?p2 <{{uri}}> . + } +} +QUERY +) + + +viewHtml=$(cat <<VIEW +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" + "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" + {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en"> + <head> + <title>Page about {{lodspk.this.value}}</title> + <link href="{{lodspk.baseUrl}}css/basic.css" rel="stylesheet" type="text/css" media="screen" /> + <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version" href="{{lodspk.this.value}}.rdf" /> + <link rel="alternate" type="text/turtle" title="Turtle Version" href="{{lodspk.this.value}}.ttl" /> + <link rel="alternate" type="text/plain" title="N-Triples Version" href="{{lodspk.this.value}}.nt" /> + <link rel="alternate" type="application/json" title="RDFJSON Version" href="{{lodspk.this.value}}.json" /> + </head> + <body about="{{lodspk.this.value}}"> + <h1>Page about <a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a></h1> + <div> + <h2>Information from {{lodspk.this.curie}}</h2> + <table> + {% for row in models.main %} + + {% if row.s1%} + <tr> + <td><a href='{{row.s1.value}}'>{{row.s1.curie}}</a></td> + + {% if row.p1.uri == 1 %} + <td><a rel='{{row.s1.curie}}' href='{{row.p1.value}}'>{{row.p1.curie}}</a></td> + {% else %} + <td><span property='{{row.s1.curie}}'>{{row.p1.value}}</span></td> + {% endif %} + + </tr> + {% endif %} + {% endfor %} + </table> + + <br/><br/> + <h2>Information pointing to {{lodspk.this.curie}}</h2> + <table> + {% for row in models.main %} + {% if row.s2%} + <tr> + <td><a href='{{row.s2.value}}'>{{row.s2.curie}}</a></td> + <td><a rev='[{{row.p2.curie}}]' href='{{row.s2.value}}'>{{row.p2.curie}}</a></td> + </tr> + {%endif %} + {% endfor %} + </table> + </div> + </body> +</html> +VIEW) + +modelRdf=$(cat <<QUERY +DESCRIBE ?resource WHERE { + [] a ?resource . +} +QUERY) + +viewRdf=$(cat <<VIEW +{{r|safe}} +VIEW) + +modelTtl=$modelRdf +viewTtl=$viewRdf +modelNt=$modelRdf +viewNt=$viewRdf +modelJson=$modelRdf +viewJson=$viewJson + +#Check models +mainModelDir=$DIR/../../models/$initToken.$1 + +if [ -e "$mainModelDir" ] +then + echo "WARNING: At least one model for $1 exists." >&2 +else + mkdir $mainModelDir +fi + +obj=( ) +if [ "$2" == "all" ] +then + obj=( html rdf ttl nt json ) +else + obj=( $2 ) +fi + +for i in ${obj[@]} +do + if [ -e $mainModelDir/$i.queries ] + then + echo ERROR: $initToken.$1/$i.queries exists in models. Operation aborted >&2 + exit 1 + fi +done + + +#Check views +mainViewDir=$DIR/../../views/$initToken.$1 + +if [ -e "$mainViewDir" ] +then + echo "WARNING: At least one view for $1 exists." >&2 +else + mkdir $mainViewDir +fi + + +for i in ${obj[@]} +do + if [ -e $mainViewDir/$i.template ] + then + echo ERROR: $initToken.$1/$i already exist in views. Operation aborted >&2 + exit 1 + fi +done + + +#Create file structure + +for i in ${obj[@]} +do + mkdir $mainModelDir/$i.queries + if [ "$i" == "html" ] + then + echo "$modelHtml" > $mainModelDir/$i.queries/main.query + echo "$viewHtml" > $mainViewDir/$i.template + else + echo "$modelRdf" > $mainModelDir/$i.queries/main.query + echo "$viewRdf" > $mainViewDir/$i.template + fi +done + +echo $initToken.$1 created/modified successfully! >&2 diff --git a/utils/modules/debug.php b/utils/modules/debug.php new file mode 100644 index 0000000000000000000000000000000000000000..2e432895282af735de1ec14efd59aeecf9f1adca --- /dev/null +++ b/utils/modules/debug.php @@ -0,0 +1,14 @@ +<? +$s = 'settings.inc.php'; +$c = file_get_contents($s); +$optionarray = Array('on' => 'true', '1' => 'true', 'off' => 'false', '0' =>'false'); +$antiarray = Array('on' => 'false', '1' => 'false', 'off' => 'true', '0' =>'true'); +$option = $optionarray[$argv[1]];; +$newC = preg_replace('/debug(.+)'.$antiarray[$argv[1]].'/', "debug'] = ".$option, $c); +if(file_put_contents($s, $newC) === FALSE){ + echo "An error ocurred"; + exit(1); +}else{ + echo "Debug mode turned ".$option."\n"; +} +?> diff --git a/utils/modules/delete-service.sh b/utils/modules/delete-service.sh new file mode 100755 index 0000000000000000000000000000000000000000..780ebab235081cc7386e529afdedf673b604d9e4 --- /dev/null +++ b/utils/modules/delete-service.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +initToken='service' + + +#Check models +mainModelDir=$DIR/../../models/$initToken.$1 + +if [ ! -e "$mainModelDir" ] +then + echo "ERROR: $initToken.$1 doesn't exist in models. Operation aborted" >&2 + exit 1 +fi + +obj=( ) +if [ "$2" == "all" ] +then + obj=( html rdf ttl nt json ) +else + obj=( $2 ) +fi + +for i in ${obj[@]} +do + if [ ! -e $mainModelDir/$i.queries ] + then + echo "WARNING: $initToken.$1/$i.query does not exists in models." >&2 + fi +done + + +#Check views +mainViewDir=$DIR/../../views/$initToken.$1 + +if [ ! -e "$mainViewDir" ] +then + echo "ERROR: $initToken.$1 doesn't exist in views. Operation aborted." >&2 +fi + + +for i in ${obj[@]} +do + if [ ! -e $mainViewDir/$i.template ] + then + echo "WARNING: $mainViewDir/$i.template doesn't exist in views." >&2 + fi +done + + +#Delete file structure + +if [ "$2" == "all" ] +then + rm -rf $mainModelDir + rm -rf $mainViewDir +else + for i in ${obj[@]} + do + rm -rf $mainModelDir/$i.queries + rm -rf $mainViewDir/$i.template + done +fi +echo $initToken.$1 deleted successfully! >&2 diff --git a/utils/modules/delete-type.sh b/utils/modules/delete-type.sh new file mode 100755 index 0000000000000000000000000000000000000000..877d3c99a927316600acf5f3c569b3340d18d630 --- /dev/null +++ b/utils/modules/delete-type.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +initToken='type' + + +#Check models +mainModelDir=$DIR/../../models/$initToken.$1 + +if [ ! -e "$mainModelDir" ] +then + echo "ERROR: $initToken.$1 doesn't exist in models. Operation aborted" >&2 + exit 1 +fi + +obj=( ) +if [ "$2" == "all" ] +then + obj=( html rdf ttl nt json ) +else + obj=( $2 ) +fi + +for i in ${obj[@]} +do + if [ ! -e $mainModelDir/$i.queries ] + then + echo "WARNING: $initToken.$1/$i.query does not exists in models." >&2 + fi +done + + +#Check views +mainViewDir=$DIR/../../views/$initToken.$1 + +if [ ! -e "$mainViewDir" ] +then + echo "ERROR: $initToken.$1 doesn't exist in views. Operation aborted." >&2 +fi + + +for i in ${obj[@]} +do + if [ ! -e $mainViewDir/$i.template ] + then + echo "WARNING: $mainViewDir/$i.template doesn't exist in views." >&2 + fi +done + + +#Delete file structure + +if [ "$2" == "all" ] +then + rm -rf $mainModelDir + rm -rf $mainViewDir +else + for i in ${obj[@]} + do + rm -rf $mainModelDir/$i.queries + rm -rf $mainViewDir/$i.template + done +fi +echo $initToken.$1 deleted successfully! >&2 diff --git a/utils/modules/delete-uri.sh b/utils/modules/delete-uri.sh new file mode 100755 index 0000000000000000000000000000000000000000..eaf82c3c06e3c62cacd542536575d2cbaa19d530 --- /dev/null +++ b/utils/modules/delete-uri.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +initToken='uri' + + +#Check models +mainModelDir=$DIR/../../models/$initToken.$1 + +if [ ! -e "$mainModelDir" ] +then + echo "ERROR: $initToken.$1 doesn't exist in models. Operation aborted" >&2 + exit 1 +fi + +obj=( ) +if [ "$2" == "all" ] +then + obj=( html rdf ttl nt json ) +else + obj=( $2 ) +fi + +for i in ${obj[@]} +do + if [ ! -e $mainModelDir/$i.queries ] + then + echo "WARNING: $initToken.$1/$i.query does not exists in models." >&2 + fi +done + + +#Check views +mainViewDir=$DIR/../../views/$initToken.$1 + +if [ ! -e "$mainViewDir" ] +then + echo "ERROR: $initToken.$1 doesn't exist in views. Operation aborted." >&2 +fi + + +for i in ${obj[@]} +do + if [ ! -e $mainViewDir/$i.template ] + then + echo "WARNING: $mainViewDir/$i.template doesn't exist in views." >&2 + fi +done + + +#Delete file structure + +if [ "$2" == "all" ] +then + rm -rf $mainModelDir + rm -rf $mainViewDir +else + for i in ${obj[@]} + do + rm -rf $mainModelDir/$i.queries + rm -rf $mainViewDir/$i.template + done +fi +echo $initToken.$1 deleted successfully! >&2 diff --git a/views/header.inc b/views/header.inc index adbefad22dc773222ab0ae36e0d78cecb89e691f..2c90255a3a3475d2c9157d0ce43379ba7f1d6b0c 100644 --- a/views/header.inc +++ b/views/header.inc @@ -1,5 +1,5 @@ -<h4>Endpoint: {{base.endpoint.local}}</h4> +<h4>Endpoint: {{lodspk.endpoint.local}}</h4> <div style='float:center'> -<a href='{{base.home}}'>Home</a> | <a href='{{base.home}}special/classes'>Classes</a> | <a href='{{base.home}}special/namedGraphs'>Named Graphs</a> +<a href='{{lodspk.home}}'>Home</a> | <a href='{{lodspk.home}}classes'>Classes</a> | <a href='{{lodspk.home}}namedGraphs'>Named Graphs</a> </div> diff --git a/views/rdfs:Resource.view.rdf b/views/rdfs:Resource.view.rdf deleted file mode 100644 index ca994557126054d192c1e40eca4f28f5e635bab8..0000000000000000000000000000000000000000 --- a/views/rdfs:Resource.view.rdf +++ /dev/null @@ -1 +0,0 @@ -{{r|safe}} diff --git a/views/service.classes/html.template b/views/service.classes/html.template new file mode 100644 index 0000000000000000000000000000000000000000..3c75a1c865f4f8252068bfc661900169f1ad498f --- /dev/null +++ b/views/service.classes/html.template @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" + "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> + <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" + {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en"> + <head> + <title>My new Service</title> + <link href="css/basic.css" rel="stylesheet" type="text/css" media="screen" /> + </head> + <body> + <h1>Classes available</h1> +{%include "../header.inc"%} + <ul> + {% for row in models.main %} + <li><a href="{{lodspk.baseUrl}}instances/{{ row.resource.curie }}">{{row.resource.curie}}</a></li> + {% endfor %} + </ul> + </body> +</html> diff --git a/views/special.classes.view.html b/views/service.instances/html.template similarity index 52% rename from views/special.classes.view.html rename to views/service.instances/html.template index 8a7777fe863303235d9f846e0be11cfbb70b9f00..c4b5de63882277515e3df3223f9a5dd5e8b7524f 100644 --- a/views/special.classes.view.html +++ b/views/service.instances/html.template @@ -4,17 +4,16 @@ <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en"> <head> - <title>Classes available</title> - <link href="{{base.baseUrl}}/lodspeakr/css/basic.css" rel="stylesheet" type="text/css" media="screen" /> + <title>Instances of {{lodspk.args.arg0}}</title> + <link href="../css/basic.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> - <h1>Classes available</h1> -{%include "header.inc"%} + <h1>Instances of class {{lodspk.args.arg0}}</h1> +{%include "../header.inc"%} <ul> - {% for row in r %} - <li><a href='{{base.baseUrl}}special/instances/{{ row.resource.curie }}'>{{row.resource.curie}}</a></li> + {% for row in models.main %} + <li><a href="{{ row.resource.value }}">{{row.resource.curie}}</a></li> {% endfor %} </ul> </body> </html> - diff --git a/views/special.namedGraphs.view.html b/views/service.namedGraphs/html.template similarity index 57% rename from views/special.namedGraphs.view.html rename to views/service.namedGraphs/html.template index 65ee0d422589ded5522de1f6a0330367f293fefc..1df5c5d4124b3a8a4fb86774acf38a31e52755d7 100644 --- a/views/special.namedGraphs.view.html +++ b/views/service.namedGraphs/html.template @@ -4,17 +4,16 @@ <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en"> <head> - <title>Graphs available in the triple store</title> - <link href="{{base.baseUrl}}/lodspeakr/css/basic.css" rel="stylesheet" type="text/css" media="screen" /> + <title>Named Graphs</title> + <link href="css/basic.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> - <h1>Graphs available</h1> -{%include "header.inc"%} + <h1>Named graphs available</h1> +{%include "../header.inc"%} <ul> - {% for row in r %} - <li>{{row.g.curie}}</li> + {% for row in models.main %} + <li>{{row.g.value}}</li> {% endfor %} </ul> </body> </html> - diff --git a/views/special.instances.view.html b/views/special.instances.view.html deleted file mode 100644 index b164024cf0adbbd522503ca1bd7e72e2066057ae..0000000000000000000000000000000000000000 --- a/views/special.instances.view.html +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" - "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> - <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" - {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en"> - <head> - <title>Instance of {{base.args.arg0}}</title> - <link href="{{base.baseUrl}}/lodspeakr/css/basic.css" rel="stylesheet" type="text/css" media="screen" /> - </head> - <body> - <h1>Instances of {{base.args.arg0}}</h1> -{%include "header.inc"%} - <ul> - {% for row in r %} - <li><a href='{{ row.resource.value }}'>{{row.resource.curie}}</a></li> - {% endfor %} - </ul> - </body> -</html> - diff --git a/views/rdfs:Resource.view.html b/views/type.rdfs:Resource/html.template similarity index 60% rename from views/rdfs:Resource.view.html rename to views/type.rdfs:Resource/html.template index 59f3631899154cb32d0456a682340ac5adfff40f..847e3b911b55106f401f7352c0275ab4cb50c7ca 100644 --- a/views/rdfs:Resource.view.html +++ b/views/type.rdfs:Resource/html.template @@ -1,42 +1,42 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> - <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}" + <html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in lodspk.ns %}xmlns:{{i}}="{{ns}}" {%endfor%}version="XHTML+RDFa 1.0" xml:lang="en"> <head> - <title>Page about {{base.this.value}}</title> - <link href="{{base.baseUrl}}/lodspeakr/css/basic.css" rel="stylesheet" type="text/css" media="screen" /> - <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version" href="{{base.this.value}}.rdf" /> - <link rel="alternate" type="text/turtle" title="Turtle Version" href="{{base.this.value}}.ttl" /> - <link rel="alternate" type="text/plain" title="N-Triples Version" href="{{base.this.value}}.nt" /> - <link rel="alternate" type="application/json" title="RDFJSON Version" href="{{base.this.value}}.json" /> + <title>Page about {{lodspk.this.value}}</title> + <link href="{{lodspk.baseUrl}}css/basic.css" rel="stylesheet" type="text/css" media="screen" /> + <link rel="alternate" type="application/rdf+xml" title="RDF/XML Version" href="{{lodspk.this.value}}.rdf" /> + <link rel="alternate" type="text/turtle" title="Turtle Version" href="{{lodspk.this.value}}.ttl" /> + <link rel="alternate" type="text/plain" title="N-Triples Version" href="{{lodspk.this.value}}.nt" /> + <link rel="alternate" type="application/json" title="RDFJSON Version" href="{{lodspk.this.value}}.json" /> </head> - <body about="{{base.this.value}}"> - <h1>Page about <a href='{{base.this.value}}'>{{base.this.curie}}</a></h1> + <body about="{{lodspk.this.value}}"> + <h1>Page about <a href='{{lodspk.this.value}}'>{{lodspk.this.curie}}</a></h1> <div> - <h2>Information from {{base.this.curie}}</h2> - <table> - {% for row in r %} + <h2>Information from {{lodspk.this.curie}}</h2> + <table> + {% for row in models.main %} {% if row.s1%} <tr> <td><a href='{{row.s1.value}}'>{{row.s1.curie}}</a></td> - + {% if row.p1.uri == 1 %} <td><a rel='{{row.s1.curie}}' href='{{row.p1.value}}'>{{row.p1.curie}}</a></td> {% else %} <td><span property='{{row.s1.curie}}'>{{row.p1.value}}</span></td> {% endif %} - + </tr> {% endif %} {% endfor %} </table> - + <br/><br/> - <h2>Information pointing to {{base.this.curie}}</h2> - <table> - {% for row in r %} + <h2>Information pointing to {{lodspk.this.curie}}</h2> + <table> + {% for row in models.main %} {% if row.s2%} <tr> <td><a href='{{row.s2.value}}'>{{row.s2.curie}}</a></td> @@ -48,4 +48,3 @@ </div> </body> </html> -