function buildExplainResponseFromConfig(&$response, $config) { $c = $config["entities"][$_REQUEST["resource"]]["search"]; $response->setShortName($config["entities"][$_REQUEST["resource"]]["title"]); if ($c["longname"]) { $response->setLongName($c["longname"]); } if ($c["description"]) { $response->setDescription($c["description"]); } if ($c["contact"]) { $response->setContact($c["contact"]); } if ($c["tags"]) { for ($i = 0; $i < count($c["tags"]); $i++) { $response->addTag($c["tags"][$i]); } } $opensearch_params = array("searchTerms", "count", "startIndex", "startPage", "language", "inputEncoding", "outputEncoding"); $url = $config['base_uri']; if (!ereg("/\\/\$/", $url)) { $url .= "/"; } $url .= $_REQUEST['resource'] . "/search?"; if ($c["parameters"]) { $query_args = array(); foreach (array_keys($c["parameters"]) as $key) { $query_arg = $key . "="; if (array_search(ereg_replace("\\?\$", '', $c["parameters"][$key]), $opensearch_params) !== False) { $query_arg .= "{" . $c["parameters"][$key] . "}"; } else { $query_arg .= "{jangle:" . $c["parameters"][$key] . "}"; } array_push($query_args, $query_arg); } $url .= join($query_args, "&"); } else { $url .= "query={searchTerms}"; } $response->setTemplate($url); if ($c["image"]) { $response->setImageLocation($c["image"]["location"]); if ($c["image"]["height"]) { $response->setImageHeight($c["image"]["height"]); } if ($c["image"]["width"]) { $response->setImageWidth($c["image"]["width"]); } if ($c["image"]["type"]) { $response->setImageType($c["image"]["type"]); } } if ($c["query"]) { $response->setExampleQuery($c["query"]); } if ($c["developer"]) { $response->setDeveloper($c["developer"]); } if ($c["attribution"]) { $response->setAttribution($c["attribution"]); } if ($c["syndicationright"]) { $response->setSyndicationRight($c["syndicationright"]); } if ($c["adultcontent"]) { $response->setAdultContent($c["adultcontent"]); } if ($c["language"]) { $response->setLanguage($c["language"]); } if ($c["inputencoding"]) { $response->addInputEncoding($c["inputencoding"]); } if ($c["outencoding"]) { $response->addInputEncoding($c["outputencoding"]); } $ctx_sets = array(); for ($i = 0; $i < count($c["indexes"]); $i++) { list($name, $index) = explode(".", $c["indexes"][$i]); if (!$ctx_sets[$name]) { $ctx_sets[$name] = array(); } if (!in_array($index, $ctx_sets[$name])) { array_push($ctx_sets[$name], $index); } } if (count($ctx_sets) > 0) { foreach (array_keys($ctx_sets) as $ctx_set) { $ident = $config["context-sets"][$ctx_set]["identifier"]; $ctx = new JangleContextSet($ctx_set, $ident); if (count($ctx_sets[$ctx_set]) > 0) { foreach ($ctx_sets[$ctx_set] as $index) { $ctx->addIndex($index); } } $response->addContextSet($ctx); } } return $response; }
function fromConnectorResponse($json) { $this->shortName = $json->shortname; if ($json->longname) { $this->longName = $json->longname; } if ($json->description) { $this->description = $json->description; } if ($json->query) { $query = get_object_vars($json->query); if ($json->query->example) { $this->exampleQuery = $query["example"]; } if ($query["context-sets"]) { foreach ($query["context-sets"] as $set) { $ctx = new JangleContextSet(); $ctx->fromConnectorResponse($set); array_push($this->indexes, $ctx); } } } if ($json->developer) { $this->developer = $json->developer; } if ($json->contact) { $this->contact = $json->contact; } if ($json->attribution) { $this->attribution = $json->attribution; } if ($json->syndicationright) { $this->syndicationRight = $json->syndicationright; } if ($json->adultcontent) { if ($json->adultcontent == true) { $this->adultContent = "True"; } } if ($json->language) { $this->language = $json->language; } if ($json->template) { $this->template = $json->template; } if ($json->tags) { $this->tags = $json->tags; } if ($json->inputencoding) { $this->inputEncoding = $json->inputencoding; } if ($json->outputencoding) { $this->outputEncoding = $json->outputencoding; } if ($json->image) { $this->image = get_object_vars($json->image); } }