get_session(); $registry = $appbox->get_registry(); $request = http_request::getInstance(); $parm = $request->get_parms( 'sbid' , 't' , 'field' // search only in the branch(es) linked to this field , 'lng' , 'debug' ); phrasea::headers(200, true, 'application/json', 'UTF-8', false); if (!$parm['lng']) { $lng2 = Session_Handler::get_locale(); $lng2 = explode('_', $lng2); if (count($lng2) > 0) $parm['lng'] = $lng2[0]; } $lng = $parm['lng']; if ($parm['debug']) print("
");

$html = '';

$sbid = (int) $parm['sbid'];

$dbname = '';

$loaded = false;

try
{
  $databox = databox::get_instance($sbid);
  $unicode = new unicode();

  $html = "" . '' . "\n";
}
catch (Exception $e)
{

}

if ($parm['debug'])
  print(htmlentities($html));
else
  print(p4string::jsonencode(array('parm' => $parm, 'html' => $html)));

if ($parm['debug'])
  print("
"); function getHTML($srcnode, &$html, $depth=0) { global $parm; if ($parm['debug']) printf("in: depth:%s \n", $depth); $bid = $parm['sbid']; $tid = $srcnode->getAttribute('id'); // let's work on each 'te' (=ts) subnode $nts = 0; $ntsopened = 0; $tts = array(); for ($n = $srcnode->firstChild; $n; $n = $n->nextSibling) { if ($n->nodeName == 'te') { if ($n->getAttribute('open')) { $key0 = null; // key of the sy in the current language (or key of the first sy if we can't find good lng) $nts0 = 0; // count of ts under this term $label = buildLabel($n, $key0, $nts0); for ($uniq = 0; $uniq < 9999; $uniq++) { if (!isset($tts[$key0 . '_' . $uniq])) break; } $tts[$key0 . '_' . $uniq] = array('label' => $label, 'nts' => $nts0, 'n' => $n); $ntsopened++; } $nts++; } } if ($parm["debug"]) printf("%s : tts(%s) :
%s

\n", __LINE__, $nts, var_export($tts, true)); if ($nts > 0) { $tab = str_repeat("\t", 1 + $depth * 2); if ($ntsopened == 0) { $html .= $tab . '' . "\n"; } else { $html .= $tab . '' . "\n"; } } if ($parm['debug']) printf("out: depth:%s \n", $depth); } function buildLabel($n, &$key0, &$nts0) { global $parm; $lngfound = false; // true when wet met a first synonym in the current language $key0 = null; // key of the sy in the current language (or key of the first sy if we can't find good lng) $label = ''; $nts0 = 0; // // compute the label of the term, regarding the current language. for ($n2 = $n->firstChild; $n2; $n2 = $n2->nextSibling) { if ($n2->nodeName == 'sy') { $lng = $n2->getAttribute('lng'); $t = $n2->getAttribute('v'); $key = $n2->getAttribute('w'); // key of the current sy if ($k = $n2->getAttribute('k')) $key .= ' (' . $k . ')'; if (!$key0) // first sy gives the key $key0 = $key; $class = $n2->getAttribute('bold') ? 'class="h"' : ''; if (!$lngfound && $lng == $parm['lng']) // overwrite the key if we found the good lng { $key0 = $key; $lngfound = true; $label = '' . $t . '' . ($label == '' ? '' : ' ; ') . $label; } else { $label = $label . ($label == '' ? '' : ' ; ') . '' . $t . ''; } } elseif ($n2->nodeName == 'te') // && $n2->getAttribute('open')) { $nts0++; } } return($label); } 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)); }