enhance dol_print_ip (#33819)

* enhance dol_print_ip

* fix cache

* fix CI
This commit is contained in:
Frédéric FRANCE
2025-04-12 16:19:45 +02:00
committed by GitHub
parent ec7ecd9f08
commit 2b468e6b0f
2 changed files with 22 additions and 7 deletions

View File

@@ -1256,7 +1256,7 @@ abstract class CommonObject
return -2;
}
if ($this->restrictiononfksoc && property_exists('socid', $this) && !empty($this->socid) && !$user->hasRight('societe', 'client', 'voir')) {
if ($this->restrictiononfksoc && property_exists($this, 'socid') && !empty($this->socid) && !$user->hasRight('societe', 'client', 'voir')) {
$sql_allowed_contacts = 'SELECT COUNT(*) as cnt FROM '.$this->db->prefix().'societe_commerciaux as sc';
$sql_allowed_contacts.= ' WHERE sc.fk_soc = '.(int) $this->socid;
$sql_allowed_contacts.= ' AND sc.fk_user = '.(int) $user->id;

View File

@@ -4769,27 +4769,42 @@ function dol_print_phone($phone, $countrycode = '', $cid = 0, $socid = 0, $addli
*/
function dol_print_ip($ip, $mode = 0)
{
global $langs;
global $conf, $langs;
$ret = '';
if (empty($mode)) {
$ret .= $ip;
if (!isset($conf->cache['resolveips'])) {
$conf->cache['resolveips'] = [];
}
if ($mode != 2) {
$countrycode = dolGetCountryCodeFromIp($ip);
if ($countrycode) { // If success, countrycode is us, fr, ...
if (file_exists(DOL_DOCUMENT_ROOT.'/theme/common/flags/'.$countrycode.'.png')) {
$ret .= ' '.img_picto($countrycode.' '.$langs->trans("AccordingToGeoIPDatabase"), DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png', '', 1);
$ret .= picto_from_langcode($countrycode);
// $ret .= img_picto($countrycode.' '.$langs->trans("AccordingToGeoIPDatabase"), DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png', '', 1);
} else {
$ret .= ' ('.$countrycode.')';
$ret .= '('.$countrycode.')';
}
$ret .= ' ';
} else {
// Nothing
}
}
if (in_array($mode, [0, 2])) {
if (empty($conf->cache['resolveips'][$ip])) {
$domain = gethostbyaddr($ip);
$conf->cache['resolveips'][$ip] = $domain; // false or domain
} else {
$domain = $conf->cache['resolveips'][$ip];
}
if ($domain) {
$ret .= $domain;
} else {
$ret .= $ip;
}
}
return $ret;
}