Skip to content
Snippets Groups Projects
Commit 5d41ee10 authored by alvaro's avatar alvaro
Browse files

Fixed error in Endpoint class

parent 64555579
No related branches found
No related tags found
No related merge requests found
......@@ -9,59 +9,58 @@ class Endpoint{
$this->params = $params;
}
public function query($q, $output = 'json'){
global $conf;
$auxoutput = $this->params['output'];
$accept = 'application/sparql-results+json';
if($output != null){
$this->params['output'] = $output;
}
if($output == 'xml'){
$accept = 'application/sparql-results+xml';
}elseif($output == 'rdf'){
$accept = 'application/rdf+xml';
}
$c = curl_init();
$context = array();
$context[0] = 'Connection: close';
$context[1] = 'Accept: '.$accept;
$params = $this->params;
$params['query'] = $q;
$url = $this->sparqlUrl.'?'.http_build_query($params, '', '&');
curl_setopt($c, CURLOPT_URL, $url);
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 query($q, $output = 'json'){
global $conf;
$auxoutput = $this->params['output'];
$accept = 'application/sparql-results+json';
if($output != null){
$this->params['output'] = $output;
}
if($output == 'xml'){
$accept = 'application/sparql-results+xml';
}elseif($output == 'rdf'){
$accept = 'application/rdf+xml';
}
$c = curl_init();
$context = array();
$context[0] = 'Connection: close';
$context[1] = 'Accept: '.$accept;
$params = $this->params;
$params['query'] = $q;
$url = $this->sparqlUrl.'?'.http_build_query($params, '', '&');
curl_setopt($c, CURLOPT_URL, $url);
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){
......
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