Skip to content
Snippets Groups Projects
Commit dd6beafe authored by alangrafu's avatar alangrafu
Browse files

Adding sharing of statics

parent 9912e10d
No related branches found
No related tags found
No related merge requests found
......@@ -382,6 +382,103 @@ class Exporter{
//break;
}
//Static files
$staticComponent = $conf['basedir'].'staticComponent';//uniqid("_:b");
$statics = $this->getComponents($conf['home'].$conf['static']['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($statics as $k=>$m){
//Controlled by
$t['p'] = OPMV.'wasControlledBy';
$t['o'] = $staticComponent;
$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'] = $staticComponent;
// Type of query
$t2 = array();
$t2['s'] = $t['o'];
$t2['s_type'] = 'bnode';
$t2['p'] = RDF.'type';
$t2['o'] = LS.'LodspeakrStaticElementsComponent';
$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."ProcessComponent";
$t3['o_type'] = 'uri';
array_push($triples, $t3);
array_push($triples, $t2);
$t2['p'] = RDFS.'label';
$t2['o'] = 'Component of LODSPeaKr in charge of static content';
$t2['o_type'] = 'literal';
array_push($triples, $t2);
$t['p'] = LS.'usedInput';
$t['o'] = $conf['basedir'].$conf['static']['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['static']['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 "#You can copy and paste the following data into a new\n";
echo "#LODSPeaKr instance at http://exampleofinstance.org/import\n";
echo "#As a side note: this is a turtle document but is served as text/plain to make it easier to copy&paste\n\n\n";
......
......@@ -25,13 +25,13 @@ class Importer{
exit(0);
}
$this->external_basedir = str_replace('benegesserit', '', $_GET['import']);
echo $this->external_basedir;
include_once('lib/arc2/ARC2.php');
$parser = ARC2::getTurtleParser();
if(isset($_GET['import'])){
$parser->parse($_GET['import']);
$this->external_basedir = str_replace('export', '', $_GET['import']);
}elseif(isset($_POST['importtext'])){
$parser->parse(RDF, $_POST['importtext']);
}else{
......@@ -47,13 +47,14 @@ class Importer{
}
$app = $appArr[0]['s'];
$this->external_basedir = $app;
$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];
$this->basedir = preg_replace('/import$/', '', (!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();
......@@ -113,6 +114,8 @@ class Importer{
$content .= $this->createNamespaces($params);
}elseif($compType == LS."LodspeakrSparqlEndpointRetriever"){
$this->createModels($inputs);
}elseif($compType == LS."LodspeakrStaticElementsComponent"){
$this->createStatics($inputs);
}elseif($compType == LS."LodspeakrVisualComponent"){
$this->createViews($inputs);
}else{
......@@ -128,6 +131,7 @@ class Importer{
echo 'Caught exception while writing settings: ', $e->getMessage(), "\n";
exit(1);
}
$this->showFinishing();
}
private function createEndpoints($ep){
......@@ -228,6 +232,36 @@ class Importer{
}
private function createStatics($statics){
try{
foreach($statics 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 statics: ', $e->getMessage(), "\n";
exit(1);
}
}
private function search($graph, $s = null, $p = null, $o = null){
$results = array();
foreach($graph as $v){
......@@ -266,6 +300,7 @@ class Importer{
}
return $results;
//$this->showFinishing();
}
private function showInterface(){
......@@ -278,7 +313,7 @@ class Importer{
You can paste the data obtained from another LODSPeaKr instance here in the box.
You can also automatize this import by adding a parameter '?import=URL' to this page.
Usually, the URL will be of the for <tt>http://example.org/foo/export</tt>
<form action='benegesserit.php' method='post'>
<form action='import' method='post'>
<textarea cols='100' rows='25' name='importtext'></textarea>
<input type='submit' value='Import'/>
</form>
......@@ -286,6 +321,20 @@ class Importer{
</html>";
echo $doc;
}
private function showFinishing(){
$doc = "<html>
<head>
<title>Finishing import</title>
</head>
<body>
<h2>Import finished</h2>
Your new application is ready. Please go to the <a href='".$this->basedir."'>home page</a>.
</body>
</html>";
echo $doc;
}
}
?>
......@@ -9,7 +9,7 @@ if($_GET['q'] == 'import'){
//Test if LODSPeaKr is configured
if(!file_exists('settings.inc.php')){
echo 'Need to configure lodspeakr first. Please run "install.sh" first';
echo 'Need to configure lodspeakr first. Please run "install.sh" first. Alternatively, you can <a href="import">import an existing application</a>';
exit(0);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment