an other chunk of PHP 8.0 Warnings fixed

This commit is contained in:
Ralf Becker 2021-10-08 15:43:48 +02:00
parent 1cfb7a8c6a
commit f21492632b
13 changed files with 36 additions and 34 deletions

View File

@ -468,7 +468,7 @@ class Accounts
$data = self::cache_read($id);
// add default description for Admins and Default group
if ($data['account_type'] === 'g')
if ($data && $data['account_type'] === 'g')
{
self::add_default_group_description($data);
}
@ -989,7 +989,7 @@ class Accounts
$ret = $just_id && $data['memberships'] ? array_keys($data['memberships']) : $data['memberships'];
}
//error_log(__METHOD__."($account_id, $just_id) data=".array2string($data)." returning ".array2string($ret));
return $ret;
return $ret ?? [];
}
/**

View File

@ -853,7 +853,7 @@ class Categories
if (is_null(self::$cache)) self::init_cache();
$cat = self::$cache[$cat_id];
$cat = self::$cache[$cat_id] ?? null;
if ($item == 'path')
{
if ($cat['parent'])
@ -864,7 +864,7 @@ class Categories
}
if ($item == 'data')
{
return $cat['data'] ? json_php_unserialize($cat['data'], true) : array();
return !empty($cat['data']) ? json_php_unserialize($cat['data'], true) : array();
}
elseif ($cat[$item])
{

View File

@ -210,7 +210,7 @@ class Config
{
self::init_static();
}
return (array)self::$configs[$app];
return self::$configs[$app] ?? [];
}
/**
@ -238,7 +238,7 @@ class Config
{
$config = self::read($app);
return is_array($config['types']) ? $config['types'] : array();
return !empty($config['types']) && is_array($config['types']) ? $config['types'] : [];
}
/**

View File

@ -202,9 +202,9 @@ class Contacts extends Contacts\Storage
$this->prefs['hide_accounts'] = '0';
}
// get the default addressbook from the users prefs
$this->default_addressbook = $GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'] ?
$this->default_addressbook = !empty($GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default']) ?
(int)$GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'] : $this->user;
$this->default_private = substr($GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'],-1) == 'p';
$this->default_private = substr($GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'] ?? '',-1) == 'p';
if ($this->default_addressbook > 0 && $this->default_addressbook != $this->user &&
($this->default_private ||
$this->default_addressbook == (int)$GLOBALS['egw']->preferences->forced['addressbook']['add_default'] ||
@ -312,14 +312,14 @@ class Contacts extends Contacts\Storage
'adr_two_countryname' => lang('country').' ('.lang('business').')',
);
//_debug_array($this->contact_fields);
$this->own_account_acl = $GLOBALS['egw_info']['server']['own_account_acl'];
$this->own_account_acl = $GLOBALS['egw_info']['server']['own_account_acl'] ?? null;
if (!is_array($this->own_account_acl)) $this->own_account_acl = json_php_unserialize($this->own_account_acl, true);
// we have only one acl (n_fn) for the whole name, as not all backends store every part in an own field
if ($this->own_account_acl && in_array('n_fn',$this->own_account_acl))
{
$this->own_account_acl = array_merge($this->own_account_acl,array('n_prefix','n_given','n_middle','n_family','n_suffix'));
}
if ($GLOBALS['egw_info']['server']['org_fileds_to_update'])
if (!empty($GLOBALS['egw_info']['server']['org_fileds_to_update']))
{
$this->org_fields = $GLOBALS['egw_info']['server']['org_fileds_to_update'];
if (!is_array($this->org_fields)) $this->org_fields = unserialize($this->org_fields);
@ -337,7 +337,7 @@ class Contacts extends Contacts\Storage
}
$this->categories = new Categories($this->user,'addressbook');
$this->delete_history = $GLOBALS['egw_info']['server']['history'];
$this->delete_history = $GLOBALS['egw_info']['server']['history'] ?? null;
}
/**

View File

@ -77,15 +77,15 @@ class Sql extends Api\Storage
// Get custom fields from addressbook instead of api
$this->customfields = Api\Storage\Customfields::get('addressbook');
if ($GLOBALS['egw_info']['server']['account_repository'])
if (!empty($GLOBALS['egw_info']['server']['account_repository']))
{
$this->account_repository = $GLOBALS['egw_info']['server']['account_repository'];
}
elseif ($GLOBALS['egw_info']['server']['auth_type'])
elseif (!empty($GLOBALS['egw_info']['server']['auth_type']))
{
$this->account_repository = $GLOBALS['egw_info']['server']['auth_type'];
}
if ($GLOBALS['egw_info']['server']['contact_repository'])
if (!empty($GLOBALS['egw_info']['server']['contact_repository']))
{
$this->contact_repository = $GLOBALS['egw_info']['server']['contact_repository'];
}

View File

@ -256,7 +256,7 @@ class Storage
}
$this->customfields = Api\Storage\Customfields::get('addressbook');
// contacts backend (contacts in LDAP require accounts in LDAP!)
if($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap')
if (($GLOBALS['egw_info']['server']['contact_repository']??null) === 'ldap' && $this->account_repository === 'ldap')
{
$this->contact_repository = 'ldap';
$this->somain = new Ldap();
@ -264,7 +264,7 @@ class Storage
}
else // sql or sql->ldap
{
if ($GLOBALS['egw_info']['server']['contact_repository'] == 'sql-ldap')
if (($GLOBALS['egw_info']['server']['contact_repository']??null) === 'sql-ldap')
{
$this->contact_repository = 'sql-ldap';
}
@ -347,9 +347,9 @@ class Storage
if ($user)
{
// contacts backend (contacts in LDAP require accounts in LDAP!)
if($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap')
if(($GLOBALS['egw_info']['server']['contact_repository']??null) === 'ldap' && $this->account_repository === 'ldap')
{
// static grants from ldap: all rights for the own personal addressbook and the group ones of the meberships
// static grants from ldap: all rights for the own personal addressbook and the group ones of the memberships
$grants = array($user => ~0);
foreach($GLOBALS['egw']->accounts->memberships($user,true) as $gid)
{

View File

@ -756,7 +756,7 @@ tinymce.init({
{
parse_str($vars,$vars);
}
list($url,$v) = explode('?', $_url); // url may contain additional vars
list($url,$v) = explode('?', $_url)+[null,null]; // url may contain additional vars
if ($v)
{
parse_str($v,$v);

View File

@ -737,13 +737,13 @@ class Account implements \ArrayAccess
if (empty($data['ident_email']) && $is_current_user)
{
$data['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
$data['ident_email'] = $GLOBALS['egw_info']['user']['account_email'] ?? null;
}
}
if (empty($data['ident_realname']))
{
$data['ident_realname'] = $account->ident_realname || !$is_current_user ?
$account->ident_realname : $GLOBALS['egw_info']['user']['account_fullname'];
$account->ident_realname : ($GLOBALS['egw_info']['user']['account_fullname'] ?? null);
}
}
}
@ -1414,7 +1414,7 @@ class Account implements \ArrayAccess
{
// for current user prefer account with ident_email matching user email or domain
// (this also helps notifications to account allowing to send with from address of current user / account_email)
if ($only_current_user && $GLOBALS['egw_info']['user']['account_email'])
if ($only_current_user && !empty($GLOBALS['egw_info']['user']['account_email']))
{
list(,$domain) = explode('@', $account_email = $GLOBALS['egw_info']['user']['account_email']);
// empty ident_email will be replaced with account_email!

View File

@ -265,10 +265,10 @@ class Credentials
throw new Api\Exception\WrongParameter("Unknown data[acc_imap_logintype]=".array2string($data['acc_imap_logintype']).'!');
}
$password = base64_decode(Api\Cache::getSession('phpgwapi', 'password'));
$realname = !$set_identity || $data['ident_realname'] ? $data['ident_realname'] :
$GLOBALS['egw_info']['user']['account_fullname'];
$email = !$set_identity || $data['ident_email'] ? $data['ident_email'] :
$GLOBALS['egw_info']['user']['account_email'];
$realname = !$set_identity || !empty($data['ident_realname']) ? $data['ident_realname'] :
($GLOBALS['egw_info']['user']['account_fullname'] ?? null);
$email = !$set_identity || !empty($data['ident_email']) ? $data['ident_email'] :
($GLOBALS['egw_info']['user']['account_email'] ?? null);
return array(
'ident_realname' => $realname,

View File

@ -674,7 +674,7 @@ class Storage extends Storage\Base
elseif (is_string($name) && $val!=null && in_array($name, $this->db_cols))
{
$extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table);
if ($extra_columns['fd'][array_search($name, $this->db_cols)])
if (!empty($extra_columns['fd'][array_search($name, $this->db_cols)]))
{
$filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
array_search($name, $this->db_cols) => $val,

View File

@ -1034,14 +1034,14 @@ class Base
$this->total = $this->db->select($this->table_name,$colums,$query,__LINE__,__FILE__,false,$order_by,false,0,$join)->NumRows();
}
}
$rs = $this->db->select($this->table_name,$mysql_calc_rows.$colums,$query,__LINE__,__FILE__,
$rs = $this->db->select($this->table_name,($mysql_calc_rows??'').$colums,$query,__LINE__,__FILE__,
$start,$order_by,$this->app,$num_rows,$join);
if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
$cols = $this->_get_columns($only_keys,$extra_cols);
}
if ((int) $this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
if ($mysql_calc_rows)
if (!empty($mysql_calc_rows))
{
$this->total = $this->db->query('SELECT FOUND_ROWS()')->fetchColumn();
}
@ -1157,8 +1157,8 @@ class Base
}
}
}
if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ',$query);
return $query;
if (!empty($query) && is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ',$query);
return $query ?? null;
}
/**

View File

@ -283,7 +283,7 @@ abstract class Tracking
//error_log(__METHOD__."() $name: data['#$name']=".array2string($data['#'.$name]).", field[values]=".array2string($field['values']));
$details['#'.$name] = array(
'label' => $field['label'],
'value' => Customfields::format($field, $data['#'.$name]),
'value' => Customfields::format($field, $data['#'.$name] ?? null),
);
//error_log("--> details['#$name']=".array2string($details['#'.$name]));
}
@ -1049,7 +1049,7 @@ abstract class Tracking
// remove the session-id in the notification mail!
$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link);
if ($popup) $link .= '&nopopup=1';
if (!empty($popup)) $link .= '&nopopup=1';
}
//error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link));
return $allow_popup ? array($link,$popup) : $link;
@ -1122,7 +1122,7 @@ abstract class Tracking
{
// if there's no old entry, the entry is not modified by definition
// if both values are '', 0 or null, we count them as equal too
$modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]);
$modified = $old && ($data[$name] ?? null) != ($old[$name] ?? null) && !(empty($data[$name]) && empty($old[$name]));
//if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified);
if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values

View File

@ -175,6 +175,8 @@ function php_safe_unserialize($str)
*/
function json_php_unserialize($str, $allow_not_serialized=false)
{
if (!isset($str)) return $str;
if ((in_array($str[0], array('a', 'i', 's', 'b', 'O', 'C')) && $str[1] == ':' || $str === 'N;') &&
($arr = php_safe_unserialize($str)) !== false || $str === 'b:0;')
{