Conflicts:
	lib/classes/caption/Field/Value.php
This commit is contained in:
Jean-Yves Gaulier
2013-12-11 19:00:35 +01:00
committed by Romain Neutron
parent f5f17549ad
commit f71fb36377

View File

@@ -353,72 +353,55 @@ class caption_Field_Value implements cache_cacheableInterface
return $value; return $value;
} }
// ---------------- new code ----------------------
$cleanvalue = str_replace(array("<em>", "</em>", "'"), array("", "", "&apos;"), $value); $cleanvalue = str_replace(array("<em>", "</em>", "'"), array("", "", "&apos;"), $value);
$fvalue = $value;
$cleanvalue = str_replace(array("<em>", "</em>", "'"), array("", "", "&apos;"), $fvalue);
list($term_noacc, $context_noacc) = $this->splitTermAndContext($cleanvalue); list($term_noacc, $context_noacc) = $this->splitTermAndContext($cleanvalue);
$term_noacc = $this->app['unicode']->remove_indexer_chars($term_noacc); $term_noacc = $this->app['unicode']->remove_indexer_chars($term_noacc);
$context_noacc = $this->app['unicode']->remove_indexer_chars($context_noacc); $context_noacc = $this->app['unicode']->remove_indexer_chars($context_noacc);
// find all synonyms in all related branches
$q = "(" . $tbranch . ")//sy[@w='" . $term_noacc . "'";
if ($context_noacc) { if ($context_noacc) {
$q = "//sy[@w='" . $term_noacc . "' and @k='" . $context_noacc . "']"; $q .= " and @k='" . $context_noacc . "']";
} else { } else {
$q = "//sy[@w='" . $term_noacc . "' and not(@k)]"; $q .= " and not(@k)]";
} }
$qjs = $link = ""; $q .= "/../sy";
// loop on each linked branch for field $nodes = $XPATH_thesaurus->query($q);
foreach ($DOM_branchs as $DOM_branch) {
$nodes = $XPATH_thesaurus->cache_query($q, $DOM_branch); // loop on every sy found
$lngfound = false; $bestnode = null;
$bestnote = 0;
foreach ($nodes as $node) { foreach ($nodes as $node) {
if ($node->getAttribute("lng") == $this->app['locale.I18n']) { $note = 0;
// le terme est dans la bonne langue, on le rend cliquable $note += ($node->getAttribute("lng") == $this->app['locale.I18n']) ? 4 : 0;
list($term, $context) = $this->splitTermAndContext($fvalue); $note += ($node->getAttribute("w") == $term_noacc) ? 2 : 0;
if($context_noacc != "")
$note += ($node->getAttribute("k") == $context_noacc) ? 1 : 0;
if($note > $bestnote)
{
$bestnote = $note;
$bestnode = $node;
}
}
if($bestnode)
{
list($term, $context) = $this->splitTermAndContext($value);
$term = str_replace(array("<em>", "</em>"), array("", ""), $term); $term = str_replace(array("<em>", "</em>"), array("", ""), $term);
$context = str_replace(array("<em>", "</em>"), array("", ""), $context); $context = str_replace(array("<em>", "</em>"), array("", ""), $context);
$qjs = $term; $qjs = $term;
if ($context) { if ($context) {
$qjs .= " [" . $context . "]"; $qjs .= " [" . $context . "]";
} }
$link = $fvalue;
$lngfound = true;
break;
}
$synonyms = $XPATH_thesaurus->query("sy[@lng='" . $this->app['locale.I18n'] . "']", $node->parentNode);
foreach ($synonyms as $synonym) {
$k = $synonym->getAttribute("k");
if ($synonym->getAttribute("w") != $term_noacc || $k != $context_noacc) {
$link = $qjs = $synonym->getAttribute("v");
$lngfound = true;
break;
}
}
}
if (! $lngfound) {
list($term, $context) = $this->splitTermAndContext($fvalue);
$term = str_replace(array("<em>", "</em>"), array("", ""), $term);
$context = str_replace(array("<em>", "</em>"), array("", ""), $context);
$qjs = $term;
if ($context) {
$qjs .= " [" . $context . "]";
}
$link = $fvalue;
}
}
if ($qjs) {
$value = "<a class=\"bounce\" onclick=\"bounce('" . $databox->get_sbas_id() . "','" $value = "<a class=\"bounce\" onclick=\"bounce('" . $databox->get_sbas_id() . "','"
. str_replace("'", "\'", $qjs) . str_replace("'", "\'", $qjs)
. "', '" . "', '"
. str_replace("'", "\'", $this->databox_field->get_name()) . str_replace("'", "\'", $this->databox_field->get_name())
. "');return(false);\">" . "');return(false);\">"
. $link . $bestnode->getAttribute('v')
. "</a>"; . "</a>";
} }