get_parms( 'bid' , 't' , 'mod' , 'debug' ); if(isset($session->usr_id) && isset($session->ses_id)) { $ses_id = $session->ses_id; $usr_id = $session->usr_id; if(!($ph_session = phrasea_open_session((int)$ses_id, $usr_id))) { header("Location: /login/?err=no-session"); exit(); } } else { header("Location: /login/"); exit(); } if(!$parm['mod']) $parm['mod'] = 'TREE'; if($parm['debug']) { header('Content-Type: text/html; charset=UTF-8'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); // HTTP/1.0 phrasea::headers(); } else { header('Content-Type: text/html; charset=UTF-8'); // header('Content-Type: application/xhtml+xml; charset=UTF-8'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); // HTTP/1.0 } $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; $dom = databox::get_dom_thesaurus($parm['bid']); if($dom) { $xpath = databox::get_xpath_thesaurus($parm['bid']);//new DOMXPath($dom); $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(noaccent_utf8($t[0], PARSED)) . '\')'; if($t[1]) $q2 .= ' and starts-with(@k, \'' . thesaurus::xquery_escape(noaccent_utf8($t[1], PARSED)) . '\')'; $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 = ''; getHTML($znode, $zhtml); } 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 .= ' '; // $zhtml .= '' . $t. ''; $zhtml .= '' .$t. ''; $zhtml .= '

'; // $zhtml .= '
'; } } if($parm['debug']) printf('zhtml=%s
\n', $zhtml); $html->appendChild($ret->createTextNode($zhtml)); } } } if($parm['debug']) { // print('
' . $ret->saveXML() . '
'); print('
' . htmlentities($zhtml) . '
'); } else { // print($ret->saveXML()); 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)); } ?>