get_parms(
'bid'
, 't'
, 'mod'
, 'debug'
);
if ( ! $parm['mod'])
$parm['mod'] = 'TREE';
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)));
// $sy_list = $root->appendChild($ret->createElement('sy_list'));
// $html_pop = $root->appendChild($ret->createElement('html_pop'));
$html = $root->appendChild($ret->createElement('html'));
if ($parm['bid'] !== null) {
$loaded = false;
$databox = $appbox->get_databox((int) $parm['bid']);
$dom = $databox->get_dom_thesaurus();
if ($dom) {
$xpath = $databox->get_xpath_thesaurus();
$unicode = new unicode();
$q = '/thesaurus';
if ($parm['debug'])
print('q:' . $q . '
\n');
if (($znode = $xpath->query($q)->item(0))) {
$q2 = '//sy';
if ($parm['t']) {
$t = splitTermAndContext($parm['t']);
$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])) . '\')';
$q2 = '//sy[' . $q2 . ']';
}
if ($parm['debug'])
print('q2:' . $q2 . '
\n');
$nodes = $xpath->query($q2, $znode);
if ($parm['mod'] == 'TREE') {
for ($i = 0; $i < $nodes->length; $i ++ ) {
$nodes->item($i)->setAttribute('bold', '1');
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'));
}
}
$zhtml = '';
getHTML2($znode, $zhtml, 0);
}
else {
$zhtml = '';
$bid = $parm['bid'];
for ($i = 0; $i < $nodes->length; $i ++ ) {
$n = $nodes->item($i);
$t = $n->getAttribute('v');
$tid = $n->getAttribute('id');
$zhtml .= '
'; $zhtml .= '' . $t . ''; $zhtml .= '
'; } } if ($parm['debug']) printf('zhtml=%s' . htmlentities($zhtml) . ''); } else { print($zhtml); } function getHTML2($srcnode, &$html, $depth) { global $parm; // printf('in: depth:%s
'; $html .= '...'; $html .= $allsy; $html .= '
'; $class = 'h'; } else { $html .= ''; $html .= ' '; $html .= $allsy; $html .= '
'; $class = 'c'; } $html .= '