2
0
forked from Wavyzz/dolibarr

Merge pull request #19655 from cfoellmann/wus/hotfix/fontawesome-PR

use any available fontawesome icon in picto
This commit is contained in:
Laurent Destailleur
2022-01-26 13:44:38 +01:00
committed by GitHub

View File

@@ -1666,7 +1666,11 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab
$limittitle = 30;
$out .= '<a class="tabTitle">';
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 .= '<span class="tabTitleText">'.dol_escape_htmltag(dol_trunc($title, $limittitle)).'</span>';
$out .= '</a>';
@@ -2021,10 +2025,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 .= '<!-- No photo to show -->';
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
@@ -3609,6 +3617,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_1em if you want to use fontaweseome icons: fontawesome_<icon-name>_<style>_<color>_<size> (only icon-name is mandatory)
* @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.
@@ -3640,6 +3649,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 = '<span class="'.$fa.' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ? ' marginleftonlyshort' : ' marginleftonly') : '');
$enabledisablehtml .= ($morecss ? ' '.$morecss : '').'" style="'.($fasize ? ('font-size: '.$fasize.';') : '').($facolor ? (' color: '.$facolor.';') : '').($morestyle ? ' '.$morestyle : '').'"'.(($notitle || empty($titlealt)) ? '' : ' title="'.dol_escape_htmltag($titlealt).'"').($moreatt ? ' '.$moreatt : '').'>';
/*if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$enabledisablehtml .= $titlealt;
}*/
$enabledisablehtml .= '</span>';
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',