From 6bbbd99be901d51599eded1ac27e3c8be8bb951a Mon Sep 17 00:00:00 2001 From: Christian Foellmann Date: Tue, 26 Oct 2021 17:23:51 +0200 Subject: [PATCH] use any available fontawesome icon in picto --- htdocs/core/lib/functions.lib.php | 47 +++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index bf36a72bfa2..5d48edabe03 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1650,7 +1650,11 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab $limittitle = 30; $out .= ''; if ($picto) { - $out .= img_picto($title, ($pictoisfullpath ? '' : 'object_').$picto, '', $pictoisfullpath, 0, 0, '', 'imgTabTitle').' '; + $noprefix = $pictoisfullpath; + if (strpos($picto, 'fontawesome_') !== false) { + $noprefix = 1; + } + $out .= img_picto($title, ($noprefix ? '' : 'object_').$picto, '', $pictoisfullpath, 0, 0, '', 'imgTabTitle').' '; } $out .= ''.dol_escape_htmltag(dol_trunc($title, $limittitle)).''; $out .= ''; @@ -2004,10 +2008,14 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi $width = 14; $cssclass = 'photorefcenter'; $picto = $object->picto; + $prefix = 'object_'; if ($object->element == 'project' && !$object->public) { $picto = 'project'; // instead of projectpub } - $nophoto = img_picto('No photo', 'object_'.$picto); + if (strpos($picto, 'fontawesome_') !== false) { + $prefix = ''; + } + $nophoto = img_picto('No photo', $prefix.$picto); } $morehtmlleft .= ''; $morehtmlleft .= '
'; @@ -3592,6 +3600,7 @@ function dol_trunc($string, $size = 40, $trunc = 'right', $stringencoding = 'UTF * Example: picto.png if picto.png is stored into htdocs/theme/mytheme/img * Example: picto.png@mymodule if picto.png is stored into htdocs/mymodule/img * Example: /mydir/mysubdir/picto.png if picto.png is stored into htdocs/mydir/mysubdir (pictoisfullpath must be set to 1) + * Example: fontawesome_envelope-open-text_fas_red if you want to use fontaweseome icons: fontawesome__style_color_size * @param string $moreatt Add more attribute on img tag (For example 'class="pictofixedwidth"') * @param boolean|int $pictoisfullpath If true or 1, image path is a full path * @param int $srconly Return only content of the src attribute of img. @@ -3623,6 +3632,40 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ } } else { $pictowithouttext = preg_replace('/(\.png|\.gif|\.svg)$/', '', $picto); + + if (strpos($pictowithouttext, 'fontawesome_') !== false) { + $pictowithouttext = explode('_', $pictowithouttext); + $marginleftonlyshort = 0; + + $fakey = 'fa-'.$pictowithouttext[1]; + $fa = $pictowithouttext[2] ? $pictowithouttext[2] : 'fa'; + $facolor = $pictowithouttext[3] ? $pictowithouttext[3] : ''; + $fasize = $pictowithouttext[4] ? $pictowithouttext[4] : ''; + + // This snippet only needed since function img_edit accepts only one additional parameter: no separate one for css only. + // class/style need to be extracted to avoid duplicate class/style validation errors when $moreatt is added to the end of the attributes. + $morestyle = ''; + $reg = array(); + if (preg_match('/class="([^"]+)"/', $moreatt, $reg)) { + $morecss .= ($morecss ? ' ' : '').$reg[1]; + $moreatt = str_replace('class="'.$reg[1].'"', '', $moreatt); + } + if (preg_match('/style="([^"]+)"/', $moreatt, $reg)) { + $morestyle = $reg[1]; + $moreatt = str_replace('style="'.$reg[1].'"', '', $moreatt); + } + $moreatt = trim($moreatt); + + $enabledisablehtml = ''; + /*if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { + $enabledisablehtml .= $titlealt; + }*/ + $enabledisablehtml .= ''; + + return $enabledisablehtml; + } + $pictowithouttext = str_replace('object_', '', $pictowithouttext); if (empty($srconly) && in_array($pictowithouttext, array( '1downarrow', '1uparrow', '1leftarrow', '1rightarrow', '1uparrow_selected', '1downarrow_selected', '1leftarrow_selected', '1rightarrow_selected',