Example #1
0
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;
}