-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparql.php
99 lines (81 loc) · 2.62 KB
/
sparql.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* @author Helena F Deus <helenadeus@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @package S3DB http://www.s3db.org
*/
#sparql.php is an API that serializes a sparql query into an S3QL query
##HEADER: Read the file and include the functions for parsing the RDF
ini_set('display_errors',0);
if($_REQUEST['su3d'])
ini_set('display_errors',1);
if(file_exists('config.inc.php'))
{
include('config.inc.php');
}
else
{
Header('Location: index.php');
exit;
}
#include(S3DB_SERVER_ROOT.'/dbstruct.php');
include_once(S3DB_SERVER_ROOT.'/core.header.php');
include_once(S3DB_SERVER_ROOT.'/rdfheader.inc.php');
include_once(S3DB_SERVER_ROOT.'/s3dbcore/sparql_read5.php');
if(is_file(S3DB_SERVER_ROOT.'/pearlib/Benchmark/Timer.php')){
require_once S3DB_SERVER_ROOT.'/pearlib/Benchmark/Timer.php';
$timer = new Benchmark_Timer();
$timer->start();
}
#include(S3DB_SERVER_ROOT.'/html2cell.php');
if(ereg('^query=&',$_SERVER['argv'][0]))
$_SERVER['argv'][0] = ereg_replace('^query=&','query=?',$_SERVER['argv'][0]);
if(is_array($argv))
foreach ($argv as $argin) {
if(ereg('(format|url|noHTML)=(.*)', $argin, $zz))
$in[$zz[1]] = $zz[2];
}
else {
$in = $_REQUEST;
##this piece does not seem to make sense any more... I wonder why i needed it?!
#ereg('query=(.*)$',$_SERVER['argv'][0],$tmp);
if($tmp) $in['query'] = urldecode($tmp[1]);
}
$default_uri = S3DB_URI_BASE.((substr(S3DB_URI_BASE, strlen(S3DB_URI_BASE)-1, 1)!='/')?'/':'');
if(ereg('^(http.*)|(.*)\.(spql)',$in['query'],$tmp)){
$a= file_get_contents($tmp[0]);
if($a) $in['query'] = $a;
else {echo "Query file is invalid.";exit;}
}
if(!$in['query']){
echo "Please specify some SPARQL query.";exit;
}
$clean = false;
$complete=false;
$goparallel=false;
if($_REQUEST['link']) $link=1;
elseif($_REQUEST['redirect']) $redirect=1;
if($_REQUEST['clean']) $clean = $_REQUEST['clean'];
$I = compact('in', 'user_id','db','default_uri','complete','goparallel','link', 'redirect','clean');
list($valid, $result) = sparql($I);
#list($valid, $result) = sparql_api($I);
if($redirect){
Header("Location: ".$result);
exit;
}
if($link){
echo "Your RDF document is available at ".S3DB_URI_BASE.ereg_replace('^'.S3DB_SERVER_ROOT, "",$result);
exit;
}
if($_REQUEST['out']=='header' || ($in['format']=='json'))
{
header("HTTP/1.1 200 OK ");
header("Content-Type: text/javascript");
#header("Content-length: 1000");
#header('Proxy-Connection: keep-alive');
#header('Connection: keep-alive');
}
echo $result;
#echo sparql_arc($I);#old version
exit;
?>