get_parms(
"bid"
, "id"
, "typ" // "TH" (thesaurus) ou "CT" (cterms)
, "t"
, "method" // "equal", "begins", "contains"
, "debug"
);
if ($parm["debug"]) {
phrasea::headers(200, true, 'text/html', 'UTF-8', true);
} else {
phrasea::headers(200, true, 'text/xml', 'UTF-8', false);
}
$ret = new DOMDocument("1.0", "UTF-8");
$ret->standalone = true;
$ret->preserveWhiteSpace = false;
$root = $ret->appendChild($ret->createElement("result"));
$root->appendChild($ret->createCDATASection(var_export($parm, true)));
$html = $root->appendChild($ret->createElement("html"));
$unicode = new unicode();
if ($parm["bid"] !== null) {
$loaded = false;
try {
$databox = $appbox->get_databox((int) $parm['bid']);
if ($parm["typ"] == "CT") {
$xqroot = "cterms";
$dom = $databox->get_dom_cterms();
} else {
$xqroot = "thesaurus";
$dom = $databox->get_dom_thesaurus();
}
if ($dom) {
$xpath = new DOMXPath($dom);
if ($parm["id"] == "T")
$q = "/thesaurus";
elseif ($parm["id"] == "C")
$q = "/cterms";
else
$q = "/$xqroot//te[@id='" . $parm["id"] . "']";
if ($parm["debug"])
print("q:" . $q . "
\n");
if (($znode = $xpath->query($q)->item(0))) {
if ($parm["t"]) {
$t = splitTermAndContext($parm["t"]);
// $q2 = "@w='" . thesaurus::xquery_escape($unicode->remove_indexer_chars($t[0])) . "'";
switch ($parm["method"]) {
case "begins":
$q2 = "starts-with(@w, '" . thesaurus::xquery_escape($unicode->remove_indexer_chars($t[0])) . "')";
if ($t[1])
$q2 .= " and starts-with(@k, '" . thesaurus::xquery_escape($unicode->remove_indexer_chars($t[1])) . "')";
break;
case "contains":
$q2 = "contains(@w, '" . thesaurus::xquery_escape($unicode->remove_indexer_chars($t[0])) . "')";
if ($t[1])
$q2 .= " and contains(@k, '" . thesaurus::xquery_escape($unicode->remove_indexer_chars($t[1])) . "')";
break;
case "equal":
default:
$q2 = "(@w='" . thesaurus::xquery_escape($unicode->remove_indexer_chars($t[0])) . "')";
if ($t[1])
$q2 .= " and (@k='" . thesaurus::xquery_escape($unicode->remove_indexer_chars($t[1])) . "')";
break;
}
$q2 = "//sy[" . $q2 . "]";
}
if ($parm["debug"])
print("q2:" . $q2 . "
\n");
$nodes = $xpath->query($q2, $znode);
for ($i = 0; $i < $nodes->length; $i ++ ) {
for ($n = $nodes->item($i)->parentNode; $n && $n->nodeType == XML_ELEMENT_NODE && $n->nodeName == "te"; $n = $n->parentNode) {
$n->setAttribute("open", "1");
if ($parm["debug"])
printf("opening node te id=%s
\n", $n->getAttribute("id"));
}
}
getHTML2($znode, $ret, $html, 0);
}
}
} catch (Exception $e) {
}
}
if ($parm["debug"])
print("
" . $ret->saveXML() . ""); else print($ret->saveXML()); function getHTML2($srcnode, $dstdom, $dstnode, $depth) { global $parm; // printf("in: depth:%s