ARC_rdf_store_ask_handler.php in Taxonomy import/export via XML 6
File
arc/ARC_rdf_store_ask_handler.php
View source
<?php
class ARC_rdf_store_ask_handler {
var $version = "0.1.0";
function __construct(&$api) {
$this->api =& $api;
$this->config = $this->api
->get_config();
}
function ARC_rdf_store_ask_handler(&$api) {
$this
->__construct($api);
}
function get_result($args = "") {
if (!isset($args["infos"])) {
return array(
"result" => "",
"error" => "missing parameter 'infos'",
);
}
$args["result_type"] = isset($args["result_type"]) ? $args["result_type"] : "xml";
$result_type = $args["result_type"];
if (!($rewriter = $this->api
->get_sparql2sql_rewriter())) {
return $this->api
->get_default_error();
}
$sql = $rewriter
->get_sql($args);
if (is_array($sql) && ($error = $sql["error"])) {
return $sql;
}
if ($result_type == "sql") {
return array(
"result" => $sql,
"error" => "",
);
}
$t1 = $this->api
->get_mtime();
if ($this->config["store_type"] != "basic") {
$this->api
->create_merge_tables();
}
if (!($rs = mysql_query($sql))) {
return array(
"result" => "",
"error" => mysql_error(),
);
}
$t2 = $this->api
->get_mtime();
$dur = $t2 - $t1;
$mthd = "get_" . $result_type . "_result";
if (method_exists($this, $mthd)) {
$args["rs"] =& $rs;
$sub_result = $this
->{$mthd}($args);
@mysql_free_result($rs);
return array(
"result" => $sub_result["result"],
"error" => $sub_result["error"],
"headers" => isset($sub_result["headers"]) ? $sub_result["headers"] : array(),
"query_time" => $dur,
);
}
@mysql_free_result($rs);
return array(
"result" => false,
"error" => "Unsupported result type '" . rawurlencode($result_type) . "'",
"headers" => array(),
"query_time" => $dur,
);
}
function get_plain_result($args = "") {
$rs = isset($args["rs"]) ? $args["rs"] : false;
$result = $rs && ($row = mysql_fetch_array($rs)) && $row["success"] ? "1" : "0";
return array(
"result" => $result,
"error" => "",
);
}
function get_bool_result($args = "") {
$rs = isset($args["rs"]) ? $args["rs"] : false;
$result = $rs && ($row = mysql_fetch_array($rs)) && $row["success"] ? true : false;
return array(
"result" => $result,
"error" => "",
);
}
function get_xml_result($args = "") {
$nl = "\n";
$ind = " ";
$rs = isset($args["rs"]) ? $args["rs"] : false;
$code = '' . '<?xml version="1.0" ?>' . $nl . '<sparql xmlns="http://www.w3.org/2005/sparql-results#">' . $nl . $ind . '<head>' . $nl . $ind . '</head>' . $nl . $ind . '<boolean>' . '';
$code .= $rs && ($row = mysql_fetch_array($rs)) && $row["success"] ? "true" : "false";
$code .= '' . '</boolean>' . $nl . '</sparql>' . '';
return array(
"result" => $code,
"error" => "",
);
}
function get_json_result($args = "") {
$nl = "\n";
$ind = " ";
$rs = isset($args["rs"]) ? $args["rs"] : false;
$jsonp = isset($args["result_type_args"]["jsonp"]) ? $args["result_type_args"]["jsonp"] : false;
$code = '' . '{' . $nl . $ind . 'head: {}' . ',' . $nl . $ind . 'boolean: ' . '';
$code .= $rs && ($row = mysql_fetch_array($rs)) && $row["success"] ? "true" : "false";
$code .= $nl . '}';
$result = $jsonp ? $jsonp . '(' . $code . ')' : $code;
return array(
"result" => $code,
"error" => "",
);
}
}