get_parms( 'bid' , 't' , 'mod' , 'debug' ); if ( ! $parm['mod']) $parm['mod'] = 'TREE'; phrasea::headers(200, true); $zhtml = ''; if ($parm['bid'] !== null) { $loaded = false; $databox = $appbox->get_databox((int) $parm['bid']); $dom = $databox->get_dom_thesaurus(); $unicode = new unicode(); if ($dom) { $xpath = $databox->get_xpath_thesaurus(); $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
\n', $zhtml); } } } if ($parm['debug']) { print('
' . htmlentities($zhtml) . '
'); } else { print($zhtml); } //function getHTML($srcnode, &$html) //{ // getHTML2($srcnode, &$html, 0); //} function getHTML2($srcnode, &$html, $depth) { global $parm; // printf('in: depth:%s
\n', $depth); $bid = $parm['bid']; $tid = $srcnode->getAttribute('id'); $class = 'h'; if ($depth > 0) { $nts = 0; $allsy = ''; for ($n = $srcnode->firstChild; $n; $n = $n->nextSibling) { if ($n->nodeName == 'sy') { $t = $n->getAttribute('v'); if ($n->getAttribute('bold')) { // $allsy .= ($allsy?' ; ':'') . 'getAttribute('id').'\' href=\'javascript:void(0);\'>' . $t. ''; $allsy .= ( $allsy ? ' ; ' : '') . 'getAttribute('id') . '\'>' . $t . ''; } else { //$allsy .= ($allsy?' ; ':'') . 'getAttribute('id').'\' href=\'javascript:void(0);\'>' . $t. ''; $allsy .= ( $allsy ? ' ; ' : '') . 'getAttribute('id') . '\' >' . $t . ''; } } elseif ($n->nodeName == 'te') { $nts ++; } } if ($allsy == '') { //$allsy = 'THESAURUS'; $allsy = 'THESAURUS'; } if ($nts > 0) { $html .= '

'; $html .= '...'; $html .= $allsy; $html .= '

'; $class = 'h'; } else { $html .= '

'; $html .= ' '; $html .= $allsy; $html .= '

'; $class = 'c'; } $html .= '
'; } for ($n = $srcnode->firstChild; $n; $n = $n->nextSibling) { if ($n->nodeName == 'te') { if ($n->getAttribute('open')) { getHTML2($n, $html, $depth + 1); if ($parm['debug']) printf('explored node te id=%s
\n', $n->getAttribute('id')); } } } if ($depth > 0) $html .= '
'; } function splitTermAndContext($word) { $term = trim($word); $context = ''; if (($po = strpos($term, '(')) !== false) { if (($pc = strpos($term, ')', $po)) !== false) { $context = trim(substr($term, $po + 1, $pc - $po - 1)); $term = trim(substr($term, 0, $po)); } else { $context = trim(substr($term, $po + 1)); $term = trim(substr($term, 0, $po)); } } return(array($term, $context)); }