From 9e11fd988dd720906c3c6b5b2effe2b8a447e3cc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 19 Feb 2016 03:32:02 +0100 Subject: [PATCH] Fix: color of category when showing full path must use color of last element of path --- htdocs/categories/class/categorie.class.php | 42 +++++++++++++++++---- htdocs/categories/viewcat.php | 2 +- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 03a66adab74..befbaf34c25 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1131,29 +1131,57 @@ class Categorie extends CommonObject * Retourne les chemin de la categorie, avec les noms des categories * separes par $sep (" >> " par defaut) * - * @param string $sep Separator - * @param string $url Url + * @param string $sep Separator + * @param string $url Url + * @param int $nocolor 0 * @return array */ - function print_all_ways($sep = " >> ", $url='') + function print_all_ways($sep = " >> ", $url='', $nocolor=0) { $ways = array(); - foreach ($this->get_all_ways() as $way) + $allways = $this->get_all_ways(); // Load array of categories + foreach ($allways as $way) { $w = array(); + $i = 0; foreach ($way as $cat) { + $i++; + + if (empty($nocolor)) + { + $forced_color='toreplace'; + if ($i == count($way)) + { + // Check contrast with background and correct text color + $forced_color='categtextwhite'; + if ($cat->color) + { + $hex=$cat->color; + $r = hexdec($hex[0].$hex[1]); + $g = hexdec($hex[2].$hex[3]); + $b = hexdec($hex[4].$hex[5]); + $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm + if ($bright >= 0.5) $forced_color='categtextblack'; // Higher than 60% + } + } + } + if ($url == '') { - $w[] = "".$cat->label.""; + $link = ''; + $linkend=''; + $w[] = $link.$cat->label.$linkend; } else { $w[] = "".$cat->label.""; } } - $ways[] = implode($sep, $w); + $newcategwithpath = preg_replace('/toreplace/', $forced_color, implode($sep, $w)); + + $ways[] = $newcategwithpath; } return $ways; @@ -1372,7 +1400,7 @@ class Categorie extends CommonObject $g = hexdec($hex[2].$hex[3]); $b = hexdec($hex[4].$hex[5]); $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm - if ($bright > 0.6) $forced_color='categtextblack'; // Higher than 60% + if ($bright >= 0.5) $forced_color='categtextblack'; // Higher than 60% } $link = ''; diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 3b5d0b64a86..a1486ff344f 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -189,7 +189,7 @@ print ''; // Path of category print '
'; -$ways = $object->print_all_ways(); +$ways = $object->print_all_ways(" >> ", '', 1); print $langs->trans("Ref").''; print ''.$langs->trans("Root").' >> '; foreach ($ways as $way)