From a07193ef4b5dfc738e40d625a79601bb63f67954 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 9 Dec 2022 15:57:18 +0100 Subject: [PATCH] Fix php8 --- htdocs/admin/agenda_extsites.php | 8 +++---- htdocs/comm/action/index.php | 14 +++++------ htdocs/core/lib/functions.lib.php | 39 +++++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/htdocs/admin/agenda_extsites.php b/htdocs/admin/agenda_extsites.php index 86701344ba4..83391e6ce3d 100644 --- a/htdocs/admin/agenda_extsites.php +++ b/htdocs/admin/agenda_extsites.php @@ -279,13 +279,13 @@ while ($i <= $MAXAGENDA) { print ''; // Calendar active by default print ''; - if ($conf->use_javascript_ajax) { + if (!empty($conf->use_javascript_ajax)) { print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key); } else { - if (empty($conf->global->{$default})) { - print '' . img_picto($langs->trans("Enabled"), 'on') . ''; - } else { + if (getDolGlobalString($default)) { print '' . img_picto($langs->trans("Disabled"), 'off') . ''; + } else { + print '' . img_picto($langs->trans("Enabled"), 'on') . ''; } } print ''; diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index a6a39d1eb05..ab814957e5b 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -274,7 +274,7 @@ if (empty($conf->global->AGENDA_DISABLE_EXT)) { $color = 'AGENDA_EXT_COLOR'.$i; $default = 'AGENDA_EXT_ACTIVEBYDEFAULT'.$i; $buggedfile = 'AGENDA_EXT_BUGGEDFILE'.$i; - if (!empty($conf->global->$source) && !empty($conf->global->$name)) { + if (getDolGlobalString($source) && getDolGlobalString($name)) { // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' $listofextcals[] = array( 'src' => getDolGlobalString($source), @@ -299,14 +299,14 @@ if (empty($user->conf->AGENDA_DISABLE_EXT)) { $enabled = 'AGENDA_EXT_ENABLED_'.$user->id.'_'.$i; $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_'.$user->id.'_'.$i; $buggedfile = 'AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i; - if (!empty($user->conf->$source) && !empty($user->conf->$name)) { + if (getDolUserString($source) && getDolUserString($name)) { // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' $listofextcals[] = array( - 'src' => $user->conf->$source, - 'name' => dol_string_nohtmltag($user->conf->$name), + 'src' => getDolUserString($source), + 'name' => dol_string_nohtmltag(getDolUserString($name)), 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz), - 'color' => dol_string_nohtmltag($user->conf->$color), - 'default' => dol_string_nohtmltag($user->conf->$default), + 'color' => dol_string_nohtmltag(getDolUserString($color)), + 'default' => dol_string_nohtmltag(getDolUserString($default)), 'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '') ); } @@ -1287,7 +1287,7 @@ if (count($listofextcals)) { } // Transparency (see https://www.kanzaki.com/docs/ical/transp.html) - if ($icalevent['TRANSP']) { + if (!empty($icalevent['TRANSP'])) { if ($icalevent['TRANSP'] == "TRANSPARENT") { $event->transparency = 0; // 0 = available / free } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 776633960e6..dbf3622f1a7 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -73,8 +73,9 @@ if (!function_exists('utf8_decode')) { /** * Return dolibarr global constant string value - * @param string $key key to return value, return '' if not set - * @param string $default value to return + * + * @param string $key key to return value, return '' if not set + * @param string $default value to return * @return string */ function getDolGlobalString($key, $default = '') @@ -86,8 +87,9 @@ function getDolGlobalString($key, $default = '') /** * Return dolibarr global constant int value - * @param string $key key to return value, return 0 if not set - * @param int $default value to return + * + * @param string $key key to return value, return 0 if not set + * @param int $default value to return * @return int */ function getDolGlobalInt($key, $default = 0) @@ -97,8 +99,37 @@ function getDolGlobalInt($key, $default = 0) return (int) (empty($conf->global->$key) ? $default : $conf->global->$key); } +/** + * Return dolibarr user constant string value + * + * @param string $key key to return value, return '' if not set + * @param string $default value to return + * @return string + */ +function getDolUserString($key, $default = '') +{ + global $user; + // return $conf->global->$key ?? $default; + return (string) (empty($user->conf->$key) ? $default : $user->conf->$key); +} + +/** + * Return dolibarr user constant int value + * + * @param string $key key to return value, return 0 if not set + * @param int $default value to return + * @return int + */ +function getDolUserInt($key, $default = 0) +{ + global $user; + // return $conf->global->$key ?? $default; + return (int) (empty($user->conf->$key) ? $default : $user->conf->$key); +} + /** * Is Dolibarr module enabled + * * @param string $module module name to check * @return int */